Kannel: Open Source WAP and SMS gateway  svn-r5335
octstr.c File Reference
#include <ctype.h>
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "gwlib.h"
#include "gwlib/html-entities.def"

Go to the source code of this file.

Data Structures

struct  Octstr
 
struct  format
 

Macros

#define VARGS(x)   (&x)
 
#define VALPARM(y)   va_list *y
 
#define VALST(z)   (*z)
 
#define MAX_IMMUTABLES   1024
 
#define CSTR_TO_LONG(ptr)   (((unsigned long) ptr) >> 2)
 
#define H2B(a)
 
#define seems_valid(ostr)   (seems_valid_real(ostr, __FILE__, __LINE__, __func__))
 
#define LLinfo   info
 
#define LLwarning   warning
 
#define LLerror   error
 
#define octstr_dump_LOGLEVEL(loglevel, ostr, level)
 
#define ENTITY(a, b)
 
#define ENTITY(a, b)   { a, b },
 

Functions

static void seems_valid_real (const Octstr *ostr, const char *filename, long lineno, const char *function)
 
static void octstr_grow (Octstr *ostr, long size)
 
static void urlcode_init (void)
 
void octstr_init (void)
 
void octstr_shutdown (void)
 
Octstroctstr_create_real (const char *cstr, const char *file, long line, const char *func)
 
Octstroctstr_create_from_data_real (const char *data, long len, const char *file, long line, const char *func)
 
Octstroctstr_imm (const char *cstr)
 
void octstr_destroy (Octstr *ostr)
 
void octstr_destroy_item (void *os)
 
long octstr_len (const Octstr *ostr)
 
Octstroctstr_copy_real (const Octstr *ostr, long from, long len, const char *file, long line, const char *func)
 
Octstroctstr_duplicate_real (const Octstr *ostr, const char *file, long line, const char *func)
 
Octstroctstr_cat (Octstr *ostr1, Octstr *ostr2)
 
int octstr_get_char (const Octstr *ostr, long pos)
 
void octstr_set_char (Octstr *ostr, long pos, int ch)
 
void octstr_get_many_chars (char *buf, Octstr *ostr, long pos, long len)
 
char * octstr_get_cstr_real (const Octstr *ostr, const char *file, long line, const char *func)
 
void octstr_append_from_hex (Octstr *ostr, char *hex)
 
void octstr_binary_to_hex (Octstr *ostr, int uppercase)
 
int octstr_hex_to_binary (Octstr *ostr)
 
void octstr_binary_to_base64 (Octstr *ostr)
 
void octstr_base64_to_binary (Octstr *ostr)
 
long octstr_parse_long (long *nump, Octstr *ostr, long pos, int base)
 
long octstr_parse_double (double *nump, Octstr *ostr, long pos)
 
int octstr_check_range (Octstr *ostr, long pos, long len, octstr_func_t filter)
 
void octstr_convert_range (Octstr *ostr, long pos, long len, octstr_func_t map)
 
static int make_printable (int c)
 
void octstr_convert_printable (Octstr *ostr)
 
int octstr_compare (const Octstr *ostr1, const Octstr *ostr2)
 
int octstr_case_compare (const Octstr *os1, const Octstr *os2)
 
int octstr_ncompare (const Octstr *ostr1, const Octstr *ostr2, long n)
 
int octstr_str_compare (const Octstr *ostr, const char *str)
 
int octstr_str_case_compare (const Octstr *ostr, const char *str)
 
int octstr_str_ncompare (const Octstr *ostr, const char *str, long n)
 
long octstr_search_char (const Octstr *ostr, int ch, long pos)
 
long octstr_rsearch_char (const Octstr *ostr, int ch, long pos)
 
long octstr_search_chars (const Octstr *ostr, const Octstr *chars, long pos)
 
long octstr_search (const Octstr *haystack, const Octstr *needle, long pos)
 
long octstr_case_search (const Octstr *haystack, const Octstr *needle, long pos)
 
long octstr_case_nsearch (const Octstr *haystack, const Octstr *needle, long pos, long n)
 
long octstr_str_search (const Octstr *haystack, const char *needle, long pos)
 
int octstr_print (FILE *f, Octstr *ostr)
 
int octstr_pretty_print (FILE *f, Octstr *ostr)
 
int octstr_write_to_socket (int socket, Octstr *ostr)
 
long octstr_write_data (Octstr *ostr, int fd, long from)
 
int octstr_append_from_socket (Octstr *ostr, int socket)
 
void octstr_insert (Octstr *ostr1, const Octstr *ostr2, long pos)
 
void octstr_truncate (Octstr *ostr, int new_len)
 
void octstr_strip_blanks (Octstr *text)
 
static int iscrlf (unsigned char c)
 
void octstr_strip_crlfs (Octstr *text)
 
void octstr_strip_nonalphanums (Octstr *text)
 
void octstr_shrink_blanks (Octstr *text)
 
void octstr_insert_data (Octstr *ostr, long pos, const char *data, long len)
 
void octstr_insert_char (Octstr *ostr, long pos, const char c)
 
void octstr_append_data (Octstr *ostr, const char *data, long len)
 
void octstr_append (Octstr *ostr1, const Octstr *ostr2)
 
void octstr_append_cstr (Octstr *ostr, const char *cstr)
 
void octstr_append_char (Octstr *ostr, int ch)
 
void octstr_delete (Octstr *ostr1, long pos, long len)
 
Octstroctstr_read_file (const char *filename)
 
Octstroctstr_read_pipe (FILE *f)
 
Listoctstr_split_words (const Octstr *ostr)
 
Listoctstr_split (const Octstr *os, const Octstr *sep)
 
int octstr_item_match (void *item, void *pattern)
 
int octstr_item_case_match (void *item, void *pattern)
 
void octstr_url_encode (Octstr *ostr)
 
int octstr_url_decode (Octstr *ostr)
 
long octstr_get_bits (Octstr *ostr, long bitpos, int numbits)
 
void octstr_set_bits (Octstr *ostr, long bitpos, int numbits, unsigned long value)
 
void octstr_append_uintvar (Octstr *ostr, unsigned long value)
 
long octstr_extract_uintvar (Octstr *ostr, unsigned long *value, long pos)
 
void octstr_append_decimal (Octstr *ostr, long value)
 
static void octstr_dump_debug (const Octstr *ostr, int level)
 
void octstr_dump_real (const Octstr *ostr, int level,...)
 
void octstr_dump_short (Octstr *ostr, int level, const char *name)
 
static void format_flags (struct format *format, const char **fmt)
 
static void format_width (struct format *format, const char **fmt, VALPARM(args))
 
static void format_prec (struct format *format, const char **fmt, VALPARM(args))
 
static void format_type (struct format *format, const char **fmt)
 
static void convert (Octstr *os, struct format *format, const char **fmt, VALPARM(args))
 
Octstroctstr_format (const char *fmt,...)
 
Octstroctstr_format_valist_real (const char *fmt, va_list args)
 
void octstr_format_append (Octstr *os, const char *fmt,...)
 
unsigned long octstr_hash_key (Octstr *ostr)
 
int octstr_recode (Octstr *tocode, Octstr *fromcode, Octstr *orig)
 
void octstr_strip_char (Octstr *text, char ch)
 
int octstr_isnum (Octstr *ostr1)
 
void octstr_replace (Octstr *haystack, Octstr *needle, Octstr *repl)
 
void octstr_replace_first (Octstr *haystack, Octstr *needle, Octstr *repl)
 
int octstr_symbolize (Octstr *ostr)
 
void octstr_delete_matching (Octstr *haystack, Octstr *needle)
 
int octstr_is_all_hex (Octstr *os)
 
void octstr_convert_to_html_entities (Octstr *input)
 
static int octstr_find_entity (Octstr *input, int startfind, int endfind)
 
void octstr_convert_from_html_entities (Octstr *input)
 

Variables

static Octstrimmutables [MAX_IMMUTABLES]
 
static Mutex immutables_mutex
 
static int immutables_init = 0
 
static char is_safe [UCHAR_MAX+1]
 

Macro Definition Documentation

◆ CSTR_TO_LONG

#define CSTR_TO_LONG (   ptr)    (((unsigned long) ptr) >> 2)

Definition at line 145 of file octstr.c.

Referenced by octstr_imm().

◆ ENTITY [1/2]

#define ENTITY (   a,
 
)
Value:
case a: \
octstr_delete(input, i, 1); \
octstr_insert(input, octstr_imm("&" b ";"), i); \
i += sizeof(b); break;
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283

◆ ENTITY [2/2]

#define ENTITY (   a,
 
)    { a, b },

◆ H2B

#define H2B (   a)
Value:
(a >= '0' && a <= '9' ? \
a - '0' : (a >= 'a' && a <= 'f' ? \
a - 'a' + 10 : (a >= 'A' && a <= 'F' ? a - 'A' + 10 : -1) \
) \
)

Definition at line 151 of file octstr.c.

Referenced by octstr_url_decode().

◆ LLerror

#define LLerror   error

Definition at line 2057 of file octstr.c.

◆ LLinfo

#define LLinfo   info

Definition at line 2055 of file octstr.c.

◆ LLwarning

#define LLwarning   warning

Definition at line 2056 of file octstr.c.

◆ MAX_IMMUTABLES

#define MAX_IMMUTABLES   1024

Definition at line 131 of file octstr.c.

Referenced by octstr_imm(), and octstr_shutdown().

◆ octstr_dump_LOGLEVEL

#define octstr_dump_LOGLEVEL (   loglevel,
  ostr,
  level 
)

Definition at line 2059 of file octstr.c.

Referenced by octstr_dump_real().

◆ seems_valid

◆ VALPARM

#define VALPARM (   y)    va_list *y

Definition at line 90 of file octstr.c.

◆ VALST

#define VALST (   z)    (*z)

Definition at line 91 of file octstr.c.

Referenced by convert(), format_prec(), and format_width().

◆ VARGS

#define VARGS (   x)    (&x)

Definition at line 89 of file octstr.c.

Referenced by octstr_format_valist_real().

Function Documentation

◆ convert()

static void convert ( Octstr os,
struct format format,
const char **  fmt,
VALPARM(args)   
)
static

Definition at line 2300 of file octstr.c.

References format::has_prec, format::min_width, format::minus, octstr_append(), octstr_append_data(), octstr_append_decimal(), octstr_binary_to_hex(), octstr_create, octstr_create_from_data, octstr_destroy(), octstr_duplicate, octstr_insert_data(), octstr_len(), octstr_truncate(), octstr_url_encode(), panic, format::prec, format::type, VALST, and format::zero.

Referenced by octstr_format_valist_real().

2302 {
2303  Octstr *new;
2304  char *s, *pad;
2305  long long n;
2306  unsigned long long u;
2307  char tmpfmt[1024];
2308  char tmpbuf[1024];
2309  char c;
2310  void *p;
2311 
2312  new = NULL;
2313 
2314  switch (**fmt)
2315  {
2316  case 'c':
2317  c = va_arg(VALST(args), int);
2318  new = octstr_create_from_data(&c, 1);
2319  break;
2320 
2321  case 'd':
2322  case 'i':
2323  switch (format->type) {
2324  case 'L':
2325  n = va_arg(VALST(args), long long);
2326  break;
2327  case 'l':
2328  n = va_arg(VALST(args), long);
2329  break;
2330  case 'h':
2331  n = (short) va_arg(VALST(args), int);
2332  break;
2333  default:
2334  n = va_arg(VALST(args), int);
2335  break;
2336  }
2337  new = octstr_create("");
2338  octstr_append_decimal(new, n);
2339  break;
2340 
2341  case 'o':
2342  case 'u':
2343  case 'x':
2344  case 'X':
2345  switch (format->type) {
2346  case 'l':
2347  u = va_arg(VALST(args), unsigned long);
2348  break;
2349  case 'L':
2350  u = va_arg(VALST(args), unsigned long long);
2351  break;
2352  case 'h':
2353  u = (unsigned short) va_arg(VALST(args), unsigned int);
2354  break;
2355  default:
2356  u = va_arg(VALST(args), unsigned int);
2357  break;
2358  }
2359  tmpfmt[0] = '%';
2360  tmpfmt[1] = 'l';
2361  tmpfmt[2] = **fmt;
2362  tmpfmt[3] = '\0';
2363  sprintf(tmpbuf, tmpfmt, u);
2364  new = octstr_create(tmpbuf);
2365  break;
2366 
2367  case 'e':
2368  case 'f':
2369  case 'g':
2370  sprintf(tmpfmt, "%%");
2371  if (format->minus)
2372  strcat(tmpfmt, "-");
2373  if (format->zero)
2374  strcat(tmpfmt, "0");
2375  if (format->min_width > 0)
2376  sprintf(strchr(tmpfmt, '\0'),
2377  "%ld", format->min_width);
2378  if (format->has_prec)
2379  sprintf(strchr(tmpfmt, '\0'),
2380  ".%ld", format->prec);
2381  if (format->type != '\0')
2382  sprintf(strchr(tmpfmt, '\0'),
2383  "%c", (int) format->type);
2384  sprintf(strchr(tmpfmt, '\0'), "%c", **fmt);
2385  snprintf(tmpbuf, sizeof(tmpbuf),
2386  tmpfmt, va_arg(VALST(args), double));
2387  new = octstr_create(tmpbuf);
2388  break;
2389 
2390  case 's':
2391  s = va_arg(VALST(args), char *);
2392  if (format->has_prec && format->prec < (long) strlen(s))
2393  n = format->prec;
2394  else
2395  n = (long) strlen(s);
2396  new = octstr_create_from_data(s, n);
2397  break;
2398 
2399  case 'p':
2400  p = va_arg(VALST(args), void *);
2401  sprintf(tmpfmt, "%p", p);
2402  new = octstr_create(tmpfmt);
2403  break;
2404 
2405  case 'S':
2406  new = octstr_duplicate(va_arg(VALST(args), Octstr *));
2407  if (!new)
2408  new = octstr_create("(null)");
2409  if (format->has_prec)
2410  octstr_truncate(new, format->prec);
2411  break;
2412 
2413  case 'E':
2414  new = octstr_duplicate(va_arg(VALST(args), Octstr *));
2415  if (!new)
2416  new = octstr_create("(null)");
2417  octstr_url_encode(new);
2418  /*
2419  * note: we use blind truncate - encoded character can get cut half-way.
2420  */
2421  if (format->has_prec)
2422  octstr_truncate(new, format->prec);
2423  break;
2424 
2425  case 'H':
2426  new = octstr_duplicate(va_arg(VALST(args), Octstr *));
2427  if (!new)
2428  new = octstr_create("(null)");
2429  /* upper case */
2430  octstr_binary_to_hex(new, 1);
2431  if (format->has_prec)
2432  octstr_truncate(new, (format->prec % 2 ? format->prec - 1 : format->prec));
2433  break;
2434 
2435  case '%':
2436  new = octstr_create("%");
2437  break;
2438 
2439  default:
2440  panic(0, "octstr_format format string syntax error.");
2441  }
2442 
2443  if (format->zero)
2444  pad = "0";
2445  else
2446  pad = " ";
2447 
2448  if (format->minus) {
2449  while (format->min_width > octstr_len(new))
2450  octstr_append_data(new, pad, 1);
2451  } else {
2452  while (format->min_width > octstr_len(new))
2453  octstr_insert_data(new, 0, pad, 1);
2454  }
2455 
2456  octstr_append(os, new);
2457  octstr_destroy(new);
2458 
2459  if (**fmt != '\0')
2460  ++(*fmt);
2461 }
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1497
int has_prec
Definition: octstr.c:2208
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:465
long type
Definition: octstr.c:2211
long min_width
Definition: octstr.c:2206
int zero
Definition: octstr.c:2204
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
void octstr_append_decimal(Octstr *ostr, long value)
Definition: octstr.c:1976
Definition: octstr.c:118
#define panic
Definition: log.h:87
#define VALST(z)
Definition: octstr.c:91
void octstr_truncate(Octstr *ostr, int new_len)
Definition: octstr.c:1327
int minus
Definition: octstr.c:2203
long prec
Definition: octstr.c:2209
#define octstr_create_from_data(data, len)
Definition: octstr.h:134
void octstr_url_encode(Octstr *ostr)
Definition: octstr.c:1673

◆ format_flags()

static void format_flags ( struct format format,
const char **  fmt 
)
static

Definition at line 2215 of file octstr.c.

References format::minus, and format::zero.

Referenced by octstr_format_valist_real().

2216 {
2217  int done;
2218 
2219  done = 0;
2220  do
2221  {
2222  switch (**fmt) {
2223  case '-':
2224  format->minus = 1;
2225  break;
2226 
2227  case '0':
2228  format->zero = 1;
2229  break;
2230 
2231  default:
2232  done = 1;
2233  }
2234 
2235  if (!done)
2236  ++(*fmt);
2237  } while (!done);
2238 }
int zero
Definition: octstr.c:2204
int minus
Definition: octstr.c:2203

◆ format_prec()

static void format_prec ( struct format format,
const char **  fmt,
VALPARM(args)   
)
static

Definition at line 2259 of file octstr.c.

References format::has_prec, format::prec, and VALST.

Referenced by octstr_format_valist_real().

2261 {
2262  char *end;
2263 
2264  if (**fmt != '.')
2265  return;
2266  ++(*fmt);
2267  if (**fmt == '*')
2268  {
2269  format->has_prec = 1;
2270  format->prec = va_arg(VALST(args), int);
2271  ++(*fmt);
2272  } else if (isdigit(**(const unsigned char **) fmt))
2273  {
2274  format->has_prec = 1;
2275  format->prec = strtol(*fmt, &end, 10);
2276  *fmt = end;
2277  /* XXX error checking is missing from here */
2278  }
2279 }
int has_prec
Definition: octstr.c:2208
#define VALST(z)
Definition: octstr.c:91
long prec
Definition: octstr.c:2209

◆ format_type()

static void format_type ( struct format format,
const char **  fmt 
)
static

Definition at line 2282 of file octstr.c.

References format::type.

Referenced by octstr_format_valist_real().

2283 {
2284  switch (**fmt) {
2285  case 'h':
2286  format->type = **fmt;
2287  ++(*fmt);
2288  break;
2289  case 'l':
2290  if (*(*fmt + 1) == 'l'){
2291  format->type = 'L';
2292  ++(*fmt);
2293  } else format->type = **fmt;
2294  ++(*fmt);
2295  break;
2296  }
2297 }
long type
Definition: octstr.c:2211

◆ format_width()

static void format_width ( struct format format,
const char **  fmt,
VALPARM(args)   
)
static

Definition at line 2241 of file octstr.c.

References format::min_width, and VALST.

Referenced by octstr_format_valist_real().

2243 {
2244  char *end;
2245 
2246  if (**fmt == '*')
2247  {
2248  format->min_width = va_arg(VALST(args), int);
2249  ++(*fmt);
2250  } else if (isdigit(**(const unsigned char **) fmt))
2251  {
2252  format->min_width = strtol(*fmt, &end, 10);
2253  *fmt = end;
2254  /* XXX error checking is missing from here */
2255  }
2256 }
long min_width
Definition: octstr.c:2206
#define VALST(z)
Definition: octstr.c:91

◆ iscrlf()

static int iscrlf ( unsigned char  c)
static

Definition at line 1373 of file octstr.c.

Referenced by octstr_strip_crlfs().

1374 {
1375  return c == '\n' || c == '\r';
1376 }

◆ make_printable()

static int make_printable ( int  c)
inlinestatic

Definition at line 858 of file octstr.c.

Referenced by octstr_convert_printable().

859 {
860  return isprint(c) ? c : '.';
861 }

◆ octstr_append()

void octstr_append ( Octstr ostr1,
const Octstr ostr2 
)

Definition at line 1504 of file octstr.c.

References gw_assert(), Octstr::len, and octstr_insert().

