static void mwi_subscription_mailboxes_str(struct ao2_container *stasis_subs, struct ast_str **str) { int num = ao2_container_count(stasis_subs); struct mwi_stasis_subscription *node; struct ao2_iterator i = ao2_iterator_init(stasis_subs, 0); while ((node = ao2_iterator_next(&i))) { if (--num) { ast_str_append(str, 0, "%s,", node->mailbox); } else { ast_str_append(str, 0, "%s", node->mailbox); } ao2_ref(node, -1); } ao2_iterator_destroy(&i); }
static void mwi_to_ami(struct ast_sip_subscription *sub, struct ast_str **buf) { struct mwi_subscription *mwi_sub; RAII_VAR(struct ast_datastore *, mwi_datastore, ast_sip_subscription_get_datastore(sub, MWI_DATASTORE), ao2_cleanup); if (!mwi_datastore) { return; } mwi_sub = mwi_datastore->data; ast_str_append(buf, 0, "SubscriptionType: mwi\r\n"); ast_str_append(buf, 0, "Mailboxes: "); mwi_subscription_mailboxes_str(mwi_sub->stasis_subs, buf); ast_str_append(buf, 0, "\r\n"); }
void ast_ari_response_created(struct ast_ari_response *response, const char *url, struct ast_json *message) { RAII_VAR(struct stasis_rest_handlers *, root, get_root_handler(), ao2_cleanup); response->message = message; response->response_code = 201; response->response_text = "Created"; ast_str_append(&response->headers, 0, "Location: /%s%s\r\n", root->path_segment, url); }
int ast_sip_contact_to_str(void *object, void *arg, int flags) { struct ast_sip_contact_wrapper *wrapper = object; struct ast_str **buf = arg; ast_str_append(buf, 0, "%s,", wrapper->contact_id); return 0; }
static int cli_aor_print_body(void *obj, void *arg, int flags) { struct ast_sip_aor *aor = obj; struct ast_sip_cli_context *context = arg; RAII_VAR(struct ast_sip_cli_formatter_entry *, formatter_entry, NULL, ao2_cleanup); int indent; int flexwidth; ast_assert(context->output_buffer != NULL); // context->current_aor = aor; indent = CLI_INDENT_TO_SPACES(context->indent_level); flexwidth = CLI_LAST_TABSTOP - indent - 12; ast_str_append(&context->output_buffer, 0, "%*s: %-*.*s %12u\n", indent, "Aor", flexwidth, flexwidth, ast_sorcery_object_get_id(aor), aor->max_contacts); if (context->recurse) { context->indent_level++; formatter_entry = ast_sip_lookup_cli_formatter("contact"); if (formatter_entry) { formatter_entry->iterate(aor, formatter_entry->print_body, context); } context->indent_level--; if (context->indent_level == 0) { ast_str_append(&context->output_buffer, 0, "\n"); } } if (context->show_details || (context->show_details_only_level_0 && context->indent_level == 0)) { ast_str_append(&context->output_buffer, 0, "\n"); ast_sip_cli_print_sorcery_objectset(aor, context, 0); } return 0; }
static void celt_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str) { struct celt_attr *attr = ast_format_get_attribute_data(format); if (!attr || !attr->framesize) { return; } ast_str_append(str, 0, "a=fmtp:%u framesize=%u\r\n", payload, attr->framesize); }
struct ast_json *ast_json_ipaddr(const struct ast_sockaddr *addr, enum ast_transport transport_type) { struct ast_str *string = ast_str_alloca(64); if (!string) { return NULL; } ast_str_set(&string, 0, (ast_sockaddr_is_ipv4(addr) || ast_sockaddr_is_ipv4_mapped(addr)) ? "IPV4/" : "IPV6/"); if (transport_type) { char *transport_string = NULL; /* NOTE: None will be applied if multiple transport types are specified in transport_type */ switch(transport_type) { case AST_TRANSPORT_UDP: transport_string = "UDP"; break; case AST_TRANSPORT_TCP: transport_string = "TCP"; break; case AST_TRANSPORT_TLS: transport_string = "TLS"; break; case AST_TRANSPORT_WS: transport_string = "WS"; break; case AST_TRANSPORT_WSS: transport_string = "WSS"; break; } if (transport_string) { ast_str_append(&string, 0, "%s/", transport_string); } } ast_str_append(&string, 0, "%s", ast_sockaddr_stringify_addr(addr)); ast_str_append(&string, 0, "/%s", ast_sockaddr_stringify_port(addr)); return ast_json_string_create(ast_str_buffer(string)); }
static char *file2display(struct ast_str **buf, ssize_t len, const char *input) { const char *ptr; ast_str_reset(*buf); for (ptr = input; *ptr; ptr++) { if (*ptr == '\n') { ast_str_append(buf, len, "\\n"); } else if (*ptr == '\r') { ast_str_append(buf, len, "\\r"); } else if (*ptr == '\t') { ast_str_append(buf, len, "\\t"); } else if (*ptr < ' ' || *ptr > 125) { ast_str_append(buf, len, "\\x%hhX", *ptr); } else { ast_str_append(buf, len, "%c", *ptr); } } return ast_str_buffer(*buf); }
static void silk_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str) { struct silk_attr *attr = ast_format_get_attribute_data(format); if (!attr) { return; } if ((attr->maxbitrate > 5000) && (attr->maxbitrate < 40000)) { ast_str_append(str, 0, "a=fmtp:%u maxaveragebitrate=%u\r\n", payload, attr->maxbitrate); } if (attr->dtx) { ast_str_append(str, 0, "a=fmtp:%u usedtx=%u\r\n", payload, attr->dtx); } if (attr->fec) { ast_str_append(str, 0, "a=fmtp:%u useinbandfec=%u\r\n", payload, attr->fec); } }
static void ilbc_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str) { struct ilbc_attr *attr = ast_format_get_attribute_data(format); if (!attr) { attr = &default_ilbc_attr; } /* send mode even when 30, see issue report ASTERISK-26221 */ ast_str_append(str, 0, "a=fmtp:%u mode=%u\r\n", payload, attr->mode); }
static int ami_registrations_aor(void *obj, void *arg, int flags) { struct ast_sip_aor *aor = obj; struct ast_sip_ami *ami = arg; int *count = ami->arg; RAII_VAR(struct ast_str *, buf, ast_sip_create_ami_event("InboundRegistrationDetail", ami), ast_free); if (!buf) { return -1; } ast_sip_sorcery_object_to_ami(aor, &buf); ast_str_append(&buf, 0, "Contacts: "); ast_sip_for_each_contact(aor, sip_contact_to_str, &buf); ast_str_append(&buf, 0, "\r\n"); astman_append(ami->s, "%s\r\n", ast_str_buffer(buf)); (*count)++; return 0; }
static void cipher_to_str(char **buf, const pj_ssl_cipher *ciphers, unsigned int cipher_num) { struct ast_str *str; int idx; str = ast_str_create(128); if (!str) { *buf = NULL; return; } for (idx = 0; idx < cipher_num; ++idx) { ast_str_append(&str, 0, "%s", pj_ssl_cipher_name(ciphers[idx])); if (idx < cipher_num - 1) { ast_str_append(&str, 0, ", "); } } *buf = ast_strdup(ast_str_buffer(str)); ast_free(str); }
int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor) { int attr = 0; if (!check_colors_allowed(fgcolor)) { return -1; } check_fgcolor(&fgcolor, &attr); check_bgcolor(&bgcolor); if (ast_opt_force_black_background) { ast_str_append(str, 0, "%c[%d;%d;%dm", ESC, attr, fgcolor, COLOR_BLACK + 10); } else if (bgcolor) { ast_str_append(str, 0, "%c[%d;%d;%dm", ESC, attr, fgcolor, bgcolor + 10); } else { ast_str_append(str, 0, "%c[%d;%dm", ESC, attr, fgcolor); } return 0; }
static int format_contact_status(void *obj, void *arg, int flags) { struct ast_sip_contact_wrapper *wrapper = obj; struct ast_sip_contact *contact = wrapper->contact; struct ast_sip_ami *ami = arg; struct ast_sip_contact_status *status; struct ast_str *buf; const struct ast_sip_endpoint *endpoint = ami->arg; buf = ast_sip_create_ami_event("ContactStatusDetail", ami); if (!buf) { return -1; } status = ast_sorcery_retrieve_by_id( ast_sip_get_sorcery(), CONTACT_STATUS, ast_sorcery_object_get_id(contact)); ast_str_append(&buf, 0, "AOR: %s\r\n", wrapper->aor_id); ast_str_append(&buf, 0, "URI: %s\r\n", contact->uri); ast_str_append(&buf, 0, "Status: %s\r\n", ast_sip_get_contact_status_label(status->status)); if (status->status == UNKNOWN) { ast_str_append(&buf, 0, "RoundtripUsec: N/A\r\n"); } else { ast_str_append(&buf, 0, "RoundtripUsec: %" PRId64 "\r\n", status->rtt); } ast_str_append(&buf, 0, "EndpointName: %s\r\n", ast_sorcery_object_get_id(endpoint)); astman_append(ami->s, "%s\r\n", ast_str_buffer(buf)); ami->count++; ast_free(buf); ao2_cleanup(status); return 0; }
/*! \brief Function which adds ICE attributes to a media stream */ static void add_ice_to_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media, pj_pool_t *pool, pjmedia_sdp_media *media) { struct ast_rtp_engine_ice *ice; struct ao2_container *candidates; const char *username, *password; pj_str_t stmp; pjmedia_sdp_attr *attr; struct ao2_iterator it_candidates; struct ast_rtp_engine_ice_candidate *candidate; if (!session->endpoint->media.rtp.ice_support || !(ice = ast_rtp_instance_get_ice(session_media->rtp)) || !(candidates = ice->get_local_candidates(session_media->rtp))) { return; } if ((username = ice->get_ufrag(session_media->rtp))) { attr = pjmedia_sdp_attr_create(pool, "ice-ufrag", pj_cstr(&stmp, username)); media->attr[media->attr_count++] = attr; } if ((password = ice->get_password(session_media->rtp))) { attr = pjmedia_sdp_attr_create(pool, "ice-pwd", pj_cstr(&stmp, password)); media->attr[media->attr_count++] = attr; } it_candidates = ao2_iterator_init(candidates, 0); for (; (candidate = ao2_iterator_next(&it_candidates)); ao2_ref(candidate, -1)) { struct ast_str *attr_candidate = ast_str_create(128); ast_str_set(&attr_candidate, -1, "%s %u %s %d %s ", candidate->foundation, candidate->id, candidate->transport, candidate->priority, ast_sockaddr_stringify_addr_remote(&candidate->address)); ast_str_append(&attr_candidate, -1, "%s typ ", ast_sockaddr_stringify_port(&candidate->address)); switch (candidate->type) { case AST_RTP_ICE_CANDIDATE_TYPE_HOST: ast_str_append(&attr_candidate, -1, "host"); break; case AST_RTP_ICE_CANDIDATE_TYPE_SRFLX: ast_str_append(&attr_candidate, -1, "srflx"); break; case AST_RTP_ICE_CANDIDATE_TYPE_RELAYED: ast_str_append(&attr_candidate, -1, "relay"); break; } if (!ast_sockaddr_isnull(&candidate->relay_address)) { ast_str_append(&attr_candidate, -1, " raddr %s rport", ast_sockaddr_stringify_addr_remote(&candidate->relay_address)); ast_str_append(&attr_candidate, -1, " %s", ast_sockaddr_stringify_port(&candidate->relay_address)); } attr = pjmedia_sdp_attr_create(pool, "candidate", pj_cstr(&stmp, ast_str_buffer(attr_candidate))); media->attr[media->attr_count++] = attr; ast_free(attr_candidate); } ao2_iterator_destroy(&it_candidates); ao2_ref(candidates, -1); }
static int cli_channelstats_print_header(void *obj, void *arg, int flags) { struct ast_sip_cli_context *context = arg; ast_assert(context->output_buffer != NULL); ast_str_append(&context->output_buffer, 0, " ...........Receive......... .........Transmit..........\n" " BridgeId ChannelId ........ UpTime.. Codec. Count Lost Pct Jitter Count Lost Pct Jitter RTT....\n" " ================="); return 0; }
static int cli_print_body(void *obj, void *arg, int flags) { struct ast_sip_auth *auth = obj; struct ast_sip_cli_context *context = arg; char title[32]; ast_assert(context->output_buffer != NULL); snprintf(title, 32, "%sAuth", context->auth_direction ? context->auth_direction : ""); ast_str_append(&context->output_buffer, 0, "%*s: %s/%s\n", CLI_INDENT_TO_SPACES(context->indent_level), title, ast_sorcery_object_get_id(auth), auth->auth_user); if (context->show_details || (context->show_details_only_level_0 && context->indent_level == 0)) { ast_str_append(&context->output_buffer, 0, "\n"); ast_sip_cli_print_sorcery_objectset(auth, context, 0); } return 0; }
static void *transport_websocket_init(const struct ast_socket_io_session *session) { struct ast_websocket *ws; struct ast_str *uri = ast_str_create(128); enum ast_websocket_result result; struct ast_uri *session_uri = ast_socket_io_uri(session); struct ast_tls_config *tls_cfg = NULL; if (!uri) { ast_log(LOG_ERROR, "Unable to allocate websocket uri\n"); return NULL; } ast_str_set(&uri, 0, "%s://%s:%s/socket.io/%s/websocket/%s", ast_uri_is_secure(session_uri) ? "wss" : "ws", ast_uri_host(session_uri), ast_uri_port(session_uri), SOCKET_IO_VERSION, ast_socket_io_id(session)); if (!ast_strlen_zero(ast_uri_query(session_uri))) { ast_str_append(&uri, 0, "?%s", ast_uri_query(session_uri)); } if (ast_uri_is_secure(session_uri)) { /* The websocket client expects a copy of the TLS configuration so provide it */ tls_cfg = ast_calloc(1, sizeof(*tls_cfg)); ast_set_flag(&tls_cfg->flags, AST_SSL_DONT_VERIFY_SERVER); } ws = ast_websocket_client_create( ast_str_buffer(uri), "socket.io", tls_cfg, &result); ast_free(uri); if (ws) { struct protoent *p; p = getprotobyname("tcp"); if (p) { int arg = 1; if (setsockopt(ast_websocket_fd(ws), p->p_proto, TCP_NODELAY, (char *) &arg, sizeof(arg) ) < 0) { ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno)); ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n"); } } ast_websocket_set_nonblock(ws); } return ws; }
static int format_ami_aor_handler(void *obj, void *arg, int flags) { struct ast_sip_aor *aor = obj; struct ast_sip_ami *ami = arg; const struct ast_sip_endpoint *endpoint = ami->arg; struct ast_str *buf; struct ao2_container *contacts; int total_contacts; int num_permanent; buf = ast_sip_create_ami_event("AorDetail", ami); if (!buf) { return -1; } contacts = ast_sip_location_retrieve_aor_contacts(aor); if (!contacts) { ast_free(buf); return -1; } sip_aor_to_ami(aor, &buf); total_contacts = ao2_container_count(contacts); num_permanent = aor->permanent_contacts ? ao2_container_count(aor->permanent_contacts) : 0; ast_str_append(&buf, 0, "TotalContacts: %d\r\n", total_contacts); ast_str_append(&buf, 0, "ContactsRegistered: %d\r\n", total_contacts - num_permanent); ast_str_append(&buf, 0, "EndpointName: %s\r\n", ast_sorcery_object_get_id(endpoint)); astman_append(ami->s, "%s\r\n", ast_str_buffer(buf)); ami->count++; ast_free(buf); ao2_ref(contacts, -1); return 0; }
static int cli_contact_print_header(void *obj, void *arg, int flags) { struct ast_sip_cli_context *context = arg; int indent = CLI_INDENT_TO_SPACES(context->indent_level); int filler = CLI_LAST_TABSTOP - indent - 23; ast_assert(context->output_buffer != NULL); ast_str_append(&context->output_buffer, 0, "%*s: <Aor/ContactUri%*.*s> <Hash....> <Status> <RTT(ms)..>\n", indent, "Contact", filler, filler, CLI_HEADER_FILLER); return 0; }
static int cli_channel_print_header(void *obj, void *arg, int flags) { struct ast_sip_cli_context *context = arg; int indent = CLI_INDENT_TO_SPACES(context->indent_level); int filler = CLI_LAST_TABSTOP - indent - 13; ast_assert(context->output_buffer != NULL); ast_str_append(&context->output_buffer, 0, "%*s: <ChannelId%*.*s> <State.....> <Time.....>\n", indent, "Channel", filler, filler, CLI_HEADER_FILLER); if (context->recurse) { context->indent_level++; indent = CLI_INDENT_TO_SPACES(context->indent_level); filler = CLI_LAST_TABSTOP - indent - 38; ast_str_append(&context->output_buffer, 0, "%*s: <DialedExten%*.*s> CLCID: <ConnectedLineCID.......>\n", indent, "Exten", filler, filler, CLI_HEADER_FILLER); context->indent_level--; } return 0; }
static int cli_print_header(void *obj, void *arg, int flags) { struct ast_sip_cli_context *context = arg; int indent = CLI_INDENT_TO_SPACES(context->indent_level); int filler = CLI_MAX_WIDTH - indent - 20; ast_assert(context->output_buffer != NULL); ast_str_append(&context->output_buffer, 0, "%*s: <AuthId/UserName%*.*s>\n", indent, "I/OAuth", filler, filler, CLI_HEADER_FILLER); return 0; }
/*! \internal \brief convert multi object blob to ami string */ static struct ast_str *multi_object_blob_to_ami(void *obj) { struct ast_str *ami_str=ast_str_create(1024); struct ast_str *ami_snapshot; const struct ast_multi_object_blob *multi = obj; enum stasis_user_multi_object_snapshot_type type; int i; if (!ami_str) { return NULL; } if (!multi) { ast_free(ami_str); return NULL; } for (type = 0; type < STASIS_UMOS_MAX; ++type) { for (i = 0; i < AST_VECTOR_SIZE(&multi->snapshots[type]); ++i) { char *name = ""; void *snapshot = AST_VECTOR_GET(&multi->snapshots[type], i); ami_snapshot = NULL; if (i > 0) { ast_asprintf(&name, "%d", i + 1); } switch (type) { case STASIS_UMOS_CHANNEL: ami_snapshot = ast_manager_build_channel_state_string_prefix(snapshot, name); break; case STASIS_UMOS_BRIDGE: ami_snapshot = ast_manager_build_bridge_state_string_prefix(snapshot, name); break; case STASIS_UMOS_ENDPOINT: /* currently not sending endpoint snapshots to AMI */ break; } if (ami_snapshot) { ast_str_append(&ami_str, 0, "%s", ast_str_buffer(ami_snapshot)); ast_free(ami_snapshot); } } } return ami_str; }
static int cli_unid_print_header(void *obj, void *arg, int flags) { struct ast_sip_cli_context *context = arg; RAII_VAR(struct ast_sip_cli_formatter_entry *, formatter_entry, NULL, ao2_cleanup); int indent = CLI_INDENT_TO_SPACES(context->indent_level); int filler = CLI_LAST_TABSTOP - indent - 7; ast_assert(context->output_buffer != NULL); ast_str_append(&context->output_buffer, 0, "%*s: <IP Address%*.*s> <Count> <Age(sec)>\n", indent, "Request", filler, filler, CLI_HEADER_FILLER); return 0; }
static int pgsql_reconnect(const char *database) { char my_database[50]; ast_copy_string(my_database, S_OR(database, dbname), sizeof(my_database)); /* mutex lock should have been locked before calling this function. */ if (pgsqlConn && PQstatus(pgsqlConn) != CONNECTION_OK) { PQfinish(pgsqlConn); pgsqlConn = NULL; } /* DB password can legitimately be 0-length */ if ((!pgsqlConn) && (!ast_strlen_zero(dbhost) || !ast_strlen_zero(dbsock)) && !ast_strlen_zero(dbuser) && !ast_strlen_zero(my_database)) { struct ast_str *connInfo = ast_str_create(32); ast_str_set(&connInfo, 0, "host=%s port=%d dbname=%s user=%s", dbhost, dbport, my_database, dbuser); if (!ast_strlen_zero(dbpass)) ast_str_append(&connInfo, 0, " password=%s", dbpass); ast_debug(1, "%u connInfo=%s\n", (unsigned int)connInfo->len, connInfo->str); pgsqlConn = PQconnectdb(connInfo->str); ast_debug(1, "%u connInfo=%s\n", (unsigned int)connInfo->len, connInfo->str); ast_free(connInfo); connInfo = NULL; ast_debug(1, "pgsqlConn=%p\n", pgsqlConn); if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) { ast_debug(1, "PostgreSQL RealTime: Successfully connected to database.\n"); connect_time = time(NULL); return 1; } else { ast_log(LOG_ERROR, "PostgreSQL RealTime: Failed to connect database %s on %s: %s\n", dbname, dbhost, PQresultErrorMessage(NULL)); return 0; } } else { ast_debug(1, "PostgreSQL RealTime: One or more of the parameters in the config does not pass our validity checks.\n"); return 1; } }
struct ast_str *ast_manager_build_bridge_state_string_prefix( const struct ast_bridge_snapshot *snapshot, const char *prefix) { struct ast_str *out = ast_str_create(128); int res; if (!out) { return NULL; } res = ast_str_set(&out, 0, "%sBridgeUniqueid: %s\r\n" "%sBridgeType: %s\r\n" "%sBridgeTechnology: %s\r\n" "%sBridgeCreator: %s\r\n" "%sBridgeName: %s\r\n" "%sBridgeNumChannels: %u\r\n" "%sBridgeVideoSourceMode: %s\r\n", prefix, snapshot->uniqueid, prefix, snapshot->subclass, prefix, snapshot->technology, prefix, ast_strlen_zero(snapshot->creator) ? "<unknown>": snapshot->creator, prefix, ast_strlen_zero(snapshot->name) ? "<unknown>": snapshot->name, prefix, snapshot->num_channels, prefix, ast_bridge_video_mode_to_string(snapshot->video_mode)); if (!res) { ast_free(out); return NULL; } if (snapshot->video_mode != AST_BRIDGE_VIDEO_MODE_NONE && !ast_strlen_zero(snapshot->video_source_id)) { res = ast_str_append(&out, 0, "%sBridgeVideoSource: %s\r\n", prefix, snapshot->video_source_id); if (!res) { ast_free(out); return NULL; } } return out; }
static void ilbc_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str) { struct ilbc_attr *attr = ast_format_get_attribute_data(format); if (!attr) { attr = &default_ilbc_attr; } /* When the VoIP/SIP client Zoiper calls Asterisk and its * iLBC 20 is disabled but iLBC 30 enabled, Zoiper still * falls back to iLBC 20, when there is no mode=30 in the * answer. Consequently, Zoiper defaults to iLBC 20. To * make that client happy, Asterisk sends mode always. * tested in June 2016, Zoiper Premium 1.13.2 for iPhone */ /* if (attr->mode != 30) */ { ast_str_append(str, 0, "a=fmtp:%u mode=%u\r\n", payload, attr->mode); } }
void ast_ari_recordings_get_stored_file(struct ast_tcptls_session_instance *ser, struct ast_variable *headers, struct ast_ari_recordings_get_stored_file_args *args, struct ast_ari_response *response) { RAII_VAR(struct stasis_app_stored_recording *, recording, stasis_app_stored_recording_find_by_name(args->recording_name), ao2_cleanup); static const char *format_type_names[AST_MEDIA_TYPE_TEXT + 1] = { [AST_MEDIA_TYPE_UNKNOWN] = "binary", [AST_MEDIA_TYPE_AUDIO] = "audio", [AST_MEDIA_TYPE_VIDEO] = "video", [AST_MEDIA_TYPE_IMAGE] = "image", [AST_MEDIA_TYPE_TEXT] = "text", }; struct ast_format *format; response->message = ast_json_null(); if (!recording) { ast_ari_response_error(response, 404, "Not Found", "Recording not found"); return; } format = ast_get_format_for_file_ext(stasis_app_stored_recording_get_extension(recording)); if (!format) { ast_ari_response_error(response, 500, "Internal Server Error", "Format specified by recording not available or loaded"); return; } response->fd = open(stasis_app_stored_recording_get_filename(recording), O_RDONLY); if (response->fd < 0) { ast_ari_response_error(response, 403, "Forbidden", "Recording could not be opened"); return; } ast_str_append(&response->headers, 0, "Content-Type: %s/%s\r\n", format_type_names[ast_format_get_type(format)], stasis_app_stored_recording_get_extension(recording)); ast_ari_response_ok(response, ast_json_null()); }
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 build_path_data(pjsip_rx_data *rdata, struct ast_str **path_str) { pjsip_generic_string_hdr *path_hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &path_hdr_name, NULL); if (!path_hdr) { return 0; } *path_str = ast_str_create(64); if (!path_str) { return -1; } ast_str_set(path_str, 0, "%.*s", (int)path_hdr->hvalue.slen, path_hdr->hvalue.ptr); while ((path_hdr = (pjsip_generic_string_hdr *) pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &path_hdr_name, path_hdr->next))) { ast_str_append(path_str, 0, ",%.*s", (int)path_hdr->hvalue.slen, path_hdr->hvalue.ptr); } return 0; }