Expand tab to spaces and remove $Id$ (#3292)

This commit is contained in:
Riza Sulistyo 2022-11-22 16:26:54 +07:00 committed by GitHub
parent d00fc12807
commit 5ac9104514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1166 changed files with 154566 additions and 155674 deletions

8
.editorconfig Normal file
View File

@ -0,0 +1,8 @@
root = true
# properties
[*.{h,c,hpp,cpp,m,java}]
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

View File

@ -223,7 +223,7 @@ OBOE_CFLAGS = @ac_oboe_cflags@
# PJMEDIA features exclusion
PJ_VIDEO_CFLAGS += $(SDL_CFLAGS) $(FFMPEG_CFLAGS) $(V4L2_CFLAGS) $(DSHOW_CFLAGS) $(QT_CFLAGS) \
$(OPENH264_CFLAGS) $(VPX_CFLAGS) $(DARWIN_CFLAGS)
$(OPENH264_CFLAGS) $(VPX_CFLAGS) $(DARWIN_CFLAGS)
PJ_VIDEO_LDFLAGS += $(SDL_LDFLAGS) $(FFMPEG_LDFLAGS) $(V4L2_LDFLAGS) $(DSHOW_LDFLAGS) \
$(OPENH264_LDFLAGS) $(VPX_LDFLAGS)
@ -231,40 +231,40 @@ PJ_VIDEO_LDFLAGS += $(SDL_LDFLAGS) $(FFMPEG_LDFLAGS) $(V4L2_LDFLAGS) $(DSHOW_LDF
export APP_CC := @CC@
export APP_CXX := @CXX@
export APP_CFLAGS := -DPJ_AUTOCONF=1\
@CFLAGS@\
$(PJ_VIDEO_CFLAGS) \
-I$(PJDIR)/pjlib/include\
-I$(PJDIR)/pjlib-util/include\
-I$(PJDIR)/pjnath/include\
-I$(PJDIR)/pjmedia/include\
-I$(PJDIR)/pjsip/include
@CFLAGS@\
$(PJ_VIDEO_CFLAGS) \
-I$(PJDIR)/pjlib/include\
-I$(PJDIR)/pjlib-util/include\
-I$(PJDIR)/pjnath/include\
-I$(PJDIR)/pjmedia/include\
-I$(PJDIR)/pjsip/include
export APP_CXXFLAGS := @CXXFLAGS@ $(APP_CFLAGS)
export APP_LDFLAGS := -L$(PJDIR)/pjlib/lib\
-L$(PJDIR)/pjlib-util/lib\
-L$(PJDIR)/pjnath/lib\
-L$(PJDIR)/pjmedia/lib\
-L$(PJDIR)/pjsip/lib\
-L$(PJDIR)/third_party/lib\
$(PJ_VIDEO_LDFLAGS) \
@LDFLAGS@
-L$(PJDIR)/pjlib-util/lib\
-L$(PJDIR)/pjnath/lib\
-L$(PJDIR)/pjmedia/lib\
-L$(PJDIR)/pjsip/lib\
-L$(PJDIR)/third_party/lib\
$(PJ_VIDEO_LDFLAGS) \
@LDFLAGS@
export APP_LDXXFLAGS := $(APP_LDFLAGS)
export APP_LIB_FILES := \
$(PJ_DIR)/pjsip/lib/libpjsua-$(LIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-ua-$(LIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-simple-$(LIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-$(LIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-codec-$(LIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-videodev-$(LIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-$(LIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-audiodev-$(LIB_SUFFIX) \
$(PJ_DIR)/pjnath/lib/libpjnath-$(LIB_SUFFIX) \
$(PJ_DIR)/pjlib-util/lib/libpjlib-util-$(LIB_SUFFIX) \
$(APP_THIRD_PARTY_LIB_FILES) \
$(PJ_DIR)/pjlib/lib/libpj-$(LIB_SUFFIX)
$(PJ_DIR)/pjsip/lib/libpjsua-$(LIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-ua-$(LIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-simple-$(LIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-$(LIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-codec-$(LIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-videodev-$(LIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-$(LIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-audiodev-$(LIB_SUFFIX) \
$(PJ_DIR)/pjnath/lib/libpjnath-$(LIB_SUFFIX) \
$(PJ_DIR)/pjlib-util/lib/libpjlib-util-$(LIB_SUFFIX) \
$(APP_THIRD_PARTY_LIB_FILES) \
$(PJ_DIR)/pjlib/lib/libpj-$(LIB_SUFFIX)
export APP_LIBXX_FILES := \
$(PJ_DIR)/pjsip/lib/libpjsua2-$(LIB_SUFFIX) \
$(APP_LIB_FILES)
$(PJ_DIR)/pjsip/lib/libpjsua2-$(LIB_SUFFIX) \
$(APP_LIB_FILES)
ifeq ($(PJ_SHARED_LIBRARIES),)
export PJLIB_LDLIB := -lpj-$(TARGET_NAME)
@ -294,21 +294,21 @@ export PJSUA_LIB_LDLIB := -lpjsua
export PJSUA2_LIB_LDLIB := -lpjsua2
export ADD_LIB_FILES := $(PJ_DIR)/pjsip/lib/libpjsua.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsua.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-ua.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsip-ua.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-simple.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsip-simple.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsip.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-codec.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjmedia/lib/libpjmedia-codec.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-videodev.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjmedia/lib/libpjmedia-videodev.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjmedia/lib/libpjmedia.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-audiodev.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjmedia/lib/libpjmedia-audiodev.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjnath/lib/libpjnath.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjnath/lib/libpjnath.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjlib-util/lib/libpjlib-util.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjlib-util/lib/libpjlib-util.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjlib/lib/libpj.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjlib/lib/libpj.$(SHLIB_SUFFIX)
$(PJ_DIR)/pjsip/lib/libpjsip-ua.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsip-ua.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip-simple.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsip-simple.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjsip/lib/libpjsip.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsip.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-codec.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjmedia/lib/libpjmedia-codec.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-videodev.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjmedia/lib/libpjmedia-videodev.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjmedia/lib/libpjmedia.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjmedia/lib/libpjmedia-audiodev.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjmedia/lib/libpjmedia-audiodev.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjnath/lib/libpjnath.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjnath/lib/libpjnath.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjlib-util/lib/libpjlib-util.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjlib-util/lib/libpjlib-util.$(SHLIB_SUFFIX) \
$(PJ_DIR)/pjlib/lib/libpj.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjlib/lib/libpj.$(SHLIB_SUFFIX)
APP_LIB_FILES += $(ADD_LIB_FILES)
APP_LIBXX_FILES += $(PJ_DIR)/pjsip/lib/libpjsua2.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/pjsip/lib/libpjsua2.$(SHLIB_SUFFIX) \
$(ADD_LIB_FILES)
$(ADD_LIB_FILES)
endif
ifeq ($(PJ_EXCLUDE_PJSUA2),1)
@ -316,23 +316,23 @@ export PJSUA2_LIB_LDLIB :=
endif
export APP_LDLIBS := $(PJSUA_LIB_LDLIB) \
$(PJSIP_UA_LDLIB) \
$(PJSIP_SIMPLE_LDLIB) \
$(PJSIP_LDLIB) \
$(PJMEDIA_CODEC_LDLIB) \
$(PJMEDIA_LDLIB) \
$(PJMEDIA_VIDEODEV_LDLIB) \
$(PJMEDIA_AUDIODEV_LDLIB) \
$(PJMEDIA_LDLIB) \
$(PJNATH_LDLIB) \
$(PJLIB_UTIL_LDLIB) \
$(APP_THIRD_PARTY_LIBS)\
$(APP_THIRD_PARTY_EXT)\
$(PJLIB_LDLIB) \
@LIBS@
$(PJSIP_UA_LDLIB) \
$(PJSIP_SIMPLE_LDLIB) \
$(PJSIP_LDLIB) \
$(PJMEDIA_CODEC_LDLIB) \
$(PJMEDIA_LDLIB) \
$(PJMEDIA_VIDEODEV_LDLIB) \
$(PJMEDIA_AUDIODEV_LDLIB) \
$(PJMEDIA_LDLIB) \
$(PJNATH_LDLIB) \
$(PJLIB_UTIL_LDLIB) \
$(APP_THIRD_PARTY_LIBS)\
$(APP_THIRD_PARTY_EXT)\
$(PJLIB_LDLIB) \
@LIBS@
export APP_LDXXLIBS := $(PJSUA2_LIB_LDLIB) \
-lstdc++ \
$(APP_LDLIBS)
-lstdc++ \
$(APP_LDLIBS)
# Here are the variables to use if application is using the library
# from within the source distribution

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -72,5 +71,5 @@
#include <pjlib-util/cli_console.h>
#include <pjlib-util/cli_telnet.h>
#endif /* __PJLIB_UTIL_H__ */
#endif /* __PJLIB_UTIL_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -40,44 +39,44 @@ PJ_BEGIN_DECL
* Helper macro to calculate the approximate length required for base256 to
* base64 conversion.
*/
#define PJ_BASE256_TO_BASE64_LEN(len) (len * 4 / 3 + 3)
#define PJ_BASE256_TO_BASE64_LEN(len) (len * 4 / 3 + 3)
/**
* Helper macro to calculate the approximage length required for base64 to
* base256 conversion.
*/
#define PJ_BASE64_TO_BASE256_LEN(len) (len * 3 / 4)
#define PJ_BASE64_TO_BASE256_LEN(len) (len * 3 / 4)
/**
* Encode a buffer into base64 encoding.
*
* @param input The input buffer.
* @param input The input buffer.
* @param in_len Size of the input buffer.
* @param output Output buffer. Caller must allocate this buffer with
* the appropriate size.
* the appropriate size.
* @param out_len On entry, it specifies the length of the output buffer.
* Upon return, this will be filled with the actual
* length of the output buffer.
* Upon return, this will be filled with the actual
* length of the output buffer.
*
* @return PJ_SUCCESS on success.
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pj_base64_encode(const pj_uint8_t *input, int in_len,
char *output, int *out_len);
char *output, int *out_len);
/**
* Decode base64 string.
*
* @param input Input string.
* @param out Buffer to store the output. Caller must allocate
* this buffer with the appropriate size.
* @param input Input string.
* @param out Buffer to store the output. Caller must allocate
* this buffer with the appropriate size.
* @param out_len On entry, it specifies the length of the output buffer.
* Upon return, this will be filled with the actual
* length of the output.
* Upon return, this will be filled with the actual
* length of the output.
*/
PJ_DECL(pj_status_t) pj_base64_decode(const pj_str_t *input,
pj_uint8_t *out, int *out_len);
pj_uint8_t *out, int *out_len);
@ -88,5 +87,5 @@ PJ_DECL(pj_status_t) pj_base64_decode(const pj_str_t *input,
PJ_END_DECL
#endif /* __PJLIB_UTIL_BASE64_H__ */
#endif /* __PJLIB_UTIL_BASE64_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2010 Teluu Inc. (http://www.teluu.com)
*
@ -60,10 +59,10 @@ PJ_BEGIN_DECL
</CMD>
</CMD>
<CMD name='disable_codec' id=0 desc="">
<ARG name='codec_list' type='choice' id='3'>
<CHOICE value='g711'/>
<CHOICE value='g722'/>
</ARG>
<ARG name='codec_list' type='choice' id='3'>
<CHOICE value='g711'/>
<CHOICE value='g722'/>
</ARG>
</CMD>
\endverbatim
*/
@ -299,10 +298,10 @@ typedef pj_status_t (*pj_cli_cmd_handler)(pj_cli_cmd_val *cval);
* Write a log message to the CLI application. The CLI application
* will send the log message to all the registered front-ends.
*
* @param cli The CLI application instance.
* @param level Verbosity level of this message message.
* @param cli The CLI application instance.
* @param level Verbosity level of this message message.
* @param buffer The message itself.
* @param len Length of this message.
* @param len Length of this message.
*/
PJ_DECL(void) pj_cli_write_log(pj_cli_t *cli,
int level,
@ -312,10 +311,10 @@ PJ_DECL(void) pj_cli_write_log(pj_cli_t *cli,
/**
* Create a new CLI application instance.
*
* @param cfg CLI application creation parameters.
* @param p_cli Pointer to receive the returned instance.
* @param cfg CLI application creation parameters.
* @param p_cli Pointer to receive the returned instance.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_cli_create(pj_cli_cfg *cfg,
pj_cli_t **p_cli);
@ -323,18 +322,18 @@ PJ_DECL(pj_status_t) pj_cli_create(pj_cli_cfg *cfg,
/**
* This specifies the function to get the id of the specified command
*
* @param cmd The specified command.
* @param cmd The specified command.
*
* @return The command id
* @return The command id
*/
PJ_DECL(pj_cli_cmd_id) pj_cli_get_cmd_id(const pj_cli_cmd_spec *cmd);
/**
* Get the internal parameter of the CLI instance.
*
* @param cli The CLI application instance.
* @param cli The CLI application instance.
*
* @return CLI parameter instance.
* @return CLI parameter instance.
*/
PJ_DECL(pj_cli_cfg*) pj_cli_get_param(pj_cli_t *cli);
@ -346,29 +345,29 @@ PJ_DECL(pj_cli_cfg*) pj_cli_get_param(pj_cli_t *cli);
* See also pj_cli_sess_end_session() to end a session instead of quitting the
* whole application.
*
* @param cli The CLI application instance.
* @param req The session on which the shutdown request is
* received.
* @param restart Indicate whether application restart is wanted.
* @param cli The CLI application instance.
* @param req The session on which the shutdown request is
* received.
* @param restart Indicate whether application restart is wanted.
*/
PJ_DECL(void) pj_cli_quit(pj_cli_t *cli, pj_cli_sess *req,
pj_bool_t restart);
pj_bool_t restart);
/**
* Check if application shutdown or restart has been requested.
*
* @param cli The CLI application instance.
* @param cli The CLI application instance.
*
* @return PJ_TRUE if pj_cli_quit() has been called.
* @return PJ_TRUE if pj_cli_quit() has been called.
*/
PJ_DECL(pj_bool_t) pj_cli_is_quitting(pj_cli_t *cli);
/**
* Check if application restart has been requested.
*
* @param cli The CLI application instance.
* @param cli The CLI application instance.
*
* @return PJ_TRUE if pj_cli_quit() has been called with
* restart parameter set.
* @return PJ_TRUE if pj_cli_quit() has been called with
* restart parameter set.
*/
PJ_DECL(pj_bool_t) pj_cli_is_restarting(pj_cli_t *cli);
@ -376,7 +375,7 @@ PJ_DECL(pj_bool_t) pj_cli_is_restarting(pj_cli_t *cli);
* Destroy a CLI application instance. This would also close all sessions
* currently running for this CLI application.
*
* @param cli The CLI application.
* @param cli The CLI application.
*/
PJ_DECL(void) pj_cli_destroy(pj_cli_t *cli);
@ -390,8 +389,8 @@ PJ_DECL(void) pj_cli_cfg_default(pj_cli_cfg *param);
/**
* Register a front end to the CLI application.
*
* @param cli The CLI application.
* @param fe The CLI front end to be registered.
* @param cli The CLI application.
* @param fe The CLI front end to be registered.
*/
PJ_DECL(void) pj_cli_register_front_end(pj_cli_t *cli,
pj_cli_front_end *fe);
@ -402,44 +401,44 @@ PJ_DECL(void) pj_cli_register_front_end(pj_cli_t *cli,
*
* Note that the input string MUST be NULL terminated.
*
* @param cli The CLI application.
* @param group Optional group to which this command will be added
* to, or specify NULL if this command is a root
* command.
* @param xml Input string containing XML node text for the
* command, MUST be NULL terminated.
* @param handler Function handler for the command. This must be NULL
* if the command specifies a command group.
* @param p_cmd Optional pointer to store the newly created
* specification.
* @param get_choice Function handler for the argument. Specify this for
* dynamic choice type arguments.
* @param cli The CLI application.
* @param group Optional group to which this command will be added
* to, or specify NULL if this command is a root
* command.
* @param xml Input string containing XML node text for the
* command, MUST be NULL terminated.
* @param handler Function handler for the command. This must be NULL
* if the command specifies a command group.
* @param p_cmd Optional pointer to store the newly created
* specification.
* @param get_choice Function handler for the argument. Specify this for
* dynamic choice type arguments.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_cli_add_cmd_from_xml(pj_cli_t *cli,
pj_cli_cmd_spec *group,
pj_cli_cmd_spec *group,
const pj_str_t *xml,
pj_cli_cmd_handler handler,
pj_cli_cmd_spec **p_cmd,
pj_cli_get_dyn_choice get_choice);
pj_cli_get_dyn_choice get_choice);
/**
* Initialize pj_cli_exec_info with its default values.
*
* @param param The param to be initialized.
* @param param The param to be initialized.
*/
PJ_DECL(void) pj_cli_exec_info_default(pj_cli_exec_info *param);
/**
* Write a log message to the specific CLI session.
*
* @param sess The CLI active session.
* @param sess The CLI active session.
* @param buffer The message itself.
* @param len Length of this message.
* @param len Length of this message.
*/
PJ_DECL(void) pj_cli_sess_write_msg(pj_cli_sess *sess,
const char *buffer,
pj_size_t len);
const char *buffer,
pj_size_t len);
/**
* Parse an input cmdline string. The first word of the command line is the
@ -459,29 +458,29 @@ PJ_DECL(void) pj_cli_sess_write_msg(pj_cli_sess *sess,
* which will be removed by the function. However any more characters
* following this newline will cause an error to be returned.
*
* @param sess The CLI session.
* @param cmdline The command line string to be parsed.
* @param val Structure to store the parsing result.
* @param pool The pool to allocate memory from.
* @param info Additional info to be returned regarding the parsing.
* @param sess The CLI session.
* @param cmdline The command line string to be parsed.
* @param val Structure to store the parsing result.
* @param pool The pool to allocate memory from.
* @param info Additional info to be returned regarding the parsing.
*
* @return This function returns the status of the parsing,
* which can be one of the following :
* - PJ_SUCCESS: a command was executed successfully.
* - PJ_EINVAL: invalid parameter to this function.
* - PJ_ENOTFOUND: command is not found.
* - PJ_CLI_EAMBIGUOUS: command/argument is ambiguous.
* - PJ_CLI_EMISSINGARG: missing argument.
* - PJ_CLI_EINVARG: invalid command argument.
* - PJ_CLI_EEXIT: "exit" has been called to end
* the current session. This is a signal for the
* application to end it's main loop.
* @return This function returns the status of the parsing,
* which can be one of the following :
* - PJ_SUCCESS: a command was executed successfully.
* - PJ_EINVAL: invalid parameter to this function.
* - PJ_ENOTFOUND: command is not found.
* - PJ_CLI_EAMBIGUOUS: command/argument is ambiguous.
* - PJ_CLI_EMISSINGARG: missing argument.
* - PJ_CLI_EINVARG: invalid command argument.
* - PJ_CLI_EEXIT: "exit" has been called to end
* the current session. This is a signal for the
* application to end it's main loop.
*/
PJ_DECL(pj_status_t) pj_cli_sess_parse(pj_cli_sess *sess,
char *cmdline,
pj_cli_cmd_val *val,
pj_pool_t *pool,
pj_cli_exec_info *info);
char *cmdline,
pj_cli_cmd_val *val,
pj_pool_t *pool,
pj_cli_exec_info *info);
/**
* End the specified session, and destroy it to release all resources used
@ -491,7 +490,7 @@ PJ_DECL(pj_status_t) pj_cli_sess_parse(pj_cli_sess *sess,
* creation process.
* See also pj_cli_quit() to quit the whole application instead.
*
* @param sess The CLI session to be destroyed.
* @param sess The CLI session to be destroyed.
*/
PJ_DECL(void) pj_cli_sess_end_session(pj_cli_sess *sess);
@ -504,23 +503,23 @@ PJ_DECL(void) pj_cli_sess_end_session(pj_cli_sess *sess);
*
* See also pj_cli_sess_parse() for more info regarding the cmdline format.
*
* @param sess The CLI session.
* @param cmdline The command line string to be executed.
* @param pool The pool to allocate memory from.
* @param info Optional pointer to receive additional information
* related to the execution of the command (such as
* the command return value).
* @param sess The CLI session.
* @param cmdline The command line string to be executed.
* @param pool The pool to allocate memory from.
* @param info Optional pointer to receive additional information
* related to the execution of the command (such as
* the command return value).
*
* @return This function returns the status of the command
* parsing and execution (note that the return value
* of the handler itself will be returned in \a info
* argument, if specified). Please see the return value
* of pj_cli_sess_parse() for possible return values.
* @return This function returns the status of the command
* parsing and execution (note that the return value
* of the handler itself will be returned in \a info
* argument, if specified). Please see the return value
* of pj_cli_sess_parse() for possible return values.
*/
PJ_DECL(pj_status_t) pj_cli_sess_exec(pj_cli_sess *sess,
char *cmdline,
pj_pool_t *pool,
pj_cli_exec_info *info);
char *cmdline,
pj_pool_t *pool,
pj_cli_exec_info *info);
/**
* @}

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2010 Teluu Inc. (http://www.teluu.com)
*
@ -70,7 +69,7 @@ typedef struct pj_cli_console_cfg
/**
* Initialize pj_cli_console_cfg with its default values.
*
* @param param The structure to be initialized.
* @param param The structure to be initialized.
*/
PJ_DECL(void) pj_cli_console_cfg_default(pj_cli_console_cfg *param);
@ -80,33 +79,33 @@ PJ_DECL(void) pj_cli_console_cfg_default(pj_cli_console_cfg *param);
* the only session instance for the console front end. On Windows operating
* system, this may open a new console window.
*
* @param cli The CLI application instance.
* @param param Optional console CLI parameters. If this value is
* NULL, default parameters will be used.
* @param p_sess Pointer to receive the session instance for the
* console front end.
* @param p_fe Optional pointer to receive the front-end instance
* of the console front-end just created.
* @param cli The CLI application instance.
* @param param Optional console CLI parameters. If this value is
* NULL, default parameters will be used.
* @param p_sess Pointer to receive the session instance for the
* console front end.
* @param p_fe Optional pointer to receive the front-end instance
* of the console front-end just created.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_cli_console_create(pj_cli_t *cli,
const pj_cli_console_cfg *param,
pj_cli_sess **p_sess,
pj_cli_front_end **p_fe);
const pj_cli_console_cfg *param,
pj_cli_sess **p_sess,
pj_cli_front_end **p_fe);
/**
* Retrieve a cmdline from console stdin and process the input accordingly.
*
* @param sess The CLI session.
* @param buf Pointer to receive the buffer.
* @param maxlen Maximum length to read.
* @param sess The CLI session.
* @param buf Pointer to receive the buffer.
* @param maxlen Maximum length to read.
*
* @return PJ_SUCCESS if an input was read
* @return PJ_SUCCESS if an input was read
*/
PJ_DECL(pj_status_t) pj_cli_console_process(pj_cli_sess *sess,
char *buf,
unsigned maxlen);
char *buf,
unsigned maxlen);
/**
* @}

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2010 Teluu Inc. (http://www.teluu.com)
*
@ -40,21 +39,21 @@ PJ_BEGIN_DECL
* Default log level for console sessions.
*/
#ifndef PJ_CLI_CONSOLE_LOG_LEVEL
# define PJ_CLI_CONSOLE_LOG_LEVEL PJ_LOG_MAX_LEVEL
# define PJ_CLI_CONSOLE_LOG_LEVEL PJ_LOG_MAX_LEVEL
#endif
/**
* Default log level for telnet sessions.
*/
#ifndef PJ_CLI_TELNET_LOG_LEVEL
# define PJ_CLI_TELNET_LOG_LEVEL 4
# define PJ_CLI_TELNET_LOG_LEVEL 4
#endif
/**
* Default port number for telnet daemon.
*/
#ifndef PJ_CLI_TELNET_PORT
# define PJ_CLI_TELNET_PORT 0
# define PJ_CLI_TELNET_PORT 0
#endif
/**
@ -62,10 +61,10 @@ PJ_BEGIN_DECL
*/
typedef enum pj_cli_front_end_type
{
PJ_CLI_CONSOLE_FRONT_END, /**< Console front end. */
PJ_CLI_TELNET_FRONT_END, /**< Telnet front end. */
PJ_CLI_HTTP_FRONT_END, /**< HTTP front end. */
PJ_CLI_GUI_FRONT_END /**< GUI front end. */
PJ_CLI_CONSOLE_FRONT_END, /**< Console front end. */
PJ_CLI_TELNET_FRONT_END, /**< Telnet front end. */
PJ_CLI_HTTP_FRONT_END, /**< HTTP front end. */
PJ_CLI_GUI_FRONT_END /**< GUI front end. */
} pj_cli_front_end_type;
@ -81,21 +80,21 @@ typedef struct pj_cli_front_end_op
* the session if the session's log verbosity level is greater than the
* level of this log message.
*
* @param fe The front end.
* @param level Verbosity level of this message message.
* @param data The message itself.
* @param len Length of this message.
* @param fe The front end.
* @param level Verbosity level of this message message.
* @param data The message itself.
* @param len Length of this message.
*/
void (*on_write_log)(pj_cli_front_end *fe, int level,
const char *data, pj_size_t len);
const char *data, pj_size_t len);
/**
* Callback to be called when the application is quitting, to signal the
* front-end to end its main loop or any currently blocking functions,
* if any.
*
* @param fe The front end.
* @param req The session which requested the application quit.
* @param fe The front end.
* @param req The session which requested the application quit.
*/
void (*on_quit)(pj_cli_front_end *fe, pj_cli_sess *req);
@ -103,7 +102,7 @@ typedef struct pj_cli_front_end_op
* Callback to be called to close and self destroy the front-end. This
* must also close any active sessions created by this front-ends.
*
* @param fe The front end.
* @param fe The front end.
*/
void (*on_destroy)(pj_cli_front_end *fe);
@ -152,7 +151,7 @@ typedef struct pj_cli_sess_op
/**
* Callback to be called to close and self destroy the session.
*
* @param sess The session to destroy.
* @param sess The session to destroy.
*/
void (*destroy)(pj_cli_sess *sess);
@ -205,4 +204,4 @@ struct pj_cli_sess
PJ_END_DECL
#endif /* __PJLIB_UTIL_CLI_IMP_H__ */
#endif /* __PJLIB_UTIL_CLI_IMP_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2010 Teluu Inc. (http://www.teluu.com)
*
@ -44,7 +43,7 @@ typedef struct pj_cli_telnet_info
/**
* The telnet's ip address.
*/
pj_str_t ip_address;
pj_str_t ip_address;
/**
* The telnet's port number.
@ -59,7 +58,7 @@ typedef struct pj_cli_telnet_info
/**
* This specifies the callback called when telnet is started
*
* @param status The status of telnet startup process.
* @param status The status of telnet startup process.
*
*/
typedef void (*pj_cli_telnet_on_started)(pj_status_t status);
@ -127,7 +126,7 @@ typedef struct pj_cli_telnet_cfg
/**
* Initialize pj_cli_telnet_cfg with its default values.
*
* @param param The structure to be initialized.
* @param param The structure to be initialized.
*/
PJ_DECL(void) pj_cli_telnet_cfg_default(pj_cli_telnet_cfg *param);
@ -135,17 +134,17 @@ PJ_DECL(void) pj_cli_telnet_cfg_default(pj_cli_telnet_cfg *param);
/**
* Create, initialize, and start a telnet daemon for the application.
*
* @param cli The CLI application instance.
* @param param Optional parameters for creating the telnet daemon.
* If this value is NULL, default parameters will be used.
* @param p_fe Optional pointer to receive the front-end instance
* of the telnet front-end just created.
* @param cli The CLI application instance.
* @param param Optional parameters for creating the telnet daemon.
* If this value is NULL, default parameters will be used.
* @param p_fe Optional pointer to receive the front-end instance
* of the telnet front-end just created.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_cli_telnet_create(pj_cli_t *cli,
pj_cli_telnet_cfg *param,
pj_cli_front_end **p_fe);
pj_cli_telnet_cfg *param,
pj_cli_front_end **p_fe);
/**
@ -154,10 +153,10 @@ PJ_DECL(pj_status_t) pj_cli_telnet_create(pj_cli_t *cli,
* @param fe The front end.
* @param info The telnet runtime information.
*
* @return PJ_SUCCESS on success.
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pj_cli_telnet_get_info(pj_cli_front_end *fe,
pj_cli_telnet_info *info);
pj_cli_telnet_info *info);
/**
* @}

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -49,7 +48,7 @@
* Maximum server address entries per one SRV record
*/
#ifndef PJ_DNS_SRV_MAX_ADDR
# define PJ_DNS_SRV_MAX_ADDR 8
# define PJ_DNS_SRV_MAX_ADDR 8
#endif
@ -66,7 +65,7 @@
* Default: 16
*/
#ifndef PJ_DNS_MAX_NAMES_IN_NAMETABLE
# define PJ_DNS_MAX_NAMES_IN_NAMETABLE 16
# define PJ_DNS_MAX_NAMES_IN_NAMETABLE 16
#endif
@ -79,7 +78,7 @@
* Maximum numbers of DNS nameservers that can be configured in resolver.
*/
#ifndef PJ_DNS_RESOLVER_MAX_NS
# define PJ_DNS_RESOLVER_MAX_NS 16
# define PJ_DNS_RESOLVER_MAX_NS 16
#endif
@ -115,7 +114,7 @@
* @see PJ_DNS_RESOLVER_INVALID_TTL
*/
#ifndef PJ_DNS_RESOLVER_MAX_TTL
# define PJ_DNS_RESOLVER_MAX_TTL (5*60)
# define PJ_DNS_RESOLVER_MAX_TTL (5*60)
#endif
/**
@ -129,7 +128,7 @@
* @see PJ_DNS_RESOLVER_MAX_TTL
*/
#ifndef PJ_DNS_RESOLVER_INVALID_TTL
# define PJ_DNS_RESOLVER_INVALID_TTL 60
# define PJ_DNS_RESOLVER_INVALID_TTL 60
#endif
/**
@ -146,7 +145,7 @@
* @see PJ_DNS_RESOLVER_BAD_NS_TTL
*/
#ifndef PJ_DNS_RESOLVER_GOOD_NS_TTL
# define PJ_DNS_RESOLVER_GOOD_NS_TTL (10*60)
# define PJ_DNS_RESOLVER_GOOD_NS_TTL (10*60)
#endif
/**
@ -158,7 +157,7 @@
* @see PJ_DNS_RESOLVER_GOOD_NS_TTL
*/
#ifndef PJ_DNS_RESOLVER_BAD_NS_TTL
# define PJ_DNS_RESOLVER_BAD_NS_TTL (1*60)
# define PJ_DNS_RESOLVER_BAD_NS_TTL (1*60)
#endif
@ -169,7 +168,7 @@
* Default: 512 byes
*/
#ifndef PJ_DNS_RESOLVER_MAX_UDP_SIZE
# define PJ_DNS_RESOLVER_MAX_UDP_SIZE 512
# define PJ_DNS_RESOLVER_MAX_UDP_SIZE 512
#endif
@ -182,7 +181,7 @@
* Default: 512
*/
#ifndef PJ_DNS_RESOLVER_RES_BUF_SIZE
# define PJ_DNS_RESOLVER_RES_BUF_SIZE 512
# define PJ_DNS_RESOLVER_RES_BUF_SIZE 512
#endif
@ -192,7 +191,7 @@
* default: 4000
*/
#ifndef PJ_DNS_RESOLVER_TMP_BUF_SIZE
# define PJ_DNS_RESOLVER_TMP_BUF_SIZE 4000
# define PJ_DNS_RESOLVER_TMP_BUF_SIZE 4000
#endif
@ -207,7 +206,7 @@
* This would save several kilobytes of .bss memory in the SIP parser.
*/
#ifndef PJ_SCANNER_USE_BITWISE
# define PJ_SCANNER_USE_BITWISE 1
# define PJ_SCANNER_USE_BITWISE 1
#endif
@ -223,7 +222,7 @@
* Default: 16
*/
#ifndef PJSTUN_MAX_ATTR
# define PJSTUN_MAX_ATTR 16
# define PJSTUN_MAX_ATTR 16
#endif
@ -234,7 +233,7 @@
* Default: 16
*/
#ifndef PJ_STUN_MAX_ATTR
# define PJ_STUN_MAX_ATTR 16
# define PJ_STUN_MAX_ATTR 16
#endif
@ -251,7 +250,7 @@
* Default: 1
*/
#ifndef PJ_CRC32_HAS_TABLES
# define PJ_CRC32_HAS_TABLES 1
# define PJ_CRC32_HAS_TABLES 1
#endif
@ -291,7 +290,7 @@
* Default: 512
*/
#ifndef PJ_CLI_MAX_CMDBUF
# define PJ_CLI_MAX_CMDBUF 512
# define PJ_CLI_MAX_CMDBUF 512
#endif
/**
@ -299,7 +298,7 @@
* Default: 8
*/
#ifndef PJ_CLI_MAX_ARGS
# define PJ_CLI_MAX_ARGS 8
# define PJ_CLI_MAX_ARGS 8
#endif
/**
@ -307,7 +306,7 @@
* Default: 32
*/
#ifndef PJ_CLI_MAX_HINTS
# define PJ_CLI_MAX_HINTS 32
# define PJ_CLI_MAX_HINTS 32
#endif
/**
@ -315,7 +314,7 @@
* Default: 4
*/
#ifndef PJ_CLI_MAX_SHORTCUTS
# define PJ_CLI_MAX_SHORTCUTS 4
# define PJ_CLI_MAX_SHORTCUTS 4
#endif
/**
@ -370,5 +369,5 @@
* @}
*/
#endif /* __PJLIB_UTIL_CONFIG_H__ */
#endif /* __PJLIB_UTIL_CONFIG_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -40,49 +39,49 @@ PJ_BEGIN_DECL
/** CRC32 context. */
typedef struct pj_crc32_context
{
pj_uint32_t crc_state; /**< Current state. */
pj_uint32_t crc_state; /**< Current state. */
} pj_crc32_context;
/**
* Initialize CRC32 context.
*
* @param ctx CRC32 context.
* @param ctx CRC32 context.
*/
PJ_DECL(void) pj_crc32_init(pj_crc32_context *ctx);
/**
* Feed data incrementally to the CRC32 algorithm.
*
* @param ctx CRC32 context.
* @param data Input data.
* @param ctx CRC32 context.
* @param data Input data.
* @param nbytes Length of the input data.
*
* @return The current CRC32 value.
* @return The current CRC32 value.
*/
PJ_DECL(pj_uint32_t) pj_crc32_update(pj_crc32_context *ctx,
const pj_uint8_t *data,
pj_size_t nbytes);
const pj_uint8_t *data,
pj_size_t nbytes);
/**
* Finalize CRC32 calculation and retrieve the CRC32 value.
*
* @param ctx CRC32 context.
* @param ctx CRC32 context.
*
* @return The current CRC value.
* @return The current CRC value.
*/
PJ_DECL(pj_uint32_t) pj_crc32_final(pj_crc32_context *ctx);
/**
* Perform one-off CRC32 calculation to the specified data.
*
* @param data Input data.
* @param data Input data.
* @param nbytes Length of input data.
*
* @return CRC value of the data.
* @return CRC value of the data.
*/
PJ_DECL(pj_uint32_t) pj_crc32_calc(const pj_uint8_t *data,
pj_size_t nbytes);
pj_size_t nbytes);
/**
@ -92,5 +91,5 @@ PJ_DECL(pj_uint32_t) pj_crc32_calc(const pj_uint8_t *data,
PJ_END_DECL
#endif /* __PJLIB_UTIL_CRC32_H__ */
#endif /* __PJLIB_UTIL_CRC32_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -62,7 +61,7 @@ PJ_BEGIN_DECL
enum
{
PJ_DNS_CLASS_IN = 1 /**< DNS class IN. */
PJ_DNS_CLASS_IN = 1 /**< DNS class IN. */
};
/**
@ -71,54 +70,54 @@ enum
*/
typedef enum pj_dns_type
{
PJ_DNS_TYPE_A = 1, /**< Host address (A) record. */
PJ_DNS_TYPE_NS = 2, /**< Authoritative name server (NS) */
PJ_DNS_TYPE_MD = 3, /**< Mail destination (MD) record. */
PJ_DNS_TYPE_MF = 4, /**< Mail forwarder (MF) record. */
PJ_DNS_TYPE_CNAME = 5, /**< Canonical name (CNAME) record. */
PJ_DNS_TYPE_SOA = 6, /**< Marks start of zone authority. */
PJ_DNS_TYPE_MB = 7, /**< Mailbox domain name (MB). */
PJ_DNS_TYPE_MG = 8, /**< Mail group member (MG). */
PJ_DNS_TYPE_MR = 9, /**< Mail rename domain name. */
PJ_DNS_TYPE_NULL = 10, /**< NULL RR. */
PJ_DNS_TYPE_WKS = 11, /**< Well known service description */
PJ_DNS_TYPE_PTR = 12, /**< Domain name pointer. */
PJ_DNS_TYPE_HINFO = 13, /**< Host information. */
PJ_DNS_TYPE_MINFO = 14, /**< Mailbox or mail list information. */
PJ_DNS_TYPE_MX = 15, /**< Mail exchange record. */
PJ_DNS_TYPE_TXT = 16, /**< Text string. */
PJ_DNS_TYPE_RP = 17, /**< Responsible person. */
PJ_DNS_TYPE_AFSB = 18, /**< AFS cell database. */
PJ_DNS_TYPE_X25 = 19, /**< X.25 calling address. */
PJ_DNS_TYPE_ISDN = 20, /**< ISDN calling address. */
PJ_DNS_TYPE_RT = 21, /**< Router. */
PJ_DNS_TYPE_NSAP = 22, /**< NSAP address. */
PJ_DNS_TYPE_NSAP_PTR= 23, /**< NSAP reverse address. */
PJ_DNS_TYPE_SIG = 24, /**< Signature. */
PJ_DNS_TYPE_KEY = 25, /**< Key. */
PJ_DNS_TYPE_PX = 26, /**< X.400 mail mapping. */
PJ_DNS_TYPE_GPOS = 27, /**< Geographical position (withdrawn) */
PJ_DNS_TYPE_AAAA = 28, /**< IPv6 address. */
PJ_DNS_TYPE_LOC = 29, /**< Location. */
PJ_DNS_TYPE_NXT = 30, /**< Next valid name in the zone. */
PJ_DNS_TYPE_EID = 31, /**< Endpoint idenfitier. */
PJ_DNS_TYPE_NIMLOC = 32, /**< Nimrod locator. */
PJ_DNS_TYPE_SRV = 33, /**< Server selection (SRV) record. */
PJ_DNS_TYPE_ATMA = 34, /**< DNS ATM address record. */
PJ_DNS_TYPE_NAPTR = 35, /**< DNS Naming authority pointer record. */
PJ_DNS_TYPE_KX = 36, /**< DNS key exchange record. */
PJ_DNS_TYPE_CERT = 37, /**< DNS certificate record. */
PJ_DNS_TYPE_A6 = 38, /**< DNS IPv6 address (experimental) */
PJ_DNS_TYPE_DNAME = 39, /**< DNS non-terminal name redirection rec. */
PJ_DNS_TYPE_A = 1, /**< Host address (A) record. */
PJ_DNS_TYPE_NS = 2, /**< Authoritative name server (NS) */
PJ_DNS_TYPE_MD = 3, /**< Mail destination (MD) record. */
PJ_DNS_TYPE_MF = 4, /**< Mail forwarder (MF) record. */
PJ_DNS_TYPE_CNAME = 5, /**< Canonical name (CNAME) record. */
PJ_DNS_TYPE_SOA = 6, /**< Marks start of zone authority. */
PJ_DNS_TYPE_MB = 7, /**< Mailbox domain name (MB). */
PJ_DNS_TYPE_MG = 8, /**< Mail group member (MG). */
PJ_DNS_TYPE_MR = 9, /**< Mail rename domain name. */
PJ_DNS_TYPE_NULL = 10, /**< NULL RR. */
PJ_DNS_TYPE_WKS = 11, /**< Well known service description */
PJ_DNS_TYPE_PTR = 12, /**< Domain name pointer. */
PJ_DNS_TYPE_HINFO = 13, /**< Host information. */
PJ_DNS_TYPE_MINFO = 14, /**< Mailbox or mail list information. */
PJ_DNS_TYPE_MX = 15, /**< Mail exchange record. */
PJ_DNS_TYPE_TXT = 16, /**< Text string. */
PJ_DNS_TYPE_RP = 17, /**< Responsible person. */
PJ_DNS_TYPE_AFSB = 18, /**< AFS cell database. */
PJ_DNS_TYPE_X25 = 19, /**< X.25 calling address. */
PJ_DNS_TYPE_ISDN = 20, /**< ISDN calling address. */
PJ_DNS_TYPE_RT = 21, /**< Router. */
PJ_DNS_TYPE_NSAP = 22, /**< NSAP address. */
PJ_DNS_TYPE_NSAP_PTR= 23, /**< NSAP reverse address. */
PJ_DNS_TYPE_SIG = 24, /**< Signature. */
PJ_DNS_TYPE_KEY = 25, /**< Key. */
PJ_DNS_TYPE_PX = 26, /**< X.400 mail mapping. */
PJ_DNS_TYPE_GPOS = 27, /**< Geographical position (withdrawn) */
PJ_DNS_TYPE_AAAA = 28, /**< IPv6 address. */
PJ_DNS_TYPE_LOC = 29, /**< Location. */
PJ_DNS_TYPE_NXT = 30, /**< Next valid name in the zone. */
PJ_DNS_TYPE_EID = 31, /**< Endpoint idenfitier. */
PJ_DNS_TYPE_NIMLOC = 32, /**< Nimrod locator. */
PJ_DNS_TYPE_SRV = 33, /**< Server selection (SRV) record. */
PJ_DNS_TYPE_ATMA = 34, /**< DNS ATM address record. */
PJ_DNS_TYPE_NAPTR = 35, /**< DNS Naming authority pointer record. */
PJ_DNS_TYPE_KX = 36, /**< DNS key exchange record. */
PJ_DNS_TYPE_CERT = 37, /**< DNS certificate record. */
PJ_DNS_TYPE_A6 = 38, /**< DNS IPv6 address (experimental) */
PJ_DNS_TYPE_DNAME = 39, /**< DNS non-terminal name redirection rec. */
PJ_DNS_TYPE_OPT = 41, /**< DNS options - contains EDNS metadata. */
PJ_DNS_TYPE_APL = 42, /**< DNS Address Prefix List (APL) record. */
PJ_DNS_TYPE_DS = 43, /**< DNS Delegation Signer (DS) */
PJ_DNS_TYPE_SSHFP = 44, /**< DNS SSH Key Fingerprint */
PJ_DNS_TYPE_IPSECKEY= 45, /**< DNS IPSEC Key. */
PJ_DNS_TYPE_RRSIG = 46, /**< DNS Resource Record signature. */
PJ_DNS_TYPE_NSEC = 47, /**< DNS Next Secure Name. */
PJ_DNS_TYPE_DNSKEY = 48 /**< DNSSEC Key. */
PJ_DNS_TYPE_OPT = 41, /**< DNS options - contains EDNS metadata. */
PJ_DNS_TYPE_APL = 42, /**< DNS Address Prefix List (APL) record. */
PJ_DNS_TYPE_DS = 43, /**< DNS Delegation Signer (DS) */
PJ_DNS_TYPE_SSHFP = 44, /**< DNS SSH Key Fingerprint */
PJ_DNS_TYPE_IPSECKEY= 45, /**< DNS IPSEC Key. */
PJ_DNS_TYPE_RRSIG = 46, /**< DNS Resource Record signature. */
PJ_DNS_TYPE_NSEC = 47, /**< DNS Next Secure Name. */
PJ_DNS_TYPE_DNSKEY = 48 /**< DNSSEC Key. */
} pj_dns_type;
@ -133,56 +132,56 @@ typedef enum pj_dns_type
*/
typedef struct pj_dns_hdr
{
pj_uint16_t id; /**< Transaction ID. */
pj_uint16_t flags; /**< Flags. */
pj_uint16_t qdcount; /**< Nb. of queries. */
pj_uint16_t anscount; /**< Nb. of res records */
pj_uint16_t nscount; /**< Nb. of NS records. */
pj_uint16_t id; /**< Transaction ID. */
pj_uint16_t flags; /**< Flags. */
pj_uint16_t qdcount; /**< Nb. of queries. */
pj_uint16_t anscount; /**< Nb. of res records */
pj_uint16_t nscount; /**< Nb. of NS records. */
pj_uint16_t arcount; /**< Nb. of additional records */
} pj_dns_hdr;
/** Create RCODE flag */
#define PJ_DNS_SET_RCODE(c) ((pj_uint16_t)((c) & 0x0F))
#define PJ_DNS_SET_RCODE(c) ((pj_uint16_t)((c) & 0x0F))
/** Create RA (Recursion Available) bit */
#define PJ_DNS_SET_RA(on) ((pj_uint16_t)((on) << 7))
#define PJ_DNS_SET_RA(on) ((pj_uint16_t)((on) << 7))
/** Create RD (Recursion Desired) bit */
#define PJ_DNS_SET_RD(on) ((pj_uint16_t)((on) << 8))
#define PJ_DNS_SET_RD(on) ((pj_uint16_t)((on) << 8))
/** Create TC (Truncated) bit */
#define PJ_DNS_SET_TC(on) ((pj_uint16_t)((on) << 9))
#define PJ_DNS_SET_TC(on) ((pj_uint16_t)((on) << 9))
/** Create AA (Authoritative Answer) bit */
#define PJ_DNS_SET_AA(on) ((pj_uint16_t)((on) << 10))
#define PJ_DNS_SET_AA(on) ((pj_uint16_t)((on) << 10))
/** Create four bits opcode */
#define PJ_DNS_SET_OPCODE(o) ((pj_uint16_t)((o) << 11))
#define PJ_DNS_SET_OPCODE(o) ((pj_uint16_t)((o) << 11))
/** Create query/response bit */
#define PJ_DNS_SET_QR(on) ((pj_uint16_t)((on) << 15))
#define PJ_DNS_SET_QR(on) ((pj_uint16_t)((on) << 15))
/** Get RCODE value */
#define PJ_DNS_GET_RCODE(val) (((val) & PJ_DNS_SET_RCODE(0x0F)) >> 0)
#define PJ_DNS_GET_RCODE(val) (((val) & PJ_DNS_SET_RCODE(0x0F)) >> 0)
/** Get RA bit */
#define PJ_DNS_GET_RA(val) (((val) & PJ_DNS_SET_RA(1)) >> 7)
#define PJ_DNS_GET_RA(val) (((val) & PJ_DNS_SET_RA(1)) >> 7)
/** Get RD bit */
#define PJ_DNS_GET_RD(val) (((val) & PJ_DNS_SET_RD(1)) >> 8)
#define PJ_DNS_GET_RD(val) (((val) & PJ_DNS_SET_RD(1)) >> 8)
/** Get TC bit */
#define PJ_DNS_GET_TC(val) (((val) & PJ_DNS_SET_TC(1)) >> 9)
#define PJ_DNS_GET_TC(val) (((val) & PJ_DNS_SET_TC(1)) >> 9)
/** Get AA bit */
#define PJ_DNS_GET_AA(val) (((val) & PJ_DNS_SET_AA(1)) >> 10)
#define PJ_DNS_GET_AA(val) (((val) & PJ_DNS_SET_AA(1)) >> 10)
/** Get OPCODE value */
#define PJ_DNS_GET_OPCODE(val) (((val) & PJ_DNS_SET_OPCODE(0x0F)) >> 11)
#define PJ_DNS_GET_OPCODE(val) (((val) & PJ_DNS_SET_OPCODE(0x0F)) >> 11)
/** Get QR bit */
#define PJ_DNS_GET_QR(val) (((val) & PJ_DNS_SET_QR(1)) >> 15)
#define PJ_DNS_GET_QR(val) (((val) & PJ_DNS_SET_QR(1)) >> 15)
/**
@ -192,15 +191,15 @@ typedef struct pj_dns_hdr
*/
typedef enum pj_dns_rcode
{
PJ_DNS_RCODE_FORMERR = 1, /**< Format error. */
PJ_DNS_RCODE_SERVFAIL = 2, /**< Server failure. */
PJ_DNS_RCODE_NXDOMAIN = 3, /**< Name Error. */
PJ_DNS_RCODE_NOTIMPL = 4, /**< Not Implemented. */
PJ_DNS_RCODE_REFUSED = 5, /**< Refused. */
PJ_DNS_RCODE_YXDOMAIN = 6, /**< The name exists. */
PJ_DNS_RCODE_YXRRSET = 7, /**< The RRset (name, type) exists. */
PJ_DNS_RCODE_FORMERR = 1, /**< Format error. */
PJ_DNS_RCODE_SERVFAIL = 2, /**< Server failure. */
PJ_DNS_RCODE_NXDOMAIN = 3, /**< Name Error. */
PJ_DNS_RCODE_NOTIMPL = 4, /**< Not Implemented. */
PJ_DNS_RCODE_REFUSED = 5, /**< Refused. */
PJ_DNS_RCODE_YXDOMAIN = 6, /**< The name exists. */
PJ_DNS_RCODE_YXRRSET = 7, /**< The RRset (name, type) exists. */
PJ_DNS_RCODE_NXRRSET = 8, /**< The RRset (name, type) doesn't exist*/
PJ_DNS_RCODE_NOTAUTH = 9, /**< Not authorized. */
PJ_DNS_RCODE_NOTAUTH = 9, /**< Not authorized. */
PJ_DNS_RCODE_NOTZONE = 10 /**< The zone specified is not a zone. */
} pj_dns_rcode;
@ -211,9 +210,9 @@ typedef enum pj_dns_rcode
*/
typedef struct pj_dns_parsed_query
{
pj_str_t name; /**< The domain in the query. */
pj_uint16_t type; /**< Type of the query (pj_dns_type) */
pj_uint16_t dnsclass; /**< Network class (PJ_DNS_CLASS_IN=1) */
pj_str_t name; /**< The domain in the query. */
pj_uint16_t type; /**< Type of the query (pj_dns_type) */
pj_uint16_t dnsclass; /**< Network class (PJ_DNS_CLASS_IN=1) */
} pj_dns_parsed_query;
@ -223,52 +222,52 @@ typedef struct pj_dns_parsed_query
*/
typedef struct pj_dns_parsed_rr
{
pj_str_t name; /**< The domain name which this rec pertains. */
pj_uint16_t type; /**< RR type code. */
pj_uint16_t dnsclass; /**< Class of data (PJ_DNS_CLASS_IN=1). */
pj_uint32_t ttl; /**< Time to live. */
pj_uint16_t rdlength; /**< Resource data length. */
void *data; /**< Pointer to the raw resource data, only
when the type is not known. If it is known,
the data will be put in rdata below. */
pj_str_t name; /**< The domain name which this rec pertains. */
pj_uint16_t type; /**< RR type code. */
pj_uint16_t dnsclass; /**< Class of data (PJ_DNS_CLASS_IN=1). */
pj_uint32_t ttl; /**< Time to live. */
pj_uint16_t rdlength; /**< Resource data length. */
void *data; /**< Pointer to the raw resource data, only
when the type is not known. If it is known,
the data will be put in rdata below. */
/** For resource types that are recognized/supported by this library,
* the parsed resource data will be placed in this rdata union.
*/
union rdata
{
/** SRV Resource Data (PJ_DNS_TYPE_SRV, 33) */
struct srv {
pj_uint16_t prio; /**< Target priority (lower is higher). */
pj_uint16_t weight; /**< Weight/proportion */
pj_uint16_t port; /**< Port number of the service */
pj_str_t target; /**< Target name. */
} srv; /**< SRV Resource Data (PJ_DNS_TYPE_SRV, 33) */
/** SRV Resource Data (PJ_DNS_TYPE_SRV, 33) */
struct srv {
pj_uint16_t prio; /**< Target priority (lower is higher). */
pj_uint16_t weight; /**< Weight/proportion */
pj_uint16_t port; /**< Port number of the service */
pj_str_t target; /**< Target name. */
} srv; /**< SRV Resource Data (PJ_DNS_TYPE_SRV, 33) */
/** CNAME Resource Data (PJ_DNS_TYPE_CNAME, 5) */
struct cname {
pj_str_t name; /**< Primary canonical name for an alias. */
} cname; /**< CNAME Resource Data (PJ_DNS_TYPE_CNAME, 5) */
/** CNAME Resource Data (PJ_DNS_TYPE_CNAME, 5) */
struct cname {
pj_str_t name; /**< Primary canonical name for an alias. */
} cname; /**< CNAME Resource Data (PJ_DNS_TYPE_CNAME, 5) */
/** NS Resource Data (PJ_DNS_TYPE_NS, 2) */
struct ns {
pj_str_t name; /**< Primary name server. */
} ns; /**< NS Resource Data (PJ_DNS_TYPE_NS, 2) */
/** NS Resource Data (PJ_DNS_TYPE_NS, 2) */
struct ns {
pj_str_t name; /**< Primary name server. */
} ns; /**< NS Resource Data (PJ_DNS_TYPE_NS, 2) */
/** PTR Resource Data (PJ_DNS_TYPE_PTR, 12) */
struct ptr {
pj_str_t name; /**< PTR name. */
} ptr; /**< PTR Resource Data (PJ_DNS_TYPE_PTR, 12) */
/** PTR Resource Data (PJ_DNS_TYPE_PTR, 12) */
struct ptr {
pj_str_t name; /**< PTR name. */
} ptr; /**< PTR Resource Data (PJ_DNS_TYPE_PTR, 12) */
/** A Resource Data (PJ_DNS_TYPE_A, 1) */
struct a {
pj_in_addr ip_addr;/**< IPv4 address in network byte order. */
} a; /**< A Resource Data (PJ_DNS_TYPE_A, 1) */
/** A Resource Data (PJ_DNS_TYPE_A, 1) */
struct a {
pj_in_addr ip_addr;/**< IPv4 address in network byte order. */
} a; /**< A Resource Data (PJ_DNS_TYPE_A, 1) */
/** AAAA Resource Data (PJ_DNS_TYPE_AAAA, 28) */
struct aaaa {
pj_in6_addr ip_addr;/**< IPv6 address in network byte order. */
} aaaa; /**< AAAA Resource Data (PJ_DNS_TYPE_AAAA, 28) */
/** AAAA Resource Data (PJ_DNS_TYPE_AAAA, 28) */
struct aaaa {
pj_in6_addr ip_addr;/**< IPv6 address in network byte order. */
} aaaa; /**< AAAA Resource Data (PJ_DNS_TYPE_AAAA, 28) */
} rdata;
@ -282,11 +281,11 @@ typedef struct pj_dns_parsed_rr
*/
typedef struct pj_dns_parsed_packet
{
pj_dns_hdr hdr; /**< Pointer to DNS hdr, in host byte order */
pj_dns_parsed_query *q; /**< Array of DNS queries. */
pj_dns_parsed_rr *ans; /**< Array of DNS RR answer. */
pj_dns_parsed_rr *ns; /**< Array of NS record in the answer. */
pj_dns_parsed_rr *arr; /**< Array of additional RR answer. */
pj_dns_hdr hdr; /**< Pointer to DNS hdr, in host byte order */
pj_dns_parsed_query *q; /**< Array of DNS queries. */
pj_dns_parsed_rr *ans; /**< Array of DNS RR answer. */
pj_dns_parsed_rr *ns; /**< Array of NS record in the answer. */
pj_dns_parsed_rr *arr; /**< Array of additional RR answer. */
} pj_dns_parsed_packet;
@ -296,9 +295,9 @@ typedef struct pj_dns_parsed_packet
*/
enum pj_dns_dup_options
{
PJ_DNS_NO_QD = 1, /**< Do not duplicate the query section. */
PJ_DNS_NO_ANS = 2, /**< Do not duplicate the answer section. */
PJ_DNS_NO_NS = 4, /**< Do not duplicate the NS section. */
PJ_DNS_NO_QD = 1, /**< Do not duplicate the query section. */
PJ_DNS_NO_ANS = 2, /**< Do not duplicate the answer section. */
PJ_DNS_NO_NS = 4, /**< Do not duplicate the NS section. */
PJ_DNS_NO_AR = 8 /**< Do not duplicate the additional rec section */
};
@ -313,61 +312,61 @@ enum pj_dns_dup_options
* specified. Once the packet is successfully built, application can send
* the packet via TCP or UDP connection.
*
* @param packet The buffer to put the DNS query packet.
* @param size On input, it specifies the size of the buffer.
* On output, it will be filled with the actual size of
* the DNS query packet.
* @param id DNS query ID to associate DNS response with the
* query.
* @param qtype DNS type of record to be queried (see #pj_dns_type).
* @param name Name to be queried from the DNS server.
* @param packet The buffer to put the DNS query packet.
* @param size On input, it specifies the size of the buffer.
* On output, it will be filled with the actual size of
* the DNS query packet.
* @param id DNS query ID to associate DNS response with the
* query.
* @param qtype DNS type of record to be queried (see #pj_dns_type).
* @param name Name to be queried from the DNS server.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_dns_make_query(void *packet,
unsigned *size,
pj_uint16_t id,
int qtype,
const pj_str_t *name);
unsigned *size,
pj_uint16_t id,
int qtype,
const pj_str_t *name);
/**
* Parse raw DNS packet into parsed DNS packet structure. This function is
* able to parse few DNS resource records such as A record, PTR record,
* CNAME record, NS record, and SRV record.
*
* @param pool Pool to allocate memory for the parsed packet.
* @param packet Pointer to the DNS packet (the TCP/UDP payload of
* the raw packet).
* @param size The size of the DNS packet.
* @param p_res Pointer to store the resulting parsed packet.
* @param pool Pool to allocate memory for the parsed packet.
* @param packet Pointer to the DNS packet (the TCP/UDP payload of
* the raw packet).
* @param size The size of the DNS packet.
* @param p_res Pointer to store the resulting parsed packet.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_dns_parse_packet(pj_pool_t *pool,
const void *packet,
unsigned size,
pj_dns_parsed_packet **p_res);
const void *packet,
unsigned size,
pj_dns_parsed_packet **p_res);
/**
* Duplicate DNS packet.
*
* @param pool The pool to allocate memory for the duplicated packet.
* @param p The DNS packet to be cloned.
* @param options Option flags, from pj_dns_dup_options.
* @param p_dst Pointer to store the cloned DNS packet.
* @param pool The pool to allocate memory for the duplicated packet.
* @param p The DNS packet to be cloned.
* @param options Option flags, from pj_dns_dup_options.
* @param p_dst Pointer to store the cloned DNS packet.
*/
PJ_DECL(void) pj_dns_packet_dup(pj_pool_t *pool,
const pj_dns_parsed_packet*p,
unsigned options,
pj_dns_parsed_packet **p_dst);
const pj_dns_parsed_packet*p,
unsigned options,
pj_dns_parsed_packet **p_dst);
/**
* Utility function to get the type name string of the specified DNS type.
*
* @param type DNS type (see #pj_dns_type).
* @param type DNS type (see #pj_dns_type).
*
* @return String name of the type (e.g. "A", "SRV", etc.).
* @return String name of the type (e.g. "A", "SRV", etc.).
*/
PJ_DECL(const char *) pj_dns_get_type_name(int type);
@ -375,77 +374,77 @@ PJ_DECL(const char *) pj_dns_get_type_name(int type);
/**
* Initialize DNS record as DNS SRV record.
*
* @param rec The DNS resource record to be initialized as DNS
* SRV record.
* @param res_name Resource name.
* @param dnsclass DNS class.
* @param ttl Resource TTL value.
* @param prio DNS SRV priority.
* @param weight DNS SRV weight.
* @param port Target port.
* @param target Target name.
* @param rec The DNS resource record to be initialized as DNS
* SRV record.
* @param res_name Resource name.
* @param dnsclass DNS class.
* @param ttl Resource TTL value.
* @param prio DNS SRV priority.
* @param weight DNS SRV weight.
* @param port Target port.
* @param target Target name.
*/
PJ_DECL(void) pj_dns_init_srv_rr(pj_dns_parsed_rr *rec,
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
unsigned prio,
unsigned weight,
unsigned port,
const pj_str_t *target);
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
unsigned prio,
unsigned weight,
unsigned port,
const pj_str_t *target);
/**
* Initialize DNS record as DNS CNAME record.
*
* @param rec The DNS resource record to be initialized as DNS
* CNAME record.
* @param res_name Resource name.
* @param dnsclass DNS class.
* @param ttl Resource TTL value.
* @param name Host name.
* @param rec The DNS resource record to be initialized as DNS
* CNAME record.
* @param res_name Resource name.
* @param dnsclass DNS class.
* @param ttl Resource TTL value.
* @param name Host name.
*/
PJ_DECL(void) pj_dns_init_cname_rr(pj_dns_parsed_rr *rec,
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_str_t *name);
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_str_t *name);
/**
* Initialize DNS record as DNS A record.
*
* @param rec The DNS resource record to be initialized as DNS
* A record.
* @param res_name Resource name.
* @param dnsclass DNS class.
* @param ttl Resource TTL value.
* @param ip_addr Host address.
* @param rec The DNS resource record to be initialized as DNS
* A record.
* @param res_name Resource name.
* @param dnsclass DNS class.
* @param ttl Resource TTL value.
* @param ip_addr Host address.
*/
PJ_DECL(void) pj_dns_init_a_rr(pj_dns_parsed_rr *rec,
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_in_addr *ip_addr);
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_in_addr *ip_addr);
/**
* Initialize DNS record as DNS AAAA record.
*
* @param rec The DNS resource record to be initialized as DNS
* AAAA record.
* @param res_name Resource name.
* @param dnsclass DNS class.
* @param ttl Resource TTL value.
* @param ip_addr Host address.
* @param rec The DNS resource record to be initialized as DNS
* AAAA record.
* @param res_name Resource name.
* @param dnsclass DNS class.
* @param ttl Resource TTL value.
* @param ip_addr Host address.
*/
PJ_DECL(void) pj_dns_init_aaaa_rr(pj_dns_parsed_rr *rec,
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_in6_addr *ip_addr);
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_in6_addr *ip_addr);
/**
* Dump DNS packet to standard log.
*
* @param res The DNS packet.
* @param res The DNS packet.
*/
PJ_DECL(void) pj_dns_dump_packet(const pj_dns_parsed_packet *res);
@ -457,5 +456,5 @@ PJ_DECL(void) pj_dns_dump_packet(const pj_dns_parsed_packet *res);
PJ_END_DECL
#endif /* __PJLIB_UTIL_DNS_H__ */
#endif /* __PJLIB_UTIL_DNS_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -46,32 +45,32 @@ typedef struct pj_dns_server pj_dns_server;
/**
* Create the DNS server instance. The instance will run immediately.
*
* @param pf The pool factory to create memory pools.
* @param pf The pool factory to create memory pools.
* @param ioqueue Ioqueue instance where the server socket will be
* registered to.
* @param af Address family of the server socket (valid values
* are pj_AF_INET() for IPv4 and pj_AF_INET6() for IPv6).
* @param port The UDP port to listen.
* @param flags Flags, currently must be zero.
* @param p_srv Pointer to receive the DNS server instance.
* registered to.
* @param af Address family of the server socket (valid values
* are pj_AF_INET() for IPv4 and pj_AF_INET6() for IPv6).
* @param port The UDP port to listen.
* @param flags Flags, currently must be zero.
* @param p_srv Pointer to receive the DNS server instance.
*
* @return PJ_SUCCESS if server has been created successfully,
* otherwise the function will return the appropriate
* error code.
* @return PJ_SUCCESS if server has been created successfully,
* otherwise the function will return the appropriate
* error code.
*/
PJ_DECL(pj_status_t) pj_dns_server_create(pj_pool_factory *pf,
pj_ioqueue_t *ioqueue,
int af,
unsigned port,
unsigned flags,
pj_dns_server **p_srv);
pj_ioqueue_t *ioqueue,
int af,
unsigned port,
unsigned flags,
pj_dns_server **p_srv);
/**
* Destroy DNS server instance.
*
* @param srv The DNS server instance.
* @param srv The DNS server instance.
*
* @return PJ_SUCCESS on success or the appropriate error code.
* @return PJ_SUCCESS on success or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_dns_server_destroy(pj_dns_server *srv);
@ -79,30 +78,30 @@ PJ_DECL(pj_status_t) pj_dns_server_destroy(pj_dns_server *srv);
/**
* Add generic resource record entries to the server.
*
* @param srv The DNS server instance.
* @param count Number of records to be added.
* @param rr Array of records to be added.
* @param srv The DNS server instance.
* @param count Number of records to be added.
* @param rr Array of records to be added.
*
* @return PJ_SUCCESS on success or the appropriate error code.
* @return PJ_SUCCESS on success or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_dns_server_add_rec(pj_dns_server *srv,
unsigned count,
const pj_dns_parsed_rr rr[]);
unsigned count,
const pj_dns_parsed_rr rr[]);
/**
* Remove the specified record from the server.
*
* @param srv The DNS server instance.
* @param srv The DNS server instance.
* @param dns_class The resource's DNS class. Valid value is PJ_DNS_CLASS_IN.
* @param type The resource type.
* @param name The resource name to be removed.
* @param type The resource type.
* @param name The resource name to be removed.
*
* @return PJ_SUCCESS on success or the appropriate error code.
* @return PJ_SUCCESS on success or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_dns_server_del_rec(pj_dns_server *srv,
int dns_class,
pj_dns_type type,
const pj_str_t *name);
int dns_class,
pj_dns_type type,
const pj_str_t *name);
@ -113,5 +112,5 @@ PJ_DECL(pj_status_t) pj_dns_server_del_rec(pj_dns_server *srv,
PJ_END_DECL
#endif /* __PJLIB_UTIL_DNS_SERVER_H__ */
#endif /* __PJLIB_UTIL_DNS_SERVER_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -43,67 +42,67 @@
* @hideinitializer
* Unable to resolve STUN server
*/
#define PJLIB_UTIL_ESTUNRESOLVE (PJLIB_UTIL_ERRNO_START+1) /* 320001 */
#define PJLIB_UTIL_ESTUNRESOLVE (PJLIB_UTIL_ERRNO_START+1) /* 320001 */
/**
* @hideinitializer
* Unknown STUN message type.
*/
#define PJLIB_UTIL_ESTUNINMSGTYPE (PJLIB_UTIL_ERRNO_START+2) /* 320002 */
#define PJLIB_UTIL_ESTUNINMSGTYPE (PJLIB_UTIL_ERRNO_START+2) /* 320002 */
/**
* @hideinitializer
* Invalid STUN message length
*/
#define PJLIB_UTIL_ESTUNINMSGLEN (PJLIB_UTIL_ERRNO_START+3) /* 320003 */
#define PJLIB_UTIL_ESTUNINMSGLEN (PJLIB_UTIL_ERRNO_START+3) /* 320003 */
/**
* @hideinitializer
* Invalid STUN attribute length
*/
#define PJLIB_UTIL_ESTUNINATTRLEN (PJLIB_UTIL_ERRNO_START+4) /* 320004 */
#define PJLIB_UTIL_ESTUNINATTRLEN (PJLIB_UTIL_ERRNO_START+4) /* 320004 */
/**
* @hideinitializer
* Invalid STUN attribute type
*/
#define PJLIB_UTIL_ESTUNINATTRTYPE (PJLIB_UTIL_ERRNO_START+5) /* 320005 */
#define PJLIB_UTIL_ESTUNINATTRTYPE (PJLIB_UTIL_ERRNO_START+5) /* 320005 */
/**
* @hideinitializer
* Invalid STUN server/socket index
*/
#define PJLIB_UTIL_ESTUNININDEX (PJLIB_UTIL_ERRNO_START+6) /* 320006 */
#define PJLIB_UTIL_ESTUNININDEX (PJLIB_UTIL_ERRNO_START+6) /* 320006 */
/**
* @hideinitializer
* No STUN binding response in the message
*/
#define PJLIB_UTIL_ESTUNNOBINDRES (PJLIB_UTIL_ERRNO_START+7) /* 320007 */
#define PJLIB_UTIL_ESTUNNOBINDRES (PJLIB_UTIL_ERRNO_START+7) /* 320007 */
/**
* @hideinitializer
* Received STUN error attribute
*/
#define PJLIB_UTIL_ESTUNRECVERRATTR (PJLIB_UTIL_ERRNO_START+8) /* 320008 */
#define PJLIB_UTIL_ESTUNRECVERRATTR (PJLIB_UTIL_ERRNO_START+8) /* 320008 */
/**
* @hideinitializer
* No STUN mapped address attribute
*/
#define PJLIB_UTIL_ESTUNNOMAP (PJLIB_UTIL_ERRNO_START+9) /* 320009 */
#define PJLIB_UTIL_ESTUNNOMAP (PJLIB_UTIL_ERRNO_START+9) /* 320009 */
/**
* @hideinitializer
* Received no response from STUN server
*/
#define PJLIB_UTIL_ESTUNNOTRESPOND (PJLIB_UTIL_ERRNO_START+10) /* 320010 */
#define PJLIB_UTIL_ESTUNNOTRESPOND (PJLIB_UTIL_ERRNO_START+10) /* 320010 */
/**
* @hideinitializer
* Symetric NAT detected by STUN
*/
#define PJLIB_UTIL_ESTUNSYMMETRIC (PJLIB_UTIL_ERRNO_START+11) /* 320011 */
#define PJLIB_UTIL_ESTUNSYMMETRIC (PJLIB_UTIL_ERRNO_START+11) /* 320011 */
/**
* @hideinitializer
* Invalid STUN magic value
*/
#define PJLIB_UTIL_ESTUNNOTMAGIC (PJLIB_UTIL_ERRNO_START+12) /* 320012 */
#define PJLIB_UTIL_ESTUNNOTMAGIC (PJLIB_UTIL_ERRNO_START+12) /* 320012 */
/**
* @hideinitializer
* Invalid STUN fingerprint value
*/
#define PJLIB_UTIL_ESTUNFINGERPRINT (PJLIB_UTIL_ERRNO_START+13) /* 320013 */
#define PJLIB_UTIL_ESTUNFINGERPRINT (PJLIB_UTIL_ERRNO_START+13) /* 320013 */
@ -114,7 +113,7 @@
* @hideinitializer
* General invalid XML message.
*/
#define PJLIB_UTIL_EINXML (PJLIB_UTIL_ERRNO_START+20) /* 320020 */
#define PJLIB_UTIL_EINXML (PJLIB_UTIL_ERRNO_START+20) /* 320020 */
/************************************************************
@ -124,7 +123,7 @@
* @hideinitializer
* General invalid JSON message.
*/
#define PJLIB_UTIL_EINJSON (PJLIB_UTIL_ERRNO_START+30) /* 320030 */
#define PJLIB_UTIL_EINJSON (PJLIB_UTIL_ERRNO_START+30) /* 320030 */
/************************************************************
@ -136,21 +135,21 @@
* This error occurs when the user supplied buffer for creating DNS
* query (#pj_dns_make_query() function) is too small.
*/
#define PJLIB_UTIL_EDNSQRYTOOSMALL (PJLIB_UTIL_ERRNO_START+40) /* 320040 */
#define PJLIB_UTIL_EDNSQRYTOOSMALL (PJLIB_UTIL_ERRNO_START+40) /* 320040 */
/**
* @hideinitializer
* Invalid DNS packet length.
* This error occurs when the received DNS response packet does not
* match all the fields length.
*/
#define PJLIB_UTIL_EDNSINSIZE (PJLIB_UTIL_ERRNO_START+41) /* 320041 */
#define PJLIB_UTIL_EDNSINSIZE (PJLIB_UTIL_ERRNO_START+41) /* 320041 */
/**
* @hideinitializer
* Invalid DNS class.
* This error occurs when the received DNS response contains network
* class other than IN (Internet).
*/
#define PJLIB_UTIL_EDNSINCLASS (PJLIB_UTIL_ERRNO_START+42) /* 320042 */
#define PJLIB_UTIL_EDNSINCLASS (PJLIB_UTIL_ERRNO_START+42) /* 320042 */
/**
* @hideinitializer
* Invalid DNS name pointer.
@ -158,39 +157,39 @@
* response packet, when the name pointer points to an invalid address
* or the parsing has triggerred too much recursion.
*/
#define PJLIB_UTIL_EDNSINNAMEPTR (PJLIB_UTIL_ERRNO_START+43) /* 320043 */
#define PJLIB_UTIL_EDNSINNAMEPTR (PJLIB_UTIL_ERRNO_START+43) /* 320043 */
/**
* @hideinitializer
* Invalid DNS nameserver address. If hostname was specified for nameserver
* address, this error means that the function was unable to resolve
* the nameserver hostname.
*/
#define PJLIB_UTIL_EDNSINNSADDR (PJLIB_UTIL_ERRNO_START+44) /* 320044 */
#define PJLIB_UTIL_EDNSINNSADDR (PJLIB_UTIL_ERRNO_START+44) /* 320044 */
/**
* @hideinitializer
* No nameserver is in DNS resolver. No nameserver is configured in the
* resolver.
*/
#define PJLIB_UTIL_EDNSNONS (PJLIB_UTIL_ERRNO_START+45) /* 320045 */
#define PJLIB_UTIL_EDNSNONS (PJLIB_UTIL_ERRNO_START+45) /* 320045 */
/**
* @hideinitializer
* No working DNS nameserver. All nameservers have been queried,
* but none was able to serve any DNS requests. These "bad" nameservers
* will be re-tested again for "goodness" after some period.
*/
#define PJLIB_UTIL_EDNSNOWORKINGNS (PJLIB_UTIL_ERRNO_START+46) /* 320046 */
#define PJLIB_UTIL_EDNSNOWORKINGNS (PJLIB_UTIL_ERRNO_START+46) /* 320046 */
/**
* @hideinitializer
* No answer record in the DNS response.
*/
#define PJLIB_UTIL_EDNSNOANSWERREC (PJLIB_UTIL_ERRNO_START+47) /* 320047 */
#define PJLIB_UTIL_EDNSNOANSWERREC (PJLIB_UTIL_ERRNO_START+47) /* 320047 */
/**
* @hideinitializer
* Invalid DNS answer. This error is raised for example when the DNS
* answer does not have a query section, or the type of RR in the answer
* doesn't match the query.
*/
#define PJLIB_UTIL_EDNSINANSWER (PJLIB_UTIL_ERRNO_START+48) /* 320048 */
#define PJLIB_UTIL_EDNSINANSWER (PJLIB_UTIL_ERRNO_START+48) /* 320048 */
/* DNS ERRORS MAPPED FROM RCODE: */
@ -198,26 +197,26 @@
/**
* Start of error code mapped from DNS RCODE
*/
#define PJLIB_UTIL_DNS_RCODE_START (PJLIB_UTIL_ERRNO_START+50) /* 320050 */
#define PJLIB_UTIL_DNS_RCODE_START (PJLIB_UTIL_ERRNO_START+50) /* 320050 */
/**
* Map DNS RCODE status into pj_status_t.
*/
#define PJ_STATUS_FROM_DNS_RCODE(rcode) (rcode==0 ? PJ_SUCCESS : \
PJLIB_UTIL_DNS_RCODE_START+rcode)
#define PJ_STATUS_FROM_DNS_RCODE(rcode) (rcode==0 ? PJ_SUCCESS : \
PJLIB_UTIL_DNS_RCODE_START+rcode)
/**
* @hideinitializer
* Format error - The name server was unable to interpret the query.
* This corresponds to DNS RCODE 1.
*/
#define PJLIB_UTIL_EDNS_FORMERR PJ_STATUS_FROM_DNS_RCODE(1) /* 320051 */
#define PJLIB_UTIL_EDNS_FORMERR PJ_STATUS_FROM_DNS_RCODE(1) /* 320051 */
/**
* @hideinitializer
* Server failure - The name server was unable to process this query due to a
* problem with the name server.
* This corresponds to DNS RCODE 2.
*/
#define PJLIB_UTIL_EDNS_SERVFAIL PJ_STATUS_FROM_DNS_RCODE(2) /* 320052 */
#define PJLIB_UTIL_EDNS_SERVFAIL PJ_STATUS_FROM_DNS_RCODE(2) /* 320052 */
/**
* @hideinitializer
* Name Error - Meaningful only for responses from an authoritative name
@ -225,51 +224,51 @@
* does not exist.
* This corresponds to DNS RCODE 3.
*/
#define PJLIB_UTIL_EDNS_NXDOMAIN PJ_STATUS_FROM_DNS_RCODE(3) /* 320053 */
#define PJLIB_UTIL_EDNS_NXDOMAIN PJ_STATUS_FROM_DNS_RCODE(3) /* 320053 */
/**
* @hideinitializer
* Not Implemented - The name server does not support the requested kind of
* query.
* This corresponds to DNS RCODE 4.
*/
#define PJLIB_UTIL_EDNS_NOTIMPL PJ_STATUS_FROM_DNS_RCODE(4) /* 320054 */
#define PJLIB_UTIL_EDNS_NOTIMPL PJ_STATUS_FROM_DNS_RCODE(4) /* 320054 */
/**
* @hideinitializer
* Refused - The name server refuses to perform the specified operation for
* policy reasons.
* This corresponds to DNS RCODE 5.
*/
#define PJLIB_UTIL_EDNS_REFUSED PJ_STATUS_FROM_DNS_RCODE(5) /* 320055 */
#define PJLIB_UTIL_EDNS_REFUSED PJ_STATUS_FROM_DNS_RCODE(5) /* 320055 */
/**
* @hideinitializer
* The name exists.
* This corresponds to DNS RCODE 6.
*/
#define PJLIB_UTIL_EDNS_YXDOMAIN PJ_STATUS_FROM_DNS_RCODE(6) /* 320056 */
#define PJLIB_UTIL_EDNS_YXDOMAIN PJ_STATUS_FROM_DNS_RCODE(6) /* 320056 */
/**
* @hideinitializer
* The RRset (name, type) exists.
* This corresponds to DNS RCODE 7.
*/
#define PJLIB_UTIL_EDNS_YXRRSET PJ_STATUS_FROM_DNS_RCODE(7) /* 320057 */
#define PJLIB_UTIL_EDNS_YXRRSET PJ_STATUS_FROM_DNS_RCODE(7) /* 320057 */
/**
* @hideinitializer
* The RRset (name, type) does not exist.
* This corresponds to DNS RCODE 8.
*/
#define PJLIB_UTIL_EDNS_NXRRSET PJ_STATUS_FROM_DNS_RCODE(8) /* 320058 */
#define PJLIB_UTIL_EDNS_NXRRSET PJ_STATUS_FROM_DNS_RCODE(8) /* 320058 */
/**
* @hideinitializer
* The requestor is not authorized to perform this operation.
* This corresponds to DNS RCODE 9.
*/
#define PJLIB_UTIL_EDNS_NOTAUTH PJ_STATUS_FROM_DNS_RCODE(9) /* 320059 */
#define PJLIB_UTIL_EDNS_NOTAUTH PJ_STATUS_FROM_DNS_RCODE(9) /* 320059 */
/**
* @hideinitializer
* The zone specified is not a zone.
* This corresponds to DNS RCODE 10.
*/
#define PJLIB_UTIL_EDNS_NOTZONE PJ_STATUS_FROM_DNS_RCODE(10)/* 320060 */
#define PJLIB_UTIL_EDNS_NOTZONE PJ_STATUS_FROM_DNS_RCODE(10)/* 320060 */
/************************************************************
@ -341,22 +340,22 @@
* @hideinitializer
* Missing/invalidSTUN MESSAGE-INTEGRITY attribute.
*/
#define PJLIB_UTIL_ESTUNMSGINT (PJLIB_UTIL_ERRNO_START+122)/* 320122 */
#define PJLIB_UTIL_ESTUNMSGINT (PJLIB_UTIL_ERRNO_START+122)/* 320122 */
/**
* @hideinitializer
* Found duplicate STUN attribute.
*/
#define PJLIB_UTIL_ESTUNDUPATTR (PJLIB_UTIL_ERRNO_START+123)/* 320123 */
#define PJLIB_UTIL_ESTUNDUPATTR (PJLIB_UTIL_ERRNO_START+123)/* 320123 */
/**
* @hideinitializer
* Missing STUN REALM attribute.
*/
#define PJLIB_UTIL_ESTUNNOREALM (PJLIB_UTIL_ERRNO_START+124)/* 320124 */
#define PJLIB_UTIL_ESTUNNOREALM (PJLIB_UTIL_ERRNO_START+124)/* 320124 */
/**
* @hideinitializer
* Missing/stale STUN NONCE attribute value.
*/
#define PJLIB_UTIL_ESTUNNONCE (PJLIB_UTIL_ERRNO_START+125)/* 320125 */
#define PJLIB_UTIL_ESTUNNONCE (PJLIB_UTIL_ERRNO_START+125)/* 320125 */
/**
* @hideinitializer
* STUN transaction terminates with failure.
@ -364,7 +363,7 @@
#define PJLIB_UTIL_ESTUNTSXFAILED (PJLIB_UTIL_ERRNO_START+126)/* 320126 */
//#define PJ_STATUS_FROM_STUN_CODE(code) (PJLIB_UTIL_ERRNO_START+code)
//#define PJ_STATUS_FROM_STUN_CODE(code) (PJLIB_UTIL_ERRNO_START+code)
/************************************************************
* HTTP Client ERROR
@ -373,27 +372,27 @@
* @hideinitializer
* Invalid URL format
*/
#define PJLIB_UTIL_EHTTPINURL (PJLIB_UTIL_ERRNO_START+151)/* 320151 */
#define PJLIB_UTIL_EHTTPINURL (PJLIB_UTIL_ERRNO_START+151)/* 320151 */
/**
* @hideinitializer
* Invalid port number
*/
#define PJLIB_UTIL_EHTTPINPORT (PJLIB_UTIL_ERRNO_START+152)/* 320152 */
#define PJLIB_UTIL_EHTTPINPORT (PJLIB_UTIL_ERRNO_START+152)/* 320152 */
/**
* @hideinitializer
* Incomplete headers received
*/
#define PJLIB_UTIL_EHTTPINCHDR (PJLIB_UTIL_ERRNO_START+153)/* 320153 */
#define PJLIB_UTIL_EHTTPINCHDR (PJLIB_UTIL_ERRNO_START+153)/* 320153 */
/**
* @hideinitializer
* Insufficient buffer
*/
#define PJLIB_UTIL_EHTTPINSBUF (PJLIB_UTIL_ERRNO_START+154)/* 320154 */
#define PJLIB_UTIL_EHTTPINSBUF (PJLIB_UTIL_ERRNO_START+154)/* 320154 */
/**
* @hideinitializer
* Connection lost
*/
#define PJLIB_UTIL_EHTTPLOST (PJLIB_UTIL_ERRNO_START+155)/* 320155 */
#define PJLIB_UTIL_EHTTPLOST (PJLIB_UTIL_ERRNO_START+155)/* 320155 */
/************************************************************
* CLI ERROR
@ -405,44 +404,44 @@
* pj_cli_sess_exec() to indicate that "exit" or equivalent command has been
* called to end the current session.
*/
#define PJ_CLI_EEXIT (PJLIB_UTIL_ERRNO_START+201)/* 320201 */
#define PJ_CLI_EEXIT (PJLIB_UTIL_ERRNO_START+201)/* 320201 */
/**
* @hideinitializer
* A required CLI argument is not specified.
*/
#define PJ_CLI_EMISSINGARG (PJLIB_UTIL_ERRNO_START+202)/* 320202 */
#define PJ_CLI_EMISSINGARG (PJLIB_UTIL_ERRNO_START+202)/* 320202 */
/**
* @hideinitializer
* Too many CLI arguments.
*/
#define PJ_CLI_ETOOMANYARGS (PJLIB_UTIL_ERRNO_START+203)/* 320203 */
#define PJ_CLI_ETOOMANYARGS (PJLIB_UTIL_ERRNO_START+203)/* 320203 */
/**
* @hideinitializer
* Invalid CLI argument. Typically this is caused by extra characters
* specified in the command line which does not match any arguments.
*/
#define PJ_CLI_EINVARG (PJLIB_UTIL_ERRNO_START+204)/* 320204 */
#define PJ_CLI_EINVARG (PJLIB_UTIL_ERRNO_START+204)/* 320204 */
/**
* @hideinitializer
* CLI command with the specified name already exist.
*/
#define PJ_CLI_EBADNAME (PJLIB_UTIL_ERRNO_START+205)/* 320205 */
#define PJ_CLI_EBADNAME (PJLIB_UTIL_ERRNO_START+205)/* 320205 */
/**
* @hideinitializer
* CLI command with the specified id already exist.
*/
#define PJ_CLI_EBADID (PJLIB_UTIL_ERRNO_START+206)/* 320206 */
#define PJ_CLI_EBADID (PJLIB_UTIL_ERRNO_START+206)/* 320206 */
/**
* @hideinitializer
* Invalid XML format for CLI command specification.
*/
#define PJ_CLI_EBADXML (PJLIB_UTIL_ERRNO_START+207)/* 320207 */
#define PJ_CLI_EBADXML (PJLIB_UTIL_ERRNO_START+207)/* 320207 */
/**
* @hideinitializer
* CLI command entered by user match with more than one command/argument
* specification.
*/
#define PJ_CLI_EAMBIGUOUS (PJLIB_UTIL_ERRNO_START+208)/* 320208 */
#define PJ_CLI_EAMBIGUOUS (PJLIB_UTIL_ERRNO_START+208)/* 320208 */
/**
* @hideinitializer
* Telnet connection lost.
@ -453,4 +452,4 @@
* @}
*/
#endif /* __PJLIB_UTIL_ERRNO_H__ */
#endif /* __PJLIB_UTIL_ERRNO_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/* Declarations for pj_getopt.
Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@ -32,7 +31,7 @@
* @{
*/
#ifdef __cplusplus
#ifdef __cplusplus
extern "C" {
#endif
@ -68,9 +67,9 @@ extern int pj_optopt;
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
@ -95,9 +94,9 @@ struct pj_getopt_option
/* Names for the values of the `has_arg' field of `struct pj_getopt_option'. */
# define no_argument 0
# define required_argument 1
# define optional_argument 2
# define no_argument 0
# define required_argument 1
# define optional_argument 2
/* Get definitions and prototypes for functions to process the
@ -127,13 +126,13 @@ struct pj_getopt_option
int pj_getopt (int argc, char *const *argv, const char *shortopts);
int pj_getopt_long (int argc, char *const *argv, const char *options,
const struct pj_getopt_option *longopts, int *longind);
const struct pj_getopt_option *longopts, int *longind);
int pj_getopt_long_only (int argc, char *const *argv,
const char *shortopts,
const struct pj_getopt_option *longopts, int *longind);
const char *shortopts,
const struct pj_getopt_option *longopts, int *longind);
#ifdef __cplusplus
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -48,54 +47,54 @@ PJ_BEGIN_DECL
*/
typedef struct pj_hmac_md5_context
{
pj_md5_context context; /**< MD5 context */
pj_uint8_t k_opad[64]; /**< opad xor-ed with key */
pj_md5_context context; /**< MD5 context */
pj_uint8_t k_opad[64]; /**< opad xor-ed with key */
} pj_hmac_md5_context;
/**
* Calculate HMAC MD5 digest for the specified input and key.
*
* @param input Pointer to the input stream.
* @param input_len Length of input stream in bytes.
* @param key Pointer to the authentication key.
* @param key_len Length of the authentication key.
* @param digest Buffer to be filled with HMAC MD5 digest.
* @param input Pointer to the input stream.
* @param input_len Length of input stream in bytes.
* @param key Pointer to the authentication key.
* @param key_len Length of the authentication key.
* @param digest Buffer to be filled with HMAC MD5 digest.
*/
PJ_DECL(void) pj_hmac_md5(const pj_uint8_t *input, unsigned input_len,
const pj_uint8_t *key, unsigned key_len,
pj_uint8_t digest[16]);
const pj_uint8_t *key, unsigned key_len,
pj_uint8_t digest[16]);
/**
* Initiate HMAC-MD5 context for incremental hashing.
*
* @param hctx HMAC-MD5 context.
* @param key Pointer to the authentication key.
* @param key_len Length of the authentication key.
* @param hctx HMAC-MD5 context.
* @param key Pointer to the authentication key.
* @param key_len Length of the authentication key.
*/
PJ_DECL(void) pj_hmac_md5_init(pj_hmac_md5_context *hctx,
const pj_uint8_t *key, unsigned key_len);
const pj_uint8_t *key, unsigned key_len);
/**
* Append string to the message.
*
* @param hctx HMAC-MD5 context.
* @param input Pointer to the input stream.
* @param input_len Length of input stream in bytes.
* @param hctx HMAC-MD5 context.
* @param input Pointer to the input stream.
* @param input_len Length of input stream in bytes.
*/
PJ_DECL(void) pj_hmac_md5_update(pj_hmac_md5_context *hctx,
const pj_uint8_t *input,
unsigned input_len);
const pj_uint8_t *input,
unsigned input_len);
/**
* Finish the message and return the digest.
*
* @param hctx HMAC-MD5 context.
* @param digest Buffer to be filled with HMAC MD5 digest.
* @param hctx HMAC-MD5 context.
* @param digest Buffer to be filled with HMAC MD5 digest.
*/
PJ_DECL(void) pj_hmac_md5_final(pj_hmac_md5_context *hctx,
pj_uint8_t digest[16]);
pj_uint8_t digest[16]);
/**
* @}
@ -104,6 +103,6 @@ PJ_DECL(void) pj_hmac_md5_final(pj_hmac_md5_context *hctx,
PJ_END_DECL
#endif /* __PJLIB_UTIL_HMAC_MD5_H__ */
#endif /* __PJLIB_UTIL_HMAC_MD5_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -44,8 +43,8 @@ PJ_BEGIN_DECL
*/
typedef struct pj_hmac_sha1_context
{
pj_sha1_context context; /**< SHA1 context */
pj_uint8_t k_opad[64]; /**< opad xor-ed with key */
pj_sha1_context context; /**< SHA1 context */
pj_uint8_t k_opad[64]; /**< opad xor-ed with key */
} pj_hmac_sha1_context;
@ -53,46 +52,46 @@ typedef struct pj_hmac_sha1_context
* Calculate HMAC-SHA1 digest for the specified input and key with this
* single function call.
*
* @param input Pointer to the input stream.
* @param input_len Length of input stream in bytes.
* @param key Pointer to the authentication key.
* @param key_len Length of the authentication key.
* @param digest Buffer to be filled with HMAC SHA1 digest.
* @param input Pointer to the input stream.
* @param input_len Length of input stream in bytes.
* @param key Pointer to the authentication key.
* @param key_len Length of the authentication key.
* @param digest Buffer to be filled with HMAC SHA1 digest.
*/
PJ_DECL(void) pj_hmac_sha1(const pj_uint8_t *input, unsigned input_len,
const pj_uint8_t *key, unsigned key_len,
pj_uint8_t digest[20]);
const pj_uint8_t *key, unsigned key_len,
pj_uint8_t digest[20]);
/**
* Initiate HMAC-SHA1 context for incremental hashing.
*
* @param hctx HMAC-SHA1 context.
* @param key Pointer to the authentication key.
* @param key_len Length of the authentication key.
* @param hctx HMAC-SHA1 context.
* @param key Pointer to the authentication key.
* @param key_len Length of the authentication key.
*/
PJ_DECL(void) pj_hmac_sha1_init(pj_hmac_sha1_context *hctx,
const pj_uint8_t *key, unsigned key_len);
const pj_uint8_t *key, unsigned key_len);
/**
* Append string to the message.
*
* @param hctx HMAC-SHA1 context.
* @param input Pointer to the input stream.
* @param input_len Length of input stream in bytes.
* @param hctx HMAC-SHA1 context.
* @param input Pointer to the input stream.
* @param input_len Length of input stream in bytes.
*/
PJ_DECL(void) pj_hmac_sha1_update(pj_hmac_sha1_context *hctx,
const pj_uint8_t *input,
unsigned input_len);
const pj_uint8_t *input,
unsigned input_len);
/**
* Finish the message and return the digest.
*
* @param hctx HMAC-SHA1 context.
* @param digest Buffer to be filled with HMAC SHA1 digest.
* @param hctx HMAC-SHA1 context.
* @param digest Buffer to be filled with HMAC SHA1 digest.
*/
PJ_DECL(void) pj_hmac_sha1_final(pj_hmac_sha1_context *hctx,
pj_uint8_t digest[20]);
pj_uint8_t digest[20]);
/**
@ -102,6 +101,6 @@ PJ_DECL(void) pj_hmac_sha1_final(pj_hmac_sha1_context *hctx,
PJ_END_DECL
#endif /* __PJLIB_UTIL_HMAC_SHA1_H__ */
#endif /* __PJLIB_UTIL_HMAC_SHA1_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
*
@ -53,8 +52,8 @@ typedef struct pj_http_req pj_http_req;
*/
typedef struct pj_http_header_elmt
{
pj_str_t name; /**< Header name */
pj_str_t value; /**< Header value */
pj_str_t name; /**< Header name */
pj_str_t value; /**< Header value */
} pj_http_header_elmt;
/**
@ -83,7 +82,7 @@ typedef struct pj_http_auth_cred
*
* Default is empty.
*/
pj_str_t scheme;
pj_str_t scheme;
/**
* Specify specific authentication realm to be responded. If this field
@ -92,14 +91,14 @@ typedef struct pj_http_auth_cred
*
* Default is empty.
*/
pj_str_t realm;
pj_str_t realm;
/**
* Specify authentication username.
*
* Default is empty.
*/
pj_str_t username;
pj_str_t username;
/**
* The type of password in \a data field. Currently only 0 is
@ -107,7 +106,7 @@ typedef struct pj_http_auth_cred
*
* Default is 0.
*/
unsigned data_type;
unsigned data_type;
/**
* Specify authentication password. The encoding of the password depends
@ -115,7 +114,7 @@ typedef struct pj_http_auth_cred
*
* Default is empty.
*/
pj_str_t data;
pj_str_t data;
} pj_http_auth_cred;
@ -186,7 +185,7 @@ typedef struct pj_http_req_param
/**
* Authentication credential needed to respond to 401/407 response.
*/
pj_http_auth_cred auth_cred;
pj_http_auth_cred auth_cred;
/**
* Optional source port range to use when binding the socket.
@ -199,7 +198,7 @@ typedef struct pj_http_req_param
*
* Default is 0 (The OS will select the source port automatically)
*/
pj_uint16_t source_port_range_start;
pj_uint16_t source_port_range_start;
/**
* Optional source port range to use when binding.
@ -207,7 +206,7 @@ typedef struct pj_http_req_param
*
* Default is 0 (The OS will select the source port automatically))
*/
pj_uint16_t source_port_range_size;
pj_uint16_t source_port_range_size;
/**
* Max number of retries if binding to a port fails.
@ -216,7 +215,7 @@ typedef struct pj_http_req_param
*
* Default is 3
*/
pj_uint16_t max_retries;
pj_uint16_t max_retries;
} pj_http_req_param;
@ -225,14 +224,14 @@ typedef struct pj_http_req_param
*/
typedef struct pj_http_auth_chal
{
pj_str_t scheme; /**< Auth scheme. */
pj_str_t realm; /**< Realm for the challenge. */
pj_str_t domain; /**< Domain. */
pj_str_t nonce; /**< Nonce challenge. */
pj_str_t opaque; /**< Opaque value. */
int stale; /**< Stale parameter. */
pj_str_t algorithm; /**< Algorithm parameter. */
pj_str_t qop; /**< Quality of protection. */
pj_str_t scheme; /**< Auth scheme. */
pj_str_t realm; /**< Realm for the challenge. */
pj_str_t domain; /**< Domain. */
pj_str_t nonce; /**< Nonce challenge. */
pj_str_t opaque; /**< Opaque value. */
int stale; /**< Stale parameter. */
pj_str_t algorithm; /**< Algorithm parameter. */
pj_str_t qop; /**< Quality of protection. */
} pj_http_auth_chal;
/**
@ -245,9 +244,9 @@ typedef struct pj_http_resp
pj_str_t reason; /**< Reason phrase */
pj_http_headers headers; /**< Response headers */
pj_http_auth_chal auth_chal; /**< Parsed WWW-Authenticate header, if
any. */
any. */
pj_int32_t content_length; /**< The value of content-length header
field. -1 if not specified. */
field. -1 if not specified. */
void *data; /**< Data received */
pj_size_t size; /**< Data size */
} pj_http_resp;
@ -257,8 +256,8 @@ typedef struct pj_http_resp
*/
typedef struct pj_http_url
{
pj_str_t username; /**< Username part */
pj_str_t passwd; /**< Password part */
pj_str_t username; /**< Username part */
pj_str_t passwd; /**< Password part */
pj_str_t protocol; /**< Protocol used */
pj_str_t host; /**< Host name */
pj_uint16_t port; /**< Port number */
@ -274,8 +273,8 @@ typedef struct pj_http_req_callback
* This callback is called when a complete HTTP response header
* is received.
*
* @param http_req The http request.
* @param resp The response of the request.
* @param http_req The http request.
* @param resp The response of the request.
*/
void (*on_response)(pj_http_req *http_req, const pj_http_resp *resp);
@ -287,13 +286,13 @@ typedef struct pj_http_req_callback
* callback to be called, application MUST set http_req_param.total_size
* to a value greater than 0.
*
* @param http_req The http request.
* @param data Pointer to the data that will be sent. Application
* @param http_req The http request.
* @param data Pointer to the data that will be sent. Application
* must set the pointer to the current data chunk/segment
* to be sent. Data must remain valid until the next
* on_send_data() callback or for the last segment,
* until it is sent.
* @param size Pointer to the data size that will be sent.
* @param size Pointer to the data size that will be sent.
*/
void (*on_send_data)(pj_http_req *http_req,
void **data, pj_size_t *size);
@ -307,9 +306,9 @@ typedef struct pj_http_req_callback
* on_complete() callback will be called with the response
* parameter containing the complete data.
*
* @param http_req The http request.
* @param data The buffer containing the data.
* @param size The length of data in the buffer.
* @param http_req The http request.
* @param data The buffer containing the data.
* @param size The length of data in the buffer.
*/
void (*on_data_read)(pj_http_req *http_req,
void *data, pj_size_t size);
@ -327,15 +326,15 @@ typedef struct pj_http_req_callback
* pj_http_req immediately by calling #pj_http_req_destroy() inside
* the callback.
*
* @param http_req The http request.
* @param status The status of the request operation. PJ_SUCCESS
* @param http_req The http request.
* @param status The status of the request operation. PJ_SUCCESS
* if the operation completed successfully
* (connection-wise). To check the server's
* status-code response to the HTTP request,
* application should check resp->status_code instead.
* @param resp The response of the corresponding request. If
* the status argument is non-PJ_SUCCESS, this
* argument will be set to NULL.
* @param resp The response of the corresponding request. If
* the status argument is non-PJ_SUCCESS, this
* argument will be set to NULL.
*/
void (*on_complete)(pj_http_req *http_req,
pj_status_t status,
@ -347,7 +346,7 @@ typedef struct pj_http_req_callback
/**
* Initialize the http request parameters with the default values.
*
* @param param The parameter to be initialized.
* @param param The parameter to be initialized.
*/
PJ_DECL(void) pj_http_req_param_default(pj_http_req_param *param);
@ -355,12 +354,12 @@ PJ_DECL(void) pj_http_req_param_default(pj_http_req_param *param);
* Add a header element/field. Application MUST make sure that
* name and val pointer remains valid until the HTTP request is sent.
*
* @param headers The headers.
* @param name The header field name.
* @param val The header field value.
* @param headers The headers.
* @param name The header field name.
* @param val The header field value.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_http_headers_add_elmt(pj_http_headers *headers,
pj_str_t *name,
@ -371,12 +370,12 @@ PJ_DECL(pj_status_t) pj_http_headers_add_elmt(pj_http_headers *headers,
* its parameters. Application MUST make sure that name and val pointer
* remains valid until the HTTP request is sent.
*
* @param headers The headers.
* @param name The header field name.
* @param val The header field value.
* @param headers The headers.
* @param name The header field name.
* @param val The header field value.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_http_headers_add_elmt2(pj_http_headers *headers,
char *name, char *val);
@ -384,11 +383,11 @@ PJ_DECL(pj_status_t) pj_http_headers_add_elmt2(pj_http_headers *headers,
/**
* Parse a http URL into its components.
*
* @param url The URL to be parsed.
* @param hurl Pointer to receive the parsed result.
* @param url The URL to be parsed.
* @param hurl Pointer to receive the parsed result.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_http_req_parse_url(const pj_str_t *url,
pj_http_url *hurl);
@ -396,24 +395,24 @@ PJ_DECL(pj_status_t) pj_http_req_parse_url(const pj_str_t *url,
/**
* Create the HTTP request.
*
* @param pool Pool to use. HTTP request will use the pool's factory
* @param pool Pool to use. HTTP request will use the pool's factory
* to allocate its own memory pool.
* @param url HTTP URL request.
* @param timer The timer to use.
* @param ioqueue The ioqueue to use.
* @param param Optional parameters. When this parameter is not
* @param url HTTP URL request.
* @param timer The timer to use.
* @param ioqueue The ioqueue to use.
* @param param Optional parameters. When this parameter is not
* specifed (NULL), the default values will be used.
* @param hcb Pointer to structure containing application
* callbacks.
* @param http_req Pointer to receive the http request instance.
* @param hcb Pointer to structure containing application
* callbacks.
* @param http_req Pointer to receive the http request instance.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_http_req_create(pj_pool_t *pool,
const pj_str_t *url,
pj_timer_heap_t *timer,
pj_ioqueue_t *ioqueue,
pj_timer_heap_t *timer,
pj_ioqueue_t *ioqueue,
const pj_http_req_param *param,
const pj_http_req_callback *hcb,
pj_http_req **http_req);
@ -458,7 +457,7 @@ PJ_DECL(pj_status_t) pj_http_req_cancel(pj_http_req *http_req,
/**
* Destroy the http request.
*
* @param http_req The http request to be destroyed.
* @param http_req The http request to be destroyed.
*
* @return PJ_SUCCESS if success.
*/
@ -469,8 +468,8 @@ PJ_DECL(pj_status_t) pj_http_req_destroy(pj_http_req *http_req);
*
* @param http_req The http request.
*
* @return PJ_TRUE if a request is pending, or
* PJ_FALSE if idle
* @return PJ_TRUE if a request is pending, or
* PJ_FALSE if idle
*/
PJ_DECL(pj_bool_t) pj_http_req_is_running(const pj_http_req *http_req);
@ -480,7 +479,7 @@ PJ_DECL(pj_bool_t) pj_http_req_is_running(const pj_http_req *http_req);
*
* @param http_req The http request.
*
* @return The user data.
* @return The user data.
*/
PJ_DECL(void *) pj_http_req_get_user_data(pj_http_req *http_req);
@ -491,4 +490,4 @@ PJ_DECL(void *) pj_http_req_get_user_data(pj_http_req *http_req);
PJ_END_DECL
#endif /* __PJLIB_UTIL_HTTP_CLIENT_H__ */
#endif /* __PJLIB_UTIL_HTTP_CLIENT_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
@ -44,12 +43,12 @@ PJ_BEGIN_DECL
*/
typedef enum pj_json_val_type
{
PJ_JSON_VAL_NULL, /**< Null value (null) */
PJ_JSON_VAL_BOOL, /**< Boolean value (true, false) */
PJ_JSON_VAL_NUMBER, /**< Numeric (float or fixed point) */
PJ_JSON_VAL_STRING, /**< Literal string value. */
PJ_JSON_VAL_ARRAY, /**< Array */
PJ_JSON_VAL_OBJ /**< Object. */
PJ_JSON_VAL_NULL, /**< Null value (null) */
PJ_JSON_VAL_BOOL, /**< Boolean value (true, false) */
PJ_JSON_VAL_NUMBER, /**< Numeric (float or fixed point) */
PJ_JSON_VAL_STRING, /**< Literal string value. */
PJ_JSON_VAL_ARRAY, /**< Array */
PJ_JSON_VAL_OBJ /**< Object. */
} pj_json_val_type;
/* Forward declaration for JSON element */
@ -73,15 +72,15 @@ typedef struct pj_json_list
struct pj_json_elem
{
PJ_DECL_LIST_MEMBER(pj_json_elem);
pj_str_t name; /**< ELement name. */
pj_json_val_type type; /**< Element type. */
pj_str_t name; /**< ELement name. */
pj_json_val_type type; /**< Element type. */
union
{
pj_bool_t is_true; /**< Boolean value. */
float num; /**< Number value. */
pj_str_t str; /**< String value. */
pj_json_list children; /**< Object and array children */
} value; /**< Element value. */
pj_bool_t is_true; /**< Boolean value. */
float num; /**< Number value. */
pj_str_t str; /**< String value. */
pj_json_list children; /**< Object and array children */
} value; /**< Element value. */
};
/**
@ -90,40 +89,40 @@ struct pj_json_elem
*/
typedef struct pj_json_err_info
{
unsigned line; /**< Line location of the error */
unsigned col; /**< Column location of the error */
int err_char; /**< The offending character. */
unsigned line; /**< Line location of the error */
unsigned col; /**< Column location of the error */
int err_char; /**< The offending character. */
} pj_json_err_info;
/**
* Type of function callback to write JSON document in pj_json_writef().
*
* @param s The string to be written to the document.
* @param size The length of the string
* @param user_data User data that was specified to pj_json_writef()
* @param s The string to be written to the document.
* @param size The length of the string
* @param user_data User data that was specified to pj_json_writef()
*
* @return If the callback returns non-PJ_SUCCESS, it will
* stop the pj_json_writef() function and this error
* will be returned to caller.
* @return If the callback returns non-PJ_SUCCESS, it will
* stop the pj_json_writef() function and this error
* will be returned to caller.
*/
typedef pj_status_t (*pj_json_writer)(const char *s,
unsigned size,
void *user_data);
unsigned size,
void *user_data);
/**
* Initialize null element.
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param el The element.
* @param name Name to be given to the element, or NULL.
*/
PJ_DECL(void) pj_json_elem_null(pj_json_elem *el, pj_str_t *name);
/**
* Initialize boolean element with the specified value.
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
*/
PJ_DECL(void) pj_json_elem_bool(pj_json_elem *el, pj_str_t *name,
pj_bool_t val);
@ -131,9 +130,9 @@ PJ_DECL(void) pj_json_elem_bool(pj_json_elem *el, pj_str_t *name,
/**
* Initialize number element with the specified value.
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
*/
PJ_DECL(void) pj_json_elem_number(pj_json_elem *el, pj_str_t *name,
float val);
@ -141,9 +140,9 @@ PJ_DECL(void) pj_json_elem_number(pj_json_elem *el, pj_str_t *name,
/**
* Initialize string element with the specified value.
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param val The value.
*/
PJ_DECL(void) pj_json_elem_string(pj_json_elem *el, pj_str_t *name,
pj_str_t *val);
@ -151,24 +150,24 @@ PJ_DECL(void) pj_json_elem_string(pj_json_elem *el, pj_str_t *name,
/**
* Initialize element as an empty array
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param el The element.
* @param name Name to be given to the element, or NULL.
*/
PJ_DECL(void) pj_json_elem_array(pj_json_elem *el, pj_str_t *name);
/**
* Initialize element as an empty object
*
* @param el The element.
* @param name Name to be given to the element, or NULL.
* @param el The element.
* @param name Name to be given to the element, or NULL.
*/
PJ_DECL(void) pj_json_elem_obj(pj_json_elem *el, pj_str_t *name);
/**
* Add an element to an object or array.
*
* @param el The object or array element.
* @param child Element to be added to the object or array.
* @param el The object or array element.
* @param child Element to be added to the object or array.
*/
PJ_DECL(void) pj_json_elem_add(pj_json_elem *el, pj_json_elem *child);
@ -176,13 +175,13 @@ PJ_DECL(void) pj_json_elem_add(pj_json_elem *el, pj_json_elem *child);
* Parse a JSON document in the buffer. The buffer MUST be NULL terminated,
* or if not then it must have enough size to put the NULL character.
*
* @param pool The pool to allocate memory for creating elements.
* @param buffer String buffer containing JSON document.
* @param size Size of the document.
* @param err_info Optional structure to be filled with info when
* parsing failed.
* @param pool The pool to allocate memory for creating elements.
* @param buffer String buffer containing JSON document.
* @param size Size of the document.
* @param err_info Optional structure to be filled with info when
* parsing failed.
*
* @return The root element from the document.
* @return The root element from the document.
*/
PJ_DECL(pj_json_elem*) pj_json_parse(pj_pool_t *pool,
char *buffer,
@ -192,13 +191,13 @@ PJ_DECL(pj_json_elem*) pj_json_parse(pj_pool_t *pool,
/**
* Write the specified element to the string buffer.
*
* @param elem The element to be written.
* @param buffer Output buffer.
* @param size On input, it must be set to the size of the buffer.
* Upon successful return, this will be set to
* the length of the written string.
* @param elem The element to be written.
* @param buffer Output buffer.
* @param size On input, it must be set to the size of the buffer.
* Upon successful return, this will be set to
* the length of the written string.
*
* @return PJ_SUCCESS on success or the appropriate error.
* @return PJ_SUCCESS on success or the appropriate error.
*/
PJ_DECL(pj_status_t) pj_json_write(const pj_json_elem *elem,
char *buffer, unsigned *size);
@ -207,13 +206,13 @@ PJ_DECL(pj_status_t) pj_json_write(const pj_json_elem *elem,
* Incrementally write the element to arbitrary medium using the specified
* callback to write the document chunks.
*
* @param elem The element to be written.
* @param writer Callback function which will be called to write
* text chunks.
* @param user_data Arbitrary user data which will be given back when
* calling the callback.
* @param elem The element to be written.
* @param writer Callback function which will be called to write
* text chunks.
* @param user_data Arbitrary user data which will be given back when
* calling the callback.
*
* @return PJ_SUCCESS on success or the appropriate error.
* @return PJ_SUCCESS on success or the appropriate error.
*/
PJ_DECL(pj_status_t) pj_json_writef(const pj_json_elem *elem,
pj_json_writer writer,
@ -225,4 +224,4 @@ PJ_DECL(pj_status_t) pj_json_writef(const pj_json_elem *elem,
PJ_END_DECL
#endif /* __PJLIB_UTIL_JSON_H__ */
#endif /* __PJLIB_UTIL_JSON_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -39,27 +38,27 @@ PJ_BEGIN_DECL
/** MD5 context. */
typedef struct pj_md5_context
{
pj_uint32_t buf[4]; /**< buf */
pj_uint32_t bits[2]; /**< bits */
pj_uint8_t in[64]; /**< in */
pj_uint32_t buf[4]; /**< buf */
pj_uint32_t bits[2]; /**< bits */
pj_uint8_t in[64]; /**< in */
} pj_md5_context;
/** Initialize the algorithm.
* @param pms MD5 context.
* @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.
* @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);
const pj_uint8_t *data, unsigned nbytes);
/** Finish the message and return the digest.
* @param pms MD5 context.
* @param digest 16 byte 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]);
@ -71,4 +70,4 @@ PJ_DECL(void) pj_md5_final(pj_md5_context *pms, pj_uint8_t digest[16]);
PJ_END_DECL
#endif /* __PJLIB_UTIL_MD5_H__ */
#endif /* __PJLIB_UTIL_MD5_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -66,10 +65,10 @@ typedef enum pj_pcap_proto_type
*/
typedef struct pj_pcap_udp_hdr
{
pj_uint16_t src_port; /**< Source port. */
pj_uint16_t dst_port; /**< Destination port */
pj_uint16_t len; /**< Length. */
pj_uint16_t csum; /**< Checksum. */
pj_uint16_t src_port; /**< Source port. */
pj_uint16_t dst_port; /**< Destination port */
pj_uint16_t len; /**< Length. */
pj_uint16_t csum; /**< Checksum. */
} pj_pcap_udp_hdr;
@ -83,40 +82,40 @@ typedef struct pj_pcap_filter
/**
* Select data link type, or zero to include any supported data links.
*/
pj_pcap_link_type link;
pj_pcap_link_type link;
/**
* Select protocol, or zero to include all supported protocols.
*/
pj_pcap_proto_type proto;
pj_pcap_proto_type proto;
/**
* Specify source IP address of the packets, or zero to include packets
* from any IP addresses. Note that IP address here must be in
* network byte order.
*/
pj_uint32_t ip_src;
pj_uint32_t ip_src;
/**
* Specify destination IP address of the packets, or zero to include packets
* destined to any IP addresses. Note that IP address here must be in
* network byte order.
*/
pj_uint32_t ip_dst;
pj_uint32_t ip_dst;
/**
* Specify source port of the packets, or zero to include packets with
* any source port number. Note that the port number must be in network
* byte order.
*/
pj_uint16_t src_port;
pj_uint16_t src_port;
/**
* Specify destination port of the packets, or zero to include packets with
* any destination port number. Note that the port number must be in network
* byte order.
*/
pj_uint16_t dst_port;
pj_uint16_t dst_port;
} pj_pcap_filter;
@ -136,22 +135,22 @@ PJ_DECL(void) pj_pcap_filter_default(pj_pcap_filter *filter);
/**
* Open PCAP file.
*
* @param pool Pool to allocate memory.
* @param path File/path name.
* @param pool Pool to allocate memory.
* @param path File/path name.
* @param p_file Pointer to receive PCAP file handle.
*
* @return PJ_SUCCESS if file can be opened successfully.
* @return PJ_SUCCESS if file can be opened successfully.
*/
PJ_DECL(pj_status_t) pj_pcap_open(pj_pool_t *pool,
const char *path,
pj_pcap_file **p_file);
const char *path,
pj_pcap_file **p_file);
/**
* Close PCAP file.
*
* @param file PCAP file handle.
* @param file PCAP file handle.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_pcap_close(pj_pcap_file *file);
@ -159,31 +158,31 @@ PJ_DECL(pj_status_t) pj_pcap_close(pj_pcap_file *file);
* Configure filter for reading the file. When filter is configured,
* only packets matching all the filter settings will be returned.
*
* @param file PCAP file handle.
* @param file PCAP file handle.
* @param filter The filter.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_pcap_set_filter(pj_pcap_file *file,
const pj_pcap_filter *filter);
const pj_pcap_filter *filter);
/**
* Read UDP payload from the next packet in the PCAP file. Optionally it
* can return the UDP header, if caller supplies it.
*
* @param file PCAP file handle.
* @param udp_hdr Optional buffer to receive UDP header.
* @param udp_payload Buffer to receive the UDP payload.
* @param file PCAP file handle.
* @param udp_hdr Optional buffer to receive UDP header.
* @param udp_payload Buffer to receive the UDP payload.
* @param udp_payload_size On input, specify the size of the buffer.
* On output, it will be filled with the actual size
* of the payload as read from the packet.
* On output, it will be filled with the actual size
* of the payload as read from the packet.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_pcap_read_udp(pj_pcap_file *file,
pj_pcap_udp_hdr *udp_hdr,
pj_uint8_t *udp_payload,
pj_size_t *udp_payload_size);
pj_pcap_udp_hdr *udp_hdr,
pj_uint8_t *udp_payload,
pj_size_t *udp_payload_size);
/**
@ -192,5 +191,5 @@ PJ_DECL(pj_status_t) pj_pcap_read_udp(pj_pcap_file *file,
PJ_END_DECL
#endif /* __PJLIB_UTIL_PCAP_H__ */
#endif /* __PJLIB_UTIL_PCAP_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -173,15 +172,15 @@ typedef struct pj_dns_async_query pj_dns_async_query;
* Type of asynchronous callback which will be called when the asynchronous
* query completes.
*
* @param user_data The user data set by application when creating the
* asynchronous query.
* @param status Status of the DNS resolution.
* @param response The response packet received from the server. This
* argument may be NULL when status is not PJ_SUCCESS.
* @param user_data The user data set by application when creating the
* asynchronous query.
* @param status Status of the DNS resolution.
* @param response The response packet received from the server. This
* argument may be NULL when status is not PJ_SUCCESS.
*/
typedef void pj_dns_callback(void *user_data,
pj_status_t status,
pj_dns_parsed_packet *response);
pj_status_t status,
pj_dns_parsed_packet *response);
/**
@ -189,13 +188,13 @@ typedef void pj_dns_callback(void *user_data,
*/
typedef struct pj_dns_settings
{
unsigned options; /**< Options flags. */
unsigned qretr_delay; /**< Query retransmit delay in msec. */
unsigned qretr_count; /**< Query maximum retransmission count. */
unsigned cache_max_ttl; /**< Maximum TTL for cached responses. If the
value is zero, caching is disabled. */
unsigned good_ns_ttl; /**< See #PJ_DNS_RESOLVER_GOOD_NS_TTL */
unsigned bad_ns_ttl; /**< See #PJ_DNS_RESOLVER_BAD_NS_TTL */
unsigned options; /**< Options flags. */
unsigned qretr_delay; /**< Query retransmit delay in msec. */
unsigned qretr_count; /**< Query maximum retransmission count. */
unsigned cache_max_ttl; /**< Maximum TTL for cached responses. If the
value is zero, caching is disabled. */
unsigned good_ns_ttl; /**< See #PJ_DNS_RESOLVER_GOOD_NS_TTL */
unsigned bad_ns_ttl; /**< See #PJ_DNS_RESOLVER_BAD_NS_TTL */
} pj_dns_settings;
@ -206,21 +205,21 @@ typedef struct pj_dns_settings
typedef struct pj_dns_a_record
{
/** The target name being queried. */
pj_str_t name;
pj_str_t name;
/** If target name corresponds to a CNAME entry, the alias contains
* the value of the CNAME entry, otherwise it will be empty.
*/
pj_str_t alias;
pj_str_t alias;
/** Number of IP addresses. */
unsigned addr_count;
unsigned addr_count;
/** IP addresses of the host found in the response */
pj_in_addr addr[PJ_DNS_MAX_IP_IN_A_REC];
pj_in_addr addr[PJ_DNS_MAX_IP_IN_A_REC];
/** Internal buffer for hostname and alias. */
char buf_[128];
char buf_[128];
} pj_dns_a_record;
@ -233,35 +232,35 @@ typedef struct pj_dns_a_record
typedef struct pj_dns_addr_record
{
/** The target name being queried. */
pj_str_t name;
pj_str_t name;
/** If target name corresponds to a CNAME entry, the alias contains
* the value of the CNAME entry, otherwise it will be empty.
*/
pj_str_t alias;
pj_str_t alias;
/** Number of IP addresses. */
unsigned addr_count;
unsigned addr_count;
/** IP addresses of the host found in the response */
struct {
/** IP address family */
int af;
/** IP address */
union {
/** IPv4 address */
pj_in_addr v4;
/** IP address family */
int af;
/** IP address */
union {
/** IPv4 address */
pj_in_addr v4;
/** IPv6 address */
pj_in6_addr v6;
} ip;
/** IPv6 address */
pj_in6_addr v6;
} ip;
} addr[PJ_DNS_MAX_IP_IN_A_REC];
/** Internal buffer for hostname and alias. */
char buf_[128];
char buf_[128];
} pj_dns_addr_record;
@ -269,7 +268,7 @@ typedef struct pj_dns_addr_record
/**
* Set default values to the DNS settings.
*
* @param s The DNS settings to be initialized.
* @param s The DNS settings to be initialized.
*/
PJ_DECL(void) pj_dns_settings_default(pj_dns_settings *s);
@ -282,28 +281,28 @@ PJ_DECL(void) pj_dns_settings_default(pj_dns_settings *s);
* and ioqueue instance, so that it doesn't need to poll the resolver
* periodically.
*
* @param pf Pool factory where the memory pool will be created from.
* @param name Optional resolver name to identify the instance in
* the log.
* @param pf Pool factory where the memory pool will be created from.
* @param name Optional resolver name to identify the instance in
* the log.
* @param options Optional options, must be zero for now.
* @param timer Optional timer heap instance to be used by the resolver.
* If timer heap is not specified, an internal timer will be
* created, and application would need to poll the resolver
* periodically.
* @param timer Optional timer heap instance to be used by the resolver.
* If timer heap is not specified, an internal timer will be
* created, and application would need to poll the resolver
* periodically.
* @param ioqueue Optional I/O Queue instance to be used by the resolver.
* If ioqueue is not specified, an internal one will be
* created, and application would need to poll the resolver
* periodically.
* If ioqueue is not specified, an internal one will be
* created, and application would need to poll the resolver
* periodically.
* @param p_resolver Pointer to receive the resolver instance.
*
* @return PJ_SUCCESS on success, or the appropriate error code,
* @return PJ_SUCCESS on success, or the appropriate error code,
*/
PJ_DECL(pj_status_t) pj_dns_resolver_create(pj_pool_factory *pf,
const char *name,
unsigned options,
pj_timer_heap_t *timer,
pj_ioqueue_t *ioqueue,
pj_dns_resolver **p_resolver);
const char *name,
unsigned options,
pj_timer_heap_t *timer,
pj_ioqueue_t *ioqueue,
pj_dns_resolver **p_resolver);
/**
@ -315,29 +314,29 @@ PJ_DECL(pj_status_t) pj_dns_resolver_create(pj_pool_factory *pf,
* @param resolver The resolver instance.
* @param count Number of name servers in the array.
* @param servers Array of name server IP addresses or hostnames. If
* hostname is specified, the hostname must be resolvable
* with pj_gethostbyname().
* @param ports Optional array of ports. If this argument is NULL,
* the nameserver will use default port.
* hostname is specified, the hostname must be resolvable
* with pj_gethostbyname().
* @param ports Optional array of ports. If this argument is NULL,
* the nameserver will use default port.
*
* @return PJ_SUCCESS on success, or the appropriate error code,
* @return PJ_SUCCESS on success, or the appropriate error code,
*/
PJ_DECL(pj_status_t) pj_dns_resolver_set_ns(pj_dns_resolver *resolver,
unsigned count,
const pj_str_t servers[],
const pj_uint16_t ports[]);
unsigned count,
const pj_str_t servers[],
const pj_uint16_t ports[]);
/**
* Get the resolver current settings.
*
* @param resolver The resolver instance.
* @param st Buffer to be filled up with resolver settings.
* @param st Buffer to be filled up with resolver settings.
*
* @return The query timeout setting, in seconds.
* @return The query timeout setting, in seconds.
*/
PJ_DECL(pj_status_t) pj_dns_resolver_get_settings(pj_dns_resolver *resolver,
pj_dns_settings *st);
pj_dns_settings *st);
/**
@ -346,12 +345,12 @@ PJ_DECL(pj_status_t) pj_dns_resolver_get_settings(pj_dns_resolver *resolver,
* ensure that all fields are initialized properly.
*
* @param resolver The resolver instance.
* @param st The resolver settings.
* @param st The resolver settings.
*
* @return PJ_SUCCESS on success, or the appropriate error code,
* @return PJ_SUCCESS on success, or the appropriate error code,
*/
PJ_DECL(pj_status_t) pj_dns_resolver_set_settings(pj_dns_resolver *resolver,
const pj_dns_settings *st);
const pj_dns_settings *st);
/**
@ -362,11 +361,11 @@ PJ_DECL(pj_status_t) pj_dns_resolver_set_settings(pj_dns_resolver *resolver,
*
* @param resolver The resolver instance.
* @param timeout Maximum time to wait for event occurence. If this
* argument is NULL, this function will wait forever
* until events occur.
* argument is NULL, this function will wait forever
* until events occur.
*/
PJ_DECL(void) pj_dns_resolver_handle_events(pj_dns_resolver *resolver,
const pj_time_val *timeout);
const pj_time_val *timeout);
/**
@ -374,13 +373,13 @@ PJ_DECL(void) pj_dns_resolver_handle_events(pj_dns_resolver *resolver,
*
* @param resolver The resolver object to be destryed
* @param notify If non-zero, all pending asynchronous queries will be
* cancelled and its callback will be called. If FALSE,
* then no callback will be called.
* cancelled and its callback will be called. If FALSE,
* then no callback will be called.
*
* @return PJ_SUCCESS on success, or the appropriate error code,
* @return PJ_SUCCESS on success, or the appropriate error code,
*/
PJ_DECL(pj_status_t) pj_dns_resolver_destroy(pj_dns_resolver *resolver,
pj_bool_t notify);
pj_bool_t notify);
/**
@ -399,68 +398,68 @@ PJ_DECL(pj_status_t) pj_dns_resolver_destroy(pj_dns_resolver *resolver,
* is started.
*
* @param resolver The resolver object.
* @param name The name to be resolved.
* @param type The type of resource (see #pj_dns_type constants).
* @param name The name to be resolved.
* @param type The type of resource (see #pj_dns_type constants).
* @param options Optional options, must be zero for now.
* @param cb Callback to be called when the query completes,
* either successfully or with failure.
* @param cb Callback to be called when the query completes,
* either successfully or with failure.
* @param user_data Arbitrary user data to be associated with the query,
* and which will be given back in the callback.
* and which will be given back in the callback.
* @param p_query Optional pointer to receive the query object, if one
* was started. If this pointer is specified, a NULL may
* be returned if response cache is available immediately.
* was started. If this pointer is specified, a NULL may
* be returned if response cache is available immediately.
*
* @return PJ_SUCCESS if either an asynchronous query has been
* started successfully or response cache is available and
* the user callback has been called.
* @return PJ_SUCCESS if either an asynchronous query has been
* started successfully or response cache is available and
* the user callback has been called.
*/
PJ_DECL(pj_status_t) pj_dns_resolver_start_query(pj_dns_resolver *resolver,
const pj_str_t *name,
int type,
unsigned options,
pj_dns_callback *cb,
void *user_data,
pj_dns_async_query **p_query);
const pj_str_t *name,
int type,
unsigned options,
pj_dns_callback *cb,
void *user_data,
pj_dns_async_query **p_query);
/**
* Cancel a pending query.
*
* @param query The pending asynchronous query to be cancelled.
* @param query The pending asynchronous query to be cancelled.
* @param notify If non-zero, the callback will be called with failure
* status to notify that the query has been cancelled.
* status to notify that the query has been cancelled.
*
* @return PJ_SUCCESS on success, or the appropriate error code,
* @return PJ_SUCCESS on success, or the appropriate error code,
*/
PJ_DECL(pj_status_t) pj_dns_resolver_cancel_query(pj_dns_async_query *query,
pj_bool_t notify);
pj_bool_t notify);
/**
* A utility function to parse a DNS response containing A records into
* DNS A record.
*
* @param pkt The DNS response packet.
* @param rec The structure to be initialized with the parsed
* DNS A record from the packet.
* @param pkt The DNS response packet.
* @param rec The structure to be initialized with the parsed
* DNS A record from the packet.
*
* @return PJ_SUCCESS if response can be parsed successfully.
* @return PJ_SUCCESS if response can be parsed successfully.
*/
PJ_DECL(pj_status_t) pj_dns_parse_a_response(const pj_dns_parsed_packet *pkt,
pj_dns_a_record *rec);
pj_dns_a_record *rec);
/**
* A utility function to parse a DNS response containing AAAA records into
* DNS AAAA record.
*
* @param pkt The DNS response packet.
* @param rec The structure to be initialized with the parsed
* DNS AAAA record from the packet.
* @param pkt The DNS response packet.
* @param rec The structure to be initialized with the parsed
* DNS AAAA record from the packet.
*
* @return PJ_SUCCESS if response can be parsed successfully.
* @return PJ_SUCCESS if response can be parsed successfully.
*/
PJ_DECL(pj_status_t) pj_dns_parse_addr_response(
const pj_dns_parsed_packet *pkt,
pj_dns_addr_record *rec);
const pj_dns_parsed_packet *pkt,
pj_dns_addr_record *rec);
/**
@ -472,25 +471,25 @@ PJ_DECL(pj_status_t) pj_dns_parse_addr_response(
* it can be indexed.
*
* @param resolver The resolver instance.
* @param pkt DNS packet to be added to the DNS cache. If the packet
* matches existing entry, it will update the entry.
* @param pkt DNS packet to be added to the DNS cache. If the packet
* matches existing entry, it will update the entry.
* @param set_ttl If the value is PJ_FALSE, the entry will not expire
* (so use with care). Otherwise cache expiration will be
* calculated based on the TTL of the answeres.
* (so use with care). Otherwise cache expiration will be
* calculated based on the TTL of the answeres.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_dns_resolver_add_entry(pj_dns_resolver *resolver,
const pj_dns_parsed_packet *pkt,
pj_bool_t set_ttl);
const pj_dns_parsed_packet *pkt,
pj_bool_t set_ttl);
/**
* Get the total number of response in the response cache.
*
* @param resolver The resolver instance.
*
* @return Current number of entries being stored in the response
* cache.
* @return Current number of entries being stored in the response
* cache.
*/
PJ_DECL(unsigned) pj_dns_resolver_get_cached_count(pj_dns_resolver *resolver);
@ -502,7 +501,7 @@ PJ_DECL(unsigned) pj_dns_resolver_get_cached_count(pj_dns_resolver *resolver);
* @param detail Will print detailed entries.
*/
PJ_DECL(void) pj_dns_resolver_dump(pj_dns_resolver *resolver,
pj_bool_t detail);
pj_bool_t detail);
/**
@ -512,5 +511,5 @@ PJ_DECL(void) pj_dns_resolver_dump(pj_dns_resolver *resolver,
PJ_END_DECL
#endif /* __PJLIB_UTIL_RESOLVER_H__ */
#endif /* __PJLIB_UTIL_RESOLVER_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -111,8 +110,8 @@ PJ_DECL(void) pj_cis_add_str( pj_cis_t *cis, const char *str);
/**
* Add specification from another specification.
*
* @param cis The specification is to be set.
* @param rhs The specification to be copied.
* @param cis The specification is to be set.
* @param rhs The specification to be copied.
*/
PJ_DECL(void) pj_cis_add_cis( pj_cis_t *cis, const pj_cis_t *rhs);
@ -146,7 +145,7 @@ PJ_DECL(void) pj_cis_invert( pj_cis_t *cis );
* @param cis The scanner character specification.
* @param c The character to check for matching.
*
* @return Non-zero if match (not necessarily one).
* @return Non-zero if match (not necessarily one).
*/
PJ_INLINE(int) pj_cis_match( const pj_cis_t *cis, pj_uint8_t c )
{
@ -160,7 +159,7 @@ PJ_INLINE(int) pj_cis_match( const pj_cis_t *cis, pj_uint8_t c )
enum
{
/** This flags specifies that the scanner should automatically skip
whitespaces
whitespaces
*/
PJ_SCAN_AUTOSKIP_WS = 1,
@ -193,12 +192,12 @@ typedef void (*pj_syn_err_func_ptr)(struct pj_scanner *scanner);
*/
typedef struct pj_scanner
{
char *begin; /**< Start of input buffer. */
char *end; /**< End of input buffer. */
char *curptr; /**< Current pointer. */
int line; /**< Current line. */
char *start_line; /**< Where current line starts. */
int skip_ws; /**< Skip whitespace flag. */
char *begin; /**< Start of input buffer. */
char *end; /**< End of input buffer. */
char *curptr; /**< Current pointer. */
int line; /**< Current line. */
char *start_line; /**< Where current line starts. */
int skip_ws; /**< Skip whitespace flag. */
pj_syn_err_func_ptr callback; /**< Syntax error callback. */
} pj_scanner;
@ -210,8 +209,8 @@ typedef struct pj_scanner
typedef struct pj_scan_state
{
char *curptr; /**< Current scanner's pointer. */
int line; /**< Current line. */
char *start_line; /**< Start of current line. */
int line; /**< Current line. */
char *start_line; /**< Start of current line. */
} pj_scan_state;
@ -223,16 +222,16 @@ typedef struct pj_scan_state
* @param scanner The scanner to be initialized.
* @param bufstart The input buffer to scan, which must be NULL terminated.
* @param buflen The length of the input buffer, which normally is
* strlen(bufstart), hence not counting the NULL terminator.
* strlen(bufstart), hence not counting the NULL terminator.
* @param options Zero, or combination of PJ_SCAN_AUTOSKIP_WS or
* PJ_SCAN_AUTOSKIP_WS_HEADER
* PJ_SCAN_AUTOSKIP_WS_HEADER
* @param callback Callback to be called when the scanner encounters syntax
* error condition.
* error condition.
*/
PJ_DECL(void) pj_scan_init( pj_scanner *scanner, char *bufstart,
pj_size_t buflen,
unsigned options,
pj_syn_err_func_ptr callback );
pj_size_t buflen,
unsigned options,
pj_syn_err_func_ptr callback );
/**
@ -263,14 +262,14 @@ PJ_INLINE(int) pj_scan_is_eof( const pj_scanner *scanner)
* be called thrown.
*
* @param scanner The scanner.
* @param spec The spec to match input string.
* @param out String to store the result.
* @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.
* no more characters.
*/
PJ_DECL(int) pj_scan_peek( pj_scanner *scanner,
const pj_cis_t *spec, pj_str_t *out);
const pj_cis_t *spec, pj_str_t *out);
/**
@ -280,14 +279,14 @@ PJ_DECL(int) pj_scan_peek( pj_scanner *scanner,
* syntax error callback will be called.
*
* @param scanner The scanner.
* @param len Length to peek.
* @param out String to store the result.
* @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.
* no more characters.
*/
PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner,
pj_size_t len, pj_str_t *out);
pj_size_t len, pj_str_t *out);
/**
@ -297,14 +296,14 @@ PJ_DECL(int) pj_scan_peek_n( pj_scanner *scanner,
* 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.
* @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);
const pj_cis_t *spec,
pj_str_t *out);
/**
@ -315,11 +314,11 @@ PJ_DECL(int) pj_scan_peek_until( pj_scanner *scanner,
* an exception will be thrown.
*
* @param scanner The scanner.
* @param spec The spec to match input string.
* @param out String to store the result.
* @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);
const pj_cis_t *spec, pj_str_t *out);
/**
@ -328,11 +327,11 @@ PJ_DECL(void) pj_scan_get( pj_scanner *scanner,
* specification for '%' characted.
*
* @param scanner The scanner.
* @param spec The spec to match input string.
* @param out String to store the result.
* @param spec The spec to match input string.
* @param out String to store the result.
*/
PJ_DECL(void) pj_scan_get_unescape( pj_scanner *scanner,
const pj_cis_t *spec, pj_str_t *out);
const pj_cis_t *spec, pj_str_t *out);
/**
@ -340,21 +339,21 @@ PJ_DECL(void) pj_scan_get_unescape( pj_scanner *scanner,
* syntax error will be thrown. Note that the resulting string will contain
* the enclosing quote.
*
* @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.
* @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);
int begin_quote, int end_quote,
pj_str_t *out);
/**
* Get characters between quotes. If current input doesn't match begin_quote,
* syntax error will be thrown. Note that the resulting string will contain
* the enclosing quote.
*
* @param scanner The scanner.
* @param scanner The scanner.
* @param begin_quotes The character array to begin the quotes. For example,
* the two characters " and '.
* @param end_quotes The character array to end the quotes. The position
@ -376,11 +375,11 @@ PJ_DECL(void) pj_scan_get_quotes(pj_scanner *scanner,
* Get N characters from the scanner.
*
* @param scanner The scanner.
* @param N Number of characters to get.
* @param out String to store the result.
* @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);
unsigned N, pj_str_t *out);
/**
@ -398,55 +397,55 @@ PJ_DECL(int) pj_scan_get_char( pj_scanner *scanner );
* 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.
* @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);
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 scanner The scanner.
* @param until_char Get until the input match this character.
* @param out String to store the result.
* @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);
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.
* @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);
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.
* @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);
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.
* @param s The string to compare with.
* @param len Length of the string to compare.
*
* @return zero, <0, or >0 (just like strcmp()).
*/
@ -458,8 +457,8 @@ PJ_DECL(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len);
* string.
*
* @param scanner The scanner.
* @param s The string to compare with.
* @param len Length of the string to compare with.
* @param s The string to compare with.
* @param len Length of the string to compare with.
*
* @return zero, <0, or >0 (just like strcmp()).
*/
@ -474,15 +473,15 @@ PJ_DECL(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len);
* -1.
*
* @param scanner The scanner.
* @param s The string to compare with.
* @param len Length of the string to compare with.
* @param s The string to compare with.
* @param len Length of the string to compare with.
*
* @return zero if equal or -1.
* @return zero if equal or -1.
*
* @see strnicmp_alnum, pj_stricmp_alnum
*/
PJ_DECL(int) pj_scan_stricmp_alnum( pj_scanner *scanner, const char *s,
int len);
int len);
/**
@ -514,10 +513,10 @@ PJ_DECL(void) pj_scan_skip_line( pj_scanner *scanner );
* Save the full scanner state.
*
* @param scanner The scanner.
* @param state Variable to store scanner's state.
* @param state Variable to store scanner's state.
*/
PJ_DECL(void) pj_scan_save_state( const pj_scanner *scanner,
pj_scan_state *state);
pj_scan_state *state);
/**
@ -526,17 +525,17 @@ PJ_DECL(void) pj_scan_save_state( const pj_scanner *scanner,
* it. This will only restore the scanner scanning position.
*
* @param scanner The scanner.
* @param state State of the scanner.
* @param state State of the scanner.
*/
PJ_DECL(void) pj_scan_restore_state( pj_scanner *scanner,
pj_scan_state *state);
pj_scan_state *state);
/**
* Get current column position.
*
* @param scanner The scanner.
*
* @return The column position.
* @return The column position.
*/
PJ_INLINE(int) pj_scan_get_col( const pj_scanner *scanner )
{

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -94,4 +93,4 @@ typedef struct pj_cis_t
PJ_END_DECL
#endif /* __PJLIB_UTIL_SCANNER_CIS_BIT_H__ */
#endif /* __PJLIB_UTIL_SCANNER_CIS_BIT_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -46,7 +45,7 @@ typedef int pj_cis_buf_t;
*/
typedef struct pj_cis_t
{
PJ_CIS_ELEM_TYPE cis_buf[256]; /**< Internal buffer. */
PJ_CIS_ELEM_TYPE cis_buf[256]; /**< Internal buffer. */
} pj_cis_t;
@ -81,4 +80,4 @@ typedef struct pj_cis_t
PJ_END_DECL
#endif /* __PJLIB_UTIL_SCANNER_CIS_BIT_H__ */
#endif /* __PJLIB_UTIL_SCANNER_CIS_BIT_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -38,35 +37,35 @@ PJ_BEGIN_DECL
/** SHA1 context */
typedef struct pj_sha1_context
{
pj_uint32_t state[5]; /**< State */
pj_uint32_t count[2]; /**< Count */
pj_uint8_t buffer[64]; /**< Buffer */
pj_uint32_t state[5]; /**< State */
pj_uint32_t count[2]; /**< Count */
pj_uint8_t buffer[64]; /**< Buffer */
} pj_sha1_context;
/** SHA1 digest size is 20 bytes */
#define PJ_SHA1_DIGEST_SIZE 20
#define PJ_SHA1_DIGEST_SIZE 20
/** Initialize the algorithm.
* @param ctx SHA1 context.
* @param ctx SHA1 context.
*/
PJ_DECL(void) pj_sha1_init(pj_sha1_context *ctx);
/** Append a stream to the message.
* @param ctx SHA1 context.
* @param data Data.
* @param nbytes Length of data.
* @param ctx SHA1 context.
* @param data Data.
* @param nbytes Length of data.
*/
PJ_DECL(void) pj_sha1_update(pj_sha1_context *ctx,
const pj_uint8_t *data,
const pj_size_t nbytes);
const pj_uint8_t *data,
const pj_size_t nbytes);
/** Finish the message and return the digest.
* @param ctx SHA1 context.
* @param digest 16 byte digest.
* @param ctx SHA1 context.
* @param digest 16 byte digest.
*/
PJ_DECL(void) pj_sha1_final(pj_sha1_context *ctx,
pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE]);
pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE]);
/**
@ -76,5 +75,5 @@ PJ_DECL(void) pj_sha1_final(pj_sha1_context *ctx,
PJ_END_DECL
#endif /* __PJLIB_UTIL_SHA1_H__ */
#endif /* __PJLIB_UTIL_SHA1_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -72,7 +71,7 @@ PJ_BEGIN_DECL
*
* Reference:
* - <A HREF="http://www.ietf.org/rfc/rfc2782.txt">RFC 2782</A>:
* A DNS RR for specifying the location of services (DNS SRV)
* A DNS RR for specifying the location of services (DNS SRV)
*/
/**
@ -87,7 +86,7 @@ typedef enum pj_dns_srv_option
* make the resolver fallback to both DNS A and DNS AAAA
* resolutions if SRV resolution fails.
*/
PJ_DNS_SRV_FALLBACK_A = 1,
PJ_DNS_SRV_FALLBACK_A = 1,
/**
* Specify if the resolver should fallback with DNS AAAA
@ -96,7 +95,7 @@ typedef enum pj_dns_srv_option
* make the resolver fallback to both DNS A and DNS AAAA
* resolutions if SRV resolution fails.
*/
PJ_DNS_SRV_FALLBACK_AAAA = 2,
PJ_DNS_SRV_FALLBACK_AAAA = 2,
/**
* Specify if the resolver should try to resolve with DNS AAAA
@ -104,7 +103,7 @@ typedef enum pj_dns_srv_option
* option is not specified, the SRV resolver will query the
* DNS A record for the target instead.
*/
PJ_DNS_SRV_RESOLVE_AAAA = 4,
PJ_DNS_SRV_RESOLVE_AAAA = 4,
/**
* Specify if the resolver should try to resolve with DNS AAAA
@ -123,22 +122,22 @@ typedef enum pj_dns_srv_option
typedef struct pj_dns_srv_record
{
/** Number of address records. */
unsigned count;
unsigned count;
/** Address records. */
struct
{
/** Server priority (the lower the higher the priority). */
unsigned priority;
/** Server priority (the lower the higher the priority). */
unsigned priority;
/** Server weight (the higher the more load it can handle). */
unsigned weight;
/** Server weight (the higher the more load it can handle). */
unsigned weight;
/** Port number. */
pj_uint16_t port;
/** Port number. */
pj_uint16_t port;
/** The host address. */
pj_dns_addr_record server;
/** The host address. */
pj_dns_addr_record server;
} entry[PJ_DNS_SRV_MAX_ADDR];
@ -153,62 +152,62 @@ typedef struct pj_dns_srv_async_query pj_dns_srv_async_query;
* when the resolution process completes.
*/
typedef void pj_dns_srv_resolver_cb(void *user_data,
pj_status_t status,
const pj_dns_srv_record *rec);
pj_status_t status,
const pj_dns_srv_record *rec);
/**
* Start DNS SRV resolution for the specified name. The full name of the
* entry will be concatenated from \a res_name and \a domain_name fragments.
*
* @param domain_name The domain name part of the name.
* @param res_name The full service name, including the transport name
* and with all the leading underscore characters and
* ending dot (e.g. "_sip._udp.", "_stun._udp.").
* @param def_port The port number to be assigned to the resolved address
* when the DNS SRV resolution fails and the name is
* resolved with DNS A resolution.
* @param pool Memory pool used to allocate memory for the query.
* @param resolver The resolver instance.
* @param option Option flags, which can be constructed from
* #pj_dns_srv_option bitmask. Note that this argument
* was called "fallback_a" in pjsip version 0.8.0 and
* older, but the new option should be backward
* compatible with existing applications. If application
* specifies PJ_TRUE as "fallback_a" value, it will
* correspond to PJ_DNS_SRV_FALLBACK_A option.
* @param token Arbitrary data to be associated with this query when
* the calback is called.
* @param cb Pointer to callback function to receive the
* notification when the resolution process completes.
* @param p_query Optional pointer to receive the query object, if one
* was started. If this pointer is specified, a NULL may
* be returned if response cache is available immediately.
* @param domain_name The domain name part of the name.
* @param res_name The full service name, including the transport name
* and with all the leading underscore characters and
* ending dot (e.g. "_sip._udp.", "_stun._udp.").
* @param def_port The port number to be assigned to the resolved address
* when the DNS SRV resolution fails and the name is
* resolved with DNS A resolution.
* @param pool Memory pool used to allocate memory for the query.
* @param resolver The resolver instance.
* @param option Option flags, which can be constructed from
* #pj_dns_srv_option bitmask. Note that this argument
* was called "fallback_a" in pjsip version 0.8.0 and
* older, but the new option should be backward
* compatible with existing applications. If application
* specifies PJ_TRUE as "fallback_a" value, it will
* correspond to PJ_DNS_SRV_FALLBACK_A option.
* @param token Arbitrary data to be associated with this query when
* the calback is called.
* @param cb Pointer to callback function to receive the
* notification when the resolution process completes.
* @param p_query Optional pointer to receive the query object, if one
* was started. If this pointer is specified, a NULL may
* be returned if response cache is available immediately.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_dns_srv_resolve(const pj_str_t *domain_name,
const pj_str_t *res_name,
unsigned def_port,
pj_pool_t *pool,
pj_dns_resolver *resolver,
unsigned option,
void *token,
pj_dns_srv_resolver_cb *cb,
pj_dns_srv_async_query **p_query);
const pj_str_t *res_name,
unsigned def_port,
pj_pool_t *pool,
pj_dns_resolver *resolver,
unsigned option,
void *token,
pj_dns_srv_resolver_cb *cb,
pj_dns_srv_async_query **p_query);
/**
* Cancel an outstanding DNS SRV query.
*
* @param query The pending asynchronous query to be cancelled.
* @param query The pending asynchronous query to be cancelled.
* @param notify If non-zero, the callback will be called with failure
* status to notify that the query has been cancelled.
* status to notify that the query has been cancelled.
*
* @return PJ_SUCCESS on success, or the appropriate error code,
* @return PJ_SUCCESS on success, or the appropriate error code,
*/
PJ_DECL(pj_status_t) pj_dns_srv_cancel_query(pj_dns_srv_async_query *query,
pj_bool_t notify);
pj_bool_t notify);
/**
@ -218,5 +217,5 @@ PJ_DECL(pj_status_t) pj_dns_srv_cancel_query(pj_dns_srv_async_query *query,
PJ_END_DECL
#endif /* __PJLIB_UTIL_SRV_RESOLVER_H__ */
#endif /* __PJLIB_UTIL_SRV_RESOLVER_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -41,20 +40,20 @@ PJ_BEGIN_DECL
* 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.
* @param pool Pool to allocate the string.
* @param src Source string to unescape.
*
* @return String with no escaped characters.
* @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.
* @param dst Target string.
* @param src Source string.
*
* @return Target string.
* @return Target string.
*/
PJ_DECL(pj_str_t*) pj_strcpy_unescape(pj_str_t *dst, const pj_str_t *src);
@ -62,35 +61,35 @@ 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.
* @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.
* @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);
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.
* @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.
* @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_ssize_t max, const pj_cis_t *unres);
PJ_END_DECL
@ -99,4 +98,4 @@ PJ_END_DECL
* @}
*/
#endif /* __PJLIB_UTIL_STRING_H__ */
#endif /* __PJLIB_UTIL_STRING_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -36,11 +35,11 @@ PJ_BEGIN_DECL
*/
typedef enum pjstun_msg_type
{
PJSTUN_BINDING_REQUEST = 0x0001, /**< Binding request */
PJSTUN_BINDING_RESPONSE = 0x0101, /**< Binding response */
PJSTUN_BINDING_ERROR_RESPONSE = 0x0111, /**< Binding error */
PJSTUN_SHARED_SECRET_REQUEST = 0x0002, /**< Secret request */
PJSTUN_SHARED_SECRET_RESPONSE = 0x0102, /**< Secret response */
PJSTUN_BINDING_REQUEST = 0x0001, /**< Binding request */
PJSTUN_BINDING_RESPONSE = 0x0101, /**< Binding response */
PJSTUN_BINDING_ERROR_RESPONSE = 0x0111, /**< Binding error */
PJSTUN_SHARED_SECRET_REQUEST = 0x0002, /**< Secret request */
PJSTUN_SHARED_SECRET_RESPONSE = 0x0102, /**< Secret response */
PJSTUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112 /**< Secret error */
} pjstun_msg_type;
@ -70,9 +69,9 @@ typedef enum pjstun_attr_type
*/
typedef struct pjstun_msg_hdr
{
pj_uint16_t type;
pj_uint16_t length;
pj_uint32_t tsx[4];
pj_uint16_t type;
pj_uint16_t length;
pj_uint32_t tsx[4];
} pjstun_msg_hdr;
@ -81,8 +80,8 @@ typedef struct pjstun_msg_hdr
*/
typedef struct pjstun_attr_hdr
{
pj_uint16_t type;
pj_uint16_t length;
pj_uint16_t type;
pj_uint16_t length;
} pjstun_attr_hdr;
@ -91,11 +90,11 @@ typedef struct pjstun_attr_hdr
*/
typedef struct pjstun_mapped_addr_attr
{
pjstun_attr_hdr hdr;
pj_uint8_t ignored;
pj_uint8_t family;
pj_uint16_t port;
pj_uint32_t addr;
pjstun_attr_hdr hdr;
pj_uint8_t ignored;
pj_uint8_t family;
pj_uint16_t port;
pj_uint32_t addr;
} pjstun_mapped_addr_attr;
typedef pjstun_mapped_addr_attr pjstun_response_addr_attr;
@ -105,42 +104,42 @@ typedef pjstun_mapped_addr_attr pjstun_reflected_form_attr;
typedef struct pjstun_change_request_attr
{
pjstun_attr_hdr hdr;
pj_uint32_t value;
pjstun_attr_hdr hdr;
pj_uint32_t value;
} pjstun_change_request_attr;
typedef struct pjstun_username_attr
{
pjstun_attr_hdr hdr;
pj_uint32_t value[1];
pjstun_attr_hdr hdr;
pj_uint32_t value[1];
} pjstun_username_attr;
typedef pjstun_username_attr pjstun_password_attr;
typedef struct pjstun_error_code_attr
{
pjstun_attr_hdr hdr;
pj_uint16_t ignored;
pj_uint8_t err_class;
pj_uint8_t number;
char reason[4];
pjstun_attr_hdr hdr;
pj_uint16_t ignored;
pj_uint8_t err_class;
pj_uint8_t number;
char reason[4];
} pjstun_error_code_attr;
typedef struct pjstun_msg
{
pjstun_msg_hdr *hdr;
int attr_count;
int attr_count;
pjstun_attr_hdr *attr[PJSTUN_MAX_ATTR];
} pjstun_msg;
/* STUN message API (stun.c). */
PJ_DECL(pj_status_t) pjstun_create_bind_req( pj_pool_t *pool,
void **msg, pj_size_t *len,
pj_uint32_t id_hi,
pj_uint32_t id_lo);
void **msg, pj_size_t *len,
pj_uint32_t id_hi,
pj_uint32_t id_lo);
PJ_DECL(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t len,
pjstun_msg *msg);
pjstun_msg *msg);
PJ_DECL(void*) pjstun_msg_find_attr( pjstun_msg *msg, pjstun_attr_type t);
@ -170,34 +169,34 @@ PJ_DECL(void*) pjstun_msg_find_attr( pjstun_msg *msg, pjstun_attr_type t);
* by the servers, and when both are equal, the address will be returned in
* \a mapped_addr argument.
*
* @param pf The pool factory where memory will be allocated from.
* @param sock_cnt Number of sockets in the socket array.
* @param sock Array of local UDP sockets which public addresses are
* to be queried from the STUN servers.
* @param srv1 Host name or IP address string of the first STUN
* server.
* @param port1 The port number of the first STUN server.
* @param srv2 Host name or IP address string of the second STUN
* server.
* @param port2 The port number of the second STUN server.
* @param mapped_addr Array to receive the mapped public address of the local
* UDP sockets, when the function returns PJ_SUCCESS.
* @param pf The pool factory where memory will be allocated from.
* @param sock_cnt Number of sockets in the socket array.
* @param sock Array of local UDP sockets which public addresses are
* to be queried from the STUN servers.
* @param srv1 Host name or IP address string of the first STUN
* server.
* @param port1 The port number of the first STUN server.
* @param srv2 Host name or IP address string of the second STUN
* server.
* @param port2 The port number of the second STUN server.
* @param mapped_addr Array to receive the mapped public address of the local
* UDP sockets, when the function returns PJ_SUCCESS.
*
* @return This functions returns PJ_SUCCESS if responses are
* received from all servers AND all servers returned the
* same mapped public address. Otherwise this function may
* return one of the following error codes:
* - PJLIB_UTIL_ESTUNNOTRESPOND: no respons from servers.
* - PJLIB_UTIL_ESTUNSYMMETRIC: different mapped addresses
* are returned by servers.
* - etc.
* @return This functions returns PJ_SUCCESS if responses are
* received from all servers AND all servers returned the
* same mapped public address. Otherwise this function may
* return one of the following error codes:
* - PJLIB_UTIL_ESTUNNOTRESPOND: no respons from servers.
* - PJLIB_UTIL_ESTUNSYMMETRIC: different mapped addresses
* are returned by servers.
* - etc.
*
*/
PJ_DECL(pj_status_t) pjstun_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[]);
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[]);
/*
@ -209,7 +208,7 @@ typedef struct pjstun_setting
* Specifies whether STUN request generated by old STUN library should
* insert magic cookie (specified in RFC 5389) in the transaction ID.
*/
pj_bool_t use_stun2;
pj_bool_t use_stun2;
/**
* Address family of the STUN servers.
@ -254,29 +253,29 @@ typedef struct pjstun_setting
* by the servers, and when both are equal, the address will be returned in
* \a mapped_addr argument.
*
* @param pf The pool factory where memory will be allocated from.
* @param opt The STUN settings.
* @param sock_cnt Number of sockets in the socket array.
* @param sock Array of local UDP sockets which public addresses are
* to be queried from the STUN servers.
* @param mapped_addr Array to receive the mapped public address of the local
* UDP sockets, when the function returns PJ_SUCCESS.
* @param pf The pool factory where memory will be allocated from.
* @param opt The STUN settings.
* @param sock_cnt Number of sockets in the socket array.
* @param sock Array of local UDP sockets which public addresses are
* to be queried from the STUN servers.
* @param mapped_addr Array to receive the mapped public address of the local
* UDP sockets, when the function returns PJ_SUCCESS.
*
* @return This functions returns PJ_SUCCESS if responses are
* received from all servers AND all servers returned the
* same mapped public address. Otherwise this function may
* return one of the following error codes:
* - PJLIB_UTIL_ESTUNNOTRESPOND: no respons from servers.
* - PJLIB_UTIL_ESTUNSYMMETRIC: different mapped addresses
* are returned by servers.
* - etc.
* @return This functions returns PJ_SUCCESS if responses are
* received from all servers AND all servers returned the
* same mapped public address. Otherwise this function may
* return one of the following error codes:
* - PJLIB_UTIL_ESTUNNOTRESPOND: no respons from servers.
* - PJLIB_UTIL_ESTUNSYMMETRIC: different mapped addresses
* are returned by servers.
* - etc.
*
*/
PJ_DECL(pj_status_t) pjstun_get_mapped_addr2( pj_pool_factory *pf,
const pjstun_setting *opt,
int sock_cnt,
pj_sock_t sock[],
pj_sockaddr_in mapped_addr[]);
const pjstun_setting *opt,
int sock_cnt,
pj_sock_t sock[],
pj_sockaddr_in mapped_addr[]);
PJ_END_DECL
@ -285,5 +284,5 @@ PJ_END_DECL
* @}
*/
#endif /* __PJSTUN_H__ */
#endif /* __PJSTUN_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -91,5 +90,5 @@ PJ_END_DECL
* \n
*/
#endif /* __PJLIB_UTIL_TYPES_H__ */
#endif /* __PJLIB_UTIL_TYPES_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -46,8 +45,8 @@ typedef struct pj_xml_node pj_xml_node;
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. */
pj_str_t name; /**< Attribute name. */
pj_str_t value; /**< Attribute value. */
};
/** This structure describes XML node head inside XML node structure.
@ -61,10 +60,10 @@ typedef struct pj_xml_node_head
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. */
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. */
};
/**
@ -76,11 +75,11 @@ struct pj_xml_node
* Note that the XML message input buffer MUST be NULL terminated and have
* length at least len+1 (len MUST NOT include the NULL terminator).
*
* @param pool Pool to allocate memory from.
* @param msg The XML message to parse, MUST be NULL terminated.
* @param len The length of the message, not including NULL terminator.
* @param pool Pool to allocate memory from.
* @param msg The XML message to parse, MUST be NULL terminated.
* @param len The length of the message, not including NULL terminator.
*
* @return XML root node, or NULL if the XML document can not be parsed.
* @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);
@ -89,24 +88,24 @@ 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 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.
* @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 prolog);
pj_bool_t prolog);
/**
* Clone XML node and all subnodes.
*
* @param pool Pool to allocate memory for new nodes.
* @param rhs The node to clone.
* @param pool Pool to allocate memory for new nodes.
* @param rhs The node to clone.
*
* @return Cloned XML node, or NULL on fail.
* @return Cloned XML node, or NULL on fail.
*/
PJ_DECL(pj_xml_node*) pj_xml_clone( pj_pool_t *pool, const pj_xml_node *rhs);
@ -114,10 +113,10 @@ PJ_DECL(pj_xml_node*) pj_xml_clone( pj_pool_t *pool, const pj_xml_node *rhs);
/**
* Create an empty node.
*
* @param pool Pool.
* @param name Node name.
* @param pool Pool.
* @param name Node name.
*
* @return The new node.
* @return The new node.
*/
PJ_DECL(pj_xml_node*) pj_xml_node_new(pj_pool_t *pool, const pj_str_t *name);
@ -125,20 +124,20 @@ PJ_DECL(pj_xml_node*) pj_xml_node_new(pj_pool_t *pool, const pj_str_t *name);
/**
* Create new XML attribute.
*
* @param pool Pool.
* @param name Attribute name.
* @param value Attribute value.
* @param pool Pool.
* @param name Attribute name.
* @param value Attribute value.
*
* @return The new XML attribute.
* @return The new XML attribute.
*/
PJ_DECL(pj_xml_attr*) pj_xml_attr_new(pj_pool_t *pool, const pj_str_t *name,
const pj_str_t *value);
const pj_str_t *value);
/**
* Add node to another node.
*
* @param parent Parent node.
* @param node Node to be added to parent.
* @param node Node to be added to parent.
*/
PJ_DECL(void) pj_xml_add_node( pj_xml_node *parent, pj_xml_node *node );
@ -146,8 +145,8 @@ 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.
* @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 );
@ -155,70 +154,70 @@ PJ_DECL(void) pj_xml_add_attr( pj_xml_node *node, pj_xml_attr *attr );
* Find first direct child node with the specified name.
*
* @param parent Parent node.
* @param name Node name to find.
* @param name Node name to find.
*
* @return XML node found or NULL.
* @return XML node found or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find_node(const pj_xml_node *parent,
const pj_str_t *name);
const pj_str_t *name);
/**
* Find next direct child node with the specified name.
*
* @param parent Parent node.
* @param node node->next is the starting point.
* @param name Node name to find.
* @param node node->next is the starting point.
* @param name Node name to find.
*
* @return XML node found or NULL.
* @return XML node found or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find_next_node(const pj_xml_node *parent,
const pj_xml_node *node,
const pj_str_t *name);
const pj_xml_node *node,
const pj_str_t *name);
/**
* Recursively find the first node with the specified name in the child nodes
* and their children.
*
* @param parent Parent node.
* @param name Node name to find.
* @param name Node name to find.
*
* @return XML node found or NULL.
* @return XML node found or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find_node_rec(const pj_xml_node *parent,
const pj_str_t *name);
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.
* @param node XML Node.
* @param name Attribute name to find.
* @param value Optional value to match.
*
* @return XML attribute found, or NULL.
* @return XML attribute found, or NULL.
*/
PJ_DECL(pj_xml_attr*) pj_xml_find_attr(const pj_xml_node *node,
const pj_str_t *name,
const pj_str_t *value);
const pj_str_t *name,
const pj_str_t *value);
/**
* Find a direct child node with the specified name and match the function.
*
* @param parent Parent node.
* @param name Optional name. If this is NULL, the name will not be
* matched.
* @param data Data to be passed to matching function.
* @param match Optional matching function.
* @param name Optional name. If this is NULL, the name will not be
* matched.
* @param data Data to be passed to matching function.
* @param match Optional matching function.
*
* @return The first matched node, or NULL.
* @return The first matched node, or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find( const pj_xml_node *parent,
const pj_str_t *name,
const void *data,
pj_bool_t (*match)(const pj_xml_node *,
const void*));
const pj_str_t *name,
const void *data,
pj_bool_t (*match)(const pj_xml_node *,
const void*));
/**
@ -226,18 +225,18 @@ PJ_DECL(pj_xml_node*) pj_xml_find( const pj_xml_node *parent,
* function.
*
* @param parent Parent node.
* @param name Optional name. If this is NULL, the name will not be
* matched.
* @param data Data to be passed to matching function.
* @param match Optional matching function.
* @param name Optional name. If this is NULL, the name will not be
* matched.
* @param data Data to be passed to matching function.
* @param match Optional matching function.
*
* @return The first matched node, or NULL.
* @return The first matched node, or NULL.
*/
PJ_DECL(pj_xml_node*) pj_xml_find_rec(const pj_xml_node *parent,
const pj_str_t *name,
const void *data,
pj_bool_t (*match)(const pj_xml_node*,
const void*));
const pj_str_t *name,
const void *data,
pj_bool_t (*match)(const pj_xml_node*,
const void*));
/**
@ -246,4 +245,4 @@ PJ_DECL(pj_xml_node*) pj_xml_find_rec(const pj_xml_node *parent,
PJ_END_DECL
#endif /* __PJ_XML_H__ */
#endif /* __PJ_XML_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -46,7 +45,7 @@ static char *sha1_test_results[] = {
static void digest_to_hex(const pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE],
char *output)
char *output)
{
int i,j;
char *c = output;
@ -77,12 +76,12 @@ static int sha1_test1(void)
for (k = 0; k < 2; k++){
pj_sha1_init(&context);
pj_sha1_update(&context, (pj_uint8_t*)sha1_test_data[k],
pj_ansi_strlen(sha1_test_data[k]));
pj_ansi_strlen(sha1_test_data[k]));
pj_sha1_final(&context, digest);
digest_to_hex(digest, output);
digest_to_hex(digest, output);
if (pj_ansi_strcmp(output, sha1_test_results[k])) {
PJ_LOG(3, (THIS_FILE, " incorrect hash result on k=%d", k));
PJ_LOG(3, (THIS_FILE, " incorrect hash result on k=%d", k));
return -10;
}
}
@ -94,7 +93,7 @@ static int sha1_test1(void)
pj_sha1_final(&context, digest);
digest_to_hex(digest, output);
if (strcmp(output, sha1_test_results[2])) {
PJ_LOG(3, (THIS_FILE, " incorrect hash result!"));
PJ_LOG(3, (THIS_FILE, " incorrect hash result!"));
return -20;
}
@ -108,18 +107,18 @@ static int sha1_test1(void)
pj_sha1_final(&context, digest);
digest_to_hex(digest, output);
if (strcmp(output, sha1_test_results[2])) {
pj_pool_release(pool);
PJ_LOG(3, (THIS_FILE, " incorrect hash result for block update!"));
pj_pool_release(pool);
PJ_LOG(3, (THIS_FILE, " incorrect hash result for block update!"));
return -21;
}
/* verify that original buffer was not modified */
for (k=0; k<MILLION; ++k) {
if (block[k] != 'a') {
pj_pool_release(pool);
PJ_LOG(3, (THIS_FILE, " block was modified!"));
return -22;
}
if (block[k] != 'a') {
pj_pool_release(pool);
PJ_LOG(3, (THIS_FILE, " block was modified!"));
return -22;
}
}
pj_pool_release(pool);
@ -171,23 +170,23 @@ static int sha1_test2(void)
PJ_LOG(3, (THIS_FILE, " SHA1 test vector 2 from rfc 3174.."));
for(i = 0; i < 4; ++i) {
int j;
int j;
pj_sha1_init(&sha);
for(j = 0; j < repeatcount[i]; ++j) {
pj_sha1_update(&sha,
(const pj_uint8_t *) testarray[i],
pj_ansi_strlen(testarray[i]));
(const pj_uint8_t *) testarray[i],
pj_ansi_strlen(testarray[i]));
}
pj_sha1_final(&sha, digest);
digest_to_hex(digest, char_digest);
if (pj_ansi_strcmp(char_digest, resultarray[i])) {
PJ_LOG(3, (THIS_FILE, " digest mismatch in test %d", i));
return -40;
}
digest_to_hex(digest, char_digest);
if (pj_ansi_strcmp(char_digest, resultarray[i])) {
PJ_LOG(3, (THIS_FILE, " digest mismatch in test %d", i));
return -40;
}
}
return 0;
@ -200,9 +199,9 @@ static int sha1_test2(void)
struct rfc2202_test
{
char *key;
unsigned key_len;
unsigned key_len;
char *input;
unsigned input_len;
unsigned input_len;
char *md5_digest;
char *sha1_digest;
};
@ -211,115 +210,115 @@ struct rfc2202_test
struct rfc2202_test rfc2202_test_vector[] =
{
{
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
16,
"Hi There",
8,
"\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d",
NULL
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
16,
"Hi There",
8,
"\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d",
NULL
},
{
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
20,
"Hi There",
8,
NULL,
"\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
20,
"Hi There",
8,
NULL,
"\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00"
},
{
"Jefe",
4,
"what do ya want for nothing?",
28,
"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",
"\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"
"Jefe",
4,
"what do ya want for nothing?",
28,
"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",
"\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79"
},
{
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa",
16,
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
50,
"\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6",
NULL
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa",
16,
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
50,
"\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6",
NULL
},
{
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
20,
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
50,
NULL,
"\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
20,
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
50,
NULL,
"\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3"
},
{
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
25,
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
50,
"\x69\x7e\xaf\x0a\xca\x3a\x3a\xea\x3a\x75\x16\x47\x46\xff\xaa\x79",
"\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
25,
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
50,
"\x69\x7e\xaf\x0a\xca\x3a\x3a\xea\x3a\x75\x16\x47\x46\xff\xaa\x79",
"\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda"
},
{
"\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
"\x0c\x0c\x0c\x0c\x0c\x0c",
16,
"Test With Truncation",
20,
"\x56\x46\x1e\xf2\x34\x2e\xdc\x00\xf9\xba\xb9\x95\x69\x0e\xfd\x4c",
NULL
"\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
"\x0c\x0c\x0c\x0c\x0c\x0c",
16,
"Test With Truncation",
20,
"\x56\x46\x1e\xf2\x34\x2e\xdc\x00\xf9\xba\xb9\x95\x69\x0e\xfd\x4c",
NULL
},
{
"\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
"\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
20,
"Test With Truncation",
20,
NULL,
"\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"
"\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
"\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
20,
"Test With Truncation",
20,
NULL,
"\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04"
},
{
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
80,
"Test Using Larger Than Block-Size Key - Hash Key First",
54,
"\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0\xcd",
"\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
80,
"Test Using Larger Than Block-Size Key - Hash Key First",
54,
"\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0\xcd",
"\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12"
},
{
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
80,
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
73,
"\x6f\x63\x0f\xad\x67\xcd\xa0\xee\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e",
"\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
80,
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
73,
"\x6f\x63\x0f\xad\x67\xcd\xa0\xee\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e",
"\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91"
}
};
@ -332,80 +331,80 @@ static int rfc2202_test(void)
/* Verify that test vectors are valid */
for (i=0; i<PJ_ARRAY_SIZE(rfc2202_test_vector); ++i) {
PJ_ASSERT_RETURN(pj_ansi_strlen(rfc2202_test_vector[i].input) ==
rfc2202_test_vector[i].input_len, -50);
PJ_ASSERT_RETURN(pj_ansi_strlen(rfc2202_test_vector[i].key) ==
rfc2202_test_vector[i].key_len, -52);
PJ_ASSERT_RETURN(rfc2202_test_vector[i].md5_digest==NULL ||
pj_ansi_strlen(rfc2202_test_vector[i].md5_digest)<=16,
-54);
PJ_ASSERT_RETURN(rfc2202_test_vector[i].sha1_digest==NULL ||
pj_ansi_strlen(rfc2202_test_vector[i].sha1_digest)<=20,
-56);
PJ_ASSERT_RETURN(pj_ansi_strlen(rfc2202_test_vector[i].input) ==
rfc2202_test_vector[i].input_len, -50);
PJ_ASSERT_RETURN(pj_ansi_strlen(rfc2202_test_vector[i].key) ==
rfc2202_test_vector[i].key_len, -52);
PJ_ASSERT_RETURN(rfc2202_test_vector[i].md5_digest==NULL ||
pj_ansi_strlen(rfc2202_test_vector[i].md5_digest)<=16,
-54);
PJ_ASSERT_RETURN(rfc2202_test_vector[i].sha1_digest==NULL ||
pj_ansi_strlen(rfc2202_test_vector[i].sha1_digest)<=20,
-56);
}
/* Test HMAC-MD5 */
PJ_LOG(3, (THIS_FILE, " HMAC-MD5 test vectors from rfc 2202.."));
for (i=0; i<PJ_ARRAY_SIZE(rfc2202_test_vector); ++i) {
pj_uint8_t digest_buf[18], *digest;
pj_uint8_t digest_buf[18], *digest;
if (rfc2202_test_vector[i].md5_digest == NULL)
continue;
if (rfc2202_test_vector[i].md5_digest == NULL)
continue;
digest_buf[0] = '\0';
digest_buf[17] = '\0';
digest_buf[0] = '\0';
digest_buf[17] = '\0';
digest = digest_buf+1;
digest = digest_buf+1;
pj_hmac_md5((pj_uint8_t*)rfc2202_test_vector[i].input,
rfc2202_test_vector[i].input_len,
(pj_uint8_t*)rfc2202_test_vector[i].key,
rfc2202_test_vector[i].key_len,
digest);
pj_hmac_md5((pj_uint8_t*)rfc2202_test_vector[i].input,
rfc2202_test_vector[i].input_len,
(pj_uint8_t*)rfc2202_test_vector[i].key,
rfc2202_test_vector[i].key_len,
digest);
/* Check for overwrites */
if (digest_buf[0] != '\0' || digest_buf[17] != '\0') {
PJ_LOG(3, (THIS_FILE, " error: overwriting outside buffer on test %d", i));
return -60;
}
/* Check for overwrites */
if (digest_buf[0] != '\0' || digest_buf[17] != '\0') {
PJ_LOG(3, (THIS_FILE, " error: overwriting outside buffer on test %d", i));
return -60;
}
/* Compare digest */
if (pj_memcmp(rfc2202_test_vector[i].md5_digest, digest, 16)) {
PJ_LOG(3, (THIS_FILE, " error: digest mismatch on test %d", i));
return -65;
}
/* Compare digest */
if (pj_memcmp(rfc2202_test_vector[i].md5_digest, digest, 16)) {
PJ_LOG(3, (THIS_FILE, " error: digest mismatch on test %d", i));
return -65;
}
}
/* Test HMAC-SHA1 */
PJ_LOG(3, (THIS_FILE, " HMAC-SHA1 test vectors from rfc 2202.."));
for (i=0; i<PJ_ARRAY_SIZE(rfc2202_test_vector); ++i) {
pj_uint8_t digest_buf[22], *digest;
pj_uint8_t digest_buf[22], *digest;
if (rfc2202_test_vector[i].sha1_digest == NULL)
continue;
if (rfc2202_test_vector[i].sha1_digest == NULL)
continue;
digest_buf[0] = '\0';
digest_buf[21] = '\0';
digest_buf[0] = '\0';
digest_buf[21] = '\0';
digest = digest_buf+1;
digest = digest_buf+1;
pj_hmac_sha1((pj_uint8_t*)rfc2202_test_vector[i].input,
rfc2202_test_vector[i].input_len,
(pj_uint8_t*)rfc2202_test_vector[i].key,
rfc2202_test_vector[i].key_len,
digest);
pj_hmac_sha1((pj_uint8_t*)rfc2202_test_vector[i].input,
rfc2202_test_vector[i].input_len,
(pj_uint8_t*)rfc2202_test_vector[i].key,
rfc2202_test_vector[i].key_len,
digest);
/* Check for overwrites */
if (digest_buf[0] != '\0' || digest_buf[21] != '\0') {
PJ_LOG(3, (THIS_FILE, " error: overwriting outside buffer on test %d", i));
return -70;
}
/* Check for overwrites */
if (digest_buf[0] != '\0' || digest_buf[21] != '\0') {
PJ_LOG(3, (THIS_FILE, " error: overwriting outside buffer on test %d", i));
return -70;
}
/* Compare digest */
if (pj_memcmp(rfc2202_test_vector[i].sha1_digest, digest, 20)) {
PJ_LOG(3, (THIS_FILE, " error: digest mismatch on test %d", i));
return -75;
}
/* Compare digest */
if (pj_memcmp(rfc2202_test_vector[i].sha1_digest, digest, 20)) {
PJ_LOG(3, (THIS_FILE, " error: digest mismatch on test %d", i));
return -75;
}
}
@ -416,30 +415,30 @@ static int rfc2202_test(void)
/* CRC32 test data, generated from crc32 test on a Linux box */
struct crc32_test_t
{
char *input;
pj_uint32_t crc;
char *input;
pj_uint32_t crc;
} crc32_test_data[] =
{
{
"",
0x0
"",
0x0
},
{
"Hello World",
0x4a17b156
"Hello World",
0x4a17b156
},
{
/* Something read from /dev/random */
"\x21\x21\x98\x10\x62\x59\xbc\x58\x42\x24\xe5\xf3\x92\x0a\x68\x3c\xa7\x67\x73\xc3",
0x506693be
/* Something read from /dev/random */
"\x21\x21\x98\x10\x62\x59\xbc\x58\x42\x24\xe5\xf3\x92\x0a\x68\x3c\xa7\x67\x73\xc3",
0x506693be
},
{
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
0xcab11777
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
0xcab11777
},
{
"123456789",
0xCBF43926
"123456789",
0xCBF43926
}
};
@ -454,41 +453,41 @@ static int crc32_test(void)
/* testing pj_crc32_calc */
for (i=0; i<PJ_ARRAY_SIZE(crc32_test_data); ++i) {
pj_uint32_t crc;
pj_uint32_t crc;
crc = pj_crc32_calc((pj_uint8_t*)crc32_test_data[i].input,
pj_ansi_strlen(crc32_test_data[i].input));
if (crc != crc32_test_data[i].crc) {
PJ_LOG(3,(THIS_FILE, " error: crc mismatch on test %d", i));
return -80;
}
crc = pj_crc32_calc((pj_uint8_t*)crc32_test_data[i].input,
pj_ansi_strlen(crc32_test_data[i].input));
if (crc != crc32_test_data[i].crc) {
PJ_LOG(3,(THIS_FILE, " error: crc mismatch on test %d", i));
return -80;
}
}
/* testing incremental CRC32 calculation */
for (i=0; i<PJ_ARRAY_SIZE(crc32_test_data); ++i) {
pj_crc32_context ctx;
pj_uint32_t crc0, crc1;
pj_size_t len;
pj_crc32_context ctx;
pj_uint32_t crc0, crc1;
pj_size_t len;
len = pj_ansi_strlen(crc32_test_data[i].input);
crc0 = pj_crc32_calc((pj_uint8_t*)crc32_test_data[i].input, len);
len = pj_ansi_strlen(crc32_test_data[i].input);
crc0 = pj_crc32_calc((pj_uint8_t*)crc32_test_data[i].input, len);
pj_crc32_init(&ctx);
pj_crc32_update(&ctx, (pj_uint8_t*)crc32_test_data[i].input,
len / 2);
pj_crc32_init(&ctx);
pj_crc32_update(&ctx, (pj_uint8_t*)crc32_test_data[i].input,
len / 2);
if (len/2 > 0) {
pj_crc32_update(&ctx, (pj_uint8_t*)crc32_test_data[i].input + len/2,
len - len/2);
}
if (len/2 > 0) {
pj_crc32_update(&ctx, (pj_uint8_t*)crc32_test_data[i].input + len/2,
len - len/2);
}
crc1 = pj_crc32_final(&ctx);
crc1 = pj_crc32_final(&ctx);
if (crc0 != crc1) {
PJ_LOG(3,(THIS_FILE,
" error: crc algorithm error on test %d", i));
return -85;
}
if (crc0 != crc1) {
PJ_LOG(3,(THIS_FILE,
" error: crc algorithm error on test %d", i));
return -85;
}
}
return 0;
@ -512,65 +511,65 @@ static struct base64_test_vec
} base64_test_vec[] =
{
{
"",
"",
ENCODE_DECODE
"",
"",
ENCODE_DECODE
},
{
"f",
"Zg==",
ENCODE_DECODE
"f",
"Zg==",
ENCODE_DECODE
},
{
"fo",
"Zm8=",
ENCODE_DECODE
"fo",
"Zm8=",
ENCODE_DECODE
},
{
"foo",
"Zm9v",
ENCODE_DECODE
"foo",
"Zm9v",
ENCODE_DECODE
},
{
"foob",
"Zm9vYg==",
ENCODE_DECODE
"foob",
"Zm9vYg==",
ENCODE_DECODE
},
{
"fooba",
"Zm9vYmE=",
ENCODE_DECODE
"fooba",
"Zm9vYmE=",
ENCODE_DECODE
},
{
"foobar",
"Zm9vYmFy",
ENCODE_DECODE
"foobar",
"Zm9vYmFy",
ENCODE_DECODE
},
{
"\x14\xfb\x9c\x03\xd9\x7e",
"FPucA9l+",
ENCODE_DECODE
"\x14\xfb\x9c\x03\xd9\x7e",
"FPucA9l+",
ENCODE_DECODE
},
{
"\x14\xfb\x9c\x03\xd9",
"FPucA9k=",
ENCODE_DECODE
"\x14\xfb\x9c\x03\xd9",
"FPucA9k=",
ENCODE_DECODE
},
{
"\x14\xfb\x9c\x03",
"FPucAw==",
ENCODE_DECODE
"\x14\xfb\x9c\x03",
"FPucAw==",
ENCODE_DECODE
},
/* with whitespaces */
{
"foobar",
"Zm9v\r\nYmFy",
DECODE
"foobar",
"Zm9v\r\nYmFy",
DECODE
},
{
"foobar",
"\nZ\r\nm 9\tv\nYm\nF\ny\n",
DECODE
"foobar",
"\nZ\r\nm 9\tv\nYm\nF\ny\n",
DECODE
},
};
@ -584,43 +583,43 @@ static int base64_test(void)
PJ_LOG(3, (THIS_FILE, " base64 test.."));
for (i=0; i<PJ_ARRAY_SIZE(base64_test_vec); ++i) {
pj_str_t input;
int out_len;
pj_str_t input;
int out_len;
/* Encode test */
if (base64_test_vec[i].flag & ENCODE) {
out_len = sizeof(output);
rc = pj_base64_encode((pj_uint8_t*)base64_test_vec[i].base256,
(int)strlen(base64_test_vec[i].base256),
output, &out_len);
if (rc != PJ_SUCCESS)
return -90;
/* Encode test */
if (base64_test_vec[i].flag & ENCODE) {
out_len = sizeof(output);
rc = pj_base64_encode((pj_uint8_t*)base64_test_vec[i].base256,
(int)strlen(base64_test_vec[i].base256),
output, &out_len);
if (rc != PJ_SUCCESS)
return -90;
if (out_len != (int)strlen(base64_test_vec[i].base64))
return -91;
if (out_len != (int)strlen(base64_test_vec[i].base64))
return -91;
output[out_len] = '\0';
if (strcmp(output, base64_test_vec[i].base64) != 0)
return -92;
}
output[out_len] = '\0';
if (strcmp(output, base64_test_vec[i].base64) != 0)
return -92;
}
/* Decode test */
if (base64_test_vec[i].flag & DECODE) {
out_len = sizeof(output);
input.ptr = (char*)base64_test_vec[i].base64;
input.slen = strlen(base64_test_vec[i].base64);
rc = pj_base64_decode(&input, (pj_uint8_t*)output, &out_len);
if (rc != PJ_SUCCESS)
return -95;
/* Decode test */
if (base64_test_vec[i].flag & DECODE) {
out_len = sizeof(output);
input.ptr = (char*)base64_test_vec[i].base64;
input.slen = strlen(base64_test_vec[i].base64);
rc = pj_base64_decode(&input, (pj_uint8_t*)output, &out_len);
if (rc != PJ_SUCCESS)
return -95;
if (out_len != (int)strlen(base64_test_vec[i].base256))
return -96;
if (out_len != (int)strlen(base64_test_vec[i].base256))
return -96;
output[out_len] = '\0';
output[out_len] = '\0';
if (strcmp(output, base64_test_vec[i].base256) != 0)
return -97;
}
if (strcmp(output, base64_test_vec[i].base256) != 0)
return -97;
}
}
return 0;
@ -633,29 +632,29 @@ int encryption_test()
rc = base64_test();
if (rc != 0)
return rc;
return rc;
rc = sha1_test1();
if (rc != 0)
return rc;
return rc;
rc = sha1_test2();
if (rc != 0)
return rc;
return rc;
rc = rfc2202_test();
if (rc != 0)
return rc;
return rc;
rc = crc32_test();
if (rc != 0)
return rc;
return rc;
return 0;
}
static void crc32_update(pj_crc32_context *c, const pj_uint8_t *data,
pj_size_t nbytes)
pj_size_t nbytes)
{
pj_crc32_update(c, data, nbytes);
}
@ -670,38 +669,38 @@ int encryption_benchmark()
pj_pool_t *pool;
pj_uint8_t *input;
union {
pj_md5_context md5_context;
pj_sha1_context sha1_context;
pj_md5_context md5_context;
pj_sha1_context sha1_context;
} context;
pj_uint8_t digest[32];
pj_size_t input_len;
struct algorithm
{
const char *name;
void (*init_context)(void*);
void (*update)(void*, const pj_uint8_t*, unsigned);
void (*final)(void*, void*);
pj_uint32_t t;
const char *name;
void (*init_context)(void*);
void (*update)(void*, const pj_uint8_t*, unsigned);
void (*final)(void*, void*);
pj_uint32_t t;
} algorithms[] =
{
{
"MD5 ",
(void (*)(void*))&pj_md5_init,
(void (*)(void*, const pj_uint8_t*, unsigned))&pj_md5_update,
(void (*)(void*, void*))&pj_md5_final
},
{
"SHA1 ",
(void (*)(void*))&pj_sha1_init,
(void (*)(void*, const pj_uint8_t*, unsigned))&pj_sha1_update,
(void (*)(void*, void*))&pj_sha1_final
},
{
"CRC32",
(void (*)(void*))&pj_crc32_init,
(void (*)(void*, const pj_uint8_t*, unsigned))&crc32_update,
(void (*)(void*, void*))&crc32_final
}
{
"MD5 ",
(void (*)(void*))&pj_md5_init,
(void (*)(void*, const pj_uint8_t*, unsigned))&pj_md5_update,
(void (*)(void*, void*))&pj_md5_final
},
{
"SHA1 ",
(void (*)(void*))&pj_sha1_init,
(void (*)(void*, const pj_uint8_t*, unsigned))&pj_sha1_update,
(void (*)(void*, void*))&pj_sha1_final
},
{
"CRC32",
(void (*)(void*))&pj_crc32_init,
(void (*)(void*, const pj_uint8_t*, unsigned))&crc32_update,
(void (*)(void*, void*))&crc32_final
}
};
#if defined(PJ_DEBUG) && PJ_DEBUG!=0
enum { LOOP = 1000 };
@ -715,46 +714,46 @@ int encryption_benchmark()
total_len = (unsigned)input_len * LOOP;
pool = pj_pool_create(mem, "enc", input_len+256, 0, NULL);
if (!pool)
return PJ_ENOMEM;
return PJ_ENOMEM;
input = (pj_uint8_t*)pj_pool_alloc(pool, input_len);
pj_memset(input, '\xaa', input_len);
PJ_LOG(3, (THIS_FILE, " feeding %d Mbytes of data",
(unsigned)(total_len/1024/1024)));
(unsigned)(total_len/1024/1024)));
/* Dry run */
for (i=0; i<PJ_ARRAY_SIZE(algorithms); ++i) {
algorithms[i].init_context(&context);
algorithms[i].update(&context, input, (unsigned)input_len);
algorithms[i].final(&context, digest);
algorithms[i].init_context(&context);
algorithms[i].update(&context, input, (unsigned)input_len);
algorithms[i].final(&context, digest);
}
/* Run */
for (i=0; i<PJ_ARRAY_SIZE(algorithms); ++i) {
int j;
pj_timestamp t1, t2;
int j;
pj_timestamp t1, t2;
pj_get_timestamp(&t1);
algorithms[i].init_context(&context);
for (j=0; j<LOOP; ++j) {
algorithms[i].update(&context, input, (unsigned)input_len);
}
algorithms[i].final(&context, digest);
pj_get_timestamp(&t2);
pj_get_timestamp(&t1);
algorithms[i].init_context(&context);
for (j=0; j<LOOP; ++j) {
algorithms[i].update(&context, input, (unsigned)input_len);
}
algorithms[i].final(&context, digest);
pj_get_timestamp(&t2);
algorithms[i].t = pj_elapsed_usec(&t1, &t2);
algorithms[i].t = pj_elapsed_usec(&t1, &t2);
}
/* Results */
for (i=0; i<PJ_ARRAY_SIZE(algorithms); ++i) {
double bytes;
double bytes;
bytes = (total_len * 1000000 / algorithms[i].t);
PJ_LOG(3, (THIS_FILE, " %s:%8d usec (%3d.%03d Mbytes/sec)",
algorithms[i].name, algorithms[i].t,
(unsigned)(bytes / 1024 / 1024),
((unsigned)(bytes) % (1024 * 1024)) / 1024));
bytes = (total_len * 1000000 / algorithms[i].t);
PJ_LOG(3, (THIS_FILE, " %s:%8d usec (%3d.%03d Mbytes/sec)",
algorithms[i].name, algorithms[i].t,
(unsigned)(bytes / 1024 / 1024),
((unsigned)(bytes) % (1024 * 1024)) / 1024));
}
return 0;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
*
@ -21,7 +20,7 @@
#if INCLUDE_HTTP_CLIENT_TEST
#define THIS_FILE "test_http"
#define THIS_FILE "test_http"
//#define VERBOSE
#define STR_PREC(s) (int)s.slen, s.ptr
#define USE_LOCAL_SERVER
@ -29,23 +28,23 @@
#include <pjlib.h>
#include <pjlib-util.h>
#define ACTION_REPLY 0
#define ACTION_IGNORE -1
#define ACTION_REPLY 0
#define ACTION_IGNORE -1
static struct server_t
{
pj_sock_t sock;
pj_uint16_t port;
pj_thread_t *thread;
pj_sock_t sock;
pj_uint16_t port;
pj_thread_t *thread;
/* Action:
* 0: reply with the response in resp.
* 0: reply with the response in resp.
* -1: ignore query (to simulate timeout).
* other: reply with that error
*/
int action;
int action;
pj_bool_t send_content_length;
unsigned data_size;
unsigned data_size;
unsigned buf_size;
} g_server;
@ -68,34 +67,34 @@ static int server_thread(void *p)
pj_sock_t newsock = PJ_INVALID_SOCKET;
while (!thread_quit) {
pj_ssize_t pkt_len;
int rc;
pj_ssize_t pkt_len;
int rc;
pj_fd_set_t rset;
pj_time_val timeout = {0, 500};
pj_time_val timeout = {0, 500};
while (!thread_quit) {
PJ_FD_ZERO(&rset);
PJ_FD_SET(srv->sock, &rset);
rc = pj_sock_select((int)srv->sock+1, &rset, NULL, NULL, &timeout);
if (rc != 1) {
continue;
}
while (!thread_quit) {
PJ_FD_ZERO(&rset);
PJ_FD_SET(srv->sock, &rset);
rc = pj_sock_select((int)srv->sock+1, &rset, NULL, NULL, &timeout);
if (rc != 1) {
continue;
}
rc = pj_sock_accept(srv->sock, &newsock, NULL, NULL);
if (rc == PJ_SUCCESS) {
break;
}
}
rc = pj_sock_accept(srv->sock, &newsock, NULL, NULL);
if (rc == PJ_SUCCESS) {
break;
}
}
if (thread_quit)
break;
if (thread_quit)
break;
while (!thread_quit) {
while (!thread_quit) {
PJ_FD_ZERO(&rset);
PJ_FD_SET(newsock, &rset);
rc = pj_sock_select((int)newsock+1, &rset, NULL, NULL, &timeout);
if (rc != 1) {
PJ_LOG(3,("http test", "client timeout"));
PJ_LOG(3,("http test", "client timeout"));
continue;
}
@ -106,17 +105,17 @@ static int server_thread(void *p)
}
}
if (thread_quit)
break;
if (thread_quit)
break;
/* Simulate network RTT */
pj_thread_sleep(50);
/* Simulate network RTT */
pj_thread_sleep(50);
if (srv->action == ACTION_IGNORE) {
continue;
} else if (srv->action == ACTION_REPLY) {
if (srv->action == ACTION_IGNORE) {
continue;
} else if (srv->action == ACTION_REPLY) {
pj_size_t send_len = 0;
unsigned ctr = 0;
unsigned ctr = 0;
pj_ansi_sprintf(pkt, "HTTP/1.0 200 OK\r\n");
if (srv->send_content_length) {
pj_ansi_sprintf(pkt + pj_ansi_strlen(pkt),
@ -127,23 +126,23 @@ static int server_thread(void *p)
pkt_len = pj_ansi_strlen(pkt);
rc = pj_sock_send(newsock, pkt, &pkt_len, 0);
if (rc != PJ_SUCCESS) {
pj_sock_close(newsock);
continue;
pj_sock_close(newsock);
continue;
}
while (send_len < srv->data_size) {
pkt_len = srv->data_size - send_len;
if (pkt_len > (signed)srv->buf_size)
pkt_len = srv->buf_size;
send_len += pkt_len;
send_len += pkt_len;
pj_create_random_string(pkt, pkt_len);
pj_ansi_sprintf(pkt, "\nPacket: %d", ++ctr);
pkt[pj_ansi_strlen(pkt)] = '\n';
rc = pj_sock_send(newsock, pkt, &pkt_len, 0);
if (rc != PJ_SUCCESS)
break;
rc = pj_sock_send(newsock, pkt, &pkt_len, 0);
if (rc != PJ_SUCCESS)
break;
}
pj_sock_close(newsock);
}
}
}
return 0;
@ -228,10 +227,10 @@ static void on_response(pj_http_req *hreq, const pj_http_resp *resp)
#endif
if (test_cancel) {
/* Need to delay closing the client socket here, otherwise the
* server will get SIGPIPE when sending response.
*/
pj_thread_sleep(100);
/* Need to delay closing the client socket here, otherwise the
* server will get SIGPIPE when sending response.
*/
pj_thread_sleep(100);
pj_http_req_cancel(hreq, PJ_TRUE);
test_cancel = PJ_FALSE;
}
@ -260,16 +259,16 @@ static int parse_url_test()
{
struct test_data
{
char *url;
pj_status_t result;
const char *username;
const char *passwd;
const char *host;
int port;
const char *path;
char *url;
pj_status_t result;
const char *username;
const char *passwd;
const char *host;
int port;
const char *path;
} test_data[] =
{
/* Simple URL without '/' in the end */
/* Simple URL without '/' in the end */
{"http://www.pjsip.org", PJ_SUCCESS, "", "", "www.pjsip.org", 80, "/"},
/* Simple URL with port number but without '/' in the end */
@ -277,97 +276,97 @@ static int parse_url_test()
/* URL with path */
{"http://127.0.0.1:280/Joomla/index.php?option=com_content&task=view&id=5&Itemid=6",
PJ_SUCCESS, "", "", "127.0.0.1", 280,
"/Joomla/index.php?option=com_content&task=view&id=5&Itemid=6"},
PJ_SUCCESS, "", "", "127.0.0.1", 280,
"/Joomla/index.php?option=com_content&task=view&id=5&Itemid=6"},
/* URL with port and path */
{"http://pjsip.org:81/about-us/", PJ_SUCCESS, "", "", "pjsip.org", 81, "/about-us/"},
/* URL with port and path */
{"http://pjsip.org:81/about-us/", PJ_SUCCESS, "", "", "pjsip.org", 81, "/about-us/"},
/* unsupported protocol */
{"ftp://www.pjsip.org", PJ_ENOTSUP, "", "", "", 80, ""},
/* unsupported protocol */
{"ftp://www.pjsip.org", PJ_ENOTSUP, "", "", "", 80, ""},
/* invalid format */
{"http:/pjsip.org/about-us/", PJLIB_UTIL_EHTTPINURL, "", "", "", 80, ""},
/* invalid format */
{"http:/pjsip.org/about-us/", PJLIB_UTIL_EHTTPINURL, "", "", "", 80, ""},
/* invalid port number */
{"http://pjsip.org:xyz/", PJLIB_UTIL_EHTTPINPORT, "", "", "", 80, ""},
/* invalid port number */
{"http://pjsip.org:xyz/", PJLIB_UTIL_EHTTPINPORT, "", "", "", 80, ""},
/* with username and password */
{"http://user:pass@pjsip.org", PJ_SUCCESS, "user", "pass", "pjsip.org", 80, "/"},
/* with username and password */
{"http://user:pass@pjsip.org", PJ_SUCCESS, "user", "pass", "pjsip.org", 80, "/"},
/* password only*/
{"http://:pass@pjsip.org", PJ_SUCCESS, "", "pass", "pjsip.org", 80, "/"},
/* password only*/
{"http://:pass@pjsip.org", PJ_SUCCESS, "", "pass", "pjsip.org", 80, "/"},
/* user only*/
{"http://user:@pjsip.org", PJ_SUCCESS, "user", "", "pjsip.org", 80, "/"},
/* user only*/
{"http://user:@pjsip.org", PJ_SUCCESS, "user", "", "pjsip.org", 80, "/"},
/* empty username and passwd*/
{"http://:@pjsip.org", PJ_SUCCESS, "", "", "pjsip.org", 80, "/"},
/* empty username and passwd*/
{"http://:@pjsip.org", PJ_SUCCESS, "", "", "pjsip.org", 80, "/"},
/* '@' character in username and path */
{"http://user@pjsip.org/@", PJ_SUCCESS, "user", "", "pjsip.org", 80, "/@"},
/* '@' character in username and path */
{"http://user@pjsip.org/@", PJ_SUCCESS, "user", "", "pjsip.org", 80, "/@"},
/* '@' character in path */
{"http://pjsip.org/@", PJ_SUCCESS, "", "", "pjsip.org", 80, "/@"},
/* '@' character in path */
{"http://pjsip.org/@", PJ_SUCCESS, "", "", "pjsip.org", 80, "/@"},
/* '@' character in path */
{"http://pjsip.org/one@", PJ_SUCCESS, "", "", "pjsip.org", 80, "/one@"},
/* '@' character in path */
{"http://pjsip.org/one@", PJ_SUCCESS, "", "", "pjsip.org", 80, "/one@"},
/* Invalid URL */
{"http://:", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://:", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://@", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://@", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http:/", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http:/", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http:///", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http:///", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://@/", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://@/", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http:///@", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http:///@", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://:::", PJ_EINVAL, "", "", "", 0, ""},
/* Invalid URL */
{"http://:::", PJ_EINVAL, "", "", "", 0, ""},
};
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(test_data); ++i) {
struct test_data *ptd;
pj_http_url hurl;
pj_status_t status;
struct test_data *ptd;
pj_http_url hurl;
pj_status_t status;
ptd = &test_data[i];
ptd = &test_data[i];
PJ_LOG(3, (THIS_FILE, ".. %s", ptd->url));
status = parse_url(ptd->url, &hurl);
PJ_LOG(3, (THIS_FILE, ".. %s", ptd->url));
status = parse_url(ptd->url, &hurl);
if (status != ptd->result) {
PJ_LOG(3,(THIS_FILE, "%d", status));
return -11;
}
if (status != PJ_SUCCESS)
continue;
if (pj_strcmp2(&hurl.username, ptd->username))
return -12;
if (pj_strcmp2(&hurl.passwd, ptd->passwd))
return -13;
if (pj_strcmp2(&hurl.host, ptd->host))
return -14;
if (hurl.port != ptd->port)
return -15;
if (pj_strcmp2(&hurl.path, ptd->path))
return -16;
if (status != ptd->result) {
PJ_LOG(3,(THIS_FILE, "%d", status));
return -11;
}
if (status != PJ_SUCCESS)
continue;
if (pj_strcmp2(&hurl.username, ptd->username))
return -12;
if (pj_strcmp2(&hurl.passwd, ptd->passwd))
return -13;
if (pj_strcmp2(&hurl.host, ptd->host))
return -14;
if (hurl.port != ptd->port)
return -15;
if (pj_strcmp2(&hurl.path, ptd->path))
return -16;
}
return 0;
@ -418,16 +417,16 @@ int http_client_test1()
return -43;
{
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/about-us/",
g_server.port);
url = pj_str(urlbuf);
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/about-us/",
g_server.port);
url = pj_str(urlbuf);
}
sstatus = pj_sock_listen(g_server.sock, 8);
@ -453,8 +452,8 @@ int http_client_test1()
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
if (pj_http_req_start(http_req))
@ -462,8 +461,8 @@ int http_client_test1()
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
#ifdef USE_LOCAL_SERVER
@ -530,16 +529,16 @@ int http_client_test2()
return -43;
{
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d",
g_server.port);
url = pj_str(urlbuf);
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d",
g_server.port);
url = pj_str(urlbuf);
}
sstatus = pj_sock_listen(g_server.sock, 8);
@ -558,17 +557,17 @@ int http_client_test2()
#endif
pj_http_headers_add_elmt2(&param.headers, (char*)"Accept",
(char*)"image/gif, image/x-xbitmap, image/jpeg, "
"image/pjpeg, application/x-ms-application,"
" application/vnd.ms-xpsdocument, "
"application/xaml+xml, "
"application/x-ms-xbap, "
"application/x-shockwave-flash, "
"application/vnd.ms-excel, "
"application/vnd.ms-powerpoint, "
"application/msword, */*");
(char*)"image/gif, image/x-xbitmap, image/jpeg, "
"image/pjpeg, application/x-ms-application,"
" application/vnd.ms-xpsdocument, "
"application/xaml+xml, "
"application/x-ms-xbap, "
"application/x-shockwave-flash, "
"application/vnd.ms-excel, "
"application/vnd.ms-powerpoint, "
"application/msword, */*");
pj_http_headers_add_elmt2(&param.headers, (char*)"Accept-Language",
(char*)"en-sg");
(char*)"en-sg");
pj_http_headers_add_elmt2(&param.headers, (char*)"User-Agent",
(char*)"Mozilla/4.0 (compatible; MSIE 7.0; "
"Windows NT 6.0; SLCC1; "
@ -583,8 +582,8 @@ int http_client_test2()
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
#ifdef USE_LOCAL_SERVER
@ -598,8 +597,8 @@ int http_client_test2()
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
#ifdef USE_LOCAL_SERVER
@ -659,16 +658,16 @@ int http_client_test_put1()
return -43;
{
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/test/test.txt",
g_server.port);
url = pj_str(urlbuf);
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/test/test.txt",
g_server.port);
url = pj_str(urlbuf);
}
sstatus = pj_sock_listen(g_server.sock, 8);
@ -701,8 +700,8 @@ int http_client_test_put1()
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
#ifdef USE_LOCAL_SERVER
@ -762,16 +761,16 @@ int http_client_test_put2()
return -43;
{
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/test/test2.txt",
g_server.port);
url = pj_str(urlbuf);
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/test/test2.txt",
g_server.port);
url = pj_str(urlbuf);
}
sstatus = pj_sock_listen(g_server.sock, 8);
@ -802,8 +801,8 @@ int http_client_test_put2()
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
#ifdef USE_LOCAL_SERVER
@ -857,16 +856,16 @@ int http_client_test_delete()
return -43;
{
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/test/test2.txt",
g_server.port);
url = pj_str(urlbuf);
pj_sockaddr_in addr2;
int addr_len = sizeof(addr2);
sstatus = pj_sock_getsockname(g_server.sock, &addr2, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr2);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/test/test2.txt",
g_server.port);
url = pj_str(urlbuf);
}
sstatus = pj_sock_listen(g_server.sock, 8);
@ -893,8 +892,8 @@ int http_client_test_delete()
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
#ifdef USE_LOCAL_SERVER
@ -953,4 +952,4 @@ int http_client_test()
* when this test is disabled.
*/
int dummy_http_client_test;
#endif /* INCLUDE_HTTP_CLIENT_TEST */
#endif /* INCLUDE_HTTP_CLIENT_TEST */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
@ -18,7 +17,7 @@
*/
#include "test.h"
#define THIS_FILE "json_test.c"
#define THIS_FILE "json_test.c"
#if INCLUDE_JSON_TEST
@ -40,12 +39,12 @@ static char json_doc1[] =
},\
\"Array1\": [116, false, \"string\", {}],\
\"Array2\": [\
{\
\"Float\": 123.,\
},\
{\
\"Float\": 123.,\
}\
{\
\"Float\": 123.,\
},\
{\
\"Float\": 123.,\
}\
]\
},\
\"Integer\": 800,\
@ -66,16 +65,16 @@ static int json_verify_1()
size = (unsigned)strlen(json_doc1);
elem = pj_json_parse(pool, json_doc1, &size, &err);
if (!elem) {
PJ_LOG(1, (THIS_FILE, " Error: json_verify_1() parse error"));
goto on_error;
PJ_LOG(1, (THIS_FILE, " Error: json_verify_1() parse error"));
goto on_error;
}
size = (unsigned)strlen(json_doc1) * 2;
out_buf = pj_pool_alloc(pool, size);
if (pj_json_write(elem, out_buf, &size)) {
PJ_LOG(1, (THIS_FILE, " Error: json_verify_1() write error"));
goto on_error;
PJ_LOG(1, (THIS_FILE, " Error: json_verify_1() write error"));
goto on_error;
}
PJ_LOG(3,(THIS_FILE, "Json document:\n%s", out_buf));
@ -94,7 +93,7 @@ int json_test(void)
rc = json_verify_1();
if (rc)
return rc;
return rc;
return 0;
}

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -76,26 +75,26 @@ int main(int argc, char *argv[])
while (argc > 1) {
char *arg = argv[--argc];
if (*arg=='-' && *(arg+1)=='i') {
interractive = 1;
if (*arg=='-' && *(arg+1)=='i') {
interractive = 1;
} else if (*arg=='-' && *(arg+1)=='n') {
no_trap = 1;
}
} else if (*arg=='-' && *(arg+1)=='n') {
no_trap = 1;
}
}
if (!no_trap) {
init_signals();
init_signals();
}
rc = test_main();
if (interractive) {
char s[10];
puts("");
puts("Press <ENTER> to exit");
if (!fgets(s, sizeof(s), stdin))
return rc;
char s[10];
puts("");
puts("Press <ENTER> to exit");
if (!fgets(s, sizeof(s), stdin))
return rc;
}
return rc;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -31,20 +30,20 @@ void app_perror(const char *msg, pj_status_t rc)
PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
}
#define DO_TEST(test) do { \
PJ_LOG(3, ("test", "Running %s...", #test)); \
rc = test; \
PJ_LOG(3, ("test", \
"%s(%d)", \
(char*)(rc ? "..ERROR" : "..success"), rc)); \
if (rc!=0) goto on_return; \
} while (0)
#define DO_TEST(test) do { \
PJ_LOG(3, ("test", "Running %s...", #test)); \
rc = test; \
PJ_LOG(3, ("test", \
"%s(%d)", \
(char*)(rc ? "..ERROR" : "..success"), rc)); \
if (rc!=0) goto on_return; \
} while (0)
pj_pool_factory *mem;
int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_INDENT;
PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_INDENT;
static int test_inner(void)
{
@ -58,8 +57,8 @@ static int test_inner(void)
rc = pj_init();
if (rc != 0) {
app_perror("pj_init() error!!", rc);
return rc;
app_perror("pj_init() error!!", rc);
return rc;
}
rc = pjlib_util_init();

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -20,16 +19,16 @@
#include <pj/types.h>
#if defined(PJ_EXCLUDE_BENCHMARK_TESTS) && (PJ_EXCLUDE_BENCHMARK_TESTS==1)
# define WITH_BENCHMARK 0
# define WITH_BENCHMARK 0
#else
# define WITH_BENCHMARK 1
# define WITH_BENCHMARK 1
#endif
#define INCLUDE_XML_TEST 1
#define INCLUDE_JSON_TEST 1
#define INCLUDE_ENCRYPTION_TEST 1
#define INCLUDE_STUN_TEST 1
#define INCLUDE_RESOLVER_TEST 1
#define INCLUDE_XML_TEST 1
#define INCLUDE_JSON_TEST 1
#define INCLUDE_ENCRYPTION_TEST 1
#define INCLUDE_STUN_TEST 1
#define INCLUDE_RESOLVER_TEST 1
#define INCLUDE_HTTP_CLIENT_TEST 1
extern int xml_test(void);

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -107,15 +106,15 @@ static int xml_parse_print_test(const char *doc)
pj_strdup2(pool, &msg, doc);
root = pj_xml_parse(pool, msg.ptr, msg.slen);
if (!root) {
PJ_LOG(1, (THIS_FILE, " Error: unable to parse XML"));
return -10;
PJ_LOG(1, (THIS_FILE, " Error: unable to parse XML"));
return -10;
}
output = (char*)pj_pool_zalloc(pool, msg.slen + 512);
output_len = pj_xml_print(root, output, msg.slen+512, PJ_TRUE);
if (output_len < 1) {
PJ_LOG(1, (THIS_FILE, " Error: buffer too small to print XML file"));
return -20;
PJ_LOG(1, (THIS_FILE, " Error: buffer too small to print XML file"));
return -20;
}
output[output_len] = '\0';
@ -128,9 +127,9 @@ int xml_test()
{
unsigned i;
for (i=0; i<sizeof(xml_doc)/sizeof(xml_doc[0]); ++i) {
int status;
if ((status=xml_parse_print_test(xml_doc[i])) != 0)
return status;
int status;
if ((status=xml_parse_print_test(xml_doc[i])) != 0)
return status;
}
return 0;
}
@ -140,6 +139,6 @@ int xml_test()
* when this test is disabled.
*/
int dummy_xml_test;
#endif /* INCLUDE_XML_TEST */
#endif /* INCLUDE_XML_TEST */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -21,8 +20,8 @@
#include <pj/assert.h>
#include <pj/errno.h>
#define INV -1
#define PADDING '='
#define INV -1
#define PADDING '='
static const char base64_char[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
@ -37,49 +36,49 @@ static const char base64_char[] = {
static int base256_char(char c)
{
if (c >= 'A' && c <= 'Z')
return (c - 'A');
return (c - 'A');
else if (c >= 'a' && c <= 'z')
return (c - 'a' + 26);
return (c - 'a' + 26);
else if (c >= '0' && c <= '9')
return (c - '0' + 52);
return (c - '0' + 52);
else if (c == '+')
return (62);
return (62);
else if (c == '/')
return (63);
return (63);
else {
/* It *may* happen on bad input, so this is not a good idea.
* pj_assert(!"Should not happen as '=' should have been filtered");
*/
return INV;
/* It *may* happen on bad input, so this is not a good idea.
* pj_assert(!"Should not happen as '=' should have been filtered");
*/
return INV;
}
}
static void base256to64(pj_uint8_t c1, pj_uint8_t c2, pj_uint8_t c3,
int padding, char *output)
int padding, char *output)
{
*output++ = base64_char[c1>>2];
*output++ = base64_char[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)];
switch (padding) {
case 0:
*output++ = base64_char[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
*output = base64_char[c3 & 0x3F];
break;
*output++ = base64_char[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
*output = base64_char[c3 & 0x3F];
break;
case 1:
*output++ = base64_char[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
*output = PADDING;
break;
*output++ = base64_char[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
*output = PADDING;
break;
case 2:
default:
*output++ = PADDING;
*output = PADDING;
break;
*output++ = PADDING;
*output = PADDING;
break;
}
}
PJ_DEF(pj_status_t) pj_base64_encode(const pj_uint8_t *input, int in_len,
char *output, int *out_len)
char *output, int *out_len)
{
const pj_uint8_t *pi = input;
pj_uint8_t c1, c2, c3;
@ -88,32 +87,32 @@ PJ_DEF(pj_status_t) pj_base64_encode(const pj_uint8_t *input, int in_len,
PJ_ASSERT_RETURN(input && output && out_len, PJ_EINVAL);
PJ_ASSERT_RETURN(*out_len >= PJ_BASE256_TO_BASE64_LEN(in_len),
PJ_ETOOSMALL);
PJ_ETOOSMALL);
while (i < in_len) {
c1 = *pi++;
++i;
c1 = *pi++;
++i;
if (i == in_len) {
base256to64(c1, 0, 0, 2, po);
po += 4;
break;
} else {
c2 = *pi++;
++i;
if (i == in_len) {
base256to64(c1, 0, 0, 2, po);
po += 4;
break;
} else {
c2 = *pi++;
++i;
if (i == in_len) {
base256to64(c1, c2, 0, 1, po);
po += 4;
break;
} else {
c3 = *pi++;
++i;
base256to64(c1, c2, c3, 0, po);
}
}
if (i == in_len) {
base256to64(c1, c2, 0, 1, po);
po += 4;
break;
} else {
c3 = *pi++;
++i;
base256to64(c1, c2, c3, 0, po);
}
}
po += 4;
po += 4;
}
*out_len = (int)(po - output);
@ -122,7 +121,7 @@ PJ_DEF(pj_status_t) pj_base64_encode(const pj_uint8_t *input, int in_len,
PJ_DEF(pj_status_t) pj_base64_decode(const pj_str_t *input,
pj_uint8_t *out, int *out_len)
pj_uint8_t *out, int *out_len)
{
const char *buf;
int len;
@ -134,33 +133,33 @@ PJ_DEF(pj_status_t) pj_base64_decode(const pj_str_t *input,
buf = input->ptr;
len = (int)input->slen;
while (len && buf[len-1] == '=')
--len;
--len;
PJ_ASSERT_RETURN(*out_len >= PJ_BASE64_TO_BASE256_LEN(len),
PJ_ETOOSMALL);
PJ_ETOOSMALL);
for (i=0, j=0; i<len; ) {
/* Fill up c, silently ignoring invalid characters */
for (k=0; k<4 && i<len; ++k) {
do {
c[k] = base256_char(buf[i++]);
} while (c[k]==INV && i<len);
}
/* Fill up c, silently ignoring invalid characters */
for (k=0; k<4 && i<len; ++k) {
do {
c[k] = base256_char(buf[i++]);
} while (c[k]==INV && i<len);
}
if (k<4) {
if (k > 1) {
out[j++] = (pj_uint8_t)((c[0]<<2) | ((c[1] & 0x30)>>4));
if (k > 2) {
out[j++] = (pj_uint8_t)
(((c[1] & 0x0F)<<4) | ((c[2] & 0x3C)>>2));
}
}
break;
}
if (k<4) {
if (k > 1) {
out[j++] = (pj_uint8_t)((c[0]<<2) | ((c[1] & 0x30)>>4));
if (k > 2) {
out[j++] = (pj_uint8_t)
(((c[1] & 0x0F)<<4) | ((c[2] & 0x3C)>>2));
}
}
break;
}
out[j++] = (pj_uint8_t)((c[0]<<2) | ((c[1] & 0x30)>>4));
out[j++] = (pj_uint8_t)(((c[1] & 0x0F)<<4) | ((c[2] & 0x3C)>>2));
out[j++] = (pj_uint8_t)(((c[2] & 0x03)<<6) | (c[3] & 0x3F));
out[j++] = (pj_uint8_t)((c[0]<<2) | ((c[1] & 0x30)>>4));
out[j++] = (pj_uint8_t)(((c[1] & 0x0F)<<4) | ((c[2] & 0x3C)>>2));
out[j++] = (pj_uint8_t)(((c[2] & 0x03)<<6) | (c[3] & 0x3F));
}
pj_assert(j <= *out_len);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2010 Teluu Inc. (http://www.teluu.com)
*
@ -57,7 +56,7 @@ struct cli_console_fe
};
static void console_write_log(pj_cli_front_end *fe, int level,
const char *data, pj_size_t len)
const char *data, pj_size_t len)
{
struct cli_console_fe * cfe = (struct cli_console_fe *)fe;
@ -91,7 +90,7 @@ static void console_destroy(pj_cli_front_end *fe)
if (cfe->input_thread) {
pj_thread_destroy(cfe->input_thread);
cfe->input_thread = NULL;
cfe->input_thread = NULL;
}
pj_sem_destroy(cfe->thread_sem);
@ -109,9 +108,9 @@ PJ_DEF(void) pj_cli_console_cfg_default(pj_cli_console_cfg *param)
}
PJ_DEF(pj_status_t) pj_cli_console_create(pj_cli_t *cli,
const pj_cli_console_cfg *param,
pj_cli_sess **p_sess,
pj_cli_front_end **p_fe)
const pj_cli_console_cfg *param,
pj_cli_sess **p_sess,
pj_cli_front_end **p_fe)
{
pj_cli_sess *sess;
struct cli_console_fe *fe;
@ -147,26 +146,26 @@ PJ_DEF(pj_status_t) pj_cli_console_create(pj_cli_t *cli,
fe->sess = sess;
status = pj_sem_create(pool, "console_fe", 0, 1, &fe->thread_sem);
if (status != PJ_SUCCESS)
return status;
return status;
status = pj_sem_create(pool, "console_fe", 0, 1, &fe->input.sem);
if (status != PJ_SUCCESS)
return status;
return status;
pj_cli_register_front_end(cli, &fe->base);
if (param->prompt_str.slen == 0) {
pj_str_t prompt_sign = pj_str(">>> ");
fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool, prompt_sign.slen+1);
pj_strcpy(&fe->cfg.prompt_str, &prompt_sign);
pj_str_t prompt_sign = pj_str(">>> ");
fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool, prompt_sign.slen+1);
pj_strcpy(&fe->cfg.prompt_str, &prompt_sign);
} else {
fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool,
param->prompt_str.slen+1);
pj_strcpy(&fe->cfg.prompt_str, &param->prompt_str);
fe->cfg.prompt_str.ptr = pj_pool_alloc(fe->pool,
param->prompt_str.slen+1);
pj_strcpy(&fe->cfg.prompt_str, &param->prompt_str);
}
fe->cfg.prompt_str.ptr[fe->cfg.prompt_str.slen] = 0;
if (param->quit_command.slen)
pj_strdup(fe->pool, &fe->cfg.quit_command, &param->quit_command);
pj_strdup(fe->pool, &fe->cfg.quit_command, &param->quit_command);
*p_sess = sess;
if (p_fe)
@ -191,9 +190,9 @@ static void send_prompt_str(pj_cli_sess *sess)
}
static void send_err_arg(pj_cli_sess *sess,
const pj_cli_exec_info *info,
const pj_str_t *msg,
pj_bool_t with_return)
const pj_cli_exec_info *info,
const pj_str_t *msg,
pj_bool_t with_return)
{
pj_str_t send_data;
char data_str[256];
@ -205,12 +204,12 @@ static void send_err_arg(pj_cli_sess *sess,
send_data.slen = 0;
if (with_return)
pj_strcat2(&send_data, "\r\n");
pj_strcat2(&send_data, "\r\n");
len = fe->cfg.prompt_str.slen + info->err_pos;
for (i=0;i<len;++i) {
pj_strcat2(&send_data, " ");
pj_strcat2(&send_data, " ");
}
pj_strcat2(&send_data, "^");
pj_strcat2(&send_data, "\r\n");
@ -222,43 +221,43 @@ static void send_err_arg(pj_cli_sess *sess,
}
static void send_inv_arg(pj_cli_sess *sess,
const pj_cli_exec_info *info,
pj_bool_t with_return)
const pj_cli_exec_info *info,
pj_bool_t with_return)
{
static const pj_str_t ERR_MSG = {"%Error : Invalid Arguments\r\n", 28};
send_err_arg(sess, info, &ERR_MSG, with_return);
}
static void send_too_many_arg(pj_cli_sess *sess,
const pj_cli_exec_info *info,
pj_bool_t with_return)
const pj_cli_exec_info *info,
pj_bool_t with_return)
{
static const pj_str_t ERR_MSG = {"%Error : Too Many Arguments\r\n", 29};
send_err_arg(sess, info, &ERR_MSG, with_return);
}
static void send_hint_arg(pj_str_t *send_data,
const pj_str_t *desc,
pj_ssize_t cmd_len,
pj_ssize_t max_len)
const pj_str_t *desc,
pj_ssize_t cmd_len,
pj_ssize_t max_len)
{
if ((desc) && (desc->slen > 0)) {
int j;
int j;
for (j=0;j<(max_len-cmd_len);++j) {
pj_strcat2(send_data, " ");
}
pj_strcat2(send_data, " ");
pj_strcat(send_data, desc);
send_data->ptr[send_data->slen] = 0;
printf("%s", send_data->ptr);
send_data->slen = 0;
for (j=0;j<(max_len-cmd_len);++j) {
pj_strcat2(send_data, " ");
}
pj_strcat2(send_data, " ");
pj_strcat(send_data, desc);
send_data->ptr[send_data->slen] = 0;
printf("%s", send_data->ptr);
send_data->slen = 0;
}
}
static void send_ambi_arg(pj_cli_sess *sess,
const pj_cli_exec_info *info,
pj_bool_t with_return)
const pj_cli_exec_info *info,
pj_bool_t with_return)
{
unsigned i;
pj_size_t len;
@ -275,92 +274,92 @@ static void send_ambi_arg(pj_cli_sess *sess,
send_data.slen = 0;
if (with_return)
pj_strcat2(&send_data, "\r\n");
pj_strcat2(&send_data, "\r\n");
len = fe->cfg.prompt_str.slen + info->err_pos;
for (i=0;i<len;++i) {
pj_strcat2(&send_data, " ");
pj_strcat2(&send_data, " ");
}
pj_strcat2(&send_data, "^");
/* Get the max length of the command name */
for (i=0;i<info->hint_cnt;++i) {
if (hint[i].type.slen > 0) {
if (pj_stricmp(&hint[i].type, &sc_type) == 0) {
if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) {
cmd_length += (hint[i].name.slen + 3);
} else {
cmd_length = hint[i].name.slen;
}
} else {
cmd_length = hint[i].name.slen;
}
} else {
cmd_length = hint[i].name.slen;
}
if (hint[i].type.slen > 0) {
if (pj_stricmp(&hint[i].type, &sc_type) == 0) {
if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) {
cmd_length += (hint[i].name.slen + 3);
} else {
cmd_length = hint[i].name.slen;
}
} else {
cmd_length = hint[i].name.slen;
}
} else {
cmd_length = hint[i].name.slen;
}
if (cmd_length > max_length) {
max_length = cmd_length;
}
if (cmd_length > max_length) {
max_length = cmd_length;
}
}
cmd_length = 0;
for (i=0;i<info->hint_cnt;++i) {
if (hint[i].type.slen > 0) {
if (pj_stricmp(&hint[i].type, &sc_type) == 0) {
parse_state = OP_SHORTCUT;
} else if (pj_stricmp(&hint[i].type, &choice_type) == 0) {
parse_state = OP_CHOICE;
} else {
parse_state = OP_TYPE;
}
} else {
parse_state = OP_NORMAL;
}
if (hint[i].type.slen > 0) {
if (pj_stricmp(&hint[i].type, &sc_type) == 0) {
parse_state = OP_SHORTCUT;
} else if (pj_stricmp(&hint[i].type, &choice_type) == 0) {
parse_state = OP_CHOICE;
} else {
parse_state = OP_TYPE;
}
} else {
parse_state = OP_NORMAL;
}
if (parse_state != OP_SHORTCUT) {
pj_strcat2(&send_data, "\r\n ");
cmd_length = hint[i].name.slen;
}
if (parse_state != OP_SHORTCUT) {
pj_strcat2(&send_data, "\r\n ");
cmd_length = hint[i].name.slen;
}
switch (parse_state) {
case OP_CHOICE:
pj_strcat2(&send_data, "[");
pj_strcat(&send_data, &hint[i].name);
pj_strcat2(&send_data, "]");
break;
case OP_TYPE:
pj_strcat2(&send_data, "<");
pj_strcat(&send_data, &hint[i].type);
pj_strcat2(&send_data, ">");
break;
case OP_SHORTCUT:
/* Format : "Command | sc | description" */
{
cmd_length += hint[i].name.slen;
if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) {
pj_strcat2(&send_data, " | ");
cmd_length += 3;
} else {
pj_strcat2(&send_data, "\r\n ");
}
pj_strcat(&send_data, &hint[i].name);
}
break;
default:
pj_strcat(&send_data, &hint[i].name);
break;
}
switch (parse_state) {
case OP_CHOICE:
pj_strcat2(&send_data, "[");
pj_strcat(&send_data, &hint[i].name);
pj_strcat2(&send_data, "]");
break;
case OP_TYPE:
pj_strcat2(&send_data, "<");
pj_strcat(&send_data, &hint[i].type);
pj_strcat2(&send_data, ">");
break;
case OP_SHORTCUT:
/* Format : "Command | sc | description" */
{
cmd_length += hint[i].name.slen;
if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) {
pj_strcat2(&send_data, " | ");
cmd_length += 3;
} else {
pj_strcat2(&send_data, "\r\n ");
}
pj_strcat(&send_data, &hint[i].name);
}
break;
default:
pj_strcat(&send_data, &hint[i].name);
break;
}
if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) ||
((i+1) >= info->hint_cnt) ||
(pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen)))
{
/* Add description info */
send_hint_arg(&send_data, &hint[i].desc, cmd_length, max_length);
if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) ||
((i+1) >= info->hint_cnt) ||
(pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen)))
{
/* Add description info */
send_hint_arg(&send_data, &hint[i].desc, cmd_length, max_length);
cmd_length = 0;
}
cmd_length = 0;
}
}
pj_strcat2(&send_data, "\r\n");
pj_strcat(&send_data, &fe->cfg.prompt_str);
@ -387,27 +386,27 @@ static pj_bool_t handle_hint(pj_cli_sess *sess)
cmd_val = PJ_POOL_ZALLOC_T(pool, pj_cli_cmd_val);
status = pj_cli_sess_parse(sess, recv_buf, cmd_val,
pool, &info);
pool, &info);
switch (status) {
case PJ_CLI_EINVARG:
send_inv_arg(sess, &info, PJ_TRUE);
break;
send_inv_arg(sess, &info, PJ_TRUE);
break;
case PJ_CLI_ETOOMANYARGS:
send_too_many_arg(sess, &info, PJ_TRUE);
break;
send_too_many_arg(sess, &info, PJ_TRUE);
break;
case PJ_CLI_EMISSINGARG:
case PJ_CLI_EAMBIGUOUS:
send_ambi_arg(sess, &info, PJ_TRUE);
break;
send_ambi_arg(sess, &info, PJ_TRUE);
break;
case PJ_SUCCESS:
if (info.hint_cnt > 0) {
/* Compelete command */
send_ambi_arg(sess, &info, PJ_TRUE);
} else {
retval = PJ_FALSE;
}
break;
if (info.hint_cnt > 0) {
/* Compelete command */
send_ambi_arg(sess, &info, PJ_TRUE);
} else {
retval = PJ_FALSE;
}
break;
}
pj_pool_release(pool);
@ -428,29 +427,29 @@ static pj_bool_t handle_exec(pj_cli_sess *sess)
printf("\r\n");
pool = pj_pool_create(pj_cli_get_param(cli)->pf, "handle_exec",
PJ_CLI_CONSOLE_POOL_SIZE, PJ_CLI_CONSOLE_POOL_INC,
NULL);
PJ_CLI_CONSOLE_POOL_SIZE, PJ_CLI_CONSOLE_POOL_INC,
NULL);
status = pj_cli_sess_exec(sess, recv_buf,
pool, &info);
pool, &info);
switch (status) {
case PJ_CLI_EINVARG:
send_inv_arg(sess, &info, PJ_FALSE);
break;
send_inv_arg(sess, &info, PJ_FALSE);
break;
case PJ_CLI_ETOOMANYARGS:
send_too_many_arg(sess, &info, PJ_FALSE);
break;
send_too_many_arg(sess, &info, PJ_FALSE);
break;
case PJ_CLI_EAMBIGUOUS:
case PJ_CLI_EMISSINGARG:
send_ambi_arg(sess, &info, PJ_FALSE);
break;
send_ambi_arg(sess, &info, PJ_FALSE);
break;
case PJ_CLI_EEXIT:
retval = PJ_FALSE;
break;
retval = PJ_FALSE;
break;
case PJ_SUCCESS:
send_prompt_str(sess);
break;
send_prompt_str(sess);
break;
}
pj_pool_release(pool);
@ -464,54 +463,54 @@ static int readline_thread(void * p)
printf("%s", fe->cfg.prompt_str.ptr);
while (!fe->thread_quit) {
pj_size_t input_len = 0;
pj_str_t input_str;
char *recv_buf = fe->input.buf;
pj_bool_t is_valid = PJ_TRUE;
pj_size_t input_len = 0;
pj_str_t input_str;
char *recv_buf = fe->input.buf;
pj_bool_t is_valid = PJ_TRUE;
if (fgets(recv_buf, fe->input.maxlen, stdin) == NULL) {
/*
* Be friendly to users who redirect commands into
* program, when file ends, resume with kbd.
* If exit is desired end script with q for quit
*/
/* Reopen stdin/stdout/stderr to /dev/console */
if (fgets(recv_buf, fe->input.maxlen, stdin) == NULL) {
/*
* Be friendly to users who redirect commands into
* program, when file ends, resume with kbd.
* If exit is desired end script with q for quit
*/
/* Reopen stdin/stdout/stderr to /dev/console */
#if ((defined(PJ_WIN32) && PJ_WIN32!=0) || \
(defined(PJ_WIN64) && PJ_WIN64!=0)) && \
(!defined(PJ_WIN32_WINCE) || PJ_WIN32_WINCE==0)
if (freopen ("CONIN$", "r", stdin) == NULL) {
if (freopen ("CONIN$", "r", stdin) == NULL) {
#else
if (1) {
if (1) {
#endif
puts("Cannot switch back to console from file redirection");
if (fe->cfg.quit_command.slen) {
pj_memcpy(recv_buf, fe->cfg.quit_command.ptr,
fe->input.maxlen);
}
recv_buf[fe->cfg.quit_command.slen] = '\0';
} else {
puts("Switched back to console from file redirection");
continue;
}
}
puts("Cannot switch back to console from file redirection");
if (fe->cfg.quit_command.slen) {
pj_memcpy(recv_buf, fe->cfg.quit_command.ptr,
fe->input.maxlen);
}
recv_buf[fe->cfg.quit_command.slen] = '\0';
} else {
puts("Switched back to console from file redirection");
continue;
}
}
input_str.ptr = recv_buf;
input_str.slen = pj_ansi_strlen(recv_buf);
pj_strrtrim(&input_str);
recv_buf[input_str.slen] = '\n';
recv_buf[input_str.slen+1] = 0;
if (fe->thread_quit) {
break;
}
input_len = pj_ansi_strlen(fe->input.buf);
if ((input_len > 1) && (fe->input.buf[input_len-2] == '?')) {
fe->input.buf[input_len-1] = 0;
is_valid = handle_hint(fe->sess);
if (!is_valid)
printf("%s", fe->cfg.prompt_str.ptr);
} else {
is_valid = handle_exec(fe->sess);
}
input_str.ptr = recv_buf;
input_str.slen = pj_ansi_strlen(recv_buf);
pj_strrtrim(&input_str);
recv_buf[input_str.slen] = '\n';
recv_buf[input_str.slen+1] = 0;
if (fe->thread_quit) {
break;
}
input_len = pj_ansi_strlen(fe->input.buf);
if ((input_len > 1) && (fe->input.buf[input_len-2] == '?')) {
fe->input.buf[input_len-1] = 0;
is_valid = handle_hint(fe->sess);
if (!is_valid)
printf("%s", fe->cfg.prompt_str.ptr);
} else {
is_valid = handle_exec(fe->sess);
}
pj_sem_post(fe->input.sem);
pj_sem_wait(fe->thread_sem);
@ -521,8 +520,8 @@ static int readline_thread(void * p)
}
PJ_DEF(pj_status_t) pj_cli_console_process(pj_cli_sess *sess,
char *buf,
unsigned maxlen)
char *buf,
unsigned maxlen)
{
struct cli_console_fe *fe = (struct cli_console_fe *)sess->fe;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* This is an implementation of CRC32. See ISO 3309 and ITU-T V.42
* for a formal specification
@ -20,7 +19,7 @@
/* Table of CRC-32's of all single byte values (made by makecrc.c) */
#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN != 0
#define CRC32_INDEX(c) (c & 0xff)
#define CRC32_INDEX(c) (c & 0xff)
#define CRC32_SHIFTED(c) (c >> 8)
#define CRC32_SWAP(c) (c)
@ -81,7 +80,7 @@ static const pj_uint32_t crc_tab[] = {
#elif defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN != 0
#define CRC32_INDEX(c) (c >> 24)
#define CRC32_INDEX(c) (c >> 24)
#define CRC32_SHIFTED(c) (c << 8)
#define CRC32_SWAP(c) ((((c) & 0xff000000) >> 24) | \
(((c) & 0x00ff0000) >> 8) | \
@ -154,27 +153,27 @@ PJ_DEF(void) pj_crc32_init(pj_crc32_context *ctx)
}
PJ_DEF(pj_uint32_t) pj_crc32_update(pj_crc32_context *ctx,
const pj_uint8_t *data,
pj_size_t nbytes)
const pj_uint8_t *data,
pj_size_t nbytes)
{
pj_uint32_t crc = ctx->crc_state ^ CRC32_NEGL;
for( ; (((unsigned long)(pj_ssize_t)data) & 0x03) && nbytes > 0; --nbytes) {
crc = crc_tab[CRC32_INDEX(crc) ^ *data++] ^ CRC32_SHIFTED(crc);
crc = crc_tab[CRC32_INDEX(crc) ^ *data++] ^ CRC32_SHIFTED(crc);
}
while (nbytes >= 4) {
crc ^= *(const pj_uint32_t *)data;
crc = crc_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
crc = crc_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
crc = crc_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
crc = crc_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
nbytes -= 4;
data += 4;
crc ^= *(const pj_uint32_t *)data;
crc = crc_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
crc = crc_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
crc = crc_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
crc = crc_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
nbytes -= 4;
data += 4;
}
while (nbytes--) {
crc = crc_tab[CRC32_INDEX(crc) ^ *data++] ^ CRC32_SHIFTED(crc);
crc = crc_tab[CRC32_INDEX(crc) ^ *data++] ^ CRC32_SHIFTED(crc);
}
ctx->crc_state = crc ^ CRC32_NEGL;
@ -197,25 +196,25 @@ PJ_DEF(void) pj_crc32_init(pj_crc32_context *ctx)
PJ_DEF(pj_uint32_t) pj_crc32_update(pj_crc32_context *ctx,
const pj_uint8_t *octets,
pj_size_t len)
const pj_uint8_t *octets,
pj_size_t len)
{
pj_uint32_t crc = ctx->crc_state;
while (len--) {
pj_uint32_t temp;
int j;
pj_uint32_t temp;
int j;
temp = (pj_uint32_t)((crc & 0xFF) ^ *octets++);
for (j = 0; j < 8; j++)
{
if (temp & 0x1)
temp = (temp >> 1) ^ 0xEDB88320;
else
temp >>= 1;
}
crc = (crc >> 8) ^ temp;
temp = (pj_uint32_t)((crc & 0xFF) ^ *octets++);
for (j = 0; j < 8; j++)
{
if (temp & 0x1)
temp = (temp >> 1) ^ 0xEDB88320;
else
temp >>= 1;
}
crc = (crc >> 8) ^ temp;
}
ctx->crc_state = crc;
@ -232,7 +231,7 @@ PJ_DEF(pj_uint32_t) pj_crc32_final(pj_crc32_context *ctx)
PJ_DEF(pj_uint32_t) pj_crc32_calc( const pj_uint8_t *data,
pj_size_t nbytes)
pj_size_t nbytes)
{
pj_crc32_context ctx;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -29,7 +28,7 @@
PJ_DEF(const char *) pj_dns_get_type_name(int type)
{
switch (type) {
case PJ_DNS_TYPE_A: return "A";
case PJ_DNS_TYPE_A: return "A";
case PJ_DNS_TYPE_AAAA: return "AAAA";
case PJ_DNS_TYPE_SRV: return "SRV";
case PJ_DNS_TYPE_NS: return "NS";
@ -54,10 +53,10 @@ static void write16(pj_uint8_t *p, pj_uint16_t val)
* Initialize a DNS query transaction.
*/
PJ_DEF(pj_status_t) pj_dns_make_query( void *packet,
unsigned *size,
pj_uint16_t id,
int qtype,
const pj_str_t *name)
unsigned *size,
pj_uint16_t id,
int qtype,
const pj_str_t *name)
{
pj_uint8_t *p = (pj_uint8_t*)packet;
const char *startlabel, *endlabel, *endname;
@ -86,14 +85,14 @@ PJ_DEF(pj_status_t) pj_dns_make_query( void *packet,
startlabel = endlabel = name->ptr;
endname = name->ptr + name->slen;
while (endlabel != endname) {
while (endlabel != endname && *endlabel != '.')
++endlabel;
*p++ = (pj_uint8_t)(endlabel - startlabel);
pj_memcpy(p, startlabel, endlabel-startlabel);
p += (endlabel-startlabel);
if (endlabel != endname && *endlabel == '.')
++endlabel;
startlabel = endlabel;
while (endlabel != endname && *endlabel != '.')
++endlabel;
*p++ = (pj_uint8_t)(endlabel - startlabel);
pj_memcpy(p, startlabel, endlabel-startlabel);
p += (endlabel-startlabel);
if (endlabel != endname && *endlabel == '.')
++endlabel;
startlabel = endlabel;
}
*p++ = '\0';
@ -116,66 +115,66 @@ PJ_DEF(pj_status_t) pj_dns_make_query( void *packet,
* it may contain pointers when name compression is applied)
*/
static pj_status_t get_name_len(int rec_counter, const pj_uint8_t *pkt,
const pj_uint8_t *start, const pj_uint8_t *max,
int *parsed_len, int *name_len)
const pj_uint8_t *start, const pj_uint8_t *max,
int *parsed_len, int *name_len)
{
const pj_uint8_t *p;
pj_status_t status;
/* Limit the number of recursion */
if (rec_counter > 10) {
/* Too many name recursion */
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Too many name recursion */
return PJLIB_UTIL_EDNSINNAMEPTR;
}
*name_len = *parsed_len = 0;
p = start;
while (*p) {
if ((*p & 0xc0) == 0xc0) {
/* Compression is found! */
int ptr_len = 0;
int dummy;
pj_uint16_t offset;
if ((*p & 0xc0) == 0xc0) {
/* Compression is found! */
int ptr_len = 0;
int dummy;
pj_uint16_t offset;
/* Get the 14bit offset */
pj_memcpy(&offset, p, 2);
offset ^= pj_htons((pj_uint16_t)(0xc0 << 8));
offset = pj_ntohs(offset);
/* Get the 14bit offset */
pj_memcpy(&offset, p, 2);
offset ^= pj_htons((pj_uint16_t)(0xc0 << 8));
offset = pj_ntohs(offset);
/* Check that offset is valid */
if (offset >= max - pkt)
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Check that offset is valid */
if (offset >= max - pkt)
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Get the name length from that offset. */
status = get_name_len(rec_counter+1, pkt, pkt + offset, max,
&dummy, &ptr_len);
if (status != PJ_SUCCESS)
return status;
/* Get the name length from that offset. */
status = get_name_len(rec_counter+1, pkt, pkt + offset, max,
&dummy, &ptr_len);
if (status != PJ_SUCCESS)
return status;
*parsed_len += 2;
*name_len += ptr_len;
*parsed_len += 2;
*name_len += ptr_len;
return PJ_SUCCESS;
} else {
unsigned label_len = *p;
return PJ_SUCCESS;
} else {
unsigned label_len = *p;
/* Check that label length is valid.
* Each label consists of an octet length (of size 1) followed
* by the octet of the specified length (label_len). Then it
* must be followed by either another label's octet length or
* a zero length octet (that terminates the sequence).
*/
if (p+1+label_len+1 > max)
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Check that label length is valid.
* Each label consists of an octet length (of size 1) followed
* by the octet of the specified length (label_len). Then it
* must be followed by either another label's octet length or
* a zero length octet (that terminates the sequence).
*/
if (p+1+label_len+1 > max)
return PJLIB_UTIL_EDNSINNAMEPTR;
p += (label_len + 1);
*parsed_len += (label_len + 1);
p += (label_len + 1);
*parsed_len += (label_len + 1);
if (*p != 0)
++label_len;
*name_len += label_len;
}
if (*p != 0)
++label_len;
*name_len += label_len;
}
}
++p;
(*parsed_len)++;
@ -188,60 +187,60 @@ static pj_status_t get_name_len(int rec_counter, const pj_uint8_t *pkt,
* it may contain pointers when compression is applied).
*/
static pj_status_t get_name(int rec_counter, const pj_uint8_t *pkt,
const pj_uint8_t *start, const pj_uint8_t *max,
pj_str_t *name)
const pj_uint8_t *start, const pj_uint8_t *max,
pj_str_t *name)
{
const pj_uint8_t *p;
pj_status_t status;
/* Limit the number of recursion */
if (rec_counter > 10) {
/* Too many name recursion */
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Too many name recursion */
return PJLIB_UTIL_EDNSINNAMEPTR;
}
p = start;
while (*p) {
if ((*p & 0xc0) == 0xc0) {
/* Compression is found! */
pj_uint16_t offset;
if ((*p & 0xc0) == 0xc0) {
/* Compression is found! */
pj_uint16_t offset;
/* Get the 14bit offset */
pj_memcpy(&offset, p, 2);
offset ^= pj_htons((pj_uint16_t)(0xc0 << 8));
offset = pj_ntohs(offset);
/* Get the 14bit offset */
pj_memcpy(&offset, p, 2);
offset ^= pj_htons((pj_uint16_t)(0xc0 << 8));
offset = pj_ntohs(offset);
/* Check that offset is valid */
if (offset >= max - pkt)
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Check that offset is valid */
if (offset >= max - pkt)
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Retrieve the name from that offset. */
status = get_name(rec_counter+1, pkt, pkt + offset, max, name);
if (status != PJ_SUCCESS)
return status;
/* Retrieve the name from that offset. */
status = get_name(rec_counter+1, pkt, pkt + offset, max, name);
if (status != PJ_SUCCESS)
return status;
return PJ_SUCCESS;
} else {
unsigned label_len = *p;
return PJ_SUCCESS;
} else {
unsigned label_len = *p;
/* Check that label length is valid.
* Each label consists of an octet length (of size 1) followed
* by the octet of the specified length (label_len). Then it
* must be followed by either another label's octet length or
* a zero length octet (that terminates the sequence).
*/
if (p+1+label_len+1 > max)
return PJLIB_UTIL_EDNSINNAMEPTR;
/* Check that label length is valid.
* Each label consists of an octet length (of size 1) followed
* by the octet of the specified length (label_len). Then it
* must be followed by either another label's octet length or
* a zero length octet (that terminates the sequence).
*/
if (p+1+label_len+1 > max)
return PJLIB_UTIL_EDNSINNAMEPTR;
pj_memcpy(name->ptr + name->slen, p+1, label_len);
name->slen += label_len;
pj_memcpy(name->ptr + name->slen, p+1, label_len);
name->slen += label_len;
p += label_len + 1;
if (*p != 0) {
*(name->ptr + name->slen) = '.';
++name->slen;
}
}
p += label_len + 1;
if (*p != 0) {
*(name->ptr + name->slen) = '.';
++name->slen;
}
}
}
return PJ_SUCCESS;
@ -250,8 +249,8 @@ static pj_status_t get_name(int rec_counter, const pj_uint8_t *pkt,
/* Parse query records. */
static pj_status_t parse_query(pj_dns_parsed_query *q, pj_pool_t *pool,
const pj_uint8_t *pkt, const pj_uint8_t *start,
const pj_uint8_t *max, int *parsed_len)
const pj_uint8_t *pkt, const pj_uint8_t *start,
const pj_uint8_t *max, int *parsed_len)
{
const pj_uint8_t *p = start;
int name_len, name_part_len;
@ -260,7 +259,7 @@ static pj_status_t parse_query(pj_dns_parsed_query *q, pj_pool_t *pool,
/* Get the length of the name */
status = get_name_len(0, pkt, start, max, &name_part_len, &name_len);
if (status != PJ_SUCCESS)
return status;
return status;
/* Allocate memory for the name */
q->name.ptr = (char*) pj_pool_alloc(pool, name_len+4);
@ -269,13 +268,13 @@ static pj_status_t parse_query(pj_dns_parsed_query *q, pj_pool_t *pool,
/* Get the name */
status = get_name(0, pkt, start, max, &q->name);
if (status != PJ_SUCCESS)
return status;
return status;
p = (start + name_part_len);
/* Check the size can accomodate next few fields. */
if (p + 4 > max)
return PJLIB_UTIL_EDNSINSIZE;
return PJLIB_UTIL_EDNSINSIZE;
/* Get the type */
pj_memcpy(&q->type, p, 2);
@ -295,9 +294,9 @@ static pj_status_t parse_query(pj_dns_parsed_query *q, pj_pool_t *pool,
/* Parse RR records */
static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool,
const pj_uint8_t *pkt,
const pj_uint8_t *start, const pj_uint8_t *max,
int *parsed_len)
const pj_uint8_t *pkt,
const pj_uint8_t *start, const pj_uint8_t *max,
int *parsed_len)
{
const pj_uint8_t *p = start;
int name_len, name_part_len;
@ -306,7 +305,7 @@ static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool,
/* Get the length of the name */
status = get_name_len(0, pkt, start, max, &name_part_len, &name_len);
if (status != PJ_SUCCESS)
return status;
return status;
/* Allocate memory for the name */
rr->name.ptr = (char*) pj_pool_alloc(pool, name_len+4);
@ -315,13 +314,13 @@ static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool,
/* Get the name */
status = get_name(0, pkt, start, max, &rr->name);
if (status != PJ_SUCCESS)
return status;
return status;
p = (start + name_part_len);
/* Check the size can accomodate next few fields. */
if (p+10 > max)
return PJLIB_UTIL_EDNSINSIZE;
return PJLIB_UTIL_EDNSINSIZE;
/* Get the type */
pj_memcpy(&rr->type, p, 2);
@ -335,13 +334,13 @@ static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool,
/* Class MUST be IN */
if (rr->dnsclass != 1) {
/* Class is not IN, return error only if type is known (see #1889) */
if (rr->type == PJ_DNS_TYPE_A || rr->type == PJ_DNS_TYPE_AAAA ||
rr->type == PJ_DNS_TYPE_CNAME || rr->type == PJ_DNS_TYPE_NS ||
rr->type == PJ_DNS_TYPE_PTR || rr->type == PJ_DNS_TYPE_SRV)
{
return PJLIB_UTIL_EDNSINCLASS;
}
/* Class is not IN, return error only if type is known (see #1889) */
if (rr->type == PJ_DNS_TYPE_A || rr->type == PJ_DNS_TYPE_AAAA ||
rr->type == PJ_DNS_TYPE_CNAME || rr->type == PJ_DNS_TYPE_NS ||
rr->type == PJ_DNS_TYPE_PTR || rr->type == PJ_DNS_TYPE_SRV)
{
return PJLIB_UTIL_EDNSINCLASS;
}
}
/* Get TTL */
@ -356,76 +355,76 @@ static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool,
/* Check that length is valid */
if (p + rr->rdlength > max)
return PJLIB_UTIL_EDNSINSIZE;
return PJLIB_UTIL_EDNSINSIZE;
/* Parse some well known records */
if (rr->type == PJ_DNS_TYPE_A) {
pj_memcpy(&rr->rdata.a.ip_addr, p, 4);
p += 4;
pj_memcpy(&rr->rdata.a.ip_addr, p, 4);
p += 4;
} else if (rr->type == PJ_DNS_TYPE_AAAA) {
pj_memcpy(&rr->rdata.aaaa.ip_addr, p, 16);
p += 16;
pj_memcpy(&rr->rdata.aaaa.ip_addr, p, 16);
p += 16;
} else if (rr->type == PJ_DNS_TYPE_CNAME ||
rr->type == PJ_DNS_TYPE_NS ||
rr->type == PJ_DNS_TYPE_PTR)
rr->type == PJ_DNS_TYPE_NS ||
rr->type == PJ_DNS_TYPE_PTR)
{
/* Get the length of the target name */
status = get_name_len(0, pkt, p, max, &name_part_len, &name_len);
if (status != PJ_SUCCESS)
return status;
/* Get the length of the target name */
status = get_name_len(0, pkt, p, max, &name_part_len, &name_len);
if (status != PJ_SUCCESS)
return status;
/* Allocate memory for the name */
rr->rdata.cname.name.ptr = (char*) pj_pool_alloc(pool, name_len);
rr->rdata.cname.name.slen = 0;
/* Allocate memory for the name */
rr->rdata.cname.name.ptr = (char*) pj_pool_alloc(pool, name_len);
rr->rdata.cname.name.slen = 0;
/* Get the name */
status = get_name(0, pkt, p, max, &rr->rdata.cname.name);
if (status != PJ_SUCCESS)
return status;
/* Get the name */
status = get_name(0, pkt, p, max, &rr->rdata.cname.name);
if (status != PJ_SUCCESS)
return status;
p += name_part_len;
p += name_part_len;
} else if (rr->type == PJ_DNS_TYPE_SRV) {
/* Priority */
pj_memcpy(&rr->rdata.srv.prio, p, 2);
rr->rdata.srv.prio = pj_ntohs(rr->rdata.srv.prio);
p += 2;
/* Priority */
pj_memcpy(&rr->rdata.srv.prio, p, 2);
rr->rdata.srv.prio = pj_ntohs(rr->rdata.srv.prio);
p += 2;
/* Weight */
pj_memcpy(&rr->rdata.srv.weight, p, 2);
rr->rdata.srv.weight = pj_ntohs(rr->rdata.srv.weight);
p += 2;
/* Weight */
pj_memcpy(&rr->rdata.srv.weight, p, 2);
rr->rdata.srv.weight = pj_ntohs(rr->rdata.srv.weight);
p += 2;
/* Port */
pj_memcpy(&rr->rdata.srv.port, p, 2);
rr->rdata.srv.port = pj_ntohs(rr->rdata.srv.port);
p += 2;
/* Get the length of the target name */
status = get_name_len(0, pkt, p, max, &name_part_len, &name_len);
if (status != PJ_SUCCESS)
return status;
/* Port */
pj_memcpy(&rr->rdata.srv.port, p, 2);
rr->rdata.srv.port = pj_ntohs(rr->rdata.srv.port);
p += 2;
/* Get the length of the target name */
status = get_name_len(0, pkt, p, max, &name_part_len, &name_len);
if (status != PJ_SUCCESS)
return status;
/* Allocate memory for the name */
rr->rdata.srv.target.ptr = (char*) pj_pool_alloc(pool, name_len);
rr->rdata.srv.target.slen = 0;
/* Allocate memory for the name */
rr->rdata.srv.target.ptr = (char*) pj_pool_alloc(pool, name_len);
rr->rdata.srv.target.slen = 0;
/* Get the name */
status = get_name(0, pkt, p, max, &rr->rdata.srv.target);
if (status != PJ_SUCCESS)
return status;
p += name_part_len;
/* Get the name */
status = get_name(0, pkt, p, max, &rr->rdata.srv.target);
if (status != PJ_SUCCESS)
return status;
p += name_part_len;
} else {
/* Copy the raw data */
rr->data = pj_pool_alloc(pool, rr->rdlength);
pj_memcpy(rr->data, p, rr->rdlength);
/* Copy the raw data */
rr->data = pj_pool_alloc(pool, rr->rdlength);
pj_memcpy(rr->data, p, rr->rdlength);
p += rr->rdlength;
p += rr->rdlength;
}
*parsed_len = (int)(p - start);
@ -437,9 +436,9 @@ static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool,
* Parse raw DNS packet into DNS packet structure.
*/
PJ_DEF(pj_status_t) pj_dns_parse_packet( pj_pool_t *pool,
const void *packet,
unsigned size,
pj_dns_parsed_packet **p_res)
const void *packet,
unsigned size,
pj_dns_parsed_packet **p_res)
{
pj_dns_parsed_packet *res;
const pj_uint8_t *start, *end;
@ -451,14 +450,14 @@ PJ_DEF(pj_status_t) pj_dns_parse_packet( pj_pool_t *pool,
/* Packet size must be at least as big as the header */
if (size < sizeof(pj_dns_hdr))
return PJLIB_UTIL_EDNSINSIZE;
return PJLIB_UTIL_EDNSINSIZE;
/* Create the structure */
res = PJ_POOL_ZALLOC_T(pool, pj_dns_parsed_packet);
/* Copy the DNS header, and convert endianness to host byte order */
pj_memcpy(&res->hdr, packet, sizeof(pj_dns_hdr));
res->hdr.id = pj_ntohs(res->hdr.id);
res->hdr.id = pj_ntohs(res->hdr.id);
res->hdr.flags = pj_ntohs(res->hdr.flags);
res->hdr.qdcount = pj_ntohs(res->hdr.qdcount);
res->hdr.anscount = pj_ntohs(res->hdr.anscount);
@ -472,73 +471,73 @@ PJ_DEF(pj_status_t) pj_dns_parse_packet( pj_pool_t *pool,
/* Parse query records (if any).
*/
if (res->hdr.qdcount) {
res->q = (pj_dns_parsed_query*)
pj_pool_zalloc(pool, res->hdr.qdcount *
sizeof(pj_dns_parsed_query));
for (i=0; i<res->hdr.qdcount; ++i) {
int parsed_len = 0;
status = parse_query(&res->q[i], pool, (const pj_uint8_t*)packet,
start, end, &parsed_len);
if (status != PJ_SUCCESS)
return status;
res->q = (pj_dns_parsed_query*)
pj_pool_zalloc(pool, res->hdr.qdcount *
sizeof(pj_dns_parsed_query));
for (i=0; i<res->hdr.qdcount; ++i) {
int parsed_len = 0;
status = parse_query(&res->q[i], pool, (const pj_uint8_t*)packet,
start, end, &parsed_len);
if (status != PJ_SUCCESS)
return status;
start += parsed_len;
}
start += parsed_len;
}
}
/* Parse answer, if any */
if (res->hdr.anscount) {
res->ans = (pj_dns_parsed_rr*)
pj_pool_zalloc(pool, res->hdr.anscount *
sizeof(pj_dns_parsed_rr));
res->ans = (pj_dns_parsed_rr*)
pj_pool_zalloc(pool, res->hdr.anscount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<res->hdr.anscount; ++i) {
int parsed_len;
for (i=0; i<res->hdr.anscount; ++i) {
int parsed_len;
status = parse_rr(&res->ans[i], pool, (const pj_uint8_t*)packet,
start, end, &parsed_len);
if (status != PJ_SUCCESS)
return status;
status = parse_rr(&res->ans[i], pool, (const pj_uint8_t*)packet,
start, end, &parsed_len);
if (status != PJ_SUCCESS)
return status;
start += parsed_len;
}
start += parsed_len;
}
}
/* Parse authoritative NS records, if any */
if (res->hdr.nscount) {
res->ns = (pj_dns_parsed_rr*)
pj_pool_zalloc(pool, res->hdr.nscount *
sizeof(pj_dns_parsed_rr));
res->ns = (pj_dns_parsed_rr*)
pj_pool_zalloc(pool, res->hdr.nscount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<res->hdr.nscount; ++i) {
int parsed_len;
for (i=0; i<res->hdr.nscount; ++i) {
int parsed_len;
status = parse_rr(&res->ns[i], pool, (const pj_uint8_t*)packet,
start, end, &parsed_len);
if (status != PJ_SUCCESS)
return status;
status = parse_rr(&res->ns[i], pool, (const pj_uint8_t*)packet,
start, end, &parsed_len);
if (status != PJ_SUCCESS)
return status;
start += parsed_len;
}
start += parsed_len;
}
}
/* Parse additional RR answer, if any */
if (res->hdr.arcount) {
res->arr = (pj_dns_parsed_rr*)
pj_pool_zalloc(pool, res->hdr.arcount *
sizeof(pj_dns_parsed_rr));
res->arr = (pj_dns_parsed_rr*)
pj_pool_zalloc(pool, res->hdr.arcount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<res->hdr.arcount; ++i) {
int parsed_len;
for (i=0; i<res->hdr.arcount; ++i) {
int parsed_len;
status = parse_rr(&res->arr[i], pool, (const pj_uint8_t*)packet,
start, end, &parsed_len);
if (status != PJ_SUCCESS)
return status;
status = parse_rr(&res->arr[i], pool, (const pj_uint8_t*)packet,
start, end, &parsed_len);
if (status != PJ_SUCCESS)
return status;
start += parsed_len;
}
start += parsed_len;
}
}
/* Looks like everything is okay */
@ -553,41 +552,41 @@ PJ_DEF(pj_status_t) pj_dns_parse_packet( pj_pool_t *pool,
* the string with the pool, but rather just use the pointer there.
*/
static void apply_name_table( unsigned *count,
pj_str_t nametable[],
const pj_str_t *src,
pj_pool_t *pool,
pj_str_t *dst)
pj_str_t nametable[],
const pj_str_t *src,
pj_pool_t *pool,
pj_str_t *dst)
{
unsigned i;
/* Scan strings in nametable */
for (i=0; i<*count; ++i) {
if (pj_stricmp(&nametable[i], src) == 0)
break;
if (pj_stricmp(&nametable[i], src) == 0)
break;
}
/* If name is found in nametable, use the pointer in the nametable */
if (i != *count) {
dst->ptr = nametable[i].ptr;
dst->slen = nametable[i].slen;
return;
dst->ptr = nametable[i].ptr;
dst->slen = nametable[i].slen;
return;
}
/* Otherwise duplicate the string, and insert new name in nametable */
pj_strdup(pool, dst, src);
if (*count < PJ_DNS_MAX_NAMES_IN_NAMETABLE) {
nametable[*count].ptr = dst->ptr;
nametable[*count].slen = dst->slen;
nametable[*count].ptr = dst->ptr;
nametable[*count].slen = dst->slen;
++(*count);
++(*count);
}
}
static void copy_query(pj_pool_t *pool, pj_dns_parsed_query *dst,
const pj_dns_parsed_query *src,
unsigned *nametable_count,
pj_str_t nametable[])
const pj_dns_parsed_query *src,
unsigned *nametable_count,
pj_str_t nametable[])
{
pj_memcpy(dst, src, sizeof(*src));
apply_name_table(nametable_count, nametable, &src->name, pool, &dst->name);
@ -595,32 +594,32 @@ static void copy_query(pj_pool_t *pool, pj_dns_parsed_query *dst,
static void copy_rr(pj_pool_t *pool, pj_dns_parsed_rr *dst,
const pj_dns_parsed_rr *src,
unsigned *nametable_count,
pj_str_t nametable[])
const pj_dns_parsed_rr *src,
unsigned *nametable_count,
pj_str_t nametable[])
{
pj_memcpy(dst, src, sizeof(*src));
apply_name_table(nametable_count, nametable, &src->name, pool, &dst->name);
if (src->data) {
dst->data = pj_pool_alloc(pool, src->rdlength);
pj_memcpy(dst->data, src->data, src->rdlength);
dst->data = pj_pool_alloc(pool, src->rdlength);
pj_memcpy(dst->data, src->data, src->rdlength);
}
if (src->type == PJ_DNS_TYPE_SRV) {
apply_name_table(nametable_count, nametable, &src->rdata.srv.target,
pool, &dst->rdata.srv.target);
apply_name_table(nametable_count, nametable, &src->rdata.srv.target,
pool, &dst->rdata.srv.target);
} else if (src->type == PJ_DNS_TYPE_A) {
dst->rdata.a.ip_addr.s_addr = src->rdata.a.ip_addr.s_addr;
dst->rdata.a.ip_addr.s_addr = src->rdata.a.ip_addr.s_addr;
} else if (src->type == PJ_DNS_TYPE_AAAA) {
pj_memcpy(&dst->rdata.aaaa.ip_addr, &src->rdata.aaaa.ip_addr,
sizeof(pj_in6_addr));
pj_memcpy(&dst->rdata.aaaa.ip_addr, &src->rdata.aaaa.ip_addr,
sizeof(pj_in6_addr));
} else if (src->type == PJ_DNS_TYPE_CNAME) {
pj_strdup(pool, &dst->rdata.cname.name, &src->rdata.cname.name);
pj_strdup(pool, &dst->rdata.cname.name, &src->rdata.cname.name);
} else if (src->type == PJ_DNS_TYPE_NS) {
pj_strdup(pool, &dst->rdata.ns.name, &src->rdata.ns.name);
pj_strdup(pool, &dst->rdata.ns.name, &src->rdata.ns.name);
} else if (src->type == PJ_DNS_TYPE_PTR) {
pj_strdup(pool, &dst->rdata.ptr.name, &src->rdata.ptr.name);
pj_strdup(pool, &dst->rdata.ptr.name, &src->rdata.ptr.name);
}
}
@ -628,9 +627,9 @@ static void copy_rr(pj_pool_t *pool, pj_dns_parsed_rr *dst,
* Duplicate DNS packet.
*/
PJ_DEF(void) pj_dns_packet_dup(pj_pool_t *pool,
const pj_dns_parsed_packet*p,
unsigned options,
pj_dns_parsed_packet **p_dst)
const pj_dns_parsed_packet*p,
unsigned options,
pj_dns_parsed_packet **p_dst)
{
pj_dns_parsed_packet *dst;
unsigned nametable_count = 0;
@ -655,66 +654,66 @@ PJ_DEF(void) pj_dns_packet_dup(pj_pool_t *pool,
dst->hdr.anscount = 0;
dst->hdr.nscount = 0;
dst->hdr.arcount = 0;
/* Copy query section */
if (p->hdr.qdcount && (options & PJ_DNS_NO_QD)==0) {
dst->q = (pj_dns_parsed_query*)
pj_pool_alloc(pool, p->hdr.qdcount *
sizeof(pj_dns_parsed_query));
for (i=0; i<p->hdr.qdcount; ++i) {
copy_query(pool, &dst->q[i], &p->q[i],
&nametable_count, nametable);
++dst->hdr.qdcount;
}
dst->q = (pj_dns_parsed_query*)
pj_pool_alloc(pool, p->hdr.qdcount *
sizeof(pj_dns_parsed_query));
for (i=0; i<p->hdr.qdcount; ++i) {
copy_query(pool, &dst->q[i], &p->q[i],
&nametable_count, nametable);
++dst->hdr.qdcount;
}
}
/* Copy answer section */
if (p->hdr.anscount && (options & PJ_DNS_NO_ANS)==0) {
dst->ans = (pj_dns_parsed_rr*)
pj_pool_alloc(pool, p->hdr.anscount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<p->hdr.anscount; ++i) {
copy_rr(pool, &dst->ans[i], &p->ans[i],
&nametable_count, nametable);
++dst->hdr.anscount;
}
dst->ans = (pj_dns_parsed_rr*)
pj_pool_alloc(pool, p->hdr.anscount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<p->hdr.anscount; ++i) {
copy_rr(pool, &dst->ans[i], &p->ans[i],
&nametable_count, nametable);
++dst->hdr.anscount;
}
}
/* Copy NS section */
if (p->hdr.nscount && (options & PJ_DNS_NO_NS)==0) {
dst->ns = (pj_dns_parsed_rr*)
pj_pool_alloc(pool, p->hdr.nscount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<p->hdr.nscount; ++i) {
copy_rr(pool, &dst->ns[i], &p->ns[i],
&nametable_count, nametable);
++dst->hdr.nscount;
}
dst->ns = (pj_dns_parsed_rr*)
pj_pool_alloc(pool, p->hdr.nscount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<p->hdr.nscount; ++i) {
copy_rr(pool, &dst->ns[i], &p->ns[i],
&nametable_count, nametable);
++dst->hdr.nscount;
}
}
/* Copy additional info section */
if (p->hdr.arcount && (options & PJ_DNS_NO_AR)==0) {
dst->arr = (pj_dns_parsed_rr*)
pj_pool_alloc(pool, p->hdr.arcount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<p->hdr.arcount; ++i) {
copy_rr(pool, &dst->arr[i], &p->arr[i],
&nametable_count, nametable);
++dst->hdr.arcount;
}
dst->arr = (pj_dns_parsed_rr*)
pj_pool_alloc(pool, p->hdr.arcount *
sizeof(pj_dns_parsed_rr));
for (i=0; i<p->hdr.arcount; ++i) {
copy_rr(pool, &dst->arr[i], &p->arr[i],
&nametable_count, nametable);
++dst->hdr.arcount;
}
}
}
PJ_DEF(void) pj_dns_init_srv_rr( pj_dns_parsed_rr *rec,
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
unsigned prio,
unsigned weight,
unsigned port,
const pj_str_t *target)
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
unsigned prio,
unsigned weight,
unsigned port,
const pj_str_t *target)
{
pj_bzero(rec, sizeof(*rec));
rec->name = *res_name;
@ -729,10 +728,10 @@ PJ_DEF(void) pj_dns_init_srv_rr( pj_dns_parsed_rr *rec,
PJ_DEF(void) pj_dns_init_cname_rr( pj_dns_parsed_rr *rec,
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_str_t *name)
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_str_t *name)
{
pj_bzero(rec, sizeof(*rec));
rec->name = *res_name;
@ -744,10 +743,10 @@ PJ_DEF(void) pj_dns_init_cname_rr( pj_dns_parsed_rr *rec,
PJ_DEF(void) pj_dns_init_a_rr( pj_dns_parsed_rr *rec,
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_in_addr *ip_addr)
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_in_addr *ip_addr)
{
pj_bzero(rec, sizeof(*rec));
rec->name = *res_name;
@ -759,10 +758,10 @@ PJ_DEF(void) pj_dns_init_a_rr( pj_dns_parsed_rr *rec,
PJ_DEF(void) pj_dns_init_aaaa_rr(pj_dns_parsed_rr *rec,
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_in6_addr *ip_addr)
const pj_str_t *res_name,
unsigned dnsclass,
unsigned ttl,
const pj_in6_addr *ip_addr)
{
pj_bzero(rec, sizeof(*rec));
rec->name = *res_name;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -23,51 +22,51 @@
#include <pj/string.h>
#define THIS_FILE "dns_dump.c"
#define LEVEL 3
#define LEVEL 3
static const char *spell_ttl(char *buf, int size, unsigned ttl)
{
#define DAY (3600*24)
#define HOUR (3600)
#define MINUTE (60)
#define DAY (3600*24)
#define HOUR (3600)
#define MINUTE (60)
char *p = buf;
int len;
if (ttl > DAY) {
len = pj_ansi_snprintf(p, size, "%dd ", ttl/DAY);
if (len < 1 || len >= size)
return "-err-";
size -= len;
p += len;
ttl %= DAY;
len = pj_ansi_snprintf(p, size, "%dd ", ttl/DAY);
if (len < 1 || len >= size)
return "-err-";
size -= len;
p += len;
ttl %= DAY;
}
if (ttl > HOUR) {
len = pj_ansi_snprintf(p, size, "%dh ", ttl/HOUR);
if (len < 1 || len >= size)
return "-err-";
size -= len;
p += len;
ttl %= HOUR;
len = pj_ansi_snprintf(p, size, "%dh ", ttl/HOUR);
if (len < 1 || len >= size)
return "-err-";
size -= len;
p += len;
ttl %= HOUR;
}
if (ttl > MINUTE) {
len = pj_ansi_snprintf(p, size, "%dm ", ttl/MINUTE);
if (len < 1 || len >= size)
return "-err-";
size -= len;
p += len;
ttl %= MINUTE;
len = pj_ansi_snprintf(p, size, "%dm ", ttl/MINUTE);
if (len < 1 || len >= size)
return "-err-";
size -= len;
p += len;
ttl %= MINUTE;
}
if (ttl > 0) {
len = pj_ansi_snprintf(p, size, "%ds ", ttl);
if (len < 1 || len >= size)
return "-err-";
size -= len;
p += len;
ttl = 0;
len = pj_ansi_snprintf(p, size, "%ds ", ttl);
if (len < 1 || len >= size)
return "-err-";
size -= len;
p += len;
ttl = 0;
}
*p = '\0';
@ -78,11 +77,11 @@ static const char *spell_ttl(char *buf, int size, unsigned ttl)
static void dump_query(unsigned index, const pj_dns_parsed_query *q)
{
PJ_LOG(3,(THIS_FILE, " %d. Name: %.*s",
index, (int)q->name.slen, q->name.ptr));
index, (int)q->name.slen, q->name.ptr));
PJ_LOG(3,(THIS_FILE, " Type: %s (%d)",
pj_dns_get_type_name(q->type), q->type));
pj_dns_get_type_name(q->type), q->type));
PJ_LOG(3,(THIS_FILE, " Class: %s (%d)",
(q->dnsclass==1 ? "IN" : "<Unknown>"), q->dnsclass));
(q->dnsclass==1 ? "IN" : "<Unknown>"), q->dnsclass));
}
static void dump_answer(unsigned index, const pj_dns_parsed_rr *rr)
@ -93,37 +92,37 @@ static void dump_answer(unsigned index, const pj_dns_parsed_rr *rr)
char addr[PJ_INET6_ADDRSTRLEN];
if (name->slen == 0)
name = &root_name;
name = &root_name;
PJ_LOG(3,(THIS_FILE, " %d. %s record (type=%d)",
index, pj_dns_get_type_name(rr->type),
rr->type));
index, pj_dns_get_type_name(rr->type),
rr->type));
PJ_LOG(3,(THIS_FILE, " Name: %.*s", (int)name->slen, name->ptr));
PJ_LOG(3,(THIS_FILE, " TTL: %u (%s)", rr->ttl,
spell_ttl(ttl_words, sizeof(ttl_words), rr->ttl)));
spell_ttl(ttl_words, sizeof(ttl_words), rr->ttl)));
PJ_LOG(3,(THIS_FILE, " Data length: %u", rr->rdlength));
if (rr->type == PJ_DNS_TYPE_SRV) {
PJ_LOG(3,(THIS_FILE, " SRV: prio=%d, weight=%d %.*s:%d",
rr->rdata.srv.prio, rr->rdata.srv.weight,
(int)rr->rdata.srv.target.slen,
rr->rdata.srv.target.ptr,
rr->rdata.srv.port));
PJ_LOG(3,(THIS_FILE, " SRV: prio=%d, weight=%d %.*s:%d",
rr->rdata.srv.prio, rr->rdata.srv.weight,
(int)rr->rdata.srv.target.slen,
rr->rdata.srv.target.ptr,
rr->rdata.srv.port));
} else if (rr->type == PJ_DNS_TYPE_CNAME ||
rr->type == PJ_DNS_TYPE_NS ||
rr->type == PJ_DNS_TYPE_PTR)
rr->type == PJ_DNS_TYPE_NS ||
rr->type == PJ_DNS_TYPE_PTR)
{
PJ_LOG(3,(THIS_FILE, " Name: %.*s",
(int)rr->rdata.cname.name.slen,
rr->rdata.cname.name.ptr));
PJ_LOG(3,(THIS_FILE, " Name: %.*s",
(int)rr->rdata.cname.name.slen,
rr->rdata.cname.name.ptr));
} else if (rr->type == PJ_DNS_TYPE_A) {
PJ_LOG(3,(THIS_FILE, " IP address: %s",
pj_inet_ntop2(pj_AF_INET(), &rr->rdata.a.ip_addr,
addr, sizeof(addr))));
PJ_LOG(3,(THIS_FILE, " IP address: %s",
pj_inet_ntop2(pj_AF_INET(), &rr->rdata.a.ip_addr,
addr, sizeof(addr))));
} else if (rr->type == PJ_DNS_TYPE_AAAA) {
PJ_LOG(3,(THIS_FILE, " IPv6 address: %s",
pj_inet_ntop2(pj_AF_INET6(), &rr->rdata.aaaa.ip_addr,
addr, sizeof(addr))));
PJ_LOG(3,(THIS_FILE, " IPv6 address: %s",
pj_inet_ntop2(pj_AF_INET6(), &rr->rdata.aaaa.ip_addr,
addr, sizeof(addr))));
}
}
@ -136,14 +135,14 @@ PJ_DEF(void) pj_dns_dump_packet(const pj_dns_parsed_packet *res)
/* Header part */
PJ_LOG(3,(THIS_FILE, "Domain Name System packet (%s):",
(PJ_DNS_GET_QR(res->hdr.flags) ? "response" : "query")));
(PJ_DNS_GET_QR(res->hdr.flags) ? "response" : "query")));
PJ_LOG(3,(THIS_FILE, " Transaction ID: %d", res->hdr.id));
PJ_LOG(3,(THIS_FILE,
" Flags: opcode=%d, authoritative=%d, truncated=%d, rcode=%d",
PJ_DNS_GET_OPCODE(res->hdr.flags),
PJ_DNS_GET_AA(res->hdr.flags),
PJ_DNS_GET_TC(res->hdr.flags),
PJ_DNS_GET_RCODE(res->hdr.flags)));
" Flags: opcode=%d, authoritative=%d, truncated=%d, rcode=%d",
PJ_DNS_GET_OPCODE(res->hdr.flags),
PJ_DNS_GET_AA(res->hdr.flags),
PJ_DNS_GET_TC(res->hdr.flags),
PJ_DNS_GET_RCODE(res->hdr.flags)));
PJ_LOG(3,(THIS_FILE, " Nb of queries: %d", res->hdr.qdcount));
PJ_LOG(3,(THIS_FILE, " Nb of answer RR: %d", res->hdr.anscount));
PJ_LOG(3,(THIS_FILE, " Nb of authority RR: %d", res->hdr.nscount));
@ -152,42 +151,42 @@ PJ_DEF(void) pj_dns_dump_packet(const pj_dns_parsed_packet *res)
/* Dump queries */
if (res->hdr.qdcount) {
PJ_LOG(3,(THIS_FILE, " Queries:"));
PJ_LOG(3,(THIS_FILE, " Queries:"));
for (i=0; i<res->hdr.qdcount; ++i) {
dump_query(i, &res->q[i]);
}
PJ_LOG(3,(THIS_FILE, ""));
for (i=0; i<res->hdr.qdcount; ++i) {
dump_query(i, &res->q[i]);
}
PJ_LOG(3,(THIS_FILE, ""));
}
/* Dump answers */
if (res->hdr.anscount) {
PJ_LOG(3,(THIS_FILE, " Answers RR:"));
PJ_LOG(3,(THIS_FILE, " Answers RR:"));
for (i=0; i<res->hdr.anscount; ++i) {
dump_answer(i, &res->ans[i]);
}
PJ_LOG(3,(THIS_FILE, ""));
for (i=0; i<res->hdr.anscount; ++i) {
dump_answer(i, &res->ans[i]);
}
PJ_LOG(3,(THIS_FILE, ""));
}
/* Dump NS sections */
if (res->hdr.nscount) {
PJ_LOG(3,(THIS_FILE, " NS Authority RR:"));
PJ_LOG(3,(THIS_FILE, " NS Authority RR:"));
for (i=0; i<res->hdr.nscount; ++i) {
dump_answer(i, &res->ns[i]);
}
PJ_LOG(3,(THIS_FILE, ""));
for (i=0; i<res->hdr.nscount; ++i) {
dump_answer(i, &res->ns[i]);
}
PJ_LOG(3,(THIS_FILE, ""));
}
/* Dump Additional info sections */
if (res->hdr.arcount) {
PJ_LOG(3,(THIS_FILE, " Additional Info RR:"));
PJ_LOG(3,(THIS_FILE, " Additional Info RR:"));
for (i=0; i<res->hdr.arcount; ++i) {
dump_answer(i, &res->arr[i]);
}
PJ_LOG(3,(THIS_FILE, ""));
for (i=0; i<res->hdr.arcount; ++i) {
dump_answer(i, &res->arr[i]);
}
PJ_LOG(3,(THIS_FILE, ""));
}
}

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -27,8 +26,8 @@
#include <pj/string.h>
#define THIS_FILE "dns_server.c"
#define MAX_ANS 16
#define MAX_PKT 1500
#define MAX_ANS 16
#define MAX_PKT 1500
#define MAX_LABEL 32
struct label_tab
@ -36,42 +35,42 @@ struct label_tab
unsigned count;
struct {
unsigned pos;
pj_str_t label;
unsigned pos;
pj_str_t label;
} a[MAX_LABEL];
};
struct rr
{
PJ_DECL_LIST_MEMBER(struct rr);
pj_dns_parsed_rr rec;
pj_dns_parsed_rr rec;
};
struct pj_dns_server
{
pj_pool_t *pool;
pj_pool_factory *pf;
pj_activesock_t *asock;
pj_ioqueue_op_key_t send_key;
struct rr rr_list;
pj_pool_t *pool;
pj_pool_factory *pf;
pj_activesock_t *asock;
pj_ioqueue_op_key_t send_key;
struct rr rr_list;
};
static pj_bool_t on_data_recvfrom(pj_activesock_t *asock,
void *data,
pj_size_t size,
const pj_sockaddr_t *src_addr,
int addr_len,
pj_status_t status);
void *data,
pj_size_t size,
const pj_sockaddr_t *src_addr,
int addr_len,
pj_status_t status);
PJ_DEF(pj_status_t) pj_dns_server_create( pj_pool_factory *pf,
pj_ioqueue_t *ioqueue,
int af,
unsigned port,
unsigned flags,
pj_dns_server **p_srv)
pj_ioqueue_t *ioqueue,
int af,
unsigned port,
unsigned flags,
pj_dns_server **p_srv)
{
pj_pool_t *pool;
pj_dns_server *srv;
@ -96,15 +95,15 @@ PJ_DEF(pj_status_t) pj_dns_server_create( pj_pool_factory *pf,
sock_cb.on_data_recvfrom = &on_data_recvfrom;
status = pj_activesock_create_udp(pool, &sock_addr, NULL, ioqueue,
&sock_cb, srv, &srv->asock, NULL);
&sock_cb, srv, &srv->asock, NULL);
if (status != PJ_SUCCESS)
goto on_error;
goto on_error;
pj_ioqueue_op_key_init(&srv->send_key, sizeof(srv->send_key));
status = pj_activesock_start_recvfrom(srv->asock, pool, MAX_PKT, 0);
if (status != PJ_SUCCESS)
goto on_error;
goto on_error;
*p_srv = srv;
return PJ_SUCCESS;
@ -120,8 +119,8 @@ PJ_DEF(pj_status_t) pj_dns_server_destroy(pj_dns_server *srv)
PJ_ASSERT_RETURN(srv, PJ_EINVAL);
if (srv->asock) {
pj_activesock_close(srv->asock);
srv->asock = NULL;
pj_activesock_close(srv->asock);
srv->asock = NULL;
}
pj_pool_safe_release(&srv->pool);
@ -131,20 +130,20 @@ PJ_DEF(pj_status_t) pj_dns_server_destroy(pj_dns_server *srv)
static struct rr* find_rr( pj_dns_server *srv,
unsigned dns_class,
unsigned type /* pj_dns_type */,
const pj_str_t *name)
unsigned dns_class,
unsigned type /* pj_dns_type */,
const pj_str_t *name)
{
struct rr *r;
r = srv->rr_list.next;
while (r != &srv->rr_list) {
if (r->rec.dnsclass == dns_class && r->rec.type == type &&
pj_stricmp(&r->rec.name, name)==0)
{
return r;
}
r = r->next;
if (r->rec.dnsclass == dns_class && r->rec.type == type &&
pj_stricmp(&r->rec.name, name)==0)
{
return r;
}
r = r->next;
}
return NULL;
@ -152,24 +151,24 @@ static struct rr* find_rr( pj_dns_server *srv,
PJ_DEF(pj_status_t) pj_dns_server_add_rec( pj_dns_server *srv,
unsigned count,
const pj_dns_parsed_rr rr_param[])
unsigned count,
const pj_dns_parsed_rr rr_param[])
{
unsigned i;
PJ_ASSERT_RETURN(srv && count && rr_param, PJ_EINVAL);
for (i=0; i<count; ++i) {
struct rr *rr;
struct rr *rr;
PJ_ASSERT_RETURN(find_rr(srv, rr_param[i].dnsclass, rr_param[i].type,
&rr_param[i].name) == NULL,
PJ_EEXISTS);
PJ_ASSERT_RETURN(find_rr(srv, rr_param[i].dnsclass, rr_param[i].type,
&rr_param[i].name) == NULL,
PJ_EEXISTS);
rr = (struct rr*) PJ_POOL_ZALLOC_T(srv->pool, struct rr);
pj_memcpy(&rr->rec, &rr_param[i], sizeof(pj_dns_parsed_rr));
rr = (struct rr*) PJ_POOL_ZALLOC_T(srv->pool, struct rr);
pj_memcpy(&rr->rec, &rr_param[i], sizeof(pj_dns_parsed_rr));
pj_list_push_back(&srv->rr_list, rr);
pj_list_push_back(&srv->rr_list, rr);
}
return PJ_SUCCESS;
@ -177,9 +176,9 @@ PJ_DEF(pj_status_t) pj_dns_server_add_rec( pj_dns_server *srv,
PJ_DEF(pj_status_t) pj_dns_server_del_rec( pj_dns_server *srv,
int dns_class,
pj_dns_type type,
const pj_str_t *name)
int dns_class,
pj_dns_type type,
const pj_str_t *name)
{
struct rr *rr;
@ -187,7 +186,7 @@ PJ_DEF(pj_status_t) pj_dns_server_del_rec( pj_dns_server *srv,
rr = find_rr(srv, dns_class, type, name);
if (!rr)
return PJ_ENOTFOUND;
return PJ_ENOTFOUND;
pj_list_erase(rr);
@ -208,8 +207,8 @@ static void write32(pj_uint8_t *p, pj_uint32_t val)
}
static int print_name(pj_uint8_t *pkt, int size,
pj_uint8_t *pos, const pj_str_t *name,
struct label_tab *tab)
pj_uint8_t *pos, const pj_str_t *name,
struct label_tab *tab)
{
pj_uint8_t *p = pos;
const char *endlabel, *endname;
@ -218,20 +217,20 @@ static int print_name(pj_uint8_t *pkt, int size,
/* Check if name is in the table */
for (i=0; i<tab->count; ++i) {
if (pj_strcmp(&tab->a[i].label, name)==0)
break;
if (pj_strcmp(&tab->a[i].label, name)==0)
break;
}
if (i != tab->count) {
write16(p, (pj_uint16_t)(tab->a[i].pos | (0xc0 << 8)));
return 2;
write16(p, (pj_uint16_t)(tab->a[i].pos | (0xc0 << 8)));
return 2;
} else {
if (tab->count < MAX_LABEL) {
tab->a[tab->count].pos = (unsigned)(p-pkt);
tab->a[tab->count].label.ptr = (char*)(p+1);
tab->a[tab->count].label.slen = name->slen;
++tab->count;
}
if (tab->count < MAX_LABEL) {
tab->a[tab->count].pos = (unsigned)(p-pkt);
tab->a[tab->count].label.ptr = (char*)(p+1);
tab->a[tab->count].label.slen = name->slen;
++tab->count;
}
}
endlabel = name->ptr;
@ -241,27 +240,27 @@ static int print_name(pj_uint8_t *pkt, int size,
while (endlabel != endname) {
while (endlabel != endname && *endlabel != '.')
++endlabel;
while (endlabel != endname && *endlabel != '.')
++endlabel;
label.slen = (endlabel - label.ptr);
label.slen = (endlabel - label.ptr);
if (size < label.slen+1)
return -1;
if (size < label.slen+1)
return -1;
*p = (pj_uint8_t)label.slen;
pj_memcpy(p+1, label.ptr, label.slen);
*p = (pj_uint8_t)label.slen;
pj_memcpy(p+1, label.ptr, label.slen);
size -= (int)(label.slen+1);
p += (label.slen+1);
size -= (int)(label.slen+1);
p += (label.slen+1);
if (endlabel != endname && *endlabel == '.')
++endlabel;
label.ptr = (char*)endlabel;
if (endlabel != endname && *endlabel == '.')
++endlabel;
label.ptr = (char*)endlabel;
}
if (size == 0)
return -1;
return -1;
*p++ = '\0';
@ -269,104 +268,104 @@ static int print_name(pj_uint8_t *pkt, int size,
}
static int print_rr(pj_uint8_t *pkt, int size, pj_uint8_t *pos,
const pj_dns_parsed_rr *rr, struct label_tab *tab)
const pj_dns_parsed_rr *rr, struct label_tab *tab)
{
pj_uint8_t *p = pos;
int len;
len = print_name(pkt, size, pos, &rr->name, tab);
if (len < 0)
return -1;
return -1;
p += len;
size -= len;
if (size < 8)
return -1;
return -1;
pj_assert(rr->dnsclass == 1);
write16(p+0, (pj_uint16_t)rr->type); /* type */
write16(p+2, (pj_uint16_t)rr->dnsclass); /* class */
write32(p+4, rr->ttl); /* TTL */
write16(p+0, (pj_uint16_t)rr->type); /* type */
write16(p+2, (pj_uint16_t)rr->dnsclass); /* class */
write32(p+4, rr->ttl); /* TTL */
p += 8;
size -= 8;
if (rr->type == PJ_DNS_TYPE_A) {
if (size < 6)
return -1;
if (size < 6)
return -1;
/* RDLEN is 4 */
write16(p, 4);
/* RDLEN is 4 */
write16(p, 4);
/* Address */
pj_memcpy(p+2, &rr->rdata.a.ip_addr, 4);
/* Address */
pj_memcpy(p+2, &rr->rdata.a.ip_addr, 4);
p += 6;
size -= 6;
p += 6;
size -= 6;
} else if (rr->type == PJ_DNS_TYPE_AAAA) {
if (size < 18)
return -1;
if (size < 18)
return -1;
/* RDLEN is 16 */
write16(p, 16);
/* RDLEN is 16 */
write16(p, 16);
/* Address */
pj_memcpy(p+2, &rr->rdata.aaaa.ip_addr, 16);
/* Address */
pj_memcpy(p+2, &rr->rdata.aaaa.ip_addr, 16);
p += 18;
size -= 18;
p += 18;
size -= 18;
} else if (rr->type == PJ_DNS_TYPE_CNAME ||
rr->type == PJ_DNS_TYPE_NS ||
rr->type == PJ_DNS_TYPE_PTR) {
rr->type == PJ_DNS_TYPE_NS ||
rr->type == PJ_DNS_TYPE_PTR) {
if (size < 4)
return -1;
if (size < 4)
return -1;
len = print_name(pkt, size-2, p+2, &rr->rdata.cname.name, tab);
if (len < 0)
return -1;
len = print_name(pkt, size-2, p+2, &rr->rdata.cname.name, tab);
if (len < 0)
return -1;
write16(p, (pj_uint16_t)len);
write16(p, (pj_uint16_t)len);
p += (len + 2);
size -= (len + 2);
p += (len + 2);
size -= (len + 2);
} else if (rr->type == PJ_DNS_TYPE_SRV) {
if (size < 10)
return -1;
if (size < 10)
return -1;
write16(p+2, rr->rdata.srv.prio); /* Priority */
write16(p+4, rr->rdata.srv.weight); /* Weight */
write16(p+6, rr->rdata.srv.port); /* Port */
write16(p+2, rr->rdata.srv.prio); /* Priority */
write16(p+4, rr->rdata.srv.weight); /* Weight */
write16(p+6, rr->rdata.srv.port); /* Port */
/* Target */
len = print_name(pkt, size-8, p+8, &rr->rdata.srv.target, tab);
if (len < 0)
return -1;
/* Target */
len = print_name(pkt, size-8, p+8, &rr->rdata.srv.target, tab);
if (len < 0)
return -1;
/* RDLEN */
write16(p, (pj_uint16_t)(len + 6));
/* RDLEN */
write16(p, (pj_uint16_t)(len + 6));
p += (len + 8);
size -= (len + 8);
p += (len + 8);
size -= (len + 8);
} else {
pj_assert(!"Not supported");
return -1;
pj_assert(!"Not supported");
return -1;
}
return (int)(p-pos);
}
static int print_packet(const pj_dns_parsed_packet *rec, pj_uint8_t *pkt,
int size)
int size)
{
pj_uint8_t *p = pkt;
struct label_tab tab;
@ -376,7 +375,7 @@ static int print_packet(const pj_dns_parsed_packet *rec, pj_uint8_t *pkt,
pj_assert(sizeof(pj_dns_hdr)==12);
if (size < (int)sizeof(pj_dns_hdr))
return -1;
return -1;
/* Initialize header */
write16(p+0, rec->hdr.id);
@ -392,54 +391,54 @@ static int print_packet(const pj_dns_parsed_packet *rec, pj_uint8_t *pkt,
/* Print queries */
for (i=0; i<rec->hdr.qdcount; ++i) {
len = print_name(pkt, size, p, &rec->q[i].name, &tab);
if (len < 0)
return -1;
len = print_name(pkt, size, p, &rec->q[i].name, &tab);
if (len < 0)
return -1;
p += len;
size -= len;
p += len;
size -= len;
if (size < 4)
return -1;
if (size < 4)
return -1;
/* Set type */
write16(p+0, (pj_uint16_t)rec->q[i].type);
/* Set type */
write16(p+0, (pj_uint16_t)rec->q[i].type);
/* Set class (IN=1) */
pj_assert(rec->q[i].dnsclass == 1);
write16(p+2, rec->q[i].dnsclass);
/* Set class (IN=1) */
pj_assert(rec->q[i].dnsclass == 1);
write16(p+2, rec->q[i].dnsclass);
p += 4;
p += 4;
}
/* Print answers */
for (i=0; i<rec->hdr.anscount; ++i) {
len = print_rr(pkt, size, p, &rec->ans[i], &tab);
if (len < 0)
return -1;
len = print_rr(pkt, size, p, &rec->ans[i], &tab);
if (len < 0)
return -1;
p += len;
size -= len;
p += len;
size -= len;
}
/* Print NS records */
for (i=0; i<rec->hdr.nscount; ++i) {
len = print_rr(pkt, size, p, &rec->ns[i], &tab);
if (len < 0)
return -1;
len = print_rr(pkt, size, p, &rec->ns[i], &tab);
if (len < 0)
return -1;
p += len;
size -= len;
p += len;
size -= len;
}
/* Print additional records */
for (i=0; i<rec->hdr.arcount; ++i) {
len = print_rr(pkt, size, p, &rec->arr[i], &tab);
if (len < 0)
return -1;
len = print_rr(pkt, size, p, &rec->arr[i], &tab);
if (len < 0)
return -1;
p += len;
size -= len;
p += len;
size -= len;
}
return (int)(p - pkt);
@ -447,11 +446,11 @@ static int print_packet(const pj_dns_parsed_packet *rec, pj_uint8_t *pkt,
static pj_bool_t on_data_recvfrom(pj_activesock_t *asock,
void *data,
pj_size_t size,
const pj_sockaddr_t *src_addr,
int addr_len,
pj_status_t status)
void *data,
pj_size_t size,
const pj_sockaddr_t *src_addr,
int addr_len,
pj_status_t status)
{
pj_dns_server *srv;
pj_pool_t *pool;
@ -462,18 +461,18 @@ static pj_bool_t on_data_recvfrom(pj_activesock_t *asock,
unsigned i;
if (status != PJ_SUCCESS)
return PJ_TRUE;
return PJ_TRUE;
srv = (pj_dns_server*) pj_activesock_get_user_data(asock);
pool = pj_pool_create(srv->pf, "dnssrvrx", 512, 256, NULL);
status = pj_dns_parse_packet(pool, data, (unsigned)size, &req);
if (status != PJ_SUCCESS) {
char addrinfo[PJ_INET6_ADDRSTRLEN+10];
pj_sockaddr_print(src_addr, addrinfo, sizeof(addrinfo), 3);
PJ_PERROR(4,(THIS_FILE, status, "Error parsing query from %s",
addrinfo));
goto on_return;
char addrinfo[PJ_INET6_ADDRSTRLEN+10];
pj_sockaddr_print(src_addr, addrinfo, sizeof(addrinfo), 3);
PJ_PERROR(4,(THIS_FILE, status, "Error parsing query from %s",
addrinfo));
goto on_return;
}
/* Init answer */
@ -484,78 +483,78 @@ static pj_bool_t on_data_recvfrom(pj_activesock_t *asock,
pj_memcpy(ans.q, req->q, sizeof(pj_dns_parsed_query));
if (req->hdr.qdcount != 1) {
ans.hdr.flags = PJ_DNS_SET_RCODE(PJ_DNS_RCODE_FORMERR);
goto send_pkt;
ans.hdr.flags = PJ_DNS_SET_RCODE(PJ_DNS_RCODE_FORMERR);
goto send_pkt;
}
if (req->q[0].dnsclass != PJ_DNS_CLASS_IN) {
ans.hdr.flags = PJ_DNS_SET_RCODE(PJ_DNS_RCODE_NOTIMPL);
goto send_pkt;
ans.hdr.flags = PJ_DNS_SET_RCODE(PJ_DNS_RCODE_NOTIMPL);
goto send_pkt;
}
/* Find the record */
rr = find_rr(srv, req->q->dnsclass, req->q->type, &req->q->name);
if (rr == NULL) {
ans.hdr.flags = PJ_DNS_SET_RCODE(PJ_DNS_RCODE_NXDOMAIN);
goto send_pkt;
ans.hdr.flags = PJ_DNS_SET_RCODE(PJ_DNS_RCODE_NXDOMAIN);
goto send_pkt;
}
/* Init answer record */
ans.hdr.anscount = 0;
ans.ans = (pj_dns_parsed_rr*)
pj_pool_calloc(pool, MAX_ANS, sizeof(pj_dns_parsed_rr));
pj_pool_calloc(pool, MAX_ANS, sizeof(pj_dns_parsed_rr));
/* DNS SRV query needs special treatment since it returns multiple
* records
*/
if (req->q->type == PJ_DNS_TYPE_SRV) {
struct rr *r;
struct rr *r;
r = srv->rr_list.next;
while (r != &srv->rr_list) {
if (r->rec.dnsclass == req->q->dnsclass &&
r->rec.type == PJ_DNS_TYPE_SRV &&
pj_stricmp(&r->rec.name, &req->q->name)==0 &&
ans.hdr.anscount < MAX_ANS)
{
pj_memcpy(&ans.ans[ans.hdr.anscount], &r->rec,
sizeof(pj_dns_parsed_rr));
++ans.hdr.anscount;
}
r = r->next;
}
r = srv->rr_list.next;
while (r != &srv->rr_list) {
if (r->rec.dnsclass == req->q->dnsclass &&
r->rec.type == PJ_DNS_TYPE_SRV &&
pj_stricmp(&r->rec.name, &req->q->name)==0 &&
ans.hdr.anscount < MAX_ANS)
{
pj_memcpy(&ans.ans[ans.hdr.anscount], &r->rec,
sizeof(pj_dns_parsed_rr));
++ans.hdr.anscount;
}
r = r->next;
}
} else {
/* Otherwise just copy directly from the server record */
pj_memcpy(&ans.ans[ans.hdr.anscount], &rr->rec,
sizeof(pj_dns_parsed_rr));
++ans.hdr.anscount;
/* Otherwise just copy directly from the server record */
pj_memcpy(&ans.ans[ans.hdr.anscount], &rr->rec,
sizeof(pj_dns_parsed_rr));
++ans.hdr.anscount;
}
/* For each CNAME entry, add A entry */
for (i=0; i<ans.hdr.anscount && ans.hdr.anscount < MAX_ANS; ++i) {
if (ans.ans[i].type == PJ_DNS_TYPE_CNAME) {
struct rr *r;
if (ans.ans[i].type == PJ_DNS_TYPE_CNAME) {
struct rr *r;
r = find_rr(srv, ans.ans[i].dnsclass, PJ_DNS_TYPE_A,
&ans.ans[i].name);
pj_memcpy(&ans.ans[ans.hdr.anscount], &r->rec,
sizeof(pj_dns_parsed_rr));
++ans.hdr.anscount;
}
r = find_rr(srv, ans.ans[i].dnsclass, PJ_DNS_TYPE_A,
&ans.ans[i].name);
pj_memcpy(&ans.ans[ans.hdr.anscount], &r->rec,
sizeof(pj_dns_parsed_rr));
++ans.hdr.anscount;
}
}
send_pkt:
pkt_len = print_packet(&ans, (pj_uint8_t*)data, MAX_PKT);
if (pkt_len < 1) {
PJ_LOG(4,(THIS_FILE, "Error: answer too large"));
goto on_return;
PJ_LOG(4,(THIS_FILE, "Error: answer too large"));
goto on_return;
}
status = pj_activesock_sendto(srv->asock, &srv->send_key, data, &pkt_len,
0, src_addr, addr_len);
0, src_addr, addr_len);
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
PJ_PERROR(4,(THIS_FILE, status, "Error sending answer"));
goto on_return;
PJ_PERROR(4,(THIS_FILE, status, "Error sending answer"));
goto on_return;
}
on_return:

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -36,141 +35,141 @@ static const struct
} err_str[] =
{
/* STUN errors */
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNRESOLVE, "Unable to resolve STUN server" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINMSGTYPE, "Unknown STUN message type" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINMSGLEN, "Invalid STUN message length" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINATTRLEN, "STUN attribute length error" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINATTRTYPE, "Invalid STUN attribute type" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNININDEX, "Invalid STUN server/socket index" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOBINDRES, "No STUN binding response in the message" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNRECVERRATTR, "Received STUN error attribute" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOMAP, "No STUN mapped address attribute" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOTRESPOND, "Received no response from STUN server" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNSYMMETRIC, "Symetric NAT detected by STUN" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNRESOLVE, "Unable to resolve STUN server" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINMSGTYPE, "Unknown STUN message type" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINMSGLEN, "Invalid STUN message length" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINATTRLEN, "STUN attribute length error" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINATTRTYPE, "Invalid STUN attribute type" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNININDEX, "Invalid STUN server/socket index" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOBINDRES, "No STUN binding response in the message" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNRECVERRATTR, "Received STUN error attribute" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOMAP, "No STUN mapped address attribute" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOTRESPOND, "Received no response from STUN server" ),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNSYMMETRIC, "Symetric NAT detected by STUN" ),
/* XML errors */
PJ_BUILD_ERR( PJLIB_UTIL_EINXML, "Invalid XML message" ),
PJ_BUILD_ERR( PJLIB_UTIL_EINXML, "Invalid XML message" ),
/* JSON errors */
PJ_BUILD_ERR( PJLIB_UTIL_EINJSON, "Invalid JSON document" ),
PJ_BUILD_ERR( PJLIB_UTIL_EINJSON, "Invalid JSON document" ),
/* DNS errors */
PJ_BUILD_ERR( PJLIB_UTIL_EDNSQRYTOOSMALL, "DNS query packet buffer is too small"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINSIZE, "Invalid DNS packet length"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINCLASS, "Invalid DNS class"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINNAMEPTR, "Invalid DNS name pointer"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINNSADDR, "Invalid DNS nameserver address"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSNONS, "No nameserver is in DNS resolver"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSNOWORKINGNS, "No working DNS nameserver"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSNOANSWERREC, "No answer record in the DNS response"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINANSWER, "Invalid DNS answer"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSQRYTOOSMALL, "DNS query packet buffer is too small"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINSIZE, "Invalid DNS packet length"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINCLASS, "Invalid DNS class"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINNAMEPTR, "Invalid DNS name pointer"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINNSADDR, "Invalid DNS nameserver address"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSNONS, "No nameserver is in DNS resolver"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSNOWORKINGNS, "No working DNS nameserver"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSNOANSWERREC, "No answer record in the DNS response"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNSINANSWER, "Invalid DNS answer"),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_FORMERR, "DNS \"Format error\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_SERVFAIL, "DNS \"Server failure\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NXDOMAIN, "DNS \"Name Error\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NOTIMPL, "DNS \"Not Implemented\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_REFUSED, "DNS \"Refused\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_YXDOMAIN, "DNS \"The name exists\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_YXRRSET, "DNS \"The RRset (name, type) exists\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NXRRSET, "DNS \"The RRset (name, type) does not exist\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NOTAUTH, "DNS \"Not authorized\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NOTZONE, "DNS \"The zone specified is not a zone\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_FORMERR, "DNS \"Format error\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_SERVFAIL, "DNS \"Server failure\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NXDOMAIN, "DNS \"Name Error\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NOTIMPL, "DNS \"Not Implemented\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_REFUSED, "DNS \"Refused\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_YXDOMAIN, "DNS \"The name exists\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_YXRRSET, "DNS \"The RRset (name, type) exists\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NXRRSET, "DNS \"The RRset (name, type) does not exist\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NOTAUTH, "DNS \"Not authorized\""),
PJ_BUILD_ERR( PJLIB_UTIL_EDNS_NOTZONE, "DNS \"The zone specified is not a zone\""),
/* STUN */
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNTOOMANYATTR, "Too many STUN attributes"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNUNKNOWNATTR, "Unknown STUN attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINADDRLEN, "Invalid STUN socket address length"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNIPV6NOTSUPP, "STUN IPv6 attribute not supported"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOTRESPONSE, "Expecting STUN response message"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINVALIDID, "STUN transaction ID mismatch"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOHANDLER, "Unable to find STUN handler for the request"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNMSGINTPOS, "Found non-FINGERPRINT attr. after MESSAGE-INTEGRITY"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNFINGERPOS, "Found STUN attribute after FINGERPRINT"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOUSERNAME, "Missing STUN USERNAME attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNMSGINT, "Missing/invalid STUN MESSAGE-INTEGRITY attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNDUPATTR, "Found duplicate STUN attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOREALM, "Missing STUN REALM attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNONCE, "Missing/stale STUN NONCE attribute value"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNTSXFAILED, "STUN transaction terminates with failure"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNTOOMANYATTR, "Too many STUN attributes"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNUNKNOWNATTR, "Unknown STUN attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINADDRLEN, "Invalid STUN socket address length"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNIPV6NOTSUPP, "STUN IPv6 attribute not supported"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOTRESPONSE, "Expecting STUN response message"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNINVALIDID, "STUN transaction ID mismatch"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOHANDLER, "Unable to find STUN handler for the request"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNMSGINTPOS, "Found non-FINGERPRINT attr. after MESSAGE-INTEGRITY"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNFINGERPOS, "Found STUN attribute after FINGERPRINT"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOUSERNAME, "Missing STUN USERNAME attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNMSGINT, "Missing/invalid STUN MESSAGE-INTEGRITY attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNDUPATTR, "Found duplicate STUN attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNOREALM, "Missing STUN REALM attribute"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNNONCE, "Missing/stale STUN NONCE attribute value"),
PJ_BUILD_ERR( PJLIB_UTIL_ESTUNTSXFAILED, "STUN transaction terminates with failure"),
/* HTTP Client */
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPINURL, "Invalid URL format"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPINPORT, "Invalid URL port number"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPINCHDR, "Incomplete response header received"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPINSBUF, "Insufficient buffer"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPLOST, "Connection lost"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPINURL, "Invalid URL format"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPINPORT, "Invalid URL port number"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPINCHDR, "Incomplete response header received"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPINSBUF, "Insufficient buffer"),
PJ_BUILD_ERR( PJLIB_UTIL_EHTTPLOST, "Connection lost"),
/* CLI */
PJ_BUILD_ERR( PJ_CLI_EEXIT, "Exit current session"),
PJ_BUILD_ERR( PJ_CLI_EMISSINGARG, "Missing argument"),
PJ_BUILD_ERR( PJ_CLI_ETOOMANYARGS, "Too many arguments"),
PJ_BUILD_ERR( PJ_CLI_EINVARG, "Invalid argument"),
PJ_BUILD_ERR( PJ_CLI_EBADNAME, "Command name already exists"),
PJ_BUILD_ERR( PJ_CLI_EBADID, "Command id already exists"),
PJ_BUILD_ERR( PJ_CLI_EBADXML, "Invalid XML format"),
PJ_BUILD_ERR( PJ_CLI_ETELNETLOST, "Connection lost"),
PJ_BUILD_ERR( PJ_CLI_EEXIT, "Exit current session"),
PJ_BUILD_ERR( PJ_CLI_EMISSINGARG, "Missing argument"),
PJ_BUILD_ERR( PJ_CLI_ETOOMANYARGS, "Too many arguments"),
PJ_BUILD_ERR( PJ_CLI_EINVARG, "Invalid argument"),
PJ_BUILD_ERR( PJ_CLI_EBADNAME, "Command name already exists"),
PJ_BUILD_ERR( PJ_CLI_EBADID, "Command id already exists"),
PJ_BUILD_ERR( PJ_CLI_EBADXML, "Invalid XML format"),
PJ_BUILD_ERR( PJ_CLI_ETELNETLOST, "Connection lost"),
};
#endif /* PJ_HAS_ERROR_STRING */
#endif /* PJ_HAS_ERROR_STRING */
/*
* pjlib_util_strerror()
*/
pj_str_t pjlib_util_strerror(pj_status_t statcode,
char *buf, pj_size_t bufsize )
char *buf, pj_size_t bufsize )
{
pj_str_t errstr;
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
if (statcode >= PJLIB_UTIL_ERRNO_START &&
statcode < PJLIB_UTIL_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
statcode < PJLIB_UTIL_ERRNO_START + PJ_ERRNO_SPACE_SIZE)
{
/* Find the error in the table.
* Use binary search!
*/
int first = 0;
int n = PJ_ARRAY_SIZE(err_str);
/* Find the error in the table.
* Use binary search!
*/
int first = 0;
int n = PJ_ARRAY_SIZE(err_str);
while (n > 0) {
int half = n/2;
int mid = first + half;
while (n > 0) {
int half = n/2;
int mid = first + half;
if (err_str[mid].code < statcode) {
first = mid+1;
n -= (half+1);
} else if (err_str[mid].code > statcode) {
n = half;
} else {
first = mid;
break;
}
}
if (err_str[mid].code < statcode) {
first = mid+1;
n -= (half+1);
} else if (err_str[mid].code > statcode) {
n = half;
} else {
first = mid;
break;
}
}
if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) {
pj_str_t msg;
msg.ptr = (char*)err_str[first].msg;
msg.slen = pj_ansi_strlen(err_str[first].msg);
if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) {
pj_str_t msg;
msg.ptr = (char*)err_str[first].msg;
msg.slen = pj_ansi_strlen(err_str[first].msg);
errstr.ptr = buf;
pj_strncpy_with_null(&errstr, &msg, bufsize);
return errstr;
errstr.ptr = buf;
pj_strncpy_with_null(&errstr, &msg, bufsize);
return errstr;
}
}
}
#endif /* PJ_HAS_ERROR_STRING */
#endif /* PJ_HAS_ERROR_STRING */
/* Error not found. */
errstr.ptr = buf;
errstr.slen = pj_ansi_snprintf(buf, bufsize,
"Unknown pjlib-util error %d",
statcode);
"Unknown pjlib-util error %d",
statcode);
if (errstr.slen < 1 || errstr.slen >= (pj_ssize_t)bufsize)
errstr.slen = bufsize - 1;
errstr.slen = bufsize - 1;
return errstr;
}
@ -180,8 +179,8 @@ PJ_DEF(pj_status_t) pjlib_util_init(void)
pj_status_t status;
status = pj_register_strerror(PJLIB_UTIL_ERRNO_START,
PJ_ERRNO_SPACE_SIZE,
&pjlib_util_strerror);
PJ_ERRNO_SPACE_SIZE,
&pjlib_util_strerror);
pj_assert(status == PJ_SUCCESS);
return status;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* pj_getopt entry points
*
@ -11,9 +10,9 @@
/* Internal only. Users should not call this directly. */
static
int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct pj_getopt_option *longopts, int *longind,
int long_only);
const char *shortopts,
const struct pj_getopt_option *longopts, int *longind,
int long_only);
/* pj_getopt_long and pj_getopt_long_only entry points for GNU pj_getopt.
Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc.
@ -48,7 +47,7 @@ int _getopt_internal (int argc, char *const *argv,
int
pj_getopt_long (int argc, char *const *argv, const char *options,
const struct pj_getopt_option *long_options, int *opt_index)
const struct pj_getopt_option *long_options, int *opt_index)
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
@ -62,13 +61,13 @@ int
pj_getopt (int argc, char * const * argv, const char * optstring)
{
return _getopt_internal (argc, argv, optstring,
(const struct pj_getopt_option *) 0,
(int *) 0,
0);
(const struct pj_getopt_option *) 0,
(int *) 0,
0);
}
#define _(msgid) (msgid)
#define _(msgid) (msgid)
/* This version of `pj_getopt' appears to the caller like standard Unix `pj_getopt'
but it behaves differently for the user, since it allows the user
@ -171,7 +170,7 @@ my_index (const char *str, int chr)
while (*str)
{
if (*str == chr)
return (char *) str;
return (char *) str;
str++;
}
return 0;
@ -214,39 +213,39 @@ exchange (char **argv)
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
{
/* Bottom segment is the short one. */
int len = middle - bottom;
register int i;
{
/* Bottom segment is the short one. */
int len = middle - bottom;
register int i;
/* Swap it with the top part of the top segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
}
/* Swap it with the top part of the top segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
}
else
{
/* Top segment is the short one. */
int len = top - middle;
register int i;
{
/* Top segment is the short one. */
int len = top - middle;
register int i;
/* Swap it with the bottom part of the bottom segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
SWAP_FLAGS (bottom + i, middle + i);
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
}
/* Swap it with the bottom part of the bottom segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
SWAP_FLAGS (bottom + i, middle + i);
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
}
}
/* Update records for the slots the non-options now occupy. */
@ -258,7 +257,7 @@ exchange (char **argv)
/* Initialize the internal data when the first call is made. */
static const char *_getopt_initialize (int argc, char *const *argv,
const char *optstring)
const char *optstring)
{
PJ_UNUSED_ARG(argc);
PJ_UNUSED_ARG(argv);
@ -352,15 +351,15 @@ static const char *_getopt_initialize (int argc, char *const *argv,
static int
_getopt_internal (int argc, char *const *argv, const char *optstring,
const struct pj_getopt_option *longopts, int *longind,
int long_only)
const struct pj_getopt_option *longopts, int *longind,
int long_only)
{
pj_optarg = NULL;
if (pj_optind == 0 || !__getopt_initialized)
{
if (pj_optind == 0)
pj_optind = 1; /* Don't scan ARGV[0], the program name. */
pj_optind = 1; /* Don't scan ARGV[0], the program name. */
optstring = _getopt_initialize (argc, argv, optstring);
__getopt_initialized = 1;
}
@ -376,76 +375,76 @@ _getopt_internal (int argc, char *const *argv, const char *optstring,
/* Advance to the next ARGV-element. */
/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
moved back by the user (who may also have changed the arguments). */
moved back by the user (who may also have changed the arguments). */
if (last_nonopt > pj_optind)
last_nonopt = pj_optind;
last_nonopt = pj_optind;
if (first_nonopt > pj_optind)
first_nonopt = pj_optind;
first_nonopt = pj_optind;
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
{
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
if (first_nonopt != last_nonopt && last_nonopt != pj_optind)
exchange ((char **) argv);
else if (last_nonopt != pj_optind)
first_nonopt = pj_optind;
if (first_nonopt != last_nonopt && last_nonopt != pj_optind)
exchange ((char **) argv);
else if (last_nonopt != pj_optind)
first_nonopt = pj_optind;
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
while (pj_optind < argc && NONOPTION_P)
pj_optind++;
last_nonopt = pj_optind;
}
while (pj_optind < argc && NONOPTION_P)
pj_optind++;
last_nonopt = pj_optind;
}
/* The special ARGV-element `--' means premature end of options.
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
if (pj_optind != argc && !pj_ansi_strcmp(argv[pj_optind], "--"))
{
pj_optind++;
{
pj_optind++;
if (first_nonopt != last_nonopt && last_nonopt != pj_optind)
exchange ((char **) argv);
else if (first_nonopt == last_nonopt)
first_nonopt = pj_optind;
last_nonopt = argc;
if (first_nonopt != last_nonopt && last_nonopt != pj_optind)
exchange ((char **) argv);
else if (first_nonopt == last_nonopt)
first_nonopt = pj_optind;
last_nonopt = argc;
pj_optind = argc;
}
pj_optind = argc;
}
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
and back over any non-options that we skipped and permuted. */
if (pj_optind == argc)
{
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
pj_optind = first_nonopt;
return -1;
}
{
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
pj_optind = first_nonopt;
return -1;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
either stop the scan or describe it to the caller and pass it by. */
if (NONOPTION_P)
{
if (ordering == REQUIRE_ORDER)
return -1;
pj_optarg = argv[pj_optind++];
return 1;
}
{
if (ordering == REQUIRE_ORDER)
return -1;
pj_optarg = argv[pj_optind++];
return 1;
}
/* We have found another option-ARGV-element.
Skip the initial punctuation. */
Skip the initial punctuation. */
nextchar = (argv[pj_optind] + 1
+ (longopts != NULL && argv[pj_optind][1] == '-'));
+ (longopts != NULL && argv[pj_optind][1] == '-'));
}
/* Decode the current option-ARGV-element. */
@ -465,7 +464,7 @@ _getopt_internal (int argc, char *const *argv, const char *optstring,
if (longopts != NULL
&& (argv[pj_optind][1] == '-'
|| (long_only && (argv[pj_optind][2] || !my_index (optstring, argv[pj_optind][1])))))
|| (long_only && (argv[pj_optind][2] || !my_index (optstring, argv[pj_optind][1])))))
{
char *nameend;
const struct pj_getopt_option *p;
@ -476,93 +475,93 @@ _getopt_internal (int argc, char *const *argv, const char *optstring,
int option_index;
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
/* Do nothing. */ ;
/* Do nothing. */ ;
/* Test all long options for either exact match
or abbreviated matches. */
or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp (p->name, nextchar, nameend - nextchar))
{
if ((unsigned int) (nameend - nextchar)
== (unsigned int) strlen (p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second or later nonexact match found. */
ambig = 1;
}
if (!strncmp (p->name, nextchar, nameend - nextchar))
{
if ((unsigned int) (nameend - nextchar)
== (unsigned int) strlen (p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
nextchar += strlen (nextchar);
pj_optind++;
pj_optopt = 0;
return '?';
}
{
nextchar += strlen (nextchar);
pj_optind++;
pj_optopt = 0;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
pj_optind++;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
pj_optarg = nameend + 1;
else
{
nextchar += strlen (nextchar);
{
option_index = indfound;
pj_optind++;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
pj_optarg = nameend + 1;
else
{
nextchar += strlen (nextchar);
pj_optopt = pfound->val;
return '?';
}
}
else if (pfound->has_arg == 1)
{
if (pj_optind < argc)
pj_optarg = argv[pj_optind++];
else
{
nextchar += strlen (nextchar);
pj_optopt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
pj_optopt = pfound->val;
return '?';
}
}
else if (pfound->has_arg == 1)
{
if (pj_optind < argc)
pj_optarg = argv[pj_optind++];
else
{
nextchar += strlen (nextchar);
pj_optopt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
/* Can't find it as a long option. If this is not pj_getopt_long_only,
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[pj_optind][1] == '-'
|| my_index (optstring, *nextchar) == NULL)
{
nextchar = (char *) "";
pj_optind++;
pj_optopt = 0;
return '?';
}
|| my_index (optstring, *nextchar) == NULL)
{
nextchar = (char *) "";
pj_optind++;
pj_optopt = 0;
return '?';
}
}
/* Look at and handle the next short option-character. */
@ -577,153 +576,153 @@ _getopt_internal (int argc, char *const *argv, const char *optstring,
if (temp == NULL || c == ':')
{
pj_optopt = c;
return '?';
pj_optopt = c;
return '?';
}
/* Convenience. Treat POSIX -W foo same as long option --foo */
if (temp[0] == 'W' && temp[1] == ';')
{
char *nameend;
const struct pj_getopt_option *p;
const struct pj_getopt_option *pfound = NULL;
int exact = 0;
int ambig = 0;
int indfound = 0;
int option_index;
char *nameend;
const struct pj_getopt_option *p;
const struct pj_getopt_option *pfound = NULL;
int exact = 0;
int ambig = 0;
int indfound = 0;
int option_index;
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
pj_optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
pj_optind++;
}
else if (pj_optind == argc)
{
pj_optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
return c;
}
else
/* We already incremented `pj_optind' once;
increment it again when taking next ARGV-elt as argument. */
pj_optarg = argv[pj_optind++];
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
pj_optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
pj_optind++;
}
else if (pj_optind == argc)
{
pj_optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
return c;
}
else
/* We already incremented `pj_optind' once;
increment it again when taking next ARGV-elt as argument. */
pj_optarg = argv[pj_optind++];
/* pj_optarg is now the argument, see if it's in the
table of longopts. */
/* pj_optarg is now the argument, see if it's in the
table of longopts. */
for (nextchar = nameend = pj_optarg; *nameend && *nameend != '='; nameend++)
/* Do nothing. */ ;
for (nextchar = nameend = pj_optarg; *nameend && *nameend != '='; nameend++)
/* Do nothing. */ ;
/* Test all long options for either exact match
or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp (p->name, nextchar, nameend - nextchar))
{
if ((unsigned int) (nameend - nextchar) == strlen (p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
nextchar += strlen (nextchar);
pj_optind++;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
pj_optarg = nameend + 1;
else
{
nextchar += strlen (nextchar);
return '?';
}
}
else if (pfound->has_arg == 1)
{
if (pj_optind < argc)
pj_optarg = argv[pj_optind++];
else
{
nextchar += strlen (nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
nextchar = NULL;
return 'W'; /* Let the application handle it. */
/* Test all long options for either exact match
or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp (p->name, nextchar, nameend - nextchar))
{
if ((unsigned int) (nameend - nextchar) == strlen (p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
nextchar += strlen (nextchar);
pj_optind++;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
pj_optarg = nameend + 1;
else
{
nextchar += strlen (nextchar);
return '?';
}
}
else if (pfound->has_arg == 1)
{
if (pj_optind < argc)
pj_optarg = argv[pj_optind++];
else
{
nextchar += strlen (nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
nextchar = NULL;
return 'W'; /* Let the application handle it. */
}
if (temp[1] == ':')
{
if (temp[2] == ':')
{
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0')
{
pj_optarg = nextchar;
pj_optind++;
}
else
pj_optarg = NULL;
nextchar = NULL;
}
else
{
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
pj_optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
pj_optind++;
}
else if (pj_optind == argc)
{
pj_optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
}
else
/* We already incremented `pj_optind' once;
increment it again when taking next ARGV-elt as argument. */
pj_optarg = argv[pj_optind++];
nextchar = NULL;
}
if (temp[2] == ':')
{
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0')
{
pj_optarg = nextchar;
pj_optind++;
}
else
pj_optarg = NULL;
nextchar = NULL;
}
else
{
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
pj_optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
pj_optind++;
}
else if (pj_optind == argc)
{
pj_optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
}
else
/* We already incremented `pj_optind' once;
increment it again when taking next ARGV-elt as argument. */
pj_optarg = argv[pj_optind++];
nextchar = NULL;
}
}
return c;
}

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -22,7 +21,7 @@
PJ_DEF(void) pj_hmac_md5_init(pj_hmac_md5_context *hctx,
const pj_uint8_t *key, unsigned key_len)
const pj_uint8_t *key, unsigned key_len)
{
pj_uint8_t k_ipad[64];
pj_uint8_t tk[16];
@ -64,14 +63,14 @@ PJ_DEF(void) pj_hmac_md5_init(pj_hmac_md5_context *hctx,
}
PJ_DEF(void) pj_hmac_md5_update(pj_hmac_md5_context *hctx,
const pj_uint8_t *input,
unsigned input_len)
const pj_uint8_t *input,
unsigned input_len)
{
pj_md5_update(&hctx->context, input, input_len);
}
PJ_DEF(void) pj_hmac_md5_final(pj_hmac_md5_context *hctx,
pj_uint8_t digest[16])
pj_uint8_t digest[16])
{
pj_md5_final(&hctx->context, digest);
@ -85,8 +84,8 @@ PJ_DEF(void) pj_hmac_md5_final(pj_hmac_md5_context *hctx,
}
PJ_DEF(void) pj_hmac_md5( const pj_uint8_t *input, unsigned input_len,
const pj_uint8_t *key, unsigned key_len,
pj_uint8_t digest[16] )
const pj_uint8_t *key, unsigned key_len,
pj_uint8_t digest[16] )
{
pj_hmac_md5_context ctx;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -22,7 +21,7 @@
PJ_DEF(void) pj_hmac_sha1_init(pj_hmac_sha1_context *hctx,
const pj_uint8_t *key, unsigned key_len)
const pj_uint8_t *key, unsigned key_len)
{
pj_uint8_t k_ipad[64];
pj_uint8_t tk[20];
@ -63,13 +62,13 @@ PJ_DEF(void) pj_hmac_sha1_init(pj_hmac_sha1_context *hctx,
}
PJ_DEF(void) pj_hmac_sha1_update(pj_hmac_sha1_context *hctx,
const pj_uint8_t *input, unsigned input_len)
const pj_uint8_t *input, unsigned input_len)
{
pj_sha1_update(&hctx->context, input, input_len);
}
PJ_DEF(void) pj_hmac_sha1_final(pj_hmac_sha1_context *hctx,
pj_uint8_t digest[20])
pj_uint8_t digest[20])
{
pj_sha1_final(&hctx->context, digest);
@ -83,8 +82,8 @@ PJ_DEF(void) pj_hmac_sha1_final(pj_hmac_sha1_context *hctx,
}
PJ_DEF(void) pj_hmac_sha1(const pj_uint8_t *input, unsigned input_len,
const pj_uint8_t *key, unsigned key_len,
pj_uint8_t digest[20] )
const pj_uint8_t *key, unsigned key_len,
pj_uint8_t digest[20] )
{
pj_hmac_sha1_context ctx;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
*
@ -24,20 +23,20 @@
#include <pj/except.h>
#include <pj/string.h>
#define EL_INIT(p_el, nm, typ) do { \
if (nm) { \
p_el->name = *nm; \
} else { \
p_el->name.ptr = (char*)""; \
p_el->name.slen = 0; \
} \
p_el->type = typ; \
} while (0)
#define EL_INIT(p_el, nm, typ) do { \
if (nm) { \
p_el->name = *nm; \
} else { \
p_el->name.ptr = (char*)""; \
p_el->name.slen = 0; \
} \
p_el->type = typ; \
} while (0)
struct write_state;
struct parse_state;
#define NO_NAME 1
#define NO_NAME 1
static pj_status_t elem_write(const pj_json_elem *elem,
struct write_state *st,
@ -92,10 +91,10 @@ PJ_DEF(void) pj_json_elem_add(pj_json_elem *el, pj_json_elem *child)
struct parse_state
{
pj_pool_t *pool;
pj_scanner scanner;
pj_json_err_info *err_info;
pj_cis_t float_spec; /* numbers with dot! */
pj_pool_t *pool;
pj_scanner scanner;
pj_json_err_info *err_info;
pj_cis_t float_spec; /* numbers with dot! */
};
static pj_status_t parse_children(struct parse_state *st,
@ -106,19 +105,19 @@ static pj_status_t parse_children(struct parse_state *st,
pj_scan_get_char(&st->scanner);
while (*st->scanner.curptr != end_quote) {
pj_json_elem *child;
pj_json_elem *child;
while (*st->scanner.curptr == ',')
pj_scan_get_char(&st->scanner);
while (*st->scanner.curptr == ',')
pj_scan_get_char(&st->scanner);
if (*st->scanner.curptr == end_quote)
break;
if (*st->scanner.curptr == end_quote)
break;
child = parse_elem_throw(st, NULL);
if (!child)
return PJLIB_UTIL_EINJSON;
child = parse_elem_throw(st, NULL);
if (!child)
return PJLIB_UTIL_EINJSON;
pj_json_elem_add(parent, child);
pj_json_elem_add(parent, child);
}
pj_scan_get_char(&st->scanner);
@ -139,8 +138,8 @@ static unsigned parse_quoted_string(struct parse_state *st,
token.slen-=2;
if (pj_strchr(&token, '\\') == NULL) {
*output = token;
return 0;
*output = token;
return 0;
}
output->ptr = op = pj_pool_alloc(st->pool, token.slen);
@ -149,45 +148,45 @@ static unsigned parse_quoted_string(struct parse_state *st,
iend = token.ptr + token.slen;
while (ip != iend) {
if (*ip == '\\') {
++ip;
if (ip==iend) {
goto on_error;
}
if (*ip == 'u') {
ip++;
if (iend - ip < 4) {
ip = iend -1;
goto on_error;
}
/* Only use the last two hext digits because we're on
* ASCII */
*op++ = (char)(pj_hex_digit_to_val(ip[2]) * 16 +
pj_hex_digit_to_val(ip[3]));
ip += 4;
} else if (*ip=='"' || *ip=='\\' || *ip=='/') {
*op++ = *ip++;
} else if (*ip=='b') {
*op++ = '\b';
ip++;
} else if (*ip=='f') {
*op++ = '\f';
ip++;
} else if (*ip=='n') {
*op++ = '\n';
ip++;
} else if (*ip=='r') {
*op++ = '\r';
ip++;
} else if (*ip=='t') {
*op++ = '\t';
ip++;
} else {
goto on_error;
}
} else {
*op++ = *ip++;
}
if (*ip == '\\') {
++ip;
if (ip==iend) {
goto on_error;
}
if (*ip == 'u') {
ip++;
if (iend - ip < 4) {
ip = iend -1;
goto on_error;
}
/* Only use the last two hext digits because we're on
* ASCII */
*op++ = (char)(pj_hex_digit_to_val(ip[2]) * 16 +
pj_hex_digit_to_val(ip[3]));
ip += 4;
} else if (*ip=='"' || *ip=='\\' || *ip=='/') {
*op++ = *ip++;
} else if (*ip=='b') {
*op++ = '\b';
ip++;
} else if (*ip=='f') {
*op++ = '\f';
ip++;
} else if (*ip=='n') {
*op++ = '\n';
ip++;
} else if (*ip=='r') {
*op++ = '\r';
ip++;
} else if (*ip=='t') {
*op++ = '\t';
ip++;
} else {
goto on_error;
}
} else {
*op++ = *ip++;
}
}
output->slen = op - output->ptr;
@ -205,85 +204,85 @@ static pj_json_elem* parse_elem_throw(struct parse_state *st,
pj_str_t token;
if (!elem)
elem = pj_pool_alloc(st->pool, sizeof(*elem));
elem = pj_pool_alloc(st->pool, sizeof(*elem));
/* Parse name */
if (*st->scanner.curptr == '"') {
pj_scan_get_char(&st->scanner);
pj_scan_get_until_ch(&st->scanner, '"', &token);
pj_scan_get_char(&st->scanner);
pj_scan_get_char(&st->scanner);
pj_scan_get_until_ch(&st->scanner, '"', &token);
pj_scan_get_char(&st->scanner);
if (*st->scanner.curptr == ':') {
pj_scan_get_char(&st->scanner);
name = token;
} else {
value = token;
}
if (*st->scanner.curptr == ':') {
pj_scan_get_char(&st->scanner);
name = token;
} else {
value = token;
}
}
if (value.slen) {
/* Element with string value and no name */
pj_json_elem_string(elem, &name, &value);
return elem;
/* Element with string value and no name */
pj_json_elem_string(elem, &name, &value);
return elem;
}
/* Parse value */
if (pj_cis_match(&st->float_spec, *st->scanner.curptr) ||
*st->scanner.curptr == '-')
*st->scanner.curptr == '-')
{
float val;
pj_bool_t neg = PJ_FALSE;
float val;
pj_bool_t neg = PJ_FALSE;
if (*st->scanner.curptr == '-') {
pj_scan_get_char(&st->scanner);
neg = PJ_TRUE;
}
if (*st->scanner.curptr == '-') {
pj_scan_get_char(&st->scanner);
neg = PJ_TRUE;
}
pj_scan_get(&st->scanner, &st->float_spec, &token);
val = pj_strtof(&token);
if (neg) val = -val;
pj_scan_get(&st->scanner, &st->float_spec, &token);
val = pj_strtof(&token);
if (neg) val = -val;
pj_json_elem_number(elem, &name, val);
pj_json_elem_number(elem, &name, val);
} else if (*st->scanner.curptr == '"') {
unsigned err;
char *start = st->scanner.curptr;
unsigned err;
char *start = st->scanner.curptr;
err = parse_quoted_string(st, &token);
if (err) {
st->scanner.curptr = start + err;
return NULL;
}
err = parse_quoted_string(st, &token);
if (err) {
st->scanner.curptr = start + err;
return NULL;
}
pj_json_elem_string(elem, &name, &token);
pj_json_elem_string(elem, &name, &token);
} else if (pj_isalpha(*st->scanner.curptr)) {
if (pj_scan_strcmp(&st->scanner, "false", 5)==0) {
pj_json_elem_bool(elem, &name, PJ_FALSE);
pj_scan_advance_n(&st->scanner, 5, PJ_TRUE);
} else if (pj_scan_strcmp(&st->scanner, "true", 4)==0) {
pj_json_elem_bool(elem, &name, PJ_TRUE);
pj_scan_advance_n(&st->scanner, 4, PJ_TRUE);
} else if (pj_scan_strcmp(&st->scanner, "null", 4)==0) {
pj_json_elem_null(elem, &name);
pj_scan_advance_n(&st->scanner, 4, PJ_TRUE);
} else {
return NULL;
}
if (pj_scan_strcmp(&st->scanner, "false", 5)==0) {
pj_json_elem_bool(elem, &name, PJ_FALSE);
pj_scan_advance_n(&st->scanner, 5, PJ_TRUE);
} else if (pj_scan_strcmp(&st->scanner, "true", 4)==0) {
pj_json_elem_bool(elem, &name, PJ_TRUE);
pj_scan_advance_n(&st->scanner, 4, PJ_TRUE);
} else if (pj_scan_strcmp(&st->scanner, "null", 4)==0) {
pj_json_elem_null(elem, &name);
pj_scan_advance_n(&st->scanner, 4, PJ_TRUE);
} else {
return NULL;
}
} else if (*st->scanner.curptr == '[') {
pj_json_elem_array(elem, &name);
if (parse_children(st, elem) != PJ_SUCCESS)
return NULL;
pj_json_elem_array(elem, &name);
if (parse_children(st, elem) != PJ_SUCCESS)
return NULL;
} else if (*st->scanner.curptr == '{') {
pj_json_elem_obj(elem, &name);
if (parse_children(st, elem) != PJ_SUCCESS)
return NULL;
pj_json_elem_obj(elem, &name);
if (parse_children(st, elem) != PJ_SUCCESS)
return NULL;
} else {
return NULL;
return NULL;
}
return elem;
@ -308,7 +307,7 @@ PJ_DEF(pj_json_elem*) pj_json_parse(pj_pool_t *pool,
PJ_ASSERT_RETURN(pool && buffer && size, NULL);
if (!*size)
return NULL;
return NULL;
pj_bzero(&st, sizeof(st));
st.pool = pool;
@ -321,17 +320,17 @@ PJ_DEF(pj_json_elem*) pj_json_parse(pj_pool_t *pool,
pj_cis_add_str(&st.float_spec, ".0123456789");
PJ_TRY {
root = parse_elem_throw(&st, NULL);
root = parse_elem_throw(&st, NULL);
}
PJ_CATCH_ANY {
root = NULL;
root = NULL;
}
PJ_END
if (!root && err_info) {
err_info->line = st.scanner.line;
err_info->col = pj_scan_get_col(&st.scanner) + 1;
err_info->err_char = *st.scanner.curptr;
err_info->line = st.scanner.line;
err_info->col = pj_scan_get_col(&st.scanner) + 1;
err_info->err_char = *st.scanner.curptr;
}
*size = (unsigned)((buffer + *size) - st.scanner.curptr);
@ -343,17 +342,17 @@ PJ_DEF(pj_json_elem*) pj_json_parse(pj_pool_t *pool,
struct buf_writer_data
{
char *pos;
unsigned size;
char *pos;
unsigned size;
};
static pj_status_t buf_writer(const char *s,
unsigned size,
void *user_data)
unsigned size,
void *user_data)
{
struct buf_writer_data *buf_data = (struct buf_writer_data*)user_data;
if (size+1 >= buf_data->size)
return PJ_ETOOBIG;
return PJ_ETOOBIG;
pj_memcpy(buf_data->pos, s, size);
buf_data->pos += size;
@ -375,34 +374,34 @@ PJ_DEF(pj_status_t) pj_json_write(const pj_json_elem *elem,
status = pj_json_writef(elem, &buf_writer, &buf_data);
if (status != PJ_SUCCESS)
return status;
return status;
*buf_data.pos = '\0';
*size = (unsigned)(buf_data.pos - buffer);
return PJ_SUCCESS;
}
#define MAX_INDENT 100
#define MAX_INDENT 100
#ifndef PJ_JSON_NAME_MIN_LEN
# define PJ_JSON_NAME_MIN_LEN 20
# define PJ_JSON_NAME_MIN_LEN 20
#endif
#define ESC_BUF_LEN 64
#define ESC_BUF_LEN 64
#ifndef PJ_JSON_INDENT_SIZE
# define PJ_JSON_INDENT_SIZE 3
# define PJ_JSON_INDENT_SIZE 3
#endif
struct write_state
{
pj_json_writer writer;
void *user_data;
char indent_buf[MAX_INDENT];
int indent;
char space[PJ_JSON_NAME_MIN_LEN];
pj_json_writer writer;
void *user_data;
char indent_buf[MAX_INDENT];
int indent;
char space[PJ_JSON_NAME_MIN_LEN];
};
#define CHECK(expr) do { \
status=expr; if (status!=PJ_SUCCESS) return status; } \
while (0)
status=expr; if (status!=PJ_SUCCESS) return status; } \
while (0)
static pj_status_t write_string_escaped(const pj_str_t *value,
struct write_state *st)
@ -415,64 +414,64 @@ static pj_status_t write_string_escaped(const pj_str_t *value,
pj_status_t status;
while (ip != iend) {
/* Write to buffer to speedup writing instead of calling
* the callback one by one for each character.
*/
while (ip != iend && op != oend) {
if (oend - op < 2)
break;
/* Write to buffer to speedup writing instead of calling
* the callback one by one for each character.
*/
while (ip != iend && op != oend) {
if (oend - op < 2)
break;
if (*ip == '"') {
*op++ = '\\';
*op++ = '"';
ip++;
} else if (*ip == '\\') {
*op++ = '\\';
*op++ = '\\';
ip++;
} else if (*ip == '/') {
*op++ = '\\';
*op++ = '/';
ip++;
} else if (*ip == '\b') {
*op++ = '\\';
*op++ = 'b';
ip++;
} else if (*ip == '\f') {
*op++ = '\\';
*op++ = 'f';
ip++;
} else if (*ip == '\n') {
*op++ = '\\';
*op++ = 'n';
ip++;
} else if (*ip == '\r') {
*op++ = '\\';
*op++ = 'r';
ip++;
} else if (*ip == '\t') {
*op++ = '\\';
*op++ = 't';
ip++;
} else if ((*ip >= 32 && *ip < 127)) {
/* unescaped */
*op++ = *ip++;
} else {
/* escaped */
if (oend - op < 6)
break;
*op++ = '\\';
*op++ = 'u';
*op++ = '0';
*op++ = '0';
pj_val_to_hex_digit(*ip, op);
op+=2;
ip++;
}
}
if (*ip == '"') {
*op++ = '\\';
*op++ = '"';
ip++;
} else if (*ip == '\\') {
*op++ = '\\';
*op++ = '\\';
ip++;
} else if (*ip == '/') {
*op++ = '\\';
*op++ = '/';
ip++;
} else if (*ip == '\b') {
*op++ = '\\';
*op++ = 'b';
ip++;
} else if (*ip == '\f') {
*op++ = '\\';
*op++ = 'f';
ip++;
} else if (*ip == '\n') {
*op++ = '\\';
*op++ = 'n';
ip++;
} else if (*ip == '\r') {
*op++ = '\\';
*op++ = 'r';
ip++;
} else if (*ip == '\t') {
*op++ = '\\';
*op++ = 't';
ip++;
} else if ((*ip >= 32 && *ip < 127)) {
/* unescaped */
*op++ = *ip++;
} else {
/* escaped */
if (oend - op < 6)
break;
*op++ = '\\';
*op++ = 'u';
*op++ = '0';
*op++ = '0';
pj_val_to_hex_digit(*ip, op);
op+=2;
ip++;
}
}
CHECK( st->writer( buf, (unsigned)(op-buf), st->user_data) );
op = buf;
CHECK( st->writer( buf, (unsigned)(op-buf), st->user_data) );
op = buf;
}
return PJ_SUCCESS;
@ -490,42 +489,42 @@ static pj_status_t write_children(const pj_json_list *list,
CHECK( st->writer( " ", 1, st->user_data) );
if (!pj_list_empty(list)) {
pj_bool_t indent_added = PJ_FALSE;
pj_json_elem *child = list->next;
pj_bool_t indent_added = PJ_FALSE;
pj_json_elem *child = list->next;
if (child->name.slen == 0) {
/* Simple list */
while (child != (pj_json_elem*)list) {
status = elem_write(child, st, flags);
if (status != PJ_SUCCESS)
return status;
if (child->name.slen == 0) {
/* Simple list */
while (child != (pj_json_elem*)list) {
status = elem_write(child, st, flags);
if (status != PJ_SUCCESS)
return status;
if (child->next != (pj_json_elem*)list)
CHECK( st->writer( ", ", 2, st->user_data) );
child = child->next;
}
} else {
if (st->indent < sizeof(st->indent_buf)) {
st->indent += PJ_JSON_INDENT_SIZE;
indent_added = PJ_TRUE;
}
CHECK( st->writer( "\n", 1, st->user_data) );
while (child != (pj_json_elem*)list) {
status = elem_write(child, st, flags);
if (status != PJ_SUCCESS)
return status;
if (child->next != (pj_json_elem*)list)
CHECK( st->writer( ", ", 2, st->user_data) );
child = child->next;
}
} else {
if (st->indent < sizeof(st->indent_buf)) {
st->indent += PJ_JSON_INDENT_SIZE;
indent_added = PJ_TRUE;
}
CHECK( st->writer( "\n", 1, st->user_data) );
while (child != (pj_json_elem*)list) {
status = elem_write(child, st, flags);
if (status != PJ_SUCCESS)
return status;
if (child->next != (pj_json_elem*)list)
CHECK( st->writer( ",\n", 2, st->user_data) );
else
CHECK( st->writer( "\n", 1, st->user_data) );
child = child->next;
}
if (indent_added) {
st->indent -= PJ_JSON_INDENT_SIZE;
}
CHECK( st->writer( st->indent_buf, st->indent, st->user_data) );
}
if (child->next != (pj_json_elem*)list)
CHECK( st->writer( ",\n", 2, st->user_data) );
else
CHECK( st->writer( "\n", 1, st->user_data) );
child = child->next;
}
if (indent_added) {
st->indent -= PJ_JSON_INDENT_SIZE;
}
CHECK( st->writer( st->indent_buf, st->indent, st->user_data) );
}
}
CHECK( st->writer( &quotes[1], 1, st->user_data) );
@ -539,63 +538,63 @@ static pj_status_t elem_write(const pj_json_elem *elem,
pj_status_t status;
if (elem->name.slen) {
CHECK( st->writer( st->indent_buf, st->indent, st->user_data) );
if ((flags & NO_NAME)==0) {
CHECK( st->writer( "\"", 1, st->user_data) );
CHECK( write_string_escaped(&elem->name, st) );
CHECK( st->writer( "\": ", 3, st->user_data) );
if (elem->name.slen < PJ_JSON_NAME_MIN_LEN /*&&
elem->type != PJ_JSON_VAL_OBJ &&
elem->type != PJ_JSON_VAL_ARRAY*/)
{
CHECK( st->writer( st->space,
(unsigned)(PJ_JSON_NAME_MIN_LEN -
elem->name.slen),
st->user_data) );
}
}
CHECK( st->writer( st->indent_buf, st->indent, st->user_data) );
if ((flags & NO_NAME)==0) {
CHECK( st->writer( "\"", 1, st->user_data) );
CHECK( write_string_escaped(&elem->name, st) );
CHECK( st->writer( "\": ", 3, st->user_data) );
if (elem->name.slen < PJ_JSON_NAME_MIN_LEN /*&&
elem->type != PJ_JSON_VAL_OBJ &&
elem->type != PJ_JSON_VAL_ARRAY*/)
{
CHECK( st->writer( st->space,
(unsigned)(PJ_JSON_NAME_MIN_LEN -
elem->name.slen),
st->user_data) );
}
}
}
switch (elem->type) {
case PJ_JSON_VAL_NULL:
CHECK( st->writer( "null", 4, st->user_data) );
break;
CHECK( st->writer( "null", 4, st->user_data) );
break;
case PJ_JSON_VAL_BOOL:
if (elem->value.is_true)
CHECK( st->writer( "true", 4, st->user_data) );
else
CHECK( st->writer( "false", 5, st->user_data) );
break;
if (elem->value.is_true)
CHECK( st->writer( "true", 4, st->user_data) );
else
CHECK( st->writer( "false", 5, st->user_data) );
break;
case PJ_JSON_VAL_NUMBER:
{
char num_buf[65];
int len;
{
char num_buf[65];
int len;
if (elem->value.num == (int)elem->value.num)
len = pj_ansi_snprintf(num_buf, sizeof(num_buf), "%d",
(int)elem->value.num);
else
len = pj_ansi_snprintf(num_buf, sizeof(num_buf), "%f",
elem->value.num);
if (elem->value.num == (int)elem->value.num)
len = pj_ansi_snprintf(num_buf, sizeof(num_buf), "%d",
(int)elem->value.num);
else
len = pj_ansi_snprintf(num_buf, sizeof(num_buf), "%f",
elem->value.num);
if (len < 0 || len >= sizeof(num_buf))
return PJ_ETOOBIG;
CHECK( st->writer( num_buf, len, st->user_data) );
}
break;
if (len < 0 || len >= sizeof(num_buf))
return PJ_ETOOBIG;
CHECK( st->writer( num_buf, len, st->user_data) );
}
break;
case PJ_JSON_VAL_STRING:
CHECK( st->writer( "\"", 1, st->user_data) );
CHECK( write_string_escaped( &elem->value.str, st) );
CHECK( st->writer( "\"", 1, st->user_data) );
break;
CHECK( st->writer( "\"", 1, st->user_data) );
CHECK( write_string_escaped( &elem->value.str, st) );
CHECK( st->writer( "\"", 1, st->user_data) );
break;
case PJ_JSON_VAL_ARRAY:
CHECK( write_children(&elem->value.children, "[]", st) );
break;
CHECK( write_children(&elem->value.children, "[]", st) );
break;
case PJ_JSON_VAL_OBJ:
CHECK( write_children(&elem->value.children, "{}", st) );
break;
CHECK( write_children(&elem->value.children, "{}", st) );
break;
default:
pj_assert(!"Unhandled value type");
pj_assert(!"Unhandled value type");
}
return PJ_SUCCESS;
@ -611,9 +610,9 @@ PJ_DEF(pj_status_t) pj_json_writef( const pj_json_elem *elem,
PJ_ASSERT_RETURN(elem && writer, PJ_EINVAL);
st.writer = writer;
st.user_data = user_data;
st.indent = 0;
st.writer = writer;
st.user_data = user_data;
st.indent = 0;
pj_memset(st.indent_buf, ' ', MAX_INDENT);
pj_memset(st.space, ' ', PJ_JSON_NAME_MIN_LEN);

View File

@ -1,10 +1,9 @@
/* $Id$ */
/*
* This is the implementation of MD5 algorithm, based on the code
* written by Colin Plumb. This file is put in public domain.
*/
#include <pjlib-util/md5.h>
#include <pj/string.h> /* pj_memcpy */
#include <pj/string.h> /* pj_memcpy */
/*
* This code implements the MD5 message-digest algorithm.
* The algorithm is due to Ron Rivest. This code was
@ -27,7 +26,7 @@
#endif
#ifndef HIGHFIRST
#define byteReverse(buf, len) /* Nothing */
#define byteReverse(buf, len) /* Nothing */
#else
static void byteReverse(unsigned char *buf, unsigned longs);
@ -39,10 +38,10 @@ static void byteReverse(unsigned char *buf, unsigned longs)
{
pj_uint32_t t;
do {
t = (pj_uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(pj_uint32_t *) buf = t;
buf += 4;
t = (pj_uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(pj_uint32_t *) buf = t;
buf += 4;
} while (--longs);
}
#endif
@ -71,7 +70,7 @@ PJ_DEF(void) pj_md5_init(pj_md5_context *ctx)
* of bytes.
*/
PJ_DEF(void) pj_md5_update( pj_md5_context *ctx,
unsigned char const *buf, unsigned len)
unsigned char const *buf, unsigned len)
{
pj_uint32_t t;
@ -79,35 +78,35 @@ PJ_DEF(void) pj_md5_update( pj_md5_context *ctx,
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((pj_uint32_t) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
/* Handle any leading odd-sized chunks */
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
unsigned char *p = (unsigned char *) ctx->in + t;
t = 64 - t;
if (len < t) {
pj_memcpy(p, buf, len);
return;
}
pj_memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (pj_uint32_t *) ctx->in);
buf += t;
len -= t;
t = 64 - t;
if (len < t) {
pj_memcpy(p, buf, len);
return;
}
pj_memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (pj_uint32_t *) ctx->in);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
while (len >= 64) {
pj_memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (pj_uint32_t *) ctx->in);
buf += 64;
len -= 64;
pj_memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (pj_uint32_t *) ctx->in);
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
@ -137,16 +136,16 @@ PJ_DEF(void) pj_md5_final(pj_md5_context *ctx, unsigned char digest[16])
/* Pad out to 56 mod 64 */
if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */
pj_bzero(p, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (pj_uint32_t *) ctx->in);
/* Two lots of padding: Pad the first block to 64 bytes */
pj_bzero(p, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (pj_uint32_t *) ctx->in);
/* Now fill the next block with 56 bytes */
pj_bzero(ctx->in, 56);
/* Now fill the next block with 56 bytes */
pj_bzero(ctx->in, 56);
} else {
/* Pad block to 56 bytes */
pj_bzero(p, count - 8);
/* Pad block to 56 bytes */
pj_bzero(p, count - 8);
}
byteReverse(ctx->in, 14);
@ -159,7 +158,7 @@ PJ_DEF(void) pj_md5_final(pj_md5_context *ctx, unsigned char digest[16])
MD5Transform(ctx->buf, (pj_uint32_t *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
pj_memcpy(digest, ctx->buf, 16);
pj_bzero(ctx, sizeof(*ctx)); /* In case it's sensitive */
pj_bzero(ctx, sizeof(*ctx)); /* In case it's sensitive */
}
#ifndef ASM_MD5
@ -174,7 +173,7 @@ PJ_DEF(void) pj_md5_final(pj_md5_context *ctx, unsigned char digest[16])
/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
/*
* The core of the MD5 algorithm, this alters an existing MD5 hash to

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -27,7 +26,7 @@
#include <pj/string.h>
#if 0
# define TRACE_(x) PJ_LOG(5,x)
# define TRACE_(x) PJ_LOG(5,x)
#else
# define TRACE_(x)
#endif
@ -68,25 +67,25 @@ typedef pj_uint8_t pj_pcap_eth_hdr[14];
typedef struct pj_pcap_ip_hdr
{
pj_uint8_t v_ihl;
pj_uint8_t tos;
pj_uint16_t len;
pj_uint16_t id;
pj_uint16_t flags_fragment;
pj_uint8_t ttl;
pj_uint8_t proto;
pj_uint16_t csum;
pj_uint32_t ip_src;
pj_uint32_t ip_dst;
pj_uint8_t v_ihl;
pj_uint8_t tos;
pj_uint16_t len;
pj_uint16_t id;
pj_uint16_t flags_fragment;
pj_uint8_t ttl;
pj_uint8_t proto;
pj_uint16_t csum;
pj_uint32_t ip_src;
pj_uint32_t ip_dst;
} pj_pcap_ip_hdr;
/* Implementation of pcap file */
struct pj_pcap_file
{
char obj_name[PJ_MAX_OBJ_NAME];
char obj_name[PJ_MAX_OBJ_NAME];
pj_oshandle_t fd;
pj_bool_t swap;
pj_pcap_hdr hdr;
pj_bool_t swap;
pj_pcap_hdr hdr;
pj_pcap_filter filter;
};
@ -100,8 +99,8 @@ PJ_DEF(void) pj_pcap_filter_default(pj_pcap_filter *filter)
/* Open pcap file */
PJ_DEF(pj_status_t) pj_pcap_open(pj_pool_t *pool,
const char *path,
pj_pcap_file **p_file)
const char *path,
pj_pcap_file **p_file)
{
pj_pcap_file *file;
pj_ssize_t sz;
@ -111,13 +110,13 @@ PJ_DEF(pj_status_t) pj_pcap_open(pj_pool_t *pool,
/* More sanity checks */
TRACE_(("pcap", "sizeof(pj_pcap_eth_hdr)=%d",
sizeof(pj_pcap_eth_hdr)));
sizeof(pj_pcap_eth_hdr)));
PJ_ASSERT_RETURN(sizeof(pj_pcap_eth_hdr)==14, PJ_EBUG);
TRACE_(("pcap", "sizeof(pj_pcap_ip_hdr)=%d",
sizeof(pj_pcap_ip_hdr)));
sizeof(pj_pcap_ip_hdr)));
PJ_ASSERT_RETURN(sizeof(pj_pcap_ip_hdr)==20, PJ_EBUG);
TRACE_(("pcap", "sizeof(pj_pcap_udp_hdr)=%d",
sizeof(pj_pcap_udp_hdr)));
sizeof(pj_pcap_udp_hdr)));
PJ_ASSERT_RETURN(sizeof(pj_pcap_udp_hdr)==8, PJ_EBUG);
file = PJ_POOL_ZALLOC_T(pool, pj_pcap_file);
@ -126,26 +125,26 @@ PJ_DEF(pj_status_t) pj_pcap_open(pj_pool_t *pool,
status = pj_file_open(pool, path, PJ_O_RDONLY, &file->fd);
if (status != PJ_SUCCESS)
return status;
return status;
/* Read file pcap header */
sz = sizeof(file->hdr);
status = pj_file_read(file->fd, &file->hdr, &sz);
if (status != PJ_SUCCESS) {
pj_file_close(file->fd);
return status;
pj_file_close(file->fd);
return status;
}
/* Check magic number */
if (file->hdr.magic_number == 0xa1b2c3d4) {
file->swap = PJ_FALSE;
file->swap = PJ_FALSE;
} else if (file->hdr.magic_number == 0xd4c3b2a1) {
file->swap = PJ_TRUE;
file->hdr.network = pj_ntohl(file->hdr.network);
file->swap = PJ_TRUE;
file->hdr.network = pj_ntohl(file->hdr.network);
} else {
/* Not PCAP file */
pj_file_close(file->fd);
return PJ_EINVALIDOP;
/* Not PCAP file */
pj_file_close(file->fd);
return PJ_EINVALIDOP;
}
TRACE_((file->obj_name, "PCAP file %s opened", path));
@ -164,7 +163,7 @@ PJ_DEF(pj_status_t) pj_pcap_close(pj_pcap_file *file)
/* Setup filter */
PJ_DEF(pj_status_t) pj_pcap_set_filter(pj_pcap_file *file,
const pj_pcap_filter *fil)
const pj_pcap_filter *fil)
{
PJ_ASSERT_RETURN(file && fil, PJ_EINVAL);
pj_memcpy(&file->filter, fil, sizeof(pj_pcap_filter));
@ -173,15 +172,15 @@ PJ_DEF(pj_status_t) pj_pcap_set_filter(pj_pcap_file *file,
/* Read file */
static pj_status_t read_file(pj_pcap_file *file,
void *buf,
pj_ssize_t *sz)
void *buf,
pj_ssize_t *sz)
{
pj_status_t status;
status = pj_file_read(file->fd, buf, sz);
if (status != PJ_SUCCESS)
return status;
return status;
if (*sz == 0)
return PJ_EEOF;
return PJ_EEOF;
return PJ_SUCCESS;
}
@ -190,206 +189,206 @@ static pj_status_t skip(pj_oshandle_t fd, pj_off_t bytes)
pj_status_t status;
status = pj_file_setpos(fd, bytes, PJ_SEEK_CUR);
if (status != PJ_SUCCESS)
return status;
return status;
return PJ_SUCCESS;
}
#define SKIP_PKT() \
if (rec_incl > sz_read) { \
status = skip(file->fd, rec_incl-sz_read);\
if (status != PJ_SUCCESS) \
return status; \
}
if (rec_incl > sz_read) { \
status = skip(file->fd, rec_incl-sz_read);\
if (status != PJ_SUCCESS) \
return status; \
}
/* Read UDP packet */
PJ_DEF(pj_status_t) pj_pcap_read_udp(pj_pcap_file *file,
pj_pcap_udp_hdr *udp_hdr,
pj_uint8_t *udp_payload,
pj_size_t *udp_payload_size)
pj_pcap_udp_hdr *udp_hdr,
pj_uint8_t *udp_payload,
pj_size_t *udp_payload_size)
{
PJ_ASSERT_RETURN(file && udp_payload && udp_payload_size, PJ_EINVAL);
PJ_ASSERT_RETURN(*udp_payload_size, PJ_EINVAL);
/* Check data link type in PCAP file header */
if ((file->filter.link &&
file->hdr.network != (pj_uint32_t)file->filter.link) ||
file->hdr.network != PJ_PCAP_LINK_TYPE_ETH)
file->hdr.network != (pj_uint32_t)file->filter.link) ||
file->hdr.network != PJ_PCAP_LINK_TYPE_ETH)
{
/* Link header other than Ethernet is not supported for now */
return PJ_ENOTSUP;
/* Link header other than Ethernet is not supported for now */
return PJ_ENOTSUP;
}
/* Loop until we have the packet */
for (;;) {
union {
pj_pcap_rec_hdr rec;
pj_pcap_eth_hdr eth;
pj_pcap_ip_hdr ip;
pj_pcap_udp_hdr udp;
} tmp;
unsigned rec_incl;
pj_ssize_t sz;
pj_size_t sz_read = 0;
char addr[PJ_INET_ADDRSTRLEN];
pj_status_t status;
union {
pj_pcap_rec_hdr rec;
pj_pcap_eth_hdr eth;
pj_pcap_ip_hdr ip;
pj_pcap_udp_hdr udp;
} tmp;
unsigned rec_incl;
pj_ssize_t sz;
pj_size_t sz_read = 0;
char addr[PJ_INET_ADDRSTRLEN];
pj_status_t status;
TRACE_((file->obj_name, "Reading packet.."));
pj_bzero(&addr, sizeof(addr));
TRACE_((file->obj_name, "Reading packet.."));
pj_bzero(&addr, sizeof(addr));
/* Read PCAP packet header */
sz = sizeof(tmp.rec);
status = read_file(file, &tmp.rec, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "read_file() error: %d", status));
return status;
}
/* Read PCAP packet header */
sz = sizeof(tmp.rec);
status = read_file(file, &tmp.rec, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "read_file() error: %d", status));
return status;
}
rec_incl = tmp.rec.incl_len;
rec_incl = tmp.rec.incl_len;
/* Swap byte ordering */
if (file->swap) {
tmp.rec.incl_len = pj_ntohl(tmp.rec.incl_len);
tmp.rec.orig_len = pj_ntohl(tmp.rec.orig_len);
tmp.rec.ts_sec = pj_ntohl(tmp.rec.ts_sec);
tmp.rec.ts_usec = pj_ntohl(tmp.rec.ts_usec);
}
/* Swap byte ordering */
if (file->swap) {
tmp.rec.incl_len = pj_ntohl(tmp.rec.incl_len);
tmp.rec.orig_len = pj_ntohl(tmp.rec.orig_len);
tmp.rec.ts_sec = pj_ntohl(tmp.rec.ts_sec);
tmp.rec.ts_usec = pj_ntohl(tmp.rec.ts_usec);
}
/* Read link layer header */
switch (file->hdr.network) {
case PJ_PCAP_LINK_TYPE_ETH:
sz = sizeof(tmp.eth);
status = read_file(file, &tmp.eth, &sz);
break;
default:
TRACE_((file->obj_name, "Error: link layer not Ethernet"));
return PJ_ENOTSUP;
}
/* Read link layer header */
switch (file->hdr.network) {
case PJ_PCAP_LINK_TYPE_ETH:
sz = sizeof(tmp.eth);
status = read_file(file, &tmp.eth, &sz);
break;
default:
TRACE_((file->obj_name, "Error: link layer not Ethernet"));
return PJ_ENOTSUP;
}
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading Eth header: %d", status));
return status;
}
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading Eth header: %d", status));
return status;
}
sz_read += sz;
/* Read IP header */
sz = sizeof(tmp.ip);
status = read_file(file, &tmp.ip, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading IP header: %d", status));
return status;
}
sz_read += sz;
/* Read IP header */
sz = sizeof(tmp.ip);
status = read_file(file, &tmp.ip, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading IP header: %d", status));
return status;
}
sz_read += sz;
sz_read += sz;
/* Skip if IP source mismatch */
if (file->filter.ip_src && tmp.ip.ip_src != file->filter.ip_src) {
TRACE_((file->obj_name, "IP source %s mismatch, skipping",
pj_inet_ntop2(pj_AF_INET(), (pj_in_addr*)&tmp.ip.ip_src,
addr, sizeof(addr))));
SKIP_PKT();
continue;
}
/* Skip if IP source mismatch */
if (file->filter.ip_src && tmp.ip.ip_src != file->filter.ip_src) {
TRACE_((file->obj_name, "IP source %s mismatch, skipping",
pj_inet_ntop2(pj_AF_INET(), (pj_in_addr*)&tmp.ip.ip_src,
addr, sizeof(addr))));
SKIP_PKT();
continue;
}
/* Skip if IP destination mismatch */
if (file->filter.ip_dst && tmp.ip.ip_dst != file->filter.ip_dst) {
TRACE_((file->obj_name, "IP detination %s mismatch, skipping",
pj_inet_ntop2(pj_AF_INET(), (pj_in_addr*)&tmp.ip.ip_dst,
addr, sizeof(addr))));
SKIP_PKT();
continue;
}
/* Skip if IP destination mismatch */
if (file->filter.ip_dst && tmp.ip.ip_dst != file->filter.ip_dst) {
TRACE_((file->obj_name, "IP detination %s mismatch, skipping",
pj_inet_ntop2(pj_AF_INET(), (pj_in_addr*)&tmp.ip.ip_dst,
addr, sizeof(addr))));
SKIP_PKT();
continue;
}
/* Skip if proto mismatch */
if (file->filter.proto && tmp.ip.proto != file->filter.proto) {
TRACE_((file->obj_name, "IP proto %d mismatch, skipping",
tmp.ip.proto));
SKIP_PKT();
continue;
}
/* Skip if proto mismatch */
if (file->filter.proto && tmp.ip.proto != file->filter.proto) {
TRACE_((file->obj_name, "IP proto %d mismatch, skipping",
tmp.ip.proto));
SKIP_PKT();
continue;
}
/* Read transport layer header */
switch (tmp.ip.proto) {
case PJ_PCAP_PROTO_TYPE_UDP:
sz = sizeof(tmp.udp);
status = read_file(file, &tmp.udp, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading UDP header: %d",status));
return status;
}
/* Read transport layer header */
switch (tmp.ip.proto) {
case PJ_PCAP_PROTO_TYPE_UDP:
sz = sizeof(tmp.udp);
status = read_file(file, &tmp.udp, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading UDP header: %d",status));
return status;
}
sz_read += sz;
sz_read += sz;
/* Skip if source port mismatch */
if (file->filter.src_port &&
tmp.udp.src_port != file->filter.src_port)
{
TRACE_((file->obj_name, "UDP src port %d mismatch, skipping",
pj_ntohs(tmp.udp.src_port)));
SKIP_PKT();
continue;
}
/* Skip if source port mismatch */
if (file->filter.src_port &&
tmp.udp.src_port != file->filter.src_port)
{
TRACE_((file->obj_name, "UDP src port %d mismatch, skipping",
pj_ntohs(tmp.udp.src_port)));
SKIP_PKT();
continue;
}
/* Skip if destination port mismatch */
if (file->filter.dst_port &&
tmp.udp.dst_port != file->filter.dst_port)
{
TRACE_((file->obj_name, "UDP dst port %d mismatch, skipping",
pj_ntohs(tmp.udp.dst_port)));
SKIP_PKT();
continue;
}
/* Skip if destination port mismatch */
if (file->filter.dst_port &&
tmp.udp.dst_port != file->filter.dst_port)
{
TRACE_((file->obj_name, "UDP dst port %d mismatch, skipping",
pj_ntohs(tmp.udp.dst_port)));
SKIP_PKT();
continue;
}
/* Copy UDP header if caller wants it */
if (udp_hdr) {
pj_memcpy(udp_hdr, &tmp.udp, sizeof(*udp_hdr));
}
/* Copy UDP header if caller wants it */
if (udp_hdr) {
pj_memcpy(udp_hdr, &tmp.udp, sizeof(*udp_hdr));
}
/* Calculate payload size */
sz = pj_ntohs(tmp.udp.len) - sizeof(tmp.udp);
break;
default:
TRACE_((file->obj_name, "Not UDP, skipping"));
SKIP_PKT();
continue;
}
/* Calculate payload size */
sz = pj_ntohs(tmp.udp.len) - sizeof(tmp.udp);
break;
default:
TRACE_((file->obj_name, "Not UDP, skipping"));
SKIP_PKT();
continue;
}
/* Check if payload fits the buffer */
if (sz > (pj_ssize_t)*udp_payload_size) {
TRACE_((file->obj_name,
"Error: packet too large (%d bytes required)", sz));
SKIP_PKT();
return PJ_ETOOSMALL;
}
/* Check if payload fits the buffer */
if (sz > (pj_ssize_t)*udp_payload_size) {
TRACE_((file->obj_name,
"Error: packet too large (%d bytes required)", sz));
SKIP_PKT();
return PJ_ETOOSMALL;
}
/* Read the payload */
status = read_file(file, udp_payload, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading payload: %d", status));
return status;
}
/* Read the payload */
status = read_file(file, udp_payload, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading payload: %d", status));
return status;
}
sz_read += sz;
sz_read += sz;
*udp_payload_size = sz;
*udp_payload_size = sz;
// Some layers may have trailer, e.g: link eth2.
/* Check that we've read all the packets */
//PJ_ASSERT_RETURN(sz_read == rec_incl, PJ_EBUG);
// Some layers may have trailer, e.g: link eth2.
/* Check that we've read all the packets */
//PJ_ASSERT_RETURN(sz_read == rec_incl, PJ_EBUG);
/* Skip trailer */
while (sz_read < rec_incl) {
sz = rec_incl - sz_read;
status = read_file(file, &tmp.eth, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading trailer: %d", status));
return status;
}
sz_read += sz;
}
/* Skip trailer */
while (sz_read < rec_incl) {
sz = rec_incl - sz_read;
status = read_file(file, &tmp.eth, &sz);
if (status != PJ_SUCCESS) {
TRACE_((file->obj_name, "Error reading trailer: %d", status));
return status;
}
sz_read += sz;
}
return PJ_SUCCESS;
return PJ_SUCCESS;
}
/* Does not reach here */

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2009-2011 Teluu Inc. (http://www.teluu.com)
*

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -28,10 +27,10 @@
#define THIS_FILE "scanner.c"
#define PJ_SCAN_IS_SPACE(c) ((c)==' ' || (c)=='\t')
#define PJ_SCAN_IS_NEWLINE(c) ((c)=='\r' || (c)=='\n')
#define PJ_SCAN_IS_PROBABLY_SPACE(c) ((c) <= 32)
#define PJ_SCAN_CHECK_EOF(s) (s != scanner->end)
#define PJ_SCAN_IS_SPACE(c) ((c)==' ' || (c)=='\t')
#define PJ_SCAN_IS_NEWLINE(c) ((c)=='\r' || (c)=='\n')
#define PJ_SCAN_IS_PROBABLY_SPACE(c) ((c) <= 32)
#define PJ_SCAN_CHECK_EOF(s) (s != scanner->end)
#if defined(PJ_SCANNER_USE_BITWISE) && PJ_SCANNER_USE_BITWISE != 0
@ -54,7 +53,7 @@ PJ_DEF(void) pj_cis_add_range(pj_cis_t *cis, int cstart, int cend)
while (cstart != cend) {
PJ_CIS_SET(cis, cstart);
++cstart;
++cstart;
}
}
@ -73,7 +72,7 @@ PJ_DEF(void) pj_cis_add_str( pj_cis_t *cis, const char *str)
{
while (*str) {
PJ_CIS_SET(cis, *str);
++str;
++str;
}
}
@ -81,8 +80,8 @@ PJ_DEF(void) pj_cis_add_cis( pj_cis_t *cis, const pj_cis_t *rhs)
{
int i;
for (i=0; i<256; ++i) {
if (PJ_CIS_ISSET(rhs, i))
PJ_CIS_SET(cis, i);
if (PJ_CIS_ISSET(rhs, i))
PJ_CIS_SET(cis, i);
}
}
@ -98,7 +97,7 @@ PJ_DEF(void) pj_cis_del_str( pj_cis_t *cis, const char *str)
{
while (*str) {
PJ_CIS_CLR(cis, *str);
++str;
++str;
}
}
@ -107,7 +106,7 @@ PJ_DEF(void) pj_cis_invert( pj_cis_t *cis )
unsigned i;
/* Can not set zero. This is the requirement of the parser. */
for (i=1; i<256; ++i) {
if (PJ_CIS_ISSET(cis,i))
if (PJ_CIS_ISSET(cis,i))
PJ_CIS_CLR(cis,i);
else
PJ_CIS_SET(cis,i);
@ -115,8 +114,8 @@ PJ_DEF(void) pj_cis_invert( pj_cis_t *cis )
}
PJ_DEF(void) pj_scan_init( pj_scanner *scanner, char *bufstart,
pj_size_t buflen, unsigned options,
pj_syn_err_func_ptr callback )
pj_size_t buflen, unsigned options,
pj_syn_err_func_ptr callback )
{
PJ_CHECK_STACK();
@ -128,7 +127,7 @@ PJ_DEF(void) pj_scan_init( pj_scanner *scanner, char *bufstart,
scanner->skip_ws = options;
if (scanner->skip_ws)
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
@ -143,53 +142,53 @@ PJ_DEF(void) pj_scan_skip_whitespace( pj_scanner *scanner )
register char *s = scanner->curptr;
while (PJ_SCAN_IS_SPACE(*s)) {
++s;
++s;
}
if (PJ_SCAN_IS_NEWLINE(*s) && (scanner->skip_ws & PJ_SCAN_AUTOSKIP_NEWLINE)) {
for (;;) {
if (*s == '\r') {
++s;
if (*s == '\n') ++s;
++scanner->line;
scanner->curptr = scanner->start_line = s;
} else if (*s == '\n') {
++s;
++scanner->line;
scanner->curptr = scanner->start_line = s;
} else if (PJ_SCAN_IS_SPACE(*s)) {
do {
++s;
} while (PJ_SCAN_IS_SPACE(*s));
} else {
break;
}
}
for (;;) {
if (*s == '\r') {
++s;
if (*s == '\n') ++s;
++scanner->line;
scanner->curptr = scanner->start_line = s;
} else if (*s == '\n') {
++s;
++scanner->line;
scanner->curptr = scanner->start_line = s;
} else if (PJ_SCAN_IS_SPACE(*s)) {
do {
++s;
} while (PJ_SCAN_IS_SPACE(*s));
} else {
break;
}
}
}
if (PJ_SCAN_IS_NEWLINE(*s) && (scanner->skip_ws & PJ_SCAN_AUTOSKIP_WS_HEADER)==PJ_SCAN_AUTOSKIP_WS_HEADER) {
/* Check for header continuation. */
scanner->curptr = s;
/* Check for header continuation. */
scanner->curptr = s;
if (*s == '\r') {
++s;
}
if (*s == '\n') {
++s;
}
scanner->start_line = s;
if (*s == '\r') {
++s;
}
if (*s == '\n') {
++s;
}
scanner->start_line = s;
if (PJ_SCAN_IS_SPACE(*s)) {
register char *t = s;
do {
++t;
} while (PJ_SCAN_IS_SPACE(*t));
if (PJ_SCAN_IS_SPACE(*s)) {
register char *t = s;
do {
++t;
} while (PJ_SCAN_IS_SPACE(*t));
++scanner->line;
scanner->curptr = t;
}
++scanner->line;
scanner->curptr = t;
}
} else {
scanner->curptr = s;
scanner->curptr = s;
}
}
@ -203,26 +202,26 @@ PJ_DEF(void) pj_scan_skip_line( pj_scanner *scanner )
s = pj_memchr(scanner->curptr, '\n', scanner->end - scanner->curptr);
if (!s) {
scanner->curptr = scanner->end;
scanner->curptr = scanner->end;
} else {
scanner->curptr = scanner->start_line = s+1;
scanner->line++;
scanner->curptr = scanner->start_line = s+1;
scanner->line++;
}
}
PJ_DEF(int) pj_scan_peek( pj_scanner *scanner,
const pj_cis_t *spec, pj_str_t *out)
const pj_cis_t *spec, pj_str_t *out)
{
register char *s = scanner->curptr;
if (s >= scanner->end) {
pj_scan_syntax_err(scanner);
return -1;
pj_scan_syntax_err(scanner);
return -1;
}
/* Don't need to check EOF with PJ_SCAN_CHECK_EOF(s) */
while (pj_cis_match(spec, *s))
++s;
++s;
pj_strset3(out, scanner->curptr, s);
return *s;
@ -230,13 +229,13 @@ PJ_DEF(int) pj_scan_peek( pj_scanner *scanner,
PJ_DEF(int) pj_scan_peek_n( pj_scanner *scanner,
pj_size_t len, pj_str_t *out)
pj_size_t len, pj_str_t *out)
{
char *endpos = scanner->curptr + len;
if (endpos > scanner->end) {
pj_scan_syntax_err(scanner);
return -1;
pj_scan_syntax_err(scanner);
return -1;
}
pj_strset(out, scanner->curptr, len);
@ -245,18 +244,18 @@ PJ_DEF(int) pj_scan_peek_n( pj_scanner *scanner,
PJ_DEF(int) pj_scan_peek_until( pj_scanner *scanner,
const pj_cis_t *spec,
pj_str_t *out)
const pj_cis_t *spec,
pj_str_t *out)
{
register char *s = scanner->curptr;
if (s >= scanner->end) {
pj_scan_syntax_err(scanner);
return -1;
pj_scan_syntax_err(scanner);
return -1;
}
while (PJ_SCAN_CHECK_EOF(s) && !pj_cis_match( spec, *s))
++s;
++s;
pj_strset3(out, scanner->curptr, s);
return *s;
@ -264,19 +263,19 @@ PJ_DEF(int) pj_scan_peek_until( pj_scanner *scanner,
PJ_DEF(void) pj_scan_get( pj_scanner *scanner,
const pj_cis_t *spec, pj_str_t *out)
const pj_cis_t *spec, pj_str_t *out)
{
register char *s = scanner->curptr;
pj_assert(pj_cis_match(spec,0)==0);
if (pj_scan_is_eof(scanner) || !pj_cis_match(spec, *s)) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
do {
++s;
++s;
} while (pj_cis_match(spec, *s));
/* No need to check EOF here (PJ_SCAN_CHECK_EOF(s)) because
* buffer is NULL terminated and pj_cis_match(spec,0) should be
@ -288,13 +287,13 @@ PJ_DEF(void) pj_scan_get( pj_scanner *scanner,
scanner->curptr = s;
if (PJ_SCAN_IS_PROBABLY_SPACE(*s) && scanner->skip_ws) {
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
}
PJ_DEF(void) pj_scan_get_unescape( pj_scanner *scanner,
const pj_cis_t *spec, pj_str_t *out)
const pj_cis_t *spec, pj_str_t *out)
{
register char *s = scanner->curptr;
char *dst = s;
@ -305,51 +304,51 @@ PJ_DEF(void) pj_scan_get_unescape( pj_scanner *scanner,
pj_assert(pj_cis_match(spec,'%')==0);
if (pj_scan_is_eof(scanner) || (!pj_cis_match(spec, *s) && *s != '%')) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
out->ptr = s;
do {
if (*s == '%') {
if (s+3 <= scanner->end && pj_isxdigit(*(s+1)) &&
pj_isxdigit(*(s+2)))
{
*dst = (pj_uint8_t) ((pj_hex_digit_to_val(*(s+1)) << 4) +
pj_hex_digit_to_val(*(s+2)));
++dst;
s += 3;
} else {
*dst++ = *s++;
*dst++ = *s++;
break;
}
}
if (pj_cis_match(spec, *s)) {
char *start = s;
do {
++s;
} while (pj_cis_match(spec, *s));
if (*s == '%') {
if (s+3 <= scanner->end && pj_isxdigit(*(s+1)) &&
pj_isxdigit(*(s+2)))
{
*dst = (pj_uint8_t) ((pj_hex_digit_to_val(*(s+1)) << 4) +
pj_hex_digit_to_val(*(s+2)));
++dst;
s += 3;
} else {
*dst++ = *s++;
*dst++ = *s++;
break;
}
}
if (pj_cis_match(spec, *s)) {
char *start = s;
do {
++s;
} while (pj_cis_match(spec, *s));
if (dst != start) pj_memmove(dst, start, s-start);
dst += (s-start);
}
if (dst != start) pj_memmove(dst, start, s-start);
dst += (s-start);
}
} while (*s == '%');
scanner->curptr = s;
out->slen = (dst - out->ptr);
if (PJ_SCAN_IS_PROBABLY_SPACE(*s) && scanner->skip_ws) {
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
}
PJ_DEF(void) pj_scan_get_quote( pj_scanner *scanner,
int begin_quote, int end_quote,
pj_str_t *out)
int begin_quote, int end_quote,
pj_str_t *out)
{
char beg = (char)begin_quote;
char end = (char)end_quote;
@ -368,53 +367,53 @@ PJ_DEF(void) pj_scan_get_quotes(pj_scanner *scanner,
/* Check and eat the begin_quote. */
for (i = 0; i < qsize; ++i) {
if (*s == begin_quote[i]) {
qpair = i;
break;
}
if (*s == begin_quote[i]) {
qpair = i;
break;
}
}
if (qpair == -1) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
++s;
/* Loop until end_quote is found.
*/
do {
/* loop until end_quote is found. */
while (PJ_SCAN_CHECK_EOF(s) && *s != '\n' && *s != end_quote[qpair]) {
++s;
}
/* loop until end_quote is found. */
while (PJ_SCAN_CHECK_EOF(s) && *s != '\n' && *s != end_quote[qpair]) {
++s;
}
/* check that no backslash character precedes the end_quote. */
if (*s == end_quote[qpair]) {
if (*(s-1) == '\\') {
char *q = s-2;
char *r = s-2;
/* check that no backslash character precedes the end_quote. */
if (*s == end_quote[qpair]) {
if (*(s-1) == '\\') {
char *q = s-2;
char *r = s-2;
while (r != scanner->begin && *r == '\\') {
--r;
}
/* break from main loop if we have odd number of backslashes */
if (((unsigned)(q-r) & 0x01) == 1) {
break;
}
++s;
} else {
/* end_quote is not preceeded by backslash. break now. */
break;
}
} else {
/* loop ended by non-end_quote character. break now. */
break;
}
while (r != scanner->begin && *r == '\\') {
--r;
}
/* break from main loop if we have odd number of backslashes */
if (((unsigned)(q-r) & 0x01) == 1) {
break;
}
++s;
} else {
/* end_quote is not preceeded by backslash. break now. */
break;
}
} else {
/* loop ended by non-end_quote character. break now. */
break;
}
} while (1);
/* Check and eat the end quote. */
if (*s != end_quote[qpair]) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
++s;
@ -423,17 +422,17 @@ PJ_DEF(void) pj_scan_get_quotes(pj_scanner *scanner,
scanner->curptr = s;
if (PJ_SCAN_IS_PROBABLY_SPACE(*s) && scanner->skip_ws) {
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
}
PJ_DEF(void) pj_scan_get_n( pj_scanner *scanner,
unsigned N, pj_str_t *out)
unsigned N, pj_str_t *out)
{
if (scanner->curptr + N > scanner->end) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
pj_strset(out, scanner->curptr, N);
@ -441,9 +440,9 @@ PJ_DEF(void) pj_scan_get_n( pj_scanner *scanner,
scanner->curptr += N;
if (!pj_scan_is_eof(scanner) &&
PJ_SCAN_IS_PROBABLY_SPACE(*scanner->curptr) && scanner->skip_ws)
PJ_SCAN_IS_PROBABLY_SPACE(*scanner->curptr) && scanner->skip_ws)
{
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
}
@ -454,8 +453,8 @@ PJ_DEF(int) pj_scan_get_char( pj_scanner *scanner )
int chr;
if (s >= scanner->end || !*s) {
pj_scan_syntax_err(scanner);
return 0;
pj_scan_syntax_err(scanner);
return 0;
}
chr = *s;
@ -463,9 +462,9 @@ PJ_DEF(int) pj_scan_get_char( pj_scanner *scanner )
++s;
scanner->curptr = s;
if (PJ_SCAN_CHECK_EOF(s) && PJ_SCAN_IS_PROBABLY_SPACE(*s) &&
scanner->skip_ws)
scanner->skip_ws)
{
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
return chr;
}
@ -474,16 +473,16 @@ PJ_DEF(int) pj_scan_get_char( pj_scanner *scanner )
PJ_DEF(void) pj_scan_get_newline( pj_scanner *scanner )
{
if (pj_scan_is_eof(scanner) || !PJ_SCAN_IS_NEWLINE(*scanner->curptr)) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
/* We have checked scanner->curptr validity above */
if (*scanner->curptr == '\r') {
++scanner->curptr;
++scanner->curptr;
}
if (!pj_scan_is_eof(scanner) && *scanner->curptr == '\n') {
++scanner->curptr;
++scanner->curptr;
}
++scanner->line;
@ -494,9 +493,9 @@ PJ_DEF(void) pj_scan_get_newline( pj_scanner *scanner )
* This would cause scanner to incorrectly eat two new lines, e.g.
* when parsing:
*
* Content-Length: 120\r\n
* \r\n
* <space><space><space>...
* Content-Length: 120\r\n
* \r\n
* <space><space><space>...
*
* When pj_scan_get_newline() is called to parse the first newline
* in the Content-Length header, it will eat the second newline
@ -510,17 +509,17 @@ PJ_DEF(void) pj_scan_get_newline( pj_scanner *scanner )
PJ_DEF(void) pj_scan_get_until( pj_scanner *scanner,
const pj_cis_t *spec, pj_str_t *out)
const pj_cis_t *spec, pj_str_t *out)
{
register char *s = scanner->curptr;
if (s >= scanner->end) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
while (PJ_SCAN_CHECK_EOF(s) && !pj_cis_match(spec, *s)) {
++s;
++s;
}
pj_strset3(out, scanner->curptr, s);
@ -528,25 +527,25 @@ PJ_DEF(void) pj_scan_get_until( pj_scanner *scanner,
scanner->curptr = s;
if (!pj_scan_is_eof(scanner) && PJ_SCAN_IS_PROBABLY_SPACE(*s) &&
scanner->skip_ws)
scanner->skip_ws)
{
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
}
PJ_DEF(void) pj_scan_get_until_ch( pj_scanner *scanner,
int until_char, pj_str_t *out)
int until_char, pj_str_t *out)
{
register char *s = scanner->curptr;
if (s >= scanner->end) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
while (PJ_SCAN_CHECK_EOF(s) && *s != until_char) {
++s;
++s;
}
pj_strset3(out, scanner->curptr, s);
@ -554,27 +553,27 @@ PJ_DEF(void) pj_scan_get_until_ch( pj_scanner *scanner,
scanner->curptr = s;
if (!pj_scan_is_eof(scanner) && PJ_SCAN_IS_PROBABLY_SPACE(*s) &&
scanner->skip_ws)
scanner->skip_ws)
{
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
}
PJ_DEF(void) pj_scan_get_until_chr( pj_scanner *scanner,
const char *until_spec, pj_str_t *out)
const char *until_spec, pj_str_t *out)
{
register char *s = scanner->curptr;
pj_size_t speclen;
if (s >= scanner->end) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
speclen = strlen(until_spec);
while (PJ_SCAN_CHECK_EOF(s) && !memchr(until_spec, *s, speclen)) {
++s;
++s;
}
pj_strset3(out, scanner->curptr, s);
@ -582,26 +581,26 @@ PJ_DEF(void) pj_scan_get_until_chr( pj_scanner *scanner,
scanner->curptr = s;
if (!pj_scan_is_eof(scanner) && PJ_SCAN_IS_PROBABLY_SPACE(*s) &&
scanner->skip_ws)
scanner->skip_ws)
{
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
}
PJ_DEF(void) pj_scan_advance_n( pj_scanner *scanner,
unsigned N, pj_bool_t skip_ws)
unsigned N, pj_bool_t skip_ws)
{
if (scanner->curptr + N > scanner->end) {
pj_scan_syntax_err(scanner);
return;
pj_scan_syntax_err(scanner);
return;
}
scanner->curptr += N;
if (!pj_scan_is_eof(scanner) &&
PJ_SCAN_IS_PROBABLY_SPACE(*scanner->curptr) && skip_ws)
PJ_SCAN_IS_PROBABLY_SPACE(*scanner->curptr) && skip_ws)
{
pj_scan_skip_whitespace(scanner);
pj_scan_skip_whitespace(scanner);
}
}
@ -609,8 +608,8 @@ PJ_DEF(void) pj_scan_advance_n( pj_scanner *scanner,
PJ_DEF(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len)
{
if (scanner->curptr + len > scanner->end) {
pj_scan_syntax_err(scanner);
return -1;
pj_scan_syntax_err(scanner);
return -1;
}
return strncmp(scanner->curptr, s, len);
}
@ -619,24 +618,24 @@ PJ_DEF(int) pj_scan_strcmp( pj_scanner *scanner, const char *s, int len)
PJ_DEF(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len)
{
if (scanner->curptr + len > scanner->end) {
pj_scan_syntax_err(scanner);
return -1;
pj_scan_syntax_err(scanner);
return -1;
}
return pj_ansi_strnicmp(scanner->curptr, s, len);
}
PJ_DEF(int) pj_scan_stricmp_alnum( pj_scanner *scanner, const char *s,
int len)
int len)
{
if (scanner->curptr + len > scanner->end) {
pj_scan_syntax_err(scanner);
return -1;
pj_scan_syntax_err(scanner);
return -1;
}
return strnicmp_alnum(scanner->curptr, s, len);
}
PJ_DEF(void) pj_scan_save_state( const pj_scanner *scanner,
pj_scan_state *state)
pj_scan_state *state)
{
state->curptr = scanner->curptr;
state->line = scanner->line;
@ -645,7 +644,7 @@ PJ_DEF(void) pj_scan_save_state( const pj_scanner *scanner,
PJ_DEF(void) pj_scan_restore_state( pj_scanner *scanner,
pj_scan_state *state)
pj_scan_state *state)
{
scanner->curptr = state->curptr;
scanner->line = state->line;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -38,7 +37,7 @@ PJ_DEF(pj_status_t) pj_cis_init(pj_cis_buf_t *cis_buf, pj_cis_t *cis)
for (i=0; i<PJ_CIS_MAX_INDEX; ++i) {
if ((cis_buf->use_mask & (1 << i)) == 0) {
cis->cis_id = i;
cis_buf->use_mask |= (1 << i);
cis_buf->use_mask |= (1 << i);
return PJ_SUCCESS;
}
}

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Modified 2/07
* By Benny Prijono <benny@prijono.org>
@ -20,10 +19,10 @@ Still 100% Public Domain
Corrected a problem which generated improper hash values on 16 bit machines
Routine SHA1Update changed from
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int
len)
to
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned
long len)
The 'len' parameter was declared an int which works fine on 32 bit machines.
@ -204,20 +203,20 @@ PJ_DEF(void) pj_sha1_init(pj_sha1_context* context)
/* Run your data through this. */
PJ_DEF(void) pj_sha1_update(pj_sha1_context* context,
const pj_uint8_t* data, const pj_size_t len)
const pj_uint8_t* data, const pj_size_t len)
{
pj_size_t i, j;
j = (context->count[0] >> 3) & 63;
if ((context->count[0] += (pj_uint32_t)len << 3) < (len << 3))
context->count[1]++;
context->count[1]++;
context->count[1] += ((pj_uint32_t)len >> 29);
if ((j + len) > 63) {
pj_memcpy(&context->buffer[j], data, (i = 64-j));
SHA1_Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) {
pj_uint8_t tmp[64];
pj_memcpy(tmp, data + i, 64);
pj_uint8_t tmp[64];
pj_memcpy(tmp, data + i, 64);
SHA1_Transform(context->state, tmp);
}
j = 0;
@ -230,7 +229,7 @@ PJ_DEF(void) pj_sha1_update(pj_sha1_context* context,
/* Add padding and return the message digest. */
PJ_DEF(void) pj_sha1_final(pj_sha1_context* context,
pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE])
pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE])
{
pj_uint32_t i;
pj_uint8_t finalcount[8];
@ -254,7 +253,7 @@ PJ_DEF(void) pj_sha1_final(pj_sha1_context* context,
pj_memset(context->buffer, 0, 64);
pj_memset(context->state, 0, 20);
pj_memset(context->count, 0, 8);
pj_memset(finalcount, 0, 8); /* SWR */
pj_memset(finalcount, 0, 8); /* SWR */
#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */
SHA1_Transform(context->state, context->buffer);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -30,49 +29,49 @@ PJ_DEF(pj_str_t) pj_str_unescape( pj_pool_t *pool, const pj_str_t *src_str)
char *dst;
if (pj_strchr(src_str, '%')==NULL)
return *src_str;
return *src_str;
dst = dst_str.ptr = (char*) pj_pool_alloc(pool, src_str->slen);
while (src != end) {
if (*src == '%' && src < end-2 && pj_isxdigit(*(src+1)) &&
pj_isxdigit(*(src+2)))
{
*dst = (pj_uint8_t) ((pj_hex_digit_to_val(*(src+1)) << 4) +
pj_hex_digit_to_val(*(src+2)));
++dst;
src += 3;
} else {
*dst++ = *src++;
}
if (*src == '%' && src < end-2 && pj_isxdigit(*(src+1)) &&
pj_isxdigit(*(src+2)))
{
*dst = (pj_uint8_t) ((pj_hex_digit_to_val(*(src+1)) << 4) +
pj_hex_digit_to_val(*(src+2)));
++dst;
src += 3;
} else {
*dst++ = *src++;
}
}
dst_str.slen = dst - dst_str.ptr;
return dst_str;
}
PJ_DEF(pj_str_t*) pj_strcpy_unescape(pj_str_t *dst_str,
const pj_str_t *src_str)
const pj_str_t *src_str)
{
const char *src = src_str->ptr;
const char *end = src + src_str->slen;
char *dst = dst_str->ptr;
while (src != end) {
if (*src == '%' && src < end-2) {
*dst = (pj_uint8_t) ((pj_hex_digit_to_val(*(src+1)) << 4) +
pj_hex_digit_to_val(*(src+2)));
++dst;
src += 3;
} else {
*dst++ = *src++;
}
if (*src == '%' && src < end-2) {
*dst = (pj_uint8_t) ((pj_hex_digit_to_val(*(src+1)) << 4) +
pj_hex_digit_to_val(*(src+2)));
++dst;
src += 3;
} else {
*dst++ = *src++;
}
}
dst_str->slen = dst - dst_str->ptr;
return dst_str;
}
PJ_DEF(pj_ssize_t) pj_strncpy2_escape( char *dst_str, const pj_str_t *src_str,
pj_ssize_t max, const pj_cis_t *unres)
pj_ssize_t max, const pj_cis_t *unres)
{
const char *src = src_str->ptr;
const char *src_end = src + src_str->slen;
@ -80,29 +79,29 @@ PJ_DEF(pj_ssize_t) pj_strncpy2_escape( char *dst_str, const pj_str_t *src_str,
char *dst_end = dst + max;
if (max < src_str->slen)
return -1;
return -1;
while (src != src_end && dst != dst_end) {
if (pj_cis_match(unres, *src)) {
*dst++ = *src++;
} else {
if (dst < dst_end-2) {
*dst++ = '%';
pj_val_to_hex_digit(*src, dst);
dst+=2;
++src;
} else {
break;
}
}
if (pj_cis_match(unres, *src)) {
*dst++ = *src++;
} else {
if (dst < dst_end-2) {
*dst++ = '%';
pj_val_to_hex_digit(*src, dst);
dst+=2;
++src;
} else {
break;
}
}
}
return src==src_end ? dst-dst_str : -1;
}
PJ_DEF(pj_str_t*) pj_strncpy_escape(pj_str_t *dst_str,
const pj_str_t *src_str,
pj_ssize_t max, const pj_cis_t *unres)
const pj_str_t *src_str,
pj_ssize_t max, const pj_cis_t *unres)
{
dst_str->slen = pj_strncpy2_escape(dst_str->ptr, src_str, max, unres);
return dst_str->slen < 0 ? NULL : dst_str;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -27,9 +26,9 @@
#define THIS_FILE "stun_simple.c"
PJ_DEF(pj_status_t) pjstun_create_bind_req( pj_pool_t *pool,
void **msg, pj_size_t *len,
pj_uint32_t id_hi,
pj_uint32_t id_lo)
void **msg, pj_size_t *len,
pj_uint32_t id_hi,
pj_uint32_t id_lo)
{
pjstun_msg_hdr *hdr;
@ -38,7 +37,7 @@ PJ_DEF(pj_status_t) pjstun_create_bind_req( pj_pool_t *pool,
hdr = PJ_POOL_ZALLOC_T(pool, pjstun_msg_hdr);
if (!hdr)
return PJ_ENOMEM;
return PJ_ENOMEM;
hdr->type = pj_htons(PJSTUN_BINDING_REQUEST);
hdr->tsx[2] = pj_htonl(id_hi);
@ -50,7 +49,7 @@ PJ_DEF(pj_status_t) pjstun_create_bind_req( pj_pool_t *pool,
}
PJ_DEF(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t buf_len,
pjstun_msg *msg)
pjstun_msg *msg)
{
pj_uint16_t msg_type, msg_len;
char *p_attr;
@ -68,53 +67,53 @@ PJ_DEF(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t buf_len,
case PJSTUN_SHARED_SECRET_REQUEST:
case PJSTUN_SHARED_SECRET_RESPONSE:
case PJSTUN_SHARED_SECRET_ERROR_RESPONSE:
break;
break;
default:
PJ_LOG(4,(THIS_FILE, "Error: unknown msg type %d", msg_type));
return PJLIB_UTIL_ESTUNINMSGTYPE;
PJ_LOG(4,(THIS_FILE, "Error: unknown msg type %d", msg_type));
return PJLIB_UTIL_ESTUNINMSGTYPE;
}
msg_len = pj_ntohs(msg->hdr->length);
if (msg_len != buf_len - sizeof(pjstun_msg_hdr)) {
PJ_LOG(4,(THIS_FILE, "Error: invalid msg_len %d (expecting %d)",
msg_len, buf_len - sizeof(pjstun_msg_hdr)));
return PJLIB_UTIL_ESTUNINMSGLEN;
PJ_LOG(4,(THIS_FILE, "Error: invalid msg_len %d (expecting %d)",
msg_len, buf_len - sizeof(pjstun_msg_hdr)));
return PJLIB_UTIL_ESTUNINMSGLEN;
}
msg->attr_count = 0;
p_attr = (char*)buf + sizeof(pjstun_msg_hdr);
while (msg_len > 0 && msg->attr_count < attr_max_cnt) {
pjstun_attr_hdr **attr = &msg->attr[msg->attr_count];
pj_uint32_t len;
pj_uint16_t attr_type;
pjstun_attr_hdr **attr = &msg->attr[msg->attr_count];
pj_uint32_t len;
pj_uint16_t attr_type;
*attr = (pjstun_attr_hdr*)p_attr;
len = pj_ntohs((pj_uint16_t) ((*attr)->length)) + sizeof(pjstun_attr_hdr);
len = (len + 3) & ~3;
*attr = (pjstun_attr_hdr*)p_attr;
len = pj_ntohs((pj_uint16_t) ((*attr)->length)) + sizeof(pjstun_attr_hdr);
len = (len + 3) & ~3;
if (msg_len < len) {
PJ_LOG(4,(THIS_FILE, "Error: length mismatch in attr %d",
msg->attr_count));
return PJLIB_UTIL_ESTUNINATTRLEN;
}
if (msg_len < len) {
PJ_LOG(4,(THIS_FILE, "Error: length mismatch in attr %d",
msg->attr_count));
return PJLIB_UTIL_ESTUNINATTRLEN;
}
attr_type = pj_ntohs((*attr)->type);
if (attr_type > PJSTUN_ATTR_REFLECTED_FROM &&
attr_type != PJSTUN_ATTR_XOR_MAPPED_ADDR)
{
PJ_LOG(5,(THIS_FILE, "Warning: unknown attr type %x in attr %d. "
"Attribute was ignored.",
attr_type, msg->attr_count));
}
attr_type = pj_ntohs((*attr)->type);
if (attr_type > PJSTUN_ATTR_REFLECTED_FROM &&
attr_type != PJSTUN_ATTR_XOR_MAPPED_ADDR)
{
PJ_LOG(5,(THIS_FILE, "Warning: unknown attr type %x in attr %d. "
"Attribute was ignored.",
attr_type, msg->attr_count));
}
msg_len = (pj_uint16_t)(msg_len - len);
p_attr += len;
++msg->attr_count;
msg_len = (pj_uint16_t)(msg_len - len);
p_attr += len;
++msg->attr_count;
}
if (msg->attr_count == attr_max_cnt) {
PJ_LOG(4, (THIS_FILE, "Warning: max number attribute %d reached.",
attr_max_cnt));
PJ_LOG(4, (THIS_FILE, "Warning: max number attribute %d reached.",
attr_max_cnt));
}
return PJ_SUCCESS;
@ -127,9 +126,9 @@ PJ_DEF(void*) pjstun_msg_find_attr( pjstun_msg *msg, pjstun_attr_type t)
PJ_CHECK_STACK();
for (i=0; i<msg->attr_count; ++i) {
pjstun_attr_hdr *attr = msg->attr[i];
if (pj_ntohs(attr->type) == t)
return attr;
pjstun_attr_hdr *attr = msg->attr[i];
if (pj_ntohs(attr->type) == t)
return attr;
}
return 0;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -32,15 +31,15 @@ enum { MAX_REQUEST = 4 };
static int stun_timer[] = {500, 500, 500, 500 };
#define STUN_MAGIC 0x2112A442
#define THIS_FILE "stun_client.c"
#define THIS_FILE "stun_client.c"
#define TRACE_(x) PJ_LOG(6,x)
#define TRACE_(x) PJ_LOG(6,x)
PJ_DEF(pj_status_t) pjstun_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[])
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[])
{
pjstun_setting opt;
@ -55,10 +54,10 @@ PJ_DEF(pj_status_t) pjstun_get_mapped_addr( pj_pool_factory *pf,
}
PJ_DEF(pj_status_t) pjstun_get_mapped_addr2(pj_pool_factory *pf,
const pjstun_setting *opt,
int sock_cnt,
pj_sock_t sock[],
pj_sockaddr_in mapped_addr[])
const pjstun_setting *opt,
int sock_cnt,
pj_sock_t sock[],
pj_sockaddr_in mapped_addr[])
{
unsigned srv_cnt;
const pj_str_t *srv1, *srv2;
@ -67,13 +66,13 @@ PJ_DEF(pj_status_t) pjstun_get_mapped_addr2(pj_pool_factory *pf,
int i, send_cnt = 0, nfds;
pj_pool_t *pool;
struct query_rec {
struct {
pj_uint32_t mapped_addr;
pj_uint32_t mapped_port;
} srv[2];
struct {
pj_uint32_t mapped_addr;
pj_uint32_t mapped_port;
} srv[2];
} *rec;
void *out_msg;
pj_size_t out_msg_len;
pj_size_t out_msg_len;
int wait_resp = 0;
pj_status_t status;
@ -89,28 +88,28 @@ PJ_DEF(pj_status_t) pjstun_get_mapped_addr2(pj_pool_factory *pf,
/* Create pool. */
pool = pj_pool_create(pf, "stun%p", 400, 400, NULL);
if (!pool)
return PJ_ENOMEM;
return PJ_ENOMEM;
/* Allocate client records */
rec = (struct query_rec*) pj_pool_calloc(pool, sock_cnt, sizeof(*rec));
if (!rec) {
status = PJ_ENOMEM;
goto on_error;
status = PJ_ENOMEM;
goto on_error;
}
TRACE_((THIS_FILE, " Memory allocated."));
/* Create the outgoing BIND REQUEST message template */
status = pjstun_create_bind_req( pool, &out_msg, &out_msg_len,
pj_rand(), pj_rand());
pj_rand(), pj_rand());
if (status != PJ_SUCCESS)
goto on_error;
goto on_error;
/* Insert magic cookie (specified in RFC 5389) when requested to. */
if (opt->use_stun2) {
pjstun_msg_hdr *hdr = (pjstun_msg_hdr*)out_msg;
hdr->tsx[0] = pj_htonl(STUN_MAGIC);
pjstun_msg_hdr *hdr = (pjstun_msg_hdr*)out_msg;
hdr->tsx[0] = pj_htonl(STUN_MAGIC);
}
TRACE_((THIS_FILE, " Binding request created."));
@ -118,19 +117,19 @@ PJ_DEF(pj_status_t) pjstun_get_mapped_addr2(pj_pool_factory *pf,
/* Resolve servers. */
status = pj_sockaddr_init(opt->af, &srv_addr[0], srv1, (pj_uint16_t)port1);
if (status != PJ_SUCCESS)
goto on_error;
goto on_error;
srv_cnt = 1;
if (srv2 && port2) {
status = pj_sockaddr_init(opt->af, &srv_addr[1], srv2,
(pj_uint16_t)port2);
if (status != PJ_SUCCESS)
goto on_error;
status = pj_sockaddr_init(opt->af, &srv_addr[1], srv2,
(pj_uint16_t)port2);
if (status != PJ_SUCCESS)
goto on_error;
if (pj_sockaddr_cmp(&srv_addr[1], &srv_addr[0]) != 0) {
srv_cnt++;
}
if (pj_sockaddr_cmp(&srv_addr[1], &srv_addr[0]) != 0) {
srv_cnt++;
}
}
TRACE_((THIS_FILE, " Server initialized, using %d server(s)", srv_cnt));
@ -146,9 +145,9 @@ PJ_DEF(pj_status_t) pjstun_get_mapped_addr2(pj_pool_factory *pf,
#if defined(PJ_SELECT_NEEDS_NFDS) && PJ_SELECT_NEEDS_NFDS!=0
nfds = -1;
for (i=0; i<sock_cnt; ++i) {
if (sock[i] > nfds) {
nfds = sock[i];
}
if (sock[i] > nfds) {
nfds = sock[i];
}
}
#else
nfds = FD_SETSIZE-1;
@ -156,198 +155,198 @@ PJ_DEF(pj_status_t) pjstun_get_mapped_addr2(pj_pool_factory *pf,
/* Main retransmission loop. */
for (send_cnt=0; send_cnt<MAX_REQUEST; ++send_cnt) {
pj_time_val next_tx, now;
pj_fd_set_t r;
int select_rc;
pj_time_val next_tx, now;
pj_fd_set_t r;
int select_rc;
PJ_FD_ZERO(&r);
PJ_FD_ZERO(&r);
/* Send messages to servers that has not given us response. */
for (i=0; i<sock_cnt && status==PJ_SUCCESS; ++i) {
unsigned j;
for (j=0; j<srv_cnt && status==PJ_SUCCESS; ++j) {
pjstun_msg_hdr *msg_hdr = (pjstun_msg_hdr*) out_msg;
/* Send messages to servers that has not given us response. */
for (i=0; i<sock_cnt && status==PJ_SUCCESS; ++i) {
unsigned j;
for (j=0; j<srv_cnt && status==PJ_SUCCESS; ++j) {
pjstun_msg_hdr *msg_hdr = (pjstun_msg_hdr*) out_msg;
pj_ssize_t sent_len;
if (rec[i].srv[j].mapped_port != 0)
continue;
if (rec[i].srv[j].mapped_port != 0)
continue;
/* Modify message so that we can distinguish response. */
msg_hdr->tsx[2] = pj_htonl(i);
msg_hdr->tsx[3] = pj_htonl(j);
/* Modify message so that we can distinguish response. */
msg_hdr->tsx[2] = pj_htonl(i);
msg_hdr->tsx[3] = pj_htonl(j);
/* Send! */
/* Send! */
sent_len = out_msg_len;
status = pj_sock_sendto(sock[i], out_msg, &sent_len, 0,
(pj_sockaddr_t*)&srv_addr[j],
pj_sockaddr_get_len(&srv_addr[j]));
}
}
status = pj_sock_sendto(sock[i], out_msg, &sent_len, 0,
(pj_sockaddr_t*)&srv_addr[j],
pj_sockaddr_get_len(&srv_addr[j]));
}
}
/* All requests sent.
* The loop below will wait for responses until all responses have
* been received (i.e. wait_resp==0) or timeout occurs, which then
* we'll go to the next retransmission iteration.
*/
TRACE_((THIS_FILE, " Request(s) sent, counter=%d", send_cnt));
/* All requests sent.
* The loop below will wait for responses until all responses have
* been received (i.e. wait_resp==0) or timeout occurs, which then
* we'll go to the next retransmission iteration.
*/
TRACE_((THIS_FILE, " Request(s) sent, counter=%d", send_cnt));
/* Calculate time of next retransmission. */
pj_gettickcount(&next_tx);
next_tx.sec += (stun_timer[send_cnt]/1000);
next_tx.msec += (stun_timer[send_cnt]%1000);
pj_time_val_normalize(&next_tx);
/* Calculate time of next retransmission. */
pj_gettickcount(&next_tx);
next_tx.sec += (stun_timer[send_cnt]/1000);
next_tx.msec += (stun_timer[send_cnt]%1000);
pj_time_val_normalize(&next_tx);
for (pj_gettickcount(&now), select_rc=1;
status==PJ_SUCCESS && select_rc>=1 && wait_resp>0
&& PJ_TIME_VAL_LT(now, next_tx);
pj_gettickcount(&now))
{
pj_time_val timeout;
for (pj_gettickcount(&now), select_rc=1;
status==PJ_SUCCESS && select_rc>=1 && wait_resp>0
&& PJ_TIME_VAL_LT(now, next_tx);
pj_gettickcount(&now))
{
pj_time_val timeout;
timeout = next_tx;
PJ_TIME_VAL_SUB(timeout, now);
timeout = next_tx;
PJ_TIME_VAL_SUB(timeout, now);
for (i=0; i<sock_cnt; ++i) {
PJ_FD_SET(sock[i], &r);
}
for (i=0; i<sock_cnt; ++i) {
PJ_FD_SET(sock[i], &r);
}
select_rc = pj_sock_select(nfds+1, &r, NULL, NULL, &timeout);
TRACE_((THIS_FILE, " select() rc=%d", select_rc));
if (select_rc < 1)
continue;
select_rc = pj_sock_select(nfds+1, &r, NULL, NULL, &timeout);
TRACE_((THIS_FILE, " select() rc=%d", select_rc));
if (select_rc < 1)
continue;
for (i=0; i<sock_cnt; ++i) {
int sock_idx, srv_idx;
for (i=0; i<sock_cnt; ++i) {
int sock_idx, srv_idx;
pj_ssize_t len;
pjstun_msg msg;
pj_sockaddr addr;
int addrlen = sizeof(addr);
pjstun_mapped_addr_attr *attr;
char recv_buf[128];
pjstun_msg msg;
pj_sockaddr addr;
int addrlen = sizeof(addr);
pjstun_mapped_addr_attr *attr;
char recv_buf[128];
if (!PJ_FD_ISSET(sock[i], &r))
continue;
if (!PJ_FD_ISSET(sock[i], &r))
continue;
len = sizeof(recv_buf);
status = pj_sock_recvfrom( sock[i], recv_buf,
&len, 0,
(pj_sockaddr_t*)&addr,
&addrlen);
status = pj_sock_recvfrom( sock[i], recv_buf,
&len, 0,
(pj_sockaddr_t*)&addr,
&addrlen);
if (status != PJ_SUCCESS) {
PJ_PERROR(4,(THIS_FILE, status,
"recvfrom() error ignored"));
if (status != PJ_SUCCESS) {
PJ_PERROR(4,(THIS_FILE, status,
"recvfrom() error ignored"));
/* Ignore non-PJ_SUCCESS status.
* It possible that other SIP entity is currently
* sending SIP request to us, and because SIP message
* is larger than STUN, we could get EMSGSIZE when
* we call recvfrom().
*/
status = PJ_SUCCESS;
continue;
}
/* Ignore non-PJ_SUCCESS status.
* It possible that other SIP entity is currently
* sending SIP request to us, and because SIP message
* is larger than STUN, we could get EMSGSIZE when
* we call recvfrom().
*/
status = PJ_SUCCESS;
continue;
}
status = pjstun_parse_msg(recv_buf, len, &msg);
if (status != PJ_SUCCESS) {
PJ_PERROR(4,(THIS_FILE, status,
"STUN parsing error ignored"));
status = pjstun_parse_msg(recv_buf, len, &msg);
if (status != PJ_SUCCESS) {
PJ_PERROR(4,(THIS_FILE, status,
"STUN parsing error ignored"));
/* Also ignore non-successful parsing. This may not
* be STUN response at all. See the comment above.
*/
status = PJ_SUCCESS;
continue;
}
/* Also ignore non-successful parsing. This may not
* be STUN response at all. See the comment above.
*/
status = PJ_SUCCESS;
continue;
}
sock_idx = pj_ntohl(msg.hdr->tsx[2]);
srv_idx = pj_ntohl(msg.hdr->tsx[3]);
sock_idx = pj_ntohl(msg.hdr->tsx[2]);
srv_idx = pj_ntohl(msg.hdr->tsx[3]);
if (sock_idx<0 || sock_idx>=sock_cnt || sock_idx!=i ||
srv_idx<0 || srv_idx>=2)
{
status = PJLIB_UTIL_ESTUNININDEX;
continue;
}
if (sock_idx<0 || sock_idx>=sock_cnt || sock_idx!=i ||
srv_idx<0 || srv_idx>=2)
{
status = PJLIB_UTIL_ESTUNININDEX;
continue;
}
if (pj_ntohs(msg.hdr->type) != PJSTUN_BINDING_RESPONSE) {
status = PJLIB_UTIL_ESTUNNOBINDRES;
continue;
}
if (pj_ntohs(msg.hdr->type) != PJSTUN_BINDING_RESPONSE) {
status = PJLIB_UTIL_ESTUNNOBINDRES;
continue;
}
if (rec[sock_idx].srv[srv_idx].mapped_port != 0) {
/* Already got response */
continue;
}
if (rec[sock_idx].srv[srv_idx].mapped_port != 0) {
/* Already got response */
continue;
}
/* From this part, we consider the packet as a valid STUN
* response for our request.
*/
--wait_resp;
/* From this part, we consider the packet as a valid STUN
* response for our request.
*/
--wait_resp;
if (pjstun_msg_find_attr(&msg, PJSTUN_ATTR_ERROR_CODE) != NULL) {
status = PJLIB_UTIL_ESTUNRECVERRATTR;
continue;
}
if (pjstun_msg_find_attr(&msg, PJSTUN_ATTR_ERROR_CODE) != NULL) {
status = PJLIB_UTIL_ESTUNRECVERRATTR;
continue;
}
attr = (pjstun_mapped_addr_attr*)
pjstun_msg_find_attr(&msg, PJSTUN_ATTR_MAPPED_ADDR);
if (!attr) {
attr = (pjstun_mapped_addr_attr*)
pjstun_msg_find_attr(&msg, PJSTUN_ATTR_XOR_MAPPED_ADDR);
if (!attr || attr->family != 1) {
status = PJLIB_UTIL_ESTUNNOMAP;
continue;
}
}
attr = (pjstun_mapped_addr_attr*)
pjstun_msg_find_attr(&msg, PJSTUN_ATTR_MAPPED_ADDR);
if (!attr) {
attr = (pjstun_mapped_addr_attr*)
pjstun_msg_find_attr(&msg, PJSTUN_ATTR_XOR_MAPPED_ADDR);
if (!attr || attr->family != 1) {
status = PJLIB_UTIL_ESTUNNOMAP;
continue;
}
}
rec[sock_idx].srv[srv_idx].mapped_addr = attr->addr;
rec[sock_idx].srv[srv_idx].mapped_port = attr->port;
if (pj_ntohs(attr->hdr.type) == PJSTUN_ATTR_XOR_MAPPED_ADDR) {
rec[sock_idx].srv[srv_idx].mapped_addr ^= pj_htonl(STUN_MAGIC);
rec[sock_idx].srv[srv_idx].mapped_port ^= pj_htons(STUN_MAGIC >> 16);
}
}
}
rec[sock_idx].srv[srv_idx].mapped_addr = attr->addr;
rec[sock_idx].srv[srv_idx].mapped_port = attr->port;
if (pj_ntohs(attr->hdr.type) == PJSTUN_ATTR_XOR_MAPPED_ADDR) {
rec[sock_idx].srv[srv_idx].mapped_addr ^= pj_htonl(STUN_MAGIC);
rec[sock_idx].srv[srv_idx].mapped_port ^= pj_htons(STUN_MAGIC >> 16);
}
}
}
/* The best scenario is if all requests have been replied.
* Then we don't need to go to the next retransmission iteration.
*/
if (wait_resp <= 0)
break;
/* The best scenario is if all requests have been replied.
* Then we don't need to go to the next retransmission iteration.
*/
if (wait_resp <= 0)
break;
}
TRACE_((THIS_FILE, " All responses received, calculating result.."));
for (i=0; i<sock_cnt && status==PJ_SUCCESS; ++i) {
if (srv_cnt == 1) {
mapped_addr[i].sin_family = pj_AF_INET();
mapped_addr[i].sin_addr.s_addr = rec[i].srv[0].mapped_addr;
mapped_addr[i].sin_port = (pj_uint16_t)rec[i].srv[0].mapped_port;
if (srv_cnt == 1) {
mapped_addr[i].sin_family = pj_AF_INET();
mapped_addr[i].sin_addr.s_addr = rec[i].srv[0].mapped_addr;
mapped_addr[i].sin_port = (pj_uint16_t)rec[i].srv[0].mapped_port;
if (rec[i].srv[0].mapped_addr == 0 || rec[i].srv[0].mapped_port == 0) {
status = PJLIB_UTIL_ESTUNNOTRESPOND;
break;
}
} else if (rec[i].srv[0].mapped_addr == rec[i].srv[1].mapped_addr &&
rec[i].srv[0].mapped_port == rec[i].srv[1].mapped_port)
{
mapped_addr[i].sin_family = pj_AF_INET();
mapped_addr[i].sin_addr.s_addr = rec[i].srv[0].mapped_addr;
mapped_addr[i].sin_port = (pj_uint16_t)rec[i].srv[0].mapped_port;
if (rec[i].srv[0].mapped_addr == 0 || rec[i].srv[0].mapped_port == 0) {
status = PJLIB_UTIL_ESTUNNOTRESPOND;
break;
}
} else if (rec[i].srv[0].mapped_addr == rec[i].srv[1].mapped_addr &&
rec[i].srv[0].mapped_port == rec[i].srv[1].mapped_port)
{
mapped_addr[i].sin_family = pj_AF_INET();
mapped_addr[i].sin_addr.s_addr = rec[i].srv[0].mapped_addr;
mapped_addr[i].sin_port = (pj_uint16_t)rec[i].srv[0].mapped_port;
if (rec[i].srv[0].mapped_addr == 0 || rec[i].srv[0].mapped_port == 0) {
status = PJLIB_UTIL_ESTUNNOTRESPOND;
break;
}
} else {
status = PJLIB_UTIL_ESTUNSYMMETRIC;
break;
}
if (rec[i].srv[0].mapped_addr == 0 || rec[i].srv[0].mapped_port == 0) {
status = PJLIB_UTIL_ESTUNNOTRESPOND;
break;
}
} else {
status = PJLIB_UTIL_ESTUNSYMMETRIC;
break;
}
}
TRACE_((THIS_FILE, " Pool usage=%d of %d", pj_pool_get_used_size(pool),
pj_pool_get_capacity(pool)));
pj_pool_get_capacity(pool)));
pj_pool_release(pool);

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -25,8 +24,8 @@
#include <pj/log.h>
#include <pj/os.h>
#define EX_SYNTAX_ERROR 12
#define THIS_FILE "xml.c"
#define EX_SYNTAX_ERROR 12
#define THIS_FILE "xml.c"
static void on_syntax_error(struct pj_scanner *scanner)
{
@ -59,38 +58,38 @@ static pj_xml_node *xml_parse_node( pj_pool_t *pool, pj_scanner *scanner)
PJ_CHECK_STACK();
if (*scanner->curptr != '<')
on_syntax_error(scanner);
on_syntax_error(scanner);
/* Handle Processing Instructino (PI) construct (i.e. "<?") */
if (*scanner->curptr == '<' && *(scanner->curptr+1) == '?') {
pj_scan_advance_n(scanner, 2, PJ_FALSE);
for (;;) {
pj_str_t dummy;
pj_scan_get_until_ch(scanner, '?', &dummy);
if (*scanner->curptr=='?' && *(scanner->curptr+1)=='>') {
pj_scan_advance_n(scanner, 2, PJ_TRUE);
break;
} else {
pj_scan_advance_n(scanner, 1, PJ_FALSE);
}
}
return xml_parse_node(pool, scanner);
pj_scan_advance_n(scanner, 2, PJ_FALSE);
for (;;) {
pj_str_t dummy;
pj_scan_get_until_ch(scanner, '?', &dummy);
if (*scanner->curptr=='?' && *(scanner->curptr+1)=='>') {
pj_scan_advance_n(scanner, 2, PJ_TRUE);
break;
} else {
pj_scan_advance_n(scanner, 1, PJ_FALSE);
}
}
return xml_parse_node(pool, scanner);
}
/* Handle comments construct (i.e. "<!") */
if (pj_scan_strcmp(scanner, "<!", 2) == 0) {
pj_scan_advance_n(scanner, 2, PJ_FALSE);
for (;;) {
pj_str_t dummy;
pj_scan_get_until_ch(scanner, '>', &dummy);
if (pj_scan_strcmp(scanner, ">", 1) == 0) {
pj_scan_advance_n(scanner, 1, PJ_TRUE);
break;
} else {
pj_scan_advance_n(scanner, 1, PJ_FALSE);
}
}
return xml_parse_node(pool, scanner);
pj_scan_advance_n(scanner, 2, PJ_FALSE);
for (;;) {
pj_str_t dummy;
pj_scan_get_until_ch(scanner, '>', &dummy);
if (pj_scan_strcmp(scanner, ">", 1) == 0) {
pj_scan_advance_n(scanner, 1, PJ_TRUE);
break;
} else {
pj_scan_advance_n(scanner, 1, PJ_FALSE);
}
}
return xml_parse_node(pool, scanner);
}
/* Alloc node. */
@ -104,73 +103,73 @@ static pj_xml_node *xml_parse_node( pj_pool_t *pool, pj_scanner *scanner)
/* Get attributes. */
while (*scanner->curptr != '>' && *scanner->curptr != '/') {
pj_xml_attr *attr = alloc_attr(pool);
pj_scan_get_until_chr( scanner, "=> \t\r\n", &attr->name);
if (*scanner->curptr == '=') {
pj_scan_get_char( scanner );
pj_xml_attr *attr = alloc_attr(pool);
pj_scan_get_until_chr( scanner, "=> \t\r\n", &attr->name);
if (*scanner->curptr == '=') {
pj_scan_get_char( scanner );
pj_scan_get_quotes(scanner, "\"'", "\"'", 2, &attr->value);
/* remove quote characters */
++attr->value.ptr;
attr->value.slen -= 2;
}
pj_list_push_back( &node->attr_head, attr );
/* remove quote characters */
++attr->value.ptr;
attr->value.slen -= 2;
}
pj_list_push_back( &node->attr_head, attr );
}
if (*scanner->curptr == '/') {
pj_scan_get_char(scanner);
if (pj_scan_get_char(scanner) != '>')
on_syntax_error(scanner);
return node;
pj_scan_get_char(scanner);
if (pj_scan_get_char(scanner) != '>')
on_syntax_error(scanner);
return node;
}
/* Enclosing bracket. */
if (pj_scan_get_char(scanner) != '>')
on_syntax_error(scanner);
on_syntax_error(scanner);
/* Sub nodes. */
while (*scanner->curptr == '<' && *(scanner->curptr+1) != '/'
&& *(scanner->curptr+1) != '!')
&& *(scanner->curptr+1) != '!')
{
pj_xml_node *sub_node = xml_parse_node(pool, scanner);
pj_list_push_back( &node->node_head, sub_node );
pj_xml_node *sub_node = xml_parse_node(pool, scanner);
pj_list_push_back( &node->node_head, sub_node );
}
/* Content. */
if (!pj_scan_is_eof(scanner) && *scanner->curptr != '<') {
pj_scan_get_until_ch(scanner, '<', &node->content);
pj_scan_get_until_ch(scanner, '<', &node->content);
}
/* CDATA content. */
if (*scanner->curptr == '<' && *(scanner->curptr+1) == '!' &&
pj_scan_strcmp(scanner, "<![CDATA[", 9) == 0)
pj_scan_strcmp(scanner, "<![CDATA[", 9) == 0)
{
pj_scan_advance_n(scanner, 9, PJ_FALSE);
pj_scan_get_until_ch(scanner, ']', &node->content);
while (pj_scan_strcmp(scanner, "]]>", 3)) {
pj_str_t dummy;
pj_scan_advance_n(scanner, 9, PJ_FALSE);
pj_scan_get_until_ch(scanner, ']', &node->content);
while (pj_scan_strcmp(scanner, "]]>", 3)) {
pj_str_t dummy;
pj_scan_advance_n(scanner, 1, PJ_FALSE);
pj_scan_get_until_ch(scanner, ']', &dummy);
}
node->content.slen = scanner->curptr - node->content.ptr;
pj_scan_advance_n(scanner, 3, PJ_TRUE);
pj_scan_advance_n(scanner, 1, PJ_FALSE);
pj_scan_get_until_ch(scanner, ']', &dummy);
}
node->content.slen = scanner->curptr - node->content.ptr;
pj_scan_advance_n(scanner, 3, PJ_TRUE);
}
/* Enclosing node. */
if (pj_scan_get_char(scanner) != '<' || pj_scan_get_char(scanner) != '/')
on_syntax_error(scanner);
on_syntax_error(scanner);
pj_scan_get_until_chr(scanner, " \t>", &end_name);
/* Compare name. */
if (pj_stricmp(&node->name, &end_name) != 0)
on_syntax_error(scanner);
on_syntax_error(scanner);
/* Enclosing '>' */
if (pj_scan_get_char(scanner) != '>')
on_syntax_error(scanner);
on_syntax_error(scanner);
return node;
}
@ -182,17 +181,17 @@ PJ_DEF(pj_xml_node*) pj_xml_parse( pj_pool_t *pool, char *msg, pj_size_t len)
PJ_USE_EXCEPTION;
if (!msg || !len || !pool)
return NULL;
return NULL;
pj_scan_init( &scanner, msg, len,
PJ_SCAN_AUTOSKIP_WS|PJ_SCAN_AUTOSKIP_NEWLINE,
&on_syntax_error);
PJ_SCAN_AUTOSKIP_WS|PJ_SCAN_AUTOSKIP_NEWLINE,
&on_syntax_error);
PJ_TRY {
node = xml_parse_node(pool, &scanner);
node = xml_parse_node(pool, &scanner);
}
PJ_CATCH_ANY {
PJ_LOG(4,(THIS_FILE, "Syntax error parsing XML in line %d column %d",
scanner.line, pj_scan_get_col(&scanner)));
PJ_LOG(4,(THIS_FILE, "Syntax error parsing XML in line %d column %d",
scanner.line, pj_scan_get_col(&scanner)));
}
PJ_END;
pj_scan_fini( &scanner );
@ -201,22 +200,22 @@ PJ_DEF(pj_xml_node*) pj_xml_parse( pj_pool_t *pool, char *msg, pj_size_t len)
/* This is a recursive function. */
static int xml_print_node( const pj_xml_node *node, int indent,
char *buf, pj_size_t len )
char *buf, pj_size_t len )
{
int i;
char *p = buf;
pj_xml_attr *attr;
pj_xml_node *sub_node;
#define SIZE_LEFT() ((int)(len - (p-buf)))
#define SIZE_LEFT() ((int)(len - (p-buf)))
PJ_CHECK_STACK();
/* Print name. */
if (SIZE_LEFT() < node->name.slen + indent + 5)
return -1;
return -1;
for (i=0; i<indent; ++i)
*p++ = ' ';
*p++ = ' ';
*p++ = '<';
pj_memcpy(p, node->name.ptr, node->name.slen);
p += node->name.slen;
@ -225,36 +224,36 @@ static int xml_print_node( const pj_xml_node *node, int indent,
attr = node->attr_head.next;
while (attr != &node->attr_head) {
if (SIZE_LEFT() < attr->name.slen + attr->value.slen + 4)
return -1;
if (SIZE_LEFT() < attr->name.slen + attr->value.slen + 4)
return -1;
*p++ = ' ';
*p++ = ' ';
/* Attribute name. */
pj_memcpy(p, attr->name.ptr, attr->name.slen);
p += attr->name.slen;
/* Attribute name. */
pj_memcpy(p, attr->name.ptr, attr->name.slen);
p += attr->name.slen;
/* Attribute value. */
if (attr->value.slen) {
*p++ = '=';
*p++ = '"';
pj_memcpy(p, attr->value.ptr, attr->value.slen);
p += attr->value.slen;
*p++ = '"';
}
/* Attribute value. */
if (attr->value.slen) {
*p++ = '=';
*p++ = '"';
pj_memcpy(p, attr->value.ptr, attr->value.slen);
p += attr->value.slen;
*p++ = '"';
}
attr = attr->next;
attr = attr->next;
}
/* Check for empty node. */
if (node->content.slen==0 &&
node->node_head.next==(pj_xml_node*)&node->node_head)
node->node_head.next==(pj_xml_node*)&node->node_head)
{
if (SIZE_LEFT() < 3) return -1;
*p++ = ' ';
*p++ = '/';
*p++ = '>';
return (int)(p-buf);
*p++ = ' ';
*p++ = '/';
*p++ = '>';
return (int)(p-buf);
}
/* Enclosing '>' */
@ -264,39 +263,39 @@ static int xml_print_node( const pj_xml_node *node, int indent,
/* Print sub nodes. */
sub_node = node->node_head.next;
while (sub_node != (pj_xml_node*)&node->node_head) {
int printed;
int printed;
if (SIZE_LEFT() < indent + 3)
return -1;
//*p++ = '\r';
*p++ = '\n';
if (SIZE_LEFT() < indent + 3)
return -1;
//*p++ = '\r';
*p++ = '\n';
printed = xml_print_node(sub_node, indent + 1, p, SIZE_LEFT());
if (printed < 0)
return -1;
printed = xml_print_node(sub_node, indent + 1, p, SIZE_LEFT());
if (printed < 0)
return -1;
p += printed;
sub_node = sub_node->next;
p += printed;
sub_node = sub_node->next;
}
/* Content. */
if (node->content.slen) {
if (SIZE_LEFT() < node->content.slen) return -1;
pj_memcpy(p, node->content.ptr, node->content.slen);
p += node->content.slen;
if (SIZE_LEFT() < node->content.slen) return -1;
pj_memcpy(p, node->content.ptr, node->content.slen);
p += node->content.slen;
}
/* Enclosing node. */
if (node->node_head.next != (pj_xml_node*)&node->node_head) {
if (SIZE_LEFT() < node->name.slen + 5 + indent)
return -1;
//*p++ = '\r';
*p++ = '\n';
for (i=0; i<indent; ++i)
*p++ = ' ';
if (SIZE_LEFT() < node->name.slen + 5 + indent)
return -1;
//*p++ = '\r';
*p++ = '\n';
for (i=0; i<indent; ++i)
*p++ = ' ';
} else {
if (SIZE_LEFT() < node->name.slen + 3)
return -1;
if (SIZE_LEFT() < node->name.slen + 3)
return -1;
}
*p++ = '<';
*p++ = '/';
@ -310,25 +309,25 @@ static int xml_print_node( const pj_xml_node *node, int indent,
}
PJ_DEF(int) pj_xml_print(const pj_xml_node *node, char *buf, pj_size_t len,
pj_bool_t include_prolog)
pj_bool_t include_prolog)
{
int prolog_len = 0;
int printed;
if (!node || !buf || !len)
return 0;
return 0;
if (include_prolog) {
pj_str_t prolog = {"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", 39};
if ((int)len < prolog.slen)
return -1;
pj_memcpy(buf, prolog.ptr, prolog.slen);
prolog_len = (int)prolog.slen;
pj_str_t prolog = {"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", 39};
if ((int)len < prolog.slen)
return -1;
pj_memcpy(buf, prolog.ptr, prolog.slen);
prolog_len = (int)prolog.slen;
}
printed = xml_print_node(node, 0, buf+prolog_len, len-prolog_len) + prolog_len;
if (printed > 0 && len-printed >= 1) {
buf[printed++] = '\n';
buf[printed++] = '\n';
}
return printed;
}
@ -341,7 +340,7 @@ PJ_DEF(pj_xml_node*) pj_xml_node_new(pj_pool_t *pool, const pj_str_t *name)
}
PJ_DEF(pj_xml_attr*) pj_xml_attr_new( pj_pool_t *pool, const pj_str_t *name,
const pj_str_t *value)
const pj_str_t *value)
{
pj_xml_attr *attr = alloc_attr(pool);
pj_strdup( pool, &attr->name, name);
@ -360,70 +359,70 @@ PJ_DEF(void) pj_xml_add_attr( pj_xml_node *node, pj_xml_attr *attr )
}
PJ_DEF(pj_xml_node*) pj_xml_find_node(const pj_xml_node *parent,
const pj_str_t *name)
const pj_str_t *name)
{
const pj_xml_node *node = parent->node_head.next;
PJ_CHECK_STACK();
while (node != (void*)&parent->node_head) {
if (pj_stricmp(&node->name, name) == 0)
return (pj_xml_node*)node;
node = node->next;
if (pj_stricmp(&node->name, name) == 0)
return (pj_xml_node*)node;
node = node->next;
}
return NULL;
}
PJ_DEF(pj_xml_node*) pj_xml_find_node_rec(const pj_xml_node *parent,
const pj_str_t *name)
const pj_str_t *name)
{
const pj_xml_node *node = parent->node_head.next;
PJ_CHECK_STACK();
while (node != (void*)&parent->node_head) {
pj_xml_node *found;
if (pj_stricmp(&node->name, name) == 0)
return (pj_xml_node*)node;
found = pj_xml_find_node_rec(node, name);
if (found)
return (pj_xml_node*)found;
node = node->next;
pj_xml_node *found;
if (pj_stricmp(&node->name, name) == 0)
return (pj_xml_node*)node;
found = pj_xml_find_node_rec(node, name);
if (found)
return (pj_xml_node*)found;
node = node->next;
}
return NULL;
}
PJ_DEF(pj_xml_node*) pj_xml_find_next_node( const pj_xml_node *parent,
const pj_xml_node *node,
const pj_str_t *name)
const pj_xml_node *node,
const pj_str_t *name)
{
PJ_CHECK_STACK();
node = node->next;
while (node != (void*)&parent->node_head) {
if (pj_stricmp(&node->name, name) == 0)
return (pj_xml_node*)node;
node = node->next;
if (pj_stricmp(&node->name, name) == 0)
return (pj_xml_node*)node;
node = node->next;
}
return NULL;
}
PJ_DEF(pj_xml_attr*) pj_xml_find_attr( const pj_xml_node *node,
const pj_str_t *name,
const pj_str_t *value)
const pj_str_t *name,
const pj_str_t *value)
{
const pj_xml_attr *attr = node->attr_head.next;
while (attr != (void*)&node->attr_head) {
if (pj_stricmp(&attr->name, name)==0) {
if (value) {
if (pj_stricmp(&attr->value, value)==0)
return (pj_xml_attr*)attr;
} else {
return (pj_xml_attr*)attr;
}
}
attr = attr->next;
if (pj_stricmp(&attr->name, name)==0) {
if (value) {
if (pj_stricmp(&attr->value, value)==0)
return (pj_xml_attr*)attr;
} else {
return (pj_xml_attr*)attr;
}
}
attr = attr->next;
}
return NULL;
}
@ -431,69 +430,69 @@ PJ_DEF(pj_xml_attr*) pj_xml_find_attr( const pj_xml_node *node,
PJ_DEF(pj_xml_node*) pj_xml_find( const pj_xml_node *parent,
const pj_str_t *name,
const void *data,
pj_bool_t (*match)(const pj_xml_node *,
const void*))
const pj_str_t *name,
const void *data,
pj_bool_t (*match)(const pj_xml_node *,
const void*))
{
const pj_xml_node *node = (const pj_xml_node *)parent->node_head.next;
if (!name && !match)
return NULL;
return NULL;
while (node != (const pj_xml_node*) &parent->node_head) {
if (name) {
if (pj_stricmp(&node->name, name)!=0) {
node = node->next;
continue;
}
}
if (match) {
if (match(node, data))
return (pj_xml_node*)node;
} else {
return (pj_xml_node*)node;
}
if (name) {
if (pj_stricmp(&node->name, name)!=0) {
node = node->next;
continue;
}
}
if (match) {
if (match(node, data))
return (pj_xml_node*)node;
} else {
return (pj_xml_node*)node;
}
node = node->next;
node = node->next;
}
return NULL;
}
PJ_DEF(pj_xml_node*) pj_xml_find_rec( const pj_xml_node *parent,
const pj_str_t *name,
const void *data,
pj_bool_t (*match)(const pj_xml_node*,
const void*))
const pj_str_t *name,
const void *data,
pj_bool_t (*match)(const pj_xml_node*,
const void*))
{
const pj_xml_node *node = (const pj_xml_node *)parent->node_head.next;
if (!name && !match)
return NULL;
return NULL;
while (node != (const pj_xml_node*) &parent->node_head) {
pj_xml_node *found;
pj_xml_node *found;
if (name) {
if (pj_stricmp(&node->name, name)==0) {
if (match) {
if (match(node, data))
return (pj_xml_node*)node;
} else {
return (pj_xml_node*)node;
}
}
if (name) {
if (pj_stricmp(&node->name, name)==0) {
if (match) {
if (match(node, data))
return (pj_xml_node*)node;
} else {
return (pj_xml_node*)node;
}
}
} else if (match) {
if (match(node, data))
return (pj_xml_node*)node;
}
} else if (match) {
if (match(node, data))
return (pj_xml_node*)node;
}
found = pj_xml_find_rec(node, name, data, match);
if (found)
return found;
found = pj_xml_find_rec(node, name, data, match);
if (found)
return found;
node = node->next;
node = node->next;
}
return NULL;
}
@ -513,26 +512,26 @@ PJ_DEF(pj_xml_node*) pj_xml_clone( pj_pool_t *pool, const pj_xml_node *rhs)
r_attr = rhs->attr_head.next;
while (r_attr != &rhs->attr_head) {
pj_xml_attr *attr;
pj_xml_attr *attr;
attr = alloc_attr(pool);
pj_strdup(pool, &attr->name, &r_attr->name);
pj_strdup(pool, &attr->value, &r_attr->value);
attr = alloc_attr(pool);
pj_strdup(pool, &attr->name, &r_attr->name);
pj_strdup(pool, &attr->value, &r_attr->value);
pj_list_push_back(&node->attr_head, attr);
pj_list_push_back(&node->attr_head, attr);
r_attr = r_attr->next;
r_attr = r_attr->next;
}
/* Clone all child nodes. */
child = rhs->node_head.next;
while (child != (pj_xml_node*) &rhs->node_head) {
pj_xml_node *new_child;
pj_xml_node *new_child;
new_child = pj_xml_clone(pool, child);
pj_list_push_back(&node->node_head, new_child);
new_child = pj_xml_clone(pool, child);
pj_list_push_back(&node->node_head, new_child);
child = child->next;
child = child->next;
}
return node;

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2009-2011 Teluu Inc. (http://www.teluu.com)
*

View File

@ -8,17 +8,17 @@ AC_OS_OBJS=@ac_os_objs@
# (the library) for this specific operating system. Object files common
# to all operating systems should go in Makefile instead.
#
export PJLIB_OBJS += $(AC_OS_OBJS) \
addr_resolv_sock.o \
log_writer_stdout.o \
os_timestamp_common.o \
pool_policy_malloc.o sock_bsd.o sock_select.o
export PJLIB_OBJS += $(AC_OS_OBJS) \
addr_resolv_sock.o \
log_writer_stdout.o \
os_timestamp_common.o \
pool_policy_malloc.o sock_bsd.o sock_select.o
#
# TEST_OBJS are operating system specific object files to be included in
# the test application.
#
export TEST_OBJS += @ac_main_obj@
export TEST_OBJS += @ac_main_obj@
#
# Additional LDFLAGS for pjlib-test
@ -30,5 +30,5 @@ export TEST_OBJS += @ac_main_obj@
# TARGETS are make targets in the Makefile, to be executed for this given
# operating system.
#
export TARGETS = $(PJLIB_LIB) $(PJLIB_SONAME)
export TARGETS = $(PJLIB_LIB) $(PJLIB_SONAME)
export TARGETS_EXE = $(TEST_EXE)

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -36,36 +35,36 @@ public:
class iterator
{
public:
iterator()
iterator()
{
}
explicit iterator(pj_hash_table_t *h, pj_hash_iterator_t *i)
explicit iterator(pj_hash_table_t *h, pj_hash_iterator_t *i)
: ht_(h), it_(i)
{
}
iterator(const iterator &rhs)
iterator(const iterator &rhs)
: ht_(rhs.ht_), it_(rhs.it_)
{
}
void operator++()
void operator++()
{
it_ = pj_hash_next(ht_, it_);
}
bool operator==(const iterator &rhs)
bool operator==(const iterator &rhs)
{
return ht_ == rhs.ht_ && it_ == rhs.it_;
}
iterator & operator=(const iterator &rhs)
iterator & operator=(const iterator &rhs)
{
ht_=rhs.ht_; it_=rhs.it_;
return *this;
}
private:
pj_hash_table_t *ht_;
pj_hash_iterator_t it_val_;
pj_hash_iterator_t *it_;
pj_hash_table_t *ht_;
pj_hash_iterator_t it_val_;
pj_hash_iterator_t *it_;
friend class Pj_Hash_Table;
friend class Pj_Hash_Table;
};
//
@ -73,7 +72,7 @@ public:
//
Pj_Hash_Table(Pj_Pool *pool, unsigned size)
{
table_ = pj_hash_create(pool->pool_(), size);
table_ = pj_hash_create(pool->pool_(), size);
}
//
@ -90,7 +89,7 @@ public:
const void *key,
unsigned keylen = PJ_HASH_KEY_STRING)
{
return pj_hash_calc(initial_hval, key, keylen);
return pj_hash_calc(initial_hval, key, keylen);
}
//
@ -98,7 +97,7 @@ public:
//
pj_hash_table_t *pj_hash_table_t_()
{
return table_;
return table_;
}
//
@ -106,7 +105,7 @@ public:
//
void *get(const void *key, unsigned keylen = PJ_HASH_KEY_STRING)
{
return pj_hash_get(table_, key, keylen);
return pj_hash_get(table_, key, keylen);
}
//
@ -118,7 +117,7 @@ public:
void *value,
unsigned keylen = PJ_HASH_KEY_STRING)
{
pj_hash_set(pool->pool_(), table_, key, keylen, value);
pj_hash_set(pool->pool_(), table_, key, keylen, value);
}
//
@ -126,7 +125,7 @@ public:
//
unsigned count()
{
return pj_hash_count(table_);
return pj_hash_count(table_);
}
//
@ -134,9 +133,9 @@ public:
//
iterator begin()
{
iterator it(table_, NULL);
it.it_ = pj_hash_first(table_, &it.it_val_);
return it;
iterator it(table_, NULL);
it.it_ = pj_hash_first(table_, &it.it_val_);
return it;
}
//
@ -144,7 +143,7 @@ public:
//
iterator end()
{
return iterator(table_, NULL);
return iterator(table_, NULL);
}
private:
@ -152,5 +151,5 @@ private:
};
#endif /* __PJPP_HASH_HPP__ */
#endif /* __PJPP_HASH_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -48,35 +47,35 @@ public:
class const_iterator
{
public:
const_iterator()
const_iterator()
: node_(NULL)
{}
const_iterator(const List_Node *nd)
const_iterator(const List_Node *nd)
: node_((List_Node*)nd)
{}
const List_Node * operator *()
const List_Node * operator *()
{
return node_;
}
const List_Node * operator -> ()
const List_Node * operator -> ()
{
return node_;
}
const_iterator operator++()
const_iterator operator++()
{
return const_iterator((const List_Node *)node_->next);
}
bool operator==(const const_iterator &rhs)
bool operator==(const const_iterator &rhs)
{
return node_ == rhs.node_;
}
bool operator!=(const const_iterator &rhs)
bool operator!=(const const_iterator &rhs)
{
return node_ != rhs.node_;
}
protected:
List_Node *node_;
List_Node *node_;
};
//
@ -85,28 +84,28 @@ public:
class iterator : public const_iterator
{
public:
iterator()
iterator()
{}
iterator(List_Node *nd)
iterator(List_Node *nd)
: const_iterator(nd)
{}
List_Node * operator *()
List_Node * operator *()
{
return node_;
}
List_Node * operator -> ()
List_Node * operator -> ()
{
return node_;
}
iterator operator++()
iterator operator++()
{
return iterator((List_Node*)node_->next);
}
bool operator==(const iterator &rhs)
bool operator==(const iterator &rhs)
{
return node_ == rhs.node_;
}
bool operator!=(const iterator &rhs)
bool operator!=(const iterator &rhs)
{
return node_ != rhs.node_;
}
@ -126,11 +125,11 @@ public:
//
operator pj_list&()
{
return (pj_list&)root_;
return (pj_list&)root_;
}
operator const pj_list&()
{
return (const pj_list&)root_;
return (const pj_list&)root_;
}
//
@ -138,11 +137,11 @@ public:
//
operator pj_list*()
{
return (pj_list*)&root_;
return (pj_list*)&root_;
}
operator const pj_list*()
{
return (const pj_list*)&root_;
return (const pj_list*)&root_;
}
//
@ -150,7 +149,7 @@ public:
//
bool empty() const
{
return pj_list_empty(&root_);
return pj_list_empty(&root_);
}
//
@ -158,7 +157,7 @@ public:
//
iterator begin()
{
return iterator(root_.next);
return iterator(root_.next);
}
//
@ -166,7 +165,7 @@ public:
//
const_iterator begin() const
{
return const_iterator(root_.next);
return const_iterator(root_.next);
}
//
@ -174,7 +173,7 @@ public:
//
const_iterator end() const
{
return const_iterator((List_Node*)&root_);
return const_iterator((List_Node*)&root_);
}
//
@ -182,7 +181,7 @@ public:
//
iterator end()
{
return iterator((List_Node*)&root_);
return iterator((List_Node*)&root_);
}
//
@ -190,7 +189,7 @@ public:
//
void insert_before (iterator &pos, List_Node *node)
{
pj_list_insert_before( *pos, node );
pj_list_insert_before( *pos, node );
}
//
@ -198,7 +197,7 @@ public:
//
void insert_after(iterator &pos, List_Node *node)
{
pj_list_insert_after(*pos, node);
pj_list_insert_after(*pos, node);
}
//
@ -206,7 +205,7 @@ public:
//
void merge_first(List_Node *list2)
{
pj_list_merge_first(&root_, list2);
pj_list_merge_first(&root_, list2);
}
//
@ -214,7 +213,7 @@ public:
//
void merge_last(Pj_List *list)
{
pj_list_merge_last(&root_, &list->root_);
pj_list_merge_last(&root_, &list->root_);
}
//
@ -222,7 +221,7 @@ public:
//
void insert_nodes_before(iterator &pos, Pj_List *list2)
{
pj_list_insert_nodes_before(*pos, &list2->root_);
pj_list_insert_nodes_before(*pos, &list2->root_);
}
//
@ -230,7 +229,7 @@ public:
//
void insert_nodes_after(iterator &pos, Pj_List *list2)
{
pj_list_insert_nodes_after(*pos, &list2->root_);
pj_list_insert_nodes_after(*pos, &list2->root_);
}
//
@ -238,7 +237,7 @@ public:
//
void erase(iterator &it)
{
pj_list_erase(*it);
pj_list_erase(*it);
}
//
@ -246,7 +245,7 @@ public:
//
List_Node *front()
{
return root_.next;
return root_.next;
}
//
@ -254,7 +253,7 @@ public:
//
const List_Node *front() const
{
return root_.next;
return root_.next;
}
//
@ -262,7 +261,7 @@ public:
//
void pop_front()
{
pj_list_erase(root_.next);
pj_list_erase(root_.next);
}
//
@ -270,7 +269,7 @@ public:
//
List_Node *back()
{
return root_.prev;
return root_.prev;
}
//
@ -278,7 +277,7 @@ public:
//
const List_Node *back() const
{
return root_.prev;
return root_.prev;
}
//
@ -286,7 +285,7 @@ public:
//
void pop_back()
{
pj_list_erase(root_.prev);
pj_list_erase(root_.prev);
}
//
@ -294,8 +293,8 @@ public:
//
iterator find(List_Node *node)
{
List_Node *n = pj_list_find_node(&root_, node);
return n ? iterator(n) : end();
List_Node *n = pj_list_find_node(&root_, node);
return n ? iterator(n) : end();
}
//
@ -303,8 +302,8 @@ public:
//
const_iterator find(List_Node *node) const
{
List_Node *n = pj_list_find_node(&root_, node);
return n ? const_iterator(n) : end();
List_Node *n = pj_list_find_node(&root_, node);
return n ? const_iterator(n) : end();
}
//
@ -312,7 +311,7 @@ public:
//
void push_back(List_Node *node)
{
pj_list_insert_after(root_.prev, node);
pj_list_insert_after(root_.prev, node);
}
//
@ -320,7 +319,7 @@ public:
//
void push_front(List_Node *node)
{
pj_list_insert_before(root_.next, node);
pj_list_insert_before(root_.next, node);
}
//
@ -328,25 +327,25 @@ public:
//
void clear()
{
root_.next = &root_;
root_.prev = &root_;
root_.next = &root_;
root_.prev = &root_;
}
private:
struct RootNode
{
PJ_DECL_LIST_MEMBER(List_Node);
PJ_DECL_LIST_MEMBER(List_Node);
} root_;
void compiletest()
{
// If you see error in this line,
// it's because List_Node is not derived from Pj_List_Node.
List_Node *n = (List_Node*)0;
n = (List_Node *)n->next; n = (List_Node *)n->prev;
// If you see error in this line,
// it's because List_Node is not derived from Pj_List_Node.
List_Node *n = (List_Node*)0;
n = (List_Node *)n->next; n = (List_Node *)n->prev;
}
};
#endif /* __PJPP_LIST_HPP__ */
#endif /* __PJPP_LIST_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -145,5 +144,5 @@ public:
#endif /* __PJPP_LOCK_HPP__ */
#endif /* __PJPP_LOCK_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -86,7 +85,7 @@ public:
//
static pj_status_t sleep(unsigned msec)
{
return pj_thread_sleep(msec);
return pj_thread_sleep(msec);
}
//
@ -119,7 +118,7 @@ class Pj_Thread : public Pj_Object
public:
enum Flags
{
FLAG_SUSPENDED = PJ_THREAD_SUSPENDED
FLAG_SUSPENDED = PJ_THREAD_SUSPENDED
};
//
@ -149,7 +148,7 @@ public:
pj_status_t create( Pj_Pool *pool,
unsigned flags = 0,
const char *thread_name = NULL,
pj_size_t stack_size = PJ_THREAD_DEFAULT_STACK_SIZE)
pj_size_t stack_size = PJ_THREAD_DEFAULT_STACK_SIZE)
{
destroy();
return Pj_Thread_API::create( pool, &thread_, &thread_proc, this,
@ -161,7 +160,7 @@ public:
//
pj_thread_t *pj_thread_t_()
{
return thread_;
return thread_;
}
//
@ -321,7 +320,7 @@ public:
pj_status_t create( Pj_Pool *pool, pj_atomic_value_t value)
{
destroy();
return pj_atomic_create(pool->pool_(), value, &var_);
return pj_atomic_create(pool->pool_(), value, &var_);
}
//
@ -340,7 +339,7 @@ public:
//
pj_atomic_t *pj_atomic_t_()
{
return var_;
return var_;
}
//
@ -348,7 +347,7 @@ public:
//
void set(pj_atomic_value_t val)
{
pj_atomic_set(var_, val);
pj_atomic_set(var_, val);
}
//
@ -356,7 +355,7 @@ public:
//
pj_atomic_value_t get()
{
return pj_atomic_get(var_);
return pj_atomic_get(var_);
}
//
@ -364,7 +363,7 @@ public:
//
void inc()
{
pj_atomic_inc(var_);
pj_atomic_inc(var_);
}
//
@ -380,7 +379,7 @@ public:
//
void dec()
{
pj_atomic_dec(var_);
pj_atomic_dec(var_);
}
//
@ -423,9 +422,9 @@ public:
//
enum Type
{
DEFAULT = PJ_MUTEX_DEFAULT,
SIMPLE = PJ_MUTEX_SIMPLE,
RECURSE = PJ_MUTEX_RECURSE,
DEFAULT = PJ_MUTEX_DEFAULT,
SIMPLE = PJ_MUTEX_SIMPLE,
RECURSE = PJ_MUTEX_RECURSE,
};
//
@ -452,7 +451,7 @@ public:
pj_status_t create( Pj_Pool *pool, Type type, const char *name = NULL)
{
destroy();
return pj_mutex_create( pool->pool_(), name, type,
return pj_mutex_create( pool->pool_(), name, type,
&mutex_ );
}
@ -477,7 +476,7 @@ public:
//
pj_mutex_t *pj_mutex_t_()
{
return mutex_;
return mutex_;
}
//
@ -486,7 +485,7 @@ public:
void destroy()
{
if (mutex_) {
pj_mutex_destroy(mutex_);
pj_mutex_destroy(mutex_);
mutex_ = NULL;
}
}
@ -496,7 +495,7 @@ public:
//
pj_status_t acquire()
{
return pj_mutex_lock(mutex_);
return pj_mutex_lock(mutex_);
}
//
@ -504,7 +503,7 @@ public:
//
pj_status_t release()
{
return pj_mutex_unlock(mutex_);
return pj_mutex_unlock(mutex_);
}
//
@ -512,7 +511,7 @@ public:
//
pj_status_t tryacquire()
{
return pj_mutex_trylock(mutex_);
return pj_mutex_trylock(mutex_);
}
private:
@ -533,7 +532,7 @@ public:
unsigned initial = 0, const char *name = NULL)
: sem_(NULL)
{
create(pool, max, initial, name);
create(pool, max, initial, name);
}
//
@ -551,7 +550,7 @@ public:
unsigned initial = 0, const char *name = NULL )
{
destroy();
return pj_sem_create( pool->pool_(), name, initial, max, &sem_);
return pj_sem_create( pool->pool_(), name, initial, max, &sem_);
}
//
@ -570,7 +569,7 @@ public:
//
pj_sem_t *pj_sem_t_()
{
return (pj_sem_t*)this;
return (pj_sem_t*)this;
}
//
@ -578,7 +577,7 @@ public:
//
pj_status_t wait()
{
return pj_sem_wait(this->pj_sem_t_());
return pj_sem_wait(this->pj_sem_t_());
}
//
@ -586,7 +585,7 @@ public:
//
pj_status_t acquire()
{
return wait();
return wait();
}
//
@ -594,7 +593,7 @@ public:
//
pj_status_t trywait()
{
return pj_sem_trywait(this->pj_sem_t_());
return pj_sem_trywait(this->pj_sem_t_());
}
//
@ -602,7 +601,7 @@ public:
//
pj_status_t tryacquire()
{
return trywait();
return trywait();
}
//
@ -610,7 +609,7 @@ public:
//
pj_status_t post()
{
return pj_sem_post(this->pj_sem_t_());
return pj_sem_post(this->pj_sem_t_());
}
//
@ -618,7 +617,7 @@ public:
//
pj_status_t release()
{
return post();
return post();
}
private:
@ -657,7 +656,7 @@ public:
bool initial = false, const char *name = NULL)
{
destroy();
return pj_event_create(pool->pool_(), name, manual_reset, initial,
return pj_event_create(pool->pool_(), name, manual_reset, initial,
&event_);
}
@ -666,7 +665,7 @@ public:
//
pj_event_t *pj_event_t_()
{
return event_;
return event_;
}
//
@ -675,7 +674,7 @@ public:
void destroy()
{
if (event_) {
pj_event_destroy(event_);
pj_event_destroy(event_);
event_ = NULL;
}
}
@ -685,7 +684,7 @@ public:
//
pj_status_t wait()
{
return pj_event_wait(event_);
return pj_event_wait(event_);
}
//
@ -693,7 +692,7 @@ public:
//
pj_status_t trywait()
{
return pj_event_trywait(event_);
return pj_event_trywait(event_);
}
//
@ -701,7 +700,7 @@ public:
//
pj_status_t set()
{
return pj_event_set(this->pj_event_t_());
return pj_event_set(this->pj_event_t_());
}
//
@ -709,7 +708,7 @@ public:
//
pj_status_t pulse()
{
return pj_event_pulse(this->pj_event_t_());
return pj_event_pulse(this->pj_event_t_());
}
//
@ -717,7 +716,7 @@ public:
//
pj_status_t reset()
{
return pj_event_reset(this->pj_event_t_());
return pj_event_reset(this->pj_event_t_());
}
private:
@ -732,54 +731,54 @@ class Pj_Timestamp
public:
pj_status_t get_timestamp()
{
return pj_get_timestamp(&ts_);
return pj_get_timestamp(&ts_);
}
Pj_Timestamp& operator += (const Pj_Timestamp &rhs)
{
pj_add_timestamp(&ts_, &rhs.ts_);
return *this;
pj_add_timestamp(&ts_, &rhs.ts_);
return *this;
}
Pj_Timestamp& operator -= (const Pj_Timestamp &rhs)
{
pj_sub_timestamp(&ts_, &rhs.ts_);
return *this;
pj_sub_timestamp(&ts_, &rhs.ts_);
return *this;
}
Pj_Time_Val to_time() const
{
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return Pj_Time_Val(pj_elapsed_time(&zero.ts_, &ts_));
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return Pj_Time_Val(pj_elapsed_time(&zero.ts_, &ts_));
}
pj_uint32_t to_msec() const
{
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return pj_elapsed_msec(&zero.ts_, &ts_);
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return pj_elapsed_msec(&zero.ts_, &ts_);
}
pj_uint32_t to_usec() const
{
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return pj_elapsed_usec(&zero.ts_, &ts_);
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return pj_elapsed_usec(&zero.ts_, &ts_);
}
pj_uint32_t to_nanosec() const
{
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return pj_elapsed_nanosec(&zero.ts_, &ts_);
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return pj_elapsed_nanosec(&zero.ts_, &ts_);
}
pj_uint32_t to_cycle() const
{
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return pj_elapsed_cycle(&zero.ts_, &ts_);
Pj_Timestamp zero;
pj_memset(&zero, 0, sizeof(zero));
return pj_elapsed_cycle(&zero.ts_, &ts_);
}
private:
@ -798,7 +797,7 @@ public:
//
static pj_status_t gettimeofday( Pj_Time_Val *tv )
{
return pj_gettimeofday(tv);
return pj_gettimeofday(tv);
}
//
@ -807,7 +806,7 @@ public:
static pj_status_t time_decode( const Pj_Time_Val *tv,
pj_parsed_time *pt )
{
return pj_time_decode(tv, pt);
return pj_time_decode(tv, pt);
}
//
@ -816,7 +815,7 @@ public:
static pj_status_t time_encode( const pj_parsed_time *pt,
Pj_Time_Val *tv)
{
return pj_time_encode(pt, tv);
return pj_time_encode(pt, tv);
}
//
@ -824,7 +823,7 @@ public:
//
static pj_status_t time_local_to_gmt( Pj_Time_Val *tv )
{
return pj_time_local_to_gmt( tv );
return pj_time_local_to_gmt( tv );
}
//
@ -832,7 +831,7 @@ public:
//
static pj_status_t time_gmt_to_local( Pj_Time_Val *tv)
{
return pj_time_gmt_to_local( tv );
return pj_time_gmt_to_local( tv );
}
};
@ -866,5 +865,5 @@ inline pj_status_t Pj_Time_Val::to_local()
return Pj_OS_API::time_gmt_to_local(this);
}
#endif /* __PJPP_OS_HPP__ */
#endif /* __PJPP_OS_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -112,7 +111,7 @@ public:
~Pj_Pool()
{
if (p_)
pj_pool_release(p_);
pj_pool_release(p_);
}
//
@ -120,7 +119,7 @@ public:
//
const char *getobjname() const
{
return pj_pool_getobjname(p_);
return pj_pool_getobjname(p_);
}
//
@ -128,7 +127,7 @@ public:
//
operator pj_pool_t*()
{
return p_;
return p_;
}
//
@ -136,7 +135,7 @@ public:
//
pj_pool_t *pool_()
{
return p_;
return p_;
}
//
@ -144,7 +143,7 @@ public:
//
const pj_pool_t *pool_() const
{
return p_;
return p_;
}
//
@ -152,7 +151,7 @@ public:
//
pj_pool_t *pj_pool_t_()
{
return p_;
return p_;
}
//
@ -160,7 +159,7 @@ public:
//
void reset()
{
pj_pool_reset(p_);
pj_pool_reset(p_);
}
//
@ -168,7 +167,7 @@ public:
//
pj_size_t get_capacity()
{
pj_pool_get_capacity(p_);
pj_pool_get_capacity(p_);
}
//
@ -176,7 +175,7 @@ public:
//
pj_size_t get_used_size()
{
pj_pool_get_used_size(p_);
pj_pool_get_used_size(p_);
}
//
@ -184,7 +183,7 @@ public:
//
void *alloc(pj_size_t size)
{
return pj_pool_alloc(p_, size);
return pj_pool_alloc(p_, size);
}
//
@ -192,7 +191,7 @@ public:
//
void *calloc(pj_size_t count, pj_size_t elem)
{
return pj_pool_calloc(p_, count, elem);
return pj_pool_calloc(p_, count, elem);
}
//
@ -218,9 +217,9 @@ public:
// Construct caching pool.
//
Pj_Caching_Pool( pj_size_t cache_capacity = 0,
const pj_pool_factory_policy *pol=&pj_pool_factory_default_policy)
const pj_pool_factory_policy *pol=&pj_pool_factory_default_policy)
{
pj_caching_pool_init(&cp_, pol, cache_capacity);
pj_caching_pool_init(&cp_, pol, cache_capacity);
}
//
@ -228,7 +227,7 @@ public:
//
~Pj_Caching_Pool()
{
pj_caching_pool_destroy(&cp_);
pj_caching_pool_destroy(&cp_);
}
//
@ -239,7 +238,7 @@ public:
const char *name = NULL,
pj_pool_callback *callback = NULL)
{
return (pj_pool_t*)(*cp_.factory.create_pool)(&cp_.factory, name,
return (pj_pool_t*)(*cp_.factory.create_pool)(&cp_.factory, name,
initial_size,
increment_size,
callback);
@ -275,5 +274,5 @@ inline Pj_Pool::Pj_Pool( Pj_Caching_Pool &caching_pool,
}
#endif /* __PJPP_POOL_HPP__ */
#endif /* __PJPP_POOL_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -46,7 +45,7 @@ public:
Pj_Async_Op()
: handler_(NULL)
{
pj_ioqueue_op_key_init(this, sizeof(*this));
pj_ioqueue_op_key_init(this, sizeof(*this));
}
//
@ -55,7 +54,7 @@ public:
explicit Pj_Async_Op(Pj_Event_Handler *handler)
: handler_(handler)
{
pj_ioqueue_op_key_init(this, sizeof(*this));
pj_ioqueue_op_key_init(this, sizeof(*this));
}
//
@ -319,7 +318,7 @@ public:
// Create proactor.
//
pj_status_t create( Pj_Pool *pool, pj_size_t max_fd,
pj_size_t timer_entry_count)
pj_size_t timer_entry_count)
{
pj_status_t status;
@ -413,7 +412,7 @@ public:
* with the timeout to wait from timer, and use the minimum value.
*/
if (max_timeout && timeout >= *max_timeout) {
timeout = *max_timeout;
timeout = *max_timeout;
}
/* Poll events in ioqueue. */
@ -421,7 +420,7 @@ public:
ioqueue_count = pj_ioqueue_poll(ioq_, &timeout);
if (ioqueue_count < 0)
return ioqueue_count;
return ioqueue_count;
return ioqueue_count + timer_count;
}
@ -449,7 +448,7 @@ private:
static bool schedule_timer( pj_timer_heap_t *timer,
Pj_Event_Handler *handler,
const Pj_Time_Val &delay,
const Pj_Time_Val &delay,
int id=-1)
{
handler->timer_.id = id;
@ -465,7 +464,7 @@ private:
pj_ssize_t bytes_read)
{
Pj_Event_Handler *handler =
(Pj_Event_Handler*) pj_ioqueue_get_user_data(key);
(Pj_Event_Handler*) pj_ioqueue_get_user_data(key);
handler->on_read_complete((Pj_Async_Op*)op_key, bytes_read);
}
@ -478,7 +477,7 @@ private:
pj_ssize_t bytes_sent)
{
Pj_Event_Handler *handler =
(Pj_Event_Handler*) pj_ioqueue_get_user_data(key);
(Pj_Event_Handler*) pj_ioqueue_get_user_data(key);
handler->on_write_complete((Pj_Async_Op*)op_key, bytes_sent);
}
@ -492,7 +491,7 @@ private:
pj_status_t status)
{
Pj_Event_Handler *handler =
(Pj_Event_Handler*) pj_ioqueue_get_user_data(key);
(Pj_Event_Handler*) pj_ioqueue_get_user_data(key);
handler->on_accept_complete((Pj_Async_Op*)op_key, new_sock, status);
}
@ -504,12 +503,12 @@ private:
pj_status_t status)
{
Pj_Event_Handler *handler =
(Pj_Event_Handler*) pj_ioqueue_get_user_data(key);
(Pj_Event_Handler*) pj_ioqueue_get_user_data(key);
handler->on_connect_complete(status);
}
};
#endif /* __PJPP_PROACTOR_HPP__ */
#endif /* __PJPP_PROACTOR_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -34,7 +33,7 @@ class Pj_Cis_Buffer
public:
Pj_Cis_Buffer()
{
pj_cis_buf_init(&buf_);
pj_cis_buf_init(&buf_);
}
private:
@ -49,57 +48,57 @@ class Pj_Cis
public:
Pj_Cis(Pj_Cis_Buffer *buf)
{
pj_cis_init(&buf->buf_, &cis_);
pj_cis_init(&buf->buf_, &cis_);
}
Pj_Cis(const Pj_Cis &rhs)
{
pj_cis_dup(&cis_, (pj_cis_t*)&rhs.cis_);
pj_cis_dup(&cis_, (pj_cis_t*)&rhs.cis_);
}
void add_range(int start, int end)
{
pj_cis_add_range(&cis_, start, end);
pj_cis_add_range(&cis_, start, end);
}
void add_alpha()
{
pj_cis_add_alpha(&cis_);
pj_cis_add_alpha(&cis_);
}
void add_num()
{
pj_cis_add_num(&cis_);
pj_cis_add_num(&cis_);
}
void add_str(const char *str)
{
pj_cis_add_str(&cis_, str);
pj_cis_add_str(&cis_, str);
}
void add_cis(const Pj_Cis &rhs)
{
pj_cis_add_cis(&cis_, &rhs.cis_);
pj_cis_add_cis(&cis_, &rhs.cis_);
}
void del_range(int start, int end)
{
pj_cis_del_range(&cis_, start, end);
pj_cis_del_range(&cis_, start, end);
}
void del_str(const char *str)
{
pj_cis_del_str(&cis_, str);
pj_cis_del_str(&cis_, str);
}
void invert()
{
pj_cis_invert(&cis_);
pj_cis_invert(&cis_);
}
bool match(int c) const
{
return pj_cis_match(&cis_, c) != 0;
return pj_cis_match(&cis_, c) != 0;
}
private:
@ -115,126 +114,126 @@ public:
enum
{
SYNTAX_ERROR = 101
SYNTAX_ERROR = 101
};
static void syntax_error_handler_throw_pj(pj_scanner *);
typedef pj_scan_state State;
void init(char *buf, int len, unsigned options=PJ_SCAN_AUTOSKIP_WS,
pj_syn_err_func_ptr callback = &syntax_error_handler_throw_pj)
pj_syn_err_func_ptr callback = &syntax_error_handler_throw_pj)
{
pj_scan_init(&scanner_, buf, len, options, callback);
pj_scan_init(&scanner_, buf, len, options, callback);
}
void fini()
{
pj_scan_fini(&scanner_);
pj_scan_fini(&scanner_);
}
int eof() const
{
return pj_scan_is_eof(&scanner_);
return pj_scan_is_eof(&scanner_);
}
int peek_char() const
{
return *scanner_.curptr;
return *scanner_.curptr;
}
int peek(const Pj_Cis *cis, Pj_String *out)
{
return pj_scan_peek(&scanner_, &cis->cis_, out);
return pj_scan_peek(&scanner_, &cis->cis_, out);
}
int peek_n(pj_size_t len, Pj_String *out)
{
return pj_scan_peek_n(&scanner_, len, out);
return pj_scan_peek_n(&scanner_, len, out);
}
int peek_until(const Pj_Cis *cis, Pj_String *out)
{
return pj_scan_peek_until(&scanner_, &cis->cis_, out);
return pj_scan_peek_until(&scanner_, &cis->cis_, out);
}
void get(const Pj_Cis *cis, Pj_String *out)
{
pj_scan_get(&scanner_, &cis->cis_, out);
pj_scan_get(&scanner_, &cis->cis_, out);
}
void get_n(unsigned N, Pj_String *out)
{
pj_scan_get_n(&scanner_, N, out);
pj_scan_get_n(&scanner_, N, out);
}
int get_char()
{
return pj_scan_get_char(&scanner_);
return pj_scan_get_char(&scanner_);
}
void get_quote(int begin_quote, int end_quote, Pj_String *out)
{
pj_scan_get_quote(&scanner_, begin_quote, end_quote, out);
pj_scan_get_quote(&scanner_, begin_quote, end_quote, out);
}
void get_newline()
{
pj_scan_get_newline(&scanner_);
pj_scan_get_newline(&scanner_);
}
void get_until(const Pj_Cis *cis, Pj_String *out)
{
pj_scan_get_until(&scanner_, &cis->cis_, out);
pj_scan_get_until(&scanner_, &cis->cis_, out);
}
void get_until_ch(int until_ch, Pj_String *out)
{
pj_scan_get_until_ch(&scanner_, until_ch, out);
pj_scan_get_until_ch(&scanner_, until_ch, out);
}
void get_until_chr(const char *spec, Pj_String *out)
{
pj_scan_get_until_chr(&scanner_, spec, out);
pj_scan_get_until_chr(&scanner_, spec, out);
}
void advance_n(unsigned N, bool skip_ws=true)
{
pj_scan_advance_n(&scanner_, N, skip_ws);
pj_scan_advance_n(&scanner_, N, skip_ws);
}
int strcmp(const char *s, int len)
{
return pj_scan_strcmp(&scanner_, s, len);
return pj_scan_strcmp(&scanner_, s, len);
}
int stricmp(const char *s, int len)
{
return pj_scan_stricmp(&scanner_, s, len);
return pj_scan_stricmp(&scanner_, s, len);
}
void skip_ws()
{
pj_scan_skip_whitespace(&scanner_);
pj_scan_skip_whitespace(&scanner_);
}
void save_state(State *state) const
{
pj_scan_save_state(&scanner_, state);
pj_scan_save_state(&scanner_, state);
}
void restore_state(State *state)
{
pj_scan_restore_state(&scanner_, state);
pj_scan_restore_state(&scanner_, state);
}
int get_pos_line() const
{
return scanner_.line;
return scanner_.line;
}
int get_pos_col() const
{
return pj_scan_get_col(&scanner_);
return pj_scan_get_col(&scanner_);
}
@ -242,5 +241,5 @@ private:
pj_scanner scanner_;
};
#endif /* __PJPP_SCANNER_HPP__ */
#endif /* __PJPP_SCANNER_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -43,7 +42,7 @@ public:
//
pj_uint16_t get_port_number() const
{
return pj_sockaddr_in_get_port(this);
return pj_sockaddr_in_get_port(this);
}
//
@ -51,8 +50,8 @@ public:
//
void set_port_number(pj_uint16_t port)
{
sin_family = PJ_AF_INET;
pj_sockaddr_in_set_port(this, port);
sin_family = PJ_AF_INET;
pj_sockaddr_in_set_port(this, port);
}
//
@ -60,7 +59,7 @@ public:
//
pj_uint32_t get_ip_address() const
{
return pj_sockaddr_in_get_addr(this).s_addr;
return pj_sockaddr_in_get_addr(this).s_addr;
}
//
@ -68,7 +67,7 @@ public:
//
const char *get_address() const
{
return pj_inet_ntoa(sin_addr);
return pj_inet_ntoa(sin_addr);
}
//
@ -76,8 +75,8 @@ public:
//
void set_ip_address(pj_uint32_t addr)
{
sin_family = PJ_AF_INET;
pj_sockaddr_in_set_addr(this, addr);
sin_family = PJ_AF_INET;
pj_sockaddr_in_set_addr(this, addr);
}
//
@ -85,7 +84,7 @@ public:
//
pj_status_t set_address(const pj_str_t *addr)
{
return pj_sockaddr_in_set_str_addr(this, addr);
return pj_sockaddr_in_set_str_addr(this, addr);
}
//
@ -94,7 +93,7 @@ public:
pj_status_t set_address(const char *addr)
{
pj_str_t s;
return pj_sockaddr_in_set_str_addr(this, pj_cstr(&s, addr));
return pj_sockaddr_in_set_str_addr(this, pj_cstr(&s, addr));
}
//
@ -102,7 +101,7 @@ public:
//
bool operator==(const Pj_Inet_Addr &rhs) const
{
return sin_family == rhs.sin_family &&
return sin_family == rhs.sin_family &&
sin_addr.s_addr == rhs.sin_addr.s_addr &&
sin_port == rhs.sin_port;
}
@ -166,7 +165,7 @@ public:
//
void set_handle(pj_sock_t sock)
{
sock_ = sock;
sock_ = sock;
}
//
@ -174,7 +173,7 @@ public:
//
pj_sock_t get_handle() const
{
return sock_;
return sock_;
}
//
@ -182,7 +181,7 @@ public:
//
pj_sock_t& get_handle()
{
return sock_;
return sock_;
}
//
@ -198,7 +197,7 @@ public:
//
pj_status_t create(int af, int type, int proto)
{
return pj_sock_socket(af, type, proto, &sock_);
return pj_sock_socket(af, type, proto, &sock_);
}
//
@ -206,7 +205,7 @@ public:
//
pj_status_t bind(const Pj_Inet_Addr &addr)
{
return pj_sock_bind(sock_, &addr, sizeof(Pj_Inet_Addr));
return pj_sock_bind(sock_, &addr, sizeof(Pj_Inet_Addr));
}
//
@ -214,7 +213,7 @@ public:
//
pj_status_t close()
{
pj_sock_close(sock_);
pj_sock_close(sock_);
}
//
@ -222,7 +221,7 @@ public:
//
pj_status_t getpeername(Pj_Inet_Addr *addr)
{
return pj_sock_getpeername(sock_, addr, &addr->addrlen_);
return pj_sock_getpeername(sock_, addr, &addr->addrlen_);
}
//
@ -230,7 +229,7 @@ public:
//
pj_status_t getsockname(Pj_Inet_Addr *addr)
{
return pj_sock_getsockname(sock_, addr, &addr->addrlen_);
return pj_sock_getsockname(sock_, addr, &addr->addrlen_);
}
//
@ -239,7 +238,7 @@ public:
pj_status_t getsockopt(pj_uint16_t level, pj_uint16_t optname,
void *optval, int *optlen)
{
return pj_sock_getsockopt(sock_, level, optname, optval, optlen);
return pj_sock_getsockopt(sock_, level, optname, optval, optlen);
}
//
@ -248,7 +247,7 @@ public:
pj_status_t setsockopt(pj_uint16_t level, pj_uint16_t optname,
const void *optval, int optlen)
{
return pj_sock_setsockopt(sock_, level, optname, optval, optlen);
return pj_sock_setsockopt(sock_, level, optname, optval, optlen);
}
//
@ -257,7 +256,7 @@ public:
pj_ssize_t recv(void *buf, pj_size_t len, int flag = 0)
{
pj_ssize_t bytes = len;
if (pj_sock_recv(sock_, buf, &bytes, flag) != PJ_SUCCESS)
if (pj_sock_recv(sock_, buf, &bytes, flag) != PJ_SUCCESS)
return -1;
return bytes;
}
@ -268,7 +267,7 @@ public:
pj_ssize_t send(const void *buf, pj_ssize_t len, int flag = 0)
{
pj_ssize_t bytes = len;
if (pj_sock_send(sock_, buf, &bytes, flag) != PJ_SUCCESS)
if (pj_sock_send(sock_, buf, &bytes, flag) != PJ_SUCCESS)
return -1;
return bytes;
}
@ -278,7 +277,7 @@ public:
//
pj_status_t connect(const Pj_Inet_Addr &addr)
{
return pj_sock_connect(sock_, &addr, sizeof(Pj_Inet_Addr));
return pj_sock_connect(sock_, &addr, sizeof(Pj_Inet_Addr));
}
//
@ -339,7 +338,7 @@ public:
//
pj_status_t listen(int backlog = 5)
{
return pj_sock_listen(sock_, backlog);
return pj_sock_listen(sock_, backlog);
}
//
@ -363,7 +362,7 @@ public:
//
pj_status_t shutdown(int how = PJ_SHUT_RDWR)
{
return pj_sock_shutdown(sock_, how);
return pj_sock_shutdown(sock_, how);
}
};
@ -415,7 +414,7 @@ public:
{
pj_ssize_t bytes = len;
int *addrlen = fromaddr ? &fromaddr->addrlen_ : NULL;
if (pj_sock_recvfrom( sock_, buf, &bytes, flag,
if (pj_sock_recvfrom( sock_, buf, &bytes, flag,
fromaddr, addrlen) != PJ_SUCCESS)
{
return -1;
@ -430,7 +429,7 @@ public:
const Pj_Inet_Addr &addr)
{
pj_ssize_t bytes = len;
if (pj_sock_sendto( sock_, buf, &bytes, flag,
if (pj_sock_sendto( sock_, buf, &bytes, flag,
&addr, sizeof(pj_sockaddr_in)) != PJ_SUCCESS)
{
return -1;
@ -440,5 +439,5 @@ public:
};
#endif /* __PJPP_SOCK_HPP__ */
#endif /* __PJPP_SOCK_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -35,8 +34,8 @@ public:
//
Pj_String()
{
pj_assert(sizeof(Pj_String) == sizeof(pj_str_t));
ptr=NULL;
pj_assert(sizeof(Pj_String) == sizeof(pj_str_t));
ptr=NULL;
slen=0;
}
@ -45,7 +44,7 @@ public:
//
Pj_String(char *str)
{
set(str);
set(str);
}
//
@ -53,7 +52,7 @@ public:
//
Pj_String(Pj_Pool &pool, const char *src)
{
set(pool, src);
set(pool, src);
}
//
@ -61,8 +60,8 @@ public:
//
explicit Pj_String(pj_str_t &s)
{
ptr = s.ptr;
slen = s.slen;
ptr = s.ptr;
slen = s.slen;
}
//
@ -70,8 +69,8 @@ public:
//
explicit Pj_String(const pj_str_t &s)
{
ptr = (char*)s.ptr;
slen = s.slen;
ptr = (char*)s.ptr;
slen = s.slen;
}
//
@ -79,7 +78,7 @@ public:
//
Pj_String(Pj_Pool &pool, const pj_str_t *s)
{
set(pool, s);
set(pool, s);
}
//
@ -87,7 +86,7 @@ public:
//
Pj_String(Pj_Pool &pool, const Pj_String &rhs)
{
set(pool, rhs);
set(pool, rhs);
}
//
@ -95,8 +94,8 @@ public:
//
explicit Pj_String(const Pj_String &rhs)
{
ptr = rhs.ptr;
slen = rhs.slen;
ptr = rhs.ptr;
slen = rhs.slen;
}
//
@ -104,7 +103,7 @@ public:
//
Pj_String(char *str, pj_size_t len)
{
set(str, len);
set(str, len);
}
//
@ -112,7 +111,7 @@ public:
//
Pj_String(char *begin, char *end)
{
pj_strset3(this, begin, end);
pj_strset3(this, begin, end);
}
//
@ -120,7 +119,7 @@ public:
//
operator pj_str_t*()
{
return this;
return this;
}
//
@ -128,7 +127,7 @@ public:
//
operator const pj_str_t*() const
{
return this;
return this;
}
//
@ -136,7 +135,7 @@ public:
//
pj_size_t length() const
{
return pj_strlen(this);
return pj_strlen(this);
}
//
@ -144,7 +143,7 @@ public:
//
pj_size_t size() const
{
return length();
return length();
}
//
@ -152,7 +151,7 @@ public:
//
const char *buf() const
{
return ptr;
return ptr;
}
//
@ -160,7 +159,7 @@ public:
//
void set(char *str)
{
pj_strset2(this, str);
pj_strset2(this, str);
}
//
@ -168,7 +167,7 @@ public:
//
void set(Pj_Pool &pool, const char *s)
{
pj_strdup2(pool, this, s);
pj_strdup2(pool, this, s);
}
//
@ -176,7 +175,7 @@ public:
//
void set(pj_str_t *s)
{
pj_strassign(this, s);
pj_strassign(this, s);
}
//
@ -184,7 +183,7 @@ public:
//
void set(Pj_Pool &pool, const pj_str_t *s)
{
pj_strdup(pool, this, s);
pj_strdup(pool, this, s);
}
//
@ -192,7 +191,7 @@ public:
//
void set(char *str, pj_size_t len)
{
pj_strset(this, str, len);
pj_strset(this, str, len);
}
//
@ -200,7 +199,7 @@ public:
//
void set(char *begin, char *end)
{
pj_strset3(this, begin, end);
pj_strset3(this, begin, end);
}
//
@ -208,7 +207,7 @@ public:
//
void set(Pj_String &rhs)
{
pj_strassign(this, &rhs);
pj_strassign(this, &rhs);
}
//
@ -216,7 +215,7 @@ public:
//
void set(Pj_Pool &pool, const Pj_String *s)
{
pj_strdup(pool, this, s);
pj_strdup(pool, this, s);
}
//
@ -224,7 +223,7 @@ public:
//
void set(Pj_Pool &pool, const Pj_String &s)
{
pj_strdup(pool, this, &s);
pj_strdup(pool, this, &s);
}
//
@ -232,7 +231,7 @@ public:
//
void strcpy(const pj_str_t *s)
{
pj_strcpy(this, s);
pj_strcpy(this, s);
}
//
@ -240,7 +239,7 @@ public:
//
void strcpy(const Pj_String &rhs)
{
pj_strcpy(this, &rhs);
pj_strcpy(this, &rhs);
}
//
@ -248,7 +247,7 @@ public:
//
void strcpy(const char *s)
{
pj_strcpy2(this, s);
pj_strcpy2(this, s);
}
//
@ -256,7 +255,7 @@ public:
//
int strcmp(const char *s) const
{
return pj_strcmp2(this, s);
return pj_strcmp2(this, s);
}
//
@ -264,7 +263,7 @@ public:
//
int strcmp(const pj_str_t *s) const
{
return pj_strcmp(this, s);
return pj_strcmp(this, s);
}
//
@ -272,7 +271,7 @@ public:
//
int strcmp(const Pj_String &rhs) const
{
return pj_strcmp(this, &rhs);
return pj_strcmp(this, &rhs);
}
//
@ -280,7 +279,7 @@ public:
//
int strncmp(const char *s, pj_size_t len) const
{
return pj_strncmp2(this, s, len);
return pj_strncmp2(this, s, len);
}
//
@ -288,7 +287,7 @@ public:
//
int strncmp(const pj_str_t *s, pj_size_t len) const
{
return pj_strncmp(this, s, len);
return pj_strncmp(this, s, len);
}
//
@ -296,7 +295,7 @@ public:
//
int strncmp(const Pj_String &rhs, pj_size_t len) const
{
return pj_strncmp(this, &rhs, len);
return pj_strncmp(this, &rhs, len);
}
//
@ -304,7 +303,7 @@ public:
//
int stricmp(const char *s) const
{
return pj_stricmp2(this, s);
return pj_stricmp2(this, s);
}
//
@ -312,7 +311,7 @@ public:
//
int stricmp(const pj_str_t *s) const
{
return pj_stricmp(this, s);
return pj_stricmp(this, s);
}
//
@ -320,7 +319,7 @@ public:
//
int stricmp(const Pj_String &rhs) const
{
return stricmp(&rhs);
return stricmp(&rhs);
}
//
@ -328,7 +327,7 @@ public:
//
int strnicmp(const char *s, pj_size_t len) const
{
return pj_strnicmp2(this, s, len);
return pj_strnicmp2(this, s, len);
}
//
@ -336,7 +335,7 @@ public:
//
int strnicmp(const pj_str_t *s, pj_size_t len) const
{
return pj_strnicmp(this, s, len);
return pj_strnicmp(this, s, len);
}
//
@ -344,7 +343,7 @@ public:
//
int strnicmp(const Pj_String &rhs, pj_size_t len) const
{
return strnicmp(&rhs, len);
return strnicmp(&rhs, len);
}
//
@ -352,7 +351,7 @@ public:
//
bool operator==(const char *s) const
{
return strcmp(s) == 0;
return strcmp(s) == 0;
}
//
@ -360,7 +359,7 @@ public:
//
bool operator==(const pj_str_t *s) const
{
return strcmp(s) == 0;
return strcmp(s) == 0;
}
//
@ -368,7 +367,7 @@ public:
//
bool operator==(const Pj_String &rhs) const
{
return pj_strcmp(this, &rhs) == 0;
return pj_strcmp(this, &rhs) == 0;
}
//
@ -376,8 +375,8 @@ public:
//
Pj_String& operator=(char *s)
{
set(s);
return *this;
set(s);
return *this;
}
///
@ -385,9 +384,9 @@ public:
//
Pj_String& operator=(const Pj_String &rhs)
{
ptr = rhs.ptr;
slen = rhs.slen;
return *this;
ptr = rhs.ptr;
slen = rhs.slen;
return *this;
}
//
@ -395,7 +394,7 @@ public:
//
char *strchr(int chr)
{
return pj_strchr(this, chr);
return pj_strchr(this, chr);
}
//
@ -403,7 +402,7 @@ public:
//
char *find(int chr)
{
return strchr(chr);
return strchr(chr);
}
//
@ -411,7 +410,7 @@ public:
//
void strcat(const Pj_String &rhs)
{
pj_strcat(this, &rhs);
pj_strcat(this, &rhs);
}
//
@ -419,7 +418,7 @@ public:
//
void ltrim()
{
pj_strltrim(this);
pj_strltrim(this);
}
//
@ -427,7 +426,7 @@ public:
//
void rtrim()
{
pj_strrtrim(this);
pj_strrtrim(this);
}
//
@ -435,7 +434,7 @@ public:
//
void trim()
{
pj_strtrim(this);
pj_strtrim(this);
}
//
@ -443,7 +442,7 @@ public:
//
unsigned long to_ulong() const
{
return pj_strtoul(this);
return pj_strtoul(this);
}
//
@ -464,5 +463,5 @@ public:
};
#endif /* __PJPP_STRING_HPP__ */
#endif /* __PJPP_STRING_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -108,7 +107,7 @@ public:
pj_status_t create(Pj_Pool *pool, pj_size_t initial_count)
{
destroy();
return pj_timer_heap_create(pool->pool_(), initial_count, &ht_);
return pj_timer_heap_create(pool->pool_(), initial_count, &ht_);
}
//
@ -127,7 +126,7 @@ public:
//
pj_timer_heap_t *get_timer_heap()
{
return ht_;
return ht_;
}
//
@ -153,7 +152,7 @@ public:
int id)
{
ent->entry_.id = id;
return pj_timer_heap_schedule(ht_, &ent->entry_, &delay) == 0;
return pj_timer_heap_schedule(ht_, &ent->entry_, &delay) == 0;
}
//
@ -161,7 +160,7 @@ public:
//
bool cancel(Pj_Timer_Entry *ent)
{
return pj_timer_heap_cancel(ht_, &ent->entry_) == 1;
return pj_timer_heap_cancel(ht_, &ent->entry_) == 1;
}
//
@ -169,7 +168,7 @@ public:
//
pj_size_t count()
{
return pj_timer_heap_count(ht_);
return pj_timer_heap_count(ht_);
}
//
@ -178,7 +177,7 @@ public:
//
bool earliest_time(Pj_Time_Val *t)
{
return pj_timer_heap_earliest_time(ht_, t) == PJ_SUCCESS;
return pj_timer_heap_earliest_time(ht_, t) == PJ_SUCCESS;
}
//
@ -187,12 +186,12 @@ public:
//
unsigned poll(Pj_Time_Val *next_delay = NULL)
{
return pj_timer_heap_poll(ht_, next_delay);
return pj_timer_heap_poll(ht_, next_delay);
}
private:
pj_timer_heap_t *ht_;
};
#endif /* __PJPP_TIMER_HPP__ */
#endif /* __PJPP_TIMER_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -34,96 +33,96 @@ public:
class Node : private pj_rbtree_node
{
friend class PJ_Tree;
friend class iterator;
friend class reverse_iterator;
friend class PJ_Tree;
friend class iterator;
friend class reverse_iterator;
public:
Node() {}
explicit Node(void *data) { user_data = data; }
void set_user_data(void *data) { user_data = data; }
void *get_user_data() const { return user_data; }
Node() {}
explicit Node(void *data) { user_data = data; }
void set_user_data(void *data) { user_data = data; }
void *get_user_data() const { return user_data; }
};
class iterator
{
public:
iterator() {}
iterator(const iterator &rhs) : tr_(rhs.tr_), nd_(rhs.nd_) {}
iterator(pj_rbtree *tr, pj_rbtree_node *nd) : tr_(tr), nd_(nd) {}
Node *operator*() { return (Node*)nd_; }
bool operator==(const iterator &rhs) const { return tr_==rhs.tr_ && nd_==rhs.nd_; }
iterator &operator=(const iterator &rhs) { tr_=rhs.tr_; nd_=rhs.nd_; return *this; }
void operator++() { nd_=pj_rbtree_next(tr_, nd_); }
void operator--() { nd_=pj_rbtree_prev(tr_, nd_); }
iterator() {}
iterator(const iterator &rhs) : tr_(rhs.tr_), nd_(rhs.nd_) {}
iterator(pj_rbtree *tr, pj_rbtree_node *nd) : tr_(tr), nd_(nd) {}
Node *operator*() { return (Node*)nd_; }
bool operator==(const iterator &rhs) const { return tr_==rhs.tr_ && nd_==rhs.nd_; }
iterator &operator=(const iterator &rhs) { tr_=rhs.tr_; nd_=rhs.nd_; return *this; }
void operator++() { nd_=pj_rbtree_next(tr_, nd_); }
void operator--() { nd_=pj_rbtree_prev(tr_, nd_); }
protected:
pj_rbtree *tr_;
pj_rbtree_node *nd_;
pj_rbtree *tr_;
pj_rbtree_node *nd_;
};
class reverse_iterator : public iterator
{
public:
reverse_iterator() {}
reverse_iterator(const reverse_iterator &it) : iterator(it) {}
reverse_iterator(pj_rbtree *t, pj_rbtree_node *n) : iterator(t, n) {}
reverse_iterator &operator=(const reverse_iterator &rhs) { iterator::operator=(rhs); return *this; }
Node *operator*() { return (Node*)nd_; }
bool operator==(const reverse_iterator &rhs) const { return iterator::operator==(rhs); }
void operator++() { nd_=pj_rbtree_prev(tr_, nd_); }
void operator--() { nd_=pj_rbtree_next(tr_, nd_); }
reverse_iterator() {}
reverse_iterator(const reverse_iterator &it) : iterator(it) {}
reverse_iterator(pj_rbtree *t, pj_rbtree_node *n) : iterator(t, n) {}
reverse_iterator &operator=(const reverse_iterator &rhs) { iterator::operator=(rhs); return *this; }
Node *operator*() { return (Node*)nd_; }
bool operator==(const reverse_iterator &rhs) const { return iterator::operator==(rhs); }
void operator++() { nd_=pj_rbtree_prev(tr_, nd_); }
void operator--() { nd_=pj_rbtree_next(tr_, nd_); }
};
explicit PJ_Tree(Comp *comp) { pj_rbtree_init(&t_, comp); }
iterator begin()
{
return iterator(&t_, pj_rbtree_first(&t_));
return iterator(&t_, pj_rbtree_first(&t_));
}
iterator end()
{
return iterator(&t_, NULL);
return iterator(&t_, NULL);
}
reverse_iterator rbegin()
{
return reverse_iterator(&t_, pj_rbtree_last(&t_));
return reverse_iterator(&t_, pj_rbtree_last(&t_));
}
reverse_iterator rend()
{
return reverse_iterator(&t_, NULL);
return reverse_iterator(&t_, NULL);
}
bool insert(Node *node)
{
return pj_rbtree_insert(&t_, node)==0 ? true : false;
return pj_rbtree_insert(&t_, node)==0 ? true : false;
}
Node *find(const void *key)
{
return (Node*)pj_rbtree_find(&t_, key);
return (Node*)pj_rbtree_find(&t_, key);
}
Node *erase(Node *node)
{
return (Node*)pj_rbtree_erase(&t_, node);
return (Node*)pj_rbtree_erase(&t_, node);
}
unsigned max_height(Node *node=NULL)
{
return pj_rbtree_max_height(&t_, node);
return pj_rbtree_max_height(&t_, node);
}
unsigned min_height(Node *node=NULL)
{
return pj_rbtree_min_height(&t_, node);
return pj_rbtree_min_height(&t_, node);
}
private:
pj_rbtree t_;
};
#endif /* __PJPP_TREE_HPP__ */
#endif /* __PJPP_TREE_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -124,25 +123,25 @@ public:
Pj_Time_Val & operator = (const Pj_Time_Val &rhs)
{
sec = rhs.sec;
msec = rhs.msec;
return *this;
sec = rhs.sec;
msec = rhs.msec;
return *this;
}
Pj_Time_Val & operator += (const Pj_Time_Val &rhs)
{
PJ_TIME_VAL_ADD((*this), rhs);
return *this;
PJ_TIME_VAL_ADD((*this), rhs);
return *this;
}
Pj_Time_Val & operator -= (const Pj_Time_Val &rhs)
{
PJ_TIME_VAL_SUB((*this), rhs);
return *this;
PJ_TIME_VAL_SUB((*this), rhs);
return *this;
}
/* Must include os.hpp to use these, otherwise unresolved in linking */
inline pj_status_t gettimeofday();
inline pj_status_t gettimeofday();
inline pj_parsed_time decode();
inline pj_status_t encode(const pj_parsed_time *pt);
inline pj_status_t to_gmt();
@ -160,16 +159,16 @@ private:
//
// Macro to declare common object comparison operators.
//
#define PJ_DECLARE_OPERATORS(rhs_type) \
bool operator!=(rhs_type rhs) const { \
return !operator==(rhs); } \
bool operator<=(rhs_type rhs) const { \
return operator<(rhs) || operator==(rhs); } \
bool operator>(rhs_type rhs) const { \
return !operator<=(rhs); } \
bool operator>=(rhs_type rhs) const { \
return !operator<(rhs); }
#define PJ_DECLARE_OPERATORS(rhs_type) \
bool operator!=(rhs_type rhs) const { \
return !operator==(rhs); } \
bool operator<=(rhs_type rhs) const { \
return operator<(rhs) || operator==(rhs); } \
bool operator>(rhs_type rhs) const { \
return !operator<=(rhs); } \
bool operator>=(rhs_type rhs) const { \
return !operator<(rhs); }
#endif /* __PJPP_TYPES_HPP__ */
#endif /* __PJPP_TYPES_HPP__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -59,135 +58,135 @@ typedef struct pj_activesock_cb
* This callback is called when a data arrives as the result of
* pj_activesock_start_read().
*
* @param asock The active socket.
* @param data The buffer containing the new data, if any. If
* the status argument is non-PJ_SUCCESS, this
* argument may be NULL.
* @param size The length of data in the buffer.
* @param status The status of the read operation. This may contain
* non-PJ_SUCCESS for example when the TCP connection
* has been closed. In this case, the buffer may
* contain left over data from previous callback which
* the application may want to process.
* @param remainder If application wishes to leave some data in the
* buffer (common for TCP applications), it should
* move the remainder data to the front part of the
* buffer and set the remainder length here. The value
* of this parameter will be ignored for datagram
* sockets.
* @param asock The active socket.
* @param data The buffer containing the new data, if any. If
* the status argument is non-PJ_SUCCESS, this
* argument may be NULL.
* @param size The length of data in the buffer.
* @param status The status of the read operation. This may contain
* non-PJ_SUCCESS for example when the TCP connection
* has been closed. In this case, the buffer may
* contain left over data from previous callback which
* the application may want to process.
* @param remainder If application wishes to leave some data in the
* buffer (common for TCP applications), it should
* move the remainder data to the front part of the
* buffer and set the remainder length here. The value
* of this parameter will be ignored for datagram
* sockets.
*
* @return PJ_TRUE if further read is desired, and PJ_FALSE
* when application no longer wants to receive data.
* Application may destroy the active socket in the
* callback and return PJ_FALSE here.
* @return PJ_TRUE if further read is desired, and PJ_FALSE
* when application no longer wants to receive data.
* Application may destroy the active socket in the
* callback and return PJ_FALSE here.
*/
pj_bool_t (*on_data_read)(pj_activesock_t *asock,
void *data,
pj_size_t size,
pj_status_t status,
pj_size_t *remainder);
void *data,
pj_size_t size,
pj_status_t status,
pj_size_t *remainder);
/**
* This callback is called when a packet arrives as the result of
* pj_activesock_start_recvfrom().
*
* @param asock The active socket.
* @param data The buffer containing the packet, if any. If
* the status argument is non-PJ_SUCCESS, this
* argument will be set to NULL.
* @param size The length of packet in the buffer. If
* the status argument is non-PJ_SUCCESS, this
* argument will be set to zero.
* @param src_addr Source address of the packet.
* @param addr_len Length of the source address.
* @param status This contains
* @param asock The active socket.
* @param data The buffer containing the packet, if any. If
* the status argument is non-PJ_SUCCESS, this
* argument will be set to NULL.
* @param size The length of packet in the buffer. If
* the status argument is non-PJ_SUCCESS, this
* argument will be set to zero.
* @param src_addr Source address of the packet.
* @param addr_len Length of the source address.
* @param status This contains
*
* @return PJ_TRUE if further read is desired, and PJ_FALSE
* when application no longer wants to receive data.
* Application may destroy the active socket in the
* callback and return PJ_FALSE here.
* @return PJ_TRUE if further read is desired, and PJ_FALSE
* when application no longer wants to receive data.
* Application may destroy the active socket in the
* callback and return PJ_FALSE here.
*/
pj_bool_t (*on_data_recvfrom)(pj_activesock_t *asock,
void *data,
pj_size_t size,
const pj_sockaddr_t *src_addr,
int addr_len,
pj_status_t status);
void *data,
pj_size_t size,
const pj_sockaddr_t *src_addr,
int addr_len,
pj_status_t status);
/**
* This callback is called when data has been sent.
*
* @param asock The active socket.
* @param send_key Key associated with the send operation.
* @param sent If value is positive non-zero it indicates the
* number of data sent. When the value is negative,
* it contains the error code which can be retrieved
* by negating the value (i.e. status=-sent).
* @param asock The active socket.
* @param send_key Key associated with the send operation.
* @param sent If value is positive non-zero it indicates the
* number of data sent. When the value is negative,
* it contains the error code which can be retrieved
* by negating the value (i.e. status=-sent).
*
* @return Application may destroy the active socket in the
* callback and return PJ_FALSE here.
* @return Application may destroy the active socket in the
* callback and return PJ_FALSE here.
*/
pj_bool_t (*on_data_sent)(pj_activesock_t *asock,
pj_ioqueue_op_key_t *send_key,
pj_ssize_t sent);
pj_ioqueue_op_key_t *send_key,
pj_ssize_t sent);
/**
* This callback is called when new connection arrives as the result
* of pj_activesock_start_accept(). If the status of accept operation is
* needed use on_accept_complete2 instead of this callback.
*
* @param asock The active socket.
* @param newsock The new incoming socket.
* @param src_addr The source address of the connection.
* @param addr_len Length of the source address.
* @param asock The active socket.
* @param newsock The new incoming socket.
* @param src_addr The source address of the connection.
* @param addr_len Length of the source address.
*
* @return PJ_TRUE if further accept() is desired, and PJ_FALSE
* when application no longer wants to accept incoming
* connection. Application may destroy the active socket
* in the callback and return PJ_FALSE here.
* @return PJ_TRUE if further accept() is desired, and PJ_FALSE
* when application no longer wants to accept incoming
* connection. Application may destroy the active socket
* in the callback and return PJ_FALSE here.
*/
pj_bool_t (*on_accept_complete)(pj_activesock_t *asock,
pj_sock_t newsock,
const pj_sockaddr_t *src_addr,
int src_addr_len);
pj_sock_t newsock,
const pj_sockaddr_t *src_addr,
int src_addr_len);
/**
* This callback is called when new connection arrives as the result
* of pj_activesock_start_accept().
*
* @param asock The active socket.
* @param newsock The new incoming socket.
* @param src_addr The source address of the connection.
* @param addr_len Length of the source address.
* @param status The status of the accept operation. This may contain
* non-PJ_SUCCESS for example when the TCP listener is in
* bad state for example on iOS platform after the
* application waking up from background.
* @param asock The active socket.
* @param newsock The new incoming socket.
* @param src_addr The source address of the connection.
* @param addr_len Length of the source address.
* @param status The status of the accept operation. This may contain
* non-PJ_SUCCESS for example when the TCP listener is in
* bad state for example on iOS platform after the
* application waking up from background.
*
* @return PJ_TRUE if further accept() is desired, and PJ_FALSE
* when application no longer wants to accept incoming
* connection. Application may destroy the active socket
* in the callback and return PJ_FALSE here.
* @return PJ_TRUE if further accept() is desired, and PJ_FALSE
* when application no longer wants to accept incoming
* connection. Application may destroy the active socket
* in the callback and return PJ_FALSE here.
*/
pj_bool_t (*on_accept_complete2)(pj_activesock_t *asock,
pj_sock_t newsock,
const pj_sockaddr_t *src_addr,
int src_addr_len,
pj_status_t status);
pj_sock_t newsock,
const pj_sockaddr_t *src_addr,
int src_addr_len,
pj_status_t status);
/**
* This callback is called when pending connect operation has been
* completed.
*
* @param asock The active socket.
* @param status The connection result. If connection has been
* successfully established, the status will contain
* PJ_SUCCESS.
* @param asock The active socket.
* @param status The connection result. If connection has been
* successfully established, the status will contain
* PJ_SUCCESS.
*
* @return Application may destroy the active socket in the
* callback and return PJ_FALSE here.
* @return Application may destroy the active socket in the
* callback and return PJ_FALSE here.
*/
pj_bool_t (*on_connect_complete)(pj_activesock_t *asock,
pj_status_t status);
pj_status_t status);
} pj_activesock_cb;
@ -253,7 +252,7 @@ typedef struct pj_activesock_cfg
/**
* Initialize the active socket configuration with the default values.
*
* @param cfg The configuration to be initialized.
* @param cfg The configuration to be initialized.
*/
PJ_DECL(void) pj_activesock_cfg_default(pj_activesock_cfg *cfg);
@ -262,73 +261,73 @@ PJ_DECL(void) pj_activesock_cfg_default(pj_activesock_cfg *cfg);
* Create the active socket for the specified socket. This will register
* the socket to the specified ioqueue.
*
* @param pool Pool to allocate memory from.
* @param sock The socket handle.
* @param sock_type Specify socket type, either pj_SOCK_DGRAM() or
* pj_SOCK_STREAM(). The active socket needs this
* information to handle connection closure for
* connection oriented sockets.
* @param ioqueue The ioqueue to use.
* @param opt Optional settings. When this setting is not specifed,
* the default values will be used.
* @param cb Pointer to structure containing application
* callbacks.
* @param user_data Arbitrary user data to be associated with this
* active socket.
* @param p_asock Pointer to receive the active socket instance.
* @param pool Pool to allocate memory from.
* @param sock The socket handle.
* @param sock_type Specify socket type, either pj_SOCK_DGRAM() or
* pj_SOCK_STREAM(). The active socket needs this
* information to handle connection closure for
* connection oriented sockets.
* @param ioqueue The ioqueue to use.
* @param opt Optional settings. When this setting is not specifed,
* the default values will be used.
* @param cb Pointer to structure containing application
* callbacks.
* @param user_data Arbitrary user data to be associated with this
* active socket.
* @param p_asock Pointer to receive the active socket instance.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_create(pj_pool_t *pool,
pj_sock_t sock,
int sock_type,
const pj_activesock_cfg *opt,
pj_ioqueue_t *ioqueue,
const pj_activesock_cb *cb,
void *user_data,
pj_activesock_t **p_asock);
pj_sock_t sock,
int sock_type,
const pj_activesock_cfg *opt,
pj_ioqueue_t *ioqueue,
const pj_activesock_cb *cb,
void *user_data,
pj_activesock_t **p_asock);
/**
* Create UDP socket descriptor, bind it to the specified address, and
* create the active socket for the socket descriptor.
*
* @param pool Pool to allocate memory from.
* @param addr Specifies the address family of the socket and the
* address where the socket should be bound to. If
* this argument is NULL, then AF_INET is assumed and
* the socket will be bound to any addresses and port.
* @param ioqueue The ioqueue.
* @param opt Optional settings. When this setting is not specifed,
* the default values will be used.
* @param cb Pointer to structure containing application
* callbacks.
* @param user_data Arbitrary user data to be associated with this
* active socket.
* @param p_asock Pointer to receive the active socket instance.
* @param bound_addr If this argument is specified, it will be filled with
* the bound address on return.
* @param pool Pool to allocate memory from.
* @param addr Specifies the address family of the socket and the
* address where the socket should be bound to. If
* this argument is NULL, then AF_INET is assumed and
* the socket will be bound to any addresses and port.
* @param ioqueue The ioqueue.
* @param opt Optional settings. When this setting is not specifed,
* the default values will be used.
* @param cb Pointer to structure containing application
* callbacks.
* @param user_data Arbitrary user data to be associated with this
* active socket.
* @param p_asock Pointer to receive the active socket instance.
* @param bound_addr If this argument is specified, it will be filled with
* the bound address on return.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_create_udp(pj_pool_t *pool,
const pj_sockaddr *addr,
const pj_activesock_cfg *opt,
pj_ioqueue_t *ioqueue,
const pj_activesock_cb *cb,
void *user_data,
pj_activesock_t **p_asock,
pj_sockaddr *bound_addr);
const pj_sockaddr *addr,
const pj_activesock_cfg *opt,
pj_ioqueue_t *ioqueue,
const pj_activesock_cb *cb,
void *user_data,
pj_activesock_t **p_asock,
pj_sockaddr *bound_addr);
/**
* Close the active socket. This will unregister the socket from the
* ioqueue and ultimately close the socket.
*
* @param asock The active socket.
* @param asock The active socket.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_close(pj_activesock_t *asock);
@ -344,12 +343,12 @@ PJ_DECL(pj_status_t) pj_activesock_close(pj_activesock_t *asock);
* This API is only available if PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT
* is set to non-zero.
*
* @param asock The active socket.
* @param val The value of background mode setting.
* @param asock The active socket.
* @param val The value of background mode setting.
*
*/
PJ_DECL(void) pj_activesock_set_iphone_os_bg(pj_activesock_t *asock,
int val);
int val);
/**
* Enable/disable support for iPhone OS background mode. This setting
@ -361,7 +360,7 @@ PJ_DECL(void) pj_activesock_set_iphone_os_bg(pj_activesock_t *asock,
* This API is only available if PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT
* is set to non-zero.
*
* @param val The value of global background mode setting.
* @param val The value of global background mode setting.
*
*/
PJ_DECL(void) pj_activesock_enable_iphone_os_bg(pj_bool_t val);
@ -372,23 +371,23 @@ PJ_DECL(void) pj_activesock_enable_iphone_os_bg(pj_bool_t val);
* inspect this data in the callbacks and associate it with higher
* level processing.
*
* @param asock The active socket.
* @param asock The active socket.
* @param user_data The user data to be associated with the active
* socket.
* socket.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_set_user_data(pj_activesock_t *asock,
void *user_data);
void *user_data);
/**
* Retrieve the user data previously associated with this active
* socket.
*
* @param asock The active socket.
* @param asock The active socket.
*
* @return The user data.
* @return The user data.
*/
PJ_DECL(void*) pj_activesock_get_user_data(pj_activesock_t *asock);
@ -407,131 +406,131 @@ PJ_DECL(void*) pj_activesock_get_user_data(pj_activesock_t *asock);
* operations. Further read operations will be done automatically by the
* active socket when \a on_data_read() callback returns non-zero.
*
* @param asock The active socket.
* @param pool Pool used to allocate buffers for incoming data.
* @param asock The active socket.
* @param pool Pool used to allocate buffers for incoming data.
* @param buff_size The size of each buffer, in bytes.
* @param flags Flags to be given to pj_ioqueue_recv().
* @param flags Flags to be given to pj_ioqueue_recv().
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_start_read(pj_activesock_t *asock,
pj_pool_t *pool,
unsigned buff_size,
pj_uint32_t flags);
pj_pool_t *pool,
unsigned buff_size,
pj_uint32_t flags);
/**
* Same as #pj_activesock_start_read(), except that the application
* supplies the buffers for the read operation so that the acive socket
* does not have to allocate the buffers.
*
* @param asock The active socket.
* @param pool Pool used to allocate buffers for incoming data.
* @param asock The active socket.
* @param pool Pool used to allocate buffers for incoming data.
* @param buff_size The size of each buffer, in bytes.
* @param readbuf Array of packet buffers, each has buff_size size.
* @param flags Flags to be given to pj_ioqueue_recv().
* @param flags Flags to be given to pj_ioqueue_recv().
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_start_read2(pj_activesock_t *asock,
pj_pool_t *pool,
unsigned buff_size,
void *readbuf[],
pj_uint32_t flags);
pj_pool_t *pool,
unsigned buff_size,
void *readbuf[],
pj_uint32_t flags);
/**
* Same as pj_activesock_start_read(), except that this function is used
* only for datagram sockets, and it will trigger \a on_data_recvfrom()
* callback instead.
*
* @param asock The active socket.
* @param pool Pool used to allocate buffers for incoming data.
* @param asock The active socket.
* @param pool Pool used to allocate buffers for incoming data.
* @param buff_size The size of each buffer, in bytes.
* @param flags Flags to be given to pj_ioqueue_recvfrom().
* @param flags Flags to be given to pj_ioqueue_recvfrom().
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_start_recvfrom(pj_activesock_t *asock,
pj_pool_t *pool,
unsigned buff_size,
pj_uint32_t flags);
pj_pool_t *pool,
unsigned buff_size,
pj_uint32_t flags);
/**
* Same as #pj_activesock_start_recvfrom() except that the recvfrom()
* operation takes the buffer from the argument rather than creating
* new ones.
*
* @param asock The active socket.
* @param pool Pool used to allocate buffers for incoming data.
* @param asock The active socket.
* @param pool Pool used to allocate buffers for incoming data.
* @param buff_size The size of each buffer, in bytes.
* @param readbuf Array of packet buffers, each has buff_size size.
* @param flags Flags to be given to pj_ioqueue_recvfrom().
* @param flags Flags to be given to pj_ioqueue_recvfrom().
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_start_recvfrom2(pj_activesock_t *asock,
pj_pool_t *pool,
unsigned buff_size,
void *readbuf[],
pj_uint32_t flags);
pj_pool_t *pool,
unsigned buff_size,
void *readbuf[],
pj_uint32_t flags);
/**
* Send data using the socket.
*
* @param asock The active socket.
* @param asock The active socket.
* @param send_key The operation key to send the data, which is useful
* if application wants to submit multiple pending
* send operations and want to track which exact data
* has been sent in the \a on_data_sent() callback.
* @param data The data to be sent. This data must remain valid
* until the data has been sent.
* @param size The size of the data.
* @param flags Flags to be given to pj_ioqueue_send().
* if application wants to submit multiple pending
* send operations and want to track which exact data
* has been sent in the \a on_data_sent() callback.
* @param data The data to be sent. This data must remain valid
* until the data has been sent.
* @param size The size of the data.
* @param flags Flags to be given to pj_ioqueue_send().
*
*
* @return PJ_SUCCESS if data has been sent immediately, or
* PJ_EPENDING if data cannot be sent immediately. In
* this case the \a on_data_sent() callback will be
* called when data is actually sent. Any other return
* value indicates error condition.
* @return PJ_SUCCESS if data has been sent immediately, or
* PJ_EPENDING if data cannot be sent immediately. In
* this case the \a on_data_sent() callback will be
* called when data is actually sent. Any other return
* value indicates error condition.
*/
PJ_DECL(pj_status_t) pj_activesock_send(pj_activesock_t *asock,
pj_ioqueue_op_key_t *send_key,
const void *data,
pj_ssize_t *size,
unsigned flags);
pj_ioqueue_op_key_t *send_key,
const void *data,
pj_ssize_t *size,
unsigned flags);
/**
* Send datagram using the socket.
*
* @param asock The active socket.
* @param asock The active socket.
* @param send_key The operation key to send the data, which is useful
* if application wants to submit multiple pending
* send operations and want to track which exact data
* has been sent in the \a on_data_sent() callback.
* @param data The data to be sent. This data must remain valid
* until the data has been sent.
* @param size The size of the data.
* @param flags Flags to be given to pj_ioqueue_send().
* @param addr The destination address.
* if application wants to submit multiple pending
* send operations and want to track which exact data
* has been sent in the \a on_data_sent() callback.
* @param data The data to be sent. This data must remain valid
* until the data has been sent.
* @param size The size of the data.
* @param flags Flags to be given to pj_ioqueue_send().
* @param addr The destination address.
* @param addr_len The length of the address.
*
* @return PJ_SUCCESS if data has been sent immediately, or
* PJ_EPENDING if data cannot be sent immediately. In
* this case the \a on_data_sent() callback will be
* called when data is actually sent. Any other return
* value indicates error condition.
* @return PJ_SUCCESS if data has been sent immediately, or
* PJ_EPENDING if data cannot be sent immediately. In
* this case the \a on_data_sent() callback will be
* called when data is actually sent. Any other return
* value indicates error condition.
*/
PJ_DECL(pj_status_t) pj_activesock_sendto(pj_activesock_t *asock,
pj_ioqueue_op_key_t *send_key,
const void *data,
pj_ssize_t *size,
unsigned flags,
const pj_sockaddr_t *addr,
int addr_len);
pj_ioqueue_op_key_t *send_key,
const void *data,
pj_ssize_t *size,
unsigned flags,
const pj_sockaddr_t *addr,
int addr_len);
#if PJ_HAS_TCP
/**
@ -546,40 +545,40 @@ PJ_DECL(pj_status_t) pj_activesock_sendto(pj_activesock_t *asock,
* operations. Further accept() operations will be done automatically by
* the active socket when \a on_accept_complete() callback returns non-zero.
*
* @param asock The active socket.
* @param pool Pool used to allocate some internal data for the
* operation.
* @param asock The active socket.
* @param pool Pool used to allocate some internal data for the
* operation.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_activesock_start_accept(pj_activesock_t *asock,
pj_pool_t *pool);
pj_pool_t *pool);
/**
* Starts asynchronous socket connect() operation for this socket. Once
* the connection is done (either successfully or not), the
* \a on_connect_complete() callback will be called.
*
* @param asock The active socket.
* @param pool The pool to allocate some internal data for the
* operation.
* @param asock The active socket.
* @param pool The pool to allocate some internal data for the
* operation.
* @param remaddr Remote address.
* @param addr_len Length of the remote address.
*
* @return PJ_SUCCESS if connection can be established immediately,
* or PJ_EPENDING if connection cannot be established
* immediately. In this case the \a on_connect_complete()
* callback will be called when connection is complete.
* Any other return value indicates error condition.
* @return PJ_SUCCESS if connection can be established immediately,
* or PJ_EPENDING if connection cannot be established
* immediately. In this case the \a on_connect_complete()
* callback will be called when connection is complete.
* Any other return value indicates error condition.
*/
PJ_DECL(pj_status_t) pj_activesock_start_connect(pj_activesock_t *asock,
pj_pool_t *pool,
const pj_sockaddr_t *remaddr,
int addr_len);
pj_pool_t *pool,
const pj_sockaddr_t *remaddr,
int addr_len);
#endif /* PJ_HAS_TCP */
#endif /* PJ_HAS_TCP */
/**
* @}
@ -587,5 +586,5 @@ PJ_DECL(pj_status_t) pj_activesock_start_connect(pj_activesock_t *asock,
PJ_END_DECL
#endif /* __PJ_ASYNCSOCK_H__ */
#endif /* __PJ_ASYNCSOCK_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -64,11 +63,11 @@ PJ_BEGIN_DECL
/** This structure describes an Internet host address. */
typedef struct pj_hostent
{
char *h_name; /**< The official name of the host. */
char **h_aliases; /**< Aliases list. */
int h_addrtype; /**< Host address type. */
int h_length; /**< Length of address. */
char **h_addr_list; /**< List of addresses. */
char *h_name; /**< The official name of the host. */
char **h_aliases; /**< Aliases list. */
int h_addrtype; /**< Host address type. */
int h_length; /**< Length of address. */
char **h_addr_list; /**< List of addresses. */
} pj_hostent;
/** Shortcut to h_addr_list[0] */
@ -79,8 +78,8 @@ typedef struct pj_hostent
*/
typedef struct pj_addrinfo
{
char ai_canonname[PJ_MAX_HOSTNAME]; /**< Canonical name for host*/
pj_sockaddr ai_addr; /**< Binary address. */
char ai_canonname[PJ_MAX_HOSTNAME]; /**< Canonical name for host*/
pj_sockaddr ai_addr; /**< Binary address. */
} pj_addrinfo;
@ -89,14 +88,14 @@ typedef struct pj_addrinfo
* For host resolution function that also works with IPv6, please see
* #pj_getaddrinfo().
*
* @param name Host name to resolve. Specifying IPv4 address here
* may fail on some platforms (e.g. Windows)
* @param he The pj_hostent structure to be filled. Note that
* the pointers in this structure points to temporary
* variables which value will be reset upon subsequent
* invocation.
* @param name Host name to resolve. Specifying IPv4 address here
* may fail on some platforms (e.g. Windows)
* @param he The pj_hostent structure to be filled. Note that
* the pointers in this structure points to temporary
* variables which value will be reset upon subsequent
* invocation.
*
* @return PJ_SUCCESS, or the appropriate error codes.
* @return PJ_SUCCESS, or the appropriate error codes.
*/
PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
@ -104,14 +103,14 @@ PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he);
/**
* Resolve the primary IP address of local host.
*
* @param af The desired address family to query. Valid values
* are pj_AF_INET() or pj_AF_INET6().
* @param af The desired address family to query. Valid values
* are pj_AF_INET() or pj_AF_INET6().
* @param addr On successful resolution, the address family and address
* part of this socket address will be filled up with the host
* IP address, in network byte order. Other parts of the socket
* address are untouched.
* part of this socket address will be filled up with the host
* IP address, in network byte order. Other parts of the socket
* address are untouched.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr);
@ -119,21 +118,21 @@ PJ_DECL(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr);
/**
* Get the interface IP address to send data to the specified destination.
*
* @param af The desired address family to query. Valid values
* are pj_AF_INET() or pj_AF_INET6().
* @param dst The destination host.
* @param af The desired address family to query. Valid values
* are pj_AF_INET() or pj_AF_INET6().
* @param dst The destination host.
* @param itf_addr On successful resolution, the address family and address
* part of this socket address will be filled up with the host
* IP address, in network byte order. Other parts of the socket
* address should be ignored.
* part of this socket address will be filled up with the host
* IP address, in network byte order. Other parts of the socket
* address should be ignored.
* @param allow_resolve If \a dst may contain hostname (instead of IP
* address), specify whether hostname resolution should
* be performed. If not, default interface address will
* be returned.
* address), specify whether hostname resolution should
* be performed. If not, default interface address will
* be returned.
* @param p_dst_addr If not NULL, it will be filled with the IP address of
* the destination host.
* the destination host.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_getipinterface(int af,
const pj_str_t *dst,
@ -145,17 +144,17 @@ PJ_DECL(pj_status_t) pj_getipinterface(int af,
* Get the IP address of the default interface. Default interface is the
* interface of the default route.
*
* @param af The desired address family to query. Valid values
* are pj_AF_INET() or pj_AF_INET6().
* @param af The desired address family to query. Valid values
* are pj_AF_INET() or pj_AF_INET6().
* @param addr On successful resolution, the address family and address
* part of this socket address will be filled up with the host
* IP address, in network byte order. Other parts of the socket
* address are untouched.
* part of this socket address will be filled up with the host
* IP address, in network byte order. Other parts of the socket
* address are untouched.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_getdefaultipinterface(int af,
pj_sockaddr *addr);
pj_sockaddr *addr);
/**
@ -164,21 +163,21 @@ PJ_DECL(pj_status_t) pj_getdefaultipinterface(int af,
* to be used in creating a socket with which to address the specified
* service.
*
* @param af The desired address family to query. Valid values
* are pj_AF_INET(), pj_AF_INET6(), or pj_AF_UNSPEC().
* @param name Descriptive name or an address string, such as host
* name.
* @param count On input, it specifies the number of elements in
* \a ai array. On output, this will be set with the
* number of address informations found for the
* specified name.
* @param ai Array of address info to be filled with the information
* about the host.
* @param af The desired address family to query. Valid values
* are pj_AF_INET(), pj_AF_INET6(), or pj_AF_UNSPEC().
* @param name Descriptive name or an address string, such as host
* name.
* @param count On input, it specifies the number of elements in
* \a ai array. On output, this will be set with the
* number of address informations found for the
* specified name.
* @param ai Array of address info to be filled with the information
* about the host.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *name,
unsigned *count, pj_addrinfo ai[]);
unsigned *count, pj_addrinfo ai[]);
@ -186,5 +185,5 @@ PJ_DECL(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *name,
PJ_END_DECL
#endif /* __PJ_ADDR_RESOLV_H__ */
#endif /* __PJ_ADDR_RESOLV_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -41,49 +40,49 @@ PJ_BEGIN_DECL
* Insert value to the array at the given position, and rearrange the
* remaining nodes after the position.
*
* @param array the array.
* @param array the array.
* @param elem_size the size of the individual element.
* @param count the CURRENT number of elements in the array.
* @param pos the position where the new element is put.
* @param value the value to copy to the new element.
* @param count the CURRENT number of elements in the array.
* @param pos the position where the new element is put.
* @param value the value to copy to the new element.
*/
PJ_DECL(void) pj_array_insert( void *array,
unsigned elem_size,
unsigned count,
unsigned pos,
const void *value);
unsigned elem_size,
unsigned count,
unsigned pos,
const void *value);
/**
* Erase a value from the array at given position, and rearrange the remaining
* elements post the erased element.
*
* @param array the array.
* @param array the array.
* @param elem_size the size of the individual element.
* @param count the current number of elements in the array.
* @param pos the index/position to delete.
* @param count the current number of elements in the array.
* @param pos the index/position to delete.
*/
PJ_DECL(void) pj_array_erase( void *array,
unsigned elem_size,
unsigned count,
unsigned pos);
unsigned elem_size,
unsigned count,
unsigned pos);
/**
* Search the first value in the array according to matching function.
*
* @param array the array.
* @param array the array.
* @param elem_size the individual size of the element.
* @param count the number of elements.
* @param count the number of elements.
* @param matching the matching function, which MUST return PJ_SUCCESS if
* the specified element match.
* the specified element match.
* @param result the pointer to the value found.
*
* @return PJ_SUCCESS if value is found, otherwise the error code.
* @return PJ_SUCCESS if value is found, otherwise the error code.
*/
PJ_DECL(pj_status_t) pj_array_find( const void *array,
unsigned elem_size,
unsigned count,
pj_status_t (*matching)(const void *value),
void **result);
unsigned elem_size,
unsigned count,
pj_status_t (*matching)(const void *value),
void **result);
/**
* @}
@ -92,5 +91,5 @@ PJ_DECL(pj_status_t) pj_array_find( const void *array,
PJ_END_DECL
#endif /* __PJ_ARRAY_H__ */
#endif /* __PJ_ARRAY_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -43,7 +42,7 @@
* offending statements.
* For release build, this macro will not do anything.
*
* @param expr The expression to be evaluated.
* @param expr The expression to be evaluated.
*/
#ifndef pj_assert
# define pj_assert(expr) assert(expr)
@ -57,9 +56,9 @@
*/
// #if defined(PJ_ENABLE_EXTRA_CHECK) && PJ_ENABLE_EXTRA_CHECK != 0
#define PJ_ASSERT_RETURN(expr,retval) \
do { \
if (!(expr)) { pj_assert(expr); return retval; } \
} while (0)
do { \
if (!(expr)) { pj_assert(expr); return retval; } \
} while (0)
//#else
//# define PJ_ASSERT_RETURN(expr,retval) pj_assert(expr)
//#endif
@ -71,15 +70,15 @@
*/
//#if defined(PJ_ENABLE_EXTRA_CHECK) && PJ_ENABLE_EXTRA_CHECK != 0
#define PJ_ASSERT_ON_FAIL(expr,exec_on_fail) \
do { \
pj_assert(expr); \
if (!(expr)) exec_on_fail; \
} while (0)
do { \
pj_assert(expr); \
if (!(expr)) exec_on_fail; \
} while (0)
//#else
//# define PJ_ASSERT_ON_FAIL(expr,exec_on_fail) pj_assert(expr)
//#endif
/** @} */
#endif /* __PJ_ASSERT_H__ */
#endif /* __PJ_ASSERT_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -33,5 +32,5 @@
# define assert(expr)
#endif
#endif /* __PJ_COMPAT_ASSERT_H__ */
#endif /* __PJ_COMPAT_ASSERT_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -29,30 +28,30 @@
# error "This file is only for armcc!"
#endif
#define PJ_CC_NAME "armcc"
#define PJ_CC_NAME "armcc"
#define PJ_CC_VER_1 (__ARMCC_VERSION/100000)
#define PJ_CC_VER_2 ((__ARMCC_VERSION%100000)/10000)
#define PJ_CC_VER_3 (__ARMCC_VERSION%10000)
#ifdef __cplusplus
# define PJ_INLINE_SPECIFIER inline
# define PJ_INLINE_SPECIFIER inline
#else
# define PJ_INLINE_SPECIFIER static __inline
# define PJ_INLINE_SPECIFIER static __inline
#endif
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_ATTR_MAY_ALIAS __attribute__ ((__may_alias__))
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_ATTR_MAY_ALIAS __attribute__ ((__may_alias__))
#define PJ_HAS_INT64 1
#define PJ_HAS_INT64 1
typedef long long pj_int64_t;
typedef unsigned long long pj_uint64_t;
#define PJ_INT64_FMT "L"
#define PJ_INT64_FMT "L"
#define PJ_UNREACHED(x)
#define PJ_UNREACHED(x)
#endif /* __PJ_COMPAT_CC_ARMCC_H__ */
#endif /* __PJ_COMPAT_CC_ARMCC_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -29,28 +28,28 @@
# error "This file is only for Code Warrior!"
#endif
#define PJ_CC_NAME "codewarrior"
#define PJ_CC_VER_1 ((__MWERKS__ & 0xF000) >> 12)
#define PJ_CC_VER_2 ((__MWERKS__ & 0x0F00) >> 8)
#define PJ_CC_VER_3 ((__MWERKS__ & 0xFF))
#define PJ_CC_NAME "codewarrior"
#define PJ_CC_VER_1 ((__MWERKS__ & 0xF000) >> 12)
#define PJ_CC_VER_2 ((__MWERKS__ & 0x0F00) >> 8)
#define PJ_CC_VER_3 ((__MWERKS__ & 0xFF))
#define PJ_INLINE_SPECIFIER static inline
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN
#define PJ_ATTR_MAY_ALIAS
#define PJ_INLINE_SPECIFIER static inline
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN
#define PJ_ATTR_MAY_ALIAS
#define PJ_HAS_INT64 1
#define PJ_HAS_INT64 1
typedef long long pj_int64_t;
typedef unsigned long long pj_uint64_t;
#define PJ_INT64(val) val##LL
#define PJ_UINT64(val) val##LLU
#define PJ_INT64_FMT "L"
#define PJ_INT64(val) val##LL
#define PJ_UINT64(val) val##LLU
#define PJ_INT64_FMT "L"
#define PJ_UNREACHED(x)
#define PJ_UNREACHED(x)
#endif /* __PJ_COMPAT_CC_CODEW_H__ */
#endif /* __PJ_COMPAT_CC_CODEW_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -29,52 +28,52 @@
# error "This file is only for gcc!"
#endif
#define PJ_CC_NAME "gcc"
#define PJ_CC_VER_1 __GNUC__
#define PJ_CC_VER_2 __GNUC_MINOR__
#define PJ_CC_NAME "gcc"
#define PJ_CC_VER_1 __GNUC__
#define PJ_CC_VER_2 __GNUC_MINOR__
/* __GNUC_PATCHLEVEL__ doesn't exist in gcc-2.9x.x */
#ifdef __GNUC_PATCHLEVEL__
# define PJ_CC_VER_3 __GNUC_PATCHLEVEL__
# define PJ_CC_VER_3 __GNUC_PATCHLEVEL__
#else
# define PJ_CC_VER_3 0
# define PJ_CC_VER_3 0
#endif
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_HAS_INT64 1
#define PJ_HAS_INT64 1
#ifdef __STRICT_ANSI__
#include <inttypes.h>
typedef int64_t pj_int64_t;
typedef uint64_t pj_uint64_t;
#define PJ_INLINE_SPECIFIER static __inline
#define PJ_ATTR_NORETURN
#define PJ_ATTR_MAY_ALIAS
typedef int64_t pj_int64_t;
typedef uint64_t pj_uint64_t;
#define PJ_INLINE_SPECIFIER static __inline
#define PJ_ATTR_NORETURN
#define PJ_ATTR_MAY_ALIAS
#else
typedef long long pj_int64_t;
typedef unsigned long long pj_uint64_t;
#define PJ_INLINE_SPECIFIER static inline
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_ATTR_MAY_ALIAS __attribute__((__may_alias__))
typedef long long pj_int64_t;
typedef unsigned long long pj_uint64_t;
#define PJ_INLINE_SPECIFIER static inline
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_ATTR_MAY_ALIAS __attribute__((__may_alias__))
#endif
#define PJ_INT64(val) val##LL
#define PJ_UINT64(val) val##ULL
#define PJ_INT64_FMT "L"
#define PJ_INT64(val) val##LL
#define PJ_UINT64(val) val##ULL
#define PJ_INT64_FMT "L"
#ifdef __GLIBC__
# define PJ_HAS_BZERO 1
# define PJ_HAS_BZERO 1
#endif
#define PJ_UNREACHED(x)
#define PJ_UNREACHED(x)
#define PJ_ALIGN_DATA(declaration, alignment) declaration __attribute__((aligned (alignment)))
#endif /* __PJ_COMPAT_CC_GCC_H__ */
#endif /* __PJ_COMPAT_CC_GCC_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -29,27 +28,27 @@
# error "This file is only for gcce!"
#endif
#define PJ_CC_NAME "gcce"
#define PJ_CC_VER_1 __GCCE__
#define PJ_CC_VER_2 __GCCE_MINOR__
#define PJ_CC_VER_3 __GCCE_PATCHLEVEL__
#define PJ_CC_NAME "gcce"
#define PJ_CC_VER_1 __GCCE__
#define PJ_CC_VER_2 __GCCE_MINOR__
#define PJ_CC_VER_3 __GCCE_PATCHLEVEL__
#define PJ_INLINE_SPECIFIER static inline
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_ATTR_MAY_ALIAS __attribute__ ((__may_alias__))
#define PJ_INLINE_SPECIFIER static inline
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_ATTR_MAY_ALIAS __attribute__ ((__may_alias__))
#define PJ_HAS_INT64 1
#define PJ_HAS_INT64 1
typedef long long pj_int64_t;
typedef unsigned long long pj_uint64_t;
#define PJ_INT64(val) val##LL
#define PJ_UINT64(val) val##LLU
#define PJ_INT64_FMT "L"
#define PJ_INT64(val) val##LL
#define PJ_UINT64(val) val##LLU
#define PJ_INT64_FMT "L"
#endif /* __PJ_COMPAT_CC_GCCE_H__ */
#endif /* __PJ_COMPAT_CC_GCCE_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -29,10 +28,10 @@
# error "This header file is only for Visual C compiler!"
#endif
#define PJ_CC_NAME "msvc"
#define PJ_CC_VER_1 (_MSC_VER/100)
#define PJ_CC_VER_2 (_MSC_VER%100)
#define PJ_CC_VER_3 0
#define PJ_CC_NAME "msvc"
#define PJ_CC_VER_1 (_MSC_VER/100)
#define PJ_CC_VER_2 (_MSC_VER%100)
#define PJ_CC_VER_3 0
/* Disable CRT deprecation warnings. */
#if PJ_CC_VER_1 >= 8 && !defined(_CRT_SECURE_NO_DEPRECATE)
@ -56,33 +55,33 @@
#endif
#ifdef __cplusplus
# define PJ_INLINE_SPECIFIER inline
# define PJ_INLINE_SPECIFIER inline
#else
# define PJ_INLINE_SPECIFIER static __inline
# define PJ_INLINE_SPECIFIER static __inline
#endif
#define PJ_EXPORT_DECL_SPECIFIER __declspec(dllexport)
#define PJ_EXPORT_DEF_SPECIFIER __declspec(dllexport)
#define PJ_EXPORT_DEF_SPECIFIER __declspec(dllexport)
#define PJ_IMPORT_DECL_SPECIFIER __declspec(dllimport)
#define PJ_THREAD_FUNC
#define PJ_NORETURN __declspec(noreturn)
#define PJ_ATTR_NORETURN
#define PJ_ATTR_MAY_ALIAS
#define PJ_THREAD_FUNC
#define PJ_NORETURN __declspec(noreturn)
#define PJ_ATTR_NORETURN
#define PJ_ATTR_MAY_ALIAS
#define PJ_HAS_INT64 1
#define PJ_HAS_INT64 1
typedef __int64 pj_int64_t;
typedef unsigned __int64 pj_uint64_t;
#define PJ_INT64(val) val##i64
#define PJ_UINT64(val) val##ui64
#define PJ_INT64_FMT "I64"
#define PJ_INT64(val) val##i64
#define PJ_UINT64(val) val##ui64
#define PJ_INT64_FMT "I64"
#define PJ_UNREACHED(x)
#define PJ_UNREACHED(x)
#define PJ_ALIGN_DATA(declaration, alignment) __declspec(align(alignment)) declaration
#endif /* __PJ_COMPAT_CC_MSVC_H__ */
#endif /* __PJ_COMPAT_CC_MSVC_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -29,28 +28,28 @@
# error "This file is only for mwcc!"
#endif
#define PJ_CC_NAME "mwcc32sym"
#define PJ_CC_VER_1 1
#define PJ_CC_VER_2 0
#define PJ_CC_VER_3 0
#define PJ_CC_NAME "mwcc32sym"
#define PJ_CC_VER_1 1
#define PJ_CC_VER_2 0
#define PJ_CC_VER_3 0
#define PJ_INLINE_SPECIFIER static inline
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_ATTR_MAY_ALIAS
#define PJ_INLINE_SPECIFIER static inline
#define PJ_THREAD_FUNC
#define PJ_NORETURN
#define PJ_ATTR_NORETURN __attribute__ ((noreturn))
#define PJ_ATTR_MAY_ALIAS
#define PJ_HAS_INT64 1
#define PJ_HAS_INT64 1
typedef long long pj_int64_t;
typedef unsigned long long pj_uint64_t;
#define PJ_INT64(val) val##LL
#define PJ_UINT64(val) val##LLU
#define PJ_INT64_FMT "L"
#define PJ_INT64(val) val##LL
#define PJ_UINT64(val) val##LLU
#define PJ_INT64_FMT "L"
#define PJ_UNREACHED(x)
#define PJ_UNREACHED(x)
#endif /* __PJ_COMPAT_CC_MWCC_H__ */
#endif /* __PJ_COMPAT_CC_MWCC_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -28,18 +27,18 @@
#if defined(PJ_HAS_CTYPE_H) && PJ_HAS_CTYPE_H != 0
# include <ctype.h>
#else
# define isalnum(c) (isalpha(c) || isdigit(c))
# define isalpha(c) (islower(c) || isupper(c))
# define isascii(c) (((unsigned char)(c))<=0x7f)
# define isdigit(c) ((c)>='0' && (c)<='9')
# define isspace(c) ((c)==' ' || (c)=='\t' ||\
(c)=='\n' || (c)=='\r' || (c)=='\v')
# define islower(c) ((c)>='a' && (c)<='z')
# define isupper(c) ((c)>='A' && (c)<='Z')
# define isxdigit(c) (isdigit(c) || (tolower(c)>='a'&&tolower(c)<='f'))
# define tolower(c) (((c) >= 'A' && (c) <= 'Z') ? (c)+('a'-'A') : (c))
# define toupper(c) (((c) >= 'a' && (c) <= 'z') ? (c)-('a'-'A') : (c))
# define isalnum(c) (isalpha(c) || isdigit(c))
# define isalpha(c) (islower(c) || isupper(c))
# define isascii(c) (((unsigned char)(c))<=0x7f)
# define isdigit(c) ((c)>='0' && (c)<='9')
# define isspace(c) ((c)==' ' || (c)=='\t' ||\
(c)=='\n' || (c)=='\r' || (c)=='\v')
# define islower(c) ((c)>='a' && (c)<='z')
# define isupper(c) ((c)>='A' && (c)<='Z')
# define isxdigit(c) (isdigit(c) || (tolower(c)>='a'&&tolower(c)<='f'))
# define tolower(c) (((c) >= 'A' && (c) <= 'Z') ? (c)+('a'-'A') : (c))
# define toupper(c) (((c) >= 'a' && (c) <= 'z') ? (c)-('a'-'A') : (c))
#endif
#endif /* __PJ_COMPAT_CTYPE_H__ */
#endif /* __PJ_COMPAT_CTYPE_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -25,14 +24,14 @@
defined(PJ_WIN64) && PJ_WIN64 != 0
typedef unsigned long pj_os_err_type;
# define pj_get_native_os_error() GetLastError()
# define pj_get_native_netos_error() WSAGetLastError()
# define pj_get_native_os_error() GetLastError()
# define pj_get_native_netos_error() WSAGetLastError()
#elif defined(PJ_HAS_ERRNO_VAR) && PJ_HAS_ERRNO_VAR!= 0
typedef int pj_os_err_type;
# define pj_get_native_os_error() (errno)
# define pj_get_native_netos_error() (errno)
# define pj_get_native_os_error() (errno)
# define pj_get_native_netos_error() (errno)
#else
@ -41,5 +40,5 @@
#endif
#endif /* __PJ_COMPAT_ERRNO_H__ */
#endif /* __PJ_COMPAT_ERRNO_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -84,5 +83,5 @@
#endif
#endif /* __PJ_COMPAT_HIGH_PRECISION_H__ */
#endif /* __PJ_COMPAT_HIGH_PRECISION_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2017 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2017 George Joseph <gjoseph@digium.com>
@ -33,8 +32,8 @@
# ifdef _MSC_VER
# pragma message("limits.h is not found or not supported. LONG_MIN and "\
"LONG_MAX will be defined by the library in "\
"pj/compats/limits.h and overridable in config_site.h")
"LONG_MAX will be defined by the library in "\
"pj/compats/limits.h and overridable in config_site.h")
# else
# warning "limits.h is not found or not supported. LONG_MIN and LONG_MAX " \
"will be defined by the library in pj/compats/limits.h and "\

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -25,12 +24,12 @@
* @brief Describes Alpha processor family specifics.
*/
#define PJ_M_NAME "alpha"
#define PJ_M_NAME "alpha"
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#endif /* __PJ_COMPAT_M_ALPHA_H__ */
#endif /* __PJ_COMPAT_M_ALPHA_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -29,11 +28,11 @@
* This file covers PJ_M_ARMV4 etc.
*/
#define PJ_M_NAME "armv4"
#define PJ_M_NAME "armv4"
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#define PJ_HAS_PENTIUM 0
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0
#endif /* __PJ_COMPAT_M_ARMV4_H__ */
#endif /* __PJ_COMPAT_M_ARMV4_H__ */

View File

@ -1,4 +1,3 @@
/* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
@ -34,7 +33,7 @@
*/
#ifdef PJ_DARWINOS
# ifdef __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# define WORDS_BIGENDIAN 1
# endif
#else
/* Endianness, as detected by autoconf */
@ -42,11 +41,11 @@
#endif
#ifdef WORDS_BIGENDIAN
# define PJ_IS_LITTLE_ENDIAN 0
# define PJ_IS_BIG_ENDIAN 1
# define PJ_IS_LITTLE_ENDIAN 0
# define PJ_IS_BIG_ENDIAN 1
#else
# define PJ_IS_LITTLE_ENDIAN 1
# define PJ_IS_BIG_ENDIAN 0
# define PJ_IS_LITTLE_ENDIAN 1
# define PJ_IS_BIG_ENDIAN 0
#endif
@ -54,7 +53,7 @@
#undef PJ_HAS_FLOATING_POINT
/* Deprecated */
#define PJ_HAS_PENTIUM 0
#define PJ_HAS_PENTIUM 0
#endif /* __PJ_COMPAT_M_AUTO_H__ */
#endif /* __PJ_COMPAT_M_AUTO_H__ */

Some files were not shown because too many files have changed in this diff Show More