static int w_set_dlg_profile(struct sip_msg *msg, char *profile, char *value) { pv_elem_t *pve; str val_s; pve = (pv_elem_t *)value; if (((struct dlg_profile_table*)profile)->has_value) { if ( pve==NULL || pv_printf_s(msg, pve, &val_s)!=0 || val_s.len == 0 || val_s.s == NULL) { LM_WARN("cannot get string for value\n"); return -1; } if ( set_dlg_profile( msg, &val_s, (struct dlg_profile_table*)profile) < 0 ) { LM_ERR("failed to set profile\n"); return -1; } } else { if ( set_dlg_profile( msg, NULL, (struct dlg_profile_table*)profile) < 0 ) { LM_ERR("failed to set profile\n"); return -1; } } return 1; }
static int w_set_dlg_profile(struct sip_msg *msg, char *profile, char *value) { struct dlg_cell *dlg; pv_elem_t *pve = (pv_elem_t *)value; str val_s; if ( (dlg=get_current_dialog())==NULL ) { LM_CRIT("BUG - setting profile from script, but no dialog found\n"); return -1; } if (((struct dlg_profile_table*)profile)->has_value) { if ( pve==NULL || pv_printf_s(msg, pve, &val_s)!=0 || val_s.len == 0 || val_s.s == NULL) { LM_WARN("cannot get string for value\n"); return -1; } if ( set_dlg_profile( dlg, &val_s, (struct dlg_profile_table*)profile, 0) < 0 ) { LM_ERR("failed to set profile\n"); return -1; } } else { if ( set_dlg_profile( dlg, NULL, (struct dlg_profile_table*)profile, 0) < 0 ) { LM_ERR("failed to set profile\n"); return -1; } } return 1; }
static void read_dialog_profiles(char *b, int l, struct dlg_cell *dlg,int double_check) { struct dlg_profile_table *profile; struct dlg_profile_link *it; str name, val; char *end; char *p; char bk; end = b + l; p = b; current_dlg_pointer = dlg; do { /* read a new pair from input string */ p = read_pair( p, end, &name, &val); if (p==NULL) break; LM_DBG("new profile found <%.*s>=<%.*s>\n",name.len,name.s,val.len,val.s); if (double_check) { for (it=dlg->profile_links;it;it=it->next) { if (it->profile->name.len == name.len && memcmp(it->profile->name.s,name.s,name.len) == 0) { LM_DBG("Profile is already linked into the dlg\n"); goto next; } } } /* add to the profile */ profile = search_dlg_profile( &name ); if (profile==NULL) { LM_DBG("profile <%.*s> does not exist now, creating it\n",name.len,name.s); /* create a new one */ bk = name.s[name.len]; name.s[name.len] = 0; if (add_profile_definitions(name.s, (val.len && val.s)?1:0 ) != 0) { LM_ERR("failed to add dialog profile <%.*s>\n", name.len, name.s); name.s[name.len] = bk; continue; } name.s[name.len] = bk; /* double check the created profile */ profile = search_dlg_profile(&name); if (profile == NULL) { LM_CRIT("BUG - cannot find just added dialog profile <%.*s>\n", name.len, name.s); continue; } } if (set_dlg_profile( NULL, profile->has_value?&val:NULL, profile) < 0 ) LM_ERR("failed to add to profile, skipping....\n"); next: ; } while(p!=end); current_dlg_pointer = NULL; }