dundi-parser.h File Reference

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

Include dependency graph for dundi-parser.h:

This graph shows which files directly or indirectly include this file:

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

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, const 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

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

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

References ast_eid::eid.

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

00056 {
00057    int x;
00058    char *os = s;
00059    if (maxlen < 13) {
00060       if (s && (maxlen > 0))
00061          *s = '\0';
00062    } else {
00063       for (x=0;x<6;x++) {
00064          sprintf(s, "%02hhX", (unsigned char)eid->eid[x]);
00065          s += 2;
00066       }
00067    }
00068    return os;
00069 }

int dundi_eid_zero ( dundi_eid eid  ) 

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

References ARRAY_LEN, and ast_eid::eid.

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

00084 {
00085    int x;
00086    for (x = 0; x < ARRAY_LEN(eid->eid); x++)
00087       if (eid->eid[x]) return 0;
00088    return 1;
00089 }

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

Definition at line 247 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(), dundi_show_cache(), and dundi_show_mappings().

00248 {
00249    strcpy(buf, "");
00250    buf[bufsiz-1] = '\0';
00251    if (flags & DUNDI_FLAG_EXISTS) {
00252       strncat(buf, "EXISTS|", bufsiz - strlen(buf) - 1);
00253    }
00254    if (flags & DUNDI_FLAG_MATCHMORE) {
00255       strncat(buf, "MATCHMORE|", bufsiz - strlen(buf) - 1);
00256    }
00257    if (flags & DUNDI_FLAG_CANMATCH) {
00258       strncat(buf, "CANMATCH|", bufsiz - strlen(buf) - 1);
00259    }
00260    if (flags & DUNDI_FLAG_IGNOREPAT) {
00261       strncat(buf, "IGNOREPAT|", bufsiz - strlen(buf) - 1);
00262    }
00263    if (flags & DUNDI_FLAG_RESIDENTIAL) {
00264       strncat(buf, "RESIDENCE|", bufsiz - strlen(buf) - 1);
00265    }
00266    if (flags & DUNDI_FLAG_COMMERCIAL) {
00267       strncat(buf, "COMMERCIAL|", bufsiz - strlen(buf) - 1);
00268    }
00269    if (flags & DUNDI_FLAG_MOBILE) {
00270       strncat(buf, "MOBILE", bufsiz - strlen(buf) - 1);
00271    }
00272    if (flags & DUNDI_FLAG_NOUNSOLICITED) {
00273       strncat(buf, "NOUNSLCTD|", bufsiz - strlen(buf) - 1);
00274    }
00275    if (flags & DUNDI_FLAG_NOCOMUNSOLICIT) {
00276       strncat(buf, "NOCOMUNSLTD|", bufsiz - strlen(buf) - 1);
00277    }
00278    /* Get rid of trailing | */
00279    if (ast_strlen_zero(buf))
00280       strcpy(buf, "NONE|");
00281    buf[strlen(buf)-1] = '\0';
00282    return buf;
00283 }

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

Definition at line 112 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().

00113 {
00114    strcpy(buf, "");
00115    buf[bufsiz-1] = '\0';
00116    if (flags & DUNDI_HINT_TTL_EXPIRED) {
00117       strncat(buf, "TTLEXPIRED|", bufsiz - strlen(buf) - 1);
00118    }
00119    if (flags & DUNDI_HINT_DONT_ASK) {
00120       strncat(buf, "DONTASK|", bufsiz - strlen(buf) - 1);
00121    }
00122    if (flags & DUNDI_HINT_UNAFFECTED) {
00123       strncat(buf, "UNAFFECTED|", bufsiz - strlen(buf) - 1);
00124    }
00125    /* Get rid of trailing | */
00126    if (ast_strlen_zero(buf))
00127       strcpy(buf, "NONE|");
00128    buf[strlen(buf)-1] = '\0';
00129    return buf;
00130 }

const char* dundi_ie2str ( int  ie  ) 

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

References ARRAY_LEN, infoelts, and iax2_ie::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().

00375 {
00376    int x;
00377    for (x = 0; x < ARRAY_LEN(infoelts); x++) {
00378       if (infoelts[x].ie == ie)
00379          return infoelts[x].name;
00380    }
00381    return "Unknown IE";
00382 }

