mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
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
This commit is contained in:
@@ -332,7 +332,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
|
|||||||
while(v) {
|
while(v) {
|
||||||
/* Find a candidate extension */
|
/* Find a candidate extension */
|
||||||
start = strdup(v->value);
|
start = strdup(v->value);
|
||||||
if (start && !ast_strcasestr(start, "hidefromdir=yes")) {
|
if (start && !strcasestr(start, "hidefromdir=yes")) {
|
||||||
stringp=start;
|
stringp=start;
|
||||||
strsep(&stringp, ",");
|
strsep(&stringp, ",");
|
||||||
pos = strsep(&stringp, ",");
|
pos = strsep(&stringp, ",");
|
||||||
|
@@ -1754,7 +1754,7 @@ char *ast_recvtext(struct ast_channel *chan, int timeout)
|
|||||||
if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
|
if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
|
||||||
done = 1; /* force a break */
|
done = 1; /* force a break */
|
||||||
else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
|
else if (f->frametype == AST_FRAME_TEXT) { /* what we want */
|
||||||
buf = ast_strndup((char *) f->data, f->datalen); /* dup and break */
|
buf = strndup((char *) f->data, f->datalen); /* dup and break */
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
ast_frfree(f);
|
ast_frfree(f);
|
||||||
|
@@ -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));
|
ast_copy_string(tmp, get_header(req, "To"), sizeof(tmp));
|
||||||
else
|
else
|
||||||
ast_copy_string(tmp, get_header(req, "From"), sizeof(tmp));
|
ast_copy_string(tmp, get_header(req, "From"), sizeof(tmp));
|
||||||
tag = ast_strcasestr(tmp, "tag=");
|
tag = strcasestr(tmp, "tag=");
|
||||||
if (tag) {
|
if (tag) {
|
||||||
tag += 4;
|
tag += 4;
|
||||||
c = strchr(tag, ';');
|
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_all_header(resp, req, "Record-Route");
|
||||||
copy_header(resp, req, "From");
|
copy_header(resp, req, "From");
|
||||||
ot = get_header(req, "To");
|
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
|
/* Add the proper tag if we don't have it already. If they have specified
|
||||||
their tag, use it. Otherwise, use our own tag */
|
their tag, use it. Otherwise, use our own tag */
|
||||||
if (!ast_strlen_zero(p->theirtag) && ast_test_flag(p, SIP_OUTGOING))
|
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
|
/* 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) */
|
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
|
/* Add the proper tag if we don't have it already. If they have specified
|
||||||
their tag, use it. Otherwise, use our own tag */
|
their tag, use it. Otherwise, use our own tag */
|
||||||
if (ast_test_flag(p, SIP_OUTGOING) && !ast_strlen_zero(p->theirtag))
|
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 */
|
/* Get their tag if we haven't already */
|
||||||
if (ast_strlen_zero(p->theirtag)) {
|
if (ast_strlen_zero(p->theirtag)) {
|
||||||
to = get_header(req, "To");
|
to = get_header(req, "To");
|
||||||
to = ast_strcasestr(to, "tag=");
|
to = strcasestr(to, "tag=");
|
||||||
if (to) {
|
if (to) {
|
||||||
to += 4;
|
to += 4;
|
||||||
ast_copy_string(p->theirtag, to, sizeof(p->theirtag));
|
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 */
|
/* Find their tag if we haven't got it */
|
||||||
if (ast_strlen_zero(p->theirtag)) {
|
if (ast_strlen_zero(p->theirtag)) {
|
||||||
from = get_header(req, "From");
|
from = get_header(req, "From");
|
||||||
from = ast_strcasestr(from, "tag=");
|
from = strcasestr(from, "tag=");
|
||||||
if (from) {
|
if (from) {
|
||||||
from += 4;
|
from += 4;
|
||||||
ast_copy_string(p->theirtag, from, sizeof(p->theirtag));
|
ast_copy_string(p->theirtag, from, sizeof(p->theirtag));
|
||||||
|
7
cli.c
7
cli.c
@@ -47,15 +47,10 @@ void ast_cli(int fd, char *fmt, ...)
|
|||||||
{
|
{
|
||||||
char *stuff;
|
char *stuff;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
#ifdef SOLARIS
|
|
||||||
stuff = (char *)malloc(10240);
|
|
||||||
vsnprintf(stuff, 10240, fmt, ap);
|
|
||||||
#else
|
|
||||||
res = vasprintf(&stuff, fmt, ap);
|
res = vasprintf(&stuff, fmt, ap);
|
||||||
#endif
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
ast_log(LOG_ERROR, "Out of memory\n");
|
ast_log(LOG_ERROR, "Out of memory\n");
|
||||||
|
@@ -197,14 +197,32 @@ struct ast_realloca {
|
|||||||
(ra)->ptr; \
|
(ra)->ptr; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#define HAVE_VASPRINTF
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define ast_strcasestr strcasestr
|
#define HAVE_STRCASESTR
|
||||||
#define ast_strndup strndup
|
#define HAVE_STRNDUP
|
||||||
#define ast_strnlen strnlen
|
#define HAVE_STRNLEN
|
||||||
#else /* !__linux__ */
|
#endif
|
||||||
char *ast_strcasestr(const char *, const char *);
|
|
||||||
char *ast_strndup(const char *, size_t);
|
#ifdef SOLARIS
|
||||||
size_t ast_strnlen(const char *, size_t);
|
#undef HAVE_VASPRINTF
|
||||||
#endif /* !__linux__ */
|
#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 */
|
#endif /* _ASTERISK_STRINGS_H */
|
||||||
|
4
pbx.c
4
pbx.c
@@ -3104,7 +3104,7 @@ static int handle_show_applications(int fd, int argc, char *argv[])
|
|||||||
int printapp=0;
|
int printapp=0;
|
||||||
total_apps++;
|
total_apps++;
|
||||||
if (like) {
|
if (like) {
|
||||||
if (ast_strcasestr(a->name, argv[3])) {
|
if (strcasestr(a->name, argv[3])) {
|
||||||
printapp = 1;
|
printapp = 1;
|
||||||
total_match++;
|
total_match++;
|
||||||
}
|
}
|
||||||
@@ -3114,7 +3114,7 @@ static int handle_show_applications(int fd, int argc, char *argv[])
|
|||||||
int i;
|
int i;
|
||||||
printapp = 1;
|
printapp = 1;
|
||||||
for (i=3;i<argc;i++) {
|
for (i=3;i<argc;i++) {
|
||||||
if (! ast_strcasestr(a->description, argv[i])) {
|
if (!strcasestr(a->description, argv[i])) {
|
||||||
printapp = 0;
|
printapp = 0;
|
||||||
} else {
|
} else {
|
||||||
total_match++;
|
total_match++;
|
||||||
|
@@ -51,9 +51,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||||||
#include "asterisk/utils.h"
|
#include "asterisk/utils.h"
|
||||||
#include "asterisk/lock.h"
|
#include "asterisk/lock.h"
|
||||||
#include "asterisk/agi.h"
|
#include "asterisk/agi.h"
|
||||||
#ifdef SOLARIS
|
|
||||||
#include "asterisk/astmm.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_ARGS 128
|
#define MAX_ARGS 128
|
||||||
#define MAX_COMMANDS 128
|
#define MAX_COMMANDS 128
|
||||||
|
51
utils.c
51
utils.c
@@ -20,6 +20,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "asterisk.h"
|
#include "asterisk.h"
|
||||||
|
|
||||||
@@ -492,22 +493,22 @@ int ast_false(const char *s)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Case-insensitive substring matching */
|
#ifndef HAVE_STRCASESTR
|
||||||
#ifndef __linux__
|
|
||||||
static char *upper(const char *orig, char *buf, int bufsize)
|
static char *upper(const char *orig, char *buf, int bufsize)
|
||||||
{
|
{
|
||||||
int i;
|
int i = 0;
|
||||||
memset(buf, 0, bufsize);
|
|
||||||
for (i=0; i<bufsize - 1; i++) {
|
while (i < (bufsize - 1) && orig[i]) {
|
||||||
buf[i] = toupper(orig[i]);
|
buf[i] = toupper(orig[i]);
|
||||||
if (orig[i] == '\0') {
|
i++;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf[i] = '\0';
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ast_strcasestr(const char *haystack, const char *needle)
|
char *strcasestr(const char *haystack, const char *needle)
|
||||||
{
|
{
|
||||||
char *u1, *u2;
|
char *u1, *u2;
|
||||||
int u1len = strlen(haystack) + 1, u2len = strlen(needle) + 1;
|
int u1len = strlen(haystack) + 1, u2len = strlen(needle) + 1;
|
||||||
@@ -532,8 +533,10 @@ char *ast_strcasestr(const char *haystack, const char *needle)
|
|||||||
return NULL;
|
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;
|
size_t len;
|
||||||
|
|
||||||
@@ -543,10 +546,12 @@ size_t ast_strnlen(const char *s, size_t n)
|
|||||||
|
|
||||||
return len;
|
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);
|
char *new = malloc(len + 1);
|
||||||
|
|
||||||
if (!new)
|
if (!new)
|
||||||
@@ -555,5 +560,25 @@ char *ast_strndup(const char *s, size_t n)
|
|||||||
new[len] = '\0';
|
new[len] = '\0';
|
||||||
return memcpy(new, s, len);
|
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
|
||||||
|
Reference in New Issue
Block a user