dect
/
asterisk
Archived
13
0
Fork 0

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: http://svn.digium.com/svn/asterisk/trunk@6143 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
kpfleming 2005-07-15 22:06:15 +00:00
parent 467a58ed8f
commit 63a6a077da
8 changed files with 75 additions and 40 deletions

View File

@ -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, ",");

View File

@ -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);

View File

@ -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));

7
cli.c
View File

@ -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");

View File

@ -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 */

4
pbx.c
View File

@ -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;i<argc;i++) {
if (! ast_strcasestr(a->description, argv[i])) {
if (!strcasestr(a->description, argv[i])) {
printapp = 0;
} else {
total_match++;

View File

@ -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

51
utils.c
View File

@ -20,6 +20,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#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<bufsize - 1; i++) {
int i = 0;
while (i < (bufsize - 1) && orig[i]) {
buf[i] = toupper(orig[i]);
if (orig[i] == '\0') {
break;
}
i++;
}
buf[i] = '\0';
return buf;
}
char *ast_strcasestr(const char *haystack, const char *needle)
char *strcasestr(const char *haystack, const char *needle)
{
char *u1, *u2;
int u1len = strlen(haystack) + 1, u2len = strlen(needle) + 1;
@ -532,8 +533,10 @@ char *ast_strcasestr(const char *haystack, const char *needle)
return NULL;
}
}
#endif
size_t ast_strnlen(const char *s, size_t n)
#ifndef HAVE_STRNLEN
size_t strnlen(const char *s, size_t n)
{
size_t len;
@ -543,10 +546,12 @@ size_t ast_strnlen(const char *s, size_t n)
return len;
}
#endif
char *ast_strndup(const char *s, size_t n)
#ifndef HAVE_STRNDUP
char *strndup(const char *s, size_t n)
{
size_t len = ast_strnlen(s, n);
size_t len = strnlen(s, n);
char *new = malloc(len + 1);
if (!new)
@ -555,5 +560,25 @@ char *ast_strndup(const char *s, size_t n)
new[len] = '\0';
return memcpy(new, s, len);
}
#endif
#endif /* !__linux__ */
#ifndef HAVE_VASPRINTF
int vasprintf(char **strp, const char *fmt, va_list ap)
{
int size;
va_list ap2;
*strp = NULL;
va_copy(ap2, ap);
size = vsnprintf(*strp, 0, fmt, ap2);
va_end(ap2);
*strp = malloc(size + 1);
if (!*strp)
return -1;
va_start(fmt, ap);
vsnprintf(*strp, size + 1, fmt, ap);
va_end(ap);
return size;
}
#endif