Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
dundi-parser.c File Reference

Distributed Universal Number Discovery (DUNDi) More...

#include "asterisk.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "asterisk/frame.h"
#include "asterisk/utils.h"
#include "asterisk/dundi.h"
#include "dundi-parser.h"
Include dependency graph for dundi-parser.c:

Go to the source code of this file.

Data Structures

struct  dundi_ie
 

Functions

static void dump_answer (char *output, int maxlen, void *value, int len)
 
static void dump_byte (char *output, int maxlen, void *value, int len)
 
static void dump_cause (char *output, int maxlen, void *value, int len)
 
static void dump_cbypass (char *output, int maxlen, void *value, int len)
 
static void dump_eid (char *output, int maxlen, void *value, int len)
 
static void dump_encrypted (char *output, int maxlen, void *value, int len)
 
static void dump_hint (char *output, int maxlen, void *value, int len)
 
static void dump_ies (unsigned char *iedata, int spaces, int len)
 
static void dump_int (char *output, int maxlen, void *value, int len)
 
static void dump_raw (char *output, int maxlen, void *value, int len)
 
static void dump_short (char *output, int maxlen, void *value, int len)
 
static void dump_string (char *output, int maxlen, void *value, int len)
 
char * dundi_eid_to_str_short (char *s, int maxlen, dundi_eid *eid)
 
int dundi_eid_zero (dundi_eid *eid)
 
char * dundi_flags2str (char *buf, int bufsiz, int flags)
 
char * dundi_hint2str (char *buf, int bufsiz, 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 *data)
 
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 *data)
 
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(*func)(const char *))
 
void dundi_set_output (void(*func)(const char *))
 
void dundi_showframe (struct dundi_hdr *fhi, int rx, struct ast_sockaddr *sin, int datalen)
 
int dundi_str_short_to_eid (dundi_eid *eid, const char *s)
 
static void internalerror (const char *str)
 
static void internaloutput (const char *str)
 
static char * proto2str (int proto, char *buf, int bufsiz)
 

Variables

static void(* errorf )(const char *str) = internalerror
 
static struct dundi_ie infoelts []
 
static void(* outputf )(const char *str) = internaloutput
 

Detailed Description

Distributed Universal Number Discovery (DUNDi)

Definition in file dundi-parser.c.

Function Documentation

◆ dump_answer()

static void dump_answer ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

References answer(), ast_eid_to_str(), dundi_answer::data, dundi_flags2str(), dundi_answer::eid, dundi_answer::flags, proto2str(), dundi_answer::protocol, tmp(), and dundi_answer::weight.

285 {
286  struct dundi_answer *answer;
287  char proto[40];
288  char flags[40];
289  char eid_str[40];
290  char tmp[512]="";
291  int datalen;
292 
293  if (len < sizeof(*answer)) {
294  snprintf(output, maxlen, "Invalid Answer");
295  return;
296  }
297 
298  answer = (struct dundi_answer *)(value);
299 
300  datalen = len - offsetof(struct dundi_answer, data);
301  if (datalen > sizeof(tmp) - 1)
302  datalen = sizeof(tmp) - 1;
303 
304  memcpy(tmp, answer->data, datalen);
305  tmp[datalen] = '\0';
306 
307  ast_eid_to_str(eid_str, sizeof(eid_str), &answer->eid);
308  snprintf(output, maxlen, "[%s] %d <%s/%s> from [%s]",
309  dundi_flags2str(flags, sizeof(flags), ntohs(answer->flags)),
310  ntohs(answer->weight),
311  proto2str(answer->protocol, proto, sizeof(proto)),
312  tmp, eid_str);
313 }
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
Definition: main/utils.c:2587
static int tmp()
Definition: bt_open.c:389
int value
Definition: syslog.c:37
unsigned short flags
Definition: dundi.h:105
unsigned char protocol
Definition: dundi.h:104
static int answer(void *data)
Definition: chan_pjsip.c:682
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
unsigned short weight
Definition: dundi.h:106
static char * proto2str(int proto, char *buf, int bufsiz)
Definition: dundi-parser.c:224
dundi_eid eid
Definition: dundi.h:103
char * dundi_flags2str(char *buf, int bufsiz, int flags)
Definition: dundi-parser.c:246
unsigned char data[0]
Definition: dundi.h:107

◆ dump_byte()

static void dump_byte ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

References ast_copy_string().

217 {
218  if (len == (int)sizeof(unsigned char))
219  snprintf(output, maxlen, "%d", *((unsigned char *)value));
220  else
221  ast_copy_string(output, "Invalid BYTE", maxlen);
222 }
int value
Definition: syslog.c:37
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ dump_cause()

static void dump_cause ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

References ARRAY_LEN, ast_strlen_zero, dundi_cause::causecode, causes, desc, and dundi_cause::desc.

