constification and code simplifications
authorLuigi Rizzo <rizzo@icir.org>
Fri, 14 Apr 2006 22:02:19 +0000 (22:02 +0000)
committerLuigi Rizzo <rizzo@icir.org>
Fri, 14 Apr 2006 22:02:19 +0000 (22:02 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@20165 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_voicemail.c
include/asterisk/adsi.h
res/res_adsi.c

index d64c496..f8e8219 100644 (file)
@@ -769,7 +769,7 @@ static void vm_change_password_shell(struct ast_vm_user *vmu, char *newpassword)
                ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
 }
 
-static int make_dir(char *dest, int len, char *context, char *ext, char *folder)
+static int make_dir(char *dest, int len, const char *context, const char *ext, const char *folder)
 {
        return snprintf(dest, len, "%s%s/%s/%s", VM_SPOOL_DIR, context, ext, folder);
 }
@@ -786,7 +786,7 @@ static int make_file(char *dest, int len, char *dir, int num)
  * \param folder  String. Ignored if is null or empty string. 
  * \return 0 on failure, 1 on success.
  */
-static int create_dirpath(char *dest, int len, char *context, char *ext, char *folder)
+static int create_dirpath(char *dest, int len, const char *context, const char *ext, const char *folder)
 {
        mode_t  mode = VOICEMAIL_DIR_MODE;
 
@@ -1929,10 +1929,7 @@ static int invent_message(struct ast_channel *chan, char *context, char *ext, in
                if (res)
                        return res;
        }
-       if (busy)
-               res = ast_streamfile(chan, "vm-isonphone", chan->language);
-       else
-               res = ast_streamfile(chan, "vm-isunavail", chan->language);
+       res = ast_streamfile(chan, busy ? "vm-isonphone" : "vm-isunavail", chan->language);
        if (res)
                return -1;
        res = ast_waitstream(chan, ecodes);
@@ -1950,32 +1947,21 @@ static void free_zone(struct vm_zone *z)
        free(z);
 }
 
-static char *mbox(int id)
+static const char *mbox(int id)
 {
-       switch(id) {
-       case 0:
-               return "INBOX";
-       case 1:
-               return "Old";
-       case 2:
-               return "Work";
-       case 3:
-               return "Family";
-       case 4:
-               return "Friends";
-       case 5:
-               return "Cust1";
-       case 6:
-               return "Cust2";
-       case 7:
-               return "Cust3";
-       case 8:
-               return "Cust4";
-       case 9:
-               return "Cust5";
-       default:
-               return "Unknown";
-       }
+       static const char *msgs[] = {
+               "INBOX",
+               "Old",
+               "Work",   
+               "Family",
+               "Friends",
+               "Cust1",
+               "Cust2",
+               "Cust3",
+               "Cust4",  
+               "Cust5",
+       };
+       return (id >= 0 && id < (sizeof(msgs)/sizeof(msgs[0]))) ? msgs[id] : "Unknown";
 }
 
 #ifdef USE_ODBC_STORAGE
