Sat Aug 6 00:39:55 2011

Asterisk developer's documentation


dundi-parser.h File Reference

#include "asterisk/dundi.h"
#include "asterisk/aes.h"

Go to the source code of this file.

Data Structures

struct  dundi_ie_data
struct  dundi_ies

Defines

#define DUNDI_MAX_ANSWERS   100
#define DUNDI_MAX_STACK   512

Functions

int dundi_eid_cmp (dundi_eid *eid1, dundi_eid *eid2)
char * dundi_eid_to_str (char *s, int maxlen, dundi_eid *eid)
char * dundi_eid_to_str_short (char *s, int maxlen, dundi_eid *eid)
int dundi_eid_zero (dundi_eid *eid)
char * dundi_flags2str (char *s, int maxlen, int flags)
char * dundi_hint2str (char *s, int maxlen, int flags)
const char * dundi_ie2str (int ie)
int dundi_ie_append (struct dundi_ie_data *ied, unsigned char ie)
int dundi_ie_append_addr (struct dundi_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
int dundi_ie_append_answer (struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid, unsigned char protocol, unsigned short flags, unsigned short weight, char *desc)
int dundi_ie_append_byte (struct dundi_ie_data *ied, unsigned char ie, unsigned char dat)
int dundi_ie_append_cause (struct dundi_ie_data *ied, unsigned char ie, unsigned char cause, char *desc)
int dundi_ie_append_eid (struct dundi_ie_data *ied, unsigned char ie, dundi_eid *eid)
int dundi_ie_append_encdata (struct dundi_ie_data *ied, unsigned char ie, unsigned char *iv, void *data, int datalen)
int dundi_ie_append_hint (struct dundi_ie_data *ied, unsigned char ie, unsigned short flags, char *data)
int dundi_ie_append_int (struct dundi_ie_data *ied, unsigned char ie, unsigned int value)
int dundi_ie_append_raw (struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
int dundi_ie_append_short (struct dundi_ie_data *ied, unsigned char ie, unsigned short value)
int dundi_ie_append_str (struct dundi_ie_data *ied, unsigned char ie, char *str)
int dundi_parse_ies (struct dundi_ies *ies, unsigned char *data, int datalen)
void dundi_set_error (void(*output)(const char *data))
void dundi_set_output (void(*output)(const char *data))
void dundi_showframe (struct dundi_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen)
int dundi_str_short_to_eid (dundi_eid *eid, char *s)
int dundi_str_to_eid (dundi_eid *eid, char *s)


Define Documentation

#define DUNDI_MAX_ANSWERS   100

Definition at line 19 of file dundi-parser.h.

Referenced by dundi_parse_ies().

#define DUNDI_MAX_STACK   512

Definition at line 18 of file dundi-parser.h.

Referenced by append_transaction(), dundi_parse_ies(), and optimize_transactions().


Function Documentation

int dundi_eid_cmp ( dundi_eid eid1,
dundi_eid eid2 
)

Definition at line 122 of file dundi-parser.c.

Referenced by build_peer(), build_transactions(), destroy_trans(), dundi_answer_entity(), dundi_answer_query(), dundi_ie_append_eid_appropriately(), dundi_lookup_internal(), dundi_query_thread(), find_peer(), optimize_transactions(), and register_request().

00123 {
00124    return memcmp(eid1, eid2, sizeof(dundi_eid));
00125 }

char* dundi_eid_to_str ( char *  s,
int  maxlen,
dundi_eid eid 
)

Definition at line 57 of file dundi-parser.c.

References _dundi_eid::eid.

Referenced by append_transaction(), build_transactions(), cache_lookup(), cache_lookup_internal(), check_key(), complete_peer_helper(), destroy_trans(), do_autokill(), do_register(), do_register_expire(), dump_answer(), dump_eid(), dundi_answer_entity(), dundi_lookup_internal(), dundi_lookup_local(), dundi_lookup_thread(), dundi_precache_thread(), dundi_prop_precache(), dundi_query_thread(), dundi_send(), dundi_show_entityid(), dundi_show_peer(), dundi_show_peers(), dundi_show_requests(), handle_command_response(), populate_addr(), register_request(), reset_global_eid(), and update_key().

00058 {
00059    int x;
00060    char *os = s;
00061    if (maxlen < 18) {
00062       if (s && (maxlen > 0))
00063          *s = '\0';
00064    } else {
00065       for (x=0;x<5;x++) {
00066          sprintf(s, "%02x:", eid->eid[x]);
00067          s += 3;
00068       }
00069       sprintf(s, "%02x", eid->eid[5]);
00070    }
00071    return os;
00072 }

char* dundi_eid_to_str_short ( char *  s,
int  maxlen,
dundi_eid eid 
)

Definition at line 74 of file dundi-parser.c.

References _dundi_eid::eid.

Referenced by cache_lookup(), cache_save(), cache_save_hint(), and handle_command_response().

00075 {
00076    int x;
00077    char *os = s;
00078    if (maxlen < 13) {
00079       if (s && (maxlen > 0))
00080          *s = '\0';
00081    } else {
00082       for (x=0;x<6;x++) {
00083          sprintf(s, "%02X", eid->eid[x]);
00084          s += 2;
00085       }
00086    }
00087    return os;
00088 }

int dundi_eid_zero ( dundi_eid eid  ) 

Definition at line 114 of file dundi-parser.c.

References _dundi_eid::eid.

Referenced by build_transactions(), dundi_discover(), dundi_query(), dundi_show_requests(), and precache_trans().

00115 {
00116    int x;
00117    for (x=0;x<sizeof(eid->eid) / sizeof(eid->eid[0]);x++)
00118       if (eid->eid[x]) return 0;
00119    return 1;
00120 }

char* dundi_flags2str ( char *  s,
int  maxlen,
int  flags 
)

Definition at line 273 of file dundi-parser.c.

References ast_strlen_zero(), DUNDI_FLAG_CANMATCH, DUNDI_FLAG_COMMERCIAL, DUNDI_FLAG_EXISTS, DUNDI_FLAG_IGNOREPAT, DUNDI_FLAG_MATCHMORE, DUNDI_FLAG_MOBILE, DUNDI_FLAG_NOCOMUNSOLICIT, DUNDI_FLAG_NOUNSOLICITED, and DUNDI_FLAG_RESIDENTIAL.

Referenced by cache_lookup_internal(), dump_answer(), dundi_do_lookup(), and dundi_show_mappings().

00274 {
00275    strcpy(buf, "");
00276    buf[bufsiz-1] = '\0';
00277    if (flags & DUNDI_FLAG_EXISTS) {
00278       strncat(buf, "EXISTS|", bufsiz - strlen(buf) - 1);
00279    }
00280    if (flags & DUNDI_FLAG_MATCHMORE) {
00281       strncat(buf, "MATCHMORE|", bufsiz - strlen(buf) - 1);
00282    }
00283    if (flags & DUNDI_FLAG_CANMATCH) {
00284       strncat(buf, "CANMATCH|", bufsiz - strlen(buf) - 1);
00285    }
00286    if (flags & DUNDI_FLAG_IGNOREPAT) {
00287       strncat(buf, "IGNOREPAT|", bufsiz - strlen(buf) - 1);
00288    }
00289    if (flags & DUNDI_FLAG_RESIDENTIAL) {
00290       strncat(buf, "RESIDENCE|", bufsiz - strlen(buf) - 1);
00291    }
00292    if (flags & DUNDI_FLAG_COMMERCIAL) {
00293       strncat(buf, "COMMERCIAL|", bufsiz - strlen(buf) - 1);
00294    }
00295    if (flags & DUNDI_FLAG_MOBILE) {
00296       strncat(buf, "MOBILE", bufsiz - strlen(buf) - 1);
00297    }
00298    if (flags & DUNDI_FLAG_NOUNSOLICITED) {
00299       strncat(buf, "NOUNSLCTD|", bufsiz - strlen(buf) - 1);
00300    }
00301    if (flags & DUNDI_FLAG_NOCOMUNSOLICIT) {
00302       strncat(buf, "NOCOMUNSLTD|", bufsiz - strlen(buf) - 1);
00303    }
00304    /* Get rid of trailing | */
00305    if (ast_strlen_zero(buf))
00306       strcpy(buf, "NONE|");
00307    buf[strlen(buf)-1] = '\0';
00308    return buf;
00309 }

char* dundi_hint2str ( char *  s,
int  maxlen,
int  flags 
)

Definition at line 151 of file dundi-parser.c.

References ast_strlen_zero(), DUNDI_HINT_DONT_ASK, DUNDI_HINT_TTL_EXPIRED, and DUNDI_HINT_UNAFFECTED.

Referenced by dump_hint().

00152 {
00153    strcpy(buf, "");
00154    buf[bufsiz-1] = '\0';
00155    if (flags & DUNDI_HINT_TTL_EXPIRED) {
00156       strncat(buf, "TTLEXPIRED|", bufsiz - strlen(buf) - 1);
00157    }
00158    if (flags & DUNDI_HINT_DONT_ASK) {
00159       strncat(buf, "DONTASK|", bufsiz - strlen(buf) - 1);
00160    }
00161    if (flags & DUNDI_HINT_UNAFFECTED) {
00162       strncat(buf, "UNAFFECTED|", bufsiz - strlen(buf) - 1);
00163    }
00164    /* Get rid of trailing | */
00165    if (ast_strlen_zero(buf))
00166       strcpy(buf, "NONE|");
00167    buf[strlen(buf)-1] = '\0';
00168    return buf;
00169 }

const char* dundi_ie2str ( int  ie  ) 

Definition at line 389 of file dundi-parser.c.

References ies, and name.

Referenced by dundi_ie_append_answer(), dundi_ie_append_cause(), dundi_ie_append_encdata(), dundi_ie_append_hint(), dundi_ie_append_raw(), and dundi_parse_ies().

00390 {
00391    int x;
00392    for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
00393       if (ies[x].ie == ie)
00394          return ies[x].name;
00395    }
00396    return "Unknown IE";
00397 }

int dundi_ie_append ( struct dundi_ie_data ied,
unsigned char  ie 
)

Definition at line 639 of file dundi-parser.c.

References dundi_ie_append_raw().

Referenced by dundi_discover().

00640 {
00641    return dundi_ie_append_raw(ied, ie, NULL, 0);
00642 }

int dundi_ie_append_addr ( struct dundi_ie_data ied,
unsigned char  ie,
struct sockaddr_in *  sin 
)

Definition at line 605 of file dundi-parser.c.

References dundi_ie_append_raw().

00606 {
00607    return dundi_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
00608 }

int dundi_ie_append_answer ( struct dundi_ie_data ied,
unsigned char  ie,
dundi_eid eid,
unsigned char  protocol,
unsigned short  flags,
unsigned short  weight,
char *  desc 
)

Definition at line 578 of file dundi-parser.c.

References dundi_ie_data::buf, dundi_ie2str(), _dundi_eid::eid, errorf, and dundi_ie_data::pos.

Referenced by dundi_lookup_thread(), and precache_trans().

00579 {
00580    char tmp[256];
00581    int datalen = data ? strlen(data) + 11 : 11;
00582    int x;
00583    unsigned short myw;
00584    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00585       snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
00586       errorf(tmp);
00587       return -1;
00588    }
00589    ied->buf[ied->pos++] = ie;
00590    ied->buf[ied->pos++] = datalen;
00591    for (x=0;x<6;x++)
00592       ied->buf[ied->pos++] = eid->eid[x];
00593    ied->buf[ied->pos++] = protocol;
00594    myw = htons(flags);
00595    memcpy(ied->buf + ied->pos, &myw, 2);
00596    ied->pos += 2;
00597    myw = htons(weight);
00598    memcpy(ied->buf + ied->pos, &myw, 2);
00599    ied->pos += 2;
00600    memcpy(ied->buf + ied->pos, data, datalen-11);
00601    ied->pos += datalen-11;
00602    return 0;
00603 }