160 {
161  static const char * const causes[] = {
162  "SUCCESS",
163  "GENERAL",
164  "DYNAMIC",
165  "NOAUTH" ,
166  };
167  char tmp2[256];
168  struct dundi_cause *cause;
169  int datalen;
170  int causecode;
171 
172  if (len < sizeof(*cause)) {
173  snprintf(output, maxlen, "<invalid contents>");
174  return;
175  }
176 
177  cause = (struct dundi_cause*) value;
178  causecode = cause->causecode;
179 
180  datalen = len - offsetof(struct dundi_cause, desc);
181  if (datalen > sizeof(tmp2) - 1)
182  datalen = sizeof(tmp2) - 1;
183 
184  memcpy(tmp2, cause->desc, datalen);
185  tmp2[datalen] = '\0';
186 
187  if (causecode < ARRAY_LEN(causes)) {
188  if (ast_strlen_zero(tmp2))
189  snprintf(output, maxlen, "%s", causes[causecode]);
190  else
191  snprintf(output, maxlen, "%s: %s", causes[causecode], tmp2);
192  } else {
193  if (ast_strlen_zero(tmp2))
194  snprintf(output, maxlen, "%d", causecode);
195  else
196  snprintf(output, maxlen, "%d: %s", causecode, tmp2);
197  }
198 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const char desc[]
Definition: cdr_mysql.c:73
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
static const struct causes_map causes[]
Definition: channel.c:136
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char desc[0]
Definition: dundi.h:136
unsigned char causecode
Definition: dundi.h:135

◆ dump_cbypass()

static void dump_cbypass ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

99 {
100  snprintf(output, maxlen, "Bypass Caches");
101 }

◆ dump_eid()

static void dump_eid ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

References ast_eid_to_str().

104 {
105  if (len == 6)
106  ast_eid_to_str(output, maxlen, (dundi_eid *)value);
107  else
108  snprintf(output, maxlen, "Invalid EID len %d", len);
109 }
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
Definition: main/utils.c:2587
int value
Definition: syslog.c:37
An Entity ID is essentially a MAC address, brief and unique.
Definition: utils.h:786
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ dump_encrypted()

static void dump_encrypted ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

316 {
317  char iv[33];
318  int x;
319  if ((len > 16) && !(len % 16)) {
320  /* Build up IV */
321  for (x=0;x<16;x++) {
322  snprintf(iv + (x << 1), 3, "%02hhx", ((unsigned char *)value)[x]);
323  }
324  snprintf(output, maxlen, "[IV %s] %d encrypted blocks\n", iv, len / 16);
325  } else
326  snprintf(output, maxlen, "Invalid Encrypted Datalen %d", len);
327 }
int value
Definition: syslog.c:37
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ dump_hint()

static void dump_hint ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

References ast_strlen_zero, dundi_hint::data, ast_frame::datalen, dundi_hint2str(), and dundi_hint::flags.

132 {
133  char tmp2[256];
134  char tmp3[256];
135  int datalen;
136  struct dundi_hint *hint;
137  if (len < sizeof(*hint)) {
138  snprintf(output, maxlen, "<invalid contents>");
139  return;
140  }
141 
142  hint = (struct dundi_hint *) value;;
143 
144  datalen = len - offsetof(struct dundi_hint, data);
145  if (datalen > sizeof(tmp3) - 1)
146  datalen = sizeof(tmp3) - 1;
147 
148  memcpy(tmp3, hint->data, datalen);
149  tmp3[datalen] = '\0';
150 
151  dundi_hint2str(tmp2, sizeof(tmp2), ntohs(hint->flags));
152 
153  if (ast_strlen_zero(tmp3))
154  snprintf(output, maxlen, "[%s]", tmp2);
155  else
156  snprintf(output, maxlen, "[%s] %s", tmp2, tmp3);
157 }
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
unsigned char data[0]
Definition: dundi.h:112
unsigned short flags
Definition: dundi.h:111
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * dundi_hint2str(char *buf, int bufsiz, int flags)
Definition: dundi-parser.c:111

◆ dump_ies()

static void dump_ies ( unsigned char *  iedata,
int  spaces,
int  len 
)
static

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

References ARRAY_LEN, dundi_ie::dump, DUNDI_IE_ENCDATA, dundi_ie::ie, infoelts, dundi_ie::name, outputf, and tmp().

Referenced by dundi_showframe().

384 {
385  int ielen;
386  int ie;
387  int x;
388  int found;
389  char interp[1024];
390  char tmp[1051];
391  if (len < 2)
392  return;
393  while(len >= 2) {
394  ie = iedata[0];
395  ielen = iedata[1];
396  /* Encrypted data is the remainder */
397  if (ie == DUNDI_IE_ENCDATA)
398  ielen = len - 2;
399  if (ielen + 2> len) {
400  snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
401  outputf(tmp);
402  return;
403  }
404  found = 0;
405  for (x = 0; x < ARRAY_LEN(infoelts); x++) {
406  if (infoelts[x].ie == ie) {
407  if (infoelts[x].dump) {
408  infoelts[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
409  snprintf(tmp, (int)sizeof(tmp), " %s%-15.15s : %s\n", (spaces ? " " : "" ), infoelts[x].name, interp);
410  outputf(tmp);
411  } else {
412  if (ielen)
413  snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
414  else
415  strcpy(interp, "Present");
416  snprintf(tmp, (int)sizeof(tmp), " %s%-15.15s : %s\n", (spaces ? " " : "" ), infoelts[x].name, interp);
417  outputf(tmp);
418  }
419  found++;
420  }
421  }
422  if (!found) {
423  snprintf(tmp, (int)sizeof(tmp), " %sUnknown IE %03d : Present\n", (spaces ? " " : "" ), ie);
424  outputf(tmp);
425  }
426  iedata += (2 + ielen);
427  len -= (2 + ielen);
428  }
429  outputf("\n");
430 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static int tmp()
Definition: bt_open.c:389
static struct dundi_ie infoelts[]
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void(* outputf)(const char *str)
Definition: dundi-parser.c:51
static const char name[]
Definition: cdr_mysql.c:74
void(* dump)(char *output, int maxlen, void *value, int len)
Definition: dundi-parser.c:344
#define DUNDI_IE_ENCDATA
Definition: dundi.h:193

◆ dump_int()

static void dump_int ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

References ast_copy_string().

201 {
202  if (len == (int)sizeof(unsigned int))
203  snprintf(output, maxlen, "%lu", (unsigned long)ntohl(*((unsigned int *)value)));
204  else
205  ast_copy_string(output, "Invalid INT", maxlen);
206 }
int value
Definition: syslog.c:37
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ dump_raw()

static void dump_raw ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

References len(), and value.

330 {
331  int x;
332  unsigned char *u = value;
333  output[maxlen - 1] = '\0';
334  strcpy(output, "[ ");
335  for (x=0;x<len;x++) {
336  snprintf(output + strlen(output), maxlen - strlen(output) - 1, "%02hhx ", u[x]);
337  }
338  strncat(output + strlen(output), "]", maxlen - strlen(output) - 1);
339 }
int value
Definition: syslog.c:37
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ dump_short()

static void dump_short ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

References ast_copy_string().

209 {
210  if (len == (int)sizeof(unsigned short))
211  snprintf(output, maxlen, "%d", ntohs(*((unsigned short *)value)));
212  else
213  ast_copy_string(output, "Invalid SHORT", maxlen);
214 }
int value
Definition: syslog.c:37
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ dump_string()

static void dump_string ( char *  output,
int  maxlen,
void *  value,
int  len 
)
static

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

91 {
92  if (maxlen > len + 1)
93  maxlen = len + 1;
94 
95  snprintf(output, maxlen, "%s", (char *) value);
96 }
int value
Definition: syslog.c:37
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ dundi_eid_to_str_short()

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

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

References ast_eid::eid.

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

55 {
56  int x;
57  char *os = s;
58  if (maxlen < 13) {
59  if (s && (maxlen > 0))
60  *s = '\0';
61  } else {
62  for (x=0;x<6;x++) {
63  sprintf(s, "%02hhX", (unsigned char)eid->eid[x]);
64  s += 2;
65  }
66  }
67  return os;
68 }
unsigned char eid[6]
Definition: utils.h:787

◆ dundi_eid_zero()

int dundi_eid_zero ( dundi_eid eid)

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

83 {
84  int x;
85  for (x = 0; x < ARRAY_LEN(eid->eid); x++)
86  if (eid->eid[x]) return 0;
87  return 1;
88 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
unsigned char eid[6]
Definition: utils.h:787

◆ dundi_flags2str()

char* dundi_flags2str ( char *  buf,
int  bufsiz,
int  flags 
)

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

References ast_strlen_zero, buf, 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().

247 {
248  strcpy(buf, "");
249  buf[bufsiz-1] = '\0';
250  if (flags & DUNDI_FLAG_EXISTS) {
251  strncat(buf, "EXISTS|", bufsiz - strlen(buf) - 1);
252  }
253  if (flags & DUNDI_FLAG_MATCHMORE) {
254  strncat(buf, "MATCHMORE|", bufsiz - strlen(buf) - 1);
255  }
256  if (flags & DUNDI_FLAG_CANMATCH) {
257  strncat(buf, "CANMATCH|", bufsiz - strlen(buf) - 1);
258  }
259  if (flags & DUNDI_FLAG_IGNOREPAT) {
260  strncat(buf, "IGNOREPAT|", bufsiz - strlen(buf) - 1);
261  }
263  strncat(buf, "RESIDENCE|", bufsiz - strlen(buf) - 1);
264  }
266  strncat(buf, "COMMERCIAL|", bufsiz - strlen(buf) - 1);
267  }
268  if (flags & DUNDI_FLAG_MOBILE) {
269  strncat(buf, "MOBILE", bufsiz - strlen(buf) - 1);
270  }
272  strncat(buf, "NOUNSLCTD|", bufsiz - strlen(buf) - 1);
273  }
275  strncat(buf, "NOCOMUNSLTD|", bufsiz - strlen(buf) - 1);
276  }
277  /* Get rid of trailing | */
278  if (ast_strlen_zero(buf))
279  strcpy(buf, "NONE|");
280  buf[strlen(buf)-1] = '\0';
281  return buf;
282 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strlen_zero(foo)
Definition: strings.h:52
unsigned short flags
Definition: dundi.h:111

◆ dundi_hint2str()

char* dundi_hint2str ( char *  buf,
int  bufsiz,
int  flags 
)

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

References ast_strlen_zero, buf, DUNDI_HINT_DONT_ASK, DUNDI_HINT_TTL_EXPIRED, and DUNDI_HINT_UNAFFECTED.

Referenced by dump_hint().

112 {
113  strcpy(buf, "");
114  buf[bufsiz-1] = '\0';
116  strncat(buf, "TTLEXPIRED|", bufsiz - strlen(buf) - 1);
117  }
118  if (flags & DUNDI_HINT_DONT_ASK) {
119  strncat(buf, "DONTASK|", bufsiz - strlen(buf) - 1);
120  }
122  strncat(buf, "UNAFFECTED|", bufsiz - strlen(buf) - 1);
123  }
124  /* Get rid of trailing | */
125  if (ast_strlen_zero(buf))
126  strcpy(buf, "NONE|");
127  buf[strlen(buf)-1] = '\0';
128  return buf;
129 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_strlen_zero(foo)
Definition: strings.h:52
unsigned short flags
Definition: dundi.h:111

