Kannel: Open Source WAP and SMS gateway  svn-r5335
octstr.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2018 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * octstr.h - Octet strings
59  *
60  * This header file declares an abstract data type, Octstr, for storing
61  * and manipulating octet strings: strings of arbitrary binary data in
62  * 8-bit bytes. Unlike C strings, they can contain the NUL byte ('\0').
63  * Conceptually, they consist of a sequence of octets (bytes) and the
64  * length of the sequence. There are various basic operations on octet
65  * strings: concatenating, comparing, printing, etc.
66  *
67  * Octet strings come in two flavors: mutable and immutable. Mutable
68  * octet strings are the normal kind and they can be modified and
69  * otherwise manipulated at will. Immutable octet strings are meant to
70  * be wrappers around a C string literal. They may not be modified, though
71  * they may be destroyed.
72  *
73  * Immutable octet strings are meant to simplify usage of octet strings
74  * together with C strings by reducing the number of octstr_* functions.
75  * For example, we need a function for searching one string within another.
76  * There needs to be different flavors of this: exact search, case-insensitive
77  * search, and a search limited to the first N octets of the strings.
78  * If in each of these one of the arguments may be either an octet string
79  * or a C string, the number of functions doubles. Thus, we use immutable
80  * strings instead:
81  *
82  * octstr_search(os, octstr_imm("foo"), 0)
83  *
84  * The above looks like a memory leak, but it is not. Each immutable
85  * octet string (i.e., with the same C string literal pointer) is really
86  * created only the first time, and octstr_destroy won't destroy it,
87  * either. The immutable octet strings are destroyed automatically when
88  * the process ends.
89  *
90  * See comments below for explanations on individual functions. Note that
91  * all functions use gw_malloc and friends, so they won't return if the
92  * memory allocations fail. Octet string functions are thread safe, as
93  * long as they only one thread at a time operates on each octet string.
94  */
95 
96 #ifndef OCTSTR_H
97 #define OCTSTR_H
98 
99 #include <stdio.h>
100 #include <stdarg.h>
101 
102 #include "list.h"
103 
104 typedef struct Octstr Octstr;
105 
106 
107 /*
108  * Initialize the Octstr subsystem.
109  */
110 void octstr_init(void);
111 
112 
113 /*
114  * Shut down the Octstr subsystem.
115  */
116 void octstr_shutdown(void);
117 
118 
119 /*
120  * Create an octet string from a NUL-terminated C string. Return pointer to
121  * the new object.
122  */
123 Octstr *octstr_create_real(const char *cstr, const char *file, long line,
124  const char *func);
125 #define octstr_create(cstr) \
126  (Octstr*)gw_claim_area(octstr_create_real((cstr), __FILE__, __LINE__, __func__))
127 
128 /*
129  * Create an octet string from arbitrary binary data. The length of the
130  * data is given, so it can contain NUL characters.
131  */
132 Octstr *octstr_create_from_data_real(const char *data, long len, const char *file,
133  long line, const char *func);
134 #define octstr_create_from_data(data, len) \
135  (Octstr*)gw_claim_area(octstr_create_from_data_real((data), (len), __FILE__, __LINE__, __func__))
136 #define octstr_create_from_data_trace(data, len, file, line, func) \
137  (Octstr*)gw_claim_area(octstr_create_from_data_real(data, len, file, line, func))
138 
139 
140 /*
141  * Create an immutable octet string from a C string literal. The
142  * C string literal MUST NOT be modified and it MUST exist until the
143  * octet string is destroyed. The immutable octet string need not be
144  * destroyed - it is destroyed automatically when octstr_shutdown is
145  * called. In fact, octstr_destroy is a no-op for immutables.
146  */
147 Octstr *octstr_imm(const char *cstr);
148 
149 
150 /*
151  * Destroy an octet string, freeing all memory it uses. A NULL argument
152  * is ignored.
153  */
154 void octstr_destroy(Octstr *ostr);
155 
156 
157 /*
158  * Destroy an octet string. Wrapper around octstr_destroy that is callable
159  * via gwlist_destroy.
160  */
161 void octstr_destroy_item(void *os);
162 
163 
164 /*
165  * Return the length of (number of octets in) an object string.
166  */
167 long octstr_len(const Octstr *ostr);
168 
169 
170 /*
171  * Create a new octet string by copying part of an existing one. Return
172  * pointer to the new object. If `from' is after end of `ostr', an empty
173  * octet string is created. If `from+len' is after the end of `ostr',
174  * `len' is reduced appropriately.
175  */
176 Octstr *octstr_copy_real(const Octstr *ostr, long from, long len, const char *file,
177  long line, const char *func);
178 #define octstr_copy(ostr, from, len) \
179  gw_claim_area(octstr_copy_real((ostr), (from), (len), __FILE__, __LINE__, __func__))
180 
181 
182 /*
183  * Copy all of an octet string.
184  */
185 Octstr *octstr_duplicate_real(const Octstr *ostr, const char *file, long line,
186  const char *func);
187 #define octstr_duplicate(ostr) \
188  gw_claim_area(octstr_duplicate_real((ostr), __FILE__, __LINE__, __func__))
189 
190 
191 /*
192  * Create a new octet string by catenating two existing ones. Return
193  * pointer to the new object.
194  */
195 Octstr *octstr_cat(Octstr *ostr1, Octstr *ostr2);
196 
197 
198 /*
199  * Return value of octet at a given position in an octet string. The returned
200  * value has a range of 0..255 for valid positions, and -1 if `pos' is
201  * after the end of the octet string.
202  */
203 int octstr_get_char(const Octstr *ostr, long pos);
204 
205 
206 /*
207  * Replace a single, existing character in an octet string. Operation cannot
208  * fail: if pos is not inside the string, the operation will silently be
209  * ignored.
210  */
211 void octstr_set_char(Octstr *ostr, long pos, int ch);
212 
213 
214 /*
215  * Copy bytes from octet string into array.
216  */
217 void octstr_get_many_chars(char *buf, Octstr *ostr, long pos, long len);
218 
219 
220 /*
221  * Return pointer to contents of octet string as a NUL-terminated C string.
222  * This is guaranteed to have a NUL character at the end, but it is not
223  * guaranteed (how could it?) to not contain NUL characters elsewhere.
224  * The pointer points directly into the internal buffer of the octet
225  * string, and must not be modified, and must not be used after any
226  * octstr_* function that modifies the octet string is called after this
227  * one. It is meant for printing debug messages easily.
228  *
229  * If the octet string is empty, an empty C string is returned, not NULL.
230  */
231 char *octstr_get_cstr_real(const Octstr *ostr, const char *file, long line,
232  const char *func);
233 #define octstr_get_cstr(ostr) \
234  (octstr_get_cstr_real(ostr, __FILE__, __LINE__, __func__))
235 
236 
237 /*
238  * Append characters from printable hexadecimal format at the tail of
239  * an octet string. "78797a" or "78797A" would be converted to "xyz"
240  * and then appended.
241  */
242 void octstr_append_from_hex(Octstr *ostr, char *hex);
243 
244 
245 /* Convert the octet string in-place to printable hexadecimal format.
246  * "xyz" would be converted to "78797a". If the uppercase
247  * flag is set, 'A' through 'F' are used instead of 'a' through 'f'.
248  */
249 void octstr_binary_to_hex(Octstr *ostr, int uppercase);
250 
251 
252 /* Convert the octet string in-place from printable hexadecimal
253  * format to binary. "78797a" or "78797A" would be converted to "xyz".
254  * If the string is not in the expected format, return -1 and leave
255  * the string unchanged. If all was fine, return 0. */
256 int octstr_hex_to_binary(Octstr *ostr);
257 
258 
259 /* Base64-encode the octet string in-place, using the MIME base64
260  * encoding defined in RFC 2045. Note that the result may be
261  * multi-line and is always terminated with a CR LF sequence. */
262 void octstr_binary_to_base64(Octstr *ostr);
263 
264 
265 /* Base64-decode the octet string in-place, using the MIME base64
266  * encoding defined in RFC 2045. */
267 void octstr_base64_to_binary(Octstr *ostr);
268 
269 
270 /* Parse a number at position 'pos' in 'ostr', using the same rules as
271  * strtol uses regarding 'base'. Skip leading whitespace.
272  *
273  * Return the position of the first character after the number,
274  * or -1 if there was an error. Return the length of the octet string
275  * if the number ran to the end of the string.
276  *
277  * Assign the number itself to the location pointed to by 'number', if
278  * there was no error.
279  *
280  * Possible errno values in case of an error:
281  * ERANGE The number did not fit in a long.
282  * EINVAL No digits of the appropriate base were found.
283  */
284 long octstr_parse_long(long *number, Octstr *ostr, long pos, int base);
285 
286 /* As above but parses and assigns double number. */
287 long octstr_parse_double(double *number, Octstr *ostr, long pos);
288 
289 
290 /* Run the 'filter' function over each character in the specified range.
291  * Return 1 if the filter returned true for all characters, otherwise 0.
292  * The octet string is not changed.
293  * For example: ok = octstr_check_range(o, 1, 10, gw_isdigit);
294  */
295 typedef int (*octstr_func_t)(int);
296 int octstr_check_range(Octstr *ostr, long pos, long len,
297  octstr_func_t filter);
298 
299 
300 /* Run the 'map' function over each character in the specified range,
301  * replacing each character with the return value of that function.
302  * For example: octstr_convert_range(o, 1, 10, tolower);
303  */
304 void octstr_convert_range(Octstr *ostr, long pos, long len,
305  octstr_func_t map);
306 
307 /*
308  * Use the octstr_convert_range() with make_printable() to ensure
309  * every char in the octstr can be printed in the current locale. Each
310  * character that is NOT printable is converted to a '.' (dot).
311  */
312 void octstr_convert_printable(Octstr *ostr);
313 
314 
315 /*
316  * Compare two octet strings, returning 0 if they are equal, negative if
317  * `ostr1' is less than `ostr2' (when compared octet-value by octet-value),
318  * and positive if greater.
319  */
320 int octstr_compare(const Octstr *ostr1, const Octstr *ostr2);
321 
322 
323 /*
324  * Like octstr_compare, except compares bytes without case sensitivity.
325  * Note that this probably doesn't work for Unicode, but should work
326  * for such 8-bit character sets as are supported by libc.
327  */
328 int octstr_case_compare(const Octstr *ostr1, const Octstr *ostr2);
329 
330 
331 /*
332  * as above, but comparing is done only up to n bytes
333  */
334 int octstr_ncompare(const Octstr *ostr1, const Octstr *ostr2, long n);
335 
336 
337 /*
338  * Same as octstr_compare, but compares the content of the octet string to
339  * a C string.
340  */
341 int octstr_str_compare(const Octstr *ostr1, const char *str);
342 
343 
344 /*
345  * Like octstr_str_compare, except compares bytes without case sensitifity.
346  */
347 int octstr_str_case_compare(const Octstr *ostr1, const char *str);
348 
349 
350 /*
351  * Same as octstr_str_compare, but comparing is done only up to n bytes.
352  */
353 int octstr_str_ncompare(const Octstr *ostr, const char *str, long n);
354 
355 
356 /*
357  * Write contents of octet string to a file. Return -1 for error, 0 for OK.
358  */
359 int octstr_print(FILE *f, Octstr *ostr);
360 
361 
362 /*
363  * Search the character from octet string starting from position pos. Returns
364  * the position (index) of the char in string, -1 if not found.
365  */
366 long octstr_search_char(const Octstr *ostr, int ch, long pos);
367 
368 
369 /*
370  * Search the character backwards from octet string starting from position pos. Returns
371  * the position (index) of the char in string, -1 if not found.
372  */
373 long octstr_rsearch_char(const Octstr *ostr, int ch, long pos);
374 
375 
376 /*
377  * Search several character from octet string starting from position pos. Returns
378  * the position (index) of the first char found in string, -1 if none was found.
379  */
380 long octstr_search_chars(const Octstr *ostr, const Octstr *chars, long pos);
381 
382 
383 /*
384  * Search for the octet string 'needle' in the octet string 'haystack'.
385  * Return the start position (index) of 'needle' in 'haystack'.
386  * Return -1 if not found.
387  */
388 long octstr_search(const Octstr *haystack, const Octstr *needle, long pos);
389 
390 
391 /*
392  * Like octstr_search, but ignores 8-bit byte case.
393  */
394 long octstr_case_search(const Octstr *haystack, const Octstr *needle, long pos);
395 
396 /*
397  * Like octstr_case_search, but searchs only first n octets.
398  */
399 long octstr_case_nsearch(const Octstr *haystack, const Octstr *needle, long pos, long n);
400 
401 /*
402  * Like octstr_search, but with needle as C-String.
403  */
404 long octstr_str_search(const Octstr *haystack, const char *needle, long pos);
405 
406 /*
407  * Write contents of octet string to a file, in human readable form.
408  * Return -1 for error, 0 for OK. Octets that are not printable characters
409  * are printed using C-style escape notation.
410  */
411 int octstr_pretty_print(FILE *f, Octstr *ostr);
412 
413 
414 /*
415  * Write contents of octet string to a socket. Return -1 for error, 0 for OK.
416  */
417 int octstr_write_to_socket(int socket, Octstr *ostr);
418 
419 /*
420  * Write contents of octet string starting at 'from' to a
421  * non-blocking file descriptor.
422  * Return the number of octets written. Return -1 for error.
423  * It is possible for this function to write only part of the octstr.
424  */
425 long octstr_write_data(Octstr *ostr, int fd, long from);
426 
427 /*
428  * Read available data from socket and return it as an octstr.
429  * Block if no data is available. If a lot of data is available,
430  * read only up to an internal limit.
431  * Return -1 for error.
432  */
433 int octstr_append_from_socket(Octstr *ostr, int socket);
434 
435 /*
436  * Insert one octet string into another. `pos' gives the position
437  * in `ostr1' where `ostr2' should be inserted.
438  */
439 void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos);
440 
441 
442 /*
443  * Insert characters from C array into an octet string. `pos'
444  * gives the position in `ostr' where `data' should be inserted. `len'
445  * gives the number of characters in `data'.
446  * If the given `pos' is greater than the length of the input octet string,
447  * it is set to that length, resulting in an append.
448  */
449 void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len);
450 
451 /*
452  * Similar as previous, expect that now a single character is inserted.
453  */
454 void octstr_insert_char(Octstr *ostr, long pos, const char c);
455 
456 
457 /*
458  * Append characters from C array at the tail of an octet string.
459  */
460 void octstr_append_data(Octstr *ostr, const char *data, long len);
461 
462 
463 /*
464  * Append a second octstr to the first.
465  */
466 void octstr_append(Octstr *ostr1, const Octstr *ostr2);
467 
468 
469 /*
470  * Append a normal C string at the tail of an octet string.
471  */
472 void octstr_append_cstr(Octstr *ostr, const char *cstr);
473 
474 
475 /*
476  * Append a single character at the tail of an octet string.
477  */
478 void octstr_append_char(Octstr *ostr, int ch);
479 
480 
481 /*
482  * Truncate octet string at `new_len'. If new_len is same or more
483  * than current, do nothing.
484  */
485 void octstr_truncate(Octstr *ostr, int new_len);
486 
487 
488 /*
489  * Strip white space from start and end of a octet string.
490  */
491 void octstr_strip_blanks(Octstr *ostr);
492 
493 /*
494  * Strip CR and LF from start and end of a octet string.
495  */
496 void octstr_strip_crlfs(Octstr *ostr);
497 
498 /*
499  * Strip non-alphanums from start and end of a octet string.
500  */
502 
503 
504 /*
505  * Shrink consecutive white space characters into one space.
506  */
507 void octstr_shrink_blanks(Octstr *ostr);
508 
509 
510 /*
511  * Delete part of an octet string.
512  */
513 void octstr_delete(Octstr *ostr1, long pos, long len);
514 
515 
516 /*
517  * Read the contents of a named file to an octet string. Return pointer to
518  * octet string.
519  */
520 Octstr *octstr_read_file(const char *filename);
521 
522 
523 /*
524  * Read the contents of a file descriptor pipe to an octet string.
525  * Return pointer to octet string.
526  */
527 Octstr *octstr_read_pipe(FILE *f);
528 
529 
530 /*
531  * Split an octet string into words at whitespace, and return a list
532  * containing the new octet strings.
533  */
534 List *octstr_split_words(const Octstr *ostr);
535 
536 
537 /*
538  * Split an octet string into substrings at every occurence of `sep'.
539  * Return List with the substrings.
540  */
541 List *octstr_split(const Octstr *os, const Octstr *sep);
542 
543 
544 /*
545  * Compare two octet strings in a manner suitable for gwlist_search.
546  */
547 int octstr_item_match(void *item, void *pattern);
548 
549 
550 /*
551  * Same as above, except compares bytes without case sensitivity
552  */
553 int octstr_item_case_match(void *item, void *pattern);
554 
555 
556 /*
557  * Print debugging information about octet string. This is abstracted to the
558  * various log levels we have: GW_DEBUG, GW_INFO, GW_WARNING, GW_ERROR
559  *
560  * If a third parameter in the argument list is given, we will dump the
561  * octstr in that log level instead of the default GW_DEBUG level.
562  */
563 void octstr_dump_real(const Octstr *ostr, int level, ...);
564 #define octstr_dump(ostr, level, ...) \
565  octstr_dump_real(ostr, level, GW_DEBUG, ##__VA_ARGS__)
566 
567 
568 /*
569  * Write the contents of an octet string to the debug log.
570  * Keep it on one line if the octet string is short and printable,
571  * otherwise use a hex dump.
572  */
573 void octstr_dump_short(Octstr *ostr, int level, const char *name);
574 
575 
576 /*
577  * decode url-encoded octstr in-place.
578  * Return 0 if all went fine, or -1 if there was some garbage
579  */
580 int octstr_url_decode(Octstr *ostr);
581 
582 
583 /*
584  * URL encode the argument string in place.
585  */
586 void octstr_url_encode(Octstr *ostr);
587 
588 
589 /*
590  * Treat the octstr as an unsigned array of bits, most significant bit
591  * first, and return the indicated bit range as an integer. numbits
592  * must not be larger than 32. Bits beyond the end of the string will
593  * be read as 0.
594  */
595 long octstr_get_bits(Octstr *ostr, long bitpos, int numbits);
596 
597 
598 /*
599  * Treat the octstr as an unsigned array of bits, most significant bit
600  * first, and set the indicated bit range to the given value. numbits
601  * must not be larger than 32. The value must fit in that number of bits.
602  * The string will be extended with 0-valued octets as necessary to hold
603  * the indicated bit range.
604  */
605 void octstr_set_bits(Octstr *ostr, long bitpos, int numbits,
606  unsigned long value);
607 
608 
609 /*
610  * Encode value in WSP's uintvar format, and append it to the octstr
611  */
612 void octstr_append_uintvar(Octstr *ostr, unsigned long value);
613 
614 
615 /*
616  * Decode a value in WSP's uintvar format at position pos of the octstr,
617  * and put the result in *value. Return the position after the uintvar.
618  * Return -1 if there is not a valid uintvar at pos.
619  */
620 long octstr_extract_uintvar(Octstr *ostr, unsigned long *value, long pos);
621 
622 
623 /*
624  * Append the decimal representation of the given value to ostr
625  */
626 void octstr_append_decimal(Octstr *ostr, long value);
627 
628 
629 /*
630  * Create a new octet string based on a printf-like (but not identical)
631  * format string, and a list of other arguments. The format string is
632  * a C string for convenience, but this may change later.
633  *
634  * The syntax for the format string is as follows:
635  *
636  * % [-] [0] [width] [. prec] [type] conversion
637  *
638  * where [] denotes optional parts and the various parts have the
639  * following meanings:
640  *
641  * - add padding to the right, instead of the left of the field
642  *
643  * 0 pad with zeroes, not spaces
644  *
645  * width minimum output width; non-negative integer or '*', indicating
646  * that the next argument is an int and gives the width
647  *
648  * . a dot to indicate that precision follows
649  *
650  * prec precision: maximum length of strings, maximum number of
651  * decimals for floating point numbers; non-negative integer
652  * or '*' indicating that the next argument is an int and
653  * gives the precision
654  *
655  * type type of integer argument: either h (for short int) or
656  * l (for long int); may only be used with conversion 'd'
657  *
658  * conversion
659  * how the field is to be converted, also implicitly defines
660  * the type of the next argument; one of
661  *
662  * d int (unless type says otherwise)
663  * output as a decimal integer
664  *
665  * e, f, g double
666  * output in various formats of floating
667  * point, see printf(3) for details
668  *
669  * s char *
670  * output as character string
671  *
672  * S Octstr *
673  * output as character string, except '\0'
674  * inside the string is included in the
675  * output
676  *
677  * E Octstr *
678  * output as character string, except that
679  * contents are URL-encoded when need to. Note
680  * that trunctae is done afterwards and can
681  * cut escape '%EE' in half
682  *
683  * H Octstr *
684  * output as character string, except that
685  * contents are HEX-encoded in uppercase
686  */
687 Octstr *octstr_format(const char *fmt, ...);
688 
689 /*
690  * Like octstr_format, but takes the argument list as a va_list.
691  */
692 Octstr *octstr_format_valist_real(const char *fmt, va_list args);
693 #define octstr_format_valist(fmt, args) gw_claim_area(octstr_format_valist_real(fmt, args))
694 
695 /*
696  * Like octstr_format, but appends output to an existing octet
697  * string, instead of creating a new one.
698  */
699 void octstr_format_append(Octstr *os, const char *fmt, ...);
700 
701 
702 /*
703  * Compute a hash key value for an octet string by adding all the
704  * octets together.
705  */
706 unsigned long octstr_hash_key(Octstr *ostr);
707 
708 /*
709  * return an Octstr encoded in charset named tocode created from the data
710  * in the Octstr orig that is encoded in the charset fromcode.
711  */
712 int octstr_recode(Octstr *tocode, Octstr *fromcode, Octstr *orig);
713 
714 /*
715  * Strip all occurence of char ch from start of Octstr
716  */
717 void octstr_strip_char(Octstr *text, char ch);
718 
719 /*
720  * Check if ostr is numeric
721  */
722 int octstr_isnum(Octstr *ostr1);
723 
724 /*
725  * Replace all occurences of needle with repl within haystack
726  */
727 void octstr_replace(Octstr *haystack, Octstr *needle, Octstr *repl);
728 
729 /*
730  * Replace first occurence of needle with repl within haystack
731  */
732 void octstr_replace_first(Octstr *haystack, Octstr *needle, Octstr *repl);
733 
734 /*
735  * Symbolize hex string '78797a' becomes '%78%79%7a'
736  */
737 int octstr_symbolize(Octstr *ostr);
738 
739 /*
740  * Remove all occurrences of 'needle' within 'haystack'.
741  */
742 void octstr_delete_matching(Octstr *haystack, Octstr *needle);
743 
744 /*
745  * Return 1, if octstr 'os' contains only hex chars, 0 otherwise.
746  */
747 int octstr_is_all_hex(Octstr *os);
748 
749 /*
750  * make data HTML safe by converting appropriate characters to HTML entities.
751  * conversion is done in place
752  */
754 
755 /*
756  * convert HTML safe data back to binary data by replacing HTML entities with their
757  * respective character values.
758  * conversion is done in place
759  */
761 
762 #endif
int octstr_hex_to_binary(Octstr *ostr)
Definition: octstr.c:494
int number
Definition: smsc_cimd2.c:213
void octstr_convert_to_html_entities(Octstr *input)
Definition: octstr.c:2738
void octstr_base64_to_binary(Octstr *ostr)
Definition: octstr.c:663
long octstr_parse_double(double *number, Octstr *ostr, long pos)
Definition: octstr.c:782
int(* octstr_func_t)(int)
Definition: octstr.h:295
Octstr * octstr_duplicate_real(const Octstr *ostr, const char *file, long line, const char *func)
Definition: octstr.c:373
int octstr_pretty_print(FILE *f, Octstr *ostr)
Definition: octstr.c:1206
long octstr_parse_long(long *number, Octstr *ostr, long pos, int base)
Definition: octstr.c:749
Octstr * octstr_create_from_data_real(const char *data, long len, const char *file, long line, const char *func)
Definition: octstr.c:250
List * octstr_split(const Octstr *os, const Octstr *sep)
Definition: octstr.c:1640
List * octstr_split_words(const Octstr *ostr)
Definition: octstr.c:1602
unsigned long octstr_hash_key(Octstr *ostr)
Definition: octstr.c:2523
void octstr_convert_from_html_entities(Octstr *input)
Definition: octstr.c:2804
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
int octstr_str_ncompare(const Octstr *ostr, const char *str, long n)
Definition: octstr.c:999
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1303
long octstr_get_bits(Octstr *ostr, long bitpos, int numbits)
Definition: octstr.c:1803
void octstr_delete_matching(Octstr *haystack, Octstr *needle)
Definition: octstr.c:2702
void octstr_strip_char(Octstr *text, char ch)
Definition: octstr.c:2616
long octstr_extract_uintvar(Octstr *ostr, unsigned long *value, long pos)
Definition: octstr.c:1954
long octstr_search_chars(const Octstr *ostr, const Octstr *chars, long pos)
Definition: octstr.c:1052
int octstr_isnum(Octstr *ostr1)
Definition: octstr.c:2634
Octstr * octstr_create_real(const char *cstr, const char *file, long line, const char *func)
Definition: octstr.c:243
void octstr_set_char(Octstr *ostr, long pos, int ch)
Definition: octstr.c:415
FILE * file
Definition: log.c:169
int octstr_str_case_compare(const Octstr *ostr1, const char *str)
Definition: octstr.c:986
int octstr_check_range(Octstr *ostr, long pos, long len, octstr_func_t filter)
Definition: octstr.c:814
void octstr_destroy_item(void *os)
Definition: octstr.c:336
Octstr * octstr_cat(Octstr *ostr1, Octstr *ostr2)
Definition: octstr.c:383
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2507
static Octstr * from
Definition: mtbatch.c:95
int octstr_case_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:903
void octstr_append_char(Octstr *ostr, int ch)
Definition: octstr.c:1517
void octstr_strip_crlfs(Octstr *ostr)
Definition: octstr.c:1378
int octstr_is_all_hex(Octstr *os)
Definition: octstr.c:2717
void octstr_replace(Octstr *haystack, Octstr *needle, Octstr *repl)
Definition: octstr.c:2649
void octstr_dump_short(Octstr *ostr, int level, const char *name)
Definition: octstr.c:2144
void octstr_append_uintvar(Octstr *ostr, unsigned long value)
Definition: octstr.c:1931
char * text
Definition: smsc_cimd2.c:921
void octstr_shrink_blanks(Octstr *ostr)
Definition: octstr.c:1433
void octstr_get_many_chars(char *buf, Octstr *ostr, long pos, long len)
Definition: octstr.c:425
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
void octstr_convert_range(Octstr *ostr, long pos, long len, octstr_func_t map)
Definition: octstr.c:836
void octstr_shutdown(void)
Definition: octstr.c:226
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1511
int octstr_symbolize(Octstr *ostr)
Definition: octstr.c:2679
void octstr_url_encode(Octstr *ostr)
Definition: octstr.c:1673
char * name
Definition: smsc_cimd2.c:212
int octstr_append_from_socket(Octstr *ostr, int socket)
Definition: octstr.c:1280
long octstr_str_search(const Octstr *haystack, const char *needle, long pos)
Definition: octstr.c:1157
Octstr * octstr_read_pipe(FILE *f)
Definition: octstr.c:1580
void octstr_set_bits(Octstr *ostr, long bitpos, int numbits, unsigned long value)
Definition: octstr.c:1849
void octstr_truncate(Octstr *ostr, int new_len)
Definition: octstr.c:1327
char filename[FILENAME_MAX+1]
Definition: log.c:171
int octstr_write_to_socket(int socket, Octstr *ostr)
Definition: octstr.c:1227
void octstr_binary_to_base64(Octstr *ostr)
Definition: octstr.c:542
long octstr_case_nsearch(const Octstr *haystack, const Octstr *needle, long pos, long n)
Definition: octstr.c:1129
int octstr_print(FILE *f, Octstr *ostr)
Definition: octstr.c:1191
void octstr_append_from_hex(Octstr *ostr, char *hex)
Definition: octstr.c:451
Octstr * octstr_format_valist_real(const char *fmt, va_list args)
Definition: octstr.c:2476
int octstr_str_compare(const Octstr *ostr1, const char *str)
Definition: octstr.c:973
void octstr_binary_to_hex(Octstr *ostr, int uppercase)
Definition: octstr.c:465
Definition: octstr.c:118
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
void octstr_init(void)
Definition: octstr.c:218
int octstr_ncompare(const Octstr *ostr1, const Octstr *ostr2, long n)
Definition: octstr.c:952
long octstr_case_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1102
int octstr_recode(Octstr *tocode, Octstr *fromcode, Octstr *orig)
Definition: octstr.c:2576
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871
int octstr_item_match(void *item, void *pattern)
Definition: octstr.c:1661
int octstr_url_decode(Octstr *ostr)
Definition: octstr.c:1746
void octstr_dump_real(const Octstr *ostr, int level,...)
Definition: octstr.c:2115
void octstr_replace_first(Octstr *haystack, Octstr *needle, Octstr *repl)
Definition: octstr.c:2664
void octstr_strip_nonalphanums(Octstr *ostr)
Definition: octstr.c:1405
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1497
int octstr_item_case_match(void *item, void *pattern)
Definition: octstr.c:1667
char * octstr_get_cstr_real(const Octstr *ostr, const char *file, long line, const char *func)
Definition: octstr.c:439
void octstr_strip_blanks(Octstr *ostr)
Definition: octstr.c:1346
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
long octstr_rsearch_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1031
long octstr_write_data(Octstr *ostr, int fd, long from)
Definition: octstr.c:1255
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1548
void octstr_insert_char(Octstr *ostr, long pos, const char c)
Definition: octstr.c:1481
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: list.c:102
void octstr_append_decimal(Octstr *ostr, long value)
Definition: octstr.c:1976
Octstr * octstr_copy_real(const Octstr *ostr, long from, long len, const char *file, long line, const char *func)
Definition: octstr.c:351
void octstr_convert_printable(Octstr *ostr)
Definition: octstr.c:864
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1070
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.