int i_config_register () { subscriber_t * new_sub; int randnum = 49152; while (i_subscriber_find_by_port (randnum)) { double s = (double)rand () / RAND_MAX; randnum = (16384 * s) + 49152; } new_sub = new_subscriber (randnum); subscriber_list_add (RD.subscribers, new_sub); return randnum; }
/*db_load: if this is a db_load then we don't write to db - as it will be an unecessary rewrite*/ int add_subscriber(impurecord_t* urec, subscriber_data_t* subscriber_data, reg_subscriber** _reg_subscriber, int db_load) { reg_subscriber *s; LM_DBG("Adding reg subscription to IMPU record"); if (!urec) { LM_ERR("no presentity impu record provided\n"); return 0; } s = new_subscriber(subscriber_data); if (!s) return -1; LM_DBG("Adding new subscription to IMPU record list"); s->next = 0; s->prev = urec->stail; if (urec->stail) urec->stail->next = s; urec->stail = s; if (!urec->shead) urec->shead = s; *_reg_subscriber = s; /*DB?*/ if(!db_load && db_mode == WRITE_THROUGH) { if(db_insert_subscriber(urec, s) != 0) { LM_ERR("Failed to insert subscriber into DB subscriber [%.*s] to IMPU [%.*s]...continuing but db will be out of sync!\n", s->presentity_uri.len, s->presentity_uri.s, urec->public_identity.len, urec->public_identity.s); goto done; } if(db_link_subscriber_to_impu(urec, s) !=0) { LM_ERR("Failed to update DB linking subscriber [%.*s] to IMPU [%.*s]...continuing but db will be out of sync!\n", s->presentity_uri.len, s->presentity_uri.s, urec->public_identity.len, urec->public_identity.s); } } done: return 0; }
int add_subscriber(impurecord_t* urec, str *watcher_uri, str *watcher_contact, subscriber_data_t* subscriber_data, reg_subscriber** _reg_subscriber) { LM_DBG("Adding reg subscription to IMPU record"); if (!urec) { LM_ERR("no presentity impu record provided\n"); return 0; } reg_subscriber *s = new_subscriber(&urec->public_identity, watcher_uri, watcher_contact, subscriber_data); if (!s) return 1; LM_DBG("Adding new subscription to IMPU record list"); s->next = 0; s->prev = urec->stail; if (urec->stail) urec->stail->next = s; urec->stail = s; if (!urec->shead) urec->shead = s; *_reg_subscriber = s; return 0; }
int i_config_register_port (int port) { subscriber_t * new_sub = new_subscriber (port); subscriber_list_add (RD.subscribers, new_sub); return 0; }