/*! \brief add an entry to the video_device table, * ignoring duplicate names. * The table is a static array of 9 elements. * The last_frame field of each entry of the table is initialized to * the current time (we need a value inside this field, on stop of the * GUI the last_frame value is not changed, to avoid checking if it is 0 we * set the initial value on current time) XXX * * PARAMETERS: * \param devices_p = pointer to the table of devices * \param device_num_p = pointer to the number of devices * \param s = name of the new device to insert * * returns 0 on success, 1 on error */ static int device_table_fill(struct video_device *devices, int *device_num_p, const char *s) { int i; struct video_device *p; /* with the current implementation, we support a maximum of 9 devices.*/ if (*device_num_p >= 9) return 0; /* more devices will be ignored */ /* ignore duplicate names */ for (i = 0; i < *device_num_p; i++) { if (!strcmp(devices[i].name, s)) return 0; } /* inserts the new video device */ p = &devices[*device_num_p]; /* XXX the string is allocated but NEVER deallocated, the good time to do that is when the module is unloaded, now we skip the problem */ p->name = ast_strdup(s); /* copy the name */ /* other fields initially NULL */ p->grabber = NULL; p->grabber_data = NULL; p->dev_buf = NULL; p->last_frame = ast_tvnow(); p->status_index = 0; (*device_num_p)++; /* one device added */ return 0; }
static char *complete_show_sorcery_object(struct ao2_container *container, struct ast_sip_cli_formatter_entry *formatter_entry, const char *word, int state) { char *result = NULL; int wordlen = strlen(word); int which = 0; struct ao2_iterator i = ao2_iterator_init(container, 0); void *object; while ((object = ao2_t_iterator_next(&i, "iterate thru endpoints table"))) { const char *id = formatter_entry->get_id(object); if (!strncasecmp(word, id, wordlen) && ++which > state) { result = ast_strdup(id); } ao2_t_ref(object, -1, "toss iterator endpoint ptr before break"); if (result) { break; } } ao2_iterator_destroy(&i); return result; }
/*! * \internal * \brief Session supplement callback on an incoming INVITE request * * If we are receiving an initial INVITE, then we will set the session's identity * based on the INVITE or configured endpoint values. If we are receiving a reinvite, * then we will potentially queue a connected line update via the \ref update_incoming_connected_line * function * * \param session The session that has received an INVITE * \param rdata The incoming INVITE */ static int caller_id_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata) { if (!session->channel) { /* * Since we have no channel this must be the initial inbound * INVITE. Set the session ID directly because the channel * has not been created yet. */ if (session->endpoint->id.trust_inbound && (!set_id_from_pai(rdata, &session->id) || !set_id_from_rpid(rdata, &session->id))) { ast_free(session->id.tag); session->id.tag = ast_strdup(session->endpoint->id.self.tag); return 0; } ast_party_id_copy(&session->id, &session->endpoint->id.self); if (!session->endpoint->id.self.number.valid) { set_id_from_from(rdata, &session->id); } } else { /* * ReINVITE or UPDATE. Check for changes to the ID and queue * a connected line update if necessary. */ update_incoming_connected_line(session, rdata); } return 0; }
static char *complete_mailbox(const char *word, int state) { struct ao2_iterator iter; int wordlen = strlen(word); int which = 0; char *ret = NULL; char *regex; const struct ast_mwi_mailbox_object *mailbox; RAII_VAR(struct ao2_container *, mailboxes, NULL, ao2_cleanup); regex = ast_alloca(2 + wordlen); sprintf(regex, "^%s", word);/* Safe */ mailboxes = ast_mwi_mailbox_get_by_regex(regex); if (!mailboxes) { return NULL; } iter = ao2_iterator_init(mailboxes, 0); for (; (mailbox = ao2_iterator_next(&iter)); ast_mwi_mailbox_unref(mailbox)) { if (++which > state) { ret = ast_strdup(ast_sorcery_object_get_id(mailbox)); ast_mwi_mailbox_unref(mailbox); break; } } ao2_iterator_destroy(&iter); return ret; }
static int privkey_file_to_str(const void *obj, const intptr_t *args, char **buf) { const struct ast_sip_transport *transport = obj; *buf = ast_strdup(transport->privkey_file); return 0; }
static int ca_list_path_to_str(const void *obj, const intptr_t *args, char **buf) { const struct ast_sip_transport *transport = obj; *buf = ast_strdup(transport->ca_list_path); return 0; }
int ast_tls_read_conf(struct ast_tls_config *tls_cfg, struct ast_tcptls_session_args *tls_desc, const char *varname, const char *value) { if (!strcasecmp(varname, "tlsenable") || !strcasecmp(varname, "sslenable")) { tls_cfg->enabled = ast_true(value) ? 1 : 0; } else if (!strcasecmp(varname, "tlscertfile") || !strcasecmp(varname, "sslcert") || !strcasecmp(varname, "tlscert")) { ast_free(tls_cfg->certfile); tls_cfg->certfile = ast_strdup(value); } else if (!strcasecmp(varname, "tlsprivatekey") || !strcasecmp(varname, "sslprivatekey")) { ast_free(tls_cfg->pvtfile); tls_cfg->pvtfile = ast_strdup(value); } else if (!strcasecmp(varname, "tlscipher") || !strcasecmp(varname, "sslcipher")) { ast_free(tls_cfg->cipher); tls_cfg->cipher = ast_strdup(value); } else if (!strcasecmp(varname, "tlscafile")) { ast_free(tls_cfg->cafile); tls_cfg->cafile = ast_strdup(value); } else if (!strcasecmp(varname, "tlscapath") || !strcasecmp(varname, "tlscadir")) { ast_free(tls_cfg->capath); tls_cfg->capath = ast_strdup(value); } else if (!strcasecmp(varname, "tlsverifyclient")) { ast_set2_flag(&tls_cfg->flags, ast_true(value), AST_SSL_VERIFY_CLIENT); } else if (!strcasecmp(varname, "tlsdontverifyserver")) { ast_set2_flag(&tls_cfg->flags, ast_true(value), AST_SSL_DONT_VERIFY_SERVER); } else if (!strcasecmp(varname, "tlsbindaddr") || !strcasecmp(varname, "sslbindaddr")) { if (ast_parse_arg(value, PARSE_ADDR, &tls_desc->local_address)) ast_log(LOG_ERROR, "Invalid %s '%s'\n", varname, value); } else if (!strcasecmp(varname, "tlsclientmethod") || !strcasecmp(varname, "sslclientmethod")) { if (!strcasecmp(value, "tlsv1")) { ast_set_flag(&tls_cfg->flags, AST_SSL_TLSV1_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_SSLV3_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_SSLV2_CLIENT); } else if (!strcasecmp(value, "sslv3")) { ast_set_flag(&tls_cfg->flags, AST_SSL_SSLV3_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_SSLV2_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_TLSV1_CLIENT); } else if (!strcasecmp(value, "sslv2")) { ast_set_flag(&tls_cfg->flags, AST_SSL_SSLV2_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_TLSV1_CLIENT); ast_clear_flag(&tls_cfg->flags, AST_SSL_SSLV3_CLIENT); } } else { return -1; } return 0; }
static int voicemail_extension_to_str(const void *obj, const intptr_t *args, char **buf) { const struct ast_sip_aor *aor = obj; *buf = ast_strdup(aor->voicemail_extension); return 0; }
static int voicemail_extension_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) { struct ast_sip_aor *aor = obj; aor->voicemail_extension = ast_strdup(var->value); return aor->voicemail_extension ? 0 : -1; }
static void *sorcery_astdb_open(const char *data) { /* We require a prefix for family string generation, or else stuff could mix together */ if (ast_strlen_zero(data)) { return NULL; } return ast_strdup(data); }
static void *sorcery_realtime_open(const char *data) { /* We require a prefix for family string generation, or else stuff could mix together */ if (ast_strlen_zero(data) || !ast_realtime_is_mapping_defined(data)) { return NULL; } return ast_strdup(data); }
static int load_column_config(const char *tmp) { char *col = NULL; char *cols = NULL, *save = NULL; char *escaped = NULL; struct ast_str *column_string = NULL; if (ast_strlen_zero(tmp)) { ast_log(LOG_WARNING, "Column names not specified. Module not loaded.\n"); return -1; } if (!(column_string = ast_str_create(1024))) { ast_log(LOG_ERROR, "Out of memory creating temporary buffer for column list for table '%s.'\n", table); return -1; } if (!(save = cols = ast_strdup(tmp))) { ast_log(LOG_ERROR, "Out of memory creating temporary buffer for column list for table '%s.'\n", table); ast_free(column_string); return -1; } while ((col = strsep(&cols, ","))) { col = ast_strip(col); escaped = sqlite3_mprintf("%q", col); if (!escaped) { ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s.'\n", col, table); ast_free(column_string); ast_free(save); return -1; } ast_str_append(&column_string, 0, "%s%s", ast_str_strlen(column_string) ? "," : "", escaped); sqlite3_free(escaped); } if (!(columns = ast_strdup(ast_str_buffer(column_string)))) { ast_log(LOG_ERROR, "Out of memory copying columns string for table '%s.'\n", table); ast_free(column_string); ast_free(save); return -1; } ast_free(column_string); ast_free(save); return 0; }
static int transport_protocol_to_str(const void *obj, const intptr_t *args, char **buf) { const struct ast_sip_transport *transport = obj; if (ARRAY_IN_BOUNDS(transport->type, transport_types)) { *buf = ast_strdup(transport_types[transport->type]); } return 0; }
void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class) { char *data = NULL; if (!ast_strlen_zero(moh_class)) { data = ast_strdup(moh_class); } stasis_app_send_command_async(control, app_control_moh_start, data); }
static int speex_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction) { struct ast_datastore *datastore = NULL; struct speex_direction_info *sdi = NULL; struct speex_info *si = NULL; char source[80]; /* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */ if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE || frame->frametype != AST_FRAME_VOICE) { return -1; } /* We are called with chan already locked */ if (!(datastore = ast_channel_datastore_find(chan, &speex_datastore, NULL))) { return -1; } si = datastore->data; sdi = (direction == AST_AUDIOHOOK_DIRECTION_READ) ? si->rx : si->tx; if (!sdi) { return -1; } if ((sdi->samples != frame->samples) || (ast_format_rate(&frame->subclass.format) != si->lastrate)) { si->lastrate = ast_format_rate(&frame->subclass.format); if (sdi->state) { speex_preprocess_state_destroy(sdi->state); } if (!(sdi->state = speex_preprocess_state_init((sdi->samples = frame->samples), si->lastrate))) { return -1; } speex_preprocess_ctl(sdi->state, SPEEX_PREPROCESS_SET_AGC, &sdi->agc); if (sdi->agc) { speex_preprocess_ctl(sdi->state, SPEEX_PREPROCESS_SET_AGC_LEVEL, &sdi->agclevel); } speex_preprocess_ctl(sdi->state, SPEEX_PREPROCESS_SET_DENOISE, &sdi->denoise); } speex_preprocess(sdi->state, frame->data.ptr, NULL); snprintf(source, sizeof(source), "%s/speex", frame->src); if (frame->mallocd & AST_MALLOCD_SRC) { ast_free((char *) frame->src); } frame->src = ast_strdup(source); frame->mallocd |= AST_MALLOCD_SRC; return 0; }
int stasis_app_control_redirect(struct stasis_app_control *control, const char *endpoint) { char *endpoint_data = ast_strdup(endpoint); if (!endpoint_data) { return -1; } stasis_app_send_command_async(control, app_control_redirect, endpoint_data, ast_free_ptr); return 0; }
int stasis_app_control_add_role(struct stasis_app_control *control, const char *role) { char *role_dup; role_dup = ast_strdup(role); if (!role_dup) { return -1; } stasis_app_send_command_async(control, app_control_add_role, role_dup, ast_free_ptr); return 0; }
/* Only call this on a parked user that hasn't had its parker_dial_string set already */ static int parked_user_set_parker_dial_string(struct parked_user *pu, struct ast_channel *parker) { char *dial_string = ast_strdupa(ast_channel_name(parker)); ast_channel_name_to_dial_string(dial_string); pu->parker_dial_string = ast_strdup(dial_string); if (!pu->parker_dial_string) { return -1; } return 0; }
static int require_client_cert_to_str(const void *obj, const intptr_t *args, char **buf) { const struct ast_sip_transport *transport = obj; RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); if (!state) { return -1; } *buf = ast_strdup(AST_YESNO(state->tls.require_client_cert)); return 0; }
/*! * \internal * \brief Set an ast_party_id name and number based on an identity header. * \param hdr From, P-Asserted-Identity, or Remote-Party-ID header on incoming message * \param[out] id The ID to set data on */ static void set_id_from_hdr(pjsip_fromto_hdr *hdr, struct ast_party_id *id) { char cid_name[AST_CHANNEL_NAME]; char cid_num[AST_CHANNEL_NAME]; pjsip_sip_uri *uri; pjsip_name_addr *id_name_addr = (pjsip_name_addr *) hdr->uri; uri = pjsip_uri_get_uri(id_name_addr); ast_copy_pj_str(cid_name, &id_name_addr->display, sizeof(cid_name)); ast_copy_pj_str(cid_num, &uri->user, sizeof(cid_num)); ast_free(id->name.str); id->name.str = ast_strdup(cid_name); if (!ast_strlen_zero(cid_name)) { id->name.valid = 1; } ast_free(id->number.str); id->number.str = ast_strdup(cid_num); if (!ast_strlen_zero(cid_num)) { id->number.valid = 1; } }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cel_config, config_flags))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) { ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); } ast_config_destroy(cfg); } else { return AST_MODULE_LOAD_DECLINE; } /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } event_sub = ast_event_subscribe(AST_EVENT_CEL, radius_log, "CEL Radius Logging", NULL, AST_EVENT_IE_END); if (!event_sub) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
static char *assign_uuid(struct ast_json *json_channel) { const char *channel_name = ast_json_string_get(ast_json_object_get(json_channel, "name")); enum hep_uuid_type uuid_type = hepv3_get_uuid_type(); char *uuid = NULL; if (!channel_name) { return NULL; } if (uuid_type == HEP_UUID_TYPE_CALL_ID) { struct ast_channel *chan = NULL; char buf[128]; if (ast_begins_with(channel_name, "PJSIP")) { chan = ast_channel_get_by_name(channel_name); if (chan && !ast_func_read(chan, "CHANNEL(pjsip,call-id)", buf, sizeof(buf))) { uuid = ast_strdup(buf); } } else if (ast_begins_with(channel_name, "SIP")) { chan = ast_channel_get_by_name(channel_name); if (chan && !ast_func_read(chan, "SIP_HEADER(call-id)", buf, sizeof(buf))) { uuid = ast_strdup(buf); } } ast_channel_cleanup(chan); } /* If we couldn't get the call-id or didn't want it, just use the channel name */ if (!uuid) { uuid = ast_strdup(channel_name); } return uuid; }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); ast_config_destroy(cfg); } else return AST_MODULE_LOAD_DECLINE; /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } if (ast_cdr_register(name, desc, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
static int localnet_to_str(const void *obj, const intptr_t *args, char **buf) { RAII_VAR(struct ast_str *, str, ast_str_create(MAX_OBJECT_FIELD), ast_free); const struct ast_sip_transport *transport = obj; RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); if (!state) { return -1; } ast_ha_join(state->localnet, &str); *buf = ast_strdup(ast_str_buffer(str)); return 0; }
char *ast_crypt(const char *key, const char *salt) { struct crypt_data data = {}; const char *crypted = crypt_r(key, salt, &data); /* Crypt may return success even if it doesn't recognize the salt. But * in those cases it always mangles the salt in some way. */ if (!crypted || !ast_begins_with(crypted, salt)) { return NULL; } return ast_strdup(crypted); }
/*! * \internal * \brief Parse and setup the stunaddr parameter. * * \param value Configuration parameter variable value. * * \retval 0 on success. * \retval -1 on error. */ static int setup_stunaddr(const char *value) { char *val; char *host_str; char *port_str; unsigned int port; struct ast_sockaddr stun_addr; if (ast_strlen_zero(value)) { /* Setting to an empty value disables STUN monitoring. */ args.monitor_enabled = 0; return 0; } val = ast_strdupa(value); if (!ast_sockaddr_split_hostport(val, &host_str, &port_str, 0) || ast_strlen_zero(host_str)) { return -1; } /* Determine STUN port */ if (ast_strlen_zero(port_str) || 1 != sscanf(port_str, "%30u", &port)) { port = STANDARD_STUN_PORT; } host_str = ast_strdup(host_str); if (!host_str) { return -1; } /* Lookup STUN address. */ memset(&stun_addr, 0, sizeof(stun_addr)); stun_addr.ss.ss_family = AF_INET; if (ast_get_ip(&stun_addr, host_str)) { ast_log(LOG_WARNING, "Unable to lookup STUN server '%s'\n", host_str); ast_free(host_str); return -1; } /* Save STUN server information. */ ast_free((char *) args.server_hostname); args.server_hostname = host_str; args.stun_port = port; /* Enable STUN monitor */ args.monitor_enabled = 1; return 0; }
static int contacts_to_str(const void *obj, const intptr_t *args, char **buf) { const struct ast_sip_aor *aor = obj; RAII_VAR(struct ast_str *, str, ast_str_create(MAX_OBJECT_FIELD), ast_free); ast_sip_for_each_contact(aor, ast_sip_contact_to_str, &str); ast_str_truncate(str, -1); *buf = ast_strdup(ast_str_buffer(str)); if (!*buf) { return -1; } return 0; }
static int create_artificial_endpoint(void) { artificial_endpoint = ast_sorcery_alloc(ast_sip_get_sorcery(), "endpoint", NULL); if (!artificial_endpoint) { return -1; } AST_VECTOR_INIT(&artificial_endpoint->inbound_auths, 1); /* Pushing a bogus value into the vector will ensure that * the proper size of the vector is returned. This value is * not actually used anywhere */ AST_VECTOR_APPEND(&artificial_endpoint->inbound_auths, ast_strdup("artificial-auth")); return 0; }
static char *complete_ulimit(struct ast_cli_args *a) { int which = 0, i; int wordlen = strlen(a->word); if (a->pos > 1) return NULL; for (i = 0; i < ARRAY_LEN(limits); i++) { if (!strncasecmp(limits[i].clicmd, a->word, wordlen)) { if (++which > a->n) return ast_strdup(limits[i].clicmd); } } return NULL; }
static int tls_method_to_str(const void *obj, const intptr_t *args, char **buf) { const struct ast_sip_transport *transport = obj; RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup); if (!state) { return -1; } if (ARRAY_IN_BOUNDS(state->tls.method, tls_method_map)) { *buf = ast_strdup(tls_method_map[state->tls.method]); } return 0; }