void destroy_evlist(void) { pres_ev_t *e1, *e2; if(EvList) { e1 = EvList->events; while(e1) { e2 = e1->next; free_pres_event(e1); e1 = e2; } shm_free(EvList); } }
int add_event(pres_ev_t* event) { pres_ev_t* ev= NULL; event_t parsed_event; str wipeer_name; char* sep; char buf[50]; int not_in_list= 0; if(EvList == NULL) { LM_ERR("'presence' modules must be loaded before this module\n"); return -1; } memset(&parsed_event, 0, sizeof(event_t)); if(event->name.s== NULL || event->name.len== 0) { LM_ERR("NULL event name\n"); return -1; } if(event->content_type.s== NULL || event->content_type.len== 0) { if (event->mandatory_body) { LM_ERR("NULL content_type param\n"); return -1; } } ev= contains_event(&event->name, &parsed_event); if(ev== NULL) { not_in_list= 1; ev= (pres_ev_t*)shm_malloc(sizeof(pres_ev_t)); if(ev== NULL) { free_event_params(parsed_event.params, PKG_MEM_TYPE); ERR_MEM(SHARE_MEM); } memset(ev, 0, sizeof(pres_ev_t)); ev->name.s= (char*)shm_malloc(event->name.len); if(ev->name.s== NULL) { free_event_params(parsed_event.params, PKG_MEM_TYPE); ERR_MEM(SHARE_MEM); } memcpy(ev->name.s, event->name.s, event->name.len); ev->name.len= event->name.len; ev->evp= shm_copy_event(&parsed_event); if(ev->evp== NULL) { LM_ERR("copying event_t structure\n"); free_event_params(parsed_event.params, PKG_MEM_TYPE); goto error; } free_event_params(parsed_event.params, PKG_MEM_TYPE); } else { free_event_params(parsed_event.params, PKG_MEM_TYPE); if(ev->content_type.s) { LM_DBG("Event already registered\n"); return 0; } } ev->content_type.s = (char*)shm_malloc(event->content_type.len); if(ev->content_type.s== NULL) { ERR_MEM(SHARE_MEM); } ev->content_type.len= event->content_type.len; memcpy(ev->content_type.s, event->content_type.s, event->content_type.len); sep= strchr(event->name.s, '.'); if(sep != NULL && strncasecmp(sep+1, "winfo", 5)== 0) { ev->type= WINFO_TYPE; wipeer_name.s= event->name.s; wipeer_name.len= sep - event->name.s; ev->wipeer= contains_event(&wipeer_name, NULL); } else { ev->type= PUBL_TYPE; wipeer_name.s= buf; memcpy(wipeer_name.s, event->name.s, event->name.len); wipeer_name.len= event->name.len; memcpy(wipeer_name.s+ wipeer_name.len, ".winfo", 6); wipeer_name.len+= 6; ev->wipeer= contains_event(&wipeer_name, NULL); } if(ev->wipeer) ev->wipeer->wipeer= ev; if(event->req_auth && ( event->get_auth_status==0 ||event->get_rules_doc== 0)) { LM_ERR("bad event structure\n"); goto error; } ev->extra_hdrs= event->extra_hdrs; ev->req_auth= event->req_auth; ev->agg_nbody= event->agg_nbody; ev->apply_auth_nbody= event->apply_auth_nbody; ev->get_auth_status= event->get_auth_status; ev->get_rules_doc= event->get_rules_doc; ev->evs_publ_handl= event->evs_publ_handl; ev->evs_subs_handl= event->evs_subs_handl; ev->mandatory_body = event->mandatory_body; ev->mandatory_timeout_notification = event->mandatory_timeout_notification; ev->etag_not_new= event->etag_not_new; ev->aux_body_processing= event->aux_body_processing; ev->aux_free_body= event->aux_free_body; ev->free_body= event->free_body; ev->build_empty_pres_info= event->build_empty_pres_info; ev->default_expires= event->default_expires; if(not_in_list) { ev->next= EvList->events; EvList->events= ev; } EvList->ev_count++; LM_DBG("succesfully added event: %.*s - len= %d\n",ev->name.len, ev->name.s, ev->name.len); /* if event 'presence' set the pointer */ if(ev->evp->parsed == EVENT_PRESENCE) *pres_event_p = ev; /* if event 'dialog' set the pointer */ if(ev->evp->parsed == EVENT_DIALOG) *dialog_event_p = ev; return 0; error: if(ev && not_in_list) { free_pres_event(ev); } return -1; }
int add_event(pres_ev_t* event) { pres_ev_t* ev= NULL; event_t parsed_event; str wipeer_name; char* sep; char buf[50]; int not_in_list= 0; memset(&parsed_event, 0, sizeof(event_t)); if(event->name.s== NULL || event->name.len== 0) { LM_ERR("NULL event name\n"); return -1; } if(event->content_type.s== NULL || event->content_type.len== 0) { LM_ERR("NULL content_type param\n"); return -1; } ev= contains_event(&event->name, &parsed_event); if(ev== NULL) { not_in_list= 1; ev= (pres_ev_t*)shm_malloc(sizeof(pres_ev_t)); if(ev== NULL) { free_event_params(parsed_event.params, PKG_MEM_TYPE); ERR_MEM(SHARE_MEM); } memset(ev, 0, sizeof(pres_ev_t)); ev->name.s= (char*)shm_malloc(event->name.len* sizeof(char)); if(ev->name.s== NULL) { free_event_params(parsed_event.params, PKG_MEM_TYPE); ERR_MEM(SHARE_MEM); } memcpy(ev->name.s, event->name.s, event->name.len); ev->name.len= event->name.len; ev->evp= shm_copy_event(&parsed_event); if(ev->evp== NULL) { LM_ERR("copying event_t structure\n"); free_event_params(parsed_event.params, PKG_MEM_TYPE); goto error; } free_event_params(parsed_event.params, PKG_MEM_TYPE); } else { free_event_params(parsed_event.params, PKG_MEM_TYPE); if(ev->content_type.s) { LM_DBG("Event already registered\n"); return 0; } } ev->content_type.s=(char*)shm_malloc(event->content_type.len* sizeof(char)) ; if(ev->content_type.s== NULL) { ERR_MEM(SHARE_MEM); } ev->content_type.len= event->content_type.len; memcpy(ev->content_type.s, event->content_type.s, event->content_type.len); sep= strchr(event->name.s, '.'); if(sep && strncmp(sep+1, "winfo", 5)== 0) { ev->type= WINFO_TYPE; wipeer_name.s= event->name.s; wipeer_name.len= sep - event->name.s; ev->wipeer= contains_event(&wipeer_name, NULL); } else { ev->type= PUBL_TYPE; wipeer_name.s= buf; memcpy(wipeer_name.s, event->name.s, event->name.len); wipeer_name.len= event->name.len; memcpy(wipeer_name.s+ wipeer_name.len, ".winfo", 6); wipeer_name.len+= 6; ev->wipeer= contains_event(&wipeer_name, NULL); } if(ev->wipeer) ev->wipeer->wipeer= ev; if(event->req_auth && ( event->get_auth_status==0 ||event->get_rules_doc== 0)) { LM_ERR("bad event structure\n"); goto error; } ev->req_auth= event->req_auth; ev->agg_nbody= event->agg_nbody; ev->apply_auth_nbody= event->apply_auth_nbody; ev->get_auth_status= event->get_auth_status; ev->get_rules_doc= event->get_rules_doc; ev->evs_publ_handl= event->evs_publ_handl; ev->etag_not_new= event->etag_not_new; ev->free_body= event->free_body; ev->default_expires= event->default_expires; if(not_in_list) { ev->next= EvList->events; EvList->events= ev; } EvList->ev_count++; LM_DBG("succesfully added event: %.*s - len= %d\n",ev->name.len, ev->name.s, ev->name.len); return 0; error: if(ev && not_in_list) { free_pres_event(ev); } return -1; }