◆ dundi_ie2str()

const char* dundi_ie2str ( int  ie)

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

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

374 {
375  int x;
376  for (x = 0; x < ARRAY_LEN(infoelts); x++) {
377  if (infoelts[x].ie == ie)
378  return infoelts[x].name;
379  }
380  return "Unknown IE";
381 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct dundi_ie infoelts[]
char * name
Definition: dundi-parser.c:343

◆ dundi_ie_append()

int dundi_ie_append ( struct dundi_ie_data ied,
unsigned char  ie 
)

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

References dundi_ie_append_raw(), and NULL.

Referenced by dundi_discover().

621 {
622  return dundi_ie_append_raw(ied, ie, NULL, 0);
623 }
#define NULL
Definition: resample.c:96
int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
Definition: dundi-parser.c:484

◆ dundi_ie_append_addr()

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

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

References dundi_ie_append_raw().

587 {
588  return dundi_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
589 }
int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
Definition: dundi-parser.c:484

◆ dundi_ie_append_answer()

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 *  data 
)

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

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

Referenced by dundi_lookup_thread(), and precache_trans().

560 {
561  char tmp[256];
562  int datalen = data ? strlen(data) + 11 : 11;
563  int x;
564  unsigned short myw;
565  if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
566  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);
567  errorf(tmp);
568  return -1;
569  }
570  ied->buf[ied->pos++] = ie;
571  ied->buf[ied->pos++] = datalen;
572  for (x=0;x<6;x++)
573  ied->buf[ied->pos++] = eid->eid[x];
574  ied->buf[ied->pos++] = protocol;
575  myw = htons(flags);
576  memcpy(ied->buf + ied->pos, &myw, 2);
577  ied->pos += 2;
578  myw = htons(weight);
579  memcpy(ied->buf + ied->pos, &myw, 2);
580  ied->pos += 2;
581  memcpy(ied->buf + ied->pos, data, datalen-11);
582  ied->pos += datalen-11;
583  return 0;
584 }
static int tmp()
Definition: bt_open.c:389
unsigned char data[0]
Definition: dundi.h:112
unsigned char buf[8192]
Definition: dundi-parser.h:56
unsigned char eid[6]
Definition: utils.h:787
unsigned short flags
Definition: dundi.h:111
char weight
static void(* errorf)(const char *str)
Definition: dundi-parser.c:52
const char * dundi_ie2str(int ie)
Definition: dundi-parser.c:373

