aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-09-23 02:40:38 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-09-23 02:40:38 +0000
commit795fe950587a0842f453c4d3a828d348596ba048 (patch)
tree0012ff0f6ebf114908e7671af34b365a898cf55b /enum.c
parent64291f076e4174d35c4f43f610dc6e9b84b36676 (diff)
fix some gcc4 pointer signedness warnings and clean up some formatting
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6628 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'enum.c')
-rwxr-xr-xenum.c288
1 files changed, 144 insertions, 144 deletions
diff --git a/enum.c b/enum.c
index d2483996d..1c47f18e7 100755
--- a/enum.c
+++ b/enum.c
@@ -101,11 +101,11 @@ static int parse_ie(char *data, int maxdatalen, char *src, int srclen)
static int parse_naptr(char *dst, int dstsize, char *tech, int techsize, char *answer, int len, char *naptrinput)
{
- char tech_return[80];
+ char tech_return[80];
char *oanswer = answer;
char flags[512] = "";
char services[512] = "";
- unsigned char *p;
+ char *p;
char regexp[512] = "";
char repl[512] = "";
char temp[512] = "";
@@ -118,7 +118,7 @@ static int parse_naptr(char *dst, int dstsize, char *tech, int techsize, char *a
regex_t preg;
regmatch_t pmatch[9];
- tech_return[0] = '\0';
+ tech_return[0] = '\0';
dst[0] = '\0';
@@ -130,30 +130,30 @@ static int parse_naptr(char *dst, int dstsize, char *tech, int techsize, char *a
len -= sizeof(struct naptr);
if ((res = parse_ie(flags, sizeof(flags) - 1, answer, len)) < 0) {
ast_log(LOG_WARNING, "Failed to get flags from NAPTR record\n");
- return -1;
- } else {
- answer += res;
- len -= res;
+ return -1;
+ } else {
+ answer += res;
+ len -= res;
}
if ((res = parse_ie(services, sizeof(services) - 1, answer, len)) < 0) {
ast_log(LOG_WARNING, "Failed to get services from NAPTR record\n");
- return -1;
- } else {
- answer += res;
- len -= res;
+ return -1;
+ } else {
+ answer += res;
+ len -= res;
}
if ((res = parse_ie(regexp, sizeof(regexp) - 1, answer, len)) < 0) {
ast_log(LOG_WARNING, "Failed to get regexp from NAPTR record\n");
- return -1;
- } else {
- answer += res;
- len -= res;
+ return -1;
+ } else {
+ answer += res;
+ len -= res;
}
if ((res = dn_expand((unsigned char *)oanswer, (unsigned char *)answer + len, (unsigned char *)answer, repl, sizeof(repl) - 1)) < 0) {
ast_log(LOG_WARNING, "Failed to expand hostname\n");
return -1;
- }
+ }
if (option_debug > 2) /* Advanced NAPTR debugging */
ast_log(LOG_DEBUG, "NAPTR input='%s', flags='%s', services='%s', regexp='%s', repl='%s'\n",
@@ -164,27 +164,27 @@ static int parse_naptr(char *dst, int dstsize, char *tech, int techsize, char *a
return -1;
}
- p = strstr(services, "e2u+");
- if(p == NULL)
- p = strstr(services, "E2U+");
- if(p){
- p = p + 4;
- if(strchr(p, ':')){
- p = strchr(p, ':') + 1;
- }
- ast_copy_string(tech_return, p, sizeof(tech_return));
+ p = strstr(services, "e2u+");
+ if (p == NULL)
+ p = strstr(services, "E2U+");
+ if (p){
+ p = p + 4;
+ if (strchr(p, ':')){
+ p = strchr(p, ':') + 1;
+ }
+ ast_copy_string(tech_return, p, sizeof(tech_return));
} else {
- p = strstr(services, "+e2u");
- if(p == NULL)
- p = strstr(services, "+E2U");
- if(p){
- *p = 0;
- p = strchr(services, ':');
- if(p)
- *p = 0;
- ast_copy_string(tech_return, services, sizeof(tech_return));
- }
+ p = strstr(services, "+e2u");
+ if (p == NULL)
+ p = strstr(services, "+E2U");
+ if (p) {
+ *p = 0;
+ p = strchr(services, ':');
+ if (p)
+ *p = 0;
+ ast_copy_string(tech_return, services, sizeof(tech_return));
+ }
}
/* DEDBUGGING STUB
@@ -195,7 +195,7 @@ static int parse_naptr(char *dst, int dstsize, char *tech, int techsize, char *a
if (regexp_len < 7) {
ast_log(LOG_WARNING, "Regex too short to be meaningful.\n");
return -1;
- }
+ }
delim = regexp[0];
@@ -238,9 +238,9 @@ static int parse_naptr(char *dst, int dstsize, char *tech, int techsize, char *a
}
regfree(&preg);
- d = temp;
- d_len--;
- while( *subst && (d_len > 0) ) {
+ d = temp;
+ d_len--;
+ while (*subst && (d_len > 0)) {
if ((subst[0] == '\\') && isdigit(subst[1]) && (pmatch[subst[1]-'0'].rm_so != -1)) {
backref = subst[1]-'0';
size = pmatch[backref].rm_eo - pmatch[backref].rm_so;
@@ -264,32 +264,32 @@ static int parse_naptr(char *dst, int dstsize, char *tech, int techsize, char *a
ast_copy_string(dst, temp, dstsize);
dst[dstsize - 1] = '\0';
- if(*tech != '\0'){ /* check if it is requested NAPTR */
- if(!strncasecmp(tech, "ALL", techsize)){
- return 1; /* return or count any RR */
- }
- if(!strncasecmp(tech_return, tech, sizeof(tech_return)<techsize?sizeof(tech_return):techsize)){
- ast_copy_string(tech, tech_return, techsize);
- return 1; /* we got out RR */
- } else { /* go to the next RR in the DNS answer */
- return 0;
- }
- }
+ if (*tech != '\0'){ /* check if it is requested NAPTR */
+ if (!strncasecmp(tech, "ALL", techsize)){
+ return 1; /* return or count any RR */
+ }
+ if (!strncasecmp(tech_return, tech, sizeof(tech_return)<techsize?sizeof(tech_return):techsize)){
+ ast_copy_string(tech, tech_return, techsize);
+ return 1; /* we got out RR */
+ } else { /* go to the next RR in the DNS answer */
+ return 0;
+ }
+ }
- /* tech was not specified, return first parsed RR */
- ast_copy_string(tech, tech_return, techsize);
+ /* tech was not specified, return first parsed RR */
+ ast_copy_string(tech, tech_return, techsize);
- return 1;
+ return 1;
}
/* do not return requested value, just count RRs and return thei number in dst */
#define ENUMLOOKUP_OPTIONS_COUNT 1
struct enum_naptr_rr {
- struct naptr naptr; /* order and preference of RR */
- char *result; /* result of naptr parsing,e.g.: tel:+5553 */
- char *tech; /* Technology (from URL scheme) */
- int sort_pos; /* sort position */
+ struct naptr naptr; /* order and preference of RR */
+ char *result; /* result of naptr parsing,e.g.: tel:+5553 */
+ char *tech; /* Technology (from URL scheme) */
+ int sort_pos; /* sort position */
};
struct enum_context {
@@ -300,10 +300,10 @@ struct enum_context {
char *txt; /* TXT record in TXT lookup */
int txtlen; /* Length */
char *naptrinput; /* The number to lookup */
- int position; /* used as counter for RRs or specifies position of required RR */
- int options; /* options , see ENUMLOOKUP_OPTIONS_* defined above */
- struct enum_naptr_rr *naptr_rrs; /* array of parsed NAPTR RRs */
- int naptr_rrs_count; /* Size of array naptr_rrs */
+ int position; /* used as counter for RRs or specifies position of required RR */
+ int options; /* options , see ENUMLOOKUP_OPTIONS_* defined above */
+ struct enum_naptr_rr *naptr_rrs; /* array of parsed NAPTR RRs */
+ int naptr_rrs_count; /* Size of array naptr_rrs */
};
/*--- txt_callback: Callback for TXT record lookup */
@@ -350,16 +350,16 @@ static int enum_callback(void *context, char *answer, int len, char *fullanswer)
res = parse_naptr(c->dst, c->dstlen, c->tech, c->techlen, answer, len, c->naptrinput);
- if(res < 0){
+ if (res < 0) {
ast_log(LOG_WARNING, "Failed to parse naptr :(\n");
return -1;
- } else if(res > 0 && !ast_strlen_zero(c->dst)){ /* ok, we got needed NAPTR */
- if(c->options & ENUMLOOKUP_OPTIONS_COUNT){ /* counting RRs */
+ } else if (res > 0 && !ast_strlen_zero(c->dst)){ /* ok, we got needed NAPTR */
+ if (c->options & ENUMLOOKUP_OPTIONS_COUNT){ /* counting RRs */
c->position++;
snprintf(c->dst, c->dstlen, "%d", c->position);
} else {
p = realloc(c->naptr_rrs, sizeof(struct enum_naptr_rr)*(c->naptr_rrs_count+1));
- if(p){
+ if (p) {
c->naptr_rrs = (struct enum_naptr_rr*)p;
memcpy(&c->naptr_rrs[c->naptr_rrs_count].naptr, answer, sizeof(struct naptr));
/* printf("order=%d, pref=%d\n", ntohs(c->naptr_rrs[c->naptr_rrs_count].naptr.order), ntohs(c->naptr_rrs[c->naptr_rrs_count].naptr.pref)); */
@@ -373,7 +373,7 @@ static int enum_callback(void *context, char *answer, int len, char *fullanswer)
return 0;
}
- if(c->options & ENUMLOOKUP_OPTIONS_COUNT){ /* counting RRs */
+ if (c->options & ENUMLOOKUP_OPTIONS_COUNT) { /* counting RRs */
snprintf(c->dst, c->dstlen, "%d", c->position);
}
@@ -385,86 +385,86 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
{
struct enum_context context;
char tmp[259 + 512];
- char naptrinput[512];
+ char naptrinput[512];
int pos = strlen(number) - 1;
int newpos = 0;
int ret = -1;
struct enum_search *s = NULL;
int version = -1;
- /* for ISN rewrite */
- char *p1 = NULL;
- char *p2 = NULL;
- int k = 0;
- int i = 0;
- int z = 0;
-
- if(number[0] == 'n'){
- strncpy(naptrinput, number+1, sizeof(naptrinput));
- } else {
- strncpy(naptrinput, number, sizeof(naptrinput));
- }
+ /* for ISN rewrite */
+ char *p1 = NULL;
+ char *p2 = NULL;
+ int k = 0;
+ int i = 0;
+ int z = 0;
+
+ if (number[0] == 'n') {
+ strncpy(naptrinput, number+1, sizeof(naptrinput));
+ } else {
+ strncpy(naptrinput, number, sizeof(naptrinput));
+ }
context.naptrinput = naptrinput; /* The number */
context.dst = dst; /* Return string */
context.dstlen = dstlen;
- context.tech = tech;
+ context.tech = tech;
context.techlen = techlen;
- context.options = 0;
- context.position = 1;
- context.naptr_rrs = NULL;
- context.naptr_rrs_count = 0;
-
- if(options != NULL){
- if(*options == 'c'){
- context.options = ENUMLOOKUP_OPTIONS_COUNT;
- context.position = 0;
- } else {
- context.position = atoi(options);
- if(context.position < 1)
- context.position = 1;
- }
- }
+ context.options = 0;
+ context.position = 1;
+ context.naptr_rrs = NULL;
+ context.naptr_rrs_count = 0;
+
+ if (options != NULL){
+ if (*options == 'c'){
+ context.options = ENUMLOOKUP_OPTIONS_COUNT;
+ context.position = 0;
+ } else {
+ context.position = atoi(options);
+ if (context.position < 1)
+ context.position = 1;
+ }
+ }
if (pos > 128)
pos = 128;
- /* ISN rewrite */
- p1 = strchr(number, '*');
+ /* ISN rewrite */
+ p1 = strchr(number, '*');
- if(number[0] == 'n'){ /* do not perform ISN rewrite ('n' is testing flag) */
- p1 = NULL;
- k = 1; /* strip 'n' from number */
- }
+ if (number[0] == 'n') { /* do not perform ISN rewrite ('n' is testing flag) */
+ p1 = NULL;
+ k = 1; /* strip 'n' from number */
+ }
- if(p1 != NULL){
- p2 = p1+1;
- while(p1 > number){
- p1--;
- tmp[newpos++] = *p1;
- tmp[newpos++] = '.';
- }
- if(*p2){
- while(*p2 && newpos < 128){
- tmp[newpos++] = *p2;
- p2++;
- }
- tmp[newpos++] = '.';
- }
+ if (p1 != NULL) {
+ p2 = p1+1;
+ while (p1 > number){
+ p1--;
+ tmp[newpos++] = *p1;
+ tmp[newpos++] = '.';
+ }
+ if (*p2) {
+ while(*p2 && newpos < 128){
+ tmp[newpos++] = *p2;
+ p2++;
+ }
+ tmp[newpos++] = '.';
+ }
- } else {
- while(pos >= k) {
- if(isdigit(number[pos])){
- tmp[newpos++] = number[pos];
- tmp[newpos++] = '.';
- }
- pos--;
- }
+ } else {
+ while (pos >= k) {
+ if (isdigit(number[pos])) {
+ tmp[newpos++] = number[pos];
+ tmp[newpos++] = '.';
+ }
+ pos--;
+ }
}
if (chan && ast_autoservice_start(chan) < 0)
return -1;
- for(;;) {
+ for (;;) {
ast_mutex_lock(&enumlock);
if (version != enumver) {
/* Ooh, a reload... */
@@ -473,9 +473,9 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
} else {
s = s->next;
}
- if(suffix != NULL){
- strncpy(tmp + newpos, suffix, sizeof(tmp) - newpos - 1);
- } else if (s) {
+ if (suffix != NULL) {
+ strncpy(tmp + newpos, suffix, sizeof(tmp) - newpos - 1);
+ } else if (s) {
strncpy(tmp + newpos, s->toplev, sizeof(tmp) - newpos - 1);
}
ast_mutex_unlock(&enumlock);
@@ -484,7 +484,7 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
ret = ast_search_dns(&context, tmp, C_IN, T_NAPTR, enum_callback);
if (ret > 0)
break;
- if(suffix != NULL)
+ if (suffix != NULL)
break;
}
if (ret < 0) {
@@ -492,12 +492,12 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
ret = 0;
}
- if(context.naptr_rrs_count >= context.position && ! (context.options & ENUMLOOKUP_OPTIONS_COUNT)){
+ if (context.naptr_rrs_count >= context.position && ! (context.options & ENUMLOOKUP_OPTIONS_COUNT)) {
/* sort array by NAPTR order/preference */
- for(k=0; k<context.naptr_rrs_count; k++){
- for(i=0; i<context.naptr_rrs_count; i++){
+ for (k=0; k<context.naptr_rrs_count; k++) {
+ for (i=0; i<context.naptr_rrs_count; i++) {
/* use order first and then preference to compare */
- if((ntohs(context.naptr_rrs[k].naptr.order) < ntohs(context.naptr_rrs[i].naptr.order)
+ if ((ntohs(context.naptr_rrs[k].naptr.order) < ntohs(context.naptr_rrs[i].naptr.order)
&& context.naptr_rrs[k].sort_pos > context.naptr_rrs[i].sort_pos)
|| (ntohs(context.naptr_rrs[k].naptr.order) > ntohs(context.naptr_rrs[i].naptr.order)
&& context.naptr_rrs[k].sort_pos < context.naptr_rrs[i].sort_pos)){
@@ -506,8 +506,8 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
context.naptr_rrs[i].sort_pos = z;
continue;
}
- if(ntohs(context.naptr_rrs[k].naptr.order) == ntohs(context.naptr_rrs[i].naptr.order)){
- if((ntohs(context.naptr_rrs[k].naptr.pref) < ntohs(context.naptr_rrs[i].naptr.pref)
+ if (ntohs(context.naptr_rrs[k].naptr.order) == ntohs(context.naptr_rrs[i].naptr.order)) {
+ if ((ntohs(context.naptr_rrs[k].naptr.pref) < ntohs(context.naptr_rrs[i].naptr.pref)
&& context.naptr_rrs[k].sort_pos > context.naptr_rrs[i].sort_pos)
|| (ntohs(context.naptr_rrs[k].naptr.pref) > ntohs(context.naptr_rrs[i].naptr.pref)
&& context.naptr_rrs[k].sort_pos < context.naptr_rrs[i].sort_pos)){
@@ -518,26 +518,26 @@ int ast_get_enum(struct ast_channel *chan, const char *number, char *dst, int ds
}
}
}
- for(k=0; k<context.naptr_rrs_count; k++){
- if(context.naptr_rrs[k].sort_pos == context.position-1){
+ for (k=0; k<context.naptr_rrs_count; k++) {
+ if (context.naptr_rrs[k].sort_pos == context.position-1) {
ast_copy_string(context.dst, context.naptr_rrs[k].result, dstlen);
ast_copy_string(context.tech, context.naptr_rrs[k].tech, techlen);
break;
}
}
- } else if( !(context.options & ENUMLOOKUP_OPTIONS_COUNT) ) {
+ } else if (!(context.options & ENUMLOOKUP_OPTIONS_COUNT)) {
context.dst[0] = 0;
}
if (chan)
ret |= ast_autoservice_stop(chan);
- for(k=0; k<context.naptr_rrs_count; k++){
- free(context.naptr_rrs[k].result);
- free(context.naptr_rrs[k].tech);
- }
+ for (k=0; k<context.naptr_rrs_count; k++) {
+ free(context.naptr_rrs[k].result);
+ free(context.naptr_rrs[k].tech);
+ }
- free(context.naptr_rrs);
+ free(context.naptr_rrs);
return ret;
}
@@ -568,7 +568,7 @@ int ast_get_txt(struct ast_channel *chan, const char *number, char *dst, int dst
if (pos > 128)
pos = 128;
- while(pos >= 0) {
+ while (pos >= 0) {
tmp[newpos++] = number[pos--];
tmp[newpos++] = '.';
}
@@ -576,7 +576,7 @@ int ast_get_txt(struct ast_channel *chan, const char *number, char *dst, int dst
if (chan && ast_autoservice_start(chan) < 0)
return -1;
- for(;;) {
+ for (;;) {
ast_mutex_lock(&enumlock);
if (version != enumver) {
/* Ooh, a reload... */