int dundi_ie_append_byte ( struct dundi_ie_data ied,
unsigned char  ie,
unsigned char  dat 
)

Definition at line 634 of file dundi-parser.c.

References dundi_ie_append_raw().

00635 {
00636    return dundi_ie_append_raw(ied, ie, &dat, 1);
00637 }

int dundi_ie_append_cause ( struct dundi_ie_data ied,
unsigned char  ie,
unsigned char  cause,
char *  desc 
)

Definition at line 522 of file dundi-parser.c.

References dundi_ie_data::buf, dundi_ie2str(), errorf, and dundi_ie_data::pos.

Referenced by dundi_answer_entity(), dundi_answer_query(), dundi_lookup_thread(), and handle_command_response().

00523 {
00524    char tmp[256];
00525    int datalen = data ? strlen(data) + 1 : 1;
00526    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00527       snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
00528       errorf(tmp);
00529       return -1;
00530    }
00531    ied->buf[ied->pos++] = ie;
00532    ied->buf[ied->pos++] = datalen;
00533    ied->buf[ied->pos++] = cause;
00534    memcpy(ied->buf + ied->pos, data, datalen-1);
00535    ied->pos += datalen-1;
00536    return 0;
00537 }

int dundi_ie_append_eid ( struct dundi_ie_data ied,
unsigned char  ie,
dundi_eid eid 
)

