/** * new_avp_from_finfo: * @param name the name the avp will have. * @param finfo the field_info from which to fetch the data. * * Creates an avp from a field_info record. * * Return value: a pointer to the newly created avp. * **/ extern AVP* new_avp_from_finfo(const gchar* name, field_info* finfo) { AVP* new_avp_val = (AVP*)g_slice_new(any_avp_type); gchar* value; gchar* repr; new_avp_val->n = scs_subscribe(avp_strings, name); repr = fvalue_to_string_repr(&finfo->value,FTREPR_DISPLAY,finfo->hfinfo->display,NULL); if (repr) { value = scs_subscribe(avp_strings, repr); g_free(repr); #ifdef _AVP_DEBUGGING dbg_print (dbg_avp,2,dbg_fp,"new_avp_from_finfo: from string: %s",value); #endif } else { #ifdef _AVP_DEBUGGING dbg_print (dbg_avp,2,dbg_fp,"new_avp_from_finfo: a proto: %s",finfo->hfinfo->abbrev); #endif value = scs_subscribe(avp_strings, ""); } new_avp_val->v = value; new_avp_val->o = '='; #ifdef _AVP_DEBUGGING dbg_print (dbg_avp,1,dbg_fp,"new_avp_from_finfo: %X %s%c%s;",(guint32) new_avp_val,new_avp_val->n,new_avp_val->o,new_avp_val->v); #endif return new_avp_val; }
/** * new_avp: * @param name the name the avp will have. * @param value the value the avp will have. * @param o the operator of this avp. * * Creates an avp given every parameter. * * Return value: a pointer to the newly created avp. * **/ extern AVP* new_avp(const gchar* name, const gchar* value, gchar o) { AVP* new_avp_val = (AVP*)g_slice_new(any_avp_type); new_avp_val->n = scs_subscribe(avp_strings, name); new_avp_val->v = scs_subscribe(avp_strings, value); new_avp_val->o = o; #ifdef _AVP_DEBUGGING dbg_print(dbg_avp,1,dbg_fp,"new_avp_val: %X %s%c%s;",(guint32) new_avp_val,new_avp_val->n,new_avp_val->o,new_avp_val->v); #endif return new_avp_val; }
/** * avp_copy: * @param from the avp to be copied. * * Creates an avp whose name op and value are copies of the given one. * * Return value: a pointer to the newly created avp. * **/ extern AVP* avp_copy(AVP* from) { AVP* new_avp_val = (AVP*)g_slice_new(any_avp_type); new_avp_val->n = scs_subscribe(avp_strings, from->n); new_avp_val->v = scs_subscribe(avp_strings, from->v); new_avp_val->o = from->o; #ifdef _AVP_DEBUGGING dbg_print(dbg_avp,1,dbg_fp,"copy_avp: %X %s%c%s;",(guint32) new_avp_val,new_avp_val->n,new_avp_val->o,new_avp_val->v); #endif return new_avp_val; }
/** * get_avp_by_name: * @param avpl the avpl from which to try to get the avp. * @param name the name of the avp we are looking for. * @param cookie variable in which to store the state between calls. * * Gets pointer to the next avp whose name is given; uses cookie to store its * state between calls. * * Return value: a pointer to the next matching avp if there's one, else NULL. * **/ extern AVP* get_avp_by_name(AVPL* avpl, gchar* name, void** cookie) { AVPN* curr; AVPN* start = (AVPN*) *cookie; #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,7,dbg_fp,"get_avp_by_name: entering: %X %s %X",avpl,name,*cookie); #endif name = scs_subscribe(avp_strings, name); if (!start) start = avpl->null.next; for ( curr = start; curr->avp; curr = curr->next ) { if ( curr->avp->n == name ) { break; } } *cookie = curr; #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,5,dbg_fp,"get_avp_by_name: got avp: %X",curr); #endif scs_unsubscribe(avp_strings, name); return curr->avp; }
/** * new_avpl: * @param name the name the avpl will have. * * Creates an empty avpl. * * Return value: a pointer to the newly created avpl. * **/ extern AVPL* new_avpl(const gchar* name) { AVPL* new_avpl_p = (AVPL*)g_slice_new(any_avp_type); #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,7,dbg_fp,"new_avpl_p: %X name=%s",new_avpl_p,name); #endif new_avpl_p->name = name ? scs_subscribe(avp_strings, name) : scs_subscribe(avp_strings, ""); new_avpl_p->len = 0; new_avpl_p->null.avp = NULL; new_avpl_p->null.next = &new_avpl_p->null; new_avpl_p->null.prev = &new_avpl_p->null; return new_avpl_p; }
/** * scs_subscribe_printf: * @fmt: a format string ... * * Formats the input and subscribes it. * * Return value: the stored copy of the formated string. * **/ gchar* scs_subscribe_printf(SCS_collection* c, gchar* fmt, ...) { va_list list; static gchar buf[SCS_HUGE_SIZE]; va_start( list, fmt ); g_vsnprintf(buf, SCS_HUGE_SIZE, fmt, list); va_end( list ); return scs_subscribe(c,buf); }
/** * new_loal: * @param name the name the loal will take. * * Creates an empty list of avp lists. * * Return value: a pointer to the newly created loal. **/ extern LoAL* new_loal(const gchar* name) { LoAL* new_loal_p = (LoAL*)g_slice_new(any_avp_type); if (! name) { name = "anonymous"; } #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,3,dbg_fp,"new_loal_p: %X name=%s",new_loal_p,name); #endif new_loal_p->name = scs_subscribe(avp_strings,name); new_loal_p->null.avpl = NULL; new_loal_p->null.next = &new_loal_p->null; new_loal_p->null.prev = &new_loal_p->null; new_loal_p->len = 0; return new_loal_p; }
/** * extract_avp_by_name: * @param avpl the avpl from which to try to extract the avp. * @param name the name of the avp we are looking for. * * Extracts from the avpl the next avp whose name is given; * * Return value: a pointer to extracted avp if there's one, else NULL. * **/ extern AVP* extract_avp_by_name(AVPL* avpl, gchar* name) { AVPN* curr; AVP* avp = NULL; #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,7,dbg_fp,"extract_avp_by_name: entering: %X %s",avpl,name); #endif name = scs_subscribe(avp_strings, name); for ( curr = avpl->null.next; curr->avp; curr = curr->next ) { if ( curr->avp->n == name ) { break; } } scs_unsubscribe(avp_strings, name); if( ! curr->avp ) return NULL; curr->next->prev = curr->prev; curr->prev->next = curr->next; avp = curr->avp; g_slice_free(any_avp_type,(any_avp_type*)curr); (avpl->len)--; #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl,4,dbg_fp,"avpl: %X new len: %i",avpl,avpl->len); #endif #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,5,dbg_fp,"extract_avp_by_name: got avp: %X",avp); #endif return avp; }
/** * new_avpl_loose_match: * @param name the name of the resulting avpl * @param src avpl to be matched agains an "op" avpl * @param op the "op" avpl that will be matched against the src avpl * @param copy_avps whether the avps in the resulting avpl should be copied * * creates an avp list containing any avps in src matching any avps in op * it will eventually create an empty list in none match * * Return value: a pointer to the newly created avpl containing the * matching avps. **/ extern AVPL* new_avpl_loose_match(const gchar* name, AVPL* src, AVPL* op, gboolean copy_avps) { AVPL* newavpl = new_avpl(scs_subscribe(avp_strings, name)); AVPN* co = NULL; AVPN* cs = NULL; ptrdiff_t c; AVP* m; AVP* copy; #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,3,dbg_fp,"new_avpl_loose_match: %X src=%X op=%X name='%s'",newavpl,src,op,name); #endif cs = src->null.next; co = op->null.next; while(1) { if (!co->avp) { return newavpl; } if (!cs->avp) { return newavpl; } c = ADDRDIFF(co->avp->n, cs->avp->n); if ( c > 0 ) { if (co->avp) co = co->next; } else if (c < 0) { if (cs->avp) cs = cs->next; } else { m = match_avp(cs->avp,co->avp); if(m) { if (copy_avps) { copy = avp_copy(m); if ( ! insert_avp(newavpl,copy) ) { delete_avp(copy); } } else { insert_avp(newavpl,m); } } if (cs->avp) cs = cs->next; } } #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,6,dbg_fp,"new_avpl_loose_match: done!"); #endif return NULL; }
extern void rename_avpl(AVPL* avpl, gchar* name) { scs_unsubscribe(avp_strings,avpl->name); avpl->name = scs_subscribe(avp_strings,name); }
/** * new_avpl_every_match: * @param name the name of the resulting avpl * @param src avpl to be matched agains an "op" avpl * @param op the "op" avpl that will be matched against the src avpl * @param copy_avps whether the avps in the resulting avpl should be copied * * creates an avp list containing any avps in src matching every avp in op * it will not create a list if there is not a match for every attribute in op * * Return value: a pointer to the newly created avpl containing the * matching avps. **/ extern AVPL* new_avpl_every_match(const gchar* name, AVPL* src, AVPL* op, gboolean copy_avps) { AVPL* newavpl; AVPN* co = NULL; AVPN* cs = NULL; ptrdiff_t c; AVP* m; AVP* copy; gboolean matches; #ifdef _AVP_DEBUGGING dbg_print(dbg_avpl_op,3,dbg_fp,"new_avpl_every_match: %X src=%X op=%X name='%s'",newavpl,src,op,name); #endif if (src->len == 0) return NULL; newavpl = new_avpl(scs_subscribe(avp_strings, name)); if (op->len == 0) return newavpl; matches = TRUE; cs = src->null.next; co = op->null.next; while(1) { if (!co->avp) { break; } if (!cs->avp) { break; } c = ADDRDIFF(co->avp->n,cs->avp->n); if ( c > 0 ) { delete_avpl(newavpl,TRUE); return NULL; } else if (c < 0) { cs = cs->next; if (! cs->avp ) { break; } } else { m = match_avp(cs->avp,co->avp); if(m) { matches++; cs = cs->next; co = co->next; if (copy_avps) { copy = avp_copy(m); if ( ! insert_avp(newavpl,copy) ) { delete_avp(copy); } } else { insert_avp(newavpl,m); } } else { cs = cs->next; } } } if (matches) { return newavpl; } else { delete_avpl(newavpl,TRUE); return NULL; } }