constification and code simplifications

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@20165 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Luigi Rizzo
2006-04-14 22:02:19 +00:00
parent 1029b57707
commit 62712ea668
3 changed files with 36 additions and 59 deletions

View 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)); 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); 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. * \param folder String. Ignored if is null or empty string.
* \return 0 on failure, 1 on success. * \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; 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) if (res)
return res; return res;
} }
if (busy) res = ast_streamfile(chan, busy ? "vm-isonphone" : "vm-isunavail", chan->language);
res = ast_streamfile(chan, "vm-isonphone", chan->language);
else
res = ast_streamfile(chan, "vm-isunavail", chan->language);
if (res) if (res)
return -1; return -1;
res = ast_waitstream(chan, ecodes); res = ast_waitstream(chan, ecodes);
@@ -1950,32 +1947,21 @@ static void free_zone(struct vm_zone *z)
free(z); free(z);
} }
static char *mbox(int id) static const char *mbox(int id)
{ {
switch(id) { static const char *msgs[] = {
case 0: "INBOX",
return "INBOX"; "Old",
case 1: "Work",
return "Old"; "Family",
case 2: "Friends",
return "Work"; "Cust1",
case 3: "Cust2",
return "Family"; "Cust3",
case 4: "Cust4",
return "Friends"; "Cust5",
case 5: };
return "Cust1"; return (id >= 0 && id < (sizeof(msgs)/sizeof(msgs[0]))) ? msgs[id] : "Unknown";
case 6:
return "Cust2";
case 7:
return "Cust3";
case 8:
return "Cust4";
case 9:
return "Cust5";
default:
return "Unknown";
}
} }
#ifdef USE_ODBC_STORAGE #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) 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 fromdir[256], todir[256], frompath[256], topath[256];
char *frombox = mbox(imbox); const char *frombox = mbox(imbox);
int recipmsgnum; int recipmsgnum;
ast_log(LOG_NOTICE, "Copying message from %s@%s to %s@%s\n", vmu->mailbox, vmu->context, recip->mailbox, recip->context); 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; ext = tmp;
context = strchr(tmp, '@'); context = strchr(tmp, '@');
if (context) { if (context) {
*context = '\0'; *context++ = '\0';
context++;
tmpptr = strchr(context, '&'); tmpptr = strchr(context, '&');
} else { } else {
tmpptr = strchr(ext, '&'); tmpptr = strchr(ext, '&');
} }
if (tmpptr) { if (tmpptr)
*tmpptr = '\0'; *tmpptr++ = '\0';
tmpptr++;
}
category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY"); 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 sfn[256];
char dfn[256]; char dfn[256];
char ddir[256]; char ddir[256];
char *dbox = mbox(box); const char *dbox = mbox(box);
int x; int x;
make_file(sfn, sizeof(sfn), dir, msg); make_file(sfn, sizeof(sfn), dir, msg);
create_dirpath(ddir, sizeof(ddir), context, username, dbox); create_dirpath(ddir, sizeof(ddir), context, username, dbox);
@@ -5899,28 +5882,22 @@ static char *complete_show_voicemail_users(const char *line, const char *word, i
int which = 0; int which = 0;
int wordlen; int wordlen;
struct ast_vm_user *vmu; struct ast_vm_user *vmu;
char *context = ""; const char *context = "";
/* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <context> */ /* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <context> */
if (pos > 4) if (pos > 4)
return NULL; return NULL;
if (pos == 3) { if (pos == 3)
if (state == 0) return (state == 0) ? ast_strdup("for") : NULL;
return strdup("for");
else
return NULL;
}
wordlen = strlen(word); wordlen = strlen(word);
AST_LIST_TRAVERSE(&users, vmu, list) { AST_LIST_TRAVERSE(&users, vmu, list) {
if (!strncasecmp(word, vmu->context, wordlen)) { if (!strncasecmp(word, vmu->context, wordlen)) {
if (context && strcmp(context, vmu->context)) { if (context && strcmp(context, vmu->context) && ++which > state)
if (++which > state) { return ast_strdup(vmu->context);
return strdup(vmu->context); /* ignore repeated contexts ? */
}
context = vmu->context; context = vmu->context;
} }
} }
}
return NULL; return NULL;
} }
@@ -5980,7 +5957,7 @@ static int load_config(void)
ast_set_flag(cur, VM_ALLOCED); ast_set_flag(cur, VM_ALLOCED);
free_user(cur); free_user(cur);
} }
AST_LIST_TRAVERSE_SAFE_END AST_LIST_TRAVERSE_SAFE_END;
zcur = zones; zcur = zones;
while (zcur) { while (zcur) {
zl = zcur; zl = zcur;

View 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. * 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 */ /*! Set which soft keys should be displayed */
/*! /*!

View 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); 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; int x=0;
/* Carefully copy the requested data */ /* Carefully copy the requested data */
@@ -439,7 +439,7 @@ static inline int ccopy(unsigned char *dst, unsigned char *src, int max)
return x; 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; int bytes=0;
@@ -453,13 +453,13 @@ int adsi_load_soft_key(unsigned char *buf, int key, char *llabel, char *slabel,
buf[bytes++] = key; buf[bytes++] = key;
/* Carefully copy long label */ /* Carefully copy long label */
bytes += ccopy(buf + bytes, (unsigned char *)llabel, 18); bytes += ccopy(buf + bytes, (const unsigned char *)llabel, 18);
/* Place delimiter */ /* Place delimiter */
buf[bytes++] = 0xff; buf[bytes++] = 0xff;
/* Short label */ /* Short label */
bytes += ccopy(buf + bytes, (unsigned char *)slabel, 7); bytes += ccopy(buf + bytes, (const unsigned char *)slabel, 7);
/* If specified, copy return string */ /* 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) if (data)
buf[bytes++] = ADSI_SWITCH_TO_DATA2; buf[bytes++] = ADSI_SWITCH_TO_DATA2;
/* Carefully copy return string */ /* Carefully copy return string */
bytes += ccopy(buf + bytes, (unsigned char *)ret, 20); bytes += ccopy(buf + bytes, (const unsigned char *)ret, 20);
} }
/* Replace parameter length */ /* Replace parameter length */