Definition at line 629 of file dundi-parser.c.

References dundi_ie_append_raw().

Referenced by do_register(), dundi_discover(), dundi_encrypt(), dundi_ie_append_eid_appropriately(), dundi_query(), and precache_trans().

00630 {
00631    return dundi_ie_append_raw(ied, ie, (unsigned char *)eid, sizeof(dundi_eid));
00632 }

int dundi_ie_append_encdata ( struct dundi_ie_data ied,
unsigned char  ie,
unsigned char *  iv,
void *  data,
int  datalen 
)

Definition at line 558 of file dundi-parser.c.

References dundi_ie_data::buf, dundi_ie2str(), errorf, and dundi_ie_data::pos.

Referenced by dundi_encrypt().

00559 {
00560    char tmp[256];
00561    datalen += 16;
00562    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00563       snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
00564       errorf(tmp);
00565       return -1;
00566    }
00567    ied->buf[ied->pos++] = ie;
00568    ied->buf[ied->pos++] = datalen;
00569    memcpy(ied->buf + ied->pos, iv, 16);
00570    ied->pos += 16;
00571    if (data) {
00572       memcpy(ied->buf + ied->pos, data, datalen-16);
00573       ied->pos += datalen-16;
00574    }
00575    return 0;
00576 }

int dundi_ie_append_hint ( struct dundi_ie_data ied,
unsigned char  ie,
unsigned short  flags,
char *  data 
)

