#include "asterisk.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "asterisk/frame.h"
#include "asterisk/utils.h"
#include "asterisk/unaligned.h"
#include "asterisk/lock.h"
#include "asterisk/threadstorage.h"
#include "iax2.h"
#include "iax2-parser.h"
#include "iax2-provision.h"
Include dependency graph for iax2-parser.c:

Go to the source code of this file.
Data Structures | |
| struct | iax2_ie |
| struct | iax_frames |
Defines | |
| #define | FRAME_CACHE_MAX_SIZE 20 |
Functions | |
| AST_LIST_HEAD_NOLOCK (iax_frame_list, iax_frame) | |
| This is just so iax_frames, a list head struct for holding a list of iax_frame structures, is defined. | |
| AST_THREADSTORAGE_CUSTOM (frame_cache, frame_cache_init, frame_cache_cleanup) | |
| A per-thread cache of iax_frame structures. | |
| static void | dump_addr (char *output, int maxlen, void *value, int len) |
| static void | dump_byte (char *output, int maxlen, void *value, int len) |
| static void | dump_datetime (char *output, int maxlen, void *value, int len) |
| static void | dump_ies (unsigned char *iedata, int len) |
| static void | dump_int (char *output, int maxlen, void *value, int len) |
| static void | dump_ipaddr (char *output, int maxlen, void *value, int len) |
| static void | dump_prefs (char *output, int maxlen, void *value, int len) |
| static void | dump_prov (char *output, int maxlen, void *value, int len) |
| static void | dump_prov_flags (char *output, int maxlen, void *value, int len) |
| static void | dump_prov_ies (char *output, int maxlen, unsigned char *iedata, int len) |
| static void | dump_samprate (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) |
| static void | frame_cache_cleanup (void *data) |
| void | iax_frame_free (struct iax_frame *fr) |
| iax_frame * | iax_frame_new (int direction, int datalen, unsigned int cacheable) |
| void | iax_frame_wrap (struct iax_frame *fr, struct ast_frame *f) |
| int | iax_get_frames (void) |
| int | iax_get_iframes (void) |
| int | iax_get_oframes (void) |
| const char * | iax_ie2str (int ie) |
| int | iax_ie_append (struct iax_ie_data *ied, unsigned char ie) |
| int | iax_ie_append_addr (struct iax_ie_data *ied, unsigned char ie, const struct sockaddr_in *sin) |
| int | iax_ie_append_byte (struct iax_ie_data *ied, unsigned char ie, unsigned char dat) |
| int | iax_ie_append_int (struct iax_ie_data *ied, unsigned char ie, unsigned int value) |
| int | iax_ie_append_raw (struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen) |
| int | iax_ie_append_short (struct iax_ie_data *ied, unsigned char ie, unsigned short value) |
| int | iax_ie_append_str (struct iax_ie_data *ied, unsigned char ie, const char *str) |
| int | iax_parse_ies (struct iax_ies *ies, unsigned char *data, int datalen) |
| void | iax_set_error (void(*func)(const char *)) |
| void | iax_set_output (void(*func)(const char *)) |
| void | iax_showframe (struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen) |
| static void | internalerror (const char *str) |
| static void | internaloutput (const char *str) |
Variables | |
| static void(*) | errorf (const char *str) = internalerror |
| static int | frames = 0 |
| static struct iax2_ie | ies [] |
| static int | iframes = 0 |
| static int | oframes = 0 |
| static void(*) | outputf (const char *str) = internaloutput |
| static struct iax2_ie | prov_ies [] |
Definition in file iax2-parser.c.
| #define FRAME_CACHE_MAX_SIZE 20 |
Definition at line 68 of file iax2-parser.c.
| AST_LIST_HEAD_NOLOCK | ( | iax_frame_list | , | |
| iax_frame | ||||
| ) |
This is just so iax_frames, a list head struct for holding a list of iax_frame structures, is defined.
| AST_THREADSTORAGE_CUSTOM | ( | frame_cache | , | |
| frame_cache_init | , | |||
| frame_cache_cleanup | ||||
| ) |
A per-thread cache of iax_frame structures.
| static void dump_addr | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 84 of file iax2-parser.c.
References ast_inet_ntoa().
00085 { 00086 struct sockaddr_in sin; 00087 if (len == (int)sizeof(sin)) { 00088 memcpy(&sin, value, len); 00089 snprintf(output, maxlen, "IPV4 %s:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 00090 } else { 00091 snprintf(output, maxlen, "Invalid Address"); 00092 } 00093 }
| static void dump_byte | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 139 of file iax2-parser.c.
00140 { 00141 if (len == (int)sizeof(unsigned char)) 00142 snprintf(output, maxlen, "%d", *((unsigned char *)value)); 00143 else 00144 ast_copy_string(output, "Invalid BYTE", maxlen); 00145 }
| static void dump_datetime | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 147 of file iax2-parser.c.
References get_unaligned_uint32().
00148 { 00149 struct tm tm; 00150 unsigned long val = (unsigned long) ntohl(get_unaligned_uint32(value)); 00151 if (len == (int)sizeof(unsigned int)) { 00152 tm.tm_sec = (val & 0x1f) << 1; 00153 tm.tm_min = (val >> 5) & 0x3f; 00154 tm.tm_hour = (val >> 11) & 0x1f; 00155 tm.tm_mday = (val >> 16) & 0x1f; 00156 tm.tm_mon = ((val >> 21) & 0x0f) - 1; 00157 tm.tm_year = ((val >> 25) & 0x7f) + 100; 00158 strftime(output, maxlen, "%Y-%m-%d %T", &tm); 00159 } else 00160 ast_copy_string(output, "Invalid DATETIME format!", maxlen); 00161 }
| static void dump_ies | ( | unsigned char * | iedata, | |
| int | len | |||
| ) | [static] |
Definition at line 357 of file iax2-parser.c.
References iax2_ie::dump, iax2_ie::ie, ies, name, and outputf.
Referenced by dundi_showframe(), and iax_showframe().
00358 { 00359 int ielen; 00360 int ie; 00361 int x; 00362 int found; 00363 char interp[1024]; 00364 char tmp[1024]; 00365 if (len < 2) 00366 return; 00367 while(len > 2) { 00368 ie = iedata[0]; 00369 ielen = iedata[1]; 00370 if (ielen + 2> len) { 00371 snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len); 00372 outputf(tmp); 00373 return; 00374 } 00375 found = 0; 00376 for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) { 00377 if (ies[x].ie == ie) { 00378 if (ies[x].dump) { 00379 ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen); 00380 snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp); 00381 outputf(tmp); 00382 } else { 00383 if (ielen) 00384 snprintf(interp, (int)sizeof(interp), "%d bytes", ielen); 00385 else 00386 strcpy(interp, "Present"); 00387 snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp); 00388 outputf(tmp); 00389 } 00390 found++; 00391 } 00392 } 00393 if (!found) { 00394 snprintf(tmp, (int)sizeof(tmp), " Unknown IE %03d : Present\n", ie); 00395 outputf(tmp); 00396 } 00397 iedata += (2 + ielen); 00398 len -= (2 + ielen); 00399 } 00400 outputf("\n"); 00401 }
| static void dump_int | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 123 of file iax2-parser.c.
References get_unaligned_uint32().
00124 { 00125 if (len == (int)sizeof(unsigned int)) 00126 snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_unaligned_uint32(value))); 00127 else 00128 ast_copy_string(output, "Invalid INT", maxlen); 00129 }
| static void dump_ipaddr | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 163 of file iax2-parser.c.
References ast_inet_ntoa().
00164 { 00165 struct sockaddr_in sin; 00166 if (len == (int)sizeof(unsigned int)) { 00167 memcpy(&sin.sin_addr, value, len); 00168 snprintf(output, maxlen, "%s", ast_inet_ntoa(sin.sin_addr)); 00169 } else 00170 ast_copy_string(output, "Invalid IPADDR", maxlen); 00171 }
| static void dump_prefs | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 104 of file iax2-parser.c.
References ast_codec_pref_convert(), and ast_codec_pref_string().
00105 { 00106 struct ast_codec_pref pref; 00107 int total_len = 0; 00108 00109 maxlen--; 00110 total_len = maxlen; 00111 00112 if (maxlen > len) 00113 maxlen = len; 00114 00115 strncpy(output, value, maxlen); 00116 output[maxlen] = '\0'; 00117 00118 ast_codec_pref_convert(&pref, output, total_len, 0); 00119 memset(output,0,total_len); 00120 ast_codec_pref_string(&pref, output, total_len); 00121 }
| static void dump_prov | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 212 of file iax2-parser.c.
References dump_prov_ies().
00213 { 00214 dump_prov_ies(output, maxlen, value, len); 00215 }
| static void dump_prov_flags | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 174 of file iax2-parser.c.
References get_unaligned_uint32(), and iax_provflags2str().
00175 { 00176 char buf[256] = ""; 00177 if (len == (int)sizeof(unsigned int)) 00178 snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_unaligned_uint32(value)), 00179 iax_provflags2str(buf, sizeof(buf), ntohl(get_unaligned_uint32(value)))); 00180 else 00181 ast_copy_string(output, "Invalid INT", maxlen); 00182 }
| static void dump_prov_ies | ( | char * | output, | |
| int | maxlen, | |||
| unsigned char * | iedata, | |||
| int | len | |||
| ) | [static] |
Definition at line 305 of file iax2-parser.c.
References iax2_ie::dump, iax2_ie::ie, name, and prov_ies.
Referenced by dump_prov().
00306 { 00307 int ielen; 00308 int ie; 00309 int x; 00310 int found; 00311 char interp[80]; 00312 char tmp[256]; 00313 if (len < 2) 00314 return; 00315 strcpy(output, "\n"); 00316 maxlen -= strlen(output); output += strlen(output); 00317 while(len > 2) { 00318 ie = iedata[0]; 00319 ielen = iedata[1]; 00320 if (ielen + 2> len) { 00321 snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len); 00322 ast_copy_string(output, tmp, maxlen); 00323 maxlen -= strlen(output); 00324 output += strlen(output); 00325 return; 00326 } 00327 found = 0; 00328 for (x=0;x<(int)sizeof(prov_ies) / (int)sizeof(prov_ies[0]); x++) { 00329 if (prov_ies[x].ie == ie) { 00330 if (prov_ies[x].dump) { 00331 prov_ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen); 00332 snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", prov_ies[x].name, interp); 00333 ast_copy_string(output, tmp, maxlen); 00334 maxlen -= strlen(output); output += strlen(output); 00335 } else { 00336 if (ielen) 00337 snprintf(interp, (int)sizeof(interp), "%d bytes", ielen); 00338 else 00339 strcpy(interp, "Present"); 00340 snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", prov_ies[x].name, interp); 00341 ast_copy_string(output, tmp, maxlen); 00342 maxlen -= strlen(output); output += strlen(output); 00343 } 00344 found++; 00345 } 00346 } 00347 if (!found) { 00348 snprintf(tmp, (int)sizeof(tmp), " Unknown Prov IE %03d : Present\n", ie); 00349 ast_copy_string(output, tmp, maxlen); 00350 maxlen -= strlen(output); output += strlen(output); 00351 } 00352 iedata += (2 + ielen); 00353 len -= (2 + ielen); 00354 } 00355 }
| static void dump_samprate | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 184 of file iax2-parser.c.
References IAX_RATE_11KHZ, IAX_RATE_16KHZ, IAX_RATE_22KHZ, IAX_RATE_44KHZ, IAX_RATE_48KHZ, and IAX_RATE_8KHZ.
00185 { 00186 char tmp[256]=""; 00187 int sr; 00188 if (len == (int)sizeof(unsigned short)) { 00189 sr = ntohs(*((unsigned short *)value)); 00190 if (sr & IAX_RATE_8KHZ) 00191 strcat(tmp, ",8khz"); 00192 if (sr & IAX_RATE_11KHZ) 00193 strcat(tmp, ",11.025khz"); 00194 if (sr & IAX_RATE_16KHZ) 00195 strcat(tmp, ",16khz"); 00196 if (sr & IAX_RATE_22KHZ) 00197 strcat(tmp, ",22.05khz"); 00198 if (sr & IAX_RATE_44KHZ) 00199 strcat(tmp, ",44.1khz"); 00200 if (sr & IAX_RATE_48KHZ) 00201 strcat(tmp, ",48khz"); 00202 if (strlen(tmp)) 00203 ast_copy_string(output, &tmp[1], maxlen); 00204 else 00205 ast_copy_string(output, "None Specified!\n", maxlen); 00206 } else 00207 ast_copy_string(output, "Invalid SHORT", maxlen); 00208 00209 }
| static void dump_short | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 131 of file iax2-parser.c.
References get_unaligned_uint16().
00132 { 00133 if (len == (int)sizeof(unsigned short)) 00134 snprintf(output, maxlen, "%d", ntohs(get_unaligned_uint16(value))); 00135 else 00136 ast_copy_string(output, "Invalid SHORT", maxlen); 00137 }
| static void dump_string | ( | char * | output, | |
| int | maxlen, | |||
| void * | value, | |||
| int | len | |||
| ) | [static] |
Definition at line 95 of file iax2-parser.c.
00096 { 00097 maxlen--; 00098 if (maxlen > len) 00099 maxlen = len; 00100 strncpy(output, value, maxlen); 00101 output[maxlen] = '\0'; 00102 }
| static void frame_cache_cleanup | ( | void * | data | ) | [static] |
Definition at line 1039 of file iax2-parser.c.
References AST_LIST_REMOVE_HEAD, frames, and free.
01040 { 01041 struct iax_frames *frames = data; 01042 struct iax_frame *cur; 01043 01044 while ((cur = AST_LIST_REMOVE_HEAD(&frames->list, list))) 01045 free(cur); 01046 01047 free(frames); 01048 }
| void iax_frame_free | ( | struct iax_frame * | fr | ) |
Definition at line 1005 of file iax2-parser.c.
References AST_LIST_INSERT_HEAD, iax_frame::cacheable, iax_frame::direction, DIRECTION_INGRESS, DIRECTION_OUTGRESS, errorf, FRAME_CACHE_MAX_SIZE, free, and iax_frames::list.
Referenced by iax2_frame_free(), and network_thread().
01006 { 01007 #if !defined(LOW_MEMORY) 01008 struct iax_frames *iax_frames; 01009 #endif 01010 01011 /* Note: does not remove from scheduler! */ 01012 if (fr->direction == DIRECTION_INGRESS) 01013 ast_atomic_fetchadd_int(&iframes, -1); 01014 else if (fr->direction == DIRECTION_OUTGRESS) 01015 ast_atomic_fetchadd_int(&oframes, -1); 01016 else { 01017 errorf("Attempt to double free frame detected\n"); 01018 return; 01019 } 01020 ast_atomic_fetchadd_int(&frames, -1); 01021 01022 #if !defined(LOW_MEMORY) 01023 if (!fr->cacheable || !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) { 01024 free(fr); 01025 return; 01026 } 01027 01028 if (iax_frames->size < FRAME_CACHE_MAX_SIZE) { 01029 fr->direction = 0; 01030 AST_LIST_INSERT_HEAD(&iax_frames->list, fr, list); 01031 iax_frames->size++; 01032 return; 01033 } 01034 #endif 01035 free(fr); 01036 }
| struct iax_frame* iax_frame_new | ( | int | direction, | |
| int | datalen, | |||
| unsigned int | cacheable | |||
| ) |
Definition at line 958 of file iax2-parser.c.
References iax_frame::afdatalen, ast_calloc, ast_calloc_cache, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, DIRECTION_INGRESS, and iax_frames::list.
Referenced by iax2_send(), and iaxfrdup2().
00959 { 00960 struct iax_frame *fr = NULL; 00961 00962 #if !defined(LOW_MEMORY) 00963 struct iax_frames *iax_frames; 00964 00965 /* Attempt to get a frame from this thread's cache */ 00966 if ((iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) { 00967 AST_LIST_TRAVERSE_SAFE_BEGIN(&iax_frames->list, fr, list) { 00968 if (fr->afdatalen >= datalen) { 00969 size_t afdatalen = fr->afdatalen; 00970 AST_LIST_REMOVE_CURRENT(&iax_frames->list, list); 00971 iax_frames->size--; 00972 memset(fr, 0, sizeof(*fr)); 00973 fr->afdatalen = afdatalen; 00974 break; 00975 } 00976 } 00977 AST_LIST_TRAVERSE_SAFE_END 00978 } 00979 if (!fr) { 00980 if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen))) 00981 return NULL; 00982 fr->afdatalen = datalen; 00983 } 00984 #else 00985 if (!(fr = ast_calloc(1, sizeof(*fr) + datalen))) 00986 return NULL; 00987 fr->afdatalen = datalen; 00988 #endif 00989 00990 00991 fr->direction = direction; 00992 fr->retrans = -1; 00993 fr->cacheable = cacheable; 00994 00995 if (fr->direction == DIRECTION_INGRESS) 00996 ast_atomic_fetchadd_int(&iframes, 1); 00997 else 00998 ast_atomic_fetchadd_int(&oframes, 1); 00999 01000 ast_atomic_fetchadd_int(&frames, 1); 01001 01002 return fr; 01003 }
Definition at line 927 of file iax2-parser.c.
References iax_frame::af, iax_frame::afdata, iax_frame::afdatalen, AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_swapcopy_samples(), ast_frame::data, ast_frame::datalen, ast_frame::delivery, f, ast_frame::frametype, ast_frame::len, LOG_ERROR, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, ast_frame::src, and ast_frame::subclass.
Referenced by iax2_send(), iaxfrdup2(), and socket_process().
00928 { 00929 fr->af.frametype = f->frametype; 00930 fr->af.subclass = f->subclass; 00931 fr->af.mallocd = 0; /* Our frame is static relative to the container */ 00932 fr->af.datalen = f->datalen; 00933 fr->af.samples = f->samples; 00934 fr->af.offset = AST_FRIENDLY_OFFSET; 00935 fr->af.src = f->src; 00936 fr->af.delivery.tv_sec = 0; 00937 fr->af.delivery.tv_usec = 0; 00938 fr->af.data = fr->afdata; 00939 fr->af.len = f->len; 00940 if (fr->af.datalen) { 00941 size_t copy_len = fr->af.datalen; 00942 if (copy_len > fr->afdatalen) { 00943 ast_log(LOG_ERROR, "Losing frame data because destination buffer size '%d' bytes not big enough for '%d' bytes in the frame\n", 00944 (int) fr->afdatalen, (int) fr->af.datalen); 00945 copy_len = fr->afdatalen; 00946 } 00947 #if __BYTE_ORDER == __LITTLE_ENDIAN 00948 /* We need to byte-swap slinear samples from network byte order */ 00949 if ((fr->af.frametype == AST_FRAME_VOICE) && (fr->af.subclass == AST_FORMAT_SLINEAR)) { 00950 /* 2 bytes / sample for SLINEAR */ 00951 ast_swapcopy_samples(fr->af.data, f->data, copy_len / 2); 00952 } else 00953 #endif 00954 memcpy(fr->af.data, f->data, copy_len); 00955 } 00956 }
| int iax_get_frames | ( | void | ) |
Definition at line 1051 of file iax2-parser.c.
Referenced by iax2_show_stats().
01051 { return frames; }
| int iax_get_iframes | ( | void | ) |
Definition at line 1052 of file iax2-parser.c.
Referenced by iax2_show_stats().
01052 { return iframes; }
| int iax_get_oframes | ( | void | ) |
Definition at line 1053 of file iax2-parser.c.
Referenced by iax2_show_stats().
01053 { return oframes; }
| const char* iax_ie2str | ( | int | ie | ) |
Definition at line 294 of file iax2-parser.c.
Referenced by iax_ie_append_raw(), and iax_parse_ies().
00295 { 00296 int x; 00297 for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) { 00298 if (ies[x].ie == ie) 00299 return ies[x].name; 00300 } 00301 return "Unknown IE"; 00302 }
| int iax_ie_append | ( | struct iax_ie_data * | ied, | |
| unsigned char | ie | |||
| ) |
Definition at line 604 of file iax2-parser.c.
References iax_ie_append_raw().
Referenced by iax2_call(), and iax_firmware_append().
00605 { 00606 return iax_ie_append_raw(ied, ie, NULL, 0); 00607 }
| int iax_ie_append_addr | ( | struct iax_ie_data * | ied, | |
| unsigned char | ie, | |||
| const struct sockaddr_in * | sin | |||
| ) |
Definition at line 575 of file iax2-parser.c.
References iax_ie_append_raw().
Referenced by iax2_start_transfer(), and update_registry().
00576 { 00577 return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in)); 00578 }
| int iax_ie_append_byte | ( | struct iax_ie_data * | ied, | |
| unsigned char | ie, | |||
| unsigned char | dat | |||
| ) |
Definition at line 599 of file iax2-parser.c.
References iax_ie_append_raw().
Referenced by __auth_reject(), __auto_hangup(), authenticate_request(), iax2_call(), iax2_hangup(), iax_provision_build(), and socket_process().
00600 { 00601 return iax_ie_append_raw(ied, ie, &dat, 1); 00602 }
| int iax_ie_append_int | ( | struct iax_ie_data * | ied, | |
| unsigned char | ie, | |||
| unsigned int | value | |||
| ) |
Definition at line 580 of file iax2-parser.c.
References iax_ie_append_raw().
Referenced by cache_get_callno_locked(), construct_rr(), iax2_call(), iax2_start_transfer(), iax_firmware_append(), iax_provision_build(), socket_process(), try_transfer(), and update_registry().
00581 { 00582 unsigned int newval; 00583 newval = htonl(value); 00584 return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval)); 00585 }
| int iax_ie_append_raw | ( | struct iax_ie_data * | ied, | |
| unsigned char | ie, | |||
| const void * | data, | |||
| int | datalen | |||
| ) |
Definition at line 560 of file iax2-parser.c.
References iax_ie_data::buf, errorf, iax_ie2str(), and iax_ie_data::pos.
Referenced by iax2_provision(), iax_firmware_append(), iax_ie_append(), iax_ie_append_addr(), iax_ie_append_byte(), iax_ie_append_int(), iax_ie_append_short(), and iax_ie_append_str().
00561 { 00562 char tmp[256]; 00563 if (datalen > ((int)sizeof(ied->buf) - ied->pos)) { 00564 snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos); 00565 errorf(tmp); 00566 return -1; 00567 } 00568 ied->buf[ied->pos++] = ie; 00569 ied->buf[ied->pos++] = datalen; 00570 memcpy(ied->buf + ied->pos, data, datalen); 00571 ied->pos += datalen; 00572 return 0; 00573 }
| int iax_ie_append_short | ( | struct iax_ie_data * | ied, | |
| unsigned char | ie, | |||
| unsigned short | value | |||
| ) |
Definition at line 587 of file iax2-parser.c.
References iax_ie_append_raw().
Referenced by authenticate_request(), cache_get_callno_locked(), construct_rr(), dp_lookup(), iax2_call(), iax2_do_register(), iax2_start_transfer(), iax_provision_build(), registry_authrequest(), registry_rerequest(), socket_process(), and update_registry().
00588 { 00589 unsigned short newval; 00590 newval = htons(value); 00591 return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval)); 00592 }
| int iax_ie_append_str | ( | struct iax_ie_data * | ied, | |
| unsigned char | ie, | |||
| const char * | str | |||
| ) |
Definition at line 594 of file iax2-parser.c.
References iax_ie_append_raw().
Referenced by __auth_reject(), __auto_hangup(), authenticate(), authenticate_request(), cache_get_callno_locked(), dp_lookup(), iax2_call(), iax2_do_register(), iax2_dprequest(), iax2_transfer(), iax_provision_build(), registry_authrequest(), registry_rerequest(), socket_process(), and update_registry().
00595 { 00596 return iax_ie_append_raw(ied, ie, str, strlen(str)); 00597 }
| int iax_parse_ies | ( | struct iax_ies * | ies, | |
| unsigned char * | data, | |||
| int | datalen | |||
| ) |
Definition at line 619 of file iax2-parser.c.
References errorf, get_unaligned_uint16(), get_unaligned_uint32(), iax_ie2str(), IAX_IE_ADSICPE, IAX_IE_APPARENT_ADDR, IAX_IE_AUTHMETHODS, IAX_IE_AUTOANSWER, IAX_IE_CALLED_CONTEXT, IAX_IE_CALLED_NUMBER, IAX_IE_CALLING_ANI, IAX_IE_CALLING_NAME, IAX_IE_CALLING_NUMBER, IAX_IE_CALLINGPRES, IAX_IE_CALLINGTNS, IAX_IE_CALLINGTON, IAX_IE_CALLNO, IAX_IE_CAPABILITY, IAX_IE_CAUSE, IAX_IE_CAUSECODE, IAX_IE_CHALLENGE, IAX_IE_CODEC_PREFS, IAX_IE_DATETIME, IAX_IE_DEVICETYPE, IAX_IE_DNID, IAX_IE_DPSTATUS, IAX_IE_ENCKEY, IAX_IE_ENCRYPTION, IAX_IE_FIRMWAREVER, IAX_IE_FORMAT, IAX_IE_FWBLOCKDATA, IAX_IE_FWBLOCKDESC, IAX_IE_IAX_UNKNOWN, IAX_IE_LANGUAGE, IAX_IE_MD5_RESULT, IAX_IE_MSGCOUNT, IAX_IE_MUSICONHOLD, IAX_IE_PASSWORD, IAX_IE_PROVVER, IAX_IE_RDNIS, IAX_IE_REFRESH, IAX_IE_RR_DELAY, IAX_IE_RR_DROPPED, IAX_IE_RR_JITTER, IAX_IE_RR_LOSS, IAX_IE_RR_OOO, IAX_IE_RR_PKTS, IAX_IE_RSA_RESULT, IAX_IE_SAMPLINGRATE, IAX_IE_SERVICEIDENT, IAX_IE_TRANSFERID, IAX_IE_USERNAME, IAX_IE_VERSION, IAX_RATE_8KHZ, ies, len, and outputf.
Referenced by socket_process().
00620 { 00621 /* Parse data into information elements */ 00622 int len; 00623 int ie; 00624 char tmp[256]; 00625 memset(ies, 0, (int)sizeof(struct iax_ies)); 00626 ies->msgcount = -1; 00627 ies->firmwarever = -1; 00628 ies->calling_ton = -1; 00629 ies->calling_tns = -1; 00630 ies->calling_pres = -1; 00631 ies->samprate = IAX_RATE_8KHZ; 00632 while(datalen >= 2) { 00633 ie = data[0]; 00634 len = data[1]; 00635 if (len > datalen - 2) { 00636 errorf("Information element length exceeds message size\n"); 00637 return -1; 00638 } 00639 switch(ie) { 00640 case IAX_IE_CALLED_NUMBER: 00641 ies->called_number = (char *)data + 2; 00642 break; 00643 case IAX_IE_CALLING_NUMBER: 00644 ies->calling_number = (char *)data + 2; 00645 break; 00646 case IAX_IE_CALLING_ANI: 00647 ies->calling_ani = (char *)data + 2; 00648 break; 00649 case IAX_IE_CALLING_NAME: 00650 ies->calling_name = (char *)data + 2; 00651 break; 00652 case IAX_IE_CALLED_CONTEXT: 00653 ies->called_context = (char *)data + 2; 00654 break; 00655 case IAX_IE_USERNAME: 00656 ies->username = (char *)data + 2; 00657 break; 00658 case IAX_IE_PASSWORD: 00659 ies->password = (char *)data + 2; 00660 break; 00661 case IAX_IE_CODEC_PREFS: 00662 ies->codec_prefs = (char *)data + 2; 00663 break; 00664 case IAX_IE_CAPABILITY: 00665 if (len != (int)sizeof(unsigned int)) { 00666 snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); 00667 errorf(tmp); 00668 } else 00669 ies->capability = ntohl(get_unaligned_uint32(data + 2)); 00670 break; 00671 case IAX_IE_FORMAT: 00672 if (len != (int)sizeof(unsigned int)) { 00673 snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len); 00674 errorf(tmp); 00675 } else 00676 ies->format = ntohl(get_unaligned_uint32(data + 2)); 00677 break; 00678 case IAX_IE_LANGUAGE: 00679 ies->language = (char *)data + 2; 00680 break; 00681 case IAX_IE_VERSION: 00682 if (len != (int)sizeof(unsigned short)) { 00683 snprintf(tmp, (int)sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); 00684 errorf(tmp); 00685 } else 00686 ies->version = ntohs(get_unaligned_uint16(data + 2)); 00687 break; 00688 case IAX_IE_ADSICPE: 00689 if (len != (int)sizeof(unsigned short)) { 00690 snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); 00691 errorf(tmp); 00692 } else 00693 ies->adsicpe = ntohs(get_unaligned_uint16(data + 2)); 00694 break; 00695 case IAX_IE_SAMPLINGRATE: 00696 if (len != (int)sizeof(unsigned short)) { 00697 snprintf(tmp, (int)sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int)sizeof(unsigned short), l