这篇教程C++ switch_str_nil函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中switch_str_nil函数的典型用法代码示例。如果您正苦于以下问题:C++ switch_str_nil函数的具体用法?C++ switch_str_nil怎么用?C++ switch_str_nil使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了switch_str_nil函数的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: SWITCH_DECLARESWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt, char **err){#ifdef SWITCH_HAVE_ODBC SQLHSTMT stmt = NULL; int result; char *err_str = NULL; if (!db_is_up(handle)) { goto error; } if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) { goto error; } if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) { goto error; } result = SQLExecute(stmt); if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO && result != SQL_NO_DATA) { goto error; } if (rstmt) { *rstmt = stmt; } else { SQLFreeHandle(SQL_HANDLE_STMT, stmt); } return SWITCH_ODBC_SUCCESS; error: if (stmt) { err_str = switch_odbc_handle_get_error(handle, stmt); } if (err_str) { if (!switch_stristr("already exists", err_str) && !switch_stristr("duplicate key name", err_str)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]/n[%s]/n", sql, switch_str_nil(err_str)); } if (err) { *err = err_str; } else { free(err_str); } } if (rstmt) { *rstmt = stmt; } else if (stmt) { SQLFreeHandle(SQL_HANDLE_STMT, stmt); }#endif return SWITCH_ODBC_FAIL;}
开发者ID:gujun,项目名称:sscore,代码行数:59,
示例2: eventpipe_events_on_dtmfvoid eventpipe_events_on_dtmf(switch_core_session_t *session, switch_event_t *event) { char args[8192]; const char *dtmf_digit = switch_str_nil(switch_event_get_header(event, "dtmf-digit")); switch_channel_t *channel = switch_core_session_get_channel(session); const char *hangup_on_star = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_hangup_on_star")); const char *conf_room = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_room")); const char *conf_member_id = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_member_id")); /* handle conference kick if channel is in conference and digit '*' was pressed */ if ((!strcmp(hangup_on_star, "true")) && (!strcmp(dtmf_digit, "*")) && (!zstr(conf_room)) && (!zstr(conf_member_id))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Conference, dtmf '*' pressed, kick member %s from room %s/n", conf_member_id, conf_room); switch_snprintf(args, sizeof(args), "%s kick %s", conf_room, conf_member_id); eventpipe_execute_api(session, "conference", args); }}
开发者ID:tamiel,项目名称:mod_eventpipe,代码行数:17,
示例3: eventpipe_execute_api/* Api helper */switch_status_t eventpipe_execute_api(switch_core_session_t *session, char *cmd, char *args) { switch_status_t status; switch_stream_handle_t stream = { 0 }; SWITCH_STANDARD_STREAM(stream); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "api: cmd %s, args %s/n", cmd, switch_str_nil(args)); status = switch_api_execute(cmd, args, session, &stream); if (status != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "api: %s(%s) failed/n", cmd, switch_str_nil(args)); } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "api: %s(%s) %s/n", cmd, switch_str_nil(args), (char *) stream.data); } free(stream.data); return status;}
开发者ID:tamiel,项目名称:mod_eventpipe,代码行数:19,
示例4: load_profilestatic switch_status_t load_profile(switch_xml_t xml){ switch_xml_t param, settings; char *name = (char *) switch_xml_attr_soft(xml, "name"); logfile_profile_t *new_profile; new_profile = switch_core_alloc(module_pool, sizeof(*new_profile)); memset(new_profile, 0, sizeof(*new_profile)); switch_core_hash_init(&(new_profile->log_hash)); new_profile->name = switch_core_strdup(module_pool, switch_str_nil(name)); new_profile->suffix = 1; new_profile->log_uuid = SWITCH_TRUE; if ((settings = switch_xml_child(xml, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); if (!strcmp(var, "logfile")) { new_profile->logfile = strdup(val); } else if (!strcmp(var, "rollover")) { new_profile->roll_size = switch_atoui(val); } else if (!strcmp(var, "maximum-rotate")) { new_profile->max_rot = switch_atoui(val); if (new_profile->max_rot == 0) { new_profile->max_rot = MAX_ROT; } } else if (!strcmp(var, "uuid")) { new_profile->log_uuid = switch_true(val); } } } if ((settings = switch_xml_child(xml, "mappings"))) { for (param = switch_xml_child(settings, "map"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); add_mapping(new_profile, var, val); } } if (zstr(new_profile->logfile)) { char logfile[512]; switch_snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "freeswitch.log"); new_profile->logfile = strdup(logfile); } if (mod_logfile_openlogfile(new_profile, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_GENERR; } switch_core_hash_insert_destructor(profile_hash, new_profile->name, (void *) new_profile, cleanup_profile); return SWITCH_STATUS_SUCCESS;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:55,
示例5: SWITCH_DECLARESWITCH_DECLARE(void) console_log(char *level_str, char *msg){ switch_log_level_t level = SWITCH_LOG_DEBUG; if (level_str) { level = switch_log_str2level(level_str); if (level == SWITCH_LOG_INVALID) { level = SWITCH_LOG_DEBUG; } } switch_log_printf(SWITCH_CHANNEL_LOG, level, "%s", switch_str_nil(msg));}
开发者ID:gujun,项目名称:sscore,代码行数:11,
示例6: SWITCH_DECLARESWITCH_DECLARE(void) CoreSession::consoleLog(char *level_str, char *msg){ switch_log_level_t level = SWITCH_LOG_DEBUG; if (level_str) { level = switch_log_str2level(level_str); if (level == SWITCH_LOG_INVALID) { level = SWITCH_LOG_DEBUG; } } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), level, "%s", switch_str_nil(msg));}
开发者ID:PauloFer1,项目名称:FreeSWITCH,代码行数:11,
示例7: SWITCH_DECLARESWITCH_DECLARE(void) console_log2(char *level_str, char *file, char *func, int line, char *msg){ switch_log_level_t level = SWITCH_LOG_DEBUG; if (level_str) { level = switch_log_str2level(level_str); if (level == SWITCH_LOG_INVALID) { level = SWITCH_LOG_DEBUG; } } switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, "%s", switch_str_nil(msg));}
开发者ID:odmanV2,项目名称:freecenter,代码行数:11,
示例8: SWITCH_STANDARD_STREAMswitch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res){ switch_status_t status = SWITCH_STATUS_FALSE; switch_stream_handle_t stream = { 0 }; SWITCH_STANDARD_STREAM(stream); //qDebug() << "Sending command: " << cmd << args << endl; status = switch_api_execute(cmd, args, NULL, &stream); *res = switch_str_nil((char *) stream.data); switch_safe_free(stream.data); return status;}
开发者ID:AricGod,项目名称:FreeSWITCH,代码行数:12,
示例9: eventpipe_events_handlervoid eventpipe_events_handler(switch_event_t *event){ struct eventpipe_call *current = NULL; const char *uuid1 = ""; const char *uuid2 = ""; switch_assert(event != NULL); if ((event->event_id != SWITCH_EVENT_CUSTOM) && (event->event_id != SWITCH_EVENT_DTMF)) { return; } uuid1 = switch_event_get_header(event, "unique-id"); if (zstr(uuid1)) { return; } switch_mutex_lock(globals.eventpipe_call_list_mutex); if (!head) { goto eventpipe_events_handler_done; } if (!head->session) { goto eventpipe_events_handler_done; } current = head; while (current) { if (current->session) { uuid2 = ""; uuid2 = switch_core_session_get_uuid(current->session); /* check if event unique-id is matching a call uuid in eventpipe */ if ((uuid2) && (!zstr(uuid2) && (!strcmp(uuid1, uuid2)))) { /* conference event case */ if (event->event_id == SWITCH_EVENT_CUSTOM) { const char *event_subclass = switch_str_nil(switch_event_get_header(event, "event-subclass")); if (!strcmp(event_subclass, PLIVO_EVENT_CONFERENCE)) { eventpipe_events_on_conference(current->session, event); } /* dtmf event case */ } else if (event->event_id == SWITCH_EVENT_DTMF) { eventpipe_events_on_dtmf(current->session, event); } goto eventpipe_events_handler_done; } } current = current->next; }eventpipe_events_handler_done: switch_mutex_unlock(globals.eventpipe_call_list_mutex);}
开发者ID:tamiel,项目名称:mod_eventpipe,代码行数:50,
示例10: cidlookup_callbackstatic int cidlookup_callback(void *pArg, int argc, char **argv, char **columnNames){ callback_t *cbt = (callback_t *) pArg; switch_memory_pool_t *pool = cbt->pool; if (argc < 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unexpected number of columns returned for SQL. Returned column count: %d. ", argc); return SWITCH_STATUS_GENERR; } cbt->name = switch_core_strdup(pool, switch_str_nil(argv[0])); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Name: %s/n", cbt->name); return SWITCH_STATUS_SUCCESS;}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:14,
示例11: eventpipe_events_on_conferencevoid eventpipe_events_on_conference(switch_core_session_t *session, switch_event_t *event) { char args[8192]; char record_args[8192]; const char *action = switch_str_nil(switch_event_get_header(event, "action")); const char *member_id = switch_str_nil(switch_event_get_header(event, "member-id")); const char *conf_room = switch_str_nil(switch_event_get_header(event, "conference-name")); const char *calluuid = switch_core_session_get_uuid(session); switch_channel_t *channel = switch_core_session_get_channel(session); if (!channel) { return; } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Event-Name: %s, Event-Subclass: %s, Conference-Name: %s, Action: %s, Member-ID: %s, Unique-ID: %s/n", switch_str_nil(switch_event_get_header(event, "event-name")), switch_str_nil(switch_event_get_header(event, "event-subclass")), conf_room, action, member_id, calluuid); if (!strcmp(action, "add-member")) { const char *enter_sound = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_enter_sound")); const char *record_file = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_record_file")); switch_channel_set_variable(channel, "eventpipe_conference_member_id", member_id); switch_channel_set_variable(channel, "eventpipe_conference_room", conf_room); if (!zstr(enter_sound)) { switch_snprintf(args, sizeof(args), "%s play %s async", conf_room, enter_sound); eventpipe_execute_api(session, "conference", args); } if (!zstr(record_file)) { switch_snprintf(record_args, sizeof(record_args), "%s record %s", conf_room, record_file); eventpipe_execute_api(session, "conference", record_args); } } else if (!strcmp(action, "del-member")) { const char *exit_sound = switch_str_nil(switch_channel_get_variable(channel, "eventpipe_conference_exit_sound")); switch_channel_set_variable(channel, "eventpipe_conference_member_id", ""); switch_channel_set_variable(channel, "eventpipe_conference_room", ""); switch_channel_set_variable(channel, "eventpipe_conference_record_file", ""); if (!zstr(exit_sound)) { switch_snprintf(args, sizeof(args), "conference %s play %s async", conf_room, exit_sound); eventpipe_execute_api(session, "conference", args); } }}
开发者ID:tamiel,项目名称:mod_eventpipe,代码行数:45,
示例12: is_valid_actionstatic switch_bool_t is_valid_action(const char *action){ int i; if (!zstr(action)) { for (i = 0;; i++) { if (!iam[i].name) { break; } if (!strcmp(iam[i].name, action)) { return SWITCH_TRUE; } } } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Action [%s]/n", switch_str_nil(action)); return SWITCH_FALSE;}
开发者ID:hsaid,项目名称:FreeSWITCH,代码行数:19,
示例13: db_is_upstatic int db_is_up(switch_odbc_handle_t *handle){ int ret = 0; SQLHSTMT stmt = NULL; SQLLEN m = 0; int result; switch_event_t *event; switch_odbc_status_t recon = 0; char *err_str = NULL; SQLCHAR sql[255] = ""; int max_tries = DEFAULT_ODBC_RETRIES; int code = 0; SQLRETURN rc; SQLSMALLINT nresultcols; if (handle) { max_tries = handle->num_retries; if (max_tries < 1) max_tries = DEFAULT_ODBC_RETRIES; } top: if (!handle) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Handle/n"); goto done; } if (handle->is_oracle) { strcpy((char *) sql, "select 1 from dual"); } else if (handle->is_firebird) { strcpy((char *) sql, "select first 1 * from RDB$RELATIONS"); } else { strcpy((char *) sql, "select 1"); } if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) { code = __LINE__; goto error; } SQLSetStmtAttr(stmt, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)30, 0); if (SQLPrepare(stmt, sql, SQL_NTS) != SQL_SUCCESS) { code = __LINE__; goto error; } result = SQLExecute(stmt); if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) { code = __LINE__; goto error; } SQLRowCount(stmt, &m); rc = SQLNumResultCols(stmt, &nresultcols); if (rc != SQL_SUCCESS) { code = __LINE__; goto error; } ret = (int) nresultcols; /* determine statement type */ if (nresultcols <= 0) { /* statement is not a select statement */ code = __LINE__; goto error; } goto done; error: err_str = switch_odbc_handle_get_error(handle, stmt); /* Make sure to free the handle before we try to reconnect */ if (stmt) { SQLFreeHandle(SQL_HANDLE_STMT, stmt); stmt = NULL; } recon = switch_odbc_handle_connect(handle); max_tries--; if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Failure-Message", "The sql server is not responding for DSN %s [%s][%d]", switch_str_nil(handle->dsn), switch_str_nil(err_str), code); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The sql server is not responding for DSN %s [%s][%d]/n", switch_str_nil(handle->dsn), switch_str_nil(err_str), code); if (recon == SWITCH_ODBC_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection has been re-established"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "The connection has been re-established/n"); } else { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection could not be re-established"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The connection could not be re-established/n"); } if (!max_tries) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "Giving up!");//.........这里部分代码省略.........
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例14: switch_name_eventSWITCH_DECLARE_CONSTRUCTOR EventConsumer::EventConsumer(const char *event_name, const char *subclass_name){ switch_name_event(event_name, &e_event_id); switch_core_new_memory_pool(&pool); if (!zstr(subclass_name)) { e_subclass_name = switch_core_strdup(pool, subclass_name); } else { e_subclass_name = NULL; } switch_queue_create(&events, 5000, pool); if (switch_event_bind_removable(__FILE__, e_event_id, e_subclass_name, event_handler, this, &node) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "bound to %s %s/n", event_name, switch_str_nil(e_subclass_name)); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to %s %s/n", event_name, switch_str_nil(e_subclass_name)); }}
开发者ID:gujun,项目名称:sscore,代码行数:20,
示例15: curl_runstatic JSBool curl_run(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval){ struct curl_obj *co = JS_GetPrivate(cx, obj); char *method = NULL, *url, *cred = NULL; char *url_p = NULL, *data = NULL, *durl = NULL; long httpRes = 0; struct curl_slist *headers = NULL; int32 timeout = 0; char ct[80] = "Content-Type: application/x-www-form-urlencoded"; if (argc < 2 || !co) { return JS_FALSE; } method = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); url = JS_GetStringBytes(JS_ValueToString(cx, argv[1])); co->curl_handle = switch_curl_easy_init(); if (!strncasecmp(url, "https", 5)) { switch_curl_easy_setopt(co->curl_handle, CURLOPT_SSL_VERIFYPEER, 0); switch_curl_easy_setopt(co->curl_handle, CURLOPT_SSL_VERIFYHOST, 0); } if (argc > 2) { data = JS_GetStringBytes(JS_ValueToString(cx, argv[2])); } if (argc > 3) { co->function = JS_ValueToFunction(cx, argv[3]); } if (argc > 4) { JS_ValueToObject(cx, argv[4], &co->user_data); } if (argc > 5) { cred = JS_GetStringBytes(JS_ValueToString(cx, argv[5])); if (!zstr(cred)) { switch_curl_easy_setopt(co->curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); switch_curl_easy_setopt(co->curl_handle, CURLOPT_USERPWD, cred); } } if (argc > 6) { JS_ValueToInt32(cx, argv[6], &timeout); if (timeout > 0) { switch_curl_easy_setopt(co->curl_handle, CURLOPT_TIMEOUT, timeout); } } if (argc > 7) { char *content_type = JS_GetStringBytes(JS_ValueToString(cx, argv[7])); switch_snprintf(ct, sizeof(ct), "Content-Type: %s", content_type); } headers = curl_slist_append(headers, ct); switch_curl_easy_setopt(co->curl_handle, CURLOPT_HTTPHEADER, headers); url_p = url; if (!strcasecmp(method, "post")) { switch_curl_easy_setopt(co->curl_handle, CURLOPT_POST, 1); if (!data) { data = ""; } switch_curl_easy_setopt(co->curl_handle, CURLOPT_POSTFIELDS, data); } else if (!zstr(data)) { durl = switch_mprintf("%s?%s", url, data); url_p = durl; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Running: method: [%s] url: [%s] data: [%s] cred=[%s] cb: [%s]/n", method, url_p, data, switch_str_nil(cred), co->function ? "yes" : "no"); switch_curl_easy_setopt(co->curl_handle, CURLOPT_URL, url_p); switch_curl_easy_setopt(co->curl_handle, CURLOPT_NOSIGNAL, 1); switch_curl_easy_setopt(co->curl_handle, CURLOPT_WRITEFUNCTION, file_callback); switch_curl_easy_setopt(co->curl_handle, CURLOPT_WRITEDATA, (void *) co); switch_curl_easy_setopt(co->curl_handle, CURLOPT_USERAGENT, "freeswitch-spidermonkey-curl/1.0"); co->saveDepth = JS_SuspendRequest(cx); switch_curl_easy_perform(co->curl_handle); switch_curl_easy_getinfo(co->curl_handle, CURLINFO_RESPONSE_CODE, &httpRes); switch_curl_easy_cleanup(co->curl_handle); curl_slist_free_all(headers); co->curl_handle = NULL; co->function = NULL; JS_ResumeRequest(cx, co->saveDepth); switch_safe_free(durl); return JS_TRUE;}
开发者ID:AricGod,项目名称:FreeSWITCH,代码行数:98,
示例16: SWITCH_DECLARESWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_callback_exec_detailed(const char *file, const char *func, int line, switch_pgsql_handle_t *handle, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err){#ifdef SWITCH_HAVE_PGSQL char *err_str = NULL; int row = 0, col = 0, err_cnt = 0; switch_pgsql_result_t *result = NULL; handle->affected_rows = 0; switch_assert(callback != NULL); if (switch_pgsql_handle_exec_base(handle, sql, err) == SWITCH_PGSQL_FAIL) { goto error; } if (switch_pgsql_next_result(handle, &result) == SWITCH_PGSQL_FAIL) { err_cnt++; err_str = switch_pgsql_handle_get_error(handle); if (result && !zstr(result->err)) { switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]/n[%s]/n", sql, switch_str_nil(result->err)); } if (!zstr(err_str)) { switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]/n[%s]/n", sql, switch_str_nil(err_str)); } switch_safe_free(err_str); err_str = NULL; } while (result != NULL) { /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Processing result with %d rows and %d columns./n", result->rows, result->cols);*/ for (row = 0; row < result->rows; ++row) { char **names; char **vals; names = calloc(result->cols, sizeof(*names)); vals = calloc(result->cols, sizeof(*vals)); switch_assert(names && vals); for (col = 0; col < result->cols; ++col) { char * tmp; int len; tmp = PQfname(result->result, col); if (tmp) { len = strlen(tmp); names[col] = malloc(len+1); names[col][len] = '/0'; strncpy(names[col], tmp, len); len = PQgetlength(result->result, row, col); vals[col] = malloc(len+1); vals[col][len] = '/0'; tmp = PQgetvalue(result->result, row, col); strncpy(vals[col], tmp, len); /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Processing result row %d, col %d: %s => %s/n", row, col, names[col], vals[col]);*/ } else { /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Processing result row %d, col %d./n", row, col);*/ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: Column number %d out of range/n", col); } } /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing callback for row %d.../n", row);*/ if (callback(pdata, result->cols, vals, names)) { switch_pgsql_finish_results(handle); /* Makes sure next call to switch_pgsql_next_result will return NULL */ row = result->rows; /* Makes us exit the for loop */ } for (col = 0; col < result->cols; ++col) { free(names[col]); free(vals[col]); } free(names); free(vals); } switch_pgsql_free_result(&result); if (switch_pgsql_next_result(handle, &result) == SWITCH_PGSQL_FAIL) { err_cnt++; err_str = switch_pgsql_handle_get_error(handle); if (result && !zstr(result->err)) { switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]/n[%s]/n", sql, switch_str_nil(result->err)); } if (!zstr(err_str)) { switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]/n[%s]/n", sql, switch_str_nil(err_str)); } switch_safe_free(err_str); err_str = NULL; } } if (err_cnt) { goto error; } return SWITCH_PGSQL_SUCCESS;error:#endif return SWITCH_PGSQL_FAIL;//.........这里部分代码省略.........
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例17: db_is_upstatic int db_is_up(switch_pgsql_handle_t *handle){ int ret = 0; switch_event_t *event; char *err_str = NULL; int max_tries = DEFAULT_PGSQL_RETRIES; int code = 0, recon = 0; if (handle) { max_tries = handle->num_retries; if (max_tries < 1) max_tries = DEFAULT_PGSQL_RETRIES; }top: if (!handle) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Handle/n"); goto done; } if (!handle->con) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Connection/n"); goto done; } /* Try a non-blocking read on the connection to gobble up any EOF from a closed connection and mark the connection BAD if it is closed. */ PQconsumeInput(handle->con); if (PQstatus(handle->con) == CONNECTION_BAD) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "PQstatus returned bad connection; reconnecting.../n"); handle->state = SWITCH_PGSQL_STATE_ERROR; PQreset(handle->con); if (PQstatus(handle->con) == CONNECTION_BAD) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "PQstatus returned bad connection -- reconnection failed!/n"); goto error; } handle->state = SWITCH_PGSQL_STATE_CONNECTED; handle->sock = PQsocket(handle->con); } /* if (!PQsendQuery(handle->con, "SELECT 1")) { code = __LINE__; goto error; } if(switch_pgsql_next_result(handle, &result) == SWITCH_PGSQL_FAIL) { code = __LINE__; goto error; } if (!result || result->status != PGRES_COMMAND_OK) { code = __LINE__; goto error; } switch_pgsql_free_result(&result); switch_pgsql_finish_results(handle); */ ret = 1; goto done;error: err_str = switch_pgsql_handle_get_error(handle); if (PQstatus(handle->con) == CONNECTION_BAD) { handle->state = SWITCH_PGSQL_STATE_ERROR; PQreset(handle->con); if (PQstatus(handle->con) == CONNECTION_OK) { handle->state = SWITCH_PGSQL_STATE_CONNECTED; recon = SWITCH_PGSQL_SUCCESS; handle->sock = PQsocket(handle->con); } } max_tries--; if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Failure-Message", "The sql server is not responding for DSN %s [%s][%d]", switch_str_nil(handle->dsn), switch_str_nil(err_str), code); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The sql server is not responding for DSN %s [%s][%d]/n", switch_str_nil(handle->dsn), switch_str_nil(err_str), code); if (recon == SWITCH_PGSQL_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection has been re-established"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "The connection has been re-established/n"); } else { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection could not be re-established"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The connection could not be re-established/n"); } if (!max_tries) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "Giving up!"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Giving up!/n"); } switch_event_fire(&event); } if (!max_tries) { goto done; }//.........这里部分代码省略.........
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例18: SWITCH_DECLARE//.........这里部分代码省略......... goto error; } result = SQLExecute(stmt); if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO && result != SQL_NO_DATA) { x_err = "execute error!"; goto error; } SQLNumResultCols(stmt, &c); SQLRowCount(stmt, &m); handle->affected_rows = (int) m; while (!done) { int name_len = 256; char **names; char **vals; int y = 0; result = SQLFetch(stmt); if (result != SQL_SUCCESS) { if (result != SQL_NO_DATA) { err_cnt++; } break; } names = calloc(c, sizeof(*names)); vals = calloc(c, sizeof(*vals)); switch_assert(names && vals); for (x = 1; x <= c; x++) { SQLSMALLINT NameLength = 0, DataType = 0, DecimalDigits = 0, Nullable = 0; SQLULEN ColumnSize = 0; names[y] = malloc(name_len); memset(names[y], 0, name_len); SQLDescribeCol(stmt, x, (SQLCHAR *) names[y], (SQLSMALLINT) name_len, &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable); if (!ColumnSize) { ColumnSize = 255; } ColumnSize++; vals[y] = malloc(ColumnSize); memset(vals[y], 0, ColumnSize); SQLGetData(stmt, x, SQL_C_CHAR, (SQLCHAR *) vals[y], ColumnSize, NULL); y++; } if (callback(pdata, y, vals, names)) { done = 1; } for (x = 0; x < y; x++) { free(names[x]); free(vals[x]); } free(names); free(vals); } SQLFreeHandle(SQL_HANDLE_STMT, stmt); stmt = NULL; /* Make sure we don't try to free this handle again */ if (!err_cnt) { return SWITCH_ODBC_SUCCESS; } error: if (stmt) { err_str = switch_odbc_handle_get_error(handle, stmt); } if (zstr(err_str) && !zstr(x_err)) { err_str = strdup(x_err); } if (err_str) { switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]/n[%s]/n", sql, switch_str_nil(err_str)); if (err) { *err = err_str; } else { free(err_str); } } if (stmt) { SQLFreeHandle(SQL_HANDLE_STMT, stmt); }#endif return SWITCH_ODBC_FAIL;}
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例19: vmivr_menu_navigatorvoid vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_event_t *msg_list_params = NULL; size_t msg_count = 0; size_t current_msg = 1; size_t next_msg = current_msg; size_t previous_msg = current_msg; char *cmd = NULL; int retry; /* Different switch to control playback of phrases */ switch_bool_t initial_count_played = SWITCH_FALSE; switch_bool_t skip_header = SWITCH_FALSE; switch_bool_t skip_playback = SWITCH_FALSE; switch_bool_t msg_deleted = SWITCH_FALSE; switch_bool_t msg_undeleted = SWITCH_FALSE; switch_bool_t msg_saved = SWITCH_FALSE; vmivr_menu_t menu = { "std_navigator" }; /* Initialize Menu Configs */ menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'/n", menu.name); goto done; } /* Get VoiceMail List And update msg count */ cmd = switch_core_session_sprintf(session, "json %s %s %s %s %s", profile->api_profile, profile->domain, profile->id, profile->folder_name, profile->folder_filter); msg_list_params = jsonapi2event(session, profile->api_msg_list, cmd); if (msg_list_params) { msg_count = atol(switch_event_get_header(msg_list_params,"VM-List-Count")); if (msg_count == 0) { goto done; } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "API message list return invalid result : %s(%s)/n", profile->api_msg_list, cmd); goto done; } /* TODO Add Detection of new message and notify the user */ for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { switch_core_session_message_t msg = { 0 }; char cid_buf[1024] = ""; menu_instance_init(&menu); switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); previous_msg = current_msg; ivre_init(&menu.ivre_d, menu.dtmfa); /* Prompt related to previous Message here */ append_event_message(session, profile, menu.phrase_params, msg_list_params, previous_msg); if (msg_deleted) { msg_deleted = SWITCH_FALSE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "ack"), "deleted", menu.phrase_params, NULL, 0); } if (msg_undeleted) { msg_undeleted = SWITCH_FALSE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "ack"), "undeleted", menu.phrase_params, NULL, 0); } if (msg_saved) { msg_saved = SWITCH_FALSE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "ack"), "saved", menu.phrase_params, NULL, 0); } switch_event_del_header(menu.phrase_params, "VM-Message-Flags"); /* Simple Protection to not go out of msg list scope */ if (next_msg == 0) { next_msg = 1; } else if (next_msg > msg_count) { next_msg = msg_count; ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "no_more_messages"), NULL, NULL, NULL, 0); } current_msg = next_msg; /* Prompt related the current message */ append_event_message(session, profile, menu.phrase_params, msg_list_params, current_msg); /* Used for extra control in phrases */ switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "VM-List-Count", "%"SWITCH_SIZE_T_FMT, msg_count); /* Display MSG CID/Name to caller */ switch_snprintf(cid_buf, sizeof(cid_buf), "%s|%s", switch_str_nil(switch_event_get_header(menu.phrase_params, "VM-Message-Caller-Number")), switch_str_nil(switch_event_get_header(menu.phrase_params, "VM-Message-Caller-Name"))); msg.from = __FILE__; msg.string_arg = cid_buf; msg.message_id = SWITCH_MESSAGE_INDICATE_DISPLAY; switch_core_session_receive_message(session, &msg); /* Save in profile the current msg info for other menu processing AND restoration of our current position */ profile->current_msg = current_msg; profile->current_msg_uuid = switch_core_session_strdup(session, switch_event_get_header(menu.phrase_params, "VM-Message-UUID"));//.........这里部分代码省略.........
开发者ID:odmanV2,项目名称:freecenter,代码行数:101,
示例20: xml_url_fetchstatic switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data){ switch_xml_t xml = NULL; char *data = NULL; xml_binding_t *binding = (xml_binding_t *) user_data; char hostname[256] = ""; char basic_data[512]; unsigned char buf[16336] = ""; ssize_t len = -1, bytes = 0; scgi_handle_t handle = { 0 }; switch_stream_handle_t stream = { 0 }; char *txt = NULL; strncpy(hostname, switch_core_get_switchname(), sizeof(hostname)); if (!binding) { return NULL; } switch_snprintf(basic_data, sizeof(basic_data), "hostname=%s§ion=%s&tag_name=%s&key_name=%s&key_value=%s", hostname, section, switch_str_nil(tag_name), switch_str_nil(key_name), switch_str_nil(key_value)); data = switch_event_build_param_string(params, basic_data, binding->vars_map); switch_assert(data); scgi_add_param(&handle, "REQUEST_METHOD", "POST"); scgi_add_param(&handle, "SERVER_PROTOCOL", "HTTP/1.0"); scgi_add_param(&handle, "REQUEST_URI", binding->uri); scgi_add_body(&handle, data); if (scgi_connect(&handle, binding->host, binding->port, binding->timeout * 1000) == SCGI_SUCCESS) { scgi_send_request(&handle); SWITCH_STANDARD_STREAM(stream); txt = (char *) stream.data; while((len = scgi_recv(&handle, buf, sizeof(buf))) > 0) { char *expanded = switch_event_expand_headers(params, (char *)buf); bytes += len; if (bytes > XML_SCGI_MAX_BYTES) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Data too big!/n"); len = -1; break; } stream.write_function(&stream, "%s", expanded); txt = (char *) stream.data; if (expanded != (char *)buf) { free(expanded); } memset(buf, 0, sizeof(buf)); } scgi_disconnect(&handle); if (len < 0 && (!txt || !strlen(txt))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DEBUG:/nURL: %s Connection Read Failed: [%s]/n", binding->url, handle.err); goto end; } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DEBUG:/nURL: %s Connection Failed: [%s]/n", binding->url, handle.err); goto end; } if (GLOBAL_DEBUG) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DEBUG:/nURL: %s/nPOST_DATA:/n%s/n/nRESPONSE:/n-----/n%s/n-----/n", binding->url, data, switch_str_nil(txt)); } if (bytes && txt) { if (!(xml = switch_xml_parse_str_dynamic(txt, FALSE))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result! [%s]/ndata: [%s] RESPONSE[%s]/n", binding->url, data, switch_str_nil(txt)); } txt = NULL; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received error trying to fetch %s/ndata: [%s] RESPONSE [%s]/n", binding->url, data, switch_str_nil(txt)); } end: switch_safe_free(data); switch_safe_free(txt); return xml;}
开发者ID:DastanIqbal,项目名称:FreeSWITCH,代码行数:98,
示例21: switch_log_printfWSChannel* WSClientParser::CreateCall( switch_core_session_t *session, const char *profileName, const char *profileContext, const char *profileDialplan, const char* ip ) { WSChannel *wsChannel = NULL; switch_memory_pool_t *pool = NULL; switch_channel_t* channel = NULL; switch_caller_profile_t *caller_profile = NULL; char *user = mpUser; char *domain = mpDomain; const char *destNumber = mpDestNumber; const char *context = NULL; const char *dialplan = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; switch_log_printf( SWITCH_CHANNEL_UUID_LOG(this->GetUUID()), SWITCH_LOG_INFO, "WSClientParser::CreateCall( " "this : %p, " "profileName : '%s', " "profileContext : '%s', " "profileDialplan : '%s', " "ip : '%s' " ") /n", this, profileName, profileContext, profileDialplan, ip ); // 参数不能为空 if ( !user || !domain || !destNumber ) { status = SWITCH_STATUS_FALSE; } // 不允许一个连接创建多个会话 if( status == SWITCH_STATUS_SUCCESS && mpChannel ) { status = SWITCH_STATUS_FALSE; } if( status == SWITCH_STATUS_SUCCESS ) { pool = switch_core_session_get_pool(session); channel = switch_core_session_get_channel(session); switch_channel_set_name( channel, switch_core_session_sprintf(session, "ws/%s/%s/%s", profileName, user, destNumber) ); }// if ( status == SWITCH_STATUS_SUCCESS && !zstr(user) && !zstr(domain)) {// // 拨号不做验证// const char *ivrUser = switch_core_session_sprintf(session, "%[email C++ switch_task_namespaces函数代码示例 C++ switch_snprintf函数代码示例
|