Definition at line 539 of file dundi-parser.c.

References dundi_ie_data::buf, dundi_ie2str(), errorf, and dundi_ie_data::pos.

Referenced by dundi_lookup_thread(), dundi_query_thread(), and precache_trans().

00540 {
00541    char tmp[256];
00542    int datalen = data ? strlen(data) + 2 : 2;
00543    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00544       snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
00545       errorf(tmp);
00546       return -1;
00547    }
00548    ied->buf[ied->pos++] = ie;
00549    ied->buf[ied->pos++] = datalen;
00550    flags = htons(flags);
00551    memcpy(ied->buf + ied->pos, &flags, sizeof(flags));
00552    ied->pos += 2;
00553    memcpy(ied->buf + ied->pos, data, datalen-1);
00554    ied->pos += datalen-2;
00555    return 0;
00556 }

int dundi_ie_append_int ( struct dundi_ie_data ied,
unsigned char  ie,
unsigned int  value 
)

Definition at line 610 of file dundi-parser.c.

References dundi_ie_append_raw().

Referenced by dundi_encrypt().

00611 {
00612    unsigned int newval;
00613    newval = htonl(value);
00614    return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
00615 }

int dundi_ie_append_raw ( struct dundi_ie_data ied,
unsigned char  ie,
void *  data,
int  datalen 
)