Referenced by add_part_header(), add_wsp_get(), append_crlf(), assembly_sar_event(), at2_init_device(), at2_pdu_encode(), at2_pdu_extract(), at2_wait_modem_command(), build_request(), build_response(), catenate_msg(), cfg_get_group_checksum(), cgw_handle_op(), cgwop_tostr(), challenge(), charset_gsm_to_utf8(), charset_utf8_to_gsm(), concat_handling_check_and_handle(), concat_msgids(), conn_write(), conn_write_withlen(), convert(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), emi2_handle_smscreq(), emimsg_tostring(), encode_binary_data(), expand_file(), get_pattern(), get_x_kannel_from_xml(), http_header_pack(), http_header_split_auth_value(), http_send_reply(), httpd_serve(), main(), make_close_delimiter(), make_multipart_value(), make_part_delimiter(), make_start_delimiter(), make_url(), mime_decompile(), mime_entity_to_octstr(), mime_something_to_entity(), msg_to_cgwop(), msg_to_emimsg(), obey_request(), octstr_append_from_hex(), octstr_format_append(), octstr_recode(), oisd_send_delivery_request(), oisd_shrink_gsm7(), ota_pack_push_headers(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_7bit(), pack_cache_control(), pack_md5(), pack_quoted_string(), pack_server_address(), pack_tpis(), packet_encode_message(), parse2trans(), pass_field_name(), pass_field_value(), proxy_unpack_credentials(), push_content_create(), radius_authenticate_pdu(), radius_type_convert(), read_body_until_eof(), read_chunked_body_data(), read_mime_headers(), read_some_headers(), recover_absolute_uri(), send_message(), set_cookies(), sms_split(), sms_to_client(), smsc2_status(), smsc_emi2_create(), soap_format_xml(), soap_msgdata_attribute(), soap_o2o_msgdata_attribute(), start_request(), unpack_cache_directive(), unpack_challenge(), unpack_credentials(), unpack_optional_q_value(), unpack_parameter(), unpack_warning_value(), urltrans_fill_escape_codes(), wap_map_url(), wml_charsets(), wsp_cap_pack_list(), wsp_pack_quoted_text(), wsp_pack_text(), wsp_pack_value(), xidris_send_sms(), and xmlrpc_print_array().

1505 {
1506  gw_assert(ostr1 != NULL);
1507  octstr_insert(ostr1, ostr2, ostr1->len);
1508 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1303
long len
Definition: octstr.c:121

◆ octstr_append_char()

void octstr_append_char ( Octstr ostr,
int  ch 
)

Definition at line 1517 of file octstr.c.

References gw_assert(), Octstr::len, and octstr_insert_data().

Referenced by add_wsp_disconnect(), add_wsp_get(), append_encoded_integer(), at2_convertpdu(), at2_decode7bituncompressed(), at2_encode7bituncompressed(), at2_encode8bituncompressed(), at2_format_address_field(), at2_init_device(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), cgw_handle_op(), cgwop_tostr(), charset_gsm_to_utf8(), charset_utf8_to_gsm(), convert_html_entity(), convert_q_value(), decode_binary_data(), emi2_handle_smscreq(), emimsg_tostring(), encode_binary_data(), get_pattern(), gsm2number(), html_to_sms(), http_header_split_auth_value(), httpsmsc_receiver(), main(), msg_to_emimsg(), oisd_expand_gsm7(), oisd_send_delivery_request(), oisd_send_response(), oisd_shrink_gsm7(), ota_tokenize_bookmarks(), ota_tokenize_settings(), output_char(), output_st_char(), output_variable(), pack_7bit(), pack_challenge(), pack_credentials(), pack_md5(), pack_parameter(), pack_quoted_string(), pack_range_value(), pack_server_address(), packet_encode_message(), parse2trans(), parse_value(), parse_variable(), prepend_catenation_udh(), proxy_unpack_credentials(), randomize(), recover_absolute_uri(), reply_known_capabilities(), set_cookies(), smasi_pdu_pack(), sms_to_client(), smsc_emi2_create(), soap_format_xml(), string_table_apply(), string_table_output(), tokenize_date(), unpack_cache_directive(), unpack_challenge(), unpack_credentials(), unpack_parameter(), unpack_range_value(), unpack_warning_value(), urltrans_fill_escape_codes(), wml_binary_output(), wml_charsets(), wsp_cap_pack_list(), wsp_pack_long_integer(), wsp_pack_quoted_text(), wsp_pack_retry_after(), wsp_pack_short_integer(), wsp_pack_text(), wsp_pack_value(), and wsp_unpack_version_value().

1518 {
1519  unsigned char c = ch;
1520 
1521  gw_assert(ch >= 0);
1522  gw_assert(ch <= UCHAR_MAX);
1523  octstr_insert_data(ostr, ostr->len, &c, 1);
1524 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
long len
Definition: octstr.c:121

◆ octstr_append_cstr()

◆ octstr_append_data()

void octstr_append_data ( Octstr ostr,
const char *  data,
long  len 
)

Definition at line 1497 of file octstr.c.

References gw_assert(), Octstr::len, and octstr_insert_data().

Referenced by add_wsp_connect(), append_integer(), at2_read_buffer(), charset_convert(), client_session(), conn_write_data(), conn_write_withlen(), convert(), gen_data(), get_pattern(), main(), octstr_append_from_socket(), octstr_append_uintvar(), octstr_format_valist_real(), octstr_read_pipe(), radius_authenticate_pdu(), read_data(), read_line(), send_post(), set_charset(), unlocked_read(), url_pattern(), and wap_msg_send().

1498 {
1499  gw_assert(ostr != NULL);
1500  octstr_insert_data(ostr, ostr->len, data, len);
1501 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
long len
Definition: octstr.c:121

◆ octstr_append_decimal()

void octstr_append_decimal ( Octstr ostr,
long  value 
)

Definition at line 1976 of file octstr.c.

References octstr_append_cstr().

Referenced by cgw_handle_op(), cgwop_create(), convert(), get_pattern(), msg_to_emimsg(), pack_server_address(), smsc_emi2_create(), unpack_parameter(), unpack_range_value(), urltrans_fill_escape_codes(), wsp_unpack_integer_value(), wsp_unpack_version_value(), and wsp_unpack_well_known_field().

1977 {
1978  char tmp[128];
1979 
1980  sprintf(tmp, "%ld", value);
1981  octstr_append_cstr(ostr, tmp);
1982 }
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1511

◆ octstr_append_from_hex()

void octstr_append_from_hex ( Octstr ostr,
char *  hex 
)

Definition at line 451 of file octstr.c.

References gw_assert(), Octstr::immutable, octstr_append(), octstr_create, octstr_destroy(), octstr_hex_to_binary(), and seems_valid.

Referenced by cimd_submit_msg(), client_thread(), main(), ota_pack_push_headers(), ota_pack_udh(), ota_tokenize_bookmarks(), and ota_tokenize_settings().

452 {
453  Octstr *output;
454 
455  seems_valid(ostr);
456  gw_assert(!ostr->immutable);
457 
458  output = octstr_create(hex);
459  octstr_hex_to_binary(output);
460  octstr_append(ostr, output);
461  octstr_destroy(output);
462 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
int immutable
Definition: octstr.c:123
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_hex_to_binary(Octstr *ostr)
Definition: octstr.c:494

◆ octstr_append_from_socket()

int octstr_append_from_socket ( Octstr ostr,
int  socket 
)

Definition at line 1280 of file octstr.c.

References error(), gw_assert(), Octstr::immutable, octstr_append_data(), and seems_valid.

Referenced by cimd2_get_packet(), cimd2_receive_msg(), oisd_get_packet(), and oisd_receive_msg().

1281 {
1282  unsigned char buf[4096];
1283  int len;
1284 
1285  seems_valid(ostr);
1286  gw_assert(!ostr->immutable);
1287 
1288 again:
1289  len = recv(socket, buf, sizeof(buf), 0);
1290  if (len < 0 && errno == EINTR)
1291  goto again;
1292 
1293  if (len < 0) {
1294  error(errno, "Could not read from socket %d", socket);
1295  return -1;
1296  }
1297 
1298  octstr_append_data(ostr, buf, len);
1299  return len;
1300 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1497
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169

◆ octstr_append_uintvar()

void octstr_append_uintvar ( Octstr ostr,
unsigned long  value 
)

Definition at line 1931 of file octstr.c.

References octstr_append_data(), and start.

Referenced by add_wsp_disconnect(), add_wsp_get(), ota_pack_push_headers(), output_variable(), pack_content_range(), pack_qvalue(), pack_range_value(), parse_attribute(), parse_element(), reply_known_capabilities(), simple_binary_output(), string_table_apply(), wml_binary_output(), wsp_cap_pack_list(), and wsp_pack_value().

1932 {
1933  /* A uintvar is defined to be up to 32 bits large, so it will
1934  * fit in 5 octets. */
1935  unsigned char octets[5];
1936  int i;
1937  int start;
1938 
1939  /* Handle last byte separately; it has no continuation bit,
1940  * and must be encoded even if value is 0. */
1941  octets[4] = value & 0x7f;
1942  value >>= 7;
1943 
1944  for (i = 3; value > 0 && i >= 0; i--) {
1945  octets[i] = 0x80 | (value & 0x7f);
1946  value >>= 7;
1947  }
1948  start = i + 1;
1949 
1950  octstr_append_data(ostr, octets + start, 5 - start);
1951 }
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1497
static int start

◆ octstr_base64_to_binary()

void octstr_base64_to_binary ( Octstr ostr)

Definition at line 663 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, seems_valid, and warning().

Referenced by extract_base64(), pack_credentials(), pack_md5(), response(), and soap_msgdata_deps().

664 {
665  long triplet;
666  long pos, len;
667  long to;
668  int quadpos = 0;
669  int warned = 0;
670  unsigned char *data;
671 
672  seems_valid(ostr);
673  gw_assert(!ostr->immutable);
674 
675  len = ostr->len;
676  data = ostr->data;
677 
678  if (len == 0)
679  return;
680 
681  to = 0;
682  triplet = 0;
683  quadpos = 0;
684  for (pos = 0; pos < len; pos++) {
685  int c = data[pos];
686  int sixbits;
687 
688  if (c >= 'A' && c <= 'Z') {
689  sixbits = c - 'A';
690  } else if (c >= 'a' && c <= 'z') {
691  sixbits = 26 + c - 'a';
692  } else if (c >= '0' && c <= '9') {
693  sixbits = 52 + c - '0';
694  } else if (c == '+') {
695  sixbits = 62;
696  } else if (c == '/') {
697  sixbits = 63;
698  } else if (c == '=') {
699  /* These can only occur at the end of encoded
700  * text. RFC 2045 says we can assume it really
701  * is the end. */
702  break;
703  } else if (isspace(c)) {
704  /* skip whitespace */
705  continue;
706  } else {
707  if (!warned) {
708  warning(0, "Unusual characters in base64 "
709  "encoded text.");
710  warned = 1;
711  }
712  continue;
713  }
714 
715  triplet = (triplet << 6) | sixbits;
716  quadpos++;
717 
718  if (quadpos == 4) {
719  data[to++] = (triplet >> 16) & 0xff;
720  data[to++] = (triplet >> 8) & 0xff;
721  data[to++] = triplet & 0xff;
722  quadpos = 0;
723  }
724  }
725 
726  /* Deal with leftover octets */
727  switch (quadpos) {
728  case 0:
729  break;
730  case 3: /* triplet has 18 bits, we want the first 16 */
731  data[to++] = (triplet >> 10) & 0xff;
732  data[to++] = (triplet >> 2) & 0xff;
733  break;
734  case 2: /* triplet has 12 bits, we want the first 8 */
735  data[to++] = (triplet >> 4) & 0xff;
736  break;
737  case 1:
738  warning(0, "Bad padding in base64 encoded text.");
739  break;
740  }
741 
742  ostr->len = to;
743  data[to] = '\0';
744 
745  seems_valid(ostr);
746 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void warning(int err, const char *fmt,...)
Definition: log.c:660
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_binary_to_base64()

void octstr_binary_to_base64 ( Octstr ostr)

Definition at line 542 of file octstr.c.

References Octstr::data, from, gw_assert(), Octstr::immutable, Octstr::len, lines, octstr_grow(), octstr_imm(), octstr_insert(), and seems_valid.

Referenced by http_add_basic_auth(), proxy_add_authentication(), soap_o2o_msgdata_attribute(), transfer_encode(), unpack_credentials(), and wsp_unpack_well_known_field().

543 {
544  static const unsigned char base64[64] =
545  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
546  long triplets;
547  long lines;
548  long orig_len;
549  unsigned char *data;
550  long from, to;
551  int left_on_line;
552 
553  seems_valid(ostr);
554  gw_assert(!ostr->immutable);
555 
556  if (ostr->len == 0) {
557  /* Always terminate with CR LF */
558  octstr_insert(ostr, octstr_imm("\015\012"), 0);
559  return;
560  }
561 
562  /* The lines must be 76 characters each (or less), and each
563  * triplet will expand to 4 characters, so we can fit 19
564  * triplets on one line. We need a CR LF after each line,
565  * which will add 2 octets per 19 triplets (rounded up). */
566  triplets = (ostr->len + 2) / 3; /* round up */
567  lines = (triplets + 18) / 19;
568 
569  octstr_grow(ostr, triplets * 4 + lines * 2);
570  orig_len = ostr->len;
571  data = ostr->data;
572 
573  ostr->len = triplets * 4 + lines * 2;
574  data[ostr->len] = '\0';
575 
576  /* This function works back-to-front, so that encoded data will
577  * not overwrite source data.
578  * from points to the start of the last triplet (which may be
579  * an odd-sized one), and to points to the start of where the
580  * last quad should go. */
581  from = (triplets - 1) * 3;
582  to = (triplets - 1) * 4 + (lines - 1) * 2;
583 
584  /* First write the CR LF after the last quad */
585  data[to + 5] = 10; /* LF */
586  data[to + 4] = 13; /* CR */
587  left_on_line = triplets - ((lines - 1) * 19);
588 
589  /* base64 encoding is in 3-octet units. To handle leftover
590  * octets, conceptually we have to zero-pad up to the next
591  * 6-bit unit, and pad with '=' characters for missing 6-bit
592  * units.
593  * We do it by first completing the first triplet with
594  * zero-octets, and after the loop replacing some of the
595  * result characters with '=' characters.
596  * There is enough room for this, because even with a 1 or 2
597  * octet source string, space for four octets of output
598  * will be reserved.
599  */
600  switch (orig_len % 3) {
601  case 0:
602  break;
603  case 1:
604  data[orig_len] = 0;
605  data[orig_len + 1] = 0;
606  break;
607  case 2:
608  data[orig_len + 1] = 0;
609  break;
610  }
611 
612  /* Now we only have perfect triplets. */
613  while (from >= 0) {
614  long whole_triplet;
615 
616  /* Add a newline, if necessary */
617  if (left_on_line == 0) {
618  to -= 2;
619  data[to + 5] = 10; /* LF */
620  data[to + 4] = 13; /* CR */
621  left_on_line = 19;
622  }
623 
624  whole_triplet = (data[from] << 16) |
625  (data[from + 1] << 8) |
626  data[from + 2];
627  data[to + 3] = base64[whole_triplet % 64];
628  data[to + 2] = base64[(whole_triplet >> 6) % 64];
629  data[to + 1] = base64[(whole_triplet >> 12) % 64];
630  data[to] = base64[(whole_triplet >> 18) % 64];
631 
632  to -= 4;
633  from -= 3;
634  left_on_line--;
635  }
636 
637  gw_assert(left_on_line == 0);
638  gw_assert(from == -3);
639  gw_assert(to == -4);
640 
641  /* Insert padding characters in the last quad. Remember that
642  * there is a CR LF between the last quad and the end of the
643  * string. */
644  switch (orig_len % 3) {
645  case 0:
646  break;
647  case 1:
648  gw_assert(data[ostr->len - 3] == 'A');
649  gw_assert(data[ostr->len - 4] == 'A');
650  data[ostr->len - 3] = '=';
651  data[ostr->len - 4] = '=';
652  break;
653  case 2:
654  gw_assert(data[ostr->len - 3] == 'A');
655  data[ostr->len - 3] = '=';
656  break;
657  }
658 
659  seems_valid(ostr);
660 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static List * lines
Definition: mtbatch.c:88
static Octstr * from
Definition: mtbatch.c:95
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1303
int immutable
Definition: octstr.c:123
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_binary_to_hex()

void octstr_binary_to_hex ( Octstr ostr,
int  uppercase 
)

Definition at line 465 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, octstr_grow(), and seems_valid.

Referenced by at2_scan_for_telnet_escapes(), bb_alog_sms(), convert(), dlr_spool_add(), get_pattern(), kannel_send_sms(), main(), make_emi60(), msg_to_cgwop(), msg_to_emimsg(), ota_pack_push_headers(), our_hash_func(), pack_7bit(), packet_add_hex_parm(), soap_msgdata_attribute(), and urltrans_fill_escape_codes().

466 {
467  unsigned char *hexits;
468  long i, tmp;
469 
470  seems_valid(ostr);
471  gw_assert(!ostr->immutable);
472  if (ostr->len == 0)
473  return;
474 
475  hexits = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
476  octstr_grow(ostr, ostr->len * 2);
477 
478  /* In-place modification must be done back-to-front to avoid
479  * overwriting the data while we read it. Even the order of
480  * the two assignments is important, to get i == 0 right. */
481  for (i = ostr->len - 1; i >= 0; i--) {
482  tmp = i << 1; /* tmp = i * 2; */
483  ostr->data[tmp + 1] = hexits[ostr->data[i] & 0xf];
484  ostr->data[tmp] = hexits[ostr->data[i] >> 4];
485  }
486 
487  ostr->len = ostr->len * 2;
488  ostr->data[ostr->len] = '\0';
489 
490  seems_valid(ostr);
491 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_case_compare()

int octstr_case_compare ( const Octstr os1,
const Octstr os2 
)

Definition at line 903 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid.

Referenced by brunet_parse_reply(), cfg_get_bool(), check_comparisons(), generic_receive_sms(), get_x_kannel_from_headers(), handle_transaction(), http_get_header_parameter(), http_header_pack(), http_header_value(), init_bearerbox(), init_smsbox(), init_wapbox(), kannel_parse_reply(), normalize_charset(), octstr_item_case_match(), octstr_recode(), ota_pack_push_headers(), ota_pack_udh(), pack_challenge(), pack_credentials(), pack_pragma(), pap_get_content(), parse_array_element(), parse_attribute(), parse_bearer(), parse_client_specifier(), parse_data_element(), parse_delivery_method(), parse_document(), parse_element(), parse_fault_element(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_network(), parse_ota_syncsettings(), parse_param_element(), parse_params_element(), parse_priority(), parse_requirement(), parse_state(), parse_struct_element(), parse_value_element(), qualifiers(), select_bearer_network(), set_any_value(), smsbox_req_handle(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_xmlrpc_post(), soap_msgdata_deps(), string_to_number(), string_to_versioned_number(), url_result_thread(), uses_gsm_msisdn_address(), uses_ipv4_address(), uses_ipv6_address(), wap_map_url(), wina_bearer_identifier(), and xidris_parse_reply().

904 {
905  int c1, c2;
906  long i, len;
907 
908  seems_valid(os1);
909  seems_valid(os2);
910 
911  if (os1->len < os2->len)
912  len = os1->len;
913  else
914  len = os2->len;
915 
916  if (len == 0) {
917  if (os1->len == 0 && os2->len > 0)
918  return -1;
919  if (os1->len > 0 && os2->len == 0)
920  return 1;
921  return 0;
922  }
923 
924  c1 = c2 = 0;
925  for (i = 0; i < len; ++i) {
926  c1 = toupper(os1->data[i]);
927  c2 = toupper(os2->data[i]);
928  if (c1 != c2)
929  break;
930  }
931 
932  if (i == len) {
933  if (i == os1->len && i == os2->len)
934  return 0;
935  if (i == os1->len)
936  return -1;
937  return 1;
938  } else {
939  /*
940  c1 = toupper(os1->data[i]);
941  c2 = toupper(os2->data[i]);
942  */
943  if (c1 < c2)
944  return -1;
945  if (c1 == c2)
946  return 0;
947  return 1;
948  }
949 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_case_nsearch()

long octstr_case_nsearch ( const Octstr haystack,
const Octstr needle,
long  pos,
long  n 
)

Definition at line 1129 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by check_control_content_type_header(), check_data_content_type_header(), check_data_x_wap_application_id_header(), drop_extension_headers(), drop_optional_header(), pass_extension_headers(), and pass_optional_header().

1130 {
1131  long i, j;
1132  int c1, c2;
1133 
1134  seems_valid(haystack);
1135  seems_valid(needle);
1136  gw_assert(pos >= 0);
1137 
1138  /* Always "find" an empty string */
1139  if (needle->len == 0)
1140  return 0;
1141 
1142  for (i = pos; i <= haystack->len - needle->len && i < n; ++i) {
1143  for (j = 0; j < needle->len && j < n; ++j) {
1144  c1 = toupper(haystack->data[i + j]);
1145  c2 = toupper(needle->data[j]);
1146  if (c1 != c2)
1147  break;
1148  }
1149  if (j == needle->len)
1150  return i;
1151  }
1152 
1153  return -1;
1154 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_case_search()

long octstr_case_search ( const Octstr haystack,
const Octstr needle,
long  pos 
)

Definition at line 1102 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by check_control_content_type_header(), drop_extension_headers(), get_mime_boundary(), http_something_accepted(), parse_appid_header(), parse_url(), strip_prefix_and_suffix(), and type_is().

1103 {
1104  long i, j;
1105  int c1, c2;
1106 
1107  seems_valid(haystack);
1108  seems_valid(needle);
1109  gw_assert(pos >= 0);
1110 
1111  /* Always "find" an empty string */
1112  if (needle->len == 0)
1113  return 0;
1114 
1115  for (i = pos; i <= haystack->len - needle->len; ++i) {
1116  for (j = 0; j < needle->len; ++j) {
1117  c1 = toupper(haystack->data[i + j]);
1118  c2 = toupper(needle->data[j]);
1119  if (c1 != c2)
1120  break;
1121  }
1122  if (j == needle->len)
1123  return i;
1124  }
1125 
1126  return -1;
1127 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_cat()

Octstr* octstr_cat ( Octstr ostr1,
Octstr ostr2 
)

Definition at line 383 of file octstr.c.

References Octstr::data, Octstr::len, octstr_create, seems_valid, and Octstr::size.

Referenced by msg_to_pdu().

384 {
385  Octstr *ostr;
386 
387  seems_valid(ostr1);
388  seems_valid(ostr2);
389 
390  ostr = octstr_create("");
391  ostr->len = ostr1->len + ostr2->len;
392  ostr->size = ostr->len + 1;
393  ostr->data = gw_malloc(ostr->size);
394 
395  if (ostr1->len > 0)
396  memcpy(ostr->data, ostr1->data, ostr1->len);
397  if (ostr2->len > 0)
398  memcpy(ostr->data + ostr1->len, ostr2->data, ostr2->len);
399  ostr->data[ostr->len] = '\0';
400 
401  seems_valid(ostr);
402  return ostr;
403 }
long size
Definition: octstr.c:122
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_check_range()

int octstr_check_range ( Octstr ostr,
long  pos,
long  len,
octstr_func_t  filter 
)

Definition at line 814 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by convert_addr_from_pdu(), get_originator_type(), handle_dlr(), handle_pdu(), is_token(), msg_to_cgwop(), msg_to_emimsg(), msg_to_pdu(), octstr_hex_to_binary(), octstr_symbolize(), oisd_send_delivery_request(), pack_parameter(), packet_add_address_parm(), packet_check(), packet_check_header(), packet_check_parameter(), packet_encode_message(), parm_valid_address(), and run_batch().

816 {
817  long end = pos + len;
818 
819  seems_valid(ostr);
820  gw_assert(len >= 0);
821 
822  if (pos >= ostr->len)
823  return 1;
824  if (end > ostr->len)
825  end = ostr->len;
826 
827  for ( ; pos < end; pos++) {
828  if (!filter(ostr->data[pos]))
829  return 0;
830  }
831 
832  return 1;
833 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_compare()

int octstr_compare ( const Octstr ostr1,
const Octstr ostr2 
)

Definition at line 871 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid.

Referenced by add_connection_header(), add_content_transfer_encoding_type(), add_content_type(), add_delimiter(), add_push_application_id(), at2_read_modems(), at2_read_pending_incoming_messages(), at2_send_one_message(), authorise_username(), boxc_receiver(), brunet_receive_sms(), cgw_read_op(), cgwop_get(), charset_to_utf8(), check_comparisons(), check_do_elements(), check_login(), check_reversible(), cid_matches(), clickatell_parse_body(), client_thread(), cmp_conn_grp_checksum(), cmp_conn_grp_id(), cmp_rout_grp_checksum(), cmp_route(), content_transformable(), dlr_init(), dlr_mem_entry_match(), find_receiver_box(), generic_receive_sms(), handle_dlr(), have_cookie(), httpd_check_authorization(), init_bearerbox(), init_smsbox(), init_wapbox(), ip_allowed_by_ppg(), ip_allowed_by_user(), item_has_key(), kannel_receive_sms(), main(), meta_data_merge(), mime_something_to_entity(), msg_to_bb(), my_cmp(), my_sort_cmp(), name(), obey_request_thread(), octstr_cmp_cb(), octstr_item_match(), octstr_sort_cb(), ota_tokenize_settings(), pack_appid_list(), packet_encode_message(), pap_convert_content(), pap_request_thread(), parse2trans(), parse_address_value(), parse_attr_value(), parse_attribute(), parse_bad_message_response_value(), parse_code(), parse_document(), parse_element(), parse_pap_value(), parse_progress_note_value(), parse_push_message_value(), parse_push_response_value(), parse_quality_of_service_value(), parse_response_result_value(), parse_url(), password_matches(), proxy_used_for_host(), push_has_pi_push_id(), radius_authenticate_pdu(), remember_receiver(), return_reply(), sendsms_thread(), session_has_addr(), session_has_pi_client_address(), set_any_value(), set_attribute_value(), smsbox_req_sendota(), smsc2_add_smsc(), smsc2_find(), smsc2_restart_smsc(), smsc_at2_create(), smsc_open(), smscconn_create(), soap_get_index(), soap_server(), start_fetch(), string_table_add(), string_table_apply(), string_table_sort_list(), test_header_combine(), transfer_encode(), udp_addwdp(), udp_receiver(), udpc_find_mapping(), update_table(), update_tables(), urltrans_find_username(), user_find_by_username(), wap_event_accept_or_create(), wap_map_user(), wildcarded_ip_found(), wsp_cap_get_data(), wsp_encoding_string_to_version(), and xidris_receive_sms().

872 {
873  int ret;
874  long len;
875 
876  seems_valid(ostr1);
877  seems_valid(ostr2);
878 
879  if (ostr1->len < ostr2->len)
880  len = ostr1->len;
881  else
882  len = ostr2->len;
883 
884  if (len == 0) {
885  if (ostr1->len == 0 && ostr2->len > 0)
886  return -1;
887  if (ostr1->len > 0 && ostr2->len == 0)
888  return 1;
889  return 0;
890  }
891 
892  ret = memcmp(ostr1->data, ostr2->data, len);
893  if (ret == 0) {
894  if (ostr1->len < ostr2->len)
895  ret = -1;
896  else if (ostr1->len > ostr2->len)
897  ret = 1;
898  }
899  return ret;
900 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_convert_from_html_entities()

void octstr_convert_from_html_entities ( Octstr input)

Definition at line 2804 of file octstr.c.

References octstr_copy, octstr_delete(), octstr_destroy(), octstr_find_entity(), octstr_insert_char(), and octstr_search_char().

2805 {
2806  int startpos = 0, endpos;
2807  int entity;
2808  Octstr *match;
2809 
2810  while ((startpos = octstr_search_char(input, '&', startpos)) != -1) {
2811  endpos = octstr_search_char(input, ';', startpos + 1);
2812  if (endpos >= 0) {
2813  match = octstr_copy(input, startpos + 1, endpos - startpos - 1);
2814  entity = octstr_find_entity(match, 0, 0);
2815  if (entity >= 0) {
2816  octstr_delete(input, startpos, endpos - startpos + 1);
2817  octstr_insert_char(input, startpos, entity);
2818  }
2819  octstr_destroy(match);
2820  }
2821  startpos++;
2822  }
2823 }
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
void octstr_insert_char(Octstr *ostr, long pos, const char c)
Definition: octstr.c:1481
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static int octstr_find_entity(Octstr *input, int startfind, int endfind)
Definition: octstr.c:2760
Definition: octstr.c:118

◆ octstr_convert_printable()

void octstr_convert_printable ( Octstr ostr)

Definition at line 864 of file octstr.c.

References Octstr::len, make_printable(), and octstr_convert_range().

Referenced by bb_alog_sms(), and get_pattern().

865 {
866  octstr_convert_range(ostr, 0, ostr->len, make_printable);
867 }
void octstr_convert_range(Octstr *ostr, long pos, long len, octstr_func_t map)
Definition: octstr.c:836
static int make_printable(int c)
Definition: octstr.c:858
long len
Definition: octstr.c:121

◆ octstr_convert_range()

void octstr_convert_range ( Octstr ostr,
long  pos,
long  len,
octstr_func_t  map 
)

Definition at line 836 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, and seems_valid.

Referenced by check_variable_syntax(), octstr_convert_printable(), parse_charset(), and parse_constant().

838 {
839  long end = pos + len;
840 
841  seems_valid(ostr);
842  gw_assert(!ostr->immutable);
843  gw_assert(len >= 0);
844 
845  if (pos >= ostr->len)
846  return;
847  if (end > ostr->len)
848  end = ostr->len;
849 
850  for ( ; pos < end; pos++) {
851  ostr->data[pos] = map(ostr->data[pos]);
852  }
853 
854  seems_valid(ostr);
855 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_convert_to_html_entities()

void octstr_convert_to_html_entities ( Octstr input)

Definition at line 2738 of file octstr.c.

References octstr_get_char(), and octstr_len().

Referenced by soap_msgdata_attribute(), soap_o2o_msgdata_attribute(), and xmlrpc_scalar_print().

2739 {
2740  int i;
2741 
2742  for (i = 0; i < octstr_len(input); ++i) {
2743  switch (octstr_get_char(input, i)) {
2744 #define ENTITY(a,b) \
2745  case a: \
2746  octstr_delete(input, i, 1); \
2747  octstr_insert(input, octstr_imm("&" b ";"), i); \
2748  i += sizeof(b); break;
2749 #include "gwlib/html-entities.def"
2750 #undef ENTITY
2751  }
2752  }
2753 }
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ octstr_copy_real()

Octstr* octstr_copy_real ( const Octstr ostr,
long  from,
long  len,
const char *  file,
long  line,
const char *  func 
)

Definition at line 351 of file octstr.c.

References Octstr::data, file, from, gw_assert(), Octstr::len, octstr_create, octstr_create_from_data_trace, and seems_valid_real().

Referenced by http_header_find_first_real().

353 {
354  if (ostr == NULL)
355  return octstr_create("");
356 
357  seems_valid_real(ostr, file, line, func);
358  gw_assert(from >= 0);
359  gw_assert(len >= 0);
360 
361  if (from >= ostr->len)
362  return octstr_create("");
363 
364  if (len > ostr->len - from)
365  len = ostr->len - from;
366 
367  return octstr_create_from_data_trace(ostr->data + from, len, file,
368  line, func);
369 }
static void seems_valid_real(const Octstr *ostr, const char *filename, long lineno, const char *function)
Definition: octstr.c:2545
gw_assert(wtls_machine->packet_to_send !=NULL)
FILE * file
Definition: log.c:169
static Octstr * from
Definition: mtbatch.c:95
#define octstr_create_from_data_trace(data, len, file, line, func)
Definition: octstr.h:136
#define octstr_create(cstr)
Definition: octstr.h:125
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_create_from_data_real()

Octstr* octstr_create_from_data_real ( const char *  data,
long  len,
const char *  file,
long  line,
const char *  func 
)

Definition at line 250 of file octstr.c.

References Octstr::data, file, gw_assert(), Octstr::immutable, Octstr::len, seems_valid, and Octstr::size.

252 {
253  Octstr *ostr;
254 
255  gw_assert(len >= 0);
256  if (data == NULL)
257  gw_assert(len == 0);
258 
259  /* if gw_assert is disabled just return NULL
260  * and caller will check for NULL or just crash.
261  */
262  if (len < 0 || (data == NULL && len != 0))
263  return NULL;
264 
265  ostr = gw_malloc_trace(sizeof(*ostr), file, line, func);
266  if (len == 0) {
267  ostr->len = 0;
268  ostr->size = 0;
269  ostr->data = NULL;
270  } else {
271  ostr->len = len;
272  ostr->size = len + 1;
273  ostr->data = gw_malloc_trace(ostr->size, file, line, func);
274  memcpy(ostr->data, data, len);
275  ostr->data[len] = '\0';
276  }
277  ostr->immutable = 0;
278  seems_valid(ostr);
279  return ostr;
280 }
gw_assert(wtls_machine->packet_to_send !=NULL)
FILE * file
Definition: log.c:169
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_create_real()

Octstr* octstr_create_real ( const char *  cstr,
const char *  file,
long  line,
const char *  func 
)

Definition at line 243 of file octstr.c.

References file, gw_assert(), and octstr_create_from_data_trace.

245 {
246  gw_assert(cstr != NULL);
247  return octstr_create_from_data_trace(cstr, strlen(cstr), file, line, func);
248 }
gw_assert(wtls_machine->packet_to_send !=NULL)
FILE * file
Definition: log.c:169
#define octstr_create_from_data_trace(data, len, file, line, func)
Definition: octstr.h:136

◆ octstr_delete()

void octstr_delete ( Octstr ostr1,
long  pos,
long  len 
)

Definition at line 1527 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, and seems_valid.

Referenced by at2_detect_modem_type(), at2_format_address_field(), at2_init_device(), at2_pdu_encode(), at2_scan_for_telnet_escapes(), catenate_msg(), cgw_decode_msg(), cgw_encode_msg(), charset_gsm_to_latin1(), check_data_content_type_header(), check_data_x_wap_application_id_header(), client_read_status(), compare_octstr_sequence(), concat_handling_check_and_handle(), conn_read_line(), convert_addr_from_pdu(), convert_cimd2_to_gsm(), data_sm_to_msg(), decode_binary_data(), dlr_find(), drop_character(), drop_extension_headers(), drop_header_true(), drop_separator(), eat_char(), eat_checksum(), eat_number(), eat_string_parm(), emi2_handle_smscreq(), encode_binary_data(), escape_data(), expand_file(), extract_msgdata_part(), find_translation(), fix_boundary_element(), get_originator_type(), get_start_param(), handle_operation(), handle_two_terminators(), http_header_get_content_type(), http_remove_hop_headers(), httpd_serve(), main(), meta_data_pack(), mime_something_to_entity(), msg_to_emimsg(), msg_to_pdu(), octstr_convert_from_html_entities(), octstr_delete_matching(), octstr_drop_leading_blanks(), octstr_drop_trailing_zeros(), octstr_replace(), octstr_replace_first(), octstr_shrink_blanks(), octstr_split_by_pos(), octstr_strip_blanks(), octstr_strip_char(), octstr_strip_crlfs(), octstr_strip_nonalphanums(), oisd_shrink_gsm7(), pack_7bit(), pack_cache_control(), pack_challenge(), pack_known_header(), pack_parameter(), pack_quoted_string(), packet_extract(), packet_set_checksum(), parse_address(), parse_appid_header(), parse_attr_value(), parse_attribute(), parse_body_part(), parse_data(), parse_entities(), parse_epilogue(), parse_get_rest(), parse_ppg_specifier(), parse_preamble(), parse_url_value(), parse_value(), pass_data_headers(), pass_extension_headers(), pass_optional_header(), pdu_to_msg(), radius_authenticate_pdu(), radius_pdu_pack(), read_line(), remove_crs(), remove_long(), remove_prefix(), replace_octstr_char(), response(), send_message(), set_charset(), skip_tail(), soap_parse_dlr(), soap_parse_mo(), split_headers(), string_table_apply(), strip_keyword(), strip_prefix_and_suffix(), unescape_data(), unlocked_read(), unlocked_write(), unpack_broken_parameters(), unpack_credentials(), unpack_datagram(), unpack_warning_value(), wap_map_url(), write_data(), wsp_pack_list(), wsp_strip_parameters(), wsp_unpack_well_known_field(), and wtp_unpack_wdp_datagram().

1528 {
1529  seems_valid(ostr1);
1530  gw_assert(!ostr1->immutable);
1531 
1532  if (pos > ostr1->len)
1533  pos = ostr1->len;
1534  if (pos + len > ostr1->len)
1535  len = ostr1->len - pos;
1536  if (len > 0) {
1537  memmove(ostr1->data + pos, ostr1->data + pos + len,
1538  ostr1->len - pos - len);
1539  ostr1->len -= len;
1540  ostr1->data[ostr1->len] = '\0';
1541  }
1542 
1543  seems_valid(ostr1);
1544 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_delete_matching()

void octstr_delete_matching ( Octstr haystack,
Octstr needle 
)

Definition at line 2702 of file octstr.c.

References gw_assert(), Octstr::immutable, octstr_delete(), octstr_len(), octstr_search(), and seems_valid.

Referenced by push_content_create().

2703 {
2704  int p = 0;
2705  long len;
2706 
2707  seems_valid(haystack);
2708  seems_valid(needle);
2709  gw_assert(!haystack->immutable);
2710  len = octstr_len(needle);
2711 
2712  while ((p = octstr_search(haystack, needle, p)) != -1) {
2713  octstr_delete(haystack, p, len);
2714  }
2715 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
int immutable
Definition: octstr.c:123
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169

◆ octstr_destroy()

void octstr_destroy ( Octstr ostr)

Definition at line 324 of file octstr.c.

References Octstr::data, Octstr::immutable, and seems_valid.

Referenced by accept_boxc(), accept_escaped(), accept_smpp(), add_client_sdu_size(), add_crs(), add_group(), add_msg_cb(), add_msisdn(), add_push_flag(), add_via(), add_wsp_get(), add_x_wap_tod(), ap_destroy(), at2_close_device(), at2_detect_modem_type(), at2_device_thread(), at2_extract_line(), at2_flush_buffer(), at2_init_device(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), at2_pdu_extract(), at2_read_pending_incoming_messages(), at2_scan_for_telnet_escapes(), at2_send_one_message(), at2_set_message_storage(), at2_wait_line(), at2_wait_modem_command(), attribute_destroy(), bb_alog_shutdown(), bb_alog_sms(), bb_print_status(), bb_smscconn_send_failed(), bb_smscconn_sent(), bearerbox_address_destroy(), bearerbox_to_smpp(), boxc_cleanup(), boxc_destroy(), boxc_receiver(), boxc_route_msg_to_smsc(), boxc_sent_pop(), boxc_sent_push(), boxc_status(), brunet_parse_body(), brunet_receive_sms(), brunet_send_sms(), catenate_msg(), cfg_destroy(), cfg_dump(), cfg_get_bool(), cfg_get_group_checksum(), cfg_get_integer(), cfg_get_list(), cfg_read(), cfgloc_destroy(), cgw_handle_op(), cgw_listener(), cgw_read_op(), cgw_sender(), cgwop_create(), cgwop_destroy(), cgwop_send(), challenge(), charset_gsm_to_utf8(), charset_utf8_to_gsm(), check_application_headers(), check_comparisons(), check_data_content_type_header(), check_data_x_wap_application_id_header(), check_do_elements(), check_login(), check_multipart(), check_reversible(), check_variable_name(), check_variable_syntax(), check_x_wap_application_id_header(), cid_matches(), cimd2_accept_delivery_report_message(), cimd2_accept_message(), cimd2_destroy(), cimd2_request(), cimd2_submit_msg(), clickatell_parse_body(), clickatell_receive_sms(), clickatell_send_sms(), client_destroy(), client_is_persistent(), client_read_status(), client_shutdown(), client_thread(), cmp_conn_grp_checksum(), cmp_conn_grp_id(), cmp_rout_grp_checksum(), concat_handling_check_and_handle(), concat_handling_clear_old_parts(), config_reload(), conn_destroy(), conn_pool_get(), conndata_destroy(), content_transformable(), convert(), convert_content(), convert_wml_to_wmlc(), cookie_destroy(), create_dlr_from_msg(), create_onetrans(), create_oneuser(), date_parse_http(), decode_binary_data(), deconvert_content(), deduce_body_state(), delayed_http_reply(), deliver_to_bearerbox_real(), destroy_concatMsg(), destroy_group(), destroy_onetrans(), destroy_oneuser(), dispatch(), dlr_add(), dlr_find(), dlr_init(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), dlr_spool_shutdown(), do_queue_cleanup(), eat_int_parm(), eat_string_parm(), emi2_handle_smscreq(), emi2_listener(), emi2_receiver(), emi2_sender(), emimsg_destroy(), emimsg_send(), emimsg_tostring(), encode_binary_data(), entity_destroy(), eq_destroy_event(), expand_file(), extract_msgdata_part_by_coding(), fake_listener(), fieldmap_destroy(), fill_message(), find_charset_encoding(), find_translation(), fix_boundary_element(), flag_date_length(), for_each_file(), generic_init(), generic_parse_reply(), generic_receive_sms(), generic_send_sms(), get_and_set_debugs(), get_data(), get_msg_filename(), get_pattern(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), grp_dump(), handle_connect_reply(), handle_dlr(), handle_enquire(), handle_get_reply(), handle_login(), handle_operation(), handle_pdu(), handle_push_message(), handle_split(), handle_submit(), handle_transaction(), hash_destroy(), http_accept_request(), http_add_basic_auth(), http_close_proxy(), http_destroy_cgiargs(), http_get_header_parameter(), http_header_add_element(), http_header_combine(), http_header_mark_transformation(), http_header_pack(), http_header_remove_all(), http_header_split_auth_value(), http_header_value(), http_queue_thread(), http_remove_hop_headers(), http_send_reply(), http_something_accepted(), http_thread(), http_urlparse_destroy(), httpadmin_run(), httpadmin_start(), httpadmin_stop(), httpd_emu(), httpd_serve(), httpsmsc_receiver(), httpsmsc_send_cb(), init_bearerbox(), init_reroute(), init_smppbox(), init_smsbox(), init_smsbox_routes(), init_smsc_routes(), init_sqlbox(), init_wapbox(), io_thread(), ip_allowed_by_user(), item_destroy(), kannel_parse_reply(), kannel_receive_sms(), kannel_send_sms(), kill_kannel(), main(), main_connection_loop(), make_reply_headers(), md5digest(), meta_data_destroy(), meta_data_merge(), meta_data_pack(), meta_data_set_values(), meta_data_unpack(), mime_entity_body(), mime_entity_destroy(), mime_entity_dump_real(), mime_entity_set_body(), mime_entity_to_octstr(), mime_multipart_start_elem(), mime_something_to_entity(), msg_cb(), msg_to_bb(), msg_to_cgwop(), msg_to_emimsg(), msg_to_pdu(), normalize_charset(), normalize_number(), numhash_create(), obey_request(), obey_request_thread(), octstr_append_from_hex(), octstr_convert_from_html_entities(), octstr_destroy_item(), octstr_format_append(), octstr_read_file(), octstr_read_pipe(), octstr_recode(), ois_open_receiver(), oisd_accept_delivery_report_message(), oisd_destroy(), oisd_request(), oisd_shrink_gsm7(), oisd_submit_msg(), open_send_connection(), ota_compile(), ota_pack_message(), ota_pack_push_headers(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_7bit(), pack_accept(), pack_accept_charset(), pack_accept_language(), pack_appid_list(), pack_cache_control(), pack_challenge(), pack_content_disposition(), pack_content_range(), pack_credentials(), pack_md5(), pack_pragma(), pack_range_value(), pack_server_address(), pack_warning(), packet_add_hex_parm(), packet_add_int_parm(), packet_add_parm(), packet_check_can_receive(), packet_destroy(), packet_display_error(), packet_encode_message(), packet_get_hex_parm(), packet_get_int_parm(), pap_convert_content(), pap_get_content(), pap_request_thread(), parm_destroy(), parse_address(), parse_address_value(), parse_appid_header(), parse_array_element(), parse_attr_value(), parse_attribute(), parse_body_part(), parse_cdata(), parse_cgivars(), parse_charset(), parse_client_specifier(), parse_code(), parse_constant(), parse_data(), parse_data_element(), parse_document(), parse_element(), parse_entities(), parse_fault_element(), parse_inline_string(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_ota_syncsettings(), parse_param_element(), parse_params_element(), parse_preamble(), parse_push_message_value(), parse_push_response_value(), parse_request_line(), parse_st_octet_string(), parse_struct_element(), parse_text(), parse_url_value(), parse_uuid(), parse_value(), parse_value_element(), parse_variable(), parse_xml_tag(), pass_extension_headers(), pass_field_name(), pass_field_value(), pass_optional_header(), pattern_list_matches_ip(), pattern_route_destroy(), port_add(), port_get_fdset(), port_get_request(), port_put_request(), port_remove(), port_set_timeout(), prepend_char(), proxy_add_authentication(), proxy_thread(), proxy_unpack_credentials(), push_content_create(), push_headers_create(), radius_acct_init(), radius_acct_shutdown(), radius_authenticate_pdu(), radius_pdu_pack(), radius_pdu_unpack(), radius_type_convert(), read_body_until_eof(), read_body_with_length(), read_chunked_body_crlf(), read_chunked_body_data(), read_chunked_body_len(), read_from_bearerbox_real(), read_from_box(), read_mime_headers(), read_msg(), read_pdu(), read_ppg_config(), read_some_headers(), receive_push_reply(), receive_reply(), receive_request(), receive_smpp_thread(), recover_absolute_uri(), report_versions(), response(), return_replies_thread(), return_reply(), route_incoming_to_boxc(), route_incoming_to_smsc(), run_batch(), run_requests(), run_smsbox(), sar_info_destroy(), sardata_destroy(), sema_encode_msg(), sema_msg_session_mt(), send_bad_message_response(), send_enquire_link(), send_file(), send_gnack(), send_invoke_connect(), send_invoke_disconnect(), send_invoke_get(), send_logoff(), send_message(), send_messages(), send_msg(), send_pdu(), send_post(), send_push_response(), send_request(), send_smpp_thread(), send_to_pi(), send_udp(), send_unbind(), sendsms_thread(), server(), server_destroy(), server_thread(), set_addr_tuple(), set_bearer_defaults(), set_charset(), set_dlr_mask(), set_group_name(), set_network_defaults(), set_referer_url(), shutdown_cb(), si_compile(), simple_binary_destroy(), sl_compile(), smasi_destroy(), smasi_pdu_pack(), smasi_pdu_unpack(), smpp_destroy(), smpp_emu(), smpp_emu_handle_pdu(), smpp_emu_reader(), smpp_emu_writer(), smpp_pdu_dump_line(), smpp_pdu_init(), smpp_pdu_pack(), smpp_pdu_read_len(), smpp_tlv_add_constant(), smpp_tlv_destroy(), smpp_tlv_get_by_tag(), sms_msgdata_len(), sms_split(), sms_to_client(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_restart(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_start(), smsbox_thread(), smsbox_xmlrpc_post(), smsboxc_run(), smsc2_add_smsc(), smsc2_cleanup(), smsc2_restart_smsc(), smsc2_start(), smsc_cgw_create(), smsc_emi2_create(), smsc_emu_submit_ack(), smsc_fake_create(), smsc_http_create(), smsc_open(), smsc_smpp_create(), smsc_soap_create(), smscconn_create(), smscconn_destroy(), smscconn_reconfig(), soap_create_map(), soap_destroy_map(), soap_fetch_xml_data(), soap_format_xml(), soap_map_xml_data(), soap_parse_dlr(), soap_parse_mo(), socket_shutdown(), split_headers(), start_fetch(), start_push(), start_request(), status_cb(), store_dumper(), store_file_load(), store_spool_save(), store_spool_shutdown(), store_to_dict(), string_table_add(), string_table_apply(), string_table_collect_strings(), string_table_destroy(), string_table_proposal_destroy(), string_table_sort_list(), tcpip_connect_nb_to_server_with_port(), tcpip_connect_to_server_with_port(), tell_fatal_error(), tokenize_date(), transform_message(), type_is(), udp_addwdp(), udp_addwdp_from_client(), udp_addwdp_from_server(), udp_die(), udp_receiver(), udp_start(), udpc_create(), udpc_destroy(), unpack_cache_directive(), unpack_challenge(), unpack_credentials(), unpack_datagram(), unpack_optional_q_value(), unpack_parameter(), unpack_range_value(), unpack_warning_value(), update_table(), update_tables(), url_pattern(), url_result_thread(), urltrans_fill_escape_codes(), wait_for_ack(), wait_for_client(), wap_addr_destroy(), wap_map_destroy(), wap_map_url(), wap_msg_recv(), wap_msg_send(), wap_push_ppg_pushuser_authenticate(), wap_push_ppg_shutdown(), wap_user_map_destroy(), wml_binary_destroy(), wrapper_sender(), write_msg(), write_to_bearerbox_real(), wsp_cap_destroy(), wsp_headers_pack(), wsp_pack_list(), wsp_pack_retry_after(), wsp_pack_separate_content_type(), wsp_unpack_app_header(), wsp_unpack_well_known_field(), wtp_tpi_destroy(), wtp_unpack_wdp_datagram(), xidris_parse_reply(), xidris_receive_sms(), xidris_send_sms(), xml_error(), xmlrpc_call_destroy(), xmlrpc_call_print(), xmlrpc_doc_destroy(), xmlrpc_doc_print(), xmlrpc_doc_send(), xmlrpc_fault_destroy(), xmlrpc_member_destroy(), xmlrpc_print_array(), xmlrpc_print_struct(), xmlrpc_response_print(), xmlrpc_scalar_destroy(), xmlrpc_scalar_print(), and xmlrpc_value_print().

325 {
326  if (ostr != NULL) {
327  seems_valid(ostr);
328  if (!ostr->immutable) {
329  gw_free(ostr->data);
330  gw_free(ostr);
331  }
332  }
333 }
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120

◆ octstr_destroy_item()

◆ octstr_dump_debug()

static void octstr_dump_debug ( const Octstr ostr,
int  level 
)
static

Definition at line 1990 of file octstr.c.

References debug(), octstr_get_char(), octstr_len(), and seems_valid.

Referenced by octstr_dump_real().

1991 {
1992  unsigned char *p, *d, buf[1024], charbuf[256];
1993  long pos;
1994  const int octets_per_line = 16;
1995  int c, this_line_begins_at;
1996 
1997  if (ostr == NULL)
1998  return;
1999 
2000  seems_valid(ostr);
2001 
2002  debug("gwlib.octstr", 0, "%*sOctet string at %p:", level, "",
2003  (void *) ostr);
2004  debug("gwlib.octstr", 0, "%*s len: %lu", level, "",
2005  (unsigned long) ostr->len);
2006  debug("gwlib.octstr", 0, "%*s size: %lu", level, "",
2007  (unsigned long) ostr->size);
2008  debug("gwlib.octstr", 0, "%*s immutable: %d", level, "",
2009  ostr->immutable);
2010 
2011  buf[0] = '\0';
2012  p = buf;
2013  d = charbuf;
2014  this_line_begins_at = 0;
2015  for (pos = 0; pos < octstr_len(ostr); ) {
2016  c = octstr_get_char(ostr, pos);
2017  sprintf(p, "%02x ", c);
2018  p = strchr(p, '\0');
2019  if (isprint(c))
2020  *d++ = c;
2021  else
2022  *d++ = '.';
2023  ++pos;
2024  if (pos - this_line_begins_at == octets_per_line) {
2025  *d = '\0';
2026  debug("gwlib.octstr", 0, "%*s data: %s %s", level, "",
2027  buf, charbuf);
2028  buf[0] = '\0';
2029  charbuf[0] = '\0';
2030  p = buf;
2031  d = charbuf;
2032  this_line_begins_at = pos;
2033  }
2034  }
2035  if (pos - this_line_begins_at > 0) {
2036  *d = '\0';
2037  debug("gwlib.octstr", 0, "%*s data: %-*.*s %s", level, "",
2038  octets_per_line*3,
2039  octets_per_line*3, buf, charbuf);
2040  }
2041 
2042  debug("gwlib.octstr", 0, "%*sOctet string dump ends.", level, "");
2043 }
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
long len
Definition: octstr.c:121
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ octstr_dump_real()

void octstr_dump_real ( const Octstr ostr,
int  level,
  ... 
)

Definition at line 2115 of file octstr.c.

References error(), GW_DEBUG, GW_ERROR, GW_INFO, GW_WARNING, info(), octstr_dump_debug(), octstr_dump_LOGLEVEL, and warning().

2116 {
2117  va_list p;
2118  unsigned int loglevel;
2119 
2120  va_start(p, level);
2121  loglevel = va_arg(p, unsigned int);
2122  va_end(p);
2123 
2124  switch (loglevel) {
2125  case GW_DEBUG:
2126  octstr_dump_debug(ostr, level);
2127  break;
2128  case GW_INFO:
2129  octstr_dump_LOGLEVEL(info, ostr, level);
2130  break;
2131  case GW_WARNING:
2132  octstr_dump_LOGLEVEL(warning, ostr, level);
2133  break;
2134  case GW_ERROR:
2135  octstr_dump_LOGLEVEL(error, ostr, level);
2136  break;
2137  default:
2138  octstr_dump_debug(ostr, level);
2139  break;
2140  }
2141 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
Definition: log.h:69
Definition: log.h:69
void warning(int err, const char *fmt,...)
Definition: log.c:660
static void octstr_dump_debug(const Octstr *ostr, int level)
Definition: octstr.c:1990
#define octstr_dump_LOGLEVEL(loglevel, ostr, level)
Definition: octstr.c:2059
Definition: log.h:69
Definition: log.h:69

◆ octstr_dump_short()

void octstr_dump_short ( Octstr ostr,
int  level,
const char *  name 
)

Definition at line 2144 of file octstr.c.

References Octstr::data, debug(), Octstr::len, name, octstr_dump, and seems_valid.

Referenced by main(), and radius_pdu_unpack().

2145 {
2146  char buf[100];
2147  char *p;
2148  long i;
2149  int c;
2150 
2151  if (ostr == NULL) {
2152  debug("gwlib.octstr", 0, "%*s%s: NULL", level, "", name);
2153  return;
2154  }
2155 
2156  seems_valid(ostr);
2157 
2158  if (ostr->len < 20) {
2159  p = buf;
2160  for (i = 0; i < ostr->len; i++) {
2161  c = ostr->data[i];
2162  if (c == '\n') {
2163  *p++ = '\\';
2164  *p++ = 'n';
2165  } else if (!isprint(c)) {
2166  break;
2167  } else if (c == '"') {
2168  *p++ = '\\';
2169  *p++ = '"';
2170  } else if (c == '\\') {
2171  *p++ = '\\';
2172  *p++ = '\\';
2173  } else {
2174  *p++ = c;
2175  }
2176  }
2177  if (i == ostr->len) {
2178  *p++ = 0;
2179  /* We got through the loop without hitting nonprintable
2180  * characters. */
2181  debug("gwlib.octstr", 0, "%*s%s: \"%s\"", level, "", name, buf);
2182  return;
2183  }
2184  }
2185 
2186  debug("gwlib.octstr", 0, "%*s%s:", level, "", name);
2187  octstr_dump(ostr, level + 1);
2188 }
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
char * name
Definition: smsc_cimd2.c:212
#define seems_valid(ostr)
Definition: octstr.c:169
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_duplicate_real()

Octstr* octstr_duplicate_real ( const Octstr ostr,
const char *  file,
long  line,
const char *  func 
)

Definition at line 373 of file octstr.c.

References Octstr::data, file, Octstr::len, octstr_create_from_data_trace, and seems_valid_real().

375 {
376  if (ostr == NULL)
377  return NULL;
378  seems_valid_real(ostr, file, line, func);
379  return octstr_create_from_data_trace(ostr->data, ostr->len, file, line, func);
380 }
static void seems_valid_real(const Octstr *ostr, const char *filename, long lineno, const char *function)
Definition: octstr.c:2545
FILE * file
Definition: log.c:169
#define octstr_create_from_data_trace(data, len, file, line, func)
Definition: octstr.h:136
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_extract_uintvar()

long octstr_extract_uintvar ( Octstr ostr,
unsigned long *  value,
long  pos 
)

Definition at line 1954 of file octstr.c.

References octstr_get_char().

Referenced by is_default_cap(), parse_get_uintvar(), sanitize_capabilities(), wsp_cap_get_client_sdu(), wsp_cap_get_server_sdu(), and wsp_cap_unpack_list().

1955 {
1956  int c;
1957  int count;
1958  unsigned long ui;
1959 
1960  ui = 0;
1961  for (count = 0; count < 5; count++) {
1962  c = octstr_get_char(ostr, pos + count);
1963  if (c < 0)
1964  return -1;
1965  ui = (ui << 7) | (c & 0x7f);
1966  if (!(c & 0x80)) {
1967  *value = ui;
1968  return pos + count + 1;
1969  }
1970  }
1971 
1972  return -1;
1973 }
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ octstr_find_entity()

static int octstr_find_entity ( Octstr input,
int  startfind,
int  endfind 
)
static

Definition at line 2760 of file octstr.c.

References octstr_str_compare().

Referenced by octstr_convert_from_html_entities().

2761 {
2762 #define ENTITY(a,b) { a, b },
2763  struct entity_struct {
2764  int entity;
2765  char *entity_str;
2766  };
2767  const struct entity_struct entities[] = {
2768 #include "html-entities.def"
2769  { -1, "" } /* pivot */
2770  };
2771 #undef ENTITY
2772  int center; /* position in table that we are about to compare */
2773  int matchresult; /* result of match agains found entity name. indicates less, equal or greater */
2774 
2775  if (endfind == 0) {
2776  /* when calling this function we do not (nor even want to) know the
2777  * sizeof(entities). Hence this check. */
2778  endfind = (sizeof(entities) / sizeof(struct entity_struct)) - 1;
2779  }
2780  center = startfind + ((endfind - startfind) / 2);
2781  matchresult = octstr_str_compare(input, entities[center].entity_str);
2782  if (matchresult == 0) {
2783  return entities[center].entity;
2784  }
2785  if (endfind - startfind <= 1) {
2786  /* we are at the end of our results */
2787  return -1;
2788  }
2789  if (matchresult < 0) {
2790  /* keep searching in first part of the table */
2791  return octstr_find_entity(input, startfind, center);
2792  } else {
2793  /* keep searching in last part of the table */
2794  return octstr_find_entity(input, center, endfind);
2795  }
2796 }
static int octstr_find_entity(Octstr *input, int startfind, int endfind)
Definition: octstr.c:2760
int octstr_str_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:973

◆ octstr_format()

Octstr* octstr_format ( const char *  fmt,
  ... 
)

Definition at line 2464 of file octstr.c.

References octstr_format_valist.

Referenced by add_client_sdu_size(), add_crs(), add_msg_cb(), add_push_application_id(), add_push_flag(), add_via(), add_wsp_get(), at2_init_device(), at2_pdu_decode_report_sm(), at2_send_one_message(), at2_set_message_storage(), at2_write_line(), bb_print_status(), bearerbox_to_smpp(), boxc_route_msg_to_smsc(), boxc_status(), brunet_send_sms(), build_request(), challenge(), check_multipart(), check_x_wap_application_id_header(), clickatell_send_sms(), client_thread(), concat_handling_check_and_handle(), config_reload(), conn_pool_key(), convert_charset(), create_dlr_from_msg(), create_onetrans(), date_create_iso(), dlr_find(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), eat_string_parm(), emimsg_tostring(), error_converting(), error_requesting(), error_requesting_back(), fix_boundary_element(), flag_date_length(), for_each_file(), generic_send_sms(), get_msg_filename(), get_originator_type(), get_ton_npi_value(), handle_dlr(), handle_pdu(), handle_submit_sm(), headers_acceptable(), http_add_basic_auth(), http_header_add(), http_header_mark_transformation(), http_send_reply(), httpd_add_smsc(), httpd_loglevel(), httpd_remove_message(), httpd_remove_smsc(), httpd_restart_smsc(), httpd_serve(), httpd_stop_smsc(), init_configuration(), kannel_send_sms(), kill_kannel(), main(), make_multipart_value(), msg_to_emimsg(), msg_to_pdu(), obey_request(), open_send_connection(), pap_request_thread(), parse_appid_header(), parse_array(), parse_array_element(), parse_code(), parse_constant(), parse_data(), parse_data_element(), parse_document(), parse_fault(), parse_fault_element(), parse_inline_string(), parse_member(), parse_member_element(), parse_methodcall(), parse_methodcall_element(), parse_methodresponse(), parse_methodresponse_element(), parse_param(), parse_param_element(), parse_params(), parse_params_element(), parse_struct(), parse_struct_element(), parse_value(), parse_value_element(), parse_xml_tag(), port_key(), prepend_char(), proxy_add_authentication(), push_content_create(), radius_type_convert(), read_ppg_config(), route_incoming_to_boxc(), send_bad_message_response(), send_messages(), send_push_response(), send_smpp_thread(), set_bearer_defaults(), set_network_defaults(), set_time(), smpp_emu_writer(), smpp_pdu_init(), smpp_tlv_get_by_tag(), smsbox_req_sendota(), smsbox_sendota_post(), smsbox_xmlrpc_post(), smsc2_status(), smsc_at2_create(), smsc_cgw_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_fake_create(), smsc_http_create(), smsc_loopback_create(), smsc_oisd_create(), smsc_smpp_create(), smsc_soap_create(), soap_bouyg_validity_attribute(), soap_o2o_msgdata_attribute(), soap_o2o_validity30_attribute(), soap_rand_attribute(), soap_send(), soap_write_date(), store_file_init(), store_spool_save(), tell_fatal_error(), tell_ppg_name(), type_is(), unpack_datagram(), version_report_string(), wap_event_accept_or_create(), wap_push_ppg_pushuser_authenticate(), xidris_send_sms(), xml_error(), xmlrpc_call_print(), xmlrpc_doc_print(), xmlrpc_fault_print(), xmlrpc_print_array(), xmlrpc_print_struct(), xmlrpc_response_print(), xmlrpc_scalar_print(), and xmlrpc_value_print().

2465 {
2466  Octstr *os;
2467  va_list args;
2468 
2469  va_start(args, fmt);
2470  os = octstr_format_valist(fmt, args);
2471  va_end(args);
2472  return os;
2473 }
#define octstr_format_valist(fmt, args)
Definition: octstr.h:693
Definition: octstr.c:118

◆ octstr_format_append()

void octstr_format_append ( Octstr os,
const char *  fmt,
  ... 
)

Definition at line 2507 of file octstr.c.

References octstr_append(), octstr_destroy(), and octstr_format_valist.

Referenced by add_delimiter(), boxc_status(), brunet_send_sms(), build_request(), challenge(), clickatell_send_sms(), concat_handling_clear_old_parts(), create_onetrans(), fix_boundary_element(), get_pattern(), http_cgivar_dump_into(), http_send_reply(), httpd_serve(), kannel_send_sms(), main(), make_close_delimiter(), make_part_delimiter(), meta_data_pack(), ota_pack_message(), ota_pack_push_headers(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_appid_list(), pack_udhdata(), parse_inline_string(), prepend_catenation_udh(), randomize(), recover_absolute_uri(), send_bad_message_response(), send_packet(), send_push_response(), simple_binary_output(), smpp_pdu_dump_line(), smsbox_req_handle(), smsc2_status(), status_cb(), tell_fatal_error(), url_pattern(), urltrans_fill_escape_codes(), xidris_send_sms(), xmlrpc_call_print(), xmlrpc_print_array(), and xmlrpc_print_struct().

2508 {
2509  Octstr *temp;
2510  va_list args;
2511 
2512  va_start(args, fmt);
2513  temp = octstr_format_valist(fmt, args);
2514  va_end(args);
2515  octstr_append(os, temp);
2516  octstr_destroy(temp);
2517 }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
#define octstr_format_valist(fmt, args)
Definition: octstr.h:693
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118

◆ octstr_format_valist_real()

Octstr* octstr_format_valist_real ( const char *  fmt,
va_list  args 
)

Definition at line 2476 of file octstr.c.

References convert(), format_flags(), format_prec(), format_type(), format_width(), gw_assert(), octstr_append_data(), octstr_create, seems_valid, and VARGS.

2477 {
2478  Octstr *os;
2479  size_t n;
2480 
2481  os = octstr_create("");
2482 
2483  while (*fmt != '\0') {
2484  struct format format = { 0, };
2485 
2486  n = strcspn(fmt, "%");
2487  octstr_append_data(os, fmt, n);
2488  fmt += n;
2489 
2490  gw_assert(*fmt == '%' || *fmt == '\0');
2491  if (*fmt == '\0')
2492  continue;
2493 
2494  ++fmt;
2495  format_flags(&format, &fmt);
2496  format_width(&format, &fmt, VARGS(args));
2497  format_prec(&format, &fmt, VARGS(args));
2498  format_type(&format, &fmt);
2499  convert(os, &format, &fmt, VARGS(args));
2500  }
2501 
2502  seems_valid(os);
2503  return os;
2504 }
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1497
gw_assert(wtls_machine->packet_to_send !=NULL)
static void format_type(struct format *format, const char **fmt)
Definition: octstr.c:2282
static void format_flags(struct format *format, const char **fmt)
Definition: octstr.c:2215
static void format_width(struct format *format, const char **fmt, VALPARM(args))
Definition: octstr.c:2241
static void convert(Octstr *os, struct format *format, const char **fmt, VALPARM(args))
Definition: octstr.c:2300
#define octstr_create(cstr)
Definition: octstr.h:125
static void format_prec(struct format *format, const char **fmt, VALPARM(args))
Definition: octstr.c:2259
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
#define VARGS(x)
Definition: octstr.c:89

◆ octstr_get_bits()

long octstr_get_bits ( Octstr ostr,
long  bitpos,
int  numbits 
)

Definition at line 1803 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by deduce_tid(), get_tid(), unpack_ack(), unpack_tpis(), wtp_type(), and wtp_unpack_wdp_datagram().

1804 {
1805  long pos;
1806  long result;
1807  int mask;
1808  int shiftwidth;
1809 
1810  seems_valid(ostr);
1811  gw_assert(bitpos >= 0);
1812  gw_assert(numbits <= 32);
1813  gw_assert(numbits >= 0);
1814 
1815  pos = bitpos / 8;
1816  bitpos = bitpos % 8;
1817 
1818  /* This also takes care of the len == 0 case */
1819  if (pos >= ostr->len)
1820  return 0;
1821 
1822  mask = (1 << numbits) - 1;
1823 
1824  /* It's easy if the range fits in one octet */
1825  if (bitpos + numbits <= 8) {
1826  /* shiftwidth is the number of bits to ignore on the right.
1827  * bitpos 0 is the leftmost bit. */
1828  shiftwidth = 8 - (bitpos + numbits);
1829  return (ostr->data[pos] >> shiftwidth) & mask;
1830  }
1831 
1832  /* Otherwise... */
1833  result = 0;
1834  while (bitpos + numbits > 8) {
1835  result = (result << 8) | ostr->data[pos];
1836  numbits -= (8 - bitpos);
1837  bitpos = 0;
1838  pos++;
1839  if (pos >= ostr->len)
1840  return (result << numbits) & mask;
1841  }
1842 
1843  gw_assert(bitpos == 0);
1844  result <<= numbits;
1845  result |= ostr->data[pos] >> (8 - numbits);
1846  return result & mask;
1847 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_get_char()

int octstr_get_char ( const Octstr ostr,
long  pos 
)

Definition at line 406 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid.

Referenced by accept_escaped(), accept_safe(), add_crs(), at2_convertpdu(), at2_decode7bituncompressed(), at2_encode7bituncompressed(), at2_encode8bituncompressed(), at2_extract_line(), at2_format_address_field(), at2_pdu_decode(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_extract(), at2_scan_for_telnet_escapes(), calculate_checksum(), catenate_msg(), cfg_read(), charset_gsm_to_latin1(), charset_gsm_to_nrc_iso_21_german(), charset_gsm_to_utf8(), charset_gsm_truncate(), charset_latin1_to_gsm(), charset_nrc_iso_21_german_to_gsm(), charset_utf8_to_gsm(), check_multipart(), check_variable_syntax(), client_session(), concat_handling_check_and_handle(), concatenated_message(), conn_read_line(), convert_addr_from_pdu(), convert_cimd2_to_gsm(), convert_gsm_to_cimd2(), convert_html_entity(), create_peek_window(), data_sm_to_msg(), date_parse_http(), decode_bearer_indication(), decode_binary_data(), decode_integer(), drop_extension_headers(), eat_char(), eat_checksum(), emi2_handle_smscreq(), encode_binary_data(), escape_data(), escape_fragment(), expand_file(), extract_msgdata_part(), fix_boundary_element(), generic_receive_sms(), get_fields(), get_mime_boundary(), get_originator_type(), get_pattern(), get_start_param(), get_variable(), get_varint(), get_wtp_pdu_type(), gsm2number(), handle_connect_reply(), handle_get_reply(), handle_operation(), html_to_sms(), http_get_header_parameter(), http_header_get_content_type(), http_header_quoted_string_len(), http_header_split_auth_value(), http_header_split_value(), httpd_serve(), is_default_cap(), issafe(), kannel_receive_sms(), main(), mime_something_to_entity(), msg_to_emimsg(), msg_to_pdu(), octstr_convert_to_html_entities(), octstr_drop_leading_blanks(), octstr_drop_trailing_zeros(), octstr_dump_debug(), octstr_extract_uintvar(), octstr_is_all_hex(), octstr_isnum(), octstr_search_chars(), octstr_shrink_blanks(), octstr_strip_blanks(), octstr_strip_char(), octstr_strip_crlfs(), octstr_strip_nonalphanums(), oisd_accept_delivery_report_message(), oisd_accept_message(), oisd_expand_gsm7_to_bits(), oisd_request(), oisd_shrink_gsm7(), pack_7bit(), pack_cache_control(), pack_challenge(), pack_content_range(), pack_credentials(), pack_if_range(), pack_quoted_string(), pack_range(), pack_range_value(), pack_warning(), packet_check_header(), packet_check_parameter(), packet_extract(), packet_parse_header(), packet_set_checksum(), parse_address(), parse_constant(), parse_date(), parse_dom_fragment(), parse_escaped_value(), parse_field_name(), parse_field_value(), parse_get_char(), parse_global_phone_number(), parse_http_version(), parse_ipv4(), parse_ipv4_fragment(), parse_ipv6(), parse_ipv6_fragment(), parse_msg_to_rawmessage(), parse_peek_char(), parse_ppg_specifier(), parse_qualifier_keyword(), parse_qualifier_value(), parse_qvalue(), parse_st_octet_string(), parse_terminator(), parse_transport_padding(), parse_type(), parse_value(), parse_variable(), pass_extension_headers(), pass_field_name(), pass_field_value(), pattern_matches_ip(), pdu_to_msg(), qualifiers(), radius_type_convert(), read_mime_headers(), read_some_headers(), recover_absolute_uri(), remove_crs(), resend_sar_result(), sanitize_capabilities(), send_packet(), set_tid(), set_tid_new(), skip_html_tag(), smsbox_req_handle(), soap_fetch_xml_data(), soap_format_xml(), split_headers(), string_table_apply(), strip_keyword(), tokenize_date(), unescape_data(), unpack_datagram(), unpack_parameter(), unpack_warning_value(), urltrans_fill_escape_codes(), wait_for_ack(), wap_map_url(), wap_msg_send(), wsp_cap_get_method_mor(), wsp_cap_get_push_mor(), wsp_cap_pack_list(), wsp_cap_unpack_list(), wsp_pack_integer_string(), wsp_pack_retry_after(), wsp_pack_text(), wsp_pack_version_value(), wsp_strip_parameters(), and wtp_unpack_wdp_datagram().

407 {
408  seems_valid(ostr);
409  if (pos >= ostr->len || pos < 0)
410  return -1;
411  return ostr->data[pos];
412 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_get_cstr_real()

char* octstr_get_cstr_real ( const Octstr ostr,
const char *  file,
long  line,
const char *  func 
)

Definition at line 439 of file octstr.c.

References Octstr::data, file, Octstr::len, and seems_valid_real().

441 {
442  if (!ostr)
443  return "(null)";
444  seems_valid_real(ostr, file, line, func);
445  if (ostr->len == 0)
446  return "";
447  return ostr->data;
448 }
static void seems_valid_real(const Octstr *ostr, const char *filename, long lineno, const char *function)
Definition: octstr.c:2545
FILE * file
Definition: log.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_get_many_chars()

void octstr_get_many_chars ( char *  buf,
Octstr ostr,
long  pos,
long  len 
)

Definition at line 425 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by cimd_submit_msg(), compare_octstr_sequence(), conn_read_withlen(), convert_html_entity(), html_comment_begins(), packet_extract(), parse_integer(), parse_msg_to_rawmessage(), read_msg(), smpp_pdu_read_len(), wap_msg_recv(), and write_data().

426 {
427  gw_assert(buf != NULL);
428  seems_valid(ostr);
429 
430  if (pos >= ostr->len)
431  return;
432  if (pos + len > ostr->len)
433  len = ostr->len - pos;
434  if (len > 0)
435  memcpy(buf, ostr->data + pos, len);
436 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_grow()

static void octstr_grow ( Octstr ostr,
long  size 
)
static

Definition at line 181 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, seems_valid, size, and Octstr::size.

Referenced by octstr_binary_to_base64(), octstr_binary_to_hex(), octstr_insert(), octstr_insert_char(), octstr_insert_data(), octstr_set_bits(), and octstr_symbolize().

182 {
183  gw_assert(!ostr->immutable);
184  seems_valid(ostr);
185  gw_assert(size >= 0);
186 
187  size++; /* make room for the invisible terminating NUL */
188 
189  if (size > ostr->size) {
190  /* always reallocate in 1kB chunks */
191  size += 1024 - (size % 1024);
192  ostr->data = gw_realloc(ostr->data, size);
193  ostr->size = size;
194  }
195 }
int size
Definition: wsasm.c:84
gw_assert(wtls_machine->packet_to_send !=NULL)
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120

◆ octstr_hash_key()

unsigned long octstr_hash_key ( Octstr ostr)

Definition at line 2523 of file octstr.c.

References octstr_get_cstr, and octstr_len().

Referenced by dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), key_to_index(), and store_spool_save().

2524 {
2525  unsigned long b = 378551;
2526  unsigned long a = 63689;
2527  unsigned long hash = 0;
2528  unsigned long i = 0;
2529  unsigned long len = octstr_len(ostr);
2530  const char *str = octstr_get_cstr(ostr);
2531 
2532  for(i = 0; i < len; str++, i++) {
2533  hash = hash*a+(*str);
2534  a = a*b;
2535  }
2536 
2537  return (hash & 0x7FFFFFFF);
2538 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342

◆ octstr_hex_to_binary()

int octstr_hex_to_binary ( Octstr ostr)

Definition at line 494 of file octstr.c.

References Octstr::data, gw_assert(), gw_isxdigit(), Octstr::immutable, Octstr::len, octstr_check_range(), and seems_valid.

Referenced by accept_escaped(), at2_pdu_extract(), decode_binary_data(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), handle_operation(), main(), octstr_append_from_hex(), packet_get_hex_parm(), push_content_create(), and soap_msgdata_deps().

495 {
496  long len, i;
497  unsigned char *p;
498 
499  seems_valid(ostr);
500  gw_assert(!ostr->immutable);
501 
502  if (ostr->len == 0)
503  return 0;
504 
505  /* Check if it's in the right format */
506  if (!octstr_check_range(ostr, 0, ostr->len, gw_isxdigit))
507  return -1;
508 
509  len = ostr->len;
510 
511  /* Convert ascii data to binary values */
512  for (i = 0, p = ostr->data; i < len; i++, p++) {
513  if (*p >= '0' && *p <= '9')
514  *p -= '0';
515  else if (*p >= 'a' && *p <= 'f')
516  *p = *p - 'a' + 10;
517  else if (*p >= 'A' && *p <= 'F')
518  *p = *p - 'A' + 10;
519  else {
520  /* isxdigit checked the whole string, so we should
521  * not be able to get here. */
522  gw_assert(0);
523  *p = 0;
524  }
525  }
526 
527  /* De-hexing will compress data by factor of 2 */
528  len = ostr->len / 2;
529 
530  for (i = 0; i < len; i++) {
531  ostr->data[i] = ostr->data[i * 2] * 16 | ostr->data[i * 2 + 1];
532  }
533 
534  ostr->len = len;
535  ostr->data[len] = '\0';
536 
537  seems_valid(ostr);
538  return 0;
539 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int octstr_check_range(Octstr *ostr, long pos, long len, octstr_func_t filter)
Definition: octstr.c:814
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int gw_isxdigit(int c)
Definition: utils.c:994

◆ octstr_imm()

Octstr* octstr_imm ( const char *  cstr)

Definition at line 283 of file octstr.c.

References CSTR_TO_LONG, Octstr::data, gw_assert(), Octstr::immutable, immutables, immutables_init, immutables_mutex, Octstr::len, MAX_IMMUTABLES, mutex_lock, mutex_unlock, panic, seems_valid, and Octstr::size.

Referenced by add_connection_header(), add_content_transfer_encoding_type(), add_content_type(), add_delimiter(), add_group(), add_push_application_id(), add_via(), append_crlf(), at2_check_sms_memory(), at2_detect_modem_type(), at2_extract_line(), at2_init_device(), at2_pdu_extract(), at2_read_modems(), at2_send_one_message(), at2_wait_modem_command(), authorise_user(), bb_alog_sms(), bb_reload_smsc_groups(), bearerbox_to_smpp(), bearerbox_to_smsbox(), bearerbox_to_sql(), brunet_parse_body(), brunet_parse_reply(), brunet_send_sms(), build_request(), build_response(), cfg_get_bool(), cfg_read(), cgw_decode_msg(), cgw_encode_msg(), cgw_handle_op(), cgw_read_op(), cgwop_create(), cgwop_tostr(), challenge(), charset_to_utf8(), check_config(), check_control_content_type_header(), check_control_headers(), check_login(), cid_matches(), clickatell_parse_body(), clickatell_parse_reply(), clickatell_send_sms(), client_is_persistent(), client_thread(), cmp_conn_grp_id(), concat_msgids(), config_reload(), conn_pool_key(), connect_denied(), construct_linear_table(), construct_numbered_table(), content_transformable(), convert_addr_from_pdu(), core_is_allowed_in_group(), create_dlr_from_msg(), create_onetrans(), create_oneuser(), describe_code(), dlr_db_fields_create(), dlr_find(), dlr_init(), dlr_init_spool(), drop_extension_headers(), drop_optional_header(), escape_fragment(), expand_file(), find_charset_encoding(), fix_boundary_element(), generic_get_field_map(), generic_init(), generic_receive_sms(), get_data(), get_mime_boundary(), get_start_param(), get_x_kannel_from_headers(), handle_dlr(), handle_pdu(), handle_transaction(), http_add_basic_auth(), http_header_get_content_type(), http_header_pack(), httpadmin_start(), httpd_serve(), init_batch(), init_bearerbox(), init_configuration(), init_reroute(), init_smppbox(), init_smsbox(), init_smsbox_routes(), init_smsc_routes(), init_sqlbox(), init_wapbox(), ip_allowed_by_ppg(), ip_allowed_by_user(), kannel_parse_reply(), kannel_receive_sms(), kannel_send_sms(), main(), make_multipart_value(), make_url(), mime_decompile(), mime_entity_dump_real(), mime_entity_to_octstr(), mime_multipart_start_elem(), mime_something_to_entity(), msg_to_bb(), msg_to_cgwop(), msg_to_pdu(), name(), normalize_charset(), obey_request(), obey_request_thread(), octstr_binary_to_base64(), octstr_recode(), open_send_connection(), ota_pack_message(), ota_pack_push_headers(), ota_pack_udh(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_appid_list(), pack_cache_control(), pack_challenge(), pack_content_range(), pack_credentials(), pack_pragma(), pack_range(), packet_encode_message(), pap_convert_content(), pap_get_content(), pap_request_thread(), parse2trans(), parse_address_value(), parse_appid_header(), parse_array_element(), parse_attr_value(), parse_attribute(), parse_bad_message_response_value(), parse_bearer(), parse_client_specifier(), parse_data_element(), parse_date(), parse_delivery_method(), parse_document(), parse_element(), parse_entities(), parse_fault_element(), parse_http_version(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_network(), parse_ota_syncsettings(), parse_pap_value(), parse_param_element(), parse_params_element(), parse_priority(), parse_progress_note_value(), parse_push_message_value(), parse_push_response_value(), parse_quality_of_service_value(), parse_requirement(), parse_response_result_value(), parse_state(), parse_struct_element(), parse_url(), parse_url_value(), parse_value_element(), pass_data_headers(), pass_extension_headers(), pattern_list_matches_ip(), prefix_allowed(), prepend_crlf(), proxy_add_authentication(), push_content_create(), qualifiers(), radius_acct_init(), read_ppg_config(), read_test_ppg_config(), reply(), response(), return_reply(), select_bearer_network(), server(), set_addr_tuple(), set_any_value(), set_attribute_value(), set_dlr_mask(), set_dlr_url(), set_smsbox_id(), set_smsc_id(), skip_html_comment(), smpp_pdu_init(), smpp_tlv_get_by_name(), smpp_tlv_get_by_tag(), smppbox_is_allowed_in_group(), sms_to_client(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_start(), smsbox_to_bearerbox(), smsbox_xmlrpc_post(), smsc2_add_smsc(), smsc2_graceful_restart(), smsc2_restart_smsc(), smsc2_start(), smsc2_status(), smsc_at2_create(), smsc_cgw_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_fake_create(), smsc_http_create(), smsc_oisd_create(), smsc_open(), smsc_smpp_create(), smsc_soap_create(), smscconn_create(), smscconn_instances(), soap_create_map(), soap_fetch_xml_data(), soap_map_xml_data(), soap_msgdata_deps(), soap_parse_dlr(), soap_read_response(), soap_release_dependences(), soap_server(), sql_list(), sql_single(), sqlbox_is_allowed_in_group(), start_fetch(), start_request(), status_cb(), test_header_combine(), transfer_encode(), type_is(), udp_start(), unpack_challenge(), unpack_optional_q_value(), unpack_parameter(), update_table(), update_tables(), url_result_thread(), urltrans_add_cfg(), urltrans_fill_escape_codes(), uses_gsm_msisdn_address(), uses_ipv4_address(), uses_ipv6_address(), wap_event_accept_or_create(), wap_map_url_config(), wap_map_url_config_device_home(), wapbox_start(), wildcarded_ip_found(), wina_bearer_identifier(), wml_charsets(), wsp_encoding_string_to_version(), xidris_parse_reply(), xidris_receive_sms(), xidris_send_sms(), xml_error(), and xmlrpc_fault_print().

284 {
285  Octstr *os;
286  long i, index;
287  unsigned char *data;
288 
290  gw_assert(cstr != NULL);
291 
292  index = CSTR_TO_LONG(cstr) % MAX_IMMUTABLES;
293  data = (unsigned char *) cstr;
294 
296  i = index;
297  for (; ; ) {
298  if (immutables[i] == NULL || immutables[i]->data == data)
299  break;
300  i = (i + 1) % MAX_IMMUTABLES;
301  if (i == index)
302  panic(0, "Too many immutable strings.");
303  }
304  os = immutables[i];
305  if (os == NULL) {
306  /*
307  * Can't use octstr_create() because it copies the string,
308  * which would break our hashing.
309  */
310  os = gw_malloc(sizeof(*os));
311  os->data = data;
312  os->len = strlen(data);
313  os->size = os->len + 1;
314  os->immutable = 1;
315  immutables[i] = os;
316  seems_valid(os);
317  }
319 
320  return os;
321 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define mutex_unlock(m)
Definition: thread.h:136
#define MAX_IMMUTABLES
Definition: octstr.c:131
static Mutex immutables_mutex
Definition: octstr.c:134
static Octstr * immutables[MAX_IMMUTABLES]
Definition: octstr.c:133
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
static int immutables_init
Definition: octstr.c:135
#define CSTR_TO_LONG(ptr)
Definition: octstr.c:145
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
#define panic
Definition: log.h:87
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
#define mutex_lock(m)
Definition: thread.h:130

◆ octstr_init()

void octstr_init ( void  )

Definition at line 218 of file octstr.c.

References immutables_init, immutables_mutex, mutex_init_static, and urlcode_init().

Referenced by gwlib_init().

219 {
220  urlcode_init();
222  immutables_init = 1;
223 }
static Mutex immutables_mutex
Definition: octstr.c:134
#define mutex_init_static(mutex)
Definition: thread.h:115
static int immutables_init
Definition: octstr.c:135
static void urlcode_init(void)
Definition: octstr.c:206

◆ octstr_insert()

void octstr_insert ( Octstr ostr1,
const Octstr ostr2,
long  pos 
)

Definition at line 1303 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, octstr_grow(), and seems_valid.

Referenced by accept_escaped(), add_crs(), append_string(), cgw_decode_msg(), cgw_encode_msg(), decode_binary_data(), escape_data(), flag_date_length(), http_add_basic_auth(), init_smsbox_routes(), init_smsc_routes(), main(), msg_to_pdu(), octstr_append(), octstr_binary_to_base64(), octstr_replace(), octstr_replace_first(), output_octet_string(), output_st_octet_string(), pack_challenge(), packet_add_parm(), parse_entities(), parse_inline_string(), parse_st_octet_string(), prefix_allowed(), prepend_char(), prepend_crlf(), proxy_add_authentication(), radius_authenticate_pdu(), radius_pdu_pack(), recover_absolute_uri(), replace_octstr_char(), smasi_pdu_pack(), smpp_pdu_pack(), sms_split(), string_table_apply(), string_table_output(), unpack_parameter(), wml_binary_output(), and xmlrpc_doc_print().

1304 {
1305  if (ostr2 == NULL)
1306  return;
1307 
1308  seems_valid(ostr1);
1309  seems_valid(ostr2);
1310  gw_assert(pos <= ostr1->len);
1311  gw_assert(!ostr1->immutable);
1312 
1313  if (ostr2->len == 0)
1314  return;
1315 
1316  octstr_grow(ostr1, ostr1->len + ostr2->len);
1317  memmove(ostr1->data + pos + ostr2->len, ostr1->data + pos,
1318  ostr1->len - pos);
1319  memcpy(ostr1->data + pos, ostr2->data, ostr2->len);
1320  ostr1->len += ostr2->len;
1321  ostr1->data[ostr1->len] = '\0';
1322 
1323  seems_valid(ostr1);
1324 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_insert_char()

void octstr_insert_char ( Octstr ostr,
long  pos,
const char  c 
)

Definition at line 1481 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, octstr_grow(), and seems_valid.

Referenced by convert_addr_from_pdu(), init_smsbox_routes(), init_smsc_routes(), and octstr_convert_from_html_entities().

1482 {
1483  seems_valid(ostr);
1484  gw_assert(!ostr->immutable);
1485  gw_assert(pos <= ostr->len);
1486 
1487  octstr_grow(ostr, ostr->len + 1);
1488  if (ostr->len > pos)
1489  memmove(ostr->data + pos + 1, ostr->data + pos, ostr->len - pos);
1490  memcpy(ostr->data + pos, &c, 1);
1491  ostr->len += 1;
1492  ostr->data[ostr->len] = '\0';
1493 
1494  seems_valid(ostr);
1495 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_insert_data()

void octstr_insert_data ( Octstr ostr,
long  pos,
const char *  data,
long  len 
)

Definition at line 1461 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, octstr_grow(), and seems_valid.

Referenced by bb_smscconn_send_failed(), bb_smscconn_sent(), cgw_encode_msg(), charset_latin1_to_gsm(), compare_octstr_sequence(), convert(), convert_gsm_to_cimd2(), http_header_split_auth_value(), line_append_hex_IA5(), msg_to_emimsg(), normalize_number(), octstr_append_char(), octstr_append_cstr(), octstr_append_data(), octstr_read_file(), octstr_symbolize(), pack_into_push_datagram(), pack_into_result_datagram(), packet_add_parm(), packet_set_checksum(), sema_encode_msg(), sema_msg_session_mt(), unescape_data(), unpack_credentials(), unpack_warning_value(), write_msg(), and wsp_pack_long_integer().

1462 {
1463  seems_valid(ostr);
1464  gw_assert(!ostr->immutable);
1465  gw_assert(pos <= ostr->len);
1466 
1467  if (len == 0)
1468  return;
1469 
1470  octstr_grow(ostr, ostr->len + len);
1471  if (ostr->len > pos) { /* only if neccessary*/
1472  memmove(ostr->data + pos + len, ostr->data + pos, ostr->len - pos);
1473  }
1474  memcpy(ostr->data + pos, data, len);
1475  ostr->len += len;
1476  ostr->data[ostr->len] = '\0';
1477 
1478  seems_valid(ostr);
1479 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_is_all_hex()

int octstr_is_all_hex ( Octstr os)

Definition at line 2717 of file octstr.c.

References gw_isxdigit(), octstr_get_char(), octstr_len(), and seems_valid.

Referenced by main(), and push_content_create().

2718 {
2719  long len, i;
2720  int ch;
2721 
2722  seems_valid(os);
2723  len = octstr_len(os);
2724  for (i = 0; i < len; ++i) {
2725  ch = octstr_get_char(os, i);
2726  if (!gw_isxdigit(ch))
2727  return 0;
2728  }
2729 
2730  return 1;
2731 }
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
int gw_isxdigit(int c)
Definition: utils.c:994
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ octstr_isnum()

int octstr_isnum ( Octstr ostr1)

Definition at line 2634 of file octstr.c.

References octstr_get_char(), octstr_len(), seems_valid, and start.

2635 {
2636  int start = 0;
2637  char c;
2638 
2639  seems_valid(ostr1);
2640  while (start < octstr_len(ostr1)) {
2641  c = octstr_get_char(ostr1, start);
2642  if (!isdigit(c) && (c!='+'))
2643  return 0;
2644  start++;
2645  }
2646  return 1;
2647 }
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
static int start

◆ octstr_item_case_match()

int octstr_item_case_match ( void *  item,
void *  pattern 
)

Definition at line 1667 of file octstr.c.

References octstr_case_compare().

Referenced by client_is_persistent().

1668 {
1669  return octstr_case_compare(item, pattern) == 0;
1670 }
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:903

◆ octstr_item_match()

int octstr_item_match ( void *  item,
void *  pattern 
)

Definition at line 1661 of file octstr.c.

References octstr_compare().

Referenced by at2_detect_modem_type(), at2_init_device(), cfg_read(), check_allowed_translation(), smsbox_req_handle(), and smscconn_usable().

1662 {
1663  return octstr_compare(item, pattern) == 0;
1664 }
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ octstr_len()

long octstr_len ( const Octstr ostr)

Definition at line 342 of file octstr.c.

References Octstr::len, and seems_valid.

Referenced by add_crs(), add_msisdn(), add_network_info(), add_wsp_get(), append_string(), at2_check_sms_memory(), at2_convertpdu(), at2_decode7bituncompressed(), at2_detect_modem_type(), at2_encode7bituncompressed(), at2_encode8bituncompressed(), at2_extract_line(), at2_format_address_field(), at2_init_device(), at2_login_device(), at2_pdu_decode_deliver_sm(), at2_pdu_encode(), at2_pdu_extract(), at2_read_modems(), at2_scan_for_telnet_escapes(), at2_send_one_message(), at2_write_line(), bb_alog_sms(), bearerbox_to_smpp(), begin_sar_result(), brunet_parse_body(), brunet_send_sms(), calculate_checksum(), catenate_msg(), cfg_read(), cgw_encode_msg(), cgw_read_op(), charset_convert(), charset_from_utf8(), charset_gsm_to_latin1(), charset_gsm_to_nrc_iso_21_german(), charset_gsm_to_utf8(), charset_gsm_truncate(), charset_latin1_to_gsm(), charset_nrc_iso_21_german_to_gsm(), charset_processing(), charset_to_utf8(), charset_utf8_to_gsm(), check_data_content_type_header(), check_data_x_wap_application_id_header(), check_multipart(), check_variable_syntax(), cid_matches(), cimd2_accept_message(), cimd_submit_msg(), clickatell_receive_sms(), clickatell_send_sms(), client_session(), compare_octstr_sequence(), concat_handling_check_and_handle(), conn_read_line(), conn_read_packet(), conn_write_withlen(), convert(), convert_addr_from_pdu(), convert_cimd2_to_gsm(), convert_content(), convert_gsm_to_cimd2(), convert_wmlscript_to_wmlscriptc(), copy_until_assign(), count_occurences(), data_sm_to_msg(), date_parse_http(), date_parse_iso(), decode_binary_data(), decode_integer(), deconvert_content(), deliver_after_test_cleared(), deliver_before_test_cleared(), dlr_add(), dlr_find(), dlr_mem_entry_match(), dlr_spool_add(), eat_checksum(), eat_int_parm(), eat_string_parm(), emi2_handle_smscreq(), emimsg_tostring(), encode_binary_data(), error_from_network_error_code(), escape_data(), escape_fragment(), expand_file(), extract_msgdata_part(), extract_msgdata_part_by_coding(), fields_to_dcs(), fill_message(), find_charset_encoding(), find_translation(), fix_boundary_element(), flag_date_length(), generic_receive_sms(), get_fields(), get_header_value(), get_mime_boundary(), get_msg_filename(), get_pattern(), get_start_param(), get_variable(), get_x_kannel_from_xml(), gsm2number(), handle_dlr(), handle_operation(), handle_pdu(), html_to_sms(), http_accept_request(), http_get_header_parameter(), http_header_add_element(), http_header_find_first_real(), http_header_get(), http_header_get_content_type(), http_header_mark_transformation(), http_header_pack(), http_header_quoted_string_len(), http_header_split_auth_value(), http_header_split_value(), http_header_value(), http_send_reply(), http_use_proxy(), httpd_remove_message(), httpd_serve(), init_bearerbox(), init_smsbox_routes(), init_smsc_routes(), is_allowed_ip(), is_default_cap(), is_token(), kannel_receive_sms(), kannel_send_sms(), line_append_hex_IA5(), main(), main_loop(), make_emi31(), md5(), meta_data_merge(), meta_data_pack(), meta_data_unpack(), mime_decompile(), mime_entity_dump_real(), mime_parse(), mime_something_to_entity(), msg_to_cgwop(), msg_to_emimsg(), msg_to_pdu(), normalize_charset(), normalize_number(), numhash_get_key(), obey_request(), obey_request_thread(), octstr_convert_to_html_entities(), octstr_delete_matching(), octstr_drop_trailing_zeros(), octstr_dump_debug(), octstr_hash_key(), octstr_is_all_hex(), octstr_isnum(), octstr_read_file(), octstr_replace(), octstr_replace_first(), octstr_search_chars(), octstr_shrink_blanks(), octstr_split(), octstr_strip_blanks(), octstr_strip_char(), octstr_strip_crlfs(), octstr_strip_nonalphanums(), ois_adjust_sm_text(), ois_append_msisdn(), ois_append_sm_text(), ois_append_submission_options(), oisd_accept_message(), oisd_expand_gsm7(), oisd_expand_gsm7_to_bits(), oisd_send_delivery_request(), oisd_shrink_gsm7(), open_send_connection(), ota_compile(), ota_pack_push_headers(), our_hash_func(), output_octet_string(), output_st_octet_string(), pack_7bit(), pack_cache_control(), pack_challenge(), pack_content_range(), pack_credentials(), pack_known_header(), pack_md5(), pack_parameter(), pack_quoted_string(), pack_range(), pack_server_address(), pack_tpis(), pack_warning(), packet_add_address_parm(), packet_add_parm(), packet_check(), packet_check_header(), packet_encode_message(), packet_extract(), packet_set_checksum(), packet_set_data_size(), pap_compile(), pap_request_thread(), parm_parse(), parm_valid_address(), parse_address(), parse_appid_header(), parse_array_element(), parse_attr_value(), parse_attribute(), parse_cgivars(), parse_charset(), parse_close_delimiter(), parse_constant(), parse_context_create(), parse_data(), parse_data_element(), parse_document(), parse_element(), parse_epilogue(), parse_fault_element(), parse_field_name(), parse_field_value(), parse_get_seperated_block(), parse_http_version(), parse_integer(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_msg_to_rawmessage(), parse_ota_syncsettings(), parse_param_element(), parse_params_element(), parse_st_octet_string(), parse_struct_element(), parse_tail(), parse_text(), parse_url(), parse_url_value(), parse_value(), parse_value_element(), parse_variable(), parse_xml_tag(), pass_data_headers(), pass_field_name(), pass_field_value(), pass_optional_header(), pattern_matches_ip(), pdu_to_msg(), prepend_catenation_udh(), radius_authenticate_pdu(), radius_pdu_pack(), radius_pdu_unpack(), read_line(), read_mime_headers(), read_msg(), read_some_headers(), receive_push_reply(), remove_crs(), remove_prefix(), replace_octstr_char(), response(), return_reply(), route_incoming_to_boxc(), run_batch(), sanitize_capabilities(), sema_encode_msg(), sema_msg_session_mt(), sema_receive_msg(), sema_submit_msg(), send_bad_message_response(), send_file(), send_message(), send_packet(), send_post(), send_request(), set_charset(), set_dlr_mask(), set_zero(), si_compile(), simple_binary_output(), skip_html_comment(), skip_html_tag(), skip_tail(), sl_compile(), smpp_pdu_pack(), smpp_pdu_unpack(), sms_charset_processing(), sms_msgdata_len(), sms_split(), sms_to_client(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_req_sendsms(), smsbox_sendota_post(), smsbox_sendsms_post(), smsc_at2_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_smpp_create(), soap_fetch_xml_data(), soap_format_xml(), soap_o2o_msgdata_attribute(), soap_read_date(), split_headers(), sql_list(), sql_single(), start_fetch(), start_push(), store_file_init(), store_file_load(), store_spool_save(), string_table_add(), string_table_add_many(), string_table_apply(), string_table_collect_strings(), string_table_output(), strip_prefix_and_suffix(), timestamp_to_minutes(), tokenize_date(), truncated_datagram(), udp_get_ip(), udp_get_port(), udp_sendto(), unescape_data(), unlocked_inbuf_len(), unlocked_outbuf_len(), unlocked_write(), unpack_broken_parameters(), unpack_credentials(), unpack_datagram(), unpack_new_headers(), unpack_parameter(), unpack_warning_value(), url_result_thread(), urltrans_fill_escape_codes(), urltrans_get_pattern(), wap_map_url(), wap_msg_recv(), wml_binary_output(), wml_compile(), write_data(), write_msg(), wsp_cap_pack_list(), wsp_cap_unpack_list(), wsp_headers_unpack(), wsp_pack_integer_string(), wsp_pack_list(), wsp_pack_long_integer(), wsp_pack_value(), wsp_pack_version_value(), wsp_strip_parameters(), wsp_unpack_well_known_field(), wtp_unpack_wdp_datagram(), xidris_send_sms(), and xmlrpc_doc_parse().

343 {
344  if (ostr == NULL)
345  return 0;
346  seems_valid(ostr);
347  return ostr->len;
348 }
#define seems_valid(ostr)
Definition: octstr.c:169
long len
Definition: octstr.c:121

◆ octstr_ncompare()

int octstr_ncompare ( const Octstr ostr1,
const Octstr ostr2,
long  n 
)

Definition at line 952 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid.

Referenced by compare_octstr_sequence(), get_msg_filename(), http_header_get_content_type(), kannel_parse_reply(), pack_content_range(), pack_range(), packet_encode_message(), parse_attribute(), parse_close_delimiter(), parse_http_version(), remove_prefix(), and response().

953 {
954  long len;
955 
956  seems_valid(ostr1);
957  seems_valid(ostr2);
958 
959  if ((ostr1->len < ostr2->len) && (ostr1->len < n))
960  len = ostr1->len;
961  else if ((ostr2->len < ostr1->len) && (ostr2->len < n))
962  len = ostr2->len;
963  else
964  len = n;
965 
966  if (len == 0)
967  return 0;
968 
969  return memcmp(ostr1->data, ostr2->data, len);
970 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_parse_double()

long octstr_parse_double ( double *  nump,
Octstr ostr,
long  pos 
)

Definition at line 782 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, number, and seems_valid.

Referenced by parse_value_element(), and smscconn_create().

783 {
784  /* strtod wants a char *, and we have to compare the result to
785  * an unsigned char *. The easiest way to avoid warnings without
786  * introducing typecasts is to use two variables. */
787  char *endptr;
788  unsigned char *endpos;
789  double number;
790 
791  seems_valid(ostr);
792  gw_assert(nump != NULL);
793 
794  if (pos >= ostr->len) {
795  errno = EINVAL;
796  return -1;
797  }
798 
799  errno = 0;
800  number = strtod(ostr->data + pos, &endptr);
801  endpos = endptr;
802  if (errno == ERANGE)
803  return -1;
804  if (endpos == ostr->data + pos) {
805  errno = EINVAL;
806  return -1;
807  }
808 
809  *nump = number;
810  return endpos - ostr->data;
811 }
int number
Definition: smsc_cimd2.c:213
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_parse_long()

long octstr_parse_long ( long *  nump,
Octstr ostr,
long  pos,
int  base 
)

Definition at line 749 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, number, and seems_valid.

Referenced by at2_check_sms_memory(), at2_pdu_extract(), at2_read_pending_incoming_messages(), at2_wait_modem_command(), cfg_get_integer(), cgw_handle_op(), client_read_status(), convert_html_entity(), date_item_compare(), date_parse_http(), deduce_body_state(), eat_number(), eq_round_trip_time(), get_fields(), handle_operation(), init_bearerbox(), init_smsbox(), init_wapbox(), main(), pack_content_range(), pack_parameter(), pack_range_value(), pack_warning(), packet_check_parameter(), packet_get_int_parm(), packet_get_parm(), packet_parse_header(), parse_code(), parse_date(), parse_url(), parse_value_element(), pdu_to_msg(), read_chunked_body_len(), remove_long(), set_dlr_mask(), smsc_open(), soap_read_date(), wap_push_ppg_pushuser_authenticate(), and wsp_pack_version_value().

750 {
751  /* strtol wants a char *, and we have to compare the result to
752  * an unsigned char *. The easiest way to avoid warnings without
753  * introducing typecasts is to use two variables. */
754  char *endptr;
755  unsigned char *endpos;
756  long number;
757 
758  seems_valid(ostr);
759  gw_assert(nump != NULL);
760  gw_assert(base == 0 || (base >= 2 && base <= 36));
761 
762  if (pos >= ostr->len) {
763  errno = EINVAL;
764  return -1;
765  }
766 
767  errno = 0;
768  number = strtol(ostr->data + pos, &endptr, base);
769  endpos = endptr;
770  if (errno == ERANGE)
771  return -1;
772  if (endpos == ostr->data + pos) {
773  errno = EINVAL;
774  return -1;
775  }
776 
777  *nump = number;
778  return endpos - ostr->data;
779 }
int number
Definition: smsc_cimd2.c:213
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_pretty_print()

int octstr_pretty_print ( FILE *  f,
Octstr ostr 
)

Definition at line 1206 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by main().

1207 {
1208  unsigned char *p;
1209  long i;
1210 
1211  gw_assert(f != NULL);
1212  seems_valid(ostr);
1213 
1214  p = ostr->data;
1215  for (i = 0; i < ostr->len; ++i, ++p) {
1216  if (isprint(*p))
1217  fprintf(f, "%c", *p);
1218  else
1219  fprintf(f, "\\x%02x", *p);
1220  }
1221  if (ferror(f))
1222  return -1;
1223  return 0;
1224 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_print()

int octstr_print ( FILE *  f,
Octstr ostr 
)

Definition at line 1191 of file octstr.c.

References Octstr::data, error(), gw_assert(), Octstr::len, and seems_valid.

Referenced by client_thread(), main(), and write_msg().

1192 {
1193  gw_assert(f != NULL);
1194  seems_valid(ostr);
1195 
1196  if (ostr->len == 0)
1197  return 0;
1198  if (fwrite(ostr->data, ostr->len, 1, f) != 1) {
1199  error(errno, "Couldn't write all of octet string to file.");
1200  return -1;
1201  }
1202  return 0;
1203 }
void error(int err, const char *fmt,...)
Definition: log.c:648
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_read_file()

Octstr* octstr_read_file ( const char *  filename)

Definition at line 1548 of file octstr.c.

References error(), filename, gw_assert(), octstr_create, octstr_destroy(), octstr_insert_data(), and octstr_len().

Referenced by check_reversible(), dispatch(), expand_file(), get_msg_surrogate(), init_batch(), main(), obey_request(), post_content_create(), push_content_create(), send_file(), smsc_soap_create(), status_cb(), and store_file_load().

1549 {
1550  FILE *f;
1551  Octstr *os;
1552  char buf[4096];
1553  long n;
1554 
1555  gw_assert(filename != NULL);
1556 
1557  f = fopen(filename, "r");
1558  if (f == NULL) {
1559  error(errno, "fopen failed: couldn't open `%s'", filename);
1560  return NULL;
1561  }
1562 
1563  os = octstr_create("");
1564  if (os == NULL)
1565  goto error;
1566 
1567  while ((n = fread(buf, 1, sizeof(buf), f)) > 0)
1568  octstr_insert_data(os, octstr_len(os), buf, n);
1569 
1570  (void) fclose(f);
1571  return os;
1572 
1573 error:
1574  (void) fclose(f);
1575  octstr_destroy(os);
1576  return NULL;
1577 }
void error(int err, const char *fmt,...)
Definition: log.c:648
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
char filename[FILENAME_MAX+1]
Definition: log.c:171
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118

◆ octstr_read_pipe()

Octstr* octstr_read_pipe ( FILE *  f)

Definition at line 1580 of file octstr.c.

References error(), gw_assert(), octstr_append_data(), octstr_create, and octstr_destroy().

Referenced by obey_request().

1581 {
1582  Octstr *os;
1583  char buf[4096];
1584 
1585  gw_assert(f != NULL);
1586 
1587  os = octstr_create("");
1588  if (os == NULL)
1589  goto error;
1590 
1591  while (fgets(buf, sizeof(buf), f) != NULL)
1592  octstr_append_data(os, buf, strlen(buf));
1593 
1594  return os;
1595 
1596 error:
1597  octstr_destroy(os);
1598  return NULL;
1599 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1497
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118

◆ octstr_recode()

int octstr_recode ( Octstr tocode,
Octstr fromcode,
Octstr orig 
)

Definition at line 2576 of file octstr.c.

References charset_from_utf8(), charset_to_utf8(), octstr_append(), octstr_case_compare(), octstr_destroy(), octstr_duplicate, octstr_imm(), and octstr_truncate().

Referenced by bearerbox_to_smpp(), and obey_request_thread().

2577 {
2578  Octstr *octstr_utf8 = NULL;
2579  Octstr *octstr_final = NULL;
2580  int resultcode = 0;
2581 
2582  if (octstr_case_compare(tocode, fromcode) == 0) {
2583  goto cleanup_and_exit;
2584  }
2585 
2586  if ((octstr_case_compare(fromcode, octstr_imm ("UTF-8")) != 0) &&
2587  (octstr_case_compare(fromcode, octstr_imm ("UTF8")) != 0)) {
2588  if (charset_to_utf8(orig, &octstr_utf8, fromcode) < 0) {
2589  resultcode = -1;
2590  goto cleanup_and_exit;
2591  }
2592  } else {
2593  octstr_utf8 = octstr_duplicate(orig);
2594  }
2595 
2596  if ((octstr_case_compare(tocode, octstr_imm ("UTF-8")) != 0) &&
2597  (octstr_case_compare(tocode, octstr_imm ("UTF8")) != 0)) {
2598  if (charset_from_utf8(octstr_utf8, &octstr_final, tocode) < 0) {
2599  resultcode = -1;
2600  goto cleanup_and_exit;
2601  }
2602  } else {
2603  octstr_final = octstr_duplicate(octstr_utf8);
2604  }
2605 
2606  octstr_truncate(orig, 0);
2607  octstr_append(orig, octstr_final);
2608 
2609  cleanup_and_exit:
2610  octstr_destroy (octstr_utf8);
2611  octstr_destroy (octstr_final);
2612 
2613  return resultcode;
2614 }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
int charset_to_utf8(Octstr *from, Octstr **to, Octstr *charset_from)
Definition: charset.c:526
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
#define octstr_duplicate(ostr)
Definition: octstr.h:187
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:903
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
int charset_from_utf8(Octstr *utf8, Octstr **to, Octstr *charset_to)
Definition: charset.c:558
void octstr_truncate(Octstr *ostr, int new_len)
Definition: octstr.c:1327

◆ octstr_replace()

void octstr_replace ( Octstr haystack,
Octstr needle,
Octstr repl 
)

Definition at line 2649 of file octstr.c.

References octstr_delete(), octstr_insert(), octstr_len(), and octstr_search().

Referenced by brunet_send_sms(), clickatell_send_sms(), main(), msg_to_pdu(), and xml_error().

2650 {
2651  int p = 0;
2652  long len, repl_len;
2653 
2654  len = octstr_len(needle);
2655  repl_len = octstr_len(repl);
2656 
2657  while ((p = octstr_search(haystack, needle, p)) != -1) {
2658  octstr_delete(haystack, p, len);
2659  octstr_insert(haystack, repl, p);
2660  p += repl_len;
2661  }
2662 }
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1303
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342

◆ octstr_replace_first()

void octstr_replace_first ( Octstr haystack,
Octstr needle,
Octstr repl 
)

Definition at line 2664 of file octstr.c.

References octstr_delete(), octstr_insert(), octstr_len(), and octstr_search().

2665 {
2666  int p = 0;
2667  long len, repl_len;
2668 
2669  len = octstr_len(needle);
2670  repl_len = octstr_len(repl);
2671 
2672  p = octstr_search(haystack, needle, p);
2673  if (p != -1) {
2674  octstr_delete(haystack, p, len);
2675  octstr_insert(haystack, repl, p);
2676  }
2677 }
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1303
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342

◆ octstr_rsearch_char()

long octstr_rsearch_char ( const Octstr ostr,
int  ch,
long  pos 
)

Definition at line 1031 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

1032 {
1033  long i;
1034 
1035  seems_valid(ostr);
1036  gw_assert(ch >= 0);
1037  gw_assert(ch <= UCHAR_MAX);
1038  gw_assert(pos >= 0);
1039 
1040  if (pos >= ostr->len)
1041  return -1;
1042 
1043  for (i = pos; i >= 0; i--) {
1044  if (ostr->data[i] == ch)
1045  return i;
1046  }
1047 
1048  return -1;
1049 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_search()

long octstr_search ( const Octstr haystack,
const Octstr needle,
long  pos 
)

Definition at line 1070 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, octstr_search_char(), and seems_valid.

Referenced by at2_check_sms_memory(), at2_detect_modem_type(), at2_extract_line(), at2_pdu_extract(), at2_wait_modem_command(), bearerbox_to_smpp(), brunet_send_sms(), cfg_read(), cgw_decode_msg(), check_control_content_type_header(), check_data_content_type_header(), check_data_x_wap_application_id_header(), convert_addr_from_pdu(), count_occurences(), dlr_mem_entry_match(), drop_optional_header(), eat_string_parm(), find_charset_encoding(), get_msg_filename(), handle_dlr(), hash_cmp(), httpd_serve(), octstr_delete_matching(), octstr_replace(), octstr_replace_first(), octstr_split(), parse_appid_header(), parse_attr_value(), parse_body_part(), parse_entities(), parse_get_seperated_block(), parse_preamble(), parse_url_value(), parse_xml_tag(), pass_extension_headers(), pass_optional_header(), return_reply(), set_charset(), skip_html_comment(), string_table_apply(), and wap_push_ppg_pushuser_search_ip_from_wildcarded_list().

1071 {
1072  int first;
1073 
1074  seems_valid(haystack);
1075  seems_valid(needle);
1076  gw_assert(pos >= 0);
1077 
1078  /* Always "find" an empty string */
1079  if (needle->len == 0)
1080  return 0;
1081 
1082  if (needle->len == 1)
1083  return octstr_search_char(haystack, needle->data[0], pos);
1084 
1085  /* For each occurrence of needle's first character in ostr,
1086  * check if the rest of needle follows. Stop if there are no
1087  * more occurrences, or if the rest of needle can't possibly
1088  * fit in the haystack. */
1089  first = needle->data[0];
1090  pos = octstr_search_char(haystack, first, pos);
1091  while (pos >= 0 && haystack->len - pos >= needle->len) {
1092  if (memcmp(haystack->data + pos,
1093  needle->data, needle->len) == 0)
1094  return pos;
1095  pos = octstr_search_char(haystack, first, pos + 1);
1096  }
1097 
1098  return -1;
1099 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_search_char()

long octstr_search_char ( const Octstr ostr,
int  ch,
long  pos 
)

Definition at line 1012 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by at2_detect_modem_type(), at2_extract_line(), at2_init_device(), at2_read_pending_incoming_messages(), at2_scan_for_telnet_escapes(), cfg_read(), cgw_encode_msg(), cgw_read_op(), check_reversible(), check_variable_syntax(), client_read_status(), conn_read_line(), conn_read_packet(), copy_until_assign(), copy_until_coma(), copy_until_nul(), date_parse_http(), date_parse_iso(), decode_type(), eat_string_parm(), emi2_handle_smscreq(), extract_msgdata_part(), find_translation(), generic_init(), get_fields(), get_header_value(), get_variable(), handle_dlr(), header_is_called(), http_accept_request(), http_get_header_parameter(), http_header_get(), http_header_get_content_type(), http_header_value(), httpd_serve(), msg_to_bb(), octstr_convert_from_html_entities(), octstr_search(), octstr_search_chars(), octstr_str_search(), pack_credentials(), packet_check(), packet_extract(), packet_get_parm(), pap_compile(), parm_parse(), parse_address(), parse_attr_value(), parse_cgivars(), parse_charset(), parse_data(), parse_element(), parse_get_line(), parse_get_nul_string(), parse_st_octet_string(), parse_url(), read_line(), set_charset(), skip_html_tag(), skip_tail(), skip_until_after_colon(), soap_parse_dlr(), soap_parse_mo(), urltrans_fill_escape_codes(), wap_push_ppg_pushuser_search_ip_from_wildcarded_list(), wml_compile(), wrapper_sender(), wsp_cap_pack_list(), wsp_cap_unpack_list(), and wsp_strip_parameters().

1013 {
1014  unsigned char *p;
1015 
1016  seems_valid(ostr);
1017  gw_assert(ch >= 0);
1018  gw_assert(ch <= UCHAR_MAX);
1019  gw_assert(pos >= 0);
1020 
1021  if (pos >= ostr->len)
1022  return -1;
1023 
1024  p = memchr(ostr->data + pos, ch, ostr->len - pos);
1025  if (!p)
1026  return -1;
1027  return p - ostr->data;
1028 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_search_chars()

long octstr_search_chars ( const Octstr ostr,
const Octstr chars,
long  pos 
)

Definition at line 1052 of file octstr.c.

References gw_assert(), octstr_get_char(), octstr_len(), octstr_search_char(), and seems_valid.

Referenced by smsbox_req_handle().

1053 {
1054  long i, j;
1055 
1056  seems_valid(ostr);
1057  seems_valid(chars);
1058  gw_assert(pos >= 0);
1059 
1060  for (i = 0; i < octstr_len(chars); i++) {
1061  j = octstr_search_char(ostr, octstr_get_char(chars, i), pos);
1062  if (j != -1)
1063  return j;
1064  }
1065 
1066  return -1;
1067 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ octstr_set_bits()

void octstr_set_bits ( Octstr ostr,
long  bitpos,
int  numbits,
unsigned long  value 
)

Definition at line 1849 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, maxlen, octstr_grow(), and seems_valid.

Referenced by pack_server_address(), pack_tpis(), sanitize_capabilities(), set_user_ack(), tokenize_date(), and wtp_pack_set_rid().

1851 {
1852  long pos;
1853  unsigned long mask;
1854  int shiftwidth;
1855  int bits;
1856  int maxlen;
1857  int c;
1858 
1859  seems_valid(ostr);
1860  gw_assert(!ostr->immutable);
1861  gw_assert(bitpos >= 0);
1862  gw_assert(numbits <= 32);
1863  gw_assert(numbits >= 0);
1864 
1865  maxlen = (bitpos + numbits + 7) / 8;
1866  if (maxlen > ostr->len) {
1867  octstr_grow(ostr, maxlen);
1868  /* Make sure the new octets start out with value 0 */
1869  for (pos = ostr->len; pos < maxlen; pos++) {
1870  ostr->data[pos] = 0;
1871  }
1872  ostr->len = maxlen;
1873  ostr->data[maxlen] = 0;
1874  }
1875 
1876  mask = (1 << numbits) - 1;
1877  /* mask is also the largest value that fits */
1878  gw_assert(value <= mask);
1879 
1880  pos = bitpos / 8;
1881  bitpos = bitpos % 8;
1882 
1883  /* Does the range fit in one octet? */
1884  if (bitpos + numbits <= 8) {
1885  /* shiftwidth is the number of bits to ignore on the right.
1886  * bitpos 0 is the leftmost bit. */
1887  shiftwidth = 8 - (bitpos + numbits);
1888  /* Extract the bits we don't want to affect */
1889  c = ostr->data[pos] & ~(mask << shiftwidth);
1890  c |= value << shiftwidth;
1891  gw_assert(pos < ostr->len);
1892  ostr->data[pos] = c;
1893  return;
1894  }
1895 
1896  /* Otherwise... */
1897  /* If speed is a problem here, we could have separate cases for
1898  * the first octet (which may have bitpos > 0), and the rest,
1899  * which don't. */
1900  while (bitpos + numbits > 8) {
1901  /* We want this many bits from the value */
1902  bits = 8 - bitpos;
1903  /* There are this many bits to their right in the value */
1904  shiftwidth = numbits - bits;
1905  /* Construct a mask for "bits" bits on the far right */
1906  mask = (1 << bits) - 1;
1907  /* Get the bits we want */
1908  c = (value >> shiftwidth) & mask;
1909  /* Merge them with the bits that are already there */
1910  gw_assert(pos < ostr->len);
1911  ostr->data[pos] = (ostr->data[pos] & ~mask) | c;
1912  numbits -= (8 - bitpos);
1913  bitpos = 0;
1914  pos++;
1915  }
1916 
1917  gw_assert(bitpos == 0);
1918  gw_assert(pos < ostr->len);
1919  /* Set remaining bits. This is just like the single-octet case
1920  * before the loop, except that we know bitpos is 0. */
1921  mask = (1 << numbits) - 1;
1922  shiftwidth = 8 - numbits;
1923  c = ostr->data[pos] & ~(mask << shiftwidth);
1924  c |= value << shiftwidth;
1925  ostr->data[pos] = c;
1926 
1927  seems_valid(ostr);
1928 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
int maxlen
Definition: smsc_cimd2.c:214
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_set_char()

void octstr_set_char ( Octstr ostr,
long  pos,
int  ch 
)

◆ octstr_shrink_blanks()

void octstr_shrink_blanks ( Octstr text)

Definition at line 1433 of file octstr.c.

References gw_assert(), octstr_delete(), octstr_get_char(), octstr_len(), octstr_set_char(), seems_valid, and text.

Referenced by html_to_sms(), ota_compile(), parse_text(), string_table_collect_strings(), and xmlrpc_doc_parse().

1434 {
1435  int i, j, end;
1436 
1437  seems_valid(text);
1438  gw_assert(!text->immutable);
1439 
1440  end = octstr_len(text);
1441 
1442  /* Shrink white spaces to one */
1443  for (i = 0; i < end; i++) {
1444  if (isspace(octstr_get_char(text, i))) {
1445  /* Change the remaining space into single space. */
1446  if (octstr_get_char(text, i) != ' ')
1447  octstr_set_char(text, i, ' ');
1448 
1449  j = i = i + 1;
1450  while (isspace(octstr_get_char(text, j)))
1451  j ++;
1452  if (j - i > 0)
1453  octstr_delete(text, i, j - i);
1454  }
1455  }
1456 
1457  seems_valid(text);
1458 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
char * text
Definition: smsc_cimd2.c:921
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
void octstr_set_char(Octstr *ostr, long pos, int ch)
Definition: octstr.c:415

◆ octstr_shutdown()

void octstr_shutdown ( void  )

Definition at line 226 of file octstr.c.

References debug(), immutables, immutables_mutex, MAX_IMMUTABLES, and mutex_destroy().

Referenced by gwlib_shutdown().

227 {
228  long i, n;
229 
230  n = 0;
231  for (i = 0; i < MAX_IMMUTABLES; ++i) {
232  if (immutables[i] != NULL) {
233  gw_free(immutables[i]);
234  ++n;
235  }
236  }
237  if(n>0)
238  debug("gwlib.octstr", 0, "Immutable octet strings: %ld.", n);
240 }
#define MAX_IMMUTABLES
Definition: octstr.c:131
static Mutex immutables_mutex
Definition: octstr.c:134
static Octstr * immutables[MAX_IMMUTABLES]
Definition: octstr.c:133
void mutex_destroy(Mutex *mutex)
Definition: thread.c:97
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726

◆ octstr_split()

List* octstr_split ( const Octstr os,
const Octstr sep 
)

Definition at line 1640 of file octstr.c.

References gwlist_append(), gwlist_create, octstr_copy, octstr_len(), and octstr_search().

Referenced by at2_detect_modem_type(), at2_init_device(), brunet_parse_body(), client_is_persistent(), create_onetrans(), expand_file(), init_batch(), init_reroute(), init_smsbox_routes(), init_smsc_routes(), main(), msg_to_pdu(), pattern_list_matches_ip(), prefix_allowed(), response(), smpp_pdu_init(), smsc_soap_create(), soap_create_map(), soap_fetch_xml_data(), soap_map_xml_data(), soap_release_dependences(), udp_start(), wap_push_ppg_pushuser_search_ip_from_wildcarded_list(), and wildcarded_ip_found().

1641 {
1642  List *list;
1643  long next, pos, seplen;
1644 
1645  list = gwlist_create();
1646  pos = 0;
1647  seplen = octstr_len(sep);
1648 
1649  while ((next = octstr_search(os, sep, pos)) >= 0) {
1650  gwlist_append(list, octstr_copy(os, pos, next - pos));
1651  pos = next + seplen;
1652  }
1653 
1654  if (pos < octstr_len(os))
1655  gwlist_append(list, octstr_copy(os, pos, octstr_len(os)));
1656 
1657  return list;
1658 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define gwlist_create()
Definition: list.h:136
Definition: list.c:102

◆ octstr_split_words()

List* octstr_split_words ( const Octstr ostr)

Definition at line 1602 of file octstr.c.

References Octstr::data, gwlist_append(), gwlist_create, octstr_create_from_data, seems_valid, and start.

Referenced by brunet_parse_body(), cfg_get_list(), clickatell_parse_body(), find_translation(), get_pattern(), parse_request_line(), randomize(), smsbox_req_handle(), soap_create_map(), soap_release_dependences(), string_table_collect_words(), urltrans_fill_escape_codes(), and wrapper_sender().

1603 {
1604  unsigned char *p;
1605  List *list;
1606  Octstr *word;
1607  long i, start, end;
1608 
1609  seems_valid(ostr);
1610 
1611  list = gwlist_create();
1612 
1613  p = ostr->data;
1614  i = 0;
1615  for (; ; ) {
1616  while (i < ostr->len && isspace(*p)) {
1617  ++p;
1618  ++i;
1619  }
1620  start = i;
1621 
1622  while (i < ostr->len && !isspace(*p)) {
1623  ++p;
1624  ++i;
1625  }
1626  end = i;
1627 
1628  if (start == end)
1629  break;
1630 
1631  word = octstr_create_from_data(ostr->data + start,
1632  end - start);
1633  gwlist_append(list, word);
1634  }
1635 
1636  return list;
1637 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
#define gwlist_create()
Definition: list.h:136
#define octstr_create_from_data(data, len)
Definition: octstr.h:134
Definition: list.c:102
static int start

◆ octstr_str_case_compare()

int octstr_str_case_compare ( const Octstr ostr,
const char *  str 
)

Definition at line 986 of file octstr.c.

References Octstr::data, and seems_valid.

Referenced by convert_addr_from_pdu(), get_x_kannel_from_xml(), meta_data_get_value(), meta_data_get_values(), meta_data_remove_value(), meta_data_set_value(), meta_data_set_values(), msg_to_pdu(), and smpp_pdu_init().

987 {
988  seems_valid(ostr);
989 
990  if (str == NULL)
991  return -1;
992  if (ostr->data == NULL)
993  return strcasecmp("", str);
994 
995  return strcasecmp(ostr->data, str);
996 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120

◆ octstr_str_compare()

int octstr_str_compare ( const Octstr ostr,
const char *  str 
)

◆ octstr_str_ncompare()

int octstr_str_ncompare ( const Octstr ostr,
const char *  str,
long  n 
)

Definition at line 999 of file octstr.c.

References Octstr::data, and seems_valid.

Referenced by cid_matches().

1000 {
1001  seems_valid(ostr);
1002 
1003  if (str == NULL)
1004  return -1;
1005  if (ostr->data == NULL)
1006  return 1; /* str grater */
1007 
1008  return strncmp(ostr->data, str, n);
1009 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120

◆ octstr_str_search()

long octstr_str_search ( const Octstr haystack,
const char *  needle,
long  pos 
)

Definition at line 1157 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, octstr_search_char(), and seems_valid.

1158 {
1159  int first;
1160  int needle_len;
1161 
1162  seems_valid(haystack);
1163  gw_assert(pos >= 0);
1164 
1165  /* Always "find" an empty string */
1166  if (needle == NULL || needle[0] == '\0')
1167  return 0;
1168 
1169  needle_len = strlen(needle);
1170 
1171  if (needle_len == 1)
1172  return octstr_search_char(haystack, needle[0], pos);
1173 
1174  /* For each occurrence of needle's first character in ostr,
1175  * check if the rest of needle follows. Stop if there are no
1176  * more occurrences, or if the rest of needle can't possibly
1177  * fit in the haystack. */
1178  first = needle[0];
1179  pos = octstr_search_char(haystack, first, pos);
1180  while (pos >= 0 && haystack->len - pos >= needle_len) {
1181  if (memcmp(haystack->data + pos,
1182  needle, needle_len) == 0)
1183  return pos;
1184  pos = octstr_search_char(haystack, first, pos + 1);
1185  }
1186 
1187  return -1;
1188 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_strip_blanks()

void octstr_strip_blanks ( Octstr text)

Definition at line 1346 of file octstr.c.

References gw_assert(), octstr_delete(), octstr_get_char(), octstr_len(), seems_valid, start, and text.

Referenced by at2_extract_line(), at2_format_address_field(), cfg_read(), deduce_body_state(), find_charset_encoding(), get_header_value(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), handle_dlr(), handle_transaction(), html_to_sms(), http_add_basic_auth(), http_get_header_parameter(), http_header_add_element(), http_header_find_first_real(), http_header_get(), http_header_get_content_type(), http_header_value(), init_reroute(), init_smsbox_routes(), init_smsc_routes(), ota_compile(), pack_challenge(), pack_credentials(), pack_known_header(), pap_compile(), parm_parse(), parse_text(), parse_value(), parse_xml_tag(), proxy_add_authentication(), response(), si_compile(), sl_compile(), smsbox_sendota_post(), smsbox_sendsms_post(), soap_map_xml_data(), soap_release_dependences(), string_table_collect_strings(), transform_message(), url_result_thread(), wml_compile(), wsp_pack_separate_content_type(), wsp_strip_parameters(), and xmlrpc_doc_parse().

1347 {
1348  int start = 0, end, len = 0;
1349 
1350  seems_valid(text);
1351  gw_assert(!text->immutable);
1352 
1353  /* Remove white space from the beginning of the text */
1354  while (isspace(octstr_get_char(text, start)) &&
1355  start <= octstr_len(text))
1356  start ++;
1357 
1358  if (start > 0)
1359  octstr_delete(text, 0, start);
1360 
1361  /* and from the end. */
1362 
1363  if ((len = octstr_len(text)) > 0) {
1364  end = len = len - 1;
1365  while (isspace(octstr_get_char(text, end)) && end >= 0)
1366  end--;
1367  octstr_delete(text, end + 1, len - end);
1368  }
1369 
1370  seems_valid(text);
1371 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
char * text
Definition: smsc_cimd2.c:921
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
static int start

◆ octstr_strip_char()

void octstr_strip_char ( Octstr text,
char  ch 
)

Definition at line 2616 of file octstr.c.

References gw_assert(), octstr_delete(), octstr_get_char(), octstr_len(), seems_valid, start, and text.

2617 {
2618  int start = 0;
2619 
2620  seems_valid(text);
2621  gw_assert(!text->immutable);
2622 
2623  /* Remove char from the beginning of the text */
2624  while ((ch == octstr_get_char(text, start)) &&
2625  start <= octstr_len(text))
2626  start ++;
2627 
2628  if (start > 0)
2629  octstr_delete(text, 0, start);
2630 
2631  seems_valid(text);
2632 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
char * text
Definition: smsc_cimd2.c:921
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
static int start

◆ octstr_strip_crlfs()

void octstr_strip_crlfs ( Octstr text)

Definition at line 1378 of file octstr.c.

References gw_assert(), iscrlf(), octstr_delete(), octstr_get_char(), octstr_len(), seems_valid, start, and text.

Referenced by init_batch(), main(), parse_get_line(), parse_xml_tag(), and soap_release_dependences().

1379 {
1380  int start = 0, end, len = 0;
1381 
1382  seems_valid(text);
1383  gw_assert(!text->immutable);
1384 
1385  /* Remove white space from the beginning of the text */
1386  while (iscrlf(octstr_get_char(text, start)) &&
1387  start <= octstr_len(text))
1388  start ++;
1389 
1390  if (start > 0)
1391  octstr_delete(text, 0, start);
1392 
1393  /* and from the end. */
1394 
1395  if ((len = octstr_len(text)) > 0) {
1396  end = len = len - 1;
1397  while (iscrlf(octstr_get_char(text, end)) && end >= 0)
1398  end--;
1399  octstr_delete(text, end + 1, len - end);
1400  }
1401 
1402  seems_valid(text);
1403 }
static int iscrlf(unsigned char c)
Definition: octstr.c:1373
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
char * text
Definition: smsc_cimd2.c:921
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
static int start

◆ octstr_strip_nonalphanums()

void octstr_strip_nonalphanums ( Octstr text)

Definition at line 1405 of file octstr.c.

References gw_assert(), octstr_delete(), octstr_get_char(), octstr_len(), seems_valid, start, and text.

Referenced by string_table_collect_strings().

1406 {
1407  int start = 0, end, len = 0;
1408 
1409  seems_valid(text);
1410  gw_assert(!text->immutable);
1411 
1412  /* Remove white space from the beginning of the text */
1413  while (!isalnum(octstr_get_char(text, start)) &&
1414  start <= octstr_len(text))
1415  start ++;
1416 
1417  if (start > 0)
1418  octstr_delete(text, 0, start);
1419 
1420  /* and from the end. */
1421 
1422  if ((len = octstr_len(text)) > 0) {
1423  end = len = len - 1;
1424  while (!isalnum(octstr_get_char(text, end)) && end >= 0)
1425  end--;
1426  octstr_delete(text, end + 1, len - end);
1427  }
1428 
1429  seems_valid(text);
1430 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
char * text
Definition: smsc_cimd2.c:921
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
static int start

◆ octstr_symbolize()

int octstr_symbolize ( Octstr ostr)

Definition at line 2679 of file octstr.c.

References gw_assert(), gw_isxdigit(), Octstr::immutable, Octstr::len, octstr_check_range(), octstr_grow(), octstr_insert_data(), and seems_valid.

2680 {
2681  long len, i;
2682 
2683  seems_valid(ostr);
2684  gw_assert(!ostr->immutable);
2685 
2686  if (ostr->len == 0)
2687  return 0;
2688 
2689  /* Check if it's in the right format */
2690  if (!octstr_check_range(ostr, 0, ostr->len, gw_isxdigit))
2691  return -1;
2692 
2693  len = ostr->len + (ostr->len/2);
2694  octstr_grow(ostr, ostr->len * 2);
2695 
2696  for (i = 0; i < len; i += 3)
2697  octstr_insert_data(ostr, i, "%", 1);
2698 
2699  return 1;
2700 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int octstr_check_range(Octstr *ostr, long pos, long len, octstr_func_t filter)
Definition: octstr.c:814
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
int immutable
Definition: octstr.c:123
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
long len
Definition: octstr.c:121
int gw_isxdigit(int c)
Definition: utils.c:994

◆ octstr_truncate()

void octstr_truncate ( Octstr ostr,
int  new_len 
)

Definition at line 1327 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, and seems_valid.

Referenced by at2_detect_modem_type(), at2_init_device(), at2_pdu_extract(), charset_convert(), charset_gsm_to_utf8(), charset_gsm_truncate(), charset_utf8_to_gsm(), check_variable_syntax(), client_read_status(), convert(), emi2_handle_smscreq(), get_x_kannel_from_xml(), http_accept_request(), http_header_get_content_type(), msg_to_emimsg(), octstr_recode(), packet_encode_message(), parse_charset(), parse_st_octet_string(), parse_value(), parse_variable(), send_file(), smsc_cimd2_create(), string_table_apply(), strip_prefix_and_suffix(), and url_pattern().

1328 {
1329  if (ostr == NULL)
1330  return;
1331 
1332  seems_valid(ostr);
1333  gw_assert(!ostr->immutable);
1334  gw_assert(new_len >= 0);
1335 
1336  if (new_len >= ostr->len)
1337  return;
1338 
1339  ostr->len = new_len;
1340  ostr->data[new_len] = '\0';
1341 
1342  seems_valid(ostr);
1343 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_url_decode()

int octstr_url_decode ( Octstr ostr)

Definition at line 1746 of file octstr.c.

References code, Octstr::data, gw_assert(), H2B, Octstr::immutable, Octstr::len, seems_valid, and warning().

Referenced by brunet_send_sms(), charset_processing(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), meta_data_unpack(), msg_to_bb(), parse_cgivars(), parse_url(), soap_parse_dlr(), soap_parse_mo(), start_request(), and xidris_send_sms().

1747 {
1748  unsigned char *string;
1749  unsigned char *dptr;
1750  int code, code2, ret = 0;
1751 
1752  if (ostr == NULL)
1753  return 0;
1754 
1755  seems_valid(ostr);
1756  gw_assert(!ostr->immutable);
1757 
1758  if (ostr->len == 0)
1759  return 0;
1760 
1761  string = ostr->data;
1762  dptr = ostr->data;
1763 
1764  do {
1765  if (*string == '%') {
1766  if (*(string + 1) == '\0' || *(string + 2) == '\0') {
1767  warning(0, "octstr_url_decode: corrupted end-of-string <%s>", string);
1768  ret = -1;
1769  break;
1770  }
1771 
1772  code = H2B(*(string + 1));
1773  code2 = H2B(*(string + 2));
1774 
1775  if (code == -1 || code2 == -1) {
1776  warning(0, "octstr_url_decode: garbage detected (%c%c%c) skipping.",
1777  *string, *(string + 1), *(string + 2));
1778  *dptr++ = *string++;
1779  *dptr++ = *string++;
1780  *dptr++ = *string++;
1781  ret = -1;
1782  continue;
1783  }
1784 
1785  *dptr++ = code << 4 | code2;
1786  string += 3;
1787  }
1788  else if (*string == '+') {
1789  *dptr++ = ' ';
1790  string++;
1791  } else
1792  *dptr++ = *string++;
1793  } while (*string); /* we stop here because it terimates encoded string */
1794 
1795  *dptr = '\0';
1796  ostr->len = (dptr - ostr->data);
1797 
1798  seems_valid(ostr);
1799  return ret;
1800 }
#define H2B(a)
Definition: octstr.c:151
gw_assert(wtls_machine->packet_to_send !=NULL)
int code
Definition: smsc_cimd2.c:346
void warning(int err, const char *fmt,...)
Definition: log.c:660
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_url_encode()

void octstr_url_encode ( Octstr ostr)

Definition at line 1673 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, is_safe, Octstr::len, seems_valid, and Octstr::size.

Referenced by convert(), main(), obey_request(), sms_to_client(), and urltrans_fill_escape_codes().

1674 {
1675  long i, n, len = 0;
1676  int all_safe;
1677  unsigned char c, *str, *str2, *res, *hexits;
1678 
1679  if (ostr == NULL)
1680  return;
1681 
1682  seems_valid(ostr);
1683  gw_assert(!ostr->immutable);
1684 
1685  if (ostr->len == 0)
1686  return;
1687 
1688  /* calculate new length */
1689  for (i = n = 0, str = ostr->data, all_safe = 1; i < ostr->len; i++) {
1690  c = *str++;
1691 
1692  if (c == ' ') {
1693  all_safe = 0;
1694  continue;
1695  }
1696 
1697  if (!is_safe[c]) {
1698  n++;
1699  all_safe = 0;
1700  }
1701  }
1702 
1703  if (all_safe) /* we are done, all chars are safe */
1704  return;
1705 
1706  hexits = "0123456789ABCDEF";
1707 
1708  /*
1709  * no need to reallocate if n == 0, so we make replace in place.
1710  * NOTE: we don't do if (xxx) ... else ... because conditional jump
1711  * is not so fast as just compare (alex).
1712  */
1713  res = str2 = (n ? gw_malloc((len = ostr->len + 2 * n + 1)) : ostr->data);
1714 
1715  for (i = 0, str = ostr->data; i < ostr->len; i++) {
1716  c = *str++;
1717 
1718  if (c == ' ') {
1719  *str2++ = '+';
1720  continue;
1721  }
1722 
1723  if (!is_safe[c]) {
1724  *str2++ = '%';
1725  *str2++ = hexits[c >> 4 & 0xf];
1726  *str2++ = hexits[c & 0xf];
1727  continue;
1728  }
1729 
1730  *str2++ = c;
1731  }
1732  *str2 = 0;
1733 
1734  /* we made replace in place */
1735  if (n) {
1736  gw_free(ostr->data);
1737  ostr->data = res;
1738  ostr->size = len;
1739  ostr->len = len - 1;
1740  }
1741 
1742  seems_valid(ostr);
1743 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static char is_safe[UCHAR_MAX+1]
Definition: octstr.c:137
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_write_data()

long octstr_write_data ( Octstr ostr,
int  fd,
long  from 
)

Definition at line 1255 of file octstr.c.

References Octstr::data, error(), from, gw_assert(), Octstr::len, and seems_valid.

Referenced by unlocked_write().

1256 {
1257  long ret;
1258 
1259  gw_assert(fd >= 0);
1260  gw_assert(from >= 0);
1261  seems_valid(ostr);
1262 
1263  if (from >= ostr->len)
1264  return 0;
1265 
1266  ret = write(fd, ostr->data + from, ostr->len - from);
1267 
1268  if (ret < 0) {
1269  if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
1270  return 0;
1271  error(errno, "Error writing %ld octets to fd %d:",
1272  ostr->len - from, fd);
1273  return -1;
1274  }
1275 
1276  return ret;
1277 }
void error(int err, const char *fmt,...)
Definition: log.c:648
gw_assert(wtls_machine->packet_to_send !=NULL)
static Octstr * from
Definition: mtbatch.c:95
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ octstr_write_to_socket()

int octstr_write_to_socket ( int  socket,
Octstr ostr 
)

Definition at line 1227 of file octstr.c.

References Octstr::data, error(), gw_assert(), Octstr::len, and seems_valid.

Referenced by cimd2_request(), cimd2_send_response(), oisd_request(), and oisd_send_response().

1228 {
1229  long len;
1230  unsigned char *data;
1231  int ret;
1232 
1233  gw_assert(socket >= 0);
1234  seems_valid(ostr);
1235 
1236  data = ostr->data;
1237  len = ostr->len;
1238  while (len > 0) {
1239  ret = write(socket, data, len);
1240  if (ret == -1) {
1241  if (errno != EINTR) {
1242  error(errno, "Writing to socket failed");
1243  return -1;
1244  }
1245  } else {
1246  /* ret may be less than len */
1247  len -= ret;
1248  data += ret;
1249  }
1250  }
1251  return 0;
1252 }
void error(int err, const char *fmt,...)
Definition: log.c:648
gw_assert(wtls_machine->packet_to_send !=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121

◆ seems_valid_real()

static void seems_valid_real ( const Octstr ostr,
const char *  filename,
long  lineno,
const char *  function 
)
static

Definition at line 2545 of file octstr.c.

References Octstr::data, filename, gw_assert(), gw_assert_place, Octstr::immutable, immutables_init, Octstr::len, and Octstr::size.

Referenced by octstr_copy_real(), octstr_duplicate_real(), and octstr_get_cstr_real().

2547 {
2549  gw_assert_place(ostr != NULL,
2550  filename, lineno, function);
2551  gw_assert_allocated(ostr,
2552  filename, lineno, function);
2553  gw_assert_place(ostr->len >= 0,
2554  filename, lineno, function);
2555  gw_assert_place(ostr->size >= 0,
2556  filename, lineno, function);
2557  if (ostr->size == 0) {
2558  gw_assert_place(ostr->len == 0,
2559  filename, lineno, function);
2560  gw_assert_place(ostr->data == NULL,
2561  filename, lineno, function);
2562  } else {
2563  gw_assert_place(ostr->len + 1 <= ostr->size,
2564  filename, lineno, function);
2565  gw_assert_place(ostr->data != NULL,
2566  filename, lineno, function);
2567  if (!ostr->immutable)
2568  gw_assert_allocated(ostr->data,
2569  filename, lineno, function);
2570  gw_assert_place(ostr->data[ostr->len] == '\0',
2571  filename, lineno, function);
2572  }
2573 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
static int immutables_init
Definition: octstr.c:135
char filename[FILENAME_MAX+1]
Definition: log.c:171
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
#define gw_assert_place(expr, file, lineno, func)
Definition: gwassert.h:90

◆ urlcode_init()

static void urlcode_init ( void  )
static

Definition at line 206 of file octstr.c.

References is_safe.

Referenced by octstr_init().

207 {
208  int i;
209 
210  unsigned char *safe = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
211  "abcdefghijklmnopqrstuvwxyz"
212  "0123456789-_.~";
213  for (i = 0; safe[i] != '\0'; ++i)
214  is_safe[safe[i]] = 1;
215 }
static char is_safe[UCHAR_MAX+1]
Definition: octstr.c:137

Variable Documentation

◆ immutables

Octstr* immutables[MAX_IMMUTABLES]
static

Definition at line 133 of file octstr.c.

Referenced by octstr_imm(), and octstr_shutdown().

◆ immutables_init

int immutables_init = 0
static

Definition at line 135 of file octstr.c.

Referenced by octstr_imm(), octstr_init(), and seems_valid_real().

◆ immutables_mutex

Mutex immutables_mutex
static

Definition at line 134 of file octstr.c.

Referenced by octstr_imm(), octstr_init(), and octstr_shutdown().

◆ is_safe

char is_safe[UCHAR_MAX+1]
static

Definition at line 137 of file octstr.c.

Referenced by octstr_url_encode(), and urlcode_init().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.