more ast_copy_string conversions
authorRussell Bryant <russell@russellbryant.com>
Sun, 10 Jul 2005 23:12:25 +0000 (23:12 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sun, 10 Jul 2005 23:12:25 +0000 (23:12 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6074 65c4cc65-6c06-0410-ace0-fbb531ad65f3

15 files changed:
apps/app_adsiprog.c
apps/app_alarmreceiver.c
apps/app_directory.c
apps/app_macro.c
apps/app_math.c
apps/app_setcallerid.c
apps/app_setcidname.c
apps/app_setcidnum.c
apps/app_setrdnis.c
apps/app_settransfercapability.c
apps/app_sms.c
apps/app_talkdetect.c
apps/app_txtcidname.c
apps/app_zapras.c
apps/app_zapscan.c

index 2dee63f..b9d3c09 100755 (executable)
@@ -402,7 +402,7 @@ static struct adsi_flag *getflagbyname(struct adsi_script *state, char *name, ch
                ast_log(LOG_WARNING, "No more flag space at line %d of %s\n", lineno, script);
                return NULL;
        }
-       strncpy(state->flags[state->numflags].vname, name, sizeof(state->flags[state->numflags].vname) - 1);
+       ast_copy_string(state->flags[state->numflags].vname, name, sizeof(state->flags[state->numflags].vname));
        state->flags[state->numflags].id = state->numflags + 1;
        state->numflags++;
        return &state->flags[state->numflags-1];
@@ -505,7 +505,7 @@ static struct adsi_soft_key *getkeybyname(struct adsi_script *state, char *name,
                ast_log(LOG_WARNING, "No more key space at line %d of %s\n", lineno, script);
                return NULL;
        }
-       strncpy(state->keys[state->numkeys].vname, name, sizeof(state->keys[state->numkeys].vname) - 1);
+       ast_copy_string(state->keys[state->numkeys].vname, name, sizeof(state->keys[state->numkeys].vname));
        state->keys[state->numkeys].id = state->numkeys + 2;
        state->numkeys++;
        return &state->keys[state->numkeys-1];
@@ -521,7 +521,7 @@ static struct adsi_subscript *getsubbyname(struct adsi_script *state, char *name
                ast_log(LOG_WARNING, "No more subscript space at line %d of %s\n", lineno, script);
                return NULL;
        }
-       strncpy(state->subs[state->numsubs].vname, name, sizeof(state->subs[state->numsubs].vname) - 1);
+       ast_copy_string(state->subs[state->numsubs].vname, name, sizeof(state->subs[state->numsubs].vname));
        state->subs[state->numsubs].id = state->numsubs;
        state->numsubs++;
        return &state->subs[state->numsubs-1];
@@ -540,7 +540,7 @@ static struct adsi_state *getstatebyname(struct adsi_script *state, char *name,
                ast_log(LOG_WARNING, "No more state space at line %d of %s\n", lineno, script);
                return NULL;
        }
-       strncpy(state->states[state->numstates].vname, name, sizeof(state->states[state->numstates].vname) - 1);
+       ast_copy_string(state->states[state->numstates].vname, name, sizeof(state->states[state->numstates].vname));
        state->states[state->numstates].id = state->numstates + 1;
        state->numstates++;
        return &state->states[state->numstates-1];
@@ -559,7 +559,7 @@ static struct adsi_display *getdisplaybyname(struct adsi_script *state, char *na
                ast_log(LOG_WARNING, "No more display space at line %d of %s\n", lineno, script);
                return NULL;
        }
-       strncpy(state->displays[state->numdisplays].vname, name, sizeof(state->displays[state->numdisplays].vname) - 1);
+       ast_copy_string(state->displays[state->numdisplays].vname, name, sizeof(state->displays[state->numdisplays].vname));
        state->displays[state->numdisplays].id = state->numdisplays + 1;
        state->numdisplays++;
        return &state->displays[state->numdisplays-1];
@@ -1045,7 +1045,7 @@ static int adsi_process(struct adsi_script *state, char *buf, char *script, int
                                        break;
                                }
                        } else {
-                               strncpy(tmp2, tmp, sizeof(tmp2) - 1);
+                               ast_copy_string(tmp2, tmp, sizeof(tmp2));
                        }
                        if (strlen(tmp2) > 18) {
                                ast_log(LOG_WARNING, "Truncating full name to 18 characters at line %d of %s\n", lineno, script);
@@ -1338,7 +1338,7 @@ static struct adsi_script *compile_script(char *script)
        int x, err;
        struct adsi_script *scr;
        if (script[0] == '/')
-               strncpy(fn, script, sizeof(fn) - 1);
+               ast_copy_string(fn, script, sizeof(fn));
        else
                snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, script);
        f = fopen(fn, "r");
index bdf264e..a0788e1 100755 (executable)
@@ -310,7 +310,7 @@ static int write_metadata( FILE *logfile, char *signalling_type, struct ast_chan
        
        /* Extract the caller ID location */
        if (chan->cid.cid_num)
-               strncpy(workstring, chan->cid.cid_num, sizeof(workstring) - 1);
+               ast_copy_string(workstring, chan->cid.cid_num, sizeof(workstring));
        workstring[sizeof(workstring) - 1] = '\0';
        
        ast_callerid_parse(workstring, &cn, &cl);
@@ -389,7 +389,7 @@ static int log_events(struct ast_channel *chan,  char *signalling_type, event_no
                
                /* Make a template */
                
-               strncpy(workstring, event_spool_dir, sizeof(workstring) - 1);
+               ast_copy_string(workstring, event_spool_dir, sizeof(workstring));
                strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1);
                
                /* Make the temporary file */
@@ -581,7 +581,7 @@ static int receive_ademco_contact_id( struct ast_channel *chan, void *data, int
                memset(enew, 0, sizeof(event_node_t));
                
                enew->next = NULL;
-               strncpy(enew->data, event, sizeof(enew->data) - 1);
+               ast_copy_string(enew->data, event, sizeof(enew->data));
 
                /*
                * Insert event onto end of list
@@ -654,7 +654,7 @@ static int alarmreceiver_exec(struct ast_channel *chan, void *data)
 
        /* Set default values for this invokation of the application */
        
-       strncpy(signalling_type, ADEMCO_CONTACT_ID, sizeof(signalling_type) - 1);
+       ast_copy_string(signalling_type, ADEMCO_CONTACT_ID, sizeof(signalling_type));
 
 
        /* Answer the channel if it is not already */
@@ -751,7 +751,7 @@ static int load_config(void)
                p = ast_variable_retrieve(cfg, "general", "eventcmd");
                
                if(p){
-                       strncpy(event_app, p, sizeof(event_app) - 1);
+                       ast_copy_string(event_app, p, sizeof(event_app));
                        event_app[sizeof(event_app) - 1] = '\0';
                }
                
@@ -791,21 +791,21 @@ static int load_config(void)
                p = ast_variable_retrieve(cfg, "general", "eventspooldir");
                        
                if(p){
-                       strncpy(event_spool_dir, p, sizeof(event_spool_dir) - 1);
+                       ast_copy_string(event_spool_dir, p, sizeof(event_spool_dir));
                        event_spool_dir[sizeof(event_spool_dir) - 1] = '\0';
                }
                
                p = ast_variable_retrieve(cfg, "general", "timestampformat");
                        
                if(p){
-                       strncpy(time_stamp_format, p, sizeof(time_stamp_format) - 1);
+                       ast_copy_string(time_stamp_format, p, sizeof(time_stamp_format));
                        time_stamp_format[sizeof(time_stamp_format) - 1] = '\0';
                }
 
                p = ast_variable_retrieve(cfg, "general", "db-family");
                                                                                                                                             
                if(p){
-                       strncpy(db_family, p, sizeof(db_family) - 1);
+                       ast_copy_string(db_family, p, sizeof(db_family));
                        db_family[sizeof(db_family) - 1] = '\0';
                }
                ast_config_destroy(cfg);
index 1e451ee..252b437 100755 (executable)
@@ -183,9 +183,9 @@ static int play_mailbox_owner(struct ast_channel *chan, char *context, char *dia
                                        /* Name selected */
                                        loop = 0;
                                        if (ast_exists_extension(chan,dialcontext,ext,1,chan->cid.cid_num)) {
-                                               strncpy(chan->exten, ext, sizeof(chan->exten)-1);
+                                               ast_copy_string(chan->exten, ext, sizeof(chan->exten));
                                                chan->priority = 0;
-                                               strncpy(chan->context, dialcontext, sizeof(chan->context)-1);
+                                               ast_copy_string(chan->context, dialcontext, sizeof(chan->context));
                                        } else {
                                                ast_log(LOG_WARNING,
                                                        "Can't find extension '%s' in context '%s'.  "
@@ -296,7 +296,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
                if (ast_exists_extension(chan,chan->context,"o",1,chan->cid.cid_num) || 
                        (!ast_strlen_zero(chan->macrocontext) &&
                     ast_exists_extension(chan, chan->macrocontext, "o", 1, chan->cid.cid_num))) {
-                       strncpy(chan->exten, "o", sizeof(chan->exten)-1);
+                       strcpy(chan->exten, "o");
                        chan->priority = 0;
                        return 0;
                } else {
@@ -310,7 +310,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
                if (ast_exists_extension(chan,chan->context,"a",1,chan->cid.cid_num) || 
                        (!ast_strlen_zero(chan->macrocontext) &&
                     ast_exists_extension(chan, chan->macrocontext, "a", 1, chan->cid.cid_num))) {
-                       strncpy(chan->exten, "a", sizeof(chan->exten)-1);
+                       strcpy(chan->exten, "a");
                        chan->priority = 0;
                        return 0;
                } else {
@@ -337,7 +337,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
                                        strsep(&stringp, ",");
                                        pos = strsep(&stringp, ",");
                                        if (pos) {
-                                               strncpy(name, pos, sizeof(name) - 1);
+                                               ast_copy_string(name, pos, sizeof(name));
                                                /* Grab the last name */
                                                if (last && strrchr(pos,' '))
                                                        pos = strrchr(pos, ' ') + 1;
@@ -371,8 +371,8 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
                                        case '1':
                                                /* user pressed '1' and extensions exists */
                                                lastuserchoice = res;
-                                               strncpy(chan->context, dialcontext, sizeof(chan->context) - 1);
-                                               strncpy(chan->exten, v->name, sizeof(chan->exten) - 1);
+                                               ast_copy_string(chan->context, dialcontext, sizeof(chan->context));
+                                               ast_copy_string(chan->exten, v->name, sizeof(chan->exten));
                                                chan->priority = 0;
                                                break;
                                        case '*':
index 25d2aa8..fb48edc 100755 (executable)
@@ -124,11 +124,11 @@ static int macro_exec(struct ast_channel *chan, void *data)
        LOCAL_USER_ADD(u);
        /* Save old info */
        oldpriority = chan->priority;
-       strncpy(oldexten, chan->exten, sizeof(oldexten) - 1);
-       strncpy(oldcontext, chan->context, sizeof(oldcontext) - 1);
+       ast_copy_string(oldexten, chan->exten, sizeof(oldexten));
+       ast_copy_string(oldcontext, chan->context, sizeof(oldcontext));
        if (ast_strlen_zero(chan->macrocontext)) {
-               strncpy(chan->macrocontext, chan->context, sizeof(chan->macrocontext) - 1);
-               strncpy(chan->macroexten, chan->exten, sizeof(chan->macroexten) - 1);
+               ast_copy_string(chan->macrocontext, chan->context, sizeof(chan->macrocontext));
+               ast_copy_string(chan->macroexten, chan->exten, sizeof(chan->macroexten));
                chan->macropriority = chan->priority;
                setmacrocontext=1;
        }
@@ -158,7 +158,7 @@ static int macro_exec(struct ast_channel *chan, void *data)
        /* Setup environment for new run */
        chan->exten[0] = 's';
        chan->exten[1] = '\0';
-       strncpy(chan->context, fullmacro, sizeof(chan->context) - 1);
+       ast_copy_string(chan->context, fullmacro, sizeof(chan->context));
        chan->priority = 1;
 
        while((cur = strsep(&rest, "|")) && (argc < MAX_ARGS)) {
@@ -246,10 +246,10 @@ static int macro_exec(struct ast_channel *chan, void *data)
        if (!strcasecmp(chan->context, fullmacro)) {
                /* If we're leaving the macro normally, restore original information */
                chan->priority = oldpriority;
-               strncpy(chan->context, oldcontext, sizeof(chan->context) - 1);
+               ast_copy_string(chan->context, oldcontext, sizeof(chan->context));
                if (!(chan->_softhangup & AST_SOFTHANGUP_ASYNCGOTO)) {
                        /* Copy the extension, so long as we're not in softhangup, where we could be given an asyncgoto */
-                       strncpy(chan->exten, oldexten, sizeof(chan->exten) - 1);
+                       ast_copy_string(chan->exten, oldexten, sizeof(chan->exten));
                        if ((offsets = pbx_builtin_getvar_helper(chan, "MACRO_OFFSET"))) {
                                /* Handle macro offset if it's set by checking the availability of step n + offset + 1, otherwise continue
                                normally if there is any problem */
index 630d17b..e66341e 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- A telephony toolkit for Linux.
  *
- * simple maths application
+ * simple math application
  * 
  * Copyright (C) 2004 - 2005, Andy Powell 
  *
@@ -199,33 +199,33 @@ static int math_exec(struct ast_channel *chan, void *data)
                }
        case GTFUNCTION :
                if (fnum1 > fnum2)
-                       strncpy (user_result, "TRUE", sizeof (user_result) - 1);
+                       strcpy(user_result, "TRUE");
                else
-                       strncpy (user_result, "FALSE", sizeof (user_result) - 1);
+                       strcpy(user_result, "FALSE");
                break;
        case LTFUNCTION :
                if (fnum1 < fnum2)
-                       strncpy (user_result, "TRUE", sizeof (user_result) - 1);
+                       strcpy(user_result, "TRUE");
                else
-                       strncpy (user_result, "FALSE", sizeof (user_result) - 1);
+                       strcpy(user_result, "FALSE");
                break;
        case GTEFUNCTION :
                if (fnum1 >= fnum2)
-                       strncpy (user_result, "TRUE", sizeof (user_result) - 1);
+                       strcpy(user_result, "TRUE");
                else
-                       strncpy (user_result, "FALSE", sizeof (user_result) - 1);
+                       strcpy(user_result, "FALSE");
                break;
        case LTEFUNCTION :
                if (fnum1 <= fnum2)
-                       strncpy (user_result, "TRUE", sizeof (user_result) - 1);
+                       strcpy(user_result, "TRUE");
                else
-                       strncpy (user_result, "FALSE", sizeof (user_result) - 1);
+                       strcpy(user_result, "FALSE");
                break;                                  
        case EQFUNCTION :
                if (fnum1 == fnum2)
-                       strncpy (user_result, "TRUE", sizeof (user_result) - 1);
+                       strcpy(user_result, "TRUE");
                else
-                       strncpy (user_result, "FALSE", sizeof (user_result) - 1);
+                       strcpy(user_result, "FALSE");
                break;
        default :
                ast_log(LOG_WARNING, "Something happened that neither of us should be proud of %d\n", iaction);
index 68e9653..5104502 100755 (executable)
@@ -93,7 +93,7 @@ static int setcallerid_exec(struct ast_channel *chan, void *data)
        char *opt;
        int anitoo = 0;
        if (data)
-               strncpy(tmp, (char *)data, sizeof(tmp) - 1);
+               ast_copy_string(tmp, (char *)data, sizeof(tmp));
        opt = strchr(tmp, '|');
        if (opt) {
                *opt = '\0';
index 20cb23e..4126942 100755 (executable)
@@ -61,7 +61,7 @@ static int setcallerid_exec(struct ast_channel *chan, void *data)
        }
 
        if (data)
-               strncpy(tmp, (char *)data, sizeof(tmp) - 1);
+               ast_copy_string(tmp, (char *)data, sizeof(tmp));
        opt = strchr(tmp, '|');
        if (opt) {
                *opt = '\0';
index 5169979..befa9ce 100755 (executable)
@@ -63,7 +63,7 @@ static int setcallerid_exec(struct ast_channel *chan, void *data)
        }
 
        if (data)
-               strncpy(tmp, (char *)data, sizeof(tmp) - 1);
+               ast_copy_string(tmp, (char *)data, sizeof(tmp));
        opt = strchr(tmp, '|');
        if (opt) {
                *opt = '\0';
index 542f039..44adf1a 100755 (executable)
@@ -59,7 +59,7 @@ static int setrdnis_exec(struct ast_channel *chan, void *data)
        }
 
        if (data)
-               strncpy(tmp, (char *)data, sizeof(tmp) - 1);
+               ast_copy_string(tmp, (char *)data, sizeof(tmp));
        else
                tmp[0] = '\0';
        opt = strchr(tmp, '|');
index d9c6dc5..1242415 100755 (executable)
@@ -66,7 +66,7 @@ static int settransfercapability_exec(struct ast_channel *chan, void *data)
        int transfercapability = -1;
        
        if (data)
-               strncpy(tmp, (char *)data, sizeof(tmp) - 1);
+               ast_copy_string(tmp, (char *)data, sizeof(tmp));
        opts = strchr(tmp, '|');
        if (opts)
                *opts = '\0';
index 8c2c430..c2ffa4a 100755 (executable)
@@ -848,11 +848,11 @@ static void sms_writefile (sms_t * h)
 {
        char fn[200] = "", fn2[200] = "";
        FILE *o;
-       strncpy (fn, spool_dir, sizeof (fn) - 1);
+       ast_copy_string (fn, spool_dir, sizeof (fn));
        mkdir (fn, 0777);                       /* ensure it exists */
        snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", h->smsc ? h->rx ? "morx" : "mttx" : h->rx ? "mtrx" : "motx");
        mkdir (fn, 0777);                       /* ensure it exists */
-       strncpy (fn2, fn, sizeof (fn2) - 1);
+       ast_copy_string (fn2, fn, sizeof (fn2));
        snprintf (fn2 + strlen (fn2), sizeof (fn2) - strlen (fn2), "/%s.%s-%d", h->queue, isodate (h->scts), seq++);
        snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/.%s", fn2 + strlen (fn) + 1);
        o = fopen (fn, "w");
@@ -951,7 +951,7 @@ static unsigned char sms_handleincoming (sms_t * h)
                        h->srr = ((h->imsg[2] & 0x20) ? 1 : 0);
                        h->udhi = ((h->imsg[2] & 0x40) ? 1 : 0);
                        h->rp = ((h->imsg[2] & 0x80) ? 1 : 0);
-                       strncpy (h->oa, h->cli, sizeof (h->oa) - 1);
+                       ast_copy_string (h->oa, h->cli, sizeof (h->oa));
                        h->scts = time (0);
                        h->mr = h->imsg[p++];
                        p += unpackaddress (h->da, h->imsg + p);
@@ -1018,7 +1018,7 @@ static void sms_nextoutgoing (sms_t * h)
        char fn[100 + NAME_MAX] = "";
        DIR *d;
        char more = 0;
-       strncpy (fn, spool_dir, sizeof (fn) - 1);
+       ast_copy_string (fn, spool_dir, sizeof (fn));
        mkdir (fn, 0777);                               /* ensure it exists */
        h->rx = 0;                                               /* outgoing message */
        snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", h->smsc ? "mttx" : "motx");
@@ -1360,7 +1360,7 @@ static int sms_exec (struct ast_channel *chan, void *data)
        }
 
        if (chan->cid.cid_num)
-               strncpy (h.cli, chan->cid.cid_num, sizeof (h.cli) - 1);
+               ast_copy_string (h.cli, chan->cid.cid_num, sizeof (h.cli));
 
        {
                unsigned char *d = data,
@@ -1422,12 +1422,12 @@ static int sms_exec (struct ast_channel *chan, void *data)
                                return 0;
                        }
                        if (h.smsc) {
-                               strncpy (h.oa, d, sizeof (h.oa) - 1);
+                               ast_copy_string (h.oa, d, sizeof (h.oa));
                        } else {
-                               strncpy (h.da, d, sizeof (h.da) - 1);
+                               ast_copy_string (h.da, d, sizeof (h.da));
                        }
                        if (!h.smsc)
-                               strncpy (h.oa, h.cli, sizeof (h.oa) - 1);
+                               ast_copy_string (h.oa, h.cli, sizeof (h.oa));
                        d = p;
                        h.udl = 0;
                        while (*p && h.udl < SMSLEN)
index 52aaa78..117b835 100755 (executable)
@@ -70,7 +70,7 @@ static int background_detect_exec(struct ast_channel *chan, void *data)
                ast_log(LOG_WARNING, "BackgroundDetect requires an argument (filename)\n");
                return -1;
        }
-       strncpy(tmp, (char *)data, sizeof(tmp)-1);
+       ast_copy_string(tmp, (char *)data, sizeof(tmp));
        stringp=tmp;
        strsep(&stringp, "|");
        options = strsep(&stringp, "|");
@@ -158,7 +158,7 @@ static int background_detect_exec(struct ast_channel *chan, void *data)
                                                                        pbx_builtin_setvar_helper(chan, "TALK_DETECTED", ms_str);
                                                                        
                                                                        if (ast_exists_extension(chan, chan->context, "talk", 1, chan->cid.cid_num)) {
-                                                                               strncpy(chan->exten, "talk", sizeof(chan->exten) -1 );
+                                                                               ast_copy_string(chan->exten, "talk", sizeof(chan->exten));
                                                                                chan->priority = 0;
                                                                        }
                                                                        res = 0;
index 0a2e430..d018cbd 100755 (executable)
@@ -95,9 +95,9 @@ static int load_config(void)
        cfg = ast_config_load(ENUM_CONFIG);
        if (cfg) {
                if (!(s=ast_variable_retrieve(cfg, "general", "h323driver"))) {
-                       strncpy(h323driver, H323DRIVERDEFAULT, sizeof(h323driver) - 1);
+                       ast_copy_string(h323driver, H323DRIVERDEFAULT, sizeof(h323driver));
                } else {
-                       strncpy(h323driver, s, sizeof(h323driver) - 1);
+                       ast_copy_string(h323driver, s, sizeof(h323driver));
                }
                ast_config_destroy(cfg);
                return 0;
index faed715..b325963 100755 (executable)
@@ -193,7 +193,7 @@ static int zapras_exec(struct ast_channel *chan, void *data)
        if (!data) 
                data = "";
        LOCAL_USER_ADD(u);
-       strncpy(args, data, sizeof(args) - 1);
+       ast_copy_string(args, data, sizeof(args));
        /* Answer the channel if it's not up */
        if (chan->_state != AST_STATE_UP)
                ast_answer(chan);
index 0ce58bb..20f6c65 100755 (executable)
@@ -332,7 +332,7 @@ static int conf_exec(struct ast_channel *chan, void *data)
                }
                if ( tempchan && tempchan->type && (!strcmp(tempchan->type, "Zap")) && (tempchan != chan) ) {
                        ast_verbose(VERBOSE_PREFIX_3 "Zap channel %s is in-use, monitoring...\n", tempchan->name);
-                       strncpy(confstr, tempchan->name, sizeof(confstr) - 1);
+                       ast_copy_string(confstr, tempchan->name, sizeof(confstr));
                        ast_mutex_unlock(&tempchan->lock);
                        if ((tmp = strchr(confstr,'-'))) {
                                *tmp = '\0';