From 9d8d86e19de01ea94e3106d78af8aa44e6670745 Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Fri, 15 Jul 2005 22:06:15 +0000 Subject: [PATCH] phase two of string portability stuff: don't need ast_ prefixes on functions use individual #defines for function presence add vasprintf to portability library git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6143 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_directory.c | 2 +- channel.c | 4 +-- channels/chan_sip.c | 10 ++++---- cli.c | 7 +----- include/asterisk/strings.h | 34 +++++++++++++++++++------ pbx.c | 4 +-- res/res_agi.c | 3 --- utils.c | 51 ++++++++++++++++++++++++++++---------- 8 files changed, 75 insertions(+), 40 deletions(-) diff --git a/apps/app_directory.c b/apps/app_directory.c index 252b437872..ad21736c4b 100755 --- a/apps/app_directory.c +++ b/apps/app_directory.c @@ -332,7 +332,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char * while(v) { /* Find a candidate extension */ start = strdup(v->value); - if (start && !ast_strcasestr(start, "hidefromdir=yes")) { + if (start && !strcasestr(start, "hidefromdir=yes")) { stringp=start; strsep(&stringp, ","); pos = strsep(&stringp, ","); diff --git a/channel.c b/channel.c index ae9d98f6b4..e97ae91c30 100755 --- a/channel.c +++ b/channel.c @@ -1753,8 +1753,8 @@ char *ast_recvtext(struct ast_channel *chan, int timeout) break; /* no frame */ if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) done = 1; /* force a break */ - else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ - buf = ast_strndup((char *) f->data, f->datalen); /* dup and break */ + else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ + buf = strndup((char *) f->data, f->datalen); /* dup and break */ done = 1; } ast_frfree(f); diff --git a/channels/chan_sip.c b/channels/chan_sip.c index f904a612dd..16a8365079 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -2900,7 +2900,7 @@ static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *si ast_copy_string(tmp, get_header(req, "To"), sizeof(tmp)); else ast_copy_string(tmp, get_header(req, "From"), sizeof(tmp)); - tag = ast_strcasestr(tmp, "tag="); + tag = strcasestr(tmp, "tag="); if (tag) { tag += 4; c = strchr(tag, ';'); @@ -3671,7 +3671,7 @@ static int respprep(struct sip_request *resp, struct sip_pvt *p, char *msg, stru copy_all_header(resp, req, "Record-Route"); copy_header(resp, req, "From"); ot = get_header(req, "To"); - if (!ast_strcasestr(ot, "tag=") && strncmp(msg, "100", 3)) { + if (!strcasestr(ot, "tag=") && strncmp(msg, "100", 3)) { /* Add the proper tag if we don't have it already. If they have specified their tag, use it. Otherwise, use our own tag */ if (!ast_strlen_zero(p->theirtag) && ast_test_flag(p, SIP_OUTGOING)) @@ -3770,7 +3770,7 @@ static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, in /* Add tag *unless* this is a CANCEL, in which case we need to send it exactly as our original request, including tag (or presumably lack thereof) */ - if (!ast_strcasestr(ot, "tag=") && sipmethod != SIP_CANCEL) { + if (!strcasestr(ot, "tag=") && sipmethod != SIP_CANCEL) { /* Add the proper tag if we don't have it already. If they have specified their tag, use it. Otherwise, use our own tag */ if (ast_test_flag(p, SIP_OUTGOING) && !ast_strlen_zero(p->theirtag)) @@ -8428,7 +8428,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_ /* Get their tag if we haven't already */ if (ast_strlen_zero(p->theirtag)) { to = get_header(req, "To"); - to = ast_strcasestr(to, "tag="); + to = strcasestr(to, "tag="); if (to) { to += 4; ast_copy_string(p->theirtag, to, sizeof(p->theirtag)); @@ -9540,7 +9540,7 @@ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct soc /* Find their tag if we haven't got it */ if (ast_strlen_zero(p->theirtag)) { from = get_header(req, "From"); - from = ast_strcasestr(from, "tag="); + from = strcasestr(from, "tag="); if (from) { from += 4; ast_copy_string(p->theirtag, from, sizeof(p->theirtag)); diff --git a/cli.c b/cli.c index af77b5af5a..f539cb33a5 100755 --- a/cli.c +++ b/cli.c @@ -47,15 +47,10 @@ void ast_cli(int fd, char *fmt, ...) { char *stuff; int res = 0; - va_list ap; + va_start(ap, fmt); -#ifdef SOLARIS - stuff = (char *)malloc(10240); - vsnprintf(stuff, 10240, fmt, ap); -#else res = vasprintf(&stuff, fmt, ap); -#endif va_end(ap); if (res == -1) { ast_log(LOG_ERROR, "Out of memory\n"); diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index f6902ef1b3..70131cd9d3 100755 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -197,14 +197,32 @@ struct ast_realloca { (ra)->ptr; \ }) +#define HAVE_VASPRINTF + #ifdef __linux__ -#define ast_strcasestr strcasestr -#define ast_strndup strndup -#define ast_strnlen strnlen -#else /* !__linux__ */ -char *ast_strcasestr(const char *, const char *); -char *ast_strndup(const char *, size_t); -size_t ast_strnlen(const char *, size_t); -#endif /* !__linux__ */ +#define HAVE_STRCASESTR +#define HAVE_STRNDUP +#define HAVE_STRNLEN +#endif + +#ifdef SOLARIS +#undef HAVE_VASPRINTF +#endif + +#ifndef HAVE_STRCASESTR +char *strcasestr(const char *, const char *); +#endif + +#ifndef HAVE_STRNDUP +char *strndup(const char *, size_t); +#endif + +#ifndef HAVE_STRNLEN +size_t strnlen(const char *, size_t); +#endif + +#ifndef HAVE_VASPRINTF +int vasprintf(char **strp, const char *fmt, va_list ap); +#endif #endif /* _ASTERISK_STRINGS_H */ diff --git a/pbx.c b/pbx.c index f3360babc8..3d1d002ff9 100755 --- a/pbx.c +++ b/pbx.c @@ -3104,7 +3104,7 @@ static int handle_show_applications(int fd, int argc, char *argv[]) int printapp=0; total_apps++; if (like) { - if (ast_strcasestr(a->name, argv[3])) { + if (strcasestr(a->name, argv[3])) { printapp = 1; total_match++; } @@ -3114,7 +3114,7 @@ static int handle_show_applications(int fd, int argc, char *argv[]) int i; printapp = 1; for (i=3;idescription, argv[i])) { + if (!strcasestr(a->description, argv[i])) { printapp = 0; } else { total_match++; diff --git a/res/res_agi.c b/res/res_agi.c index df1d7a6a01..dd1f161c72 100755 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -51,9 +51,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/lock.h" #include "asterisk/agi.h" -#ifdef SOLARIS -#include "asterisk/astmm.h" -#endif #define MAX_ARGS 128 #define MAX_COMMANDS 128 diff --git a/utils.c b/utils.c index ba0b476bb0..1ab8c690d1 100755 --- a/utils.c +++ b/utils.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "asterisk.h" @@ -492,22 +493,22 @@ int ast_false(const char *s) return 0; } -/* Case-insensitive substring matching */ -#ifndef __linux__ +#ifndef HAVE_STRCASESTR static char *upper(const char *orig, char *buf, int bufsize) { - int i; - memset(buf, 0, bufsize); - for (i=0; i