@@ -2279,7 +2265,7 @@ static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu,
 static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt)
 {
        char fromdir[256], todir[256], frompath[256], topath[256];
-       char *frombox = mbox(imbox);
+       const char *frombox = mbox(imbox);
        int recipmsgnum;
 
        ast_log(LOG_NOTICE, "Copying message from %s@%s to %s@%s\n", vmu->mailbox, vmu->context, recip->mailbox, recip->context);
@@ -2389,17 +2375,14 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
        ext = tmp;
        context = strchr(tmp, '@');
        if (context) {
-               *context = '\0';
-               context++;
+               *context++ = '\0';
                tmpptr = strchr(context, '&');
        } else {
                tmpptr = strchr(ext, '&');
        }
 
-       if (tmpptr) {
-               *tmpptr = '\0';
-               tmpptr++;
-       }
+       if (tmpptr)
+               *tmpptr++ = '\0';
 
        category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY");
 
@@ -2693,7 +2676,7 @@ static int save_to_folder(struct ast_vm_user *vmu, char *dir, int msg, char *con
        char sfn[256];
        char dfn[256];
        char ddir[256];
-       char *dbox = mbox(box);
+       const char *dbox = mbox(box);
        int x;
        make_file(sfn, sizeof(sfn), dir, msg);
        create_dirpath(ddir, sizeof(ddir), context, username, dbox);
@@ -5899,26 +5882,20 @@ static char *complete_show_voicemail_users(const char *line, const char *word, i
        int which = 0;
        int wordlen;
        struct ast_vm_user *vmu;
-       char *context = "";
+       const char *context = "";
 
        /* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <context> */
        if (pos > 4)
                return NULL;
-       if (pos == 3) {
-               if (state == 0)
-                       return strdup("for");
-               else
-                       return NULL;
-       }
+       if (pos == 3)
+               return (state == 0) ? ast_strdup("for") : NULL;
        wordlen = strlen(word);
        AST_LIST_TRAVERSE(&users, vmu, list) {
                if (!strncasecmp(word, vmu->context, wordlen)) {
-                       if (context && strcmp(context, vmu->context)) {
-                               if (++which > state) {
-                                       return strdup(vmu->context);
-                               }
-                               context = vmu->context;
-                       }
+                       if (context && strcmp(context, vmu->context) && ++which > state)
+                               return ast_strdup(vmu->context);
+                       /* ignore repeated contexts ? */
+                       context = vmu->context;
                }
        }
        return NULL;
@@ -5980,7 +5957,7 @@ static int load_config(void)
                ast_set_flag(cur, VM_ALLOCED);  
                free_user(cur);
        }
-       AST_LIST_TRAVERSE_SAFE_END
+       AST_LIST_TRAVERSE_SAFE_END;
        zcur = zones;
        while (zcur) {
                zl = zcur;
index 97a7856..3b7a2d1 100644 (file)
@@ -309,7 +309,7 @@ int adsi_set_line(unsigned char *buf, int page, int line);
  * Returns number of bytes added to buffer or -1 on error.
  *
  */
-int adsi_load_soft_key(unsigned char *buf, int key, char *llabel, char *slabel, char *ret, int data);
+int adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, const char *ret, int data);
 
 /*! Set which soft keys should be displayed */
 /*!
index 730b336..2e0a004 100644 (file)
@@ -428,7 +428,7 @@ int adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msgl
        return adsi_transmit_message_full(chan, msg, msglen, msgtype, 1);
 }
 
-static inline int ccopy(unsigned char *dst, unsigned char *src, int max)
+static inline int ccopy(unsigned char *dst, const unsigned char *src, int max)
 {
        int x=0;
        /* Carefully copy the requested data */
@@ -439,7 +439,7 @@ static inline int ccopy(unsigned char *dst, unsigned char *src, int max)
        return x;
 }
 
-int adsi_load_soft_key(unsigned char *buf, int key, char *llabel, char *slabel, char *ret, int data)
+int adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, const char *ret, int data)
 {
        int bytes=0;
 
@@ -453,13 +453,13 @@ int adsi_load_soft_key(unsigned char *buf, int key, char *llabel, char *slabel,
        buf[bytes++] = key;
 
        /* Carefully copy long label */
-       bytes += ccopy(buf + bytes, (unsigned char *)llabel, 18);
+       bytes += ccopy(buf + bytes, (const unsigned char *)llabel, 18);
 
        /* Place delimiter */
        buf[bytes++] = 0xff;
 
        /* Short label */
-       bytes += ccopy(buf + bytes, (unsigned char *)slabel, 7);
+       bytes += ccopy(buf + bytes, (const unsigned char *)slabel, 7);
 
 
        /* If specified, copy return string */
@@ -469,7 +469,7 @@ int adsi_load_soft_key(unsigned char *buf, int key, char *llabel, char *slabel,
                if (data)
                        buf[bytes++] = ADSI_SWITCH_TO_DATA2;
                /* Carefully copy return string */
-               bytes += ccopy(buf + bytes, (unsigned char *)ret, 20);
+               bytes += ccopy(buf + bytes, (const unsigned char *)ret, 20);
 
        }
        /* Replace parameter length */