int dundi_ie_append ( struct dundi_ie_data ied,
unsigned char  ie 
)

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

References dundi_ie_append_raw(), and NULL.

Referenced by dundi_discover().

00620 {
00621    return dundi_ie_append_raw(ied, ie, NULL, 0);
00622 }

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

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

References dundi_ie_append_raw().

00586 {
00587    return dundi_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
00588 }

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 558 of file dundi-parser.c.

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

Referenced by dundi_lookup_thread(), and precache_trans().

00559 {
00560    char tmp[256];
00561    int datalen = data ? strlen(data) + 11 : 11;
00562    int x;
00563    unsigned short myw;
00564    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00565       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);
00566       errorf(tmp);
00567       return -1;
00568    }
00569    ied->buf[ied->pos++] = ie;
00570    ied->buf[ied->pos++] = datalen;
00571    for (x=0;x<6;x++)
00572       ied->buf[ied->pos++] = eid->eid[x];
00573    ied->buf[ied->pos++] = protocol;
00574    myw = htons(flags);
00575    memcpy(ied->buf + ied->pos, &myw, 2);
00576    ied->pos += 2;
00577    myw = htons(weight);
00578    memcpy(ied->buf + ied->pos, &myw, 2);
00579    ied->pos += 2;
00580    memcpy(ied->buf + ied->pos, data, datalen-11);
00581    ied->pos += datalen-11;
00582    return 0;
00583 }

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

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

References dundi_ie_append_raw().

Referenced by handle_command_response().

00615 {
00616    return dundi_ie_append_raw(ied, ie, &dat, 1);
00617 }

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

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

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

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

00499 {
00500    char tmp[256];
00501    int datalen = data ? strlen(data) + 1 : 1;
00502    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00503       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);
00504       errorf(tmp);
00505       return -1;
00506    }
00507    ied->buf[ied->pos++] = ie;
00508    ied->buf[ied->pos++] = datalen;
00509    ied->buf[ied->pos++] = cause;
00510    if (data) {
00511       memcpy(ied->buf + ied->pos, data, datalen-1);
00512       ied->pos += datalen-1;
00513    }
00514    return 0;
00515 }

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

Definition at line 609 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(), handle_command_response(), and precache_trans().

00610 {
00611    return dundi_ie_append_raw(ied, ie, (unsigned char *)eid, sizeof(dundi_eid));
00612 }

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

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

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

Referenced by dundi_encrypt(), and handle_command_response().

00539 {
00540    char tmp[256];
00541    datalen += 16;
00542    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00543       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);
00544       errorf(tmp);
00545       return -1;
00546    }
00547    ied->buf[ied->pos++] = ie;
00548    ied->buf[ied->pos++] = datalen;
00549    memcpy(ied->buf + ied->pos, iv, 16);
00550    ied->pos += 16;
00551    if (data) {
00552       memcpy(ied->buf + ied->pos, data, datalen-16);
00553       ied->pos += datalen-16;
00554    }
00555    return 0;
00556 }

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

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

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

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

00518 {
00519    char tmp[256];
00520    int datalen = data ? strlen(data) + 2 : 2;
00521    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00522       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);
00523       errorf(tmp);
00524       return -1;
00525    }
00526    ied->buf[ied->pos++] = ie;
00527    ied->buf[ied->pos++] = datalen;
00528    flags = htons(flags);
00529    memcpy(ied->buf + ied->pos, &flags, sizeof(flags));
00530    ied->pos += 2;
00531    if (data) {
00532       memcpy(ied->buf + ied->pos, data, datalen-2);
00533       ied->pos += datalen-2;
00534    }
00535    return 0;
00536 }

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

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

References dundi_ie_append_raw().

Referenced by dundi_encrypt().

00591 {
00592    unsigned int newval;
00593    newval = htonl(value);
00594    return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
00595 }

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

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

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

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(), dundi_ie_append_str(), and handle_command_response().

00484 {
00485    char tmp[256];
00486    if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
00487       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);
00488       errorf(tmp);
00489       return -1;
00490    }
00491    ied->buf[ied->pos++] = ie;
00492    ied->buf[ied->pos++] = datalen;
00493    memcpy(ied->buf + ied->pos, data, datalen);
00494    ied->pos += datalen;
00495    return 0;
00496 }

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

