Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

octstr.h

Go to the documentation of this file.
00001 /* ==================================================================== 
00002  * The Kannel Software License, Version 1.0 
00003  * 
00004  * Copyright (c) 2001-2008 Kannel Group  
00005  * Copyright (c) 1998-2001 WapIT Ltd.   
00006  * All rights reserved. 
00007  * 
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met: 
00011  * 
00012  * 1. Redistributions of source code must retain the above copyright 
00013  *    notice, this list of conditions and the following disclaimer. 
00014  * 
00015  * 2. Redistributions in binary form must reproduce the above copyright 
00016  *    notice, this list of conditions and the following disclaimer in 
00017  *    the documentation and/or other materials provided with the 
00018  *    distribution. 
00019  * 
00020  * 3. The end-user documentation included with the redistribution, 
00021  *    if any, must include the following acknowledgment: 
00022  *       "This product includes software developed by the 
00023  *        Kannel Group (http://www.kannel.org/)." 
00024  *    Alternately, this acknowledgment may appear in the software itself, 
00025  *    if and wherever such third-party acknowledgments normally appear. 
00026  * 
00027  * 4. The names "Kannel" and "Kannel Group" must not be used to 
00028  *    endorse or promote products derived from this software without 
00029  *    prior written permission. For written permission, please  
00030  *    contact org@kannel.org. 
00031  * 
00032  * 5. Products derived from this software may not be called "Kannel", 
00033  *    nor may "Kannel" appear in their name, without prior written 
00034  *    permission of the Kannel Group. 
00035  * 
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00039  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 
00040  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
00041  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
00042  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
00043  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
00045  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
00046  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00047  * ==================================================================== 
00048  * 
00049  * This software consists of voluntary contributions made by many 
00050  * individuals on behalf of the Kannel Group.  For more information on  
00051  * the Kannel Group, please see <http://www.kannel.org/>. 
00052  * 
00053  * Portions of this software are based upon software originally written at  
00054  * WapIT Ltd., Helsinki, Finland for the Kannel project.  
00055  */ 
00056 
00057 /*
00058  * octstr.h - Octet strings
00059  *
00060  * This header file declares an abstract data type, Octstr, for storing
00061  * and manipulating octet strings: strings of arbitrary binary data in
00062  * 8-bit bytes. Unlike C strings, they can contain the NUL byte ('\0').
00063  * Conceptually, they consist of a sequence of octets (bytes) and the
00064  * length of the sequence. There are various basic operations on octet
00065  * strings: concatenating, comparing, printing, etc.
00066  *
00067  * Octet strings come in two flavors: mutable and immutable. Mutable
00068  * octet strings are the normal kind and they can be modified and
00069  * otherwise manipulated at will. Immutable octet strings are meant to
00070  * be wrappers around a C string literal. They may not be modified, though
00071  * they may be destroyed.
00072  *
00073  * Immutable octet strings are meant to simplify usage of octet strings
00074  * together with C strings by reducing the number of octstr_* functions.
00075  * For example, we need a function for searching one string within another.
00076  * There needs to be different flavors of this: exact search, case-insensitive
00077  * search, and a search limited to the first N octets of the strings.
00078  * If in each of these one of the arguments may be either an octet string
00079  * or a C string, the number of functions doubles. Thus, we use immutable
00080  * strings instead:
00081  *
00082  *  octstr_search(os, octstr_imm("foo"), 0)
00083  *
00084  * The above looks like a memory leak, but it is not. Each immutable
00085  * octet string (i.e., with the same C string literal pointer) is really 
00086  * created only the first time, and octstr_destroy won't destroy it,
00087  * either. The immutable octet strings are destroyed automatically when
00088  * the process ends.
00089  *
00090  * See comments below for explanations on individual functions. Note that
00091  * all functions use gw_malloc and friends, so they won't return if the
00092  * memory allocations fail. Octet string functions are thread safe, as
00093  * long as they only one thread at a time operates on each octet string.
00094  */
00095 
00096 #ifndef OCTSTR_H
00097 #define OCTSTR_H
00098 
00099 #include <stdio.h>
00100 #include <stdarg.h>
00101 
00102 #include "list.h"
00103 
00104 typedef struct Octstr Octstr;
00105 
00106 
00107 /*
00108  * Initialize the Octstr subsystem.
00109  */
00110 void octstr_init(void);
00111 
00112 
00113 /*
00114  * Shut down the Octstr subsystem.
00115  */
00116 void octstr_shutdown(void);
00117 
00118 
00119 /*
00120  * Create an octet string from a NUL-terminated C string. Return pointer to
00121  * the new object.
00122  */
00123 Octstr *octstr_create_real(const char *cstr, const char *file, long line,
00124                            const char *func);
00125 #define octstr_create(cstr) \
00126     (Octstr*)gw_claim_area(octstr_create_real((cstr), __FILE__, __LINE__, __func__))
00127 
00128 /*
00129  * Create an octet string from arbitrary binary data. The length of the
00130  * data is given, so it can contain NUL characters.
00131  */
00132 Octstr *octstr_create_from_data_real(const char *data, long len, const char *file,
00133                                      long line, const char *func);
00134 #define octstr_create_from_data(data, len) \
00135     (Octstr*)gw_claim_area(octstr_create_from_data_real((data), (len), __FILE__, __LINE__, __func__))
00136 #define octstr_create_from_data_trace(data, len, file, line, func) \
00137     (Octstr*)gw_claim_area(octstr_create_from_data_real(data, len, file, line, func))
00138 
00139 
00140 /*
00141  * Create an immutable octet string from a C string literal. The
00142  * C string literal MUST NOT be modified and it MUST exist until the
00143  * octet string is destroyed. The immutable octet string need not be
00144  * destroyed - it is destroyed automatically when octstr_shutdown is
00145  * called. In fact, octstr_destroy is a no-op for immutables.
00146  */
00147 Octstr *octstr_imm(const char *cstr);
00148 
00149 
00150 /*
00151  * Destroy an octet string, freeing all memory it uses. A NULL argument
00152  * is ignored.
00153  */
00154 void octstr_destroy(Octstr *ostr);
00155 
00156 
00157 /*
00158  * Destroy an octet string. Wrapper around octstr_destroy that is callable
00159  * via gwlist_destroy.
00160  */
00161 void octstr_destroy_item(void *os);
00162 
00163 
00164 /*
00165  * Return the length of (number of octets in) an object string.
00166  */
00167 long octstr_len(const Octstr *ostr);
00168 
00169 
00170 /*
00171  * Create a new octet string by copying part of an existing one. Return 
00172  * pointer to the new object. If `from' is after end of `ostr', an empty
00173  * octet string is created. If `from+len' is after the end of `ostr', 
00174  * `len' is reduced appropriately.
00175  */
00176 Octstr *octstr_copy_real(const Octstr *ostr, long from, long len, const char *file,
00177                          long line, const char *func);
00178 #define octstr_copy(ostr, from, len) \
00179     gw_claim_area(octstr_copy_real((ostr), (from), (len), __FILE__, __LINE__, __func__))
00180 
00181 
00182 /*
00183  * Copy all of an octet string.
00184  */
00185 Octstr *octstr_duplicate_real(const Octstr *ostr, const char *file, long line,
00186                               const char *func);
00187 #define octstr_duplicate(ostr) \
00188     gw_claim_area(octstr_duplicate_real((ostr), __FILE__, __LINE__, __func__))
00189 
00190 
00191 /*
00192  * Create a new octet string by catenating two existing ones. Return 
00193  * pointer to the new object.
00194  */
00195 Octstr *octstr_cat(Octstr *ostr1, Octstr *ostr2);
00196 
00197 
00198 /*
00199  * Return value of octet at a given position in an octet string. The returned
00200  * value has a range of 0..255 for valid positions, and -1 if `pos' is
00201  * after the end of the octet string.
00202  */
00203 int octstr_get_char(const Octstr *ostr, long pos);
00204 
00205 
00206 /*
00207  * Replace a single, existing character in an octet string. Operation cannot
00208  * fail: if pos is not inside the string, the operation will silently be
00209  * ignored.
00210  */
00211 void octstr_set_char(Octstr *ostr, long pos, int ch);
00212 
00213 
00214 /*
00215  * Copy bytes from octet string into array.
00216  */
00217 void octstr_get_many_chars(char *buf, Octstr *ostr, long pos, long len);
00218 
00219 
00220 /*
00221  * Return pointer to contents of octet string as a NUL-terminated C string.
00222  * This is guaranteed to have a NUL character at the end, but it is not
00223  * guaranteed (how could it?) to not contain NUL characters elsewhere.
00224  * The pointer points directly into the internal buffer of the octet
00225  * string, and must not be modified, and must not be used after any
00226  * octstr_* function that modifies the octet string is called after this
00227  * one. It is meant for printing debug messages easily.
00228  *
00229  * If the octet string is empty, an empty C string is returned, not NULL.
00230  */
00231 char *octstr_get_cstr_real(const Octstr *ostr, const char *file, long line,
00232                            const char *func);
00233 #define octstr_get_cstr(ostr) \
00234     (octstr_get_cstr_real(ostr, __FILE__, __LINE__, __func__))
00235 
00236 
00237 /*
00238  * Append characters from printable hexadecimal format at the tail of 
00239  * an octet string. "78797a" or "78797A" would be converted to "xyz"
00240  * and then appended.
00241  */
00242 void octstr_append_from_hex(Octstr *ostr, char *hex);
00243 
00244 
00245 /* Convert the octet string in-place to printable hexadecimal format.
00246  * "xyz" would be converted to "78797a".  If the uppercase
00247  * flag is set, 'A' through 'F' are used instead of 'a' through 'f'.
00248  */
00249 void octstr_binary_to_hex(Octstr *ostr, int uppercase);
00250 
00251 
00252 /* Convert the octet string in-place from printable hexadecimal
00253  * format to binary.  "78797a" or "78797A" would be converted to "xyz".
00254  * If the string is not in the expected format, return -1 and leave
00255  * the string unchanged.  If all was fine, return 0. */
00256 int octstr_hex_to_binary(Octstr *ostr);
00257 
00258 
00259 /* Base64-encode the octet string in-place, using the MIME base64
00260  * encoding defined in RFC 2045.  Note that the result may be
00261  * multi-line and is always terminated with a CR LF sequence.  */
00262 void octstr_binary_to_base64(Octstr *ostr);
00263 
00264 
00265 /* Base64-decode the octet string in-place, using the MIME base64
00266  * encoding defined in RFC 2045. */
00267 void octstr_base64_to_binary(Octstr *ostr);
00268 
00269 
00270 /* Parse a number at position 'pos' in 'ostr', using the same rules as
00271  * strtol uses regarding 'base'.  Skip leading whitespace.
00272  * 
00273  * Return the position of the first character after the number,
00274  * or -1 if there was an error.  Return the length of the octet string
00275  * if the number ran to the end of the string.
00276  * 
00277  * Assign the number itself to the location pointed to by 'number', if
00278  * there was no error.
00279  * 
00280  * Possible errno values in case of an error:
00281  *    ERANGE    The number did not fit in a long.
00282  *    EINVAL    No digits of the appropriate base were found.
00283  */
00284 long octstr_parse_long(long *number, Octstr *ostr, long pos, int base);
00285 
00286 /* As above but parses and assigns double number. */
00287 long octstr_parse_double(double *number, Octstr *ostr, long pos);
00288 
00289 
00290 /* Run the 'filter' function over each character in the specified range.
00291  * Return 1 if the filter returned true for all characters, otherwise 0.
00292  * The octet string is not changed.
00293  * For example: ok = octstr_check_range(o, 1, 10, gw_isdigit);
00294  */
00295 typedef int (*octstr_func_t)(int);
00296 int octstr_check_range(Octstr *ostr, long pos, long len, 
00297                        octstr_func_t filter);
00298 
00299 
00300 /* Run the 'map' function over each character in the specified range,
00301  * replacing each character with the return value of that function.
00302  * For example: octstr_convert_range(o, 1, 10, tolower);
00303  */
00304 void octstr_convert_range(Octstr *ostr, long pos, long len, 
00305                           octstr_func_t map);
00306 
00307 /*
00308  * Use the octstr_convert_range() with make_printable() to ensure
00309  * every char in the octstr can be printed in the current locale. Each
00310  * character that is NOT printable is converted to a '.' (dot).
00311  */
00312 void octstr_convert_printable(Octstr *ostr);
00313 
00314 
00315 /*
00316  * Compare two octet strings, returning 0 if they are equal, negative if
00317  * `ostr1' is less than `ostr2' (when compared octet-value by octet-value),
00318  * and positive if greater.
00319  */
00320 int octstr_compare(const Octstr *ostr1, const Octstr *ostr2);
00321 
00322 
00323 /*
00324  * Like octstr_compare, except compares bytes without case sensitivity.
00325  * Note that this probably doesn't work for Unicode, but should work
00326  * for such 8-bit character sets as are supported by libc.
00327  */
00328 int octstr_case_compare(const Octstr *ostr1, const Octstr *ostr2);
00329 
00330 
00331 /*
00332  * as above, but comparing is done only up to n bytes
00333  */
00334 int octstr_ncompare(const Octstr *ostr1, const Octstr *ostr2, long n);
00335 
00336 
00337 /*
00338  * Same as octstr_compare, but compares the content of the octet string to 
00339  * a C string.
00340  */
00341 int octstr_str_compare(const Octstr *ostr1, const char *str);
00342 
00343 
00344 /*
00345  * Like octstr_str_compare, except compares bytes without case sensitifity.
00346  */
00347 int octstr_str_case_compare(const Octstr *ostr1, const char *str);
00348  
00349 
00350 /*
00351  * Same as octstr_str_compare, but comparing is done only up to n bytes.
00352  */
00353 int octstr_str_ncompare(const Octstr *ostr, const char *str, long n);
00354 
00355 
00356 /*
00357  * Write contents of octet string to a file. Return -1 for error, 0 for OK.
00358  */
00359 int octstr_print(FILE *f, Octstr *ostr);
00360 
00361 
00362 /*
00363  * Search the character from octet string starting from position pos. Returns 
00364  * the position (index) of the char in string, -1 if not found.
00365  */
00366 int octstr_search_char(const Octstr *ostr, int ch, long pos);
00367 
00368 
00369 /*
00370  * Search several character from octet string starting from position pos. Returns 
00371  * the position (index) of the first char found in string, -1 if none was found.
00372  */
00373 int octstr_search_chars(const Octstr *ostr, const Octstr *chars, long pos);
00374 
00375 
00376 /*
00377  * Search for the octet string 'needle' in the octet string 'haystack'.
00378  * Return the start position (index) of 'needle' in 'haystack'.
00379  * Return -1 if not found.
00380  */
00381 int octstr_search(const Octstr *haystack, const Octstr *needle, long pos);
00382 
00383 
00384 /*
00385  * Like octstr_search, but ignores 8-bit byte case.
00386  */
00387 int octstr_case_search(const Octstr *haystack, const Octstr *needle, long pos);
00388 
00389 /*
00390  * Like octstr_case_search, but searchs only first n octets.
00391  */
00392 int octstr_case_nsearch(const Octstr *haystack, const Octstr *needle, long pos, long n);
00393 
00394 /*
00395  * Write contents of octet string to a file, in human readable form. 
00396  * Return -1 for error, 0 for OK. Octets that are not printable characters
00397  * are printed using C-style escape notation.
00398  */
00399 int octstr_pretty_print(FILE *f, Octstr *ostr);
00400 
00401 
00402 /*
00403  * Write contents of octet string to a socket. Return -1 for error, 0 for OK.
00404  */
00405 int octstr_write_to_socket(int socket, Octstr *ostr);
00406 
00407 /*
00408  * Write contents of octet string starting at 'from' to a
00409  * non-blocking file descriptor.
00410  * Return the number of octets written.  Return -1 for error.
00411  * It is possible for this function to write only part of the octstr.
00412  */
00413 long octstr_write_data(Octstr *ostr, int fd, long from);
00414 
00415 /*
00416  * Read available data from socket and return it as an octstr.
00417  * Block if no data is available.  If a lot of data is available,
00418  * read only up to an internal limit.
00419  * Return -1 for error.
00420  */
00421 int octstr_append_from_socket(Octstr *ostr, int socket);
00422 
00423 /*
00424  * Insert one octet string into another. `pos' gives the position
00425  * in `ostr1' where `ostr2' should be inserted.
00426  */
00427 void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos);
00428 
00429 
00430 /*
00431  * Insert characters from C array into an octet string. `pos' 
00432  * gives the position in `ostr' where `data' should be inserted. `len'
00433  * gives the number of characters in `data'.
00434  * If the given `pos' is greater than the length of the input octet string,
00435  * it is set to that length, resulting in an append.
00436  */
00437 void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len);
00438 
00439 /*
00440  * Similar as previous, expect that now a single character is inserted.
00441  */
00442 void octstr_insert_char(Octstr *ostr, long pos, const char c);
00443 
00444 
00445 /*
00446  * Append characters from C array at the tail of an octet string.
00447  */
00448 void octstr_append_data(Octstr *ostr, const char *data, long len);
00449 
00450 
00451 /*
00452  * Append a second octstr to the first.
00453  */
00454 void octstr_append(Octstr *ostr1, const Octstr *ostr2);
00455 
00456 
00457 /*
00458  * Append a normal C string at the tail of an octet string.
00459  */
00460 void octstr_append_cstr(Octstr *ostr, const char *cstr);
00461 
00462 
00463 /*
00464  * Append a single character at the tail of an octet string.
00465  */
00466 void octstr_append_char(Octstr *ostr, int ch);
00467 
00468 
00469 /*
00470  * Truncate octet string at `new_len'. If new_len is same or more
00471  * than current, do nothing.
00472  */
00473 void octstr_truncate(Octstr *ostr, int new_len);
00474 
00475 
00476 /*
00477  * Strip white space from start and end of a octet string.
00478  */
00479 void octstr_strip_blanks(Octstr *ostr);
00480 
00481 /*
00482  * Strip CR and LF from start and end of a octet string.
00483  */
00484 void octstr_strip_crlfs(Octstr *ostr);
00485 
00486 /*
00487  * Strip non-alphanums from start and end of a octet string.
00488  */
00489 void octstr_strip_nonalphanums(Octstr *ostr);
00490 
00491 
00492 /*
00493  * Shrink consecutive white space characters into one space.
00494  */
00495 void octstr_shrink_blanks(Octstr *ostr);
00496 
00497 
00498 /*
00499  * Delete part of an octet string.
00500  */
00501 void octstr_delete(Octstr *ostr1, long pos, long len);
00502 
00503 
00504 /*
00505  * Read the contents of a named file to an octet string. Return pointer to
00506  * octet string.
00507  */
00508 Octstr *octstr_read_file(const char *filename);
00509 
00510 
00511 /*
00512  * Read the contents of a file descriptor pipe to an octet string. 
00513  * Return pointer to octet string.
00514  */
00515 Octstr *octstr_read_pipe(FILE *f);
00516 
00517 
00518 /*
00519  * Split an octet string into words at whitespace, and return a list
00520  * containing the new octet strings.
00521  */
00522 List *octstr_split_words(const Octstr *ostr);
00523 
00524 
00525 /*
00526  * Split an octet string into substrings at every occurence of `sep'.
00527  * Return List with the substrings.
00528  */
00529 List *octstr_split(const Octstr *os, const Octstr *sep);
00530 
00531 
00532 /*
00533  * Compare two octet strings in a manner suitable for gwlist_search.
00534  */
00535 int octstr_item_match(void *item, void *pattern);
00536 
00537 
00538 /*
00539  * Same as above, except compares bytes without case sensitivity
00540  */
00541 int octstr_item_case_match(void *item, void *pattern);
00542 
00543 
00544 /*
00545  * Print debugging information about octet string. This is abstracted to the
00546  * various log levels we have: GW_DEBUG, GW_INFO, GW_WARNING, GW_ERROR
00547  * 
00548  * If a third parameter in the argument list is given, we will dump the
00549  * octstr in that log level instead of the default GW_DEBUG level.
00550  */
00551 void octstr_dump_real(const Octstr *ostr, int level, ...);
00552 #define octstr_dump(ostr, level, ...) \
00553     octstr_dump_real(ostr, level, GW_DEBUG, ##__VA_ARGS__)
00554 
00555 
00556 /*
00557  * Write the contents of an octet string to the debug log.
00558  * Keep it on one line if the octet string is short and printable,
00559  * otherwise use a hex dump.
00560  */
00561 void octstr_dump_short(Octstr *ostr, int level, const char *name);
00562 
00563 
00564 /*
00565  * decode url-encoded octstr in-place.
00566  * Return 0 if all went fine, or -1 if there was some garbage
00567  */
00568 int octstr_url_decode(Octstr *ostr);
00569 
00570 
00571 /*
00572  * URL encode the argument string in place.
00573  */
00574 void octstr_url_encode(Octstr *ostr);
00575 
00576 
00577 /*
00578  * Treat the octstr as an unsigned array of bits, most significant bit
00579  * first, and return the indicated bit range as an integer.  numbits
00580  * must not be larger than 32.  Bits beyond the end of the string will
00581  * be read as 0.
00582  */
00583 long octstr_get_bits(Octstr *ostr, long bitpos, int numbits);
00584 
00585 
00586 /*
00587  * Treat the octstr as an unsigned array of bits, most significant bit
00588  * first, and set the indicated bit range to the given value.  numbits
00589  * must not be larger than 32.  The value must fit in that number of bits.
00590  * The string will be extended with 0-valued octets as necessary to hold
00591  * the indicated bit range.
00592  */
00593 void octstr_set_bits(Octstr *ostr, long bitpos, int numbits, 
00594                      unsigned long value);
00595 
00596 
00597 /* 
00598  * Encode value in WSP's uintvar format, and append it to the octstr
00599  */
00600 void octstr_append_uintvar(Octstr *ostr, unsigned long value);
00601 
00602 
00603 /* 
00604  * Decode a value in WSP's uintvar format at position pos of the octstr,
00605  * and put the result in *value.  Return the position after the uintvar.
00606  * Return -1 if there is not a valid uintvar at pos.
00607  */
00608 long octstr_extract_uintvar(Octstr *ostr, unsigned long *value, long pos);
00609 
00610 
00611 /*
00612  * Append the decimal representation of the given value to ostr 
00613  */
00614 void octstr_append_decimal(Octstr *ostr, long value);
00615 
00616 
00617 /*
00618  * Create a new octet string based on a printf-like (but not identical)
00619  * format string, and a list of other arguments. The format string is
00620  * a C string for convenience, but this may change later.
00621  *
00622  * The syntax for the format string is as follows:
00623  *
00624  *  % [-] [0] [width] [. prec] [type] conversion
00625  *
00626  * where [] denotes optional parts and the various parts have the
00627  * following meanings:
00628  *
00629  *  -   add padding to the right, instead of the left of the field
00630  *
00631  *  0   pad with zeroes, not spaces
00632  *
00633  *  width   minimum output width; non-negative integer or '*', indicating
00634  *      that the next argument is an int and gives the width
00635  *
00636  *  .   a dot to indicate that precision follows
00637  *
00638  *  prec    precision: maximum length of strings, maximum number of
00639  *      decimals for floating point numbers; non-negative integer
00640  *      or '*' indicating that the next argument is an int and
00641  *      gives the precision
00642  *
00643  *  type    type of integer argument: either h (for short int) or 
00644  *      l (for long int); may only be used with conversion 'd'
00645  *
00646  *  conversion
00647  *      how the field is to be converted, also implicitly defines
00648  *      the type of the next argument; one of
00649  *
00650  *          d   int (unless type says otherwise)
00651  *              output as a decimal integer
00652  *
00653  *          e, f, g double
00654  *              output in various formats of floating
00655  *              point, see printf(3) for details
00656  *
00657  *          s   char *
00658  *              output as character string
00659  *
00660  *          S   Octstr *
00661  *              output as character string, except '\0'
00662  *              inside the string is included in the
00663  *              output
00664  *
00665  *          E   Octstr *
00666  *              output as character string, except that
00667  *              contents are URL-encoded when need to. Note
00668  *              that trunctae is done afterwards and can
00669  *              cut escape '%EE' in half
00670  *
00671  *          H   Octstr *
00672  *              output as character string, except that
00673  *              contents are HEX-encoded in uppercase
00674  */
00675 Octstr *octstr_format(const char *fmt, ...);
00676 
00677 /*
00678  * Like octstr_format, but takes the argument list as a va_list.
00679  */
00680 Octstr *octstr_format_valist_real(const char *fmt, va_list args);
00681 #define octstr_format_valist(fmt, args) gw_claim_area(octstr_format_valist_real(fmt, args))
00682 
00683 /*
00684  * Like octstr_format, but appends output to an existing octet
00685  * string, instead of creating a new one.
00686  */
00687 void octstr_format_append(Octstr *os, const char *fmt, ...);
00688 
00689 
00690 /*
00691  * Compute a hash key value for an octet string by adding all the 
00692  * octets together.
00693  */
00694 unsigned long octstr_hash_key(Octstr *ostr);
00695 
00696 /*
00697  * return an Octstr encoded in charset named tocode created from the data
00698  * in the Octstr orig that is encoded in the charset fromcode.
00699  */
00700 int octstr_recode(Octstr *tocode, Octstr *fromcode, Octstr *orig);
00701 
00702 /*
00703  * Strip all occurence of char ch from start of Octstr
00704  */
00705 void octstr_strip_char(Octstr *text, char ch);
00706 
00707 /*
00708  * Check if ostr is numeric
00709  */
00710 int octstr_isnum(Octstr *ostr1);
00711 
00712 /*
00713  * Replace all occurences of needle with repl within haystack
00714  */
00715 void octstr_replace(Octstr *haystack, Octstr *needle, Octstr *repl);
00716 
00717 /*
00718  * Symbolize hex string '78797a' becomes '%78%79%7a'
00719  */
00720 int octstr_symbolize(Octstr *ostr);
00721 
00722 /*
00723  * Remove all occurrences of 'needle' within 'haystack'.
00724  */
00725 void octstr_delete_matching(Octstr *haystack, Octstr *needle);
00726 
00727 /*
00728  * Return 1, if octstr 'os' contains only hex chars, 0 otherwise.
00729  */
00730 int octstr_is_all_hex(Octstr *os);                                                    
00731                                                     
00732 /*
00733  * make data HTML safe by converting appropriate characters to HTML entities.
00734  * conversion is done in place
00735  */
00736 void octstr_convert_to_html_entities(Octstr* input);
00737 
00738 /*
00739  * convert HTML safe data back to binary data by replacing HTML entities with their
00740  * respective character values.
00741  * conversion is done in place
00742  */
00743 void octstr_convert_from_html_entities(Octstr* input);
00744 
00745 #endif
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.