#define MAX_QUERY_LEN 1024
-static int sqlcounter_detach(void *instance);
-
/*
* Note: When your counter spans more than 1 period (ie 3 months
* or 2 weeks), this module probably does NOT do what you want! It
}
+static int sqlcounter_detach(void *instance)
+{
+ rlm_sqlcounter_t *inst = (rlm_sqlcounter_t *)instance;
+
+ paircompare_unregister(inst->dict_attr->attr, sqlcounter_cmp);
+
+ return 0;
+}
+
/*
* Do any per-module initialization that is separate to each
* configured instance of the module. e.g. set up connections
/*
* Set up a storage area for instance data
*/
- data = rad_malloc(sizeof(*data));
- if (!data) {
- radlog(L_ERR, "rlm_sqlcounter: Not enough memory.");
- return -1;
- }
- memset(data, 0, sizeof(*data));
+ *instance = data = talloc_zero(conf, rlm_sqlcounter_t);
+ if (!data) return -1;
/*
* If the configuration parameters can't be parsed, then
*/
if (cf_section_parse(conf, data, module_config) < 0) {
radlog(L_ERR, "rlm_sqlcounter: Unable to parse parameters.");
- sqlcounter_detach(data);
return -1;
}
*/
if (data->query == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'query' must be set.");
- sqlcounter_detach(data);
return -1;
}
*/
if (data->key_name == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'key' must be set.");
- sqlcounter_detach(data);
return -1;
}
dattr = dict_attrbyname(data->key_name);
if (dattr == NULL) {
radlog(L_ERR, "rlm_sqlcounter: No such attribute %s",
data->key_name);
- sqlcounter_detach(data);
return -1;
}
data->key_attr = dattr;
if (dattr == NULL) {
radlog(L_ERR, "rlm_sqlcounter: No such attribute %s",
data->reply_name);
- sqlcounter_detach(data);
return -1;
}
data->reply_attr = dattr;
*/
if (data->sqlmod_inst == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'sqlmod-inst' must be set.");
- sqlcounter_detach(data);
return -1;
}
*/
if (data->counter_name == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'counter-name' must be set.");
- sqlcounter_detach(data);
return -1;
}
if (dattr == NULL) {
radlog(L_ERR, "rlm_sqlcounter: Failed to create counter attribute %s",
data->counter_name);
- sqlcounter_detach(data);
return -1;
}
if (dattr->vendor != 0) {
radlog(L_ERR, "Counter attribute must not be a VSA");
- sqlcounter_detach(data);
return -1;
}
data->dict_attr = dattr;
*/
if (data->check_name == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'check-name' must be set.");
- sqlcounter_detach(data);
return -1;
}
dict_addattr(data->check_name, 0, PW_TYPE_INTEGER, -1, flags);
if (dattr == NULL) {
radlog(L_ERR, "rlm_sqlcounter: Failed to create check attribute %s",
data->check_name);
- sqlcounter_detach(data);
return -1;
}
DEBUG2("rlm_sqlcounter: Check attribute %s is number %d",
*/
if (data->reset == NULL) {
radlog(L_ERR, "rlm_sqlcounter: 'reset' must be set.");
- sqlcounter_detach(data);
return -1;
}
now = time(NULL);
if (find_next_reset(data,now) == -1) {
radlog(L_ERR, "rlm_sqlcounter: Failed to find the next reset time.");
- sqlcounter_detach(data);
return -1;
}
if (find_prev_reset(data,now) == -1) {
radlog(L_ERR, "rlm_sqlcounter: Failed to find the previous reset time.");
- sqlcounter_detach(data);
return -1;
}
return rcode;
}
-static int sqlcounter_detach(void *instance)
-{
- rlm_sqlcounter_t *inst = (rlm_sqlcounter_t *)instance;
-
- paircompare_unregister(inst->dict_attr->attr, sqlcounter_cmp);
-
- free(inst);
- return 0;
-}
-
/*
* The module name should be the only globally exported symbol.
* That is, everything else should be 'static'.