◆ dundi_ie_append_byte()

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

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

References dundi_ie_append_raw().

Referenced by handle_command_response().

616 {
617  return dundi_ie_append_raw(ied, ie, &dat, 1);
618 }
int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
Definition: dundi-parser.c:484

◆ dundi_ie_append_cause()

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

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

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

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

500 {
501  char tmp[256];
502  int datalen = data ? strlen(data) + 1 : 1;
503  if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
504  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);
505  errorf(tmp);
506  return -1;
507  }
508  ied->buf[ied->pos++] = ie;
509  ied->buf[ied->pos++] = datalen;
510  ied->buf[ied->pos++] = cause;
511  if (data) {
512  memcpy(ied->buf + ied->pos, data, datalen-1);
513  ied->pos += datalen-1;
514  }
515  return 0;
516 }
static int tmp()
Definition: bt_open.c:389
unsigned char data[0]
Definition: dundi.h:112
unsigned char buf[8192]
Definition: dundi-parser.h:56
static void(* errorf)(const char *str)
Definition: dundi-parser.c:52
const char * dundi_ie2str(int ie)
Definition: dundi-parser.c:373

◆ dundi_ie_append_eid()

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

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

611 {
612  return dundi_ie_append_raw(ied, ie, (unsigned char *)eid, sizeof(dundi_eid));
613 }
An Entity ID is essentially a MAC address, brief and unique.
Definition: utils.h:786
int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
Definition: dundi-parser.c:484

◆ dundi_ie_append_encdata()

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

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

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

