struct stasis_app_control *control_create(struct ast_channel *channel) { RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup); int res; control = ao2_alloc(sizeof(*control), control_dtor); if (!control) { return NULL; } res = ast_cond_init(&control->wait_cond, NULL); if (res != 0) { ast_log(LOG_ERROR, "Error initializing ast_cond_t: %s\n", strerror(errno)); return NULL; } control->command_queue = ao2_container_alloc_list( AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL); if (!control->command_queue) { return NULL; } control->channel = channel; AST_LIST_HEAD_INIT(&control->add_rules); AST_LIST_HEAD_INIT(&control->remove_rules); ao2_ref(control, +1); return control; }
static void *dialed_interface_duplicate(void *data) { struct ast_dialed_interface *di = NULL; AST_LIST_HEAD(, ast_dialed_interface) *old_list; AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL; if(!(old_list = data)) { return NULL; } if(!(new_list = ast_calloc(1, sizeof(*new_list)))) { return NULL; } AST_LIST_HEAD_INIT(new_list); AST_LIST_LOCK(old_list); AST_LIST_TRAVERSE(old_list, di, list) { struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface)); if(!di2) { AST_LIST_UNLOCK(old_list); dialed_interface_destroy(new_list); return NULL; } strcpy(di2->interface, di->interface); AST_LIST_INSERT_TAIL(new_list, di2, list); } AST_LIST_UNLOCK(old_list); return new_list; }
/*! * \internal * \brief Session supplement callback on an incoming INVITE request * * Retrieve the header_datastore from the session or create one if it doesn't exist. * Create and initialize the list if needed. * Insert the headers. */ static int incoming_request(struct ast_sip_session *session, pjsip_rx_data * rdata) { pj_pool_t *pool = session->inv_session->dlg->pool; RAII_VAR(struct ast_datastore *, datastore, ast_sip_session_get_datastore(session, header_datastore.type), ao2_cleanup); if (!datastore) { if (!(datastore = ast_sip_session_alloc_datastore(&header_datastore, header_datastore.type)) || !(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list))) || ast_sip_session_add_datastore(session, datastore)) { ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n"); return 0; } AST_LIST_HEAD_INIT((struct hdr_list *) datastore->data); } insert_headers(pool, (struct hdr_list *) datastore->data, rdata->msg_info.msg); return 0; }
/*! * \internal * \brief Implements PJSIP_HEADER 'add' by inserting the specified header into thge list. * * Retrieve the header_datastore from the session or create one if it doesn't exist. * Create and initialize the list if needed. * Create the pj_strs for name and value. * Create pjsip_msg and hdr_list_entry. * Add the entry to the list. */ static int add_header(void *obj) { struct header_data *data = obj; struct ast_sip_session *session = data->channel->session; pj_pool_t *pool = session->inv_session->dlg->pool; pj_str_t pj_header_name; pj_str_t pj_header_value; struct hdr_list_entry *le; struct hdr_list *list; RAII_VAR(struct ast_datastore *, datastore, ast_sip_session_get_datastore(session, header_datastore.type), ao2_cleanup); if (!datastore) { if (!(datastore = ast_sip_session_alloc_datastore(&header_datastore, header_datastore.type)) || !(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list))) || ast_sip_session_add_datastore(session, datastore)) { ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n"); return -1; } AST_LIST_HEAD_INIT((struct hdr_list *) datastore->data); } ast_debug(1, "Adding header %s with value %s\n", data->header_name, data->header_value); pj_cstr(&pj_header_name, data->header_name); pj_cstr(&pj_header_value, data->header_value); le = pj_pool_zalloc(pool, sizeof(struct hdr_list_entry)); le->hdr = (pjsip_hdr *) pjsip_generic_string_hdr_create(pool, &pj_header_name, &pj_header_value); list = datastore->data; AST_LIST_INSERT_TAIL(list, le, nextptr); return 0; }