#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"Include dependency graph for octstr.c:

Go to the source code of this file.
Data Structures | |
| struct | Octstr |
| struct | format |
Defines | |
| #define | VARGS(x) (&x) |
| #define | VALPARM(y) va_list *y |
| #define | VALST(z) (*z) |
| #define | MAX_IMMUTABLES 1024 |
| #define | CSTR_TO_LONG(ptr) (((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 | |
| void | seems_valid_real (const Octstr *ostr, const char *filename, long lineno, const char *function) |
| void | octstr_grow (Octstr *ostr, long size) |
| void | urlcode_init (void) |
| void | octstr_init (void) |
| void | octstr_shutdown (void) |
| Octstr * | octstr_create_real (const char *cstr, const char *file, long line, const char *func) |
| Octstr * | octstr_create_from_data_real (const char *data, long len, const char *file, long line, const char *func) |
| Octstr * | octstr_imm (const char *cstr) |
| void | octstr_destroy (Octstr *ostr) |
| void | octstr_destroy_item (void *os) |
| long | octstr_len (const Octstr *ostr) |
| Octstr * | octstr_copy_real (const Octstr *ostr, long from, long len, const char *file, long line, const char *func) |
| Octstr * | octstr_duplicate_real (const Octstr *ostr, const char *file, long line, const char *func) |
| Octstr * | octstr_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) |
| 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) |
| int | octstr_search_char (const Octstr *ostr, int ch, long pos) |
| int | octstr_search_chars (const Octstr *ostr, const Octstr *chars, long pos) |
| int | octstr_search (const Octstr *haystack, const Octstr *needle, long pos) |
| int | octstr_case_search (const Octstr *haystack, const Octstr *needle, long pos) |
| int | octstr_case_nsearch (const Octstr *haystack, const Octstr *needle, long pos, long n) |
| 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) |
| 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) |
| Octstr * | octstr_read_file (const char *filename) |
| Octstr * | octstr_read_pipe (FILE *f) |
| List * | octstr_split_words (const Octstr *ostr) |
| List * | octstr_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) |
| 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) |
| void | format_flags (struct format *format, const char **fmt) |
| void | format_width (struct format *format, const char **fmt, VALPARM(args)) |
| void | format_prec (struct format *format, const char **fmt, VALPARM(args)) |
| void | format_type (struct format *format, const char **fmt) |
| void | convert (Octstr *os, struct format *format, const char **fmt, VALPARM(args)) |
| Octstr * | octstr_format (const char *fmt,...) |
| Octstr * | octstr_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) |
| 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) |
| int | octstr_find_entity (Octstr *input, int startfind, int endfind) |
| void | octstr_convert_from_html_entities (Octstr *input) |
Variables | |
| Octstr * | immutables [MAX_IMMUTABLES] |
| Mutex | immutables_mutex |
| int | immutables_init = 0 |
| char | is_safe [UCHAR_MAX+1] |
|
|
Definition at line 144 of file octstr.c. Referenced by octstr_imm(). |
|
|
|
|
|
Value: case a: \ octstr_delete(input, i, 1); \ octstr_insert(input, octstr_imm("&" b ";"), i); \ i += sizeof(b); break; |
|
|
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 150 of file octstr.c. Referenced by octstr_url_decode(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 1996 of file octstr.c. Referenced by octstr_dump_real(). |
|
|
|
|
|
|
Definition at line 90 of file octstr.c. Referenced by convert(), format_prec(), and format_width(). |
|
|
Definition at line 88 of file octstr.c. Referenced by octstr_format_valist_real(). |
|
||||||||||||||||||||
|
Definition at line 2232 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(). 02234 {
02235 Octstr *new;
02236 char *s, *pad;
02237 long n;
02238 unsigned long u;
02239 char tmpfmt[1024];
02240 char tmpbuf[1024];
02241 char c;
02242 void *p;
02243
02244 new = NULL;
02245
02246 switch (**fmt)
02247 {
02248 case 'c':
02249 c = va_arg(VALST(args), int);
02250 new = octstr_create_from_data(&c, 1);
02251 break;
02252
02253 case 'd':
02254 case 'i':
02255 switch (format->type) {
02256 case 'l':
02257 n = va_arg(VALST(args), long);
02258 break;
02259 case 'h':
02260 n = (short) va_arg(VALST(args), int);
02261 break;
02262 default:
02263 n = va_arg(VALST(args), int);
02264 break;
02265 }
02266 new = octstr_create("");
02267 octstr_append_decimal(new, n);
02268 break;
02269
02270 case 'o':
02271 case 'u':
02272 case 'x':
02273 case 'X':
02274 switch (format->type) {
02275 case 'l':
02276 u = va_arg(VALST(args), unsigned long);
02277 break;
02278 case 'h':
02279 u = (unsigned short) va_arg(VALST(args), unsigned int);
02280 break;
02281 default:
02282 u = va_arg(VALST(args), unsigned int);
02283 break;
02284 }
02285 tmpfmt[0] = '%';
02286 tmpfmt[1] = 'l';
02287 tmpfmt[2] = **fmt;
02288 tmpfmt[3] = '\0';
02289 sprintf(tmpbuf, tmpfmt, u);
02290 new = octstr_create(tmpbuf);
02291 break;
02292
02293 case 'e':
02294 case 'f':
02295 case 'g':
02296 sprintf(tmpfmt, "%%");
02297 if (format->minus)
02298 strcat(tmpfmt, "-");
02299 if (format->zero)
02300 strcat(tmpfmt, "0");
02301 if (format->min_width > 0)
02302 sprintf(strchr(tmpfmt, '\0'),
02303 "%ld", format->min_width);
02304 if (format->has_prec)
02305 sprintf(strchr(tmpfmt, '\0'),
02306 ".%ld", format->prec);
02307 if (format->type != '\0')
02308 sprintf(strchr(tmpfmt, '\0'),
02309 "%c", (int) format->type);
02310 sprintf(strchr(tmpfmt, '\0'), "%c", **fmt);
02311 snprintf(tmpbuf, sizeof(tmpbuf),
02312 tmpfmt, va_arg(VALST(args), double));
02313 new = octstr_create(tmpbuf);
02314 break;
02315
02316 case 's':
02317 s = va_arg(VALST(args), char *);
02318 if (format->has_prec && format->prec < (long) strlen(s))
02319 n = format->prec;
02320 else
02321 n = (long) strlen(s);
02322 new = octstr_create_from_data(s, n);
02323 break;
02324
02325 case 'p':
02326 p = va_arg(VALST(args), void *);
02327 sprintf(tmpfmt, "%p", p);
02328 new = octstr_create(tmpfmt);
02329 break;
02330
02331 case 'S':
02332 new = octstr_duplicate(va_arg(VALST(args), Octstr *));
02333 if (!new)
02334 new = octstr_create("(null)");
02335 if (format->has_prec)
02336 octstr_truncate(new, format->prec);
02337 break;
02338
02339 case 'E':
02340 new = octstr_duplicate(va_arg(VALST(args), Octstr *));
02341 if (!new)
02342 new = octstr_create("(null)");
02343 octstr_url_encode(new);
02344 /*
02345 * note: we use blind truncate - encoded character can get cut half-way.
02346 */
02347 if (format->has_prec)
02348 octstr_truncate(new, format->prec);
02349 break;
02350
02351 case 'H':
02352 new = octstr_duplicate(va_arg(VALST(args), Octstr *));
02353 if (!new)
02354 new = octstr_create("(null)");
02355 /* upper case */
02356 octstr_binary_to_hex(new, 1);
02357 if (format->has_prec)
02358 octstr_truncate(new, (format->prec % 2 ? format->prec - 1 : format->prec));
02359 break;
02360
02361 case '%':
02362 new = octstr_create("%");
02363 break;
02364
02365 default:
02366 panic(0, "octstr_format format string syntax error.");
02367 }
02368
02369 if (format->zero)
02370 pad = "0";
02371 else
02372 pad = " ";
02373
02374 if (format->minus) {
02375 while (format->min_width > octstr_len(new))
02376 octstr_append_data(new, pad, 1);
02377 } else {
02378 while (format->min_width > octstr_len(new))
02379 octstr_insert_data(new, 0, pad, 1);
02380 }
02381
02382 octstr_append(os, new);
02383 octstr_destroy(new);
02384
02385 if (**fmt != '\0')
02386 ++(*fmt);
02387 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 2152 of file octstr.c. References format::minus, and format::zero. Referenced by octstr_format_valist_real(). 02153 {
02154 int done;
02155
02156 done = 0;
02157 do
02158 {
02159 switch (**fmt) {
02160 case '-':
02161 format->minus = 1;
02162 break;
02163
02164 case '0':
02165 format->zero = 1;
02166 break;
02167
02168 default:
02169 done = 1;
02170 }
02171
02172 if (!done)
02173 ++(*fmt);
02174 } while (!done);
02175 }
|
|
||||||||||||||||
|
Definition at line 2196 of file octstr.c. References format::has_prec, format::prec, and VALST. Referenced by octstr_format_valist_real(). 02198 {
02199 char *end;
02200
02201 if (**fmt != '.')
02202 return;
02203 ++(*fmt);
02204 if (**fmt == '*')
02205 {
02206 format->has_prec = 1;
02207 format->prec = va_arg(VALST(args), int);
02208 ++(*fmt);
02209 } else if (isdigit(**(const unsigned char **) fmt))
02210 {
02211 format->has_prec = 1;
02212 format->prec = strtol(*fmt, &end, 10);
02213 *fmt = end;
02214 /* XXX error checking is missing from here */
02215 }
02216 }
|
|
||||||||||||
|
Definition at line 2219 of file octstr.c. References format::type. Referenced by octstr_format_valist_real(). 02220 {
02221 switch (**fmt)
02222 {
02223 case 'h':
02224 case 'l':
02225 format->type = **fmt;
02226 ++(*fmt);
02227 break;
02228 }
02229 }
|
|
||||||||||||||||
|
Definition at line 2178 of file octstr.c. References format::min_width, and VALST. Referenced by octstr_format_valist_real(). 02180 {
02181 char *end;
02182
02183 if (**fmt == '*')
02184 {
02185 format->min_width = va_arg(VALST(args), int);
02186 ++(*fmt);
02187 } else if (isdigit(**(const unsigned char **) fmt))
02188 {
02189 format->min_width = strtol(*fmt, &end, 10);
02190 *fmt = end;
02191 /* XXX error checking is missing from here */
02192 }
02193 }
|
|
|
Definition at line 1313 of file octstr.c. Referenced by octstr_strip_crlfs(). 01314 {
01315 return c == '\n' || c == '\r';
01316 }
|
|
|
Definition at line 853 of file octstr.c. Referenced by octstr_convert_printable(). 00854 {
00855 return isprint(c) ? c : '.';
00856 }
|
|
||||||||||||
Here is the call graph for this function:

|
||||||||||||
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1451 of file octstr.c. References Octstr::len, and octstr_insert_data(). Referenced by add_content_transfer_encoding_type(), append_uuid(), at2_read_line(), at2_wait_modem_command(), bb_print_status(), boxc_status(), cfg_read(), clickatell_send_sms(), create_onetrans(), get_pattern(), http_header_get_content_type(), httpd_serve(), kannel_send_sms(), mime_entity_dump_real(), mime_something_to_entity(), octstr_append_decimal(), operation_name(), packet_extract(), parse_cookie(), radius_type_convert(), smasi_pdu_pack(), smsc2_status(), store_file_status(), store_spool_status(), and urltrans_fill_escape_codes(). 01452 {
01453 octstr_insert_data(ostr, ostr->len, cstr, strlen(cstr));
01454 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 1437 of file octstr.c. References data, gw_assert, Octstr::len, and octstr_insert_data(). Referenced by add_wsp_connect(), append_integer(), at2_read_buffer(), charset_convert(), conn_write_data(), conn_write_withlen(), convert(), gen_data(), get_pattern(), octstr_append_from_socket(), octstr_append_uintvar(), octstr_format_valist_real(), octstr_read_pipe(), radius_authenticate_pdu(), read_data(), read_line(), set_charset(), unlocked_read(), and wap_msg_send(). 01438 {
01439 gw_assert(ostr != NULL);
01440 octstr_insert_data(ostr, ostr->len, data, len);
01441 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1913 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(). 01914 {
01915 char tmp[128];
01916
01917 sprintf(tmp, "%ld", value);
01918 octstr_append_cstr(ostr, tmp);
01919 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 446 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(). 00447 {
00448 Octstr *output;
00449
00450 seems_valid(ostr);
00451 gw_assert(!ostr->immutable);
00452
00453 output = octstr_create(hex);
00454 octstr_hex_to_binary(output);
00455 octstr_append(ostr, output);
00456 octstr_destroy(output);
00457 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1220 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(). 01221 {
01222 unsigned char buf[4096];
01223 int len;
01224
01225 seems_valid(ostr);
01226 gw_assert(!ostr->immutable);
01227
01228 again:
01229 len = recv(socket, buf, sizeof(buf), 0);
01230 if (len < 0 && errno == EINTR)
01231 goto again;
01232
01233 if (len < 0) {
01234 error(errno, "Could not read from socket %d", socket);
01235 return -1;
01236 }
01237
01238 octstr_append_data(ostr, buf, len);
01239 return len;
01240 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1868 of file octstr.c. References octstr_append_data(). 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(). 01869 {
01870 /* A uintvar is defined to be up to 32 bits large, so it will
01871 * fit in 5 octets. */
01872 unsigned char octets[5];
01873 int i;
01874 int start;
01875
01876 /* Handle last byte separately; it has no continuation bit,
01877 * and must be encoded even if value is 0. */
01878 octets[4] = value & 0x7f;
01879 value >>= 7;
01880
01881 for (i = 3; value > 0 && i >= 0; i--) {
01882 octets[i] = 0x80 | (value & 0x7f);
01883 value >>= 7;
01884 }
01885 start = i + 1;
01886
01887 octstr_append_data(ostr, octets + start, 5 - start);
01888 }
|
Here is the call graph for this function:

|
|
Definition at line 658 of file octstr.c. References data, Octstr::data, gw_assert, Octstr::immutable, Octstr::len, seems_valid, and warning(). Referenced by extract_base64(), pack_credentials(), pack_md5(), and soap_msgdata_deps(). 00659 {
00660 long triplet;
00661 long pos, len;
00662 long to;
00663 int quadpos = 0;
00664 int warned = 0;
00665 unsigned char *data;
00666
00667 seems_valid(ostr);
00668 gw_assert(!ostr->immutable);
00669
00670 len = ostr->len;
00671 data = ostr->data;
00672
00673 if (len == 0)
00674 return;
00675
00676 to = 0;
00677 triplet = 0;
00678 quadpos = 0;
00679 for (pos = 0; pos < len; pos++) {
00680 int c = data[pos];
00681 int sixbits;
00682
00683 if (c >= 'A' && c <= 'Z') {
00684 sixbits = c - 'A';
00685 } else if (c >= 'a' && c <= 'z') {
00686 sixbits = 26 + c - 'a';
00687 } else if (c >= '0' && c <= '9') {
00688 sixbits = 52 + c - '0';
00689 } else if (c == '+') {
00690 sixbits = 62;
00691 } else if (c == '/') {
00692 sixbits = 63;
00693 } else if (c == '=') {
00694 /* These can only occur at the end of encoded
00695 * text. RFC 2045 says we can assume it really
00696 * is the end. */
00697 break;
00698 } else if (isspace(c)) {
00699 /* skip whitespace */
00700 continue;
00701 } else {
00702 if (!warned) {
00703 warning(0, "Unusual characters in base64 "
00704 "encoded text.");
00705 warned = 1;
00706 }
00707 continue;
00708 }
00709
00710 triplet = (triplet << 6) | sixbits;
00711 quadpos++;
00712
00713 if (quadpos == 4) {
00714 data[to++] = (triplet >> 16) & 0xff;
00715 data[to++] = (triplet >> 8) & 0xff;
00716 data[to++] = triplet & 0xff;
00717 quadpos = 0;
00718 }
00719 }
00720
00721 /* Deal with leftover octets */
00722 switch (quadpos) {
00723 case 0:
00724 break;
00725 case 3: /* triplet has 18 bits, we want the first 16 */
00726 data[to++] = (triplet >> 10) & 0xff;
00727 data[to++] = (triplet >> 2) & 0xff;
00728 break;
00729 case 2: /* triplet has 12 bits, we want the first 8 */
00730 data[to++] = (triplet >> 4) & 0xff;
00731 break;
00732 case 1:
00733 warning(0, "Bad padding in base64 encoded text.");
00734 break;
00735 }
00736
00737 ostr->len = to;
00738 data[to] = '\0';
00739
00740 seems_valid(ostr);
00741 }
|
Here is the call graph for this function:

|
|
Definition at line 537 of file octstr.c. References data, Octstr::data, gw_assert, Octstr::immutable, Octstr::len, 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(). 00538 {
00539 static const unsigned char base64[64] =
00540 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
00541 long triplets;
00542 long lines;
00543 long orig_len;
00544 unsigned char *data;
00545 long from, to;
00546 int left_on_line;
00547
00548 seems_valid(ostr);
00549 gw_assert(!ostr->immutable);
00550
00551 if (ostr->len == 0) {
00552 /* Always terminate with CR LF */
00553 octstr_insert(ostr, octstr_imm("\015\012"), 0);
00554 return;
00555 }
00556
00557 /* The lines must be 76 characters each (or less), and each
00558 * triplet will expand to 4 characters, so we can fit 19
00559 * triplets on one line. We need a CR LF after each line,
00560 * which will add 2 octets per 19 triplets (rounded up). */
00561 triplets = (ostr->len + 2) / 3; /* round up */
00562 lines = (triplets + 18) / 19;
00563
00564 octstr_grow(ostr, triplets * 4 + lines * 2);
00565 orig_len = ostr->len;
00566 data = ostr->data;
00567
00568 ostr->len = triplets * 4 + lines * 2;
00569 data[ostr->len] = '\0';
00570
00571 /* This function works back-to-front, so that encoded data will
00572 * not overwrite source data.
00573 * from points to the start of the last triplet (which may be
00574 * an odd-sized one), and to points to the start of where the
00575 * last quad should go. */
00576 from = (triplets - 1) * 3;
00577 to = (triplets - 1) * 4 + (lines - 1) * 2;
00578
00579 /* First write the CR LF after the last quad */
00580 data[to + 5] = 10; /* LF */
00581 data[to + 4] = 13; /* CR */
00582 left_on_line = triplets - ((lines - 1) * 19);
00583
00584 /* base64 encoding is in 3-octet units. To handle leftover
00585 * octets, conceptually we have to zero-pad up to the next
00586 * 6-bit unit, and pad with '=' characters for missing 6-bit
00587 * units.
00588 * We do it by first completing the first triplet with
00589 * zero-octets, and after the loop replacing some of the
00590 * result characters with '=' characters.
00591 * There is enough room for this, because even with a 1 or 2
00592 * octet source string, space for four octets of output
00593 * will be reserved.
00594 */
00595 switch (orig_len % 3) {
00596 case 0:
00597 break;
00598 case 1:
00599 data[orig_len] = 0;
00600 data[orig_len + 1] = 0;
00601 break;
00602 case 2:
00603 data[orig_len + 1] = 0;
00604 break;
00605 }
00606
00607 /* Now we only have perfect triplets. */
00608 while (from >= 0) {
00609 long whole_triplet;
00610
00611 /* Add a newline, if necessary */
00612 if (left_on_line == 0) {
00613 to -= 2;
00614 data[to + 5] = 10; /* LF */
00615 data[to + 4] = 13; /* CR */
00616 left_on_line = 19;
00617 }
00618
00619 whole_triplet = (data[from] << 16) |
00620 (data[from + 1] << 8) |
00621 data[from + 2];
00622 data[to + 3] = base64[whole_triplet % 64];
00623 data[to + 2] = base64[(whole_triplet >> 6) % 64];
00624 data[to + 1] = base64[(whole_triplet >> 12) % 64];
00625 data[to] = base64[(whole_triplet >> 18) % 64];
00626
00627 to -= 4;
00628 from -= 3;
00629 left_on_line--;
00630 }
00631
00632 gw_assert(left_on_line == 0);
00633 gw_assert(from == -3);
00634 gw_assert(to == -4);
00635
00636 /* Insert padding characters in the last quad. Remember that
00637 * there is a CR LF between the last quad and the end of the
00638 * string. */
00639 switch (orig_len % 3) {
00640 case 0:
00641 break;
00642 case 1:
00643 gw_assert(data[ostr->len - 3] == 'A');
00644 gw_assert(data[ostr->len - 4] == 'A');
00645 data[ostr->len - 3] = '=';
00646 data[ostr->len - 4] = '=';
00647 break;
00648 case 2:
00649 gw_assert(data[ostr->len - 3] == 'A');
00650 data[ostr->len - 3] = '=';
00651 break;
00652 }
00653
00654 seems_valid(ostr);
00655 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 460 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(), get_pattern(), kannel_send_sms(), main(), make_emi60(), msg_to_cgwop(), msg_to_emimsg(), ota_pack_push_headers(), pack_7bit(), packet_add_hex_parm(), soap_msgdata_attribute(), status_cb(), and store_file_status(). 00461 {
00462 unsigned char *hexits;
00463 long i, tmp;
00464
00465 seems_valid(ostr);
00466 gw_assert(!ostr->immutable);
00467 if (ostr->len == 0)
00468 return;
00469
00470 hexits = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
00471 octstr_grow(ostr, ostr->len * 2);
00472
00473 /* In-place modification must be done back-to-front to avoid
00474 * overwriting the data while we read it. Even the order of
00475 * the two assignments is important, to get i == 0 right. */
00476 for (i = ostr->len - 1; i >= 0; i--) {
00477 tmp = i << 1; /* tmp = i * 2; */
00478 ostr->data[tmp + 1] = hexits[ostr->data[i] & 0xf];
00479 ostr->data[tmp] = hexits[ostr->data[i] >> 4];
00480 }
00481
00482 ostr->len = ostr->len * 2;
00483 ostr->data[ostr->len] = '\0';
00484
00485 seems_valid(ostr);
00486 }
|
Here is the call graph for this function:

|
||||||||||||
|
||||||||||||||||||||
|
Definition at line 1103 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(), drop_extension_headers(), drop_optional_header(), pass_extension_headers(), and pass_optional_header(). 01104 {
01105 long i, j;
01106 int c1, c2;
01107
01108 seems_valid(haystack);
01109 seems_valid(needle);
01110 gw_assert(pos >= 0);
01111
01112 /* Always "find" an empty string */
01113 if (needle->len == 0)
01114 return 0;
01115
01116 for (i = pos; i <= haystack->len - needle->len && i < n; ++i) {
01117 for (j = 0; j < needle->len && j < n; ++j) {
01118 c1 = toupper(haystack->data[i + j]);
01119 c2 = toupper(needle->data[j]);
01120 if (c1 != c2)
01121 break;
01122 }
01123 if (j == needle->len)
01124 return i;
01125 }
01126
01127 return -1;
01128 }
|
|
||||||||||||||||
|
Definition at line 1076 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(). 01077 {
01078 long i, j;
01079 int c1, c2;
01080
01081 seems_valid(haystack);
01082 seems_valid(needle);
01083 gw_assert(pos >= 0);
01084
01085 /* Always "find" an empty string */
01086 if (needle->len == 0)
01087 return 0;
01088
01089 for (i = pos; i <= haystack->len - needle->len; ++i) {
01090 for (j = 0; j < needle->len; ++j) {
01091 c1 = toupper(haystack->data[i + j]);
01092 c2 = toupper(needle->data[j]);
01093 if (c1 != c2)
01094 break;
01095 }
01096 if (j == needle->len)
01097 return i;
01098 }
01099
01100 return -1;
01101 }
|
|
||||||||||||
|
Definition at line 377 of file octstr.c. References Octstr::data, gw_assert, Octstr::immutable, Octstr::len, octstr_create, seems_valid, and Octstr::size. 00378 {
00379 Octstr *ostr;
00380
00381 seems_valid(ostr1);
00382 seems_valid(ostr2);
00383 gw_assert(!ostr1->immutable);
00384
00385 ostr = octstr_create("");
00386 ostr->len = ostr1->len + ostr2->len;
00387 ostr->size = ostr->len + 1;
00388 ostr->data = gw_malloc(ostr->size);
00389
00390 if (ostr1->len > 0)
00391 memcpy(ostr->data, ostr1->data, ostr1->len);
00392 if (ostr2->len > 0)
00393 memcpy(ostr->data + ostr1->len, ostr2->data, ostr2->len);
00394 ostr->data[ostr->len] = '\0';
00395
00396 seems_valid(ostr);
00397 return ostr;
00398 }
|
|
||||||||||||||||||||
|
Definition at line 809 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(). 00811 {
00812 long end = pos + len;
00813
00814 seems_valid(ostr);
00815 gw_assert(len >= 0);
00816
00817 if (pos >= ostr->len)
00818 return 1;
00819 if (end > ostr->len)
00820 end = ostr->len;
00821
00822 for ( ; pos < end; pos++) {
00823 if (!filter(ostr->data[pos]))
00824 return 0;
00825 }
00826
00827 return 1;
00828 }
|
|
||||||||||||
|
|
Definition at line 2709 of file octstr.c. References octstr_copy, octstr_delete(), octstr_destroy(), octstr_find_entity(), octstr_insert_char(), and octstr_search_char(). 02710 {
02711 int startpos = 0, endpos;
02712 int entity;
02713 Octstr *match;
02714
02715 while ((startpos = octstr_search_char(input, '&', startpos)) != -1) {
02716 endpos = octstr_search_char(input, ';', startpos + 1);
02717 if (endpos >= 0) {
02718 match = octstr_copy(input, startpos + 1, endpos - startpos - 1);
02719 entity = octstr_find_entity(match, 0, 0);
02720 if (entity >= 0) {
02721 octstr_delete(input, startpos, endpos - startpos + 1);
02722 octstr_insert_char(input, startpos, entity);
02723 }
02724 octstr_destroy(match);
02725 }
02726 startpos++;
02727 }
02728 }
|
Here is the call graph for this function:

|
|
Definition at line 859 of file octstr.c. References Octstr::len, make_printable(), and octstr_convert_range(). Referenced by bb_alog_sms(), and get_pattern(). 00860 {
00861 octstr_convert_range(ostr, 0, ostr->len, make_printable);
00862 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 831 of file octstr.c. References Octstr::data, gw_assert, Octstr::immutable, Octstr::len, and seems_valid. Referenced by check_variable_syntax(), create_onetrans(), find_translation(), octstr_convert_printable(), parse_charset(), and parse_constant(). 00833 {
00834 long end = pos + len;
00835
00836 seems_valid(ostr);
00837 gw_assert(!ostr->immutable);
00838 gw_assert(len >= 0);
00839
00840 if (pos >= ostr->len)
00841 return;
00842 if (end > ostr->len)
00843 end = ostr->len;
00844
00845 for ( ; pos < end; pos++) {
00846 ostr->data[pos] = map(ostr->data[pos]);
00847 }
00848
00849 seems_valid(ostr);
00850 }
|
|
|
Definition at line 2643 of file octstr.c. References octstr_get_char(), and octstr_len(). Referenced by soap_msgdata_attribute(), soap_o2o_msgdata_attribute(), and xmlrpc_scalar_print(). 02644 {
02645 int i;
02646
02647 for (i = 0; i < octstr_len(input); ++i) {
02648 switch (octstr_get_char(input, i)) {
02649 #define ENTITY(a,b) \
02650 case a: \
02651 octstr_delete(input, i, 1); \
02652 octstr_insert(input, octstr_imm("&" b ";"), i); \
02653 i += sizeof(b); break;
02654 #include "gwlib/html-entities.def"
02655 #undef ENTITY
02656 }
02657 }
02658 }
|
Here is the call graph for this function:

|
||||||||||||||||||||||||||||
|
Definition at line 348 of file octstr.c. References Octstr::data, file, gw_assert, Octstr::len, octstr_create, octstr_create_from_data_trace, and seems_valid. Referenced by http_header_find_first_real(). 00350 {
00351 seems_valid(ostr);
00352 gw_assert(from >= 0);
00353 gw_assert(len >= 0);
00354
00355 if (from >= ostr->len)
00356 return octstr_create("");
00357
00358 if (len > ostr->len - from)
00359 len = ostr->len - from;
00360
00361 return octstr_create_from_data_trace(ostr->data + from, len, file,
00362 line, func);
00363 }
|
|
||||||||||||||||||||||||
|
Definition at line 247 of file octstr.c. References data, Octstr::data, file, gw_assert, Octstr::immutable, Octstr::len, seems_valid, and Octstr::size. 00249 {
00250 Octstr *ostr;
00251
00252 gw_assert(len >= 0);
00253 if (data == NULL)
00254 gw_assert(len == 0);
00255
00256 /* if gw_assert is disabled just return NULL
00257 * and caller will check for NULL or just crash.
00258 */
00259 if (len < 0 || (data == NULL && len != 0))
00260 return NULL;
00261
00262 ostr = gw_malloc_trace(sizeof(*ostr), file, line, func);
00263 if (len == 0) {
00264 ostr->len = 0;
00265 ostr->size = 0;
00266 ostr->data = NULL;
00267 } else {
00268 ostr->len = len;
00269 ostr->size = len + 1;
00270 ostr->data = gw_malloc_trace(ostr->size, file, line, func);
00271 memcpy(ostr->data, data, len);
00272 ostr->data[len] = '\0';
00273 }
00274 ostr->immutable = 0;
00275 seems_valid(ostr);
00276 return ostr;
00277 }
|
|
||||||||||||||||||||
|
Definition at line 240 of file octstr.c. References file, gw_assert, and octstr_create_from_data_trace. 00242 {
00243 gw_assert(cstr != NULL);
00244 return octstr_create_from_data_trace(cstr, strlen(cstr), file, line, func);
00245 }
|
|
||||||||||||||||
|
||||||||||||
|
Definition at line 2607 of file octstr.c. References gw_assert, Octstr::immutable, octstr_delete(), octstr_len(), octstr_search(), and seems_valid. Referenced by push_content_create(). 02608 {
02609 int p = 0;
02610 long len;
02611
02612 seems_valid(haystack);
02613 seems_valid(needle);
02614 gw_assert(!haystack->immutable);
02615 len = octstr_len(needle);
02616
02617 while ((p = octstr_search(haystack, needle, p)) != -1) {
02618 octstr_delete(haystack, p, len);
02619 }
02620 }
|
Here is the call graph for this function:

|
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1927 of file octstr.c. References d, debug(), octstr_get_char(), octstr_len(), and seems_valid. Referenced by octstr_dump_real(). 01928 {
01929 unsigned char *p, *d, buf[1024], charbuf[256];
01930 long pos;
01931 const int octets_per_line = 16;
01932 int c, this_line_begins_at;
01933
01934 if (ostr == NULL)
01935 return;
01936
01937 seems_valid(ostr);
01938
01939 debug("gwlib.octstr", 0, "%*sOctet string at %p:", level, "",
01940 (void *) ostr);
01941 debug("gwlib.octstr", 0, "%*s len: %lu", level, "",
01942 (unsigned long) ostr->len);
01943 debug("gwlib.octstr", 0, "%*s size: %lu", level, "",
01944 (unsigned long) ostr->size);
01945 debug("gwlib.octstr", 0, "%*s immutable: %d", level, "",
01946 ostr->immutable);
01947
01948 buf[0] = '\0';
01949 p = buf;
01950 d = charbuf;
01951 this_line_begins_at = 0;
01952 for (pos = 0; pos < octstr_len(ostr); ) {
01953 c = octstr_get_char(ostr, pos);
01954 sprintf(p, "%02x ", c);
01955 p = strchr(p, '\0');
01956 if (isprint(c))
01957 *d++ = c;
01958 else
01959 *d++ = '.';
01960 ++pos;
01961 if (pos - this_line_begins_at == octets_per_line) {
01962 *d = '\0';
01963 debug("gwlib.octstr", 0, "%*s data: %s %s", level, "",
01964 buf, charbuf);
01965 buf[0] = '\0';
01966 charbuf[0] = '\0';
01967 p = buf;
01968 d = charbuf;
01969 this_line_begins_at = pos;
01970 }
01971 }
01972 if (pos - this_line_begins_at > 0) {
01973 *d = '\0';
01974 debug("gwlib.octstr", 0, "%*s data: %-*.*s %s", level, "",
01975 octets_per_line*3,
01976 octets_per_line*3, buf, charbuf);
01977 }
01978
01979 debug("gwlib.octstr", 0, "%*sOctet string dump ends.", level, "");
01980 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 2052 of file octstr.c. References error(), GW_DEBUG, GW_ERROR, GW_INFO, GW_WARNING, info(), octstr_dump_debug(), octstr_dump_LOGLEVEL, and warning(). 02053 {
02054 va_list p;
02055 unsigned int loglevel;
02056
02057 va_start(p, level);
02058 loglevel = va_arg(p, unsigned int);
02059 va_end(p);
02060
02061 switch (loglevel) {
02062 case GW_DEBUG:
02063 octstr_dump_debug(ostr, level);
02064 break;
02065 case GW_INFO:
02066 octstr_dump_LOGLEVEL(info, ostr, level);
02067 break;
02068 case GW_WARNING:
02069 octstr_dump_LOGLEVEL(warning, ostr, level);
02070 break;
02071 case GW_ERROR:
02072 octstr_dump_LOGLEVEL(error, ostr, level);
02073 break;
02074 default:
02075 octstr_dump_debug(ostr, level);
02076 break;
02077 }
02078 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 2081 of file octstr.c. References Octstr::data, debug(), Octstr::len, name, octstr_dump, and seems_valid. Referenced by main(), and radius_pdu_unpack(). 02082 {
02083 char buf[100];
02084 char *p;
02085 long i;
02086 int c;
02087
02088 if (ostr == NULL) {
02089 debug("gwlib.octstr", 0, "%*s%s: NULL", level, "", name);
02090 return;
02091 }
02092
02093 seems_valid(ostr);
02094
02095 if (ostr->len < 20) {
02096 p = buf;
02097 for (i = 0; i < ostr->len; i++) {
02098 c = ostr->data[i];
02099 if (c == '\n') {
02100 *p++ = '\\';
02101 *p++ = 'n';
02102 } else if (!isprint(c)) {
02103 break;
02104 } else if (c == '"') {
02105 *p++ = '\\';
02106 *p++ = '"';
02107 } else if (c == '\\') {
02108 *p++ = '\\';
02109 *p++ = '\\';
02110 } else {
02111 *p++ = c;
02112 }
02113 }
02114 if (i == ostr->len) {
02115 *p++ = 0;
02116 /* We got through the loop without hitting nonprintable
02117 * characters. */
02118 debug("gwlib.octstr", 0, "%*s%s: \"%s\"", level, "", name, buf);
02119 return;
02120 }
02121 }
02122
02123 debug("gwlib.octstr", 0, "%*s%s:", level, "", name);
02124 octstr_dump(ostr, level + 1);
02125 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 367 of file octstr.c. References Octstr::data, file, Octstr::len, octstr_create_from_data_trace, and seems_valid. 00369 {
00370 if (ostr == NULL)
00371 return NULL;
00372 seems_valid(ostr);
00373 return octstr_create_from_data_trace(ostr->data, ostr->len, file, line, func);
00374 }
|
|
||||||||||||||||
|
Definition at line 1891 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(). 01892 {
01893 int c;
01894 int count;
01895 unsigned long ui;
01896
01897 ui = 0;
01898 for (count = 0; count < 5; count++) {
01899 c = octstr_get_char(ostr, pos + count);
01900 if (c < 0)
01901 return -1;
01902 ui = (ui << 7) | (c & 0x7f);
01903 if (!(c & 0x80)) {
01904 *value = ui;
01905 return pos + count + 1;
01906 }
01907 }
01908
01909 return -1;
01910 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 2665 of file octstr.c. References octstr_str_compare(). Referenced by octstr_convert_from_html_entities(). 02666 {
02667 #define ENTITY(a,b) { a, b },
02668 struct entity_struct {
02669 int entity;
02670 char *entity_str;
02671 };
02672 const struct entity_struct entities[] = {
02673 #include "html-entities.def"
02674 { -1, "" } /* pivot */
02675 };
02676 #undef ENTITY
02677 int center; /* position in table that we are about to compare */
02678 int matchresult; /* result of match agains found entity name. indicates less, equal or greater */
02679
02680 if (endfind == 0) {
02681 /* when calling this function we do not (nor even want to) know the
02682 * sizeof(entities). Hence this check. */
02683 endfind = (sizeof(entities) / sizeof(struct entity_struct)) - 1;
02684 }
02685 center = startfind + ((endfind - startfind) / 2);
02686 matchresult = octstr_str_compare(input, entities[center].entity_str);
02687 if (matchresult == 0) {
02688 return entities[center].entity;
02689 }
02690 if (endfind - startfind <= 1) {
02691 /* we are at the end of our results */
02692 return -1;
02693 }
02694 if (matchresult < 0) {
02695 /* keep searching in first part of the table */
02696 return octstr_find_entity(input, startfind, center);
02697 } else {
02698 /* keep searching in last part of the table */
02699 return octstr_find_entity(input, center, endfind);
02700 }
02701 }
|
Here is the call graph for this function:

|
||||||||||||
|
||||||||||||||||
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 2402 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. 02403 {
02404 Octstr *os;
02405 size_t n;
02406
02407 os = octstr_create("");
02408
02409 while (*fmt != '\0') {
02410 struct format format = { 0, };
02411
02412 n = strcspn(fmt, "%");
02413 octstr_append_data(os, fmt, n);
02414 fmt += n;
02415
02416 gw_assert(*fmt == '%' || *fmt == '\0');
02417 if (*fmt == '\0')
02418 continue;
02419
02420 ++fmt;
02421 format_flags(&format, &fmt);
02422 format_width(&format, &fmt, VARGS(args));
02423 format_prec(&format, &fmt, VARGS(args));
02424 format_type(&format, &fmt);
02425 convert(os, &format, &fmt, VARGS(args));
02426 }
02427
02428 seems_valid(os);
02429 return os;
02430 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 1740 of file octstr.c. References Octstr::data, gw_assert, Octstr::len, result, and seems_valid. Referenced by deduce_tid(), get_tid(), unpack_ack(), unpack_tpis(), wtp_type(), and wtp_unpack_wdp_datagram(). 01741 {
01742 long pos;
01743 long result;
01744 int mask;
01745 int shiftwidth;
01746
01747 seems_valid(ostr);
01748 gw_assert(bitpos >= 0);
01749 gw_assert(numbits <= 32);
01750 gw_assert(numbits >= 0);
01751
01752 pos = bitpos / 8;
01753 bitpos = bitpos % 8;
01754
01755 /* This also takes care of the len == 0 case */
01756 if (pos >= ostr->len)
01757 return 0;
01758
01759 mask = (1 << numbits) - 1;
01760
01761 /* It's easy if the range fits in one octet */
01762 if (bitpos + numbits <= 8) {
01763 /* shiftwidth is the number of bits to ignore on the right.
01764 * bitpos 0 is the leftmost bit. */
01765 shiftwidth = 8 - (bitpos + numbits);
01766 return (ostr->data[pos] >> shiftwidth) & mask;
01767 }
01768
01769 /* Otherwise... */
01770 result = 0;
01771 while (bitpos + numbits > 8) {
01772 result = (result << 8) | ostr->data[pos];
01773 numbits -= (8 - bitpos);
01774 bitpos = 0;
01775 pos++;
01776 if (pos >= ostr->len)
01777 return (result << numbits) & mask;
01778 }
01779
01780 gw_assert(bitpos == 0);
01781 result <<= numbits;
01782 result |= ostr->data[pos] >> (8 - numbits);
01783 return result & mask;
01784 }
|
|
||||||||||||
|
||||||||||||||||||||
|
Definition at line 434 of file octstr.c. References Octstr::data, file, Octstr::len, and seems_valid_real(). 00436 {
00437 if (!ostr)
00438 return "(null)";
00439 seems_valid_real(ostr, file, line, func);
00440 if (ostr->len == 0)
00441 return "";
00442 return ostr->data;
00443 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 420 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(). 00421 {
00422 gw_assert(buf != NULL);
00423 seems_valid(ostr);
00424
00425 if (pos >= ostr->len)
00426 return;
00427 if (pos + len > ostr->len)
00428 len = ostr->len - pos;
00429 if (len > 0)
00430 memcpy(buf, ostr->data + pos, len);
00431 }
|
|
||||||||||||
|
Definition at line 180 of file octstr.c. References Octstr::data, gw_assert, Octstr::immutable, seems_valid, Octstr::size, and 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(). 00181 {
00182 gw_assert(!ostr->immutable);
00183 seems_valid(ostr);
00184 gw_assert(size >= 0);
00185
00186 size++; /* make room for the invisible terminating NUL */
00187
00188 if (size > ostr->size) {
00189 /* always reallocate in 1kB chunks */
00190 size += 1024 - (size % 1024);
00191 ostr->data = gw_realloc(ostr->data, size);
00192 ostr->size = size;
00193 }
00194 }
|
|
|
Definition at line 2446 of file octstr.c. References octstr_get_char(), and octstr_len(). Referenced by key_to_index(), and store_spool_save(). 02447 {
02448 unsigned long key = 0;
02449 long i;
02450
02451 if (ostr == NULL)
02452 return 0;
02453
02454 for (i = 0; i < octstr_len(ostr); i++)
02455 key = key + octstr_get_char(ostr, i);
02456
02457 return key;
02458 }
|
Here is the call graph for this function:

|
|
Definition at line 489 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(), soap_msgdata_deps(), and store_file_status(). 00490 {
00491 long len, i;
00492 unsigned char *p;
00493
00494 seems_valid(ostr);
00495 gw_assert(!ostr->immutable);
00496
00497 if (ostr->len == 0)
00498 return 0;
00499
00500 /* Check if it's in the right format */
00501 if (!octstr_check_range(ostr, 0, ostr->len, gw_isxdigit))
00502 return -1;
00503
00504 len = ostr->len;
00505
00506 /* Convert ascii data to binary values */
00507 for (i = 0, p = ostr->data; i < len; i++, p++) {
00508 if (*p >= '0' && *p <= '9')
00509 *p -= '0';
00510 else if (*p >= 'a' && *p <= 'f')
00511 *p = *p - 'a' + 10;
00512 else if (*p >= 'A' && *p <= 'F')
00513 *p = *p - 'A' + 10;
00514 else {
00515 /* isxdigit checked the whole string, so we should
00516 * not be able to get here. */
00517 gw_assert(0);
00518 *p = 0;
00519 }
00520 }
00521
00522 /* De-hexing will compress data by factor of 2 */
00523 len = ostr->len / 2;
00524
00525 for (i = 0; i < len; i++) {
00526 ostr->data[i] = ostr->data[i * 2] * 16 | ostr->data[i * 2 + 1];
00527 }
00528
00529 ostr->len = len;
00530 ostr->data[len] = '\0';
00531
00532 seems_valid(ostr);
00533 return 0;
00534 }
|
Here is the call graph for this function:

|
|
|
Definition at line 215 of file octstr.c. References immutables_init, immutables_mutex, mutex_init_static, and urlcode_init(). Referenced by gwlib_init(). 00216 {
00217 urlcode_init();
00218 mutex_init_static(&immutables_mutex);
00219 immutables_init = 1;
00220 }
|
Here is the call graph for this function:

|
||||||||||||||||
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 1421 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(), and octstr_convert_from_html_entities(). 01422 {
01423 seems_valid(ostr);
01424 gw_assert(!ostr->immutable);
01425 gw_assert(pos <= ostr->len);
01426
01427 octstr_grow(ostr, ostr->len + 1);
01428 if (ostr->len > pos)
01429 memmove(ostr->data + pos + 1, ostr->data + pos, ostr->len - pos);
01430 memcpy(ostr->data + pos, &c, 1);
01431 ostr->len += 1;
01432 ostr->data[ostr->len] = '\0';
01433
01434 seems_valid(ostr);
01435 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
Here is the call graph for this function:

|
|
Definition at line 2622 of file octstr.c. References gw_isxdigit(), octstr_get_char(), octstr_len(), and seems_valid. Referenced by main(), and push_content_create(). 02623 {
02624 long len, i;
02625 int ch;
02626
02627 seems_valid(os);
02628 len = octstr_len(os);
02629 for (i = 0; i < len; ++i) {
02630 ch = octstr_get_char(os, i);
02631 if (!gw_isxdigit(ch))
02632 return 0;
02633 }
02634
02635 return 1;
02636 }
|
Here is the call graph for this function:

|
|
Definition at line 2554 of file octstr.c. References octstr_get_char(), octstr_len(), and seems_valid. 02555 {
02556 int start = 0;
02557 char c;
02558
02559 seems_valid(ostr1);
02560 while (start < octstr_len(ostr1)) {
02561 c = octstr_get_char(ostr1, start);
02562 if (!isdigit(c) && (c!='+'))
02563 return 0;
02564 start++;
02565 }
02566 return 1;
02567 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1607 of file octstr.c. References octstr_case_compare(). 01608 {
01609 return octstr_case_compare(item, pattern) == 0;
01610 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 1601 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(). 01602 {
01603 return octstr_compare(item, pattern) == 0;
01604 }
|
Here is the call graph for this function:

|
|
||||||||||||||||
|
Definition at line 947 of file octstr.c. References Octstr::data, Octstr::len, and seems_valid. Referenced by compare_octstr_sequence(), http_header_get_content_type(), kannel_parse_reply(), pack_content_range(), pack_range(), packet_encode_message(), parse_attribute(), parse_close_delimiter(), parse_http_version(), and remove_prefix(). 00948 {
00949 long len;
00950
00951 seems_valid(ostr1);
00952 seems_valid(ostr2);
00953
00954 if ((ostr1->len < ostr2->len) && (ostr1->len < n))
00955 len = ostr1->len;
00956 else if ((ostr2->len < ostr1->len) && (ostr2->len < n))
00957 len = ostr2->len;
00958 else
00959 len = n;
00960
00961 if (len == 0)
00962 return 0;
00963
00964 return memcmp(ostr1->data, ostr2->data, len);
00965 }
|
|
||||||||||||||||
|
Definition at line 777 of file octstr.c. References Octstr::data, gw_assert, Octstr::len, number, and seems_valid. Referenced by parse_value_element(), and smscconn_create(). 00778 {
00779 /* strtod wants a char *, and we have to compare the result to
00780 * an unsigned char *. The easiest way to avoid warnings without
00781 * introducing typecasts is to use two variables. */
00782 char *endptr;
00783 unsigned char *endpos;
00784 double number;
00785
00786 seems_valid(ostr);
00787 gw_assert(nump != NULL);
00788
00789 if (pos >= ostr->len) {
00790 errno = EINVAL;
00791 return -1;
00792 }
00793
00794 errno = 0;
00795 number = strtod(ostr->data + pos, &endptr);
00796 endpos = endptr;
00797 if (errno == ERANGE)
00798 return -1;
00799 if (endpos == ostr->data + pos) {
00800 errno = EINVAL;
00801 return -1;
00802 }
00803
00804 *nump = number;
00805 return endpos - ostr->data;
00806 }
|
|
||||||||||||||||||||
|
Definition at line 744 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(), date_parse_iso(), deduce_body_state(), eat_number(), eq_round_trip_time(), get_fields(), get_x_kannel_from_xml(), handle_operation(), 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(). 00745 {
00746 /* strtol wants a char *, and we have to compare the result to
00747 * an unsigned char *. The easiest way to avoid warnings without
00748 * introducing typecasts is to use two variables. */
00749 char *endptr;
00750 unsigned char *endpos;
00751 long number;
00752
00753 seems_valid(ostr);
00754 gw_assert(nump != NULL);
00755 gw_assert(base == 0 || (base >= 2 && base <= 36));
00756
00757 if (pos >= ostr->len) {
00758 errno = EINVAL;
00759 return -1;
00760 }
00761
00762 errno = 0;
00763 number = strtol(ostr->data + pos, &endptr, base);
00764 endpos = endptr;
00765 if (errno == ERANGE)
00766 return -1;
00767 if (endpos == ostr->data + pos) {
00768 errno = EINVAL;
00769 return -1;
00770 }
00771
00772 *nump = number;
00773 return endpos - ostr->data;
00774 }
|
|
||||||||||||
|
Definition at line 1146 of file octstr.c. References Octstr::data, gw_assert, Octstr::len, and seems_valid. Referenced by main(). 01147 {
01148 unsigned char *p;
01149 long i;
01150
01151 gw_assert(f != NULL);
01152 seems_valid(ostr);
01153
01154 p = ostr->data;
01155 for (i = 0; i < ostr->len; ++i, ++p) {
01156 if (isprint(*p))
01157 fprintf(f, "%c", *p);
01158 else
01159 fprintf(f, "\\x%02x", *p);
01160 }
01161 if (ferror(f))
01162 return -1;
01163 return 0;
01164 }
|
|
||||||||||||
|
Definition at line 1131 of file octstr.c. References Octstr::data, error(), gw_assert, Octstr::len, and seems_valid. Referenced by client_thread(), main(), and write_msg(). 01132 {
01133 gw_assert(f != NULL);
01134 seems_valid(ostr);
01135
01136 if (ostr->len == 0)
01137 return 0;
01138 if (fwrite(ostr->data, ostr->len, 1, f) != 1) {
01139 error(errno, "Couldn't write all of octet string to file.");
01140 return -1;
01141 }
01142 return 0;
01143 }
|
Here is the call graph for this function:

|
|
Definition at line 1488 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(), init_batch(), main(), obey_request(), post_content_create(), push_content_create(), send_file(), smsc_soap_create(), status_cb(), and store_file_load(). 01489 {
01490 FILE *f;
01491 Octstr *os;
01492 char buf[4096];
01493 long n;
01494
01495 gw_assert(filename != NULL);
01496
01497 f = fopen(filename, "r");
01498 if (f == NULL) {
01499 error(errno, "fopen failed: couldn't open `%s'", filename);
01500 return NULL;
01501 }
01502
01503 os = octstr_create("");
01504 if (os == NULL)
01505 goto error;
01506
01507 while ((n = fread(buf, 1, sizeof(buf), f)) > 0)
01508 octstr_insert_data(os, octstr_len(os), buf, n);
01509
01510 (void) fclose(f);
01511 return os;
01512
01513 error:
01514 (void) fclose(f);
01515 octstr_destroy(os);
01516 return NULL;
01517 }
|
Here is the call graph for this function:

|
|
Definition at line 1520 of file octstr.c. References error(), gw_assert, octstr_append_data(), octstr_create, and octstr_destroy(). Referenced by obey_request(). 01521 {
01522 Octstr *os;
01523 char buf[4096];
01524
01525 gw_assert(f != NULL);
01526
01527 os = octstr_create("");
01528 if (os == NULL)
01529 goto error;
01530
01531 while (fgets(buf, sizeof(buf), f) != NULL)
01532 octstr_append_data(os, buf, strlen(buf));
01533
01534 return os;
01535
01536 error:
01537 octstr_destroy(os);
01538 return NULL;
01539 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 2496 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 obey_request_thread(). 02497 {
02498 Octstr *octstr_utf8 = NULL;
02499 Octstr *octstr_final = NULL;
02500 int resultcode = 0;
02501
02502 if (octstr_case_compare(tocode, fromcode) == 0) {
02503 goto cleanup_and_exit;
02504 }
02505
02506 if ((octstr_case_compare(fromcode, octstr_imm ("UTF-8")) != 0) &&
02507 (octstr_case_compare(fromcode, octstr_imm ("UTF8")) != 0)) {
02508 if (charset_to_utf8(orig, &octstr_utf8, fromcode) < 0) {
02509 resultcode = -1;
02510 goto cleanup_and_exit;
02511 }
02512 } else {
02513 octstr_utf8 = octstr_duplicate(orig);
02514 }
02515
02516 if ((octstr_case_compare(tocode, octstr_imm ("UTF-8")) != 0) &&
02517 (octstr_case_compare(tocode, octstr_imm ("UTF8")) != 0)) {
02518 if (charset_from_utf8(octstr_utf8, &octstr_final, tocode) < 0) {
02519 resultcode = -1;
02520 goto cleanup_and_exit;
02521 }
02522 } else {
02523 octstr_final = octstr_duplicate(octstr_utf8);
02524 }
02525
02526 octstr_truncate(orig, 0);
02527 octstr_append(orig, octstr_final);
02528
02529 cleanup_and_exit:
02530 octstr_destroy (octstr_utf8);
02531 octstr_destroy (octstr_final);
02532
02533 return resultcode;
02534 }
|
Here is the call graph for this function:

|