Definition at line 597 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().

00598 {
00599    unsigned short newval;
00600    newval = htons(value);
00601    return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
00602 }

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

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

References dundi_ie_append_raw().

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

00605 {
00606    return dundi_ie_append_raw(ied, ie, str, strlen(str));
00607 }

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

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

References dundi_ies::anscount, dundi_ies::answers, dundi_ies::called_context, dundi_ies::called_number, dundi_ies::cause, dundi_ies::causestr, dundi_ies::cbypass, 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, dundi_ies::eid_direct, dundi_ies::eidcount, dundi_ies::eids, dundi_ies::encblock, dundi_ies::enclen, dundi_ies::encsharedkey, dundi_ies::encsig, errorf, dundi_ies::expiration, dundi_ies::hint, dundi_ies::keycrc32, len(), outputf, dundi_ies::q_country, dundi_ies::q_dept, dundi_ies::q_email, dundi_ies::q_ipaddr, dundi_ies::q_locality, dundi_ies::q_org, dundi_ies::q_phone, dundi_ies::q_stateprov, dundi_ies::reqeid, tmp(), dundi_ies::ttl, dundi_ies::unknowncmd, and dundi_ies::version.

Referenced by handle_command_response().

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

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 433 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, dundi_hdr::strans, and tmp().

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

00434 {
00435    char *pref[] = {
00436       "Tx",
00437       "Rx",
00438       "    ETx",
00439       "    Erx" };
00440    char *commands[] = {
00441       "ACK         ",
00442       "DPDISCOVER  ",
00443       "DPRESPONSE  ",
00444       "EIDQUERY    ",
00445       "EIDRESPONSE ",
00446       "PRECACHERQ  ",
00447       "PRECACHERP  ",
00448       "INVALID     ",
00449       "UNKNOWN CMD ",
00450       "NULL        ",
00451       "REQREQ      ",
00452       "REGRESPONSE ",
00453       "CANCEL      ",
00454       "ENCRYPT     ",
00455       "ENCREJ      " };
00456    char class2[20];
00457    char *class;
00458    char subclass2[20];
00459    char *subclass;
00460    char tmp[256];
00461    if ((fhi->cmdresp & 0x3f) > (int)sizeof(commands)/(int)sizeof(char *)) {
00462       snprintf(class2, (int)sizeof(class2), "(%d?)", fhi->cmdresp);
00463       class = class2;
00464    } else {
00465       class = commands[(int)(fhi->cmdresp & 0x3f)];
00466    }
00467    snprintf(subclass2, (int)sizeof(subclass2), "%02hhx", (unsigned char)fhi->cmdflags);
00468    subclass = subclass2;
00469    snprintf(tmp, (int)sizeof(tmp), 
00470       "%s-Frame -- OSeqno: %3.3d ISeqno: %3.3d Type: %s (%s)\n",
00471       pref[rx],
00472       fhi->oseqno, fhi->iseqno, class, fhi->cmdresp & 0x40 ? "Response" : "Command");
00473    outputf(tmp);
00474    snprintf(tmp, (int)sizeof(tmp), 
00475       "%s     Flags: %s STrans: %5.5d  DTrans: %5.5d [%s:%d]%s\n", (rx > 1) ? "     " : "",
00476       subclass, ntohs(fhi->strans) & ~DUNDI_FLAG_RESERVED, ntohs(fhi->dtrans) & ~DUNDI_FLAG_RETRANS,
00477       ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port),
00478       fhi->cmdresp & 0x80 ? " (Final)" : "");
00479    outputf(tmp);
00480    dump_ies(fhi->ies, rx > 1, datalen);
00481 }

int dundi_str_short_to_eid ( dundi_eid eid,
const char *  s 
)

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

References ast_eid::eid.

Referenced by cache_lookup_internal(), dundi_show_cache(), and dundi_show_hints().

00072 {
00073    unsigned int eid_int[6];
00074    int x;
00075    if (sscanf(s, "%2x%2x%2x%2x%2x%2x", &eid_int[0], &eid_int[1], &eid_int[2],
00076        &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
00077          return -1;
00078    for (x = 0; x < 6; x++)
00079       eid->eid[x] = eid_int[x];
00080    return 0;
00081 }


Generated on Thu Apr 16 06:30:47 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6