Definition at line 507 of file dundi-parser.c.

References dundi_ie_data::buf, dundi_ie2str(), errorf, and dundi_ie_data::pos.

Referenced by dundi_encrypt(), dundi_ie_append(), dundi_ie_append_addr(), dundi_ie_append_byte(), dundi_ie_append_eid(), dundi_ie_append_int(), dundi_ie_append_short(), and dundi_ie_append_str().

00508 {
00509    char tmp[256];
00510    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00511       snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", dundi_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
00512       errorf(tmp);
00513       return -1;
00514    }
00515    ied->buf[ied->pos++] = ie;
00516    ied->buf[ied->pos++] = datalen;
00517    memcpy(ied->buf + ied->pos, data, datalen);
00518    ied->pos += datalen;
00519    return 0;
00520 }

int dundi_ie_append_short ( struct dundi_ie_data ied,
unsigned char  ie,
unsigned short  value 
)

Definition at line 617 of file dundi-parser.c.

References dundi_ie_append_raw().

Referenced by do_register(), dundi_discover(), dundi_lookup_thread(), dundi_query(), handle_command_response(), and precache_trans().

00618 {
00619    unsigned short newval;
00620    newval = htons(value);
00621    return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
00622 }

int dundi_ie_append_str ( struct dundi_ie_data ied,
unsigned char  ie,
char *  str 
)

Definition at line 624 of file dundi-parser.c.

References dundi_ie_append_raw().

Referenced by dundi_discover(), dundi_query(), dundi_query_thread(), and precache_trans().

00625 {
00626    return dundi_ie_append_raw(ied, ie, str, strlen(str));
00627 }

int dundi_parse_ies ( struct dundi_ies ies,
unsigned char *  data,
int  datalen 
)

Definition at line 654 of file dundi-parser.c.

References dundi_ie2str(), DUNDI_IE_ANSWER, DUNDI_IE_CACHEBYPASS, DUNDI_IE_CALLED_CONTEXT, DUNDI_IE_CALLED_NUMBER, DUNDI_IE_CAUSE, DUNDI_IE_COUNTRY, DUNDI_IE_DEPARTMENT, DUNDI_IE_EID, DUNDI_IE_EID_DIRECT, DUNDI_IE_EMAIL, DUNDI_IE_ENCDATA, DUNDI_IE_EXPIRATION, DUNDI_IE_HINT, DUNDI_IE_IPADDR, DUNDI_IE_KEYCRC32, DUNDI_IE_LOCALITY, DUNDI_IE_ORGANIZATION, DUNDI_IE_PHONE, DUNDI_IE_REQEID, DUNDI_IE_SHAREDKEY, DUNDI_IE_SIGNATURE, DUNDI_IE_STATE_PROV, DUNDI_IE_TTL, DUNDI_IE_UNKNOWN, DUNDI_IE_VERSION, DUNDI_MAX_ANSWERS, DUNDI_MAX_STACK, errorf, ies, len(), and outputf.

Referenced by handle_command_response().

