From f1222ba2fdb30eac3830d608725d0f800b8e40a0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 3 Aug 2007 21:29:01 +0000 Subject: [PATCH] fix for FSCORE-40 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5566 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../applications/mod_commands/mod_commands.c | 6 ++++-- .../applications/mod_dptools/mod_dptools.c | 4 +++- src/mod/endpoints/mod_iax/mod_iax.c | 4 ++-- src/mod/endpoints/mod_sofia/sofia.c | 2 +- src/mod/endpoints/mod_sofia/sofia_glue.c | 10 ++++------ src/mod/endpoints/mod_sofia/sofia_presence.c | 2 +- .../mod_event_socket/mod_event_socket.c | 4 ++-- .../mod_spidermonkey/mod_spidermonkey.c | 8 +++++--- .../mod_spidermonkey_etpan.c | 5 ++++- src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c | 4 ++-- src/switch.c | 4 +++- src/switch_core.c | 4 +++- src/switch_ivr_originate.c | 2 +- src/switch_xml.c | 19 +++++++++++++------ 14 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 5aa6dbd1da..756bb91dc4 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -1059,7 +1059,8 @@ static int show_as_xml_callback(void *pArg, int argc, char **argv, char **column } snprintf(id, sizeof(id), "%d", holder->rows); - switch_xml_set_attr_d(row, "row_id", id); + + switch_xml_set_attr(switch_xml_set_flag(row, SWITCH_XML_DUP), strdup("row_id"), strdup(id)); for(x = 0; x < argc; x++) { char *name = columnNames[x]; @@ -1229,7 +1230,8 @@ SWITCH_STANDARD_API(show_function) char count[50]; char *xmlstr; snprintf(count, sizeof(count), "%d", holder.count); - switch_xml_set_attr_d(holder.xml, "row_count", count); + + switch_xml_set_attr(switch_xml_set_flag(holder.xml, SWITCH_XML_DUP), strdup("row_count"), strdup(count)); xmlstr = switch_xml_toxml(holder.xml); if (xmlstr) { diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 4e3d660b0f..3b30b9a6ef 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -724,7 +724,9 @@ SWITCH_STANDARD_APP(fax_detect_session_function) SWITCH_STANDARD_APP(system_session_function) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n",data); - system(data); + if(!system(data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n",data); + } } SWITCH_STANDARD_APP(tone_detect_session_function) diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c index 9a535bc988..6929c69852 100644 --- a/src/mod/endpoints/mod_iax/mod_iax.c +++ b/src/mod/endpoints/mod_iax/mod_iax.c @@ -278,8 +278,8 @@ static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *i char pref_str[256] = "("; for (x = 0; x < len; x++) { - strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str)); - strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str)); + strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str)-1); + strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str)-1); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Codec Prefs Detected: %s\n", pref_str); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index df6d001c3a..f0f10044b2 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1785,7 +1785,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ } switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); - if (!switch_strlen_zero(key)) { + if (*key != '\0') { tech_pvt->key = switch_core_session_strdup(session, key); } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index d1660fb907..cf24d369ca 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -582,10 +582,10 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) } nua_invite(tech_pvt->nh, - TAG_IF(!switch_strlen_zero(rpid), SIPTAG_HEADER_STR(rpid)), - TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)), + TAG_IF(*rpid != '\0', SIPTAG_HEADER_STR(rpid)), + TAG_IF(*alert_info != '\0', SIPTAG_HEADER_STR(alert_info)), TAG_IF(!switch_strlen_zero(extra_headers), SIPTAG_HEADER_STR(extra_headers)), - TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)), + TAG_IF(*max_forwards != '\0', SIPTAG_MAX_FORWARDS_STR(max_forwards)), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE), SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END()); @@ -600,7 +600,6 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) void sofia_glue_do_xfer_invite(switch_core_session_t *session) { - char rpid[1024]; private_object_t *tech_pvt; switch_channel_t *channel = NULL; switch_caller_profile_t *caller_profile; @@ -630,7 +629,6 @@ void sofia_glue_do_xfer_invite(switch_core_session_t *session) nua_handle_bind(tech_pvt->nh2, tech_pvt->sofia_private); nua_invite(tech_pvt->nh2, - TAG_IF(rpid, SIPTAG_HEADER_STR(rpid)), SIPTAG_CONTACT_STR(tech_pvt->profile->url), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE), SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), TAG_END()); @@ -1092,7 +1090,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t * if (!strcasecmp(a->a_name, "sendonly")) { sendonly = 1; - } else if (!strcasecmp(a->a_name, "sendrecv")) { + } else if (!strcasecmp(a->a_name, "sendrecv")) { sendonly = 0; } else if (!strcasecmp(a->a_name, "ptime")) { dptime = atoi(a->a_value); diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index f5353e2583..7133c9a873 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -1033,7 +1033,7 @@ void sofia_presence_handle_sip_i_message(int status, if ((ci = switch_loadable_module_get_chat_interface(proto))) { ci->chat_send(SOFIA_CHAT_PROTO, from_addr, to_addr, "", msg, full_from); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto ? proto : "(none)"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto); } } diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 6ed4ba7bc9..c42572208a 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -1065,7 +1065,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj switch_clear_flag_locked(listener, LFLAG_RUNNING); goto done; } - if (!switch_strlen_zero(reply)) { + if (*reply != '\0') { snprintf(buf, sizeof(buf), "Content-Type: command/reply\nReply-Text: %s\n\n", reply); len = strlen(buf); switch_socket_send(listener->sock, buf, &len); @@ -1094,7 +1094,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj break; } - if (!switch_strlen_zero(reply)) { + if (*reply != '\0') { snprintf(buf, sizeof(buf), "Content-Type: command/reply\nReply-Text: %s\n\n", reply); len = strlen(buf); switch_socket_send(listener->sock, buf, &len); diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index 7327e33c9d..564c9d8825 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -715,7 +715,7 @@ static switch_status_t sm_load_file(char *filename) } -static switch_status_t sm_load_module(char *dir, char *fname) +static switch_status_t sm_load_module(const char *dir, const char *fname) { switch_size_t len = 0; char *path; @@ -788,7 +788,7 @@ static switch_status_t load_modules(void) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); continue; } - sm_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) val); + sm_load_module(SWITCH_GLOBAL_dirs.mod_dir, val); count++; } } @@ -1964,7 +1964,9 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data) register unsigned int realsize = (unsigned int) (size * nmemb); struct config_data *config_data = data; - write(config_data->fd, ptr, realsize); + if ((write(config_data->fd, ptr, realsize) != (int)realsize)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to write all bytes!\n"); + } return realsize; } diff --git a/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c b/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c index 2c38e576ea..172727fb5d 100644 --- a/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c +++ b/src/mod/languages/mod_spidermonkey_etpan/mod_spidermonkey_etpan.c @@ -180,7 +180,10 @@ static JSBool js_email(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, close(ifd); } snprintf(buf, B64BUFFLEN, "/bin/cat %s | /usr/sbin/sendmail -tf \"%s\" %s", filename, from, to); - system(buf); + if(!system(buf)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n",buf); + } + unlink(filename); diff --git a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c index c09ed1e9f0..e2d20b371a 100644 --- a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c +++ b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c @@ -327,12 +327,12 @@ static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * cons if (action) { if (switch_core_management_exec(relative_oid, action, buf, sizeof(buf)) == SWITCH_STATUS_SUCCESS) { if (action == SMA_SET) { - if (switch_strlen_zero(buf)) { + if (*buf != '\0') { snprintf(buf, sizeof(buf), "OK\n"); } } } else { - if (switch_strlen_zero(buf)) { + if (*buf != '\0') { snprintf(buf, sizeof(buf), "ERROR\n"); } } diff --git a/src/switch.c b/src/switch.c index 4f4c3f00aa..cc083d06a2 100644 --- a/src/switch.c +++ b/src/switch.c @@ -96,7 +96,9 @@ static int freeswitch_kill_background() } /* pull the pid from the file */ - fscanf(f, "%d", &pid); + if(fscanf(f, "%d", &pid)!=1) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Unable to get the pid!\n"); + } /* if we have a valid pid */ if (pid > 0) { diff --git a/src/switch_core.c b/src/switch_core.c index 9d23f5b5a5..1a95703e14 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -355,7 +355,9 @@ SWITCH_DECLARE(int32_t) set_high_priority(void) #ifdef WIN32 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); #else - nice(-10); + if(nice(-10)!= -10) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not set nice level\n"); + } #endif #define USE_MLOCKALL diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 9b2fc24e0b..58d9ee5341 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -373,7 +373,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess fail_on_single_reject = 1; } - if ((!switch_strlen_zero(file)) && (!strcmp(file, "undef"))) { + if ((*file != '\0') && (!strcmp(file, "undef"))) { *file = '\0'; } diff --git a/src/switch_xml.c b/src/switch_xml.c index 64c75be7a5..18fd51009a 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -966,12 +966,16 @@ static int preprocess(const char *file, int write_fd, int rlevel) } } - if ((cmd = strstr(bp, ""))) { *e = '\0'; - e += 3; - write(write_fd, e, (unsigned) strlen(e)); + e += 3; + if(write(write_fd, e, (unsigned) strlen(e)) != (int) strlen(e)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Short write!\n"); + } } else { ml++; } @@ -1027,8 +1031,11 @@ static int preprocess(const char *file, int write_fd, int rlevel) continue; } - - write(write_fd, bp, (unsigned) cur); + + if(write(write_fd, bp, (unsigned) cur) != (int) cur) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Short write!\n"); + } + } close(read_fd);