... | ... |
@@ -667,11 +667,12 @@ int do_action(struct action* a, struct sip_msg* msg) |
667 | 667 |
break; |
668 | 668 |
} |
669 | 669 |
/* load the attribute(s)*/ |
670 |
- if ( load_avp( msg, (int)a->p1.number, a->p2.string, |
|
671 |
- (int)a->p3.number)!=0 ) { |
|
670 |
+ if ( (ret=load_avp( msg, (int)a->p1.number, a->p2.string, |
|
671 |
+ (int)a->p3.number))==-1 ) { |
|
672 | 672 |
LOG(L_ERR,"ERROR:do_action: load avp failed\n"); |
673 | 673 |
ret=E_UNSPEC; |
674 | 674 |
} |
675 |
+ ret = (ret==0)?1/*success*/:E_UNSPEC/*notfound*/; |
|
675 | 676 |
break; |
676 | 677 |
default: |
677 | 678 |
LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type); |
... | ... |
@@ -226,7 +226,11 @@ inline static int validate_db_row(struct db_row *row, unsigned int *val_type, |
226 | 226 |
memcpy( _p_, (_ss_).s, (_ss_).len);\ |
227 | 227 |
(_p_) += (_ss_).len;\ |
228 | 228 |
}while(0) |
229 |
- |
|
229 |
+/* |
|
230 |
+ * Returns: -1 : error |
|
231 |
+ * 0 : sucess and avp(s) loaded |
|
232 |
+ * 1 : sucess but no avp loaded |
|
233 |
+ */ |
|
230 | 234 |
int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom) |
231 | 235 |
{ |
232 | 236 |
db_res_t *res; |
... | ... |
@@ -239,10 +243,6 @@ int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom) |
239 | 243 |
int len; |
240 | 244 |
char *p; |
241 | 245 |
|
242 |
- /* |
|
243 |
- DBG("----load_avp:%d,%s,%d\n",uri_type,attr?attr:"NULL",use_dom); |
|
244 |
- */ |
|
245 |
- |
|
246 | 246 |
/* featch the user name [and domain] */ |
247 | 247 |
switch (uri_type) { |
248 | 248 |
case 0: /* RURI */ |
... | ... |
@@ -291,44 +291,47 @@ int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom) |
291 | 291 |
DBG("DEBUG:load_avp: no avp found for %.*s@%.*s <%s>\n", |
292 | 292 |
uri.user.len,uri.user.s,(use_dom!=0)*uri.host.len,uri.host.s, |
293 | 293 |
attr?attr:"NULL"); |
294 |
- } else { |
|
295 |
- for( n=0 ; n<res->n ; n++) { |
|
296 |
- /* validate row */ |
|
297 |
- if (validate_db_row( &res->rows[n] ,&val_type, &uint_val) < 0 ) |
|
298 |
- continue; |
|
299 |
- /* what do we have here?! */ |
|
300 |
- DBG("DEBUG:load_avp: found avp: <%s,%s,%d>\n", |
|
301 |
- res->rows[n].values[0].val.string_val, |
|
302 |
- res->rows[n].values[1].val.string_val, |
|
303 |
- res->rows[n].values[2].val.int_val); |
|
304 |
- /* build a new avp struct */ |
|
305 |
- len = sizeof(struct usr_avp); |
|
306 |
- len += res->rows[n].values[0].val.str_val.len ; |
|
307 |
- if (val_type==AVP_TYPE_STR) |
|
308 |
- len += res->rows[n].values[1].val.str_val.len ; |
|
309 |
- avp = (struct usr_avp*)pkg_malloc( len ); |
|
310 |
- if (avp==0) { |
|
311 |
- LOG(L_ERR,"ERROR:load_avp: no more pkg mem\n"); |
|
312 |
- continue; |
|
313 |
- } |
|
314 |
- /* fill the structure in */ |
|
315 |
- p = ((char*)avp) + sizeof(struct usr_avp); |
|
316 |
- avp->id = compute_ID( &res->rows[n].values[0].val.str_val ); |
|
317 |
- avp->val_type = val_type; |
|
318 |
- /* attribute name */ |
|
319 |
- copy_str( p, avp->attr, res->rows[n].values[0].val.str_val); |
|
320 |
- if (val_type==AVP_TYPE_INT) { |
|
321 |
- /* INT */ |
|
322 |
- avp->val.uint_val = uint_val; |
|
323 |
- } else { |
|
324 |
- /* STRING */ |
|
325 |
- copy_str( p, avp->val.str_val, |
|
326 |
- res->rows[n].values[1].val.str_val); |
|
327 |
- } |
|
328 |
- /* add avp to internal list */ |
|
329 |
- avp->next = users_avps; |
|
330 |
- users_avps = avp; |
|
294 |
+ db_free_query( avp_db_con, res); |
|
295 |
+ /*no avp found*/ |
|
296 |
+ return 1; |
|
297 |
+ } |
|
298 |
+ |
|
299 |
+ for( n=0 ; n<res->n ; n++) { |
|
300 |
+ /* validate row */ |
|
301 |
+ if (validate_db_row( &res->rows[n] ,&val_type, &uint_val) < 0 ) |
|
302 |
+ continue; |
|
303 |
+ /* what do we have here?! */ |
|
304 |
+ DBG("DEBUG:load_avp: found avp: <%s,%s,%d>\n", |
|
305 |
+ res->rows[n].values[0].val.string_val, |
|
306 |
+ res->rows[n].values[1].val.string_val, |
|
307 |
+ res->rows[n].values[2].val.int_val); |
|
308 |
+ /* build a new avp struct */ |
|
309 |
+ len = sizeof(struct usr_avp); |
|
310 |
+ len += res->rows[n].values[0].val.str_val.len ; |
|
311 |
+ if (val_type==AVP_TYPE_STR) |
|
312 |
+ len += res->rows[n].values[1].val.str_val.len ; |
|
313 |
+ avp = (struct usr_avp*)pkg_malloc( len ); |
|
314 |
+ if (avp==0) { |
|
315 |
+ LOG(L_ERR,"ERROR:load_avp: no more pkg mem\n"); |
|
316 |
+ continue; |
|
317 |
+ } |
|
318 |
+ /* fill the structure in */ |
|
319 |
+ p = ((char*)avp) + sizeof(struct usr_avp); |
|
320 |
+ avp->id = compute_ID( &res->rows[n].values[0].val.str_val ); |
|
321 |
+ avp->val_type = val_type; |
|
322 |
+ /* attribute name */ |
|
323 |
+ copy_str( p, avp->attr, res->rows[n].values[0].val.str_val); |
|
324 |
+ if (val_type==AVP_TYPE_INT) { |
|
325 |
+ /* INT */ |
|
326 |
+ avp->val.uint_val = uint_val; |
|
327 |
+ } else { |
|
328 |
+ /* STRING */ |
|
329 |
+ copy_str( p, avp->val.str_val, |
|
330 |
+ res->rows[n].values[1].val.str_val); |
|
331 | 331 |
} |
332 |
+ /* add avp to internal list */ |
|
333 |
+ avp->next = users_avps; |
|
334 |
+ users_avps = avp; |
|
332 | 335 |
} |
333 | 336 |
|
334 | 337 |
db_free_query( avp_db_con, res); |