Referenced by dundi_encrypt(), and handle_command_response().

540 {
541  char tmp[256];
542  datalen += 16;
543  if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
544  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);
545  errorf(tmp);
546  return -1;
547  }
548  ied->buf[ied->pos++] = ie;
549  ied->buf[ied->pos++] = datalen;
550  memcpy(ied->buf + ied->pos, iv, 16);
551  ied->pos += 16;
552  if (data) {
553  memcpy(ied->buf + ied->pos, data, datalen-16);
554  ied->pos += datalen-16;
555  }
556  return 0;
557 }
static int tmp()
Definition: bt_open.c:389
unsigned char data[0]
Definition: dundi.h:112
unsigned char buf[8192]
Definition: dundi-parser.h:56
static void(* errorf)(const char *str)
Definition: dundi-parser.c:52
const char * dundi_ie2str(int ie)
Definition: dundi-parser.c:373

◆ dundi_ie_append_hint()

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

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

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

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

519 {
520  char tmp[256];
521  int datalen = data ? strlen(data) + 2 : 2;
522  if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
523  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);
524  errorf(tmp);
525  return -1;
526  }
527  ied->buf[ied->pos++] = ie;
528  ied->buf[ied->pos++] = datalen;
529  flags = htons(flags);
530  memcpy(ied->buf + ied->pos, &flags, sizeof(flags));
531  ied->pos += 2;
532  if (data) {
533  memcpy(ied->buf + ied->pos, data, datalen-2);
534  ied->pos += datalen-2;
535  }
536  return 0;
537 }
static int tmp()
Definition: bt_open.c:389
unsigned char data[0]
Definition: dundi.h:112
unsigned char buf[8192]
Definition: dundi-parser.h:56
unsigned short flags
Definition: dundi.h:111
static void(* errorf)(const char *str)
Definition: dundi-parser.c:52
const char * dundi_ie2str(int ie)
Definition: dundi-parser.c:373

◆ dundi_ie_append_int()

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

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

References dundi_ie_append_raw().

Referenced by dundi_encrypt().

592 {
593  unsigned int newval;
594  newval = htonl(value);
595  return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
596 }
int value
Definition: syslog.c:37
int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
Definition: dundi-parser.c:484

◆ dundi_ie_append_raw()

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

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

References dundi_ie_data::buf, dundi_ie2str(), errorf, dundi_ie::ie, 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().

485 {
486  char tmp[256];
487  if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
488  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);
489  errorf(tmp);
490  return -1;
491  }
492  ied->buf[ied->pos++] = ie;
493  ied->buf[ied->pos++] = datalen;
494  memcpy(ied->buf + ied->pos, data, datalen);
495  ied->pos += datalen;
496  return 0;
497 }
static int tmp()
Definition: bt_open.c:389
unsigned char data[0]
Definition: dundi.h:112
unsigned char buf[8192]
Definition: dundi-parser.h:56
static void(* errorf)(const char *str)
Definition: dundi-parser.c:52
const char * dundi_ie2str(int ie)
Definition: dundi-parser.c:373

◆ dundi_ie_append_short()

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

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

599 {
600  unsigned short newval;
601  newval = htons(value);
602  return dundi_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
603 }
int value
Definition: syslog.c:37
int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
Definition: dundi-parser.c:484

◆ dundi_ie_append_str()

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

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

References dundi_ie_append_raw().

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

606 {
607  return dundi_ie_append_raw(ied, ie, str, strlen(str));
608 }
const char * str
Definition: app_jack.c:147
int dundi_ie_append_raw(struct dundi_ie_data *ied, unsigned char ie, void *data, int datalen)
Definition: dundi-parser.c:484

◆ dundi_parse_ies()

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

Definition at line 635 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_ie::ie, 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().

