summaryrefslogtreecommitdiff
path: root/pjlib-util/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-21 01:55:47 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-21 01:55:47 +0000
commit5f1de1bbb341ea1dc1d27d9bf35764b643ef904a (patch)
treed18b0365b69b8b488a0b2b2bd715e9f14f77b505 /pjlib-util/include
parent9f4da35e676737f830a90a18de08440cf0f6cdf9 (diff)
Set svn:eol-style property
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@65 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/include')
-rw-r--r--pjlib-util/include/pjlib-util/md5.h110
-rw-r--r--pjlib-util/include/pjlib-util/scanner.h1058
-rw-r--r--pjlib-util/include/pjlib-util/string.h175
-rw-r--r--pjlib-util/include/pjlib-util/stun.h282
-rw-r--r--pjlib-util/include/pjlib-util/xml.h342
5 files changed, 986 insertions, 981 deletions
diff --git a/pjlib-util/include/pjlib-util/md5.h b/pjlib-util/include/pjlib-util/md5.h
index 24e504b0..92c55fc8 100644
--- a/pjlib-util/include/pjlib-util/md5.h
+++ b/pjlib-util/include/pjlib-util/md5.h
@@ -1,55 +1,55 @@
-/* $Id$ */
-/*
- * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __PJLIB_UTIL_MD5_H__
-#define __PJLIB_UTIL_MD5_H__
-
-#include <pj/types.h>
-
-PJ_BEGIN_DECL
-
-/** MD5 context. */
-typedef struct pj_md5_context
-{
- pj_uint32_t buf[4];
- pj_uint32_t bits[2];
- pj_uint8_t in[64];
-} pj_md5_context;
-
-/** Initialize the algorithm.
- * @param pms MD5 context.
- */
-PJ_DECL(void) pj_md5_init(pj_md5_context *pms);
-
-/** Append a string to the message.
- * @param pms MD5 context.
- * @param data Data.
- * @param nbytes Length of data.
- */
-PJ_DECL(void) pj_md5_update( pj_md5_context *pms,
- const pj_uint8_t *data, unsigned nbytes);
-
-/** Finish the message and return the digest.
- * @param pms MD5 context.
- * @param digest 16 byte digest.
- */
-PJ_DECL(void) pj_md5_final(pj_md5_context *pms, pj_uint8_t digest[16]);
-
-PJ_END_DECL
-
-#endif /* __PJLIB_UTIL_MD5_H__ */
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJLIB_UTIL_MD5_H__
+#define __PJLIB_UTIL_MD5_H__
+
+#include <pj/types.h>
+
+PJ_BEGIN_DECL
+
+/** MD5 context. */
+typedef struct pj_md5_context
+{
+ pj_uint32_t buf[4];
+ pj_uint32_t bits[2];
+ pj_uint8_t in[64];
+} pj_md5_context;
+
+/** Initialize the algorithm.
+ * @param pms MD5 context.
+ */
+PJ_DECL(void) pj_md5_init(pj_md5_context *pms);
+
+/** Append a string to the message.
+ * @param pms MD5 context.
+ * @param data Data.
+ * @param nbytes Length of data.
+ */
+PJ_DECL(void) pj_md5_update( pj_md5_context *pms,
+ const pj_uint8_t *data, unsigned nbytes);
+
+/** Finish the message and return the digest.
+ * @param pms MD5 context.
+ * @param digest 16 byte digest.
+ */
+PJ_DECL(void) pj_md5_final(pj_md5_context *pms, pj_uint8_t digest[16]);
+
+PJ_END_DECL
+
+#endif /* __PJLIB_UTIL_MD5_H__ */
diff --git a/pjlib-util/include/pjlib-util/scanner.h b/pjlib-util/include/pjlib-util/scanner.h
index 209b2d36..d7db4a92 100644
--- a/pjlib-util/include/pjlib-util/scanner.h
+++ b/pjlib-util/include/pjlib-util/scanner.h
@@ -1,529 +1,529 @@
-/* $Id$ */
-/*
- * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __PJ_SCANNER_H__
-#define __PJ_SCANNER_H__
-
-/**
- * @file scanner.h
- * @brief Text Scanning.
- */
-
-#include <pj/types.h>
-
-PJ_BEGIN_DECL
-
-/**
- * @defgroup PJ_SCAN Text Scanning
- * @ingroup PJ_MISC
- * @brief
- * Text scanning utility.
- *
- * @{
- */
-
-/**
- * This describes the type of individual character specification in
- * #pj_cis_buf_t. Basicly the number of bits here
- */
-#ifndef PJ_CIS_ELEM_TYPE
-# define PJ_CIS_ELEM_TYPE pj_uint32_t
-#endif
-
-/**
- * This describes the type of individual character specification in
- * #pj_cis_buf_t.
- */
-typedef PJ_CIS_ELEM_TYPE pj_cis_elem_t;
-
-/**
- * Maximum number of input specification in a buffer.
- * Effectively this means the number of bits in pj_cis_elem_t.
- */
-#define PJ_CIS_MAX_INDEX (sizeof(pj_cis_elem_t) << 3)
-
-/**
- * The scanner input specification buffer.
- */
-typedef struct pj_cis_buf_t
-{
- pj_cis_elem_t cis_buf[256]; /**< Must be 256 (not 128)! */
- pj_cis_elem_t use_mask; /**< To keep used indexes. */
-} pj_cis_buf_t;
-
-/**
- * Character input specification.
- */
-typedef struct pj_cis_t
-{
- pj_cis_elem_t *cis_buf; /**< Pointer to buffer. */
- int cis_id; /**< Id. */
-} pj_cis_t;
-
-/**
- * Initialize scanner input specification buffer.
- *
- * @param cs_buf The scanner character specification.
- */
-PJ_DECL(void) pj_cis_buf_init(pj_cis_buf_t *cs_buf);
-
-/**
- * Create a new input specification.
- *
- * @param cs_buf Specification buffer.
- * @param cis Character input specification to be initialized.
- *
- * @return PJ_SUCCESS if new specification has been successfully
- * created, or PJ_ETOOMANY if there are already too many
- * specifications in the buffer.
- */
-PJ_DECL(pj_status_t) pj_cis_init(pj_cis_buf_t *cs_buf, pj_cis_t *cis);
-
-/**
- * Create a new input specification based on an existing specification.
- *
- * @param new_cis The new specification to be initialized.
- * @param existing The existing specification, from which the input
- * bitmask will be copied to the new specification.
- *
- * @return PJ_SUCCESS if new specification has been successfully
- * created, or PJ_ETOOMANY if there are already too many
- * specifications in the buffer.
- */
-PJ_DECL(pj_status_t) pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing);
-
-/**
- * Set the membership of the specified character.
- * Note that this is a macro, and arguments may be evaluated more than once.
- *
- * @param cis Pointer to character input specification.
- * @param c The character.
- */
-#define PJ_CIS_SET(cis,c) ((cis)->cis_buf[(c)] |= (1 << (cis)->cis_id))
-
-/**
- * Remove the membership of the specified character.
- * Note that this is a macro, and arguments may be evaluated more than once.
- *
- * @param cis Pointer to character input specification.
- * @param c The character to be removed from the membership.
- */
-#define PJ_CIS_CLR(cis,c) ((cis)->cis_buf[c] &= ~(1 << (cis)->cis_id))
-
-/**
- * Check the membership of the specified character.
- * Note that this is a macro, and arguments may be evaluated more than once.
- *
- * @param cis Pointer to character input specification.
- * @param c The character.
- */
-#define PJ_CIS_ISSET(cis,c) ((cis)->cis_buf[c] & (1 << (cis)->cis_id))
-
-/**
- * Add the characters in the specified range '[cstart, cend)' to the
- * specification (the last character itself ('cend') is not added).
- *
- * @param cis The scanner character specification.
- * @param cstart The first character in the range.
- * @param cend The next character after the last character in the range.
- */
-PJ_DECL(void) pj_cis_add_range( pj_cis_t *cis, int cstart, int cend);
-
-/**
- * Add alphabetic characters to the specification.
- *
- * @param cis The scanner character specification.
- */
-PJ_DECL(void) pj_cis_add_alpha( pj_cis_t *cis);
-
-/**
- * Add numeric characters to the specification.
- *
- * @param cis The scanner character specification.
- */
-PJ_DECL(void) pj_cis_add_num( pj_cis_t *cis);
-
-/**
- * Add the characters in the string to the specification.
- *
- * @param cis The scanner character specification.
- * @param str The string.
- */
-PJ_DECL(void) pj_cis_add_str( pj_cis_t *cis, const char *str);
-
-/**
- * Delete characters in the specified range from the specification.
- *
- * @param cis The scanner character specification.
- * @param cstart The first character in the range.
- * @param cend The next character after the last character in the range.
- */
-PJ_DECL(void) pj_cis_del_range( pj_cis_t *cis, int cstart, int cend);
-
-/**
- * Delete characters in the specified string from the specification.
- *
- * @param cis The scanner character specification.
- * @param str The string.
- */
-PJ_DECL(void) pj_cis_del_str( pj_cis_t *cis, const char *str);
-
-/**
- * Invert specification.
- *
- * @param cis The scanner character specification.
- */
-PJ_DECL(void) pj_cis_invert( pj_cis_t *cis );
-
-/**
- * Check whether the specified character belongs to the specification.
- *
- * @param cis The scanner character specification.
- * @param c The character to check for matching.
- *
- * @return Non-zero if match (not necessarily one).
- */
-PJ_INLINE(int) pj_cis_match( const pj_cis_t *cis, int c )
-{
- return PJ_CIS_ISSET(cis, c);
-}
-
-
-/**
- * Flags for scanner.
- */
-enum
-{
- /** This flags specifies that the scanner should automatically skip
- whitespaces
- */
- PJ_SCAN_AUTOSKIP_WS = 1,
-
- /** This flags specifies that the scanner should automatically skip
- SIP header continuation. This flag implies PJ_SCAN_AUTOSKIP_WS.
- */
- PJ_SCAN_AUTOSKIP_WS_HEADER = 3,
-
- /** Auto-skip new lines.
- */
- PJ_SCAN_AUTOSKIP_NEWLINE = 4,
-};
-
-
-/* Forward decl. */
-struct pj_scanner;
-
-
-/**
- * The callback function type to be called by the scanner when it encounters
- * syntax error.
- *
- * @param scanner The scanner instance that calls the callback .
- */
-typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner);
-
-
-/**
- * The text scanner structure.
- */
-typedef struct pj_scanner
-{
- char *begin; /**< Start of input buffer. */
- char *end; /**< End of input buffer. */
- char *curptr; /**< Current pointer. */
- int line; /**< Current line. */
- int col; /**< Current column. */
- int skip_ws; /**< Skip whitespace flag. */
- pj_syn_err_func_ptr callback; /**< Syntax error callback. */
-} pj_scanner;
-
-
-/**
- * This structure can be used by application to store the state of the parser,
- * so that the scanner state can be rollback to this state when necessary.
- */
-typedef struct pj_scan_state
-{
- char *curptr; /**< Current scanner's pointer. */
- int line; /**< Current line. */
- int col; /**< Current column. */
-} pj_scan_state;
-
-
-/**
- * Initialize the scanner. Note that the input string buffer must have
- * length at least buflen+1 because the scanner will NULL terminate the
- * string during initialization.
- *
- * @param scanner The scanner to be initialized.
- * @param bufstart The input buffer to scan. Note that buffer[buflen] will be
- * filled with NULL char until scanner is destroyed, so
- * the actual buffer length must be at least buflen+1.
- * @param buflen The length of the input buffer, which normally is
- * strlen(bufstart).
- * @param options Zero, or combination of PJ_SCAN_AUTOSKIP_WS or
- * PJ_SCAN_AUTOSKIP_WS_HEADER
- * @param callback Callback to be called when the scanner encounters syntax
- * error condition.
- */
-PJ_DECL(void) pj_scan_init( pj_scanner *scanner, char *bufstart, int buflen,
- unsigned options,
- pj_syn_err_func_ptr callback );
-
-
-/**
- * Call this function when application has finished using the scanner.
- *
- * @param scanner The scanner.
- */
-PJ_DECL(void) pj_scan_fini( pj_scanner *scanner );
-
-
-/**
- * Determine whether the EOF condition for the scanner has been met.
- *
- * @param scanner The scanner.
- *
- * @return Non-zero if scanner is EOF.
- */
-PJ_INLINE(int) pj_scan_is_eof( const pj_scanner *scanner)
-{
- return scanner->curptr >= scanner->end;
-}
-
-
-/**
- * Peek strings in current position according to parameter spec, and return
- * the strings in parameter out. The current scanner position will not be
- * moved. If the scanner is already in EOF state, syntax error callback will
- * be called thrown.
- *
- * @param scanner The scanner.
- * @param spec The spec to match input string.
- * @param out String to store the result.
- *
- * @return the character right after the peek-ed position or zero if there's
- * no more characters.
- */
-PJ_DECL(int) pj_scan_peek( pj_scanner *scanner,
- const pj_cis_t *spec, pj_str_t *out);
-
-
-/**
- * Peek len characters in current position, and return them in out parameter.
- * Note that whitespaces or newlines will be returned as it is, regardless
- * of PJ_SCAN_AUTOSKIP_WS settings. If the character left is less than len,
- * syntax error callback will be called.
- *
- * @param scanner The scanner.
- * @param len Length to peek.
- * @param out String to store the result.
- *
- * @return the character right after the peek-ed position or zero if there's
- * no more characters.
- */
-PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner,
- pj_size_t len, pj_str_t *out);
-
-
-/**
- * Peek strings in current position until spec is matched, and return
- * the strings in parameter out. The current scanner position will not be
- * moved. If the scanner is already in EOF state, syntax error callback will
- * be called.
- *
- * @param scanner The scanner.
- * @param spec The peeking will stop when the input match this spec.
- * @param out String to store the result.
- *
- * @return the character right after the peek-ed position.
- */
-PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner,
- const pj_cis_t *spec,
- pj_str_t *out);
-
-
-/**
- * Get characters from the buffer according to the spec, and return them
- * in out parameter. The scanner will attempt to get as many characters as
- * possible as long as the spec matches. If the first character doesn't
- * match the spec, or scanner is already in EOF when this function is called,
- * an exception will be thrown.
- *
- * @param scanner The scanner.
- * @param spec The spec to match input string.
- * @param out String to store the result.
- */
-PJ_DECL(void) pj_scan_get( pj_scanner *scanner,
- const pj_cis_t *spec, pj_str_t *out);
-
-
-/**
- * Get characters between quotes. If current input doesn't match begin_quote,
- * syntax error will be thrown.
- *
- * @param scanner The scanner.
- * @param begin_quote The character to begin the quote.
- * @param end_quote The character to end the quote.
- * @param out String to store the result.
- */
-PJ_DECL(void) pj_scan_get_quote( pj_scanner *scanner,
- int begin_quote, int end_quote,
- pj_str_t *out);
-
-/**
- * Get N characters from the scanner.
- *
- * @param scanner The scanner.
- * @param N Number of characters to get.
- * @param out String to store the result.
- */
-PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner,
- unsigned N, pj_str_t *out);
-
-
-/**
- * Get one character from the scanner.
- *
- * @param scanner The scanner.
- *
- * @return The character.
- */
-PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner );
-
-
-/**
- * Get a newline from the scanner. A newline is defined as '\\n', or '\\r', or
- * "\\r\\n". If current input is not newline, syntax error will be thrown.
- *
- * @param scanner The scanner.
- */
-PJ_DECL(void) pj_scan_get_newline( pj_scanner *scanner );
-
-
-/**
- * Get characters from the scanner and move the scanner position until the
- * current character matches the spec.
- *
- * @param scanner The scanner.
- * @param spec Get until the input match this spec.
- * @param out String to store the result.
- */
-PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner,
- const pj_cis_t *spec, pj_str_t *out);
-
-
-/**
- * Get characters from the scanner and move the scanner position until the
- * current character matches until_char.
- *
- * @param scanner The scanner.
- * @param until_char Get until the input match this character.
- * @param out String to store the result.
- */
-PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner,
- int until_char, pj_str_t *out);
-
-
-/**
- * Get characters from the scanner and move the scanner position until the
- * current character matches until_char.
- *
- * @param scanner The scanner.
- * @param until_spec Get until the input match any of these characters.
- * @param out String to store the result.
- */
-PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner,
- const char *until_spec, pj_str_t *out);
-
-/**
- * Advance the scanner N characters, and skip whitespace
- * if necessary.
- *
- * @param scanner The scanner.
- * @param N Number of characters to skip.
- * @param skip Flag to specify whether whitespace should be skipped
- * after skipping the characters.
- */
-PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner,
- unsigned N, pj_bool_t skip);
-
-
-/**
- * Compare string in current position with the specified string.
- *
- * @param scanner The scanner.
- * @param s The string to compare with.
- * @param len Length of the string to compare.
- *
- * @return zero, <0, or >0 (just like strcmp()).
- */
-PJ_DECL(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len);
-
-
-/**
- * Case-less string comparison of current position with the specified
- * string.
- *
- * @param scanner The scanner.
- * @param s The string to compare with.
- * @param len Length of the string to compare with.
- *
- * @return zero, <0, or >0 (just like strcmp()).
- */
-PJ_DECL(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len);
-
-
-/**
- * Manually skip whitespaces according to flag that was specified when
- * the scanner was initialized.
- *
- * @param scanner The scanner.
- */
-PJ_DECL(void) pj_scan_skip_whitespace( pj_scanner *scanner );
-
-
-/**
- * Save the full scanner state.
- *
- * @param scanner The scanner.
- * @param state Variable to store scanner's state.
- */
-PJ_DECL(void) pj_scan_save_state( pj_scanner *scanner, pj_scan_state *state);
-
-
-/**
- * Restore the full scanner state.
- * Note that this would not restore the string if application has modified
- * it. This will only restore the scanner scanning position.
- *
- * @param scanner The scanner.
- * @param state State of the scanner.
- */
-PJ_DECL(void) pj_scan_restore_state( pj_scanner *scanner,
- pj_scan_state *state);
-
-/**
- * @}
- */
-
-
-PJ_END_DECL
-
-#endif
-
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJ_SCANNER_H__
+#define __PJ_SCANNER_H__
+
+/**
+ * @file scanner.h
+ * @brief Text Scanning.
+ */
+
+#include <pj/types.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJ_SCAN Text Scanning
+ * @ingroup PJ_MISC
+ * @brief
+ * Text scanning utility.
+ *
+ * @{
+ */
+
+/**
+ * This describes the type of individual character specification in
+ * #pj_cis_buf_t. Basicly the number of bits here
+ */
+#ifndef PJ_CIS_ELEM_TYPE
+# define PJ_CIS_ELEM_TYPE pj_uint32_t
+#endif
+
+/**
+ * This describes the type of individual character specification in
+ * #pj_cis_buf_t.
+ */
+typedef PJ_CIS_ELEM_TYPE pj_cis_elem_t;
+
+/**
+ * Maximum number of input specification in a buffer.
+ * Effectively this means the number of bits in pj_cis_elem_t.
+ */
+#define PJ_CIS_MAX_INDEX (sizeof(pj_cis_elem_t) << 3)
+
+/**
+ * The scanner input specification buffer.
+ */
+typedef struct pj_cis_buf_t
+{
+ pj_cis_elem_t cis_buf[256]; /**< Must be 256 (not 128)! */
+ pj_cis_elem_t use_mask; /**< To keep used indexes. */
+} pj_cis_buf_t;
+
+/**
+ * Character input specification.
+ */
+typedef struct pj_cis_t
+{
+ pj_cis_elem_t *cis_buf; /**< Pointer to buffer. */
+ int cis_id; /**< Id. */
+} pj_cis_t;
+
+/**
+ * Initialize scanner input specification buffer.
+ *
+ * @param cs_buf The scanner character specification.
+ */
+PJ_DECL(void) pj_cis_buf_init(pj_cis_buf_t *cs_buf);
+
+/**
+ * Create a new input specification.
+ *
+ * @param cs_buf Specification buffer.
+ * @param cis Character input specification to be initialized.
+ *
+ * @return PJ_SUCCESS if new specification has been successfully
+ * created, or PJ_ETOOMANY if there are already too many
+ * specifications in the buffer.
+ */
+PJ_DECL(pj_status_t) pj_cis_init(pj_cis_buf_t *cs_buf, pj_cis_t *cis);
+
+/**
+ * Create a new input specification based on an existing specification.
+ *
+ * @param new_cis The new specification to be initialized.
+ * @param existing The existing specification, from which the input
+ * bitmask will be copied to the new specification.
+ *
+ * @return PJ_SUCCESS if new specification has been successfully
+ * created, or PJ_ETOOMANY if there are already too many
+ * specifications in the buffer.
+ */
+PJ_DECL(pj_status_t) pj_cis_dup(pj_cis_t *new_cis, pj_cis_t *existing);
+
+/**
+ * Set the membership of the specified character.
+ * Note that this is a macro, and arguments may be evaluated more than once.
+ *
+ * @param cis Pointer to character input specification.
+ * @param c The character.
+ */
+#define PJ_CIS_SET(cis,c) ((cis)->cis_buf[(c)] |= (1 << (cis)->cis_id))
+
+/**
+ * Remove the membership of the specified character.
+ * Note that this is a macro, and arguments may be evaluated more than once.
+ *
+ * @param cis Pointer to character input specification.
+ * @param c The character to be removed from the membership.
+ */
+#define PJ_CIS_CLR(cis,c) ((cis)->cis_buf[c] &= ~(1 << (cis)->cis_id))
+
+/**
+ * Check the membership of the specified character.
+ * Note that this is a macro, and arguments may be evaluated more than once.
+ *
+ * @param cis Pointer to character input specification.
+ * @param c The character.
+ */
+#define PJ_CIS_ISSET(cis,c) ((cis)->cis_buf[c] & (1 << (cis)->cis_id))
+
+/**
+ * Add the characters in the specified range '[cstart, cend)' to the
+ * specification (the last character itself ('cend') is not added).
+ *
+ * @param cis The scanner character specification.
+ * @param cstart The first character in the range.
+ * @param cend The next character after the last character in the range.
+ */
+PJ_DECL(void) pj_cis_add_range( pj_cis_t *cis, int cstart, int cend);
+
+/**
+ * Add alphabetic characters to the specification.
+ *
+ * @param cis The scanner character specification.
+ */
+PJ_DECL(void) pj_cis_add_alpha( pj_cis_t *cis);
+
+/**
+ * Add numeric characters to the specification.
+ *
+ * @param cis The scanner character specification.
+ */
+PJ_DECL(void) pj_cis_add_num( pj_cis_t *cis);
+
+/**
+ * Add the characters in the string to the specification.
+ *
+ * @param cis The scanner character specification.
+ * @param str The string.
+ */
+PJ_DECL(void) pj_cis_add_str( pj_cis_t *cis, const char *str);
+
+/**
+ * Delete characters in the specified range from the specification.
+ *
+ * @param cis The scanner character specification.
+ * @param cstart The first character in the range.
+ * @param cend The next character after the last character in the range.
+ */
+PJ_DECL(void) pj_cis_del_range( pj_cis_t *cis, int cstart, int cend);
+
+/**
+ * Delete characters in the specified string from the specification.
+ *
+ * @param cis The scanner character specification.
+ * @param str The string.
+ */
+PJ_DECL(void) pj_cis_del_str( pj_cis_t *cis, const char *str);
+
+/**
+ * Invert specification.
+ *
+ * @param cis The scanner character specification.
+ */
+PJ_DECL(void) pj_cis_invert( pj_cis_t *cis );
+
+/**
+ * Check whether the specified character belongs to the specification.
+ *
+ * @param cis The scanner character specification.
+ * @param c The character to check for matching.
+ *
+ * @return Non-zero if match (not necessarily one).
+ */
+PJ_INLINE(int) pj_cis_match( const pj_cis_t *cis, int c )
+{
+ return PJ_CIS_ISSET(cis, c);
+}
+
+
+/**
+ * Flags for scanner.
+ */
+enum
+{
+ /** This flags specifies that the scanner should automatically skip
+ whitespaces
+ */
+ PJ_SCAN_AUTOSKIP_WS = 1,
+
+ /** This flags specifies that the scanner should automatically skip
+ SIP header continuation. This flag implies PJ_SCAN_AUTOSKIP_WS.
+ */
+ PJ_SCAN_AUTOSKIP_WS_HEADER = 3,
+
+ /** Auto-skip new lines.
+ */
+ PJ_SCAN_AUTOSKIP_NEWLINE = 4,
+};
+
+
+/* Forward decl. */
+struct pj_scanner;
+
+
+/**
+ * The callback function type to be called by the scanner when it encounters
+ * syntax error.
+ *
+ * @param scanner The scanner instance that calls the callback .
+ */
+typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner);
+
+
+/**
+ * The text scanner structure.
+ */
+typedef struct pj_scanner
+{
+ char *begin; /**< Start of input buffer. */
+ char *end; /**< End of input buffer. */
+ char *curptr; /**< Current pointer. */
+ int line; /**< Current line. */
+ int col; /**< Current column. */
+ int skip_ws; /**< Skip whitespace flag. */
+ pj_syn_err_func_ptr callback; /**< Syntax error callback. */
+} pj_scanner;
+
+
+/**
+ * This structure can be used by application to store the state of the parser,
+ * so that the scanner state can be rollback to this state when necessary.
+ */
+typedef struct pj_scan_state
+{
+ char *curptr; /**< Current scanner's pointer. */
+ int line; /**< Current line. */
+ int col; /**< Current column. */
+} pj_scan_state;
+
+
+/**
+ * Initialize the scanner. Note that the input string buffer must have
+ * length at least buflen+1 because the scanner will NULL terminate the
+ * string during initialization.
+ *
+ * @param scanner The scanner to be initialized.
+ * @param bufstart The input buffer to scan. Note that buffer[buflen] will be
+ * filled with NULL char until scanner is destroyed, so
+ * the actual buffer length must be at least buflen+1.
+ * @param buflen The length of the input buffer, which normally is
+ * strlen(bufstart).
+ * @param options Zero, or combination of PJ_SCAN_AUTOSKIP_WS or
+ * PJ_SCAN_AUTOSKIP_WS_HEADER
+ * @param callback Callback to be called when the scanner encounters syntax
+ * error condition.
+ */
+PJ_DECL(void) pj_scan_init( pj_scanner *scanner, char *bufstart, int buflen,
+ unsigned options,
+ pj_syn_err_func_ptr callback );
+
+
+/**
+ * Call this function when application has finished using the scanner.
+ *
+ * @param scanner The scanner.
+ */
+PJ_DECL(void) pj_scan_fini( pj_scanner *scanner );
+
+
+/**
+ * Determine whether the EOF condition for the scanner has been met.
+ *
+ * @param scanner The scanner.
+ *
+ * @return Non-zero if scanner is EOF.
+ */
+PJ_INLINE(int) pj_scan_is_eof( const pj_scanner *scanner)
+{
+ return scanner->curptr >= scanner->end;
+}
+
+
+/**
+ * Peek strings in current position according to parameter spec, and return
+ * the strings in parameter out. The current scanner position will not be
+ * moved. If the scanner is already in EOF state, syntax error callback will
+ * be called thrown.
+ *
+ * @param scanner The scanner.
+ * @param spec The spec to match input string.
+ * @param out String to store the result.
+ *
+ * @return the character right after the peek-ed position or zero if there's
+ * no more characters.
+ */
+PJ_DECL(int) pj_scan_peek( pj_scanner *scanner,
+ const pj_cis_t *spec, pj_str_t *out);
+
+
+/**
+ * Peek len characters in current position, and return them in out parameter.
+ * Note that whitespaces or newlines will be returned as it is, regardless
+ * of PJ_SCAN_AUTOSKIP_WS settings. If the character left is less than len,
+ * syntax error callback will be called.
+ *
+ * @param scanner The scanner.
+ * @param len Length to peek.
+ * @param out String to store the result.
+ *
+ * @return the character right after the peek-ed position or zero if there's
+ * no more characters.
+ */
+PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner,
+ pj_size_t len, pj_str_t *out);
+
+
+/**
+ * Peek strings in current position until spec is matched, and return
+ * the strings in parameter out. The current scanner position will not be
+ * moved. If the scanner is already in EOF state, syntax error callback will
+ * be called.
+ *
+ * @param scanner The scanner.
+ * @param spec The peeking will stop when the input match this spec.
+ * @param out String to store the result.
+ *
+ * @return the character right after the peek-ed position.
+ */
+PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner,
+ const pj_cis_t *spec,
+ pj_str_t *out);
+
+
+/**
+ * Get characters from the buffer according to the spec, and return them
+ * in out parameter. The scanner will attempt to get as many characters as
+ * possible as long as the spec matches. If the first character doesn't
+ * match the spec, or scanner is already in EOF when this function is called,
+ * an exception will be thrown.
+ *
+ * @param scanner The scanner.
+ * @param spec The spec to match input string.
+ * @param out String to store the result.
+ */
+PJ_DECL(void) pj_scan_get( pj_scanner *scanner,
+ const pj_cis_t *spec, pj_str_t *out);
+
+
+/**
+ * Get characters between quotes. If current input doesn't match begin_quote,
+ * syntax error will be thrown.
+ *
+ * @param scanner The scanner.
+ * @param begin_quote The character to begin the quote.
+ * @param end_quote The character to end the quote.
+ * @param out String to store the result.
+ */
+PJ_DECL(void) pj_scan_get_quote( pj_scanner *scanner,
+ int begin_quote, int end_quote,
+ pj_str_t *out);
+
+/**
+ * Get N characters from the scanner.
+ *
+ * @param scanner The scanner.
+ * @param N Number of characters to get.
+ * @param out String to store the result.
+ */
+PJ_DECL(void) pj_scan_get_n( pj_scanner *scanner,
+ unsigned N, pj_str_t *out);
+
+
+/**
+ * Get one character from the scanner.
+ *
+ * @param scanner The scanner.
+ *
+ * @return The character.
+ */
+PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner );
+
+
+/**
+ * Get a newline from the scanner. A newline is defined as '\\n', or '\\r', or
+ * "\\r\\n". If current input is not newline, syntax error will be thrown.
+ *
+ * @param scanner The scanner.
+ */
+PJ_DECL(void) pj_scan_get_newline( pj_scanner *scanner );
+
+
+/**
+ * Get characters from the scanner and move the scanner position until the
+ * current character matches the spec.
+ *
+ * @param scanner The scanner.
+ * @param spec Get until the input match this spec.
+ * @param out String to store the result.
+ */
+PJ_DECL(void) pj_scan_get_until( pj_scanner *scanner,
+ const pj_cis_t *spec, pj_str_t *out);
+
+
+/**
+ * Get characters from the scanner and move the scanner position until the
+ * current character matches until_char.
+ *
+ * @param scanner The scanner.
+ * @param until_char Get until the input match this character.
+ * @param out String to store the result.
+ */
+PJ_DECL(void) pj_scan_get_until_ch( pj_scanner *scanner,
+ int until_char, pj_str_t *out);
+
+
+/**
+ * Get characters from the scanner and move the scanner position until the
+ * current character matches until_char.
+ *
+ * @param scanner The scanner.
+ * @param until_spec Get until the input match any of these characters.
+ * @param out String to store the result.
+ */
+PJ_DECL(void) pj_scan_get_until_chr( pj_scanner *scanner,
+ const char *until_spec, pj_str_t *out);
+
+/**
+ * Advance the scanner N characters, and skip whitespace
+ * if necessary.
+ *
+ * @param scanner The scanner.
+ * @param N Number of characters to skip.
+ * @param skip Flag to specify whether whitespace should be skipped
+ * after skipping the characters.
+ */
+PJ_DECL(void) pj_scan_advance_n( pj_scanner *scanner,
+ unsigned N, pj_bool_t skip);
+
+
+/**
+ * Compare string in current position with the specified string.
+ *
+ * @param scanner The scanner.
+ * @param s The string to compare with.
+ * @param len Length of the string to compare.
+ *
+ * @return zero, <0, or >0 (just like strcmp()).
+ */
+PJ_DECL(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len);
+
+
+/**
+ * Case-less string comparison of current position with the specified
+ * string.
+ *
+ * @param scanner The scanner.
+ * @param s The string to compare with.
+ * @param len Length of the string to compare with.
+ *
+ * @return zero, <0, or >0 (just like strcmp()).
+ */
+PJ_DECL(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len);
+
+
+/**
+ * Manually skip whitespaces according to flag that was specified when
+ * the scanner was initialized.
+ *
+ * @param scanner The scanner.
+ */
+PJ_DECL(void) pj_scan_skip_whitespace( pj_scanner *scanner );
+
+
+/**
+ * Save the full scanner state.
+ *
+ * @param scanner The scanner.
+ * @param state Variable to store scanner's state.
+ */
+PJ_DECL(void) pj_scan_save_state( pj_scanner *scanner, pj_scan_state *state);
+
+
+/**
+ * Restore the full scanner state.
+ * Note that this would not restore the string if application has modified
+ * it. This will only restore the scanner scanning position.
+ *
+ * @param scanner The scanner.
+ * @param state State of the scanner.
+ */
+PJ_DECL(void) pj_scan_restore_state( pj_scanner *scanner,
+ pj_scan_state *state);
+
+/**
+ * @}
+ */
+
+
+PJ_END_DECL
+
+#endif
+
diff --git a/pjlib-util/include/pjlib-util/string.h b/pjlib-util/include/pjlib-util/string.h
index bde48e28..617e6bd7 100644
--- a/pjlib-util/include/pjlib-util/string.h
+++ b/pjlib-util/include/pjlib-util/string.h
@@ -1,85 +1,90 @@
-/* $Id: $ */
-/*
- * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __PJLIB_UTIL_STRING_H__
-#define __PJLIB_UTIL_STRING_H__
-
-/**
- * @file string.h
- * @brief More string functions.
- */
-
-#include <pj/types.h>
-#include <pjlib-util/scanner.h>
-
-PJ_BEGIN_DECL
-
-/**
- * Unescape string.
- *
- * @param str The string to unescape.
- */
-PJ_DECL(void) pj_str_unescape(pj_str_t *str);
-
-/**
- * Unescape string to destination.
- *
- * @param dst Target string.
- * @param src Source string.
- *
- * @return Target string.
- */
-PJ_DECL(pj_str_t*) pj_strcpy_unescape(pj_str_t *dst, const pj_str_t *src);
-
-/**
- * Copy string to destination while escaping reserved characters, up to
- * the specified maximum length.
- *
- * @param dst Target string.
- * @param src Source string.
- * @param max Maximum length to copy to target string.
- * @param unres Unreserved characters, which are allowed to appear
- * unescaped.
- *
- * @return The target string if all characters have been copied
- * successfully, or NULL if there's not enough buffer to
- * escape the strings.
- */
-PJ_DECL(pj_str_t*) pj_strncpy_escape(pj_str_t *dst, const pj_str_t *src,
- pj_ssize_t max, const pj_cis_t *unres);
-
-
-/**
- * Copy string to destination while escaping reserved characters, up to
- * the specified maximum length.
- *
- * @param dst Target string.
- * @param src Source string.
- * @param max Maximum length to copy to target string.
- * @param unres Unreserved characters, which are allowed to appear
- * unescaped.
- *
- * @return The length of the destination, or -1 if there's not
- * enough buffer.
- */
-PJ_DECL(pj_ssize_t) pj_strncpy2_escape(char *dst, const pj_str_t *src,
- pj_ssize_t max, const pj_cis_t *unres);
-
-PJ_END_DECL
-
-#endif /* __PJLIB_UTIL_STRING_H__ */
+/* $Id$ */
+/*
+ * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJLIB_UTIL_STRING_H__
+#define __PJLIB_UTIL_STRING_H__
+
+/**
+ * @file string.h
+ * @brief More string functions.
+ */
+
+#include <pj/types.h>
+#include <pjlib-util/scanner.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * Unescape string. If source string does not contain any escaped
+ * characters, the function would simply return the original string.
+ * Otherwise a new string will be allocated.
+ *
+ * @param pool Pool to allocate the string.
+ * @param src Source string to unescape.
+ *
+ * @return String with no escaped characters.
+ */
+PJ_DECL(pj_str_t) pj_str_unescape( pj_pool_t *pool, const pj_str_t *src);
+
+/**
+ * Unescape string to destination.
+ *
+ * @param dst Target string.
+ * @param src Source string.
+ *
+ * @return Target string.
+ */
+PJ_DECL(pj_str_t*) pj_strcpy_unescape(pj_str_t *dst, const pj_str_t *src);
+
+/**
+ * Copy string to destination while escaping reserved characters, up to
+ * the specified maximum length.
+ *
+ * @param dst Target string.
+ * @param src Source string.
+ * @param max Maximum length to copy to target string.
+ * @param unres Unreserved characters, which are allowed to appear
+ * unescaped.
+ *
+ * @return The target string if all characters have been copied
+ * successfully, or NULL if there's not enough buffer to
+ * escape the strings.
+ */
+PJ_DECL(pj_str_t*) pj_strncpy_escape(pj_str_t *dst, const pj_str_t *src,
+ pj_ssize_t max, const pj_cis_t *unres);
+
+
+/**
+ * Copy string to destination while escaping reserved characters, up to
+ * the specified maximum length.
+ *
+ * @param dst Target string.
+ * @param src Source string.
+ * @param max Maximum length to copy to target string.
+ * @param unres Unreserved characters, which are allowed to appear
+ * unescaped.
+ *
+ * @return The length of the destination, or -1 if there's not
+ * enough buffer.
+ */
+PJ_DECL(pj_ssize_t) pj_strncpy2_escape(char *dst, const pj_str_t *src,
+ pj_ssize_t max, const pj_cis_t *unres);
+
+PJ_END_DECL
+
+#endif /* __PJLIB_UTIL_STRING_H__ */
diff --git a/pjlib-util/include/pjlib-util/stun.h b/pjlib-util/include/pjlib-util/stun.h
index b2af6d35..353e07f6 100644
--- a/pjlib-util/include/pjlib-util/stun.h
+++ b/pjlib-util/include/pjlib-util/stun.h
@@ -1,141 +1,141 @@
-/* $Id */
-/*
- * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __PJ_STUN_H__
-#define __PJ_STUN_H__
-
-#include <pj/types.h>
-#include <pj/sock.h>
-
-PJ_BEGIN_DECL
-
-#define PJ_STUN_MAX_ATTR 16
-
-typedef enum pj_stun_msg_type
-{
- PJ_STUN_BINDING_REQUEST = 0x0001,
- PJ_STUN_BINDING_RESPONSE = 0x0101,
- PJ_STUN_BINDING_ERROR_RESPONSE = 0x0111,
- PJ_STUN_SHARED_SECRET_REQUEST = 0x0002,
- PJ_STUN_SHARED_SECRET_RESPONSE = 0x0102,
- PJ_STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112
-} pj_stun_msg_type;
-
-typedef enum pj_stun_attr_type
-{
- PJ_STUN_ATTR_MAPPED_ADDR = 1,
- PJ_STUN_ATTR_RESPONSE_ADDR,
- PJ_STUN_ATTR_CHANGE_REQUEST,
- PJ_STUN_ATTR_SOURCE_ADDR,
- PJ_STUN_ATTR_CHANGED_ADDR,
- PJ_STUN_ATTR_USERNAME,
- PJ_STUN_ATTR_PASSWORD,
- PJ_STUN_ATTR_MESSAGE_INTEGRITY,
- PJ_STUN_ATTR_ERROR_CODE,
- PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES,
- PJ_STUN_ATTR_REFLECTED_FORM
-} pj_stun_attr_type;
-
-typedef struct pj_stun_msg_hdr
-{
- pj_uint16_t type;
- pj_uint16_t length;
- pj_uint32_t tsx[4];
-} pj_stun_msg_hdr;
-
-typedef struct pj_stun_attr_hdr
-{
- pj_uint16_t type;
- pj_uint16_t length;
-} pj_stun_attr_hdr;
-
-typedef struct pj_stun_mapped_addr_attr
-{
- pj_stun_attr_hdr hdr;
- pj_uint8_t ignored;
- pj_uint8_t family;
- pj_uint16_t port;
- pj_uint32_t addr;
-} pj_stun_mapped_addr_attr;
-
-typedef pj_stun_mapped_addr_attr pj_stun_response_addr_attr;
-typedef pj_stun_mapped_addr_attr pj_stun_changed_addr_attr;
-typedef pj_stun_mapped_addr_attr pj_stun_src_addr_attr;
-typedef pj_stun_mapped_addr_attr pj_stun_reflected_form_attr;
-
-typedef struct pj_stun_change_request_attr
-{
- pj_stun_attr_hdr hdr;
- pj_uint32_t value;
-} pj_stun_change_request_attr;
-
-typedef struct pj_stun_username_attr
-{
- pj_stun_attr_hdr hdr;
- pj_uint32_t value[1];
-} pj_stun_username_attr;
-
-typedef pj_stun_username_attr pj_stun_password_attr;
-
-typedef struct pj_stun_error_code_attr
-{
- pj_stun_attr_hdr hdr;
- pj_uint16_t ignored;
- pj_uint8_t err_class;
- pj_uint8_t number;
- char reason[4];
-} pj_stun_error_code_attr;
-
-typedef struct pj_stun_msg
-{
- pj_stun_msg_hdr *hdr;
- int attr_count;
- pj_stun_attr_hdr *attr[PJ_STUN_MAX_ATTR];
-} pj_stun_msg;
-
-/* STUN message API (stun.c). */
-
-PJ_DECL(pj_status_t) pj_stun_create_bind_req( pj_pool_t *pool,
- void **msg, pj_size_t *len,
- pj_uint32_t id_hi,
- pj_uint32_t id_lo);
-PJ_DECL(pj_status_t) pj_stun_parse_msg( void *buf, pj_size_t len,
- pj_stun_msg *msg);
-PJ_DECL(void*) pj_stun_msg_find_attr( pj_stun_msg *msg, pj_stun_attr_type t);
-
-/* STUN simple client API (stun_client.c) */
-enum pj_stun_err_code {
- PJ_STUN_ERR_MEMORY = (-2),
- PJ_STUN_ERR_RESOLVE = (-3),
- PJ_STUN_ERR_TRANSPORT = (-4),
- PJ_STUN_ERR_INVALID_MSG = (-5),
- PJ_STUN_ERR_NO_RESPONSE = (-6),
- PJ_STUN_ERR_SYMETRIC = (-7),
-};
-
-PJ_DECL(pj_status_t) pj_stun_get_mapped_addr( pj_pool_factory *pf,
- int sock_cnt, pj_sock_t sock[],
- const pj_str_t *srv1, int port1,
- const pj_str_t *srv2, int port2,
- pj_sockaddr_in mapped_addr[]);
-PJ_DECL(const char*) pj_stun_get_err_msg(pj_status_t status);
-
-PJ_END_DECL
-
-#endif /* __PJ_STUN_H__ */
-
+/* $Id */
+/*
+ * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJ_STUN_H__
+#define __PJ_STUN_H__
+
+#include <pj/types.h>
+#include <pj/sock.h>
+
+PJ_BEGIN_DECL
+
+#define PJ_STUN_MAX_ATTR 16
+
+typedef enum pj_stun_msg_type
+{
+ PJ_STUN_BINDING_REQUEST = 0x0001,
+ PJ_STUN_BINDING_RESPONSE = 0x0101,
+ PJ_STUN_BINDING_ERROR_RESPONSE = 0x0111,
+ PJ_STUN_SHARED_SECRET_REQUEST = 0x0002,
+ PJ_STUN_SHARED_SECRET_RESPONSE = 0x0102,
+ PJ_STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112
+} pj_stun_msg_type;
+
+typedef enum pj_stun_attr_type
+{
+ PJ_STUN_ATTR_MAPPED_ADDR = 1,
+ PJ_STUN_ATTR_RESPONSE_ADDR,
+ PJ_STUN_ATTR_CHANGE_REQUEST,
+ PJ_STUN_ATTR_SOURCE_ADDR,
+ PJ_STUN_ATTR_CHANGED_ADDR,
+ PJ_STUN_ATTR_USERNAME,
+ PJ_STUN_ATTR_PASSWORD,
+ PJ_STUN_ATTR_MESSAGE_INTEGRITY,
+ PJ_STUN_ATTR_ERROR_CODE,
+ PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES,
+ PJ_STUN_ATTR_REFLECTED_FORM
+} pj_stun_attr_type;
+
+typedef struct pj_stun_msg_hdr
+{
+ pj_uint16_t type;
+ pj_uint16_t length;
+ pj_uint32_t tsx[4];
+} pj_stun_msg_hdr;
+
+typedef struct pj_stun_attr_hdr
+{
+ pj_uint16_t type;
+ pj_uint16_t length;
+} pj_stun_attr_hdr;
+
+typedef struct pj_stun_mapped_addr_attr
+{
+ pj_stun_attr_hdr hdr;
+ pj_uint8_t ignored;
+ pj_uint8_t family;
+ pj_uint16_t port;
+ pj_uint32_t addr;
+} pj_stun_mapped_addr_attr;
+
+typedef pj_stun_mapped_addr_attr pj_stun_response_addr_attr;
+typedef pj_stun_mapped_addr_attr pj_stun_changed_addr_attr;
+typedef pj_stun_mapped_addr_attr pj_stun_src_addr_attr;
+typedef pj_stun_mapped_addr_attr pj_stun_reflected_form_attr;
+
+typedef struct pj_stun_change_request_attr
+{
+ pj_stun_attr_hdr hdr;
+ pj_uint32_t value;
+} pj_stun_change_request_attr;
+
+typedef struct pj_stun_username_attr
+{
+ pj_stun_attr_hdr hdr;
+ pj_uint32_t value[1];
+} pj_stun_username_attr;
+
+typedef pj_stun_username_attr pj_stun_password_attr;
+
+typedef struct pj_stun_error_code_attr
+{
+ pj_stun_attr_hdr hdr;
+ pj_uint16_t ignored;
+ pj_uint8_t err_class;
+ pj_uint8_t number;
+ char reason[4];
+} pj_stun_error_code_attr;
+
+typedef struct pj_stun_msg
+{
+ pj_stun_msg_hdr *hdr;
+ int attr_count;
+ pj_stun_attr_hdr *attr[PJ_STUN_MAX_ATTR];
+} pj_stun_msg;
+
+/* STUN message API (stun.c). */
+
+PJ_DECL(pj_status_t) pj_stun_create_bind_req( pj_pool_t *pool,
+ void **msg, pj_size_t *len,
+ pj_uint32_t id_hi,
+ pj_uint32_t id_lo);
+PJ_DECL(pj_status_t) pj_stun_parse_msg( void *buf, pj_size_t len,
+ pj_stun_msg *msg);
+PJ_DECL(void*) pj_stun_msg_find_attr( pj_stun_msg *msg, pj_stun_attr_type t);
+
+/* STUN simple client API (stun_client.c) */
+enum pj_stun_err_code {
+ PJ_STUN_ERR_MEMORY = (-2),
+ PJ_STUN_ERR_RESOLVE = (-3),
+ PJ_STUN_ERR_TRANSPORT = (-4),
+ PJ_STUN_ERR_INVALID_MSG = (-5),
+ PJ_STUN_ERR_NO_RESPONSE = (-6),
+ PJ_STUN_ERR_SYMETRIC = (-7),
+};
+
+PJ_DECL(pj_status_t) pj_stun_get_mapped_addr( pj_pool_factory *pf,
+ int sock_cnt, pj_sock_t sock[],
+ const pj_str_t *srv1, int port1,
+ const pj_str_t *srv2, int port2,
+ pj_sockaddr_in mapped_addr[]);
+PJ_DECL(const char*) pj_stun_get_err_msg(pj_status_t status);
+
+PJ_END_DECL
+
+#endif /* __PJ_STUN_H__ */
+
diff --git a/pjlib-util/include/pjlib-util/xml.h b/pjlib-util/include/pjlib-util/xml.h
index 05f67bbf..d54fc2d5 100644
--- a/pjlib-util/include/pjlib-util/xml.h
+++ b/pjlib-util/include/pjlib-util/xml.h
@@ -1,171 +1,171 @@
-/* $Id$ */
-/*
- * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __PJ_XML_H__
-#define __PJ_XML_H__
-
-/**
- * @file xml.h
- * @brief PJLIB XML Parser/Helper.
- */
-
-#include <pj/types.h>
-#include <pj/list.h>
-
-PJ_BEGIN_DECL
-
-/**
- * @defgroup PJ_XML XML Parser/Helper.
- * @ingroup PJ
- * @{
- */
-
-/** Typedef for XML attribute. */
-typedef struct pj_xml_attr pj_xml_attr;
-
-/** Typedef for XML nodes. */
-typedef struct pj_xml_node pj_xml_node;
-
-/** This structure declares XML attribute. */
-struct pj_xml_attr
-{
- PJ_DECL_LIST_MEMBER(pj_xml_attr); /**< Standard list elements. */
- pj_str_t name; /**< Attribute name. */
- pj_str_t value; /**< Attribute value. */
-};
-
-/** This structure describes XML node head inside XML node structure.
- */
-typedef struct pj_xml_node_head
-{
- PJ_DECL_LIST_MEMBER(pj_xml_node); /**< Standard list elements. */
-} pj_xml_node_head;
-
-/** This structure describes XML node. */
-struct pj_xml_node
-{
- PJ_DECL_LIST_MEMBER(pj_xml_node); /**< List @a prev and @a next member */
- pj_str_t name; /**< Node name. */
- pj_xml_attr attr_head; /**< Attribute list. */
- pj_xml_node_head node_head; /**< Node list. */
- pj_str_t content; /**< Node content. */
-};
-
-/**
- * Parse XML message into XML document with a single root node. The parser
- * is capable of parsing XML processing instruction construct ("<?") and
- * XML comments ("<!--"), however such constructs will be ignored and will not
- * be included in the resulted XML node tree.
- *
- * @param pool Pool to allocate memory from.
- * @param msg The XML message to parse.
- * @param len The length of the message.
- *
- * @return XML root node, or NULL if the XML document can not be parsed.
- */
-PJ_DECL(pj_xml_node*) pj_xml_parse( pj_pool_t *pool, char *msg, pj_size_t len);
-
-
-/**
- * Print XML into XML message. Note that the function WILL NOT NULL terminate
- * the output.
- *
- * @param node The XML node to print.
- * @param buf Buffer to hold the output message.
- * @param len The length of the buffer.
- * @param prolog If set to nonzero, will print XML prolog ("<?xml..")
- *
- * @return The size of the printed message, or -1 if there is not
- * sufficient space in the buffer to print the message.
- */
-PJ_DECL(int) pj_xml_print( const pj_xml_node *node, char *buf, pj_size_t len,
- pj_bool_t include_prolog);
-
-/**
- * Add node to another node.
- *
- * @param parent Parent node.
- * @param node Node to be added to parent.
- */
-PJ_DECL(void) pj_xml_add_node( pj_xml_node *parent, pj_xml_node *node );
-
-
-/**
- * Add attribute to a node.
- *
- * @param node Node.
- * @param attr Attribute to add to node.
- */
-PJ_DECL(void) pj_xml_add_attr( pj_xml_node *node, pj_xml_attr *attr );
-
-/**
- * Find first node with the specified name.
- *
- * @param parent Parent node.
- * @param name Node name to find.
- *
- * @return XML node found or NULL.
- */
-PJ_DECL(pj_xml_node*) pj_xml_find_node(pj_xml_node *parent, const pj_str_t *name);
-
-/**
- * Find first node with the specified name.
- *
- * @param parent Parent node.
- * @param name Node name to find.
- *
- * @return XML node found or NULL.
- */
-PJ_DECL(pj_xml_node*) pj_xml_find_next_node(pj_xml_node *parent, pj_xml_node *node,
- const pj_str_t *name);
-
-/**
- * Find first attribute within a node with the specified name and optional value.
- *
- * @param node XML Node.
- * @param name Attribute name to find.
- * @param value Optional value to match.
- *
- * @return XML attribute found, or NULL.
- */
-PJ_DECL(pj_xml_attr*) pj_xml_find_attr(pj_xml_node *node, const pj_str_t *name,
- const pj_str_t *value);
-
-
-/**
- * Find a direct child node with the specified name and match the function.
- *
- * @param node Parent node.
- * @param name Optional name.
- * @param data Data to be passed to matching function.
- * @param match Optional matching function.
- *
- * @return The first matched node, or NULL.
- */
-PJ_DECL(pj_xml_node*) pj_xml_find( pj_xml_node *parent, const pj_str_t *name,
- const void *data,
- pj_bool_t (*match)(pj_xml_node *, const void*));
-
-
-/**
- * @}
- */
-
-PJ_END_DECL
-
-#endif /* __PJ_XML_H__ */
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJ_XML_H__
+#define __PJ_XML_H__
+
+/**
+ * @file xml.h
+ * @brief PJLIB XML Parser/Helper.
+ */
+
+#include <pj/types.h>
+#include <pj/list.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJ_XML XML Parser/Helper.
+ * @ingroup PJ
+ * @{
+ */
+
+/** Typedef for XML attribute. */
+typedef struct pj_xml_attr pj_xml_attr;
+
+/** Typedef for XML nodes. */
+typedef struct pj_xml_node pj_xml_node;
+
+/** This structure declares XML attribute. */
+struct pj_xml_attr
+{
+ PJ_DECL_LIST_MEMBER(pj_xml_attr); /**< Standard list elements. */
+ pj_str_t name; /**< Attribute name. */
+ pj_str_t value; /**< Attribute value. */
+};
+
+/** This structure describes XML node head inside XML node structure.
+ */
+typedef struct pj_xml_node_head
+{
+ PJ_DECL_LIST_MEMBER(pj_xml_node); /**< Standard list elements. */
+} pj_xml_node_head;
+
+/** This structure describes XML node. */
+struct pj_xml_node
+{
+ PJ_DECL_LIST_MEMBER(pj_xml_node); /**< List @a prev and @a next member */
+ pj_str_t name; /**< Node name. */
+ pj_xml_attr attr_head; /**< Attribute list. */
+ pj_xml_node_head node_head; /**< Node list. */
+ pj_str_t content; /**< Node content. */
+};
+
+/**
+ * Parse XML message into XML document with a single root node. The parser
+ * is capable of parsing XML processing instruction construct ("<?") and
+ * XML comments ("<!--"), however such constructs will be ignored and will not
+ * be included in the resulted XML node tree.
+ *
+ * @param pool Pool to allocate memory from.
+ * @param msg The XML message to parse.
+ * @param len The length of the message.
+ *
+ * @return XML root node, or NULL if the XML document can not be parsed.
+ */
+PJ_DECL(pj_xml_node*) pj_xml_parse( pj_pool_t *pool, char *msg, pj_size_t len);
+
+
+/**
+ * Print XML into XML message. Note that the function WILL NOT NULL terminate
+ * the output.
+ *
+ * @param node The XML node to print.
+ * @param buf Buffer to hold the output message.
+ * @param len The length of the buffer.
+ * @param prolog If set to nonzero, will print XML prolog ("<?xml..")
+ *
+ * @return The size of the printed message, or -1 if there is not
+ * sufficient space in the buffer to print the message.
+ */
+PJ_DECL(int) pj_xml_print( const pj_xml_node *node, char *buf, pj_size_t len,
+ pj_bool_t include_prolog);
+
+/**
+ * Add node to another node.
+ *
+ * @param parent Parent node.
+ * @param node Node to be added to parent.
+ */
+PJ_DECL(void) pj_xml_add_node( pj_xml_node *parent, pj_xml_node *node );
+
+
+/**
+ * Add attribute to a node.
+ *
+ * @param node Node.
+ * @param attr Attribute to add to node.
+ */
+PJ_DECL(void) pj_xml_add_attr( pj_xml_node *node, pj_xml_attr *attr );
+
+/**
+ * Find first node with the specified name.
+ *
+ * @param parent Parent node.
+ * @param name Node name to find.
+ *
+ * @return XML node found or NULL.
+ */
+PJ_DECL(pj_xml_node*) pj_xml_find_node(pj_xml_node *parent, const pj_str_t *name);
+
+/**
+ * Find first node with the specified name.
+ *
+ * @param parent Parent node.
+ * @param name Node name to find.
+ *
+ * @return XML node found or NULL.
+ */
+PJ_DECL(pj_xml_node*) pj_xml_find_next_node(pj_xml_node *parent, pj_xml_node *node,
+ const pj_str_t *name);
+
+/**
+ * Find first attribute within a node with the specified name and optional value.
+ *
+ * @param node XML Node.
+ * @param name Attribute name to find.
+ * @param value Optional value to match.
+ *
+ * @return XML attribute found, or NULL.
+ */
+PJ_DECL(pj_xml_attr*) pj_xml_find_attr(pj_xml_node *node, const pj_str_t *name,
+ const pj_str_t *value);
+
+
+/**
+ * Find a direct child node with the specified name and match the function.
+ *
+ * @param node Parent node.
+ * @param name Optional name.
+ * @param data Data to be passed to matching function.
+ * @param match Optional matching function.
+ *
+ * @return The first matched node, or NULL.
+ */
+PJ_DECL(pj_xml_node*) pj_xml_find( pj_xml_node *parent, const pj_str_t *name,
+ const void *data,
+ pj_bool_t (*match)(pj_xml_node *, const void*));
+
+
+/**
+ * @}
+ */
+
+PJ_END_DECL
+
+#endif /* __PJ_XML_H__ */