/* * Unregister a codec factory. */ PJ_DEF(pj_status_t) pjmedia_codec_mgr_unregister_factory( pjmedia_codec_mgr *mgr, pjmedia_codec_factory *factory) { unsigned i; PJ_ASSERT_RETURN(mgr && factory, PJ_EINVAL); /* Factory must be registered. */ PJ_ASSERT_RETURN(pj_list_find_node(&mgr->factory_list, factory)==factory, PJ_ENOTFOUND); /* Erase factory from the factory list */ pj_list_erase(factory); /* Remove all supported codecs from the codec manager that were created * by the specified factory. */ for (i=0; i<mgr->codec_cnt; ) { if (mgr->codec_desc[i].factory == factory) { pj_array_erase(mgr->codec_desc, sizeof(mgr->codec_desc[0]), mgr->codec_cnt, i); --mgr->codec_cnt; } else { ++i; } } return PJ_SUCCESS; }
/* * Register new module to the endpoint. * The endpoint will then call the load and start function in the module to * properly initialize the module, and assign a unique module ID for the * module. */ PJ_DEF(pj_status_t) pjsip_endpt_register_module( pjsip_endpoint *endpt, pjsip_module *mod ) { pj_status_t status = PJ_SUCCESS; pjsip_module *m; unsigned i; pj_rwmutex_lock_write(endpt->mod_mutex); /* Make sure that this module has not been registered. */ PJ_ASSERT_ON_FAIL( pj_list_find_node(&endpt->module_list, mod) == NULL, {status = PJ_EEXISTS; goto on_return;});
pjmedia_converter_mgr_unregister_factory(pjmedia_converter_mgr *mgr, pjmedia_converter_factory *f, pj_bool_t destroy) { if (!mgr) mgr = pjmedia_converter_mgr_instance(); PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL); PJ_ASSERT_RETURN(pj_list_find_node(&mgr->factory_list, f), PJ_ENOTFOUND); pj_list_erase(f); if (destroy) (*f->op->destroy_factory)(f); return PJ_SUCCESS; }
/* * Unregister a codec factory. */ PJ_DEF(pj_status_t) pjmedia_codec_mgr_unregister_factory( pjmedia_codec_mgr *mgr, pjmedia_codec_factory *factory) { unsigned i; PJ_ASSERT_RETURN(mgr && factory, PJ_EINVAL); pj_mutex_lock(mgr->mutex); /* Factory must be registered. */ if (pj_list_find_node(&mgr->factory_list, factory) != factory) { pj_mutex_unlock(mgr->mutex); return PJ_ENOTFOUND; } /* Erase factory from the factory list */ pj_list_erase(factory); /* Remove all supported codecs from the codec manager that were created * by the specified factory. */ for (i=0; i<mgr->codec_cnt; ) { if (mgr->codec_desc[i].factory == factory) { /* Release pool of codec default param */ if (mgr->codec_desc[i].param) { pj_assert(mgr->codec_desc[i].param->pool); pj_pool_release(mgr->codec_desc[i].param->pool); } /* Remove the codec from array of codec descriptions */ pj_array_erase(mgr->codec_desc, sizeof(mgr->codec_desc[0]), mgr->codec_cnt, i); --mgr->codec_cnt; } else { ++i; } } pj_mutex_unlock(mgr->mutex); return PJ_SUCCESS; }
pjmedia_converter_mgr_register_factory(pjmedia_converter_mgr *mgr, pjmedia_converter_factory *factory) { pjmedia_converter_factory *pf; if (!mgr) mgr = pjmedia_converter_mgr_instance(); PJ_ASSERT_RETURN(mgr != NULL, PJ_EINVAL); PJ_ASSERT_RETURN(!pj_list_find_node(&mgr->factory_list, factory), PJ_EEXISTS); pf = mgr->factory_list.next; while (pf != &mgr->factory_list) { if (pf->priority > factory->priority) break; pf = pf->next; } pj_list_insert_before(pf, factory); return PJ_SUCCESS; }
pjsip_multipart_get_next_part(const pjsip_msg_body *mp, pjsip_multipart_part *part) { struct multipart_data *m_data; /* Must specify mandatory params */ PJ_ASSERT_RETURN(mp && part, NULL); /* mp must really point to an actual multipart msg body */ PJ_ASSERT_RETURN(mp->print_body==&multipart_print_body, NULL); m_data = (struct multipart_data*)mp->data; /* the part parameter must be really member of the list */ PJ_ASSERT_RETURN(pj_list_find_node(&m_data->part_head, part) != NULL, NULL); if (part->next == &m_data->part_head) return NULL; return part->next; }
int list_test() { list_node nodes[4]; // must be even number of nodes list_node list; list_node list2; list_node *p; int i; // don't change to unsigned! // // Test insert_before(). // list.value = (unsigned)-1; pj_list_init(&list); for (i=0; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i) { nodes[i].value = i; pj_list_insert_before(&list, &nodes[i]); } // check. for (i=0, p=list.next; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i, p=p->next) { pj_assert(p->value == i); if (p->value != i) { return -1; } } // // Test insert_after() // pj_list_init(&list); for (i=PJ_SIGNED_ARRAY_SIZE(nodes)-1; i>=0; --i) { pj_list_insert_after(&list, &nodes[i]); } // check. for (i=0, p=list.next; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i, p=p->next) { pj_assert(p->value == i); if (p->value != i) { return -1; } } // // Test merge_last() // // Init lists pj_list_init(&list); pj_list_init(&list2); for (i=0; i<PJ_SIGNED_ARRAY_SIZE(nodes)/2; ++i) { pj_list_insert_before(&list, &nodes[i]); } for (i=PJ_SIGNED_ARRAY_SIZE(nodes)/2; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i) { pj_list_insert_before(&list2, &nodes[i]); } // merge pj_list_merge_last(&list, &list2); // check. for (i=0, p=list.next; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i, p=p->next) { pj_assert(p->value == i); if (p->value != i) { return -1; } } // check list is empty pj_assert( pj_list_empty(&list2) ); if (!pj_list_empty(&list2)) { return -1; } // // Check merge_first() // pj_list_init(&list); pj_list_init(&list2); for (i=0; i<PJ_SIGNED_ARRAY_SIZE(nodes)/2; ++i) { pj_list_insert_before(&list, &nodes[i]); } for (i=PJ_SIGNED_ARRAY_SIZE(nodes)/2; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i) { pj_list_insert_before(&list2, &nodes[i]); } // merge pj_list_merge_first(&list2, &list); // check (list2). for (i=0, p=list2.next; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i, p=p->next) { pj_assert(p->value == i); if (p->value != i) { return -1; } } // check list is empty pj_assert( pj_list_empty(&list) ); if (!pj_list_empty(&list)) { return -1; } // // Test insert_nodes_before() // // init list pj_list_init(&list); for (i=0; i<PJ_SIGNED_ARRAY_SIZE(nodes)/2; ++i) { pj_list_insert_before(&list, &nodes[i]); } // chain remaining nodes pj_list_init(&nodes[PJ_SIGNED_ARRAY_SIZE(nodes)/2]); for (i=PJ_SIGNED_ARRAY_SIZE(nodes)/2+1; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i) { pj_list_insert_before(&nodes[PJ_SIGNED_ARRAY_SIZE(nodes)/2], &nodes[i]); } // insert nodes pj_list_insert_nodes_before(&list, &nodes[PJ_SIGNED_ARRAY_SIZE(nodes)/2]); // check for (i=0, p=list.next; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i, p=p->next) { pj_assert(p->value == i); if (p->value != i) { return -1; } } // erase test. pj_list_init(&list); for (i=0; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i) { nodes[i].value = i; pj_list_insert_before(&list, &nodes[i]); } for (i=PJ_SIGNED_ARRAY_SIZE(nodes)-1; i>=0; --i) { int j; pj_list_erase(&nodes[i]); for (j=0, p=list.next; j<i; ++j, p=p->next) { pj_assert(p->value == j); if (p->value != j) { return -1; } } } // find and search pj_list_init(&list); for (i=0; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i) { nodes[i].value = i; pj_list_insert_before(&list, &nodes[i]); } for (i=0; i<PJ_SIGNED_ARRAY_SIZE(nodes); ++i) { p = (list_node*) pj_list_find_node(&list, &nodes[i]); pj_assert( p == &nodes[i] ); if (p != &nodes[i]) { return -1; } p = (list_node*) pj_list_search(&list, (void*)(pj_ssize_t)i, &compare_node); pj_assert( p == &nodes[i] ); if (p != &nodes[i]) { return -1; } } return 0; }
static void cpool_release_pool( pj_pool_factory *pf, pj_pool_t *pool) { pj_caching_pool *cp = (pj_caching_pool*)pf; unsigned pool_capacity; unsigned i; PJ_CHECK_STACK(); PJ_ASSERT_ON_FAIL(pf && pool, return); pj_lock_acquire(cp->lock); #if PJ_SAFE_POOL /* Make sure pool is still in our used list */ if (pj_list_find_node(&cp->used_list, pool) != pool) { pj_assert(!"Attempt to destroy pool that has been destroyed before"); return; } #endif /* Erase from the used list. */ pj_list_erase(pool); /* Decrement used count. */ --cp->used_count; pool_capacity = pj_pool_get_capacity(pool); /* Destroy the pool if the size is greater than our size or if the total * capacity in our recycle list (plus the size of the pool) exceeds * maximum capacity. . */ if (pool_capacity > pool_sizes[PJ_CACHING_POOL_ARRAY_SIZE-1] || cp->capacity + pool_capacity > cp->max_capacity) { pj_pool_destroy_int(pool); pj_lock_release(cp->lock); return; } /* Reset pool. */ PJ_LOG(6, (pool->obj_name, "recycle(): cap=%d, used=%d(%d%%)", pool_capacity, pj_pool_get_used_size(pool), pj_pool_get_used_size(pool)*100/pool_capacity)); pj_pool_reset(pool); pool_capacity = pj_pool_get_capacity(pool); /* * Otherwise put the pool in our recycle list. */ i = (unsigned) (unsigned long) pool->factory_data; pj_assert(i<PJ_CACHING_POOL_ARRAY_SIZE); if (i >= PJ_CACHING_POOL_ARRAY_SIZE ) { /* Something has gone wrong with the pool. */ pj_pool_destroy_int(pool); pj_lock_release(cp->lock); return; } pj_list_insert_after(&cp->free_list[i], pool); cp->capacity += pool_capacity; pj_lock_release(cp->lock); }
// // Find a node. // const_iterator find(List_Node *node) const { List_Node *n = pj_list_find_node(&root_, node); return n ? const_iterator(n) : end(); }
/* * Send NOTIFY. */ PJ_DEF(pj_status_t) pjsua_pres_notify( pjsua_acc_id acc_id, pjsua_srv_pres *srv_pres, pjsip_evsub_state ev_state, const pj_str_t *state_str, const pj_str_t *reason, pj_bool_t with_body, const pjsua_msg_data *msg_data) { pjsua_acc *acc; pjsip_pres_status pres_status; pjsua_buddy_id buddy_id; pjsip_tx_data *tdata; pj_status_t status; /* Check parameters */ PJ_ASSERT_RETURN(acc_id!=-1 && srv_pres, PJ_EINVAL); /* Check that account ID is valid */ PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc), PJ_EINVAL); /* Check that account is valid */ PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP); PJSUA_LOCK(); acc = &pjsua_var.acc[acc_id]; /* Check that the server presence subscription is still valid */ if (pj_list_find_node(&acc->pres_srv_list, srv_pres) == NULL) { /* Subscription has been terminated */ PJSUA_UNLOCK(); return PJ_EINVALIDOP; } /* Set our online status: */ pj_bzero(&pres_status, sizeof(pres_status)); pres_status.info_cnt = 1; pres_status.info[0].basic_open = acc->online_status; pres_status.info[0].id = acc->cfg.pidf_tuple_id; //Both pjsua_var.local_uri and pjsua_var.contact_uri are enclosed in "<" and ">" //causing XML parsing to fail. //pres_status.info[0].contact = pjsua_var.local_uri; /* add RPID information */ pj_memcpy(&pres_status.info[0].rpid, &acc->rpid, sizeof(pjrpid_element)); pjsip_pres_set_status(srv_pres->sub, &pres_status); /* Check expires value. If it's zero, send our presense state but * set subscription state to TERMINATED. */ if (srv_pres->expires == 0) ev_state = PJSIP_EVSUB_STATE_TERMINATED; /* Create and send the NOTIFY to active subscription: */ status = pjsip_pres_notify(srv_pres->sub, ev_state, state_str, reason, &tdata); if (status == PJ_SUCCESS) { /* Force removal of message body if msg_body==FALSE */ if (!with_body) { tdata->msg->body = NULL; } pjsua_process_msg_data(tdata, msg_data); status = pjsip_pres_send_request( srv_pres->sub, tdata); } if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Unable to create/send NOTIFY", status); pj_list_erase(srv_pres); pjsip_pres_terminate(srv_pres->sub, PJ_FALSE); PJSUA_UNLOCK(); return status; } /* Subscribe to buddy's presence if we're not subscribed */ buddy_id = pjsua_find_buddy(srv_pres->dlg->remote.info->uri); if (buddy_id != PJSUA_INVALID_ID) { pjsua_buddy *b = &pjsua_var.buddy[buddy_id]; if (b->monitor && b->sub == NULL) { PJ_LOG(4,(THIS_FILE, "Received SUBSCRIBE from buddy %d, " "activating outgoing subscription", buddy_id)); subscribe_buddy_presence(buddy_id); } } PJSUA_UNLOCK(); return PJ_SUCCESS; }