636 {
637  /* Parse data into information elements */
638  int len;
639  int ie;
640  char tmp[256];
641  memset(ies, 0, (int)sizeof(struct dundi_ies));
642  ies->ttl = -1;
643  ies->expiration = -1;
644  ies->unknowncmd = -1;
645  ies->cause = -1;
646  while(datalen >= 2) {
647  ie = data[0];
648  len = data[1];
649  if (len > datalen - 2) {
650  errorf("Information element length exceeds message size\n");
651  return -1;
652  }
653  switch(ie) {
654  case DUNDI_IE_EID:
655  case DUNDI_IE_EID_DIRECT:
656  if (len != (int)sizeof(dundi_eid)) {
657  errorf("Improper entity identifer, expecting 6 bytes!\n");
658  } else if (ies->eidcount < DUNDI_MAX_STACK) {
659  ies->eids[ies->eidcount] = (dundi_eid *)(data + 2);
660  ies->eid_direct[ies->eidcount] = (ie == DUNDI_IE_EID_DIRECT);
661  ies->eidcount++;
662  } else
663  errorf("Too many entities in stack!\n");
664  break;
665  case DUNDI_IE_REQEID:
666  if (len != (int)sizeof(dundi_eid)) {
667  errorf("Improper requested entity identifer, expecting 6 bytes!\n");
668  } else
669  ies->reqeid = (dundi_eid *)(data + 2);
670  break;
672  ies->called_context = (char *)data + 2;
673  break;
675  ies->called_number = (char *)data + 2;
676  break;
677  case DUNDI_IE_ANSWER:
678  if (len < sizeof(struct dundi_answer)) {
679  snprintf(tmp, (int)sizeof(tmp), "Answer expected to be >=%d bytes long but was %d\n", (int)sizeof(struct dundi_answer), len);
680  errorf(tmp);
681  } else {
682  if (ies->anscount < DUNDI_MAX_ANSWERS)
683  ies->answers[ies->anscount++]= (struct dundi_answer *)(data + 2);
684  else
685  errorf("Ignoring extra answers!\n");
686  }
687  break;
688  case DUNDI_IE_TTL:
689  if (len != (int)sizeof(unsigned short)) {
690  snprintf(tmp, (int)sizeof(tmp), "Expecting ttl to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
691  errorf(tmp);
692  } else
693  ies->ttl = ntohs(*((unsigned short *)(data + 2)));
694  break;
695  case DUNDI_IE_VERSION:
696  if (len != (int)sizeof(unsigned short)) {
697  snprintf(tmp, (int)sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
698  errorf(tmp);
699  } else
700  ies->version = ntohs(*((unsigned short *)(data + 2)));
701  break;
702  case DUNDI_IE_EXPIRATION:
703  if (len != (int)sizeof(unsigned short)) {
704  snprintf(tmp, (int)sizeof(tmp), "Expecting expiration to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
705  errorf(tmp);
706  } else
707  ies->expiration = ntohs(*((unsigned short *)(data + 2)));
708  break;
709  case DUNDI_IE_KEYCRC32:
710  if (len != (int)sizeof(unsigned int)) {
711  snprintf(tmp, (int)sizeof(tmp), "Expecting expiration to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
712  errorf(tmp);
713  } else
714  ies->keycrc32 = ntohl(*((unsigned int *)(data + 2)));
715  break;
716  case DUNDI_IE_UNKNOWN:
717  if (len == 1)
718  ies->unknowncmd = data[2];
719  else {
720  snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
721  errorf(tmp);
722  }
723  break;
724  case DUNDI_IE_CAUSE:
725  if (len >= 1) {
726  ies->cause = data[2];
727  ies->causestr = (char *)data + 3;
728  } else {
729  snprintf(tmp, (int)sizeof(tmp), "Expected at least one byte cause, but was %d long\n", len);
730  errorf(tmp);
731  }
732  break;
733  case DUNDI_IE_HINT:
734  if (len >= 2) {
735  ies->hint = (struct dundi_hint *)(data + 2);
736  } else {
737  snprintf(tmp, (int)sizeof(tmp), "Expected at least two byte hint, but was %d long\n", len);
738  errorf(tmp);
739  }
740  break;
741  case DUNDI_IE_DEPARTMENT:
742  ies->q_dept = (char *)data + 2;
743  break;
745  ies->q_org = (char *)data + 2;
746  break;
747  case DUNDI_IE_LOCALITY:
748  ies->q_locality = (char *)data + 2;
749  break;
750  case DUNDI_IE_STATE_PROV:
751  ies->q_stateprov = (char *)data + 2;
752  break;
753  case DUNDI_IE_COUNTRY:
754  ies->q_country = (char *)data + 2;
755  break;
756  case DUNDI_IE_EMAIL:
757  ies->q_email = (char *)data + 2;
758  break;
759  case DUNDI_IE_PHONE:
760  ies->q_phone = (char *)data + 2;
761  break;
762  case DUNDI_IE_IPADDR:
763  ies->q_ipaddr = (char *)data + 2;
764  break;
765  case DUNDI_IE_ENCDATA:
766  /* Recalculate len as the remainder of the message, regardless of
767  theoretical length */
768  len = datalen - 2;
769  if ((len > 16) && !(len % 16)) {
770  ies->encblock = (struct dundi_encblock *)(data + 2);
771  ies->enclen = len - 16;
772  } else {
773  snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted data length %d\n", len);
774  errorf(tmp);
775  }
776  break;
777  case DUNDI_IE_SHAREDKEY:
778  if (len == 128) {
779  ies->encsharedkey = (unsigned char *)(data + 2);
780  } else {
781  snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted shared key length %d\n", len);
782  errorf(tmp);
783  }
784  break;
785  case DUNDI_IE_SIGNATURE:
786  if (len == 128) {
787  ies->encsig = (unsigned char *)(data + 2);
788  } else {
789  snprintf(tmp, (int)sizeof(tmp), "Invalid encrypted signature length %d\n", len);
790  errorf(tmp);
791  }
792  break;
794  ies->cbypass = 1;
795  break;
796  default:
797  snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", dundi_ie2str(ie), ie, len);
798  outputf(tmp);
799  }
800  /* Overwrite information element with 0, to null terminate previous portion */
801  data[0] = 0;
802  datalen -= (len + 2);
803  data += (len + 2);
804  }
805  /* Null-terminate last field */
806  *data = '\0';
807  if (datalen) {
808  errorf("Invalid information element contents, strange boundary\n");
809  return -1;
810  }
811  return 0;
812 }
#define DUNDI_IE_EXPIRATION
Definition: dundi.h:189
dundi_eid * reqeid
Definition: dundi-parser.h:24
#define DUNDI_IE_EID_DIRECT
Definition: dundi.h:185
#define DUNDI_IE_IPADDR
Definition: dundi.h:206
#define DUNDI_IE_CACHEBYPASS
Definition: dundi.h:207
struct dundi_answer * answers[DUNDI_MAX_ANSWERS+1]
Definition: dundi-parser.h:28
char * q_org
Definition: dundi-parser.h:38
#define DUNDI_IE_SHAREDKEY
Definition: dundi.h:194
char * causestr
Definition: dundi-parser.h:45
char * q_locality
Definition: dundi-parser.h:39
static int tmp()
Definition: bt_open.c:389
#define DUNDI_IE_CAUSE
Definition: dundi.h:191
#define DUNDI_IE_EMAIL
Definition: dundi.h:204
#define DUNDI_IE_REQEID
Definition: dundi.h:192
int eid_direct[DUNDI_MAX_STACK+1]
Definition: dundi-parser.h:23
char * called_number
Definition: dundi-parser.h:27
char * q_country
Definition: dundi-parser.h:41
#define DUNDI_IE_VERSION
Definition: dundi.h:188
#define DUNDI_IE_DEPARTMENT
Definition: dundi.h:199
dundi_eid * eids[DUNDI_MAX_STACK+1]
Definition: dundi-parser.h:22
An Entity ID is essentially a MAC address, brief and unique.
Definition: utils.h:786
unsigned char data[0]
Definition: dundi.h:112
int eidcount
Definition: dundi-parser.h:25
#define DUNDI_IE_LOCALITY
Definition: dundi.h:201
#define DUNDI_IE_UNKNOWN
Definition: dundi.h:190
#define DUNDI_IE_KEYCRC32
Definition: dundi.h:196
#define DUNDI_IE_SIGNATURE
Definition: dundi.h:195
struct dundi_encblock * encblock
Definition: dundi-parser.h:49
char * q_ipaddr
Definition: dundi-parser.h:44
unsigned long keycrc32
Definition: dundi-parser.h:48
#define DUNDI_IE_PHONE
Definition: dundi.h:205
#define DUNDI_IE_EID
Definition: dundi.h:182
unsigned char * encsharedkey
Definition: dundi-parser.h:46
int expiration
Definition: dundi-parser.h:33
#define DUNDI_MAX_ANSWERS
Definition: dundi-parser.h:19
char * q_stateprov
Definition: dundi-parser.h:40
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define DUNDI_IE_CALLED_CONTEXT
Definition: dundi.h:183
unsigned char * encsig
Definition: dundi-parser.h:47
#define DUNDI_IE_ORGANIZATION
Definition: dundi.h:200
static void(* outputf)(const char *str)
Definition: dundi-parser.c:51
#define DUNDI_IE_HINT
Definition: dundi.h:197
int anscount
Definition: dundi-parser.h:30
char * called_context
Definition: dundi-parser.h:26
#define DUNDI_MAX_STACK
Definition: dundi-parser.h:18
#define DUNDI_IE_CALLED_NUMBER
Definition: dundi.h:184
char * q_dept
Definition: dundi-parser.h:37
#define DUNDI_IE_STATE_PROV
Definition: dundi.h:202
char * q_phone
Definition: dundi-parser.h:43
#define DUNDI_IE_COUNTRY
Definition: dundi.h:203
#define DUNDI_IE_ENCDATA
Definition: dundi.h:193
struct dundi_hint * hint
Definition: dundi-parser.h:29
int unknowncmd
Definition: dundi-parser.h:34
static void(* errorf)(const char *str)
Definition: dundi-parser.c:52
const char * dundi_ie2str(int ie)
Definition: dundi-parser.c:373
char * q_email
Definition: dundi-parser.h:42
#define DUNDI_IE_ANSWER
Definition: dundi.h:186
unsigned char data[0]
Definition: dundi.h:107
#define DUNDI_IE_TTL
Definition: dundi.h:187

◆ dundi_set_error()

void dundi_set_error ( void(*)(const char *)  func)

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

References errorf.

Referenced by load_module().

631 {
632  errorf = func;
633 }
static void(* errorf)(const char *str)
Definition: dundi-parser.c:52

◆ dundi_set_output()

void dundi_set_output ( void(*)(const char *)  func)

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

References outputf.

Referenced by load_module().

626 {
627  outputf = func;
628 }
static void(* outputf)(const char *str)
Definition: dundi-parser.c:51

◆ dundi_showframe()

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

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

References ARRAY_LEN, ast_sockaddr_stringify(), 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().

433 {
434  char *pref[] = {
435  "Tx",
436  "Rx",
437  " ETx",
438  " Erx" };
439  char *commands[] = {
440  "ACK ",
441  "DPDISCOVER ",
442  "DPRESPONSE ",
443  "EIDQUERY ",
444  "EIDRESPONSE ",
445  "PRECACHERQ ",
446  "PRECACHERP ",
447  "INVALID ",
448  "UNKNOWN CMD ",
449  "NULL ",
450  "REGREQ ",
451  "REGRESPONSE ",
452  "CANCEL ",
453  "ENCRYPT ",
454  "ENCREJ " };
455  char class2[20];
456  char *class;
457  char subclass2[20];
458  char *subclass;
459  char tmp[256];
460  if ((fhi->cmdresp & 0x3f) >= ARRAY_LEN(commands)) {
461  snprintf(class2, sizeof(class2), "(%d?)", fhi->cmdresp & 0x3f);
462  class = class2;
463  } else {
464  class = commands[fhi->cmdresp & 0x3f];
465  }
466  snprintf(subclass2, sizeof(subclass2), "%02hhx", (unsigned char)fhi->cmdflags);
467  subclass = subclass2;
468  snprintf(tmp, sizeof(tmp),
469  "%s-Frame -- OSeqno: %3.3d ISeqno: %3.3d Type: %s (%s)\n",
470  pref[rx],
471  fhi->oseqno, fhi->iseqno, class, fhi->cmdresp & 0x40 ? "Response" : "Command");
472  outputf(tmp);
473 
474  snprintf(tmp, (int)sizeof(tmp),
475  "%s Flags: %s STrans: %5.5d DTrans: %5.5d [%s]%s\n", (rx > 1) ? " " : "",
476  subclass, ntohs(fhi->strans) & ~DUNDI_FLAG_RESERVED, ntohs(fhi->dtrans) & ~DUNDI_FLAG_RETRANS,
478  fhi->cmdresp & 0x80 ? " (Final)" : "");
479 
480  outputf(tmp);
481  dump_ies(fhi->ies, rx > 1, datalen);
482 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static int tmp()
Definition: bt_open.c:389
#define DUNDI_FLAG_RETRANS
Definition: dundi.h:50
unsigned char cmdresp
Definition: dundi.h:39
unsigned char oseqno
Definition: dundi.h:38
#define DUNDI_FLAG_RESERVED
Definition: dundi.h:51
unsigned char cmdflags
Definition: dundi.h:40
static struct agi_command commands[]
AGI commands list.
Definition: res_agi.c:3706
unsigned char ies[0]
Definition: dundi.h:41
static void dump_ies(unsigned char *iedata, int spaces, int len)
Definition: dundi-parser.c:383
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:260
static void(* outputf)(const char *str)
Definition: dundi-parser.c:51
unsigned short strans
Definition: dundi.h:35
unsigned short dtrans
Definition: dundi.h:36
unsigned char iseqno
Definition: dundi.h:37

◆ dundi_str_short_to_eid()

int dundi_str_short_to_eid ( dundi_eid eid,
const char *  s 
)

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

References ast_eid::eid.

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

71 {
72  unsigned int eid_int[6];
73  int x;
74  if (sscanf(s, "%2x%2x%2x%2x%2x%2x", &eid_int[0], &eid_int[1], &eid_int[2],
75  &eid_int[3], &eid_int[4], &eid_int[5]) != 6)
76  return -1;
77  for (x = 0; x < 6; x++)
78  eid->eid[x] = eid_int[x];
79  return 0;
80 }
unsigned char eid[6]
Definition: utils.h:787

◆ internalerror()

static void internalerror ( const char *  str)
static

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

47 {
48  fprintf(stderr, "WARNING: %s", str);
49 }
const char * str
Definition: app_jack.c:147

◆ internaloutput()

static void internaloutput ( const char *  str)
static

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

42 {
43  fputs(str, stdout);
44 }
const char * str
Definition: app_jack.c:147

◆ proto2str()

static char* proto2str ( int  proto,
char *  buf,
int  bufsiz 
)
static

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

References buf, DUNDI_PROTO_H323, DUNDI_PROTO_IAX, DUNDI_PROTO_NONE, and DUNDI_PROTO_SIP.

Referenced by dump_answer().

225 {
226  switch(proto) {
227  case DUNDI_PROTO_NONE:
228  strncpy(buf, "None", bufsiz - 1);
229  break;
230  case DUNDI_PROTO_IAX:
231  strncpy(buf, "IAX", bufsiz - 1);
232  break;
233  case DUNDI_PROTO_SIP:
234  strncpy(buf, "SIP", bufsiz - 1);
235  break;
236  case DUNDI_PROTO_H323:
237  strncpy(buf, "H.323", bufsiz - 1);
238  break;
239  default:
240  snprintf(buf, bufsiz, "Unknown Proto(%d)", proto);
241  }
242  buf[bufsiz-1] = '\0';
243  return buf;
244 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66

Variable Documentation

◆ errorf

void(* errorf) (const char *str) = internalerror
static

◆ infoelts

struct dundi_ie infoelts[]
static

Referenced by dump_ies(), and dundi_ie2str().

◆ outputf

void(* outputf) (const char *str) = internaloutput
static

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

Referenced by dump_ies(), dundi_parse_ies(), dundi_set_output(), and dundi_showframe().