00655 {
00656    /* Parse data into information elements */
00657    int len;
00658    int ie;
00659    char tmp[256];
00660    memset(ies, 0, (int)sizeof(struct dundi_ies));
00661    ies->ttl = -1;
00662    ies->expiration = -1;
00663    ies->unknowncmd = -1;
00664    ies->cause = -1;
00665    while(datalen >= 2) {
00666       ie = data[0];
00667       len = data[1];
00668       if (len > datalen - 2) {
00669          errorf("Information element length exceeds message size\n");
00670          return -1;
00671       }
00672       switch(ie) {
00673       case DUNDI_IE_EID:
00674       case DUNDI_IE_EID_DIRECT:
00675          if (len != (int)sizeof(dundi_eid)) {
00676             errorf("Improper entity identifer, expecting 6 bytes!\n");
00677          } else if (ies->eidcount < DUNDI_MAX_STACK) {
00678             ies->eids[ies->eidcount] = (dundi_eid *)(data + 2);
00679             ies->eid_direct[ies->eidcount] = (ie == DUNDI_IE_EID_DIRECT);
00680             ies->eidcount++;
00681          } else
00682             errorf("Too many entities in stack!\n");
00683          break;
00684       case DUNDI_IE_REQEID:
00685          if (len != (int)sizeof(dundi_eid)) {
00686             errorf("Improper requested entity identifer, expecting 6 bytes!\n");
00687          } else
00688             ies->reqeid = (dundi_eid *)(data + 2);
00689          break;
00690       case DUNDI_IE_CALLED_CONTEXT:
00691          ies->called_context = (char *)data + 2;
00692          break;
00693       case DUNDI_IE_CALLED_NUMBER:
00694          ies->called_number = (char *)data + 2;
00695          break;
00696       case DUNDI_IE_ANSWER:
00697          if (len < sizeof(struct dundi_answer)) {
00698             snprintf(tmp, (int)sizeof(tmp), "Answer expected to be >=%d bytes long but was %d\n", (int)sizeof(struct dundi_answer), len);
00699             errorf(tmp);
00700          } else {
00701             if (ies->anscount < DUNDI_MAX_ANSWERS)
00702                ies->answers[ies->anscount++]= (struct dundi_answer *)(data + 2);
00703             else 
00704                errorf("Ignoring extra answers!\n");
00705          }
00706          break;
00707       case DUNDI_IE_TTL:
00708          if (len != (int)sizeof(unsigned short)) {
00709             snprintf(tmp, (int)sizeof(tmp), "Expecting ttl to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00710             errorf(tmp);
00711          } else
00712             ies->ttl = ntohs(*((unsigned short *)(data + 2)));
00713          break;
00714       case DUNDI_IE_VERSION:
00715          if (len != (int)sizeof(unsigned short)) {
00716             snprintf(tmp, (int)sizeof(tmp),  "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00717             errorf(tmp);
00718          } else
00719             ies->version = ntohs(*((unsigned short *)(data + 2)));
00720          break;
00721       case DUNDI_IE_EXPIRATION:
00722          if (len != (int)sizeof(unsigned short)) {
00723             snprintf(tmp, (int)sizeof(tmp),  "Expecting expiration to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
00724             errorf(tmp);
00725          } else
00726             ies->expiration = ntohs(*((unsigned short *)(data + 2)));
00727          break;
00728       case DUNDI_IE_KEYCRC32:
00729          if (len != (int)sizeof(unsigned int)) {
00730             snprintf(tmp, (int)sizeof(tmp),  "Expecting expiration to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
00731             errorf(tmp);
00732          } else
00733             ies->keycrc32 = ntohl(*((unsigned int *)(data + 2)));
00734          break;
00735       case DUNDI_IE_UNKNOWN:
00736          if (len == 1)
00737             ies->unknowncmd = data[2];
00738          else {
00739             snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
00740             errorf(tmp);
00741          }
00742          break;
00743       case DUNDI_IE_CAUSE:
00744          if (len >= 1) {
00745             ies->cause = data[2];
00746             ies->causestr = (char *)data + 3;
00747          } else {
00748             snprintf(tmp, (int)sizeof(tmp), "Expected at least one byte cause, but was %d long\n", len);
00749             errorf(tmp);
00750          }
00751          break;
00752       case DUNDI_IE_HINT:
00753          if (len >= 2) {
00754             ies->hint = (struct dundi_hint *)(data + 2);
00755          } else {
00756             snprintf(tmp, (int)sizeof(tmp), "Expected at least two byte hint, but was %d long\n", len);
00757             errorf(tmp);
00758          }
00759          break;
00760       case DUNDI_IE_DEPARTMENT:
00761          ies->q_dept = (char *)data + 2;
00762          break;
00763       case DUNDI_IE_ORGANIZATION:
00764          ies->q_org = (char *)data + 2;
00765          break;
00766       case DUNDI_IE_LOCALITY:
00767          ies->q_locality = (char *)data + 2;
00768          break;
00769       case DUNDI_IE_STATE_PROV:
00770          ies->q_stateprov = (char *)data + 2;
00771          break;
00772       case DUNDI_IE_COUNTRY:
00773          ies->q_country = (char *)data + 2;
00774          break;
00775       case DUNDI_IE_EMAIL:
00776          ies->q_email = (char *)data + 2;
00777          break;
00778       case DUNDI_IE_PHONE:
00779          ies->q_phone = (char *)data + 2;
00780          break;
00781       case DUNDI_IE_IPADDR:
00782          ies->q_ipaddr = (char *)data + 2;
00783          break;
00784       case DUNDI_IE_ENCDATA:
00785          /* Recalculate len as the remainder of the message, regardless of
00786             theoretical length */
00787          len = datalen - 2;
00788          if ((len > 16) && !(len % 16)) {
00789             ies->encblock = (struct dundi_encblock *)(data + 2);
00790             ies->enclen = len - 16;
00791          } else {
00792             snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted data length %d\n", len);
00793             errorf(tmp);
00794          }
00795          break;
00796       case DUNDI_IE_SHAREDKEY:
00797          if (len == 128) {
00798             ies->encsharedkey = (unsigned char *)(data + 2);
00799          } else {
00800             snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted shared key length %d\n", len);
00801             errorf(tmp);
00802          }
00803          break;
00804       case DUNDI_IE_SIGNATURE:
00805          if (len == 128) {
00806             ies->encsig = (unsigned char *)(data + 2);
00807          } else {
00808             snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted signature length %d\n", len);
00809             errorf(tmp);
00810          }
00811          break;
00812       case DUNDI_IE_CACHEBYPASS:
00813          ies->cbypass = 1;
00814          break;
00815       default:
00816          snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", dundi_ie2str(ie), ie, len);
00817          outputf(tmp);
00818       }
00819       /* Overwrite information element with 0, to null terminate previous portion */
00820       data[0] = 0;
00821       datalen -= (len + 2);
00822       data += (len + 2);
00823    }
00824    /* Null-terminate last field */
00825    *data = '\0';
00826    if (datalen) {
00827       errorf("Invalid information element contents, strange boundary\n");
00828       return -1;
00829    }
00830    return 0;
00831 }

void dundi_set_error ( void(*)(const char *data)  output  ) 

void dundi_set_output ( void(*)(const char *data)  output  ) 

void dundi_showframe ( struct dundi_hdr fhi,
int  rx,
struct sockaddr_in *  sin,
int  datalen 
)

Definition at line 448 of file dundi-parser.c.

References ast_inet_ntoa(), dundi_hdr::cmdflags, dundi_hdr::cmdresp, commands, dundi_hdr::dtrans, dump_ies(), DUNDI_FLAG_RESERVED, DUNDI_FLAG_RETRANS, dundi_hdr::ies, dundi_hdr::iseqno, dundi_hdr::oseqno, outputf, and dundi_hdr::strans.

Referenced by dundi_send(), dundi_xmit(), and socket_read().

00449 {
00450    char *pref[] = {
00451       "Tx",
00452       "Rx",
00453       "    ETx",
00454       "    Erx" };
00455    char *commands[] = {
00456       "ACK         ",
00457       "DPDISCOVER  ",
00458       "DPRESPONSE  ",
00459       "EIDQUERY    ",
00460       "EIDRESPONSE ",
00461       "PRECACHERQ  ",
00462       "PRECACHERP  ",
00463       "INVALID     ",
00464       "UNKNOWN CMD ",
00465       "NULL        ",
00466       "REQREQ      ",
00467       "REGRESPONSE ",
00468       "CANCEL      ",
00469       "ENCRYPT     ",
00470       "ENCREJ      " };
00471    char class2[20];
00472    char *class;
00473    char subclass2[20];
00474    char *subclass;
00475    char tmp[256];
00476    char retries[20];
00477    if (ntohs(fhi->dtrans) & DUNDI_FLAG_RETRANS)
00478       strcpy(retries, "Yes");
00479    else
00480       strcpy(retries, "No");
00481    if ((ntohs(fhi->strans) & DUNDI_FLAG_RESERVED)) {
00482       /* Ignore frames with high bit set to 1 */
00483       return;
00484    }
00485    if ((fhi->cmdresp & 0x3f) > (int)sizeof(commands)/(int)sizeof(char *)) {
00486       snprintf(class2, (int)sizeof(class2), "(%d?)", fhi->cmdresp);
00487       class = class2;
00488    } else {
00489       class = commands[(int)(fhi->cmdresp & 0x3f)];
00490    }
00491    snprintf(subclass2, (int)sizeof(subclass2), "%02x", fhi->cmdflags);
00492    subclass = subclass2;
00493    snprintf(tmp, (int)sizeof(tmp), 
00494       "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s (%s)\n",
00495       pref[rx],
00496       retries, fhi->oseqno, fhi->iseqno, class, fhi->cmdresp & 0x40 ? "Response" : "Command");
00497    outputf(tmp);
00498    snprintf(tmp, (int)sizeof(tmp), 
00499       "%s     Flags: %s STrans: %5.5d  DTrans: %5.5d [%s:%d]%s\n", (rx > 1) ? "     " : "",
00500       subclass, ntohs(fhi->strans) & ~DUNDI_FLAG_RESERVED, ntohs(fhi->dtrans) & ~DUNDI_FLAG_RETRANS,
00501       ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port),
00502       fhi->cmdresp & 0x80 ? " (Final)" : "");
00503    outputf(tmp);
00504    dump_ies(fhi->ies, rx > 1, datalen);
00505 }

int dundi_str_short_to_eid ( dundi_eid eid,
char *  s 
)

Definition at line 102 of file dundi-parser.c.

References _dundi_eid::eid.

Referenced by cache_lookup_internal().

00103 {
00104    unsigned int eid_int[6];
00105    int x;
00106    if (sscanf(s, "%2x%2x%2x%2x%2x%2x", &eid_int[0], &eid_int[1], &eid_int[2],
00107        &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
00108          return -1;
00109    for (x=0;x<6;x++)
00110       eid->eid[x] = eid_int[x];
00111    return 0;
00112 }

int dundi_str_to_eid ( dundi_eid eid,
char *  s 
)

Definition at line 90 of file dundi-parser.c.

References _dundi_eid::eid.

Referenced by dundi_do_query(), and set_config().

00091 {
00092    unsigned int eid_int[6];
00093    int x;
00094    if (sscanf(s, "%2x:%2x:%2x:%2x:%2x:%2x", &eid_int[0], &eid_int[1], &eid_int[2],
00095        &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
00096          return -1;
00097    for (x=0;x<6;x++)
00098       eid->eid[x] = eid_int[x];
00099    return 0;
00100 }


Generated on Sat Aug 6 00:39:55 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7