2005-11-19 20:07:43 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_utils.h -- Compatability and Helper Code
|
|
|
|
*
|
|
|
|
*/
|
2006-01-02 05:00:28 +00:00
|
|
|
/*! \file switch_utils.h
|
|
|
|
\brief Compatability and Helper Code
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
Just a miscelaneaous set of general utility/helper functions.
|
|
|
|
|
2006-01-01 15:23:12 +00:00
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
#ifndef SWITCH_UTILS_H
|
|
|
|
#define SWITCH_UTILS_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
|
2006-02-23 22:41:08 +00:00
|
|
|
|
|
|
|
|
2005-11-19 20:07:43 +00:00
|
|
|
#ifndef snprintf
|
|
|
|
#define snprintf apr_snprintf
|
|
|
|
#endif
|
|
|
|
#ifndef vsnprintf
|
|
|
|
#define vsnprintf apr_vsnprintf
|
|
|
|
#endif
|
|
|
|
|
2006-02-23 22:41:08 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Evaluate the truthfullness of a string expression
|
|
|
|
\param expr a string expression
|
|
|
|
\return true or false
|
|
|
|
*/
|
|
|
|
#define switch_true(expr)\
|
|
|
|
(expr && ( !strcasecmp(expr, "yes") ||\
|
|
|
|
!strcasecmp(expr, "on") ||\
|
|
|
|
!strcasecmp(expr, "true") ||\
|
|
|
|
atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Return the RFC2833 character based on an event id
|
|
|
|
\param event the event id to convert
|
|
|
|
\return the character represented by the event or null for an invalid event
|
|
|
|
*/
|
|
|
|
SWITCH_DECLARE(char) switch_rfc2833_to_char(int event);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Return the RFC2833 event based on an key character
|
|
|
|
\param the charecter to encode
|
|
|
|
\return the event id for the specified character or -1 on an invalid input
|
|
|
|
*/
|
2006-02-24 00:02:02 +00:00
|
|
|
SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key);
|
2006-02-23 22:41:08 +00:00
|
|
|
|
2006-01-05 21:03:22 +00:00
|
|
|
/*!
|
|
|
|
\brief Duplicate a string
|
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
#define switch_copy_string apr_cpystrn
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Test for the existance of a flag on an arbitary object
|
|
|
|
\param obj the object to test
|
|
|
|
\param flag the or'd list of flags to test
|
|
|
|
\return true value if the object has the flags defined
|
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
#define switch_test_flag(obj, flag) ((obj)->flags & flag)
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Set a flag on an arbitrary object
|
|
|
|
\param obj the object to set the flags on
|
|
|
|
\param flag the or'd list of flags to set
|
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
#define switch_set_flag(obj, flag) (obj)->flags |= (flag)
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Clear a flag on an arbitrary object
|
|
|
|
\param obj the object to test
|
|
|
|
\param flag the or'd list of flags to clear
|
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
#define switch_clear_flag(obj, flag) (obj)->flags &= ~(flag)
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Copy flags from one arbitrary object to another
|
|
|
|
\param dest the object to copy the flags to
|
|
|
|
\param src the object to copy the flags from
|
|
|
|
\param flags the flags to copy
|
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
#define switch_copy_flags(dest, src, flags) (dest)->flags &= ~(flags); (dest)->flags |= ((src)->flags & (flags))
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Test for NULL or zero length string
|
|
|
|
\param s the string to test
|
|
|
|
\return true value if the string is NULL or zero length
|
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
#define switch_strlen_zero(s) (s && *s != '\0') ? 0 : 1
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Wait a desired number of microseconds and yield the CPU
|
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
#define switch_yield(ms) apr_sleep(ms * 10); apr_thread_yield();
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Declares a function designed to set a dymaic global string
|
|
|
|
\param fname the function name to declare
|
|
|
|
\param vname the name of the global pointer to modify with the new function
|
|
|
|
*/
|
2005-12-09 19:23:04 +00:00
|
|
|
#define SWITCH_DECLARE_GLOBAL_STRING_FUNC(fname, vname) static void fname(char *string) { if (vname) {free(vname); vname = NULL;}vname = strdup(string);}
|
2005-11-19 20:07:43 +00:00
|
|
|
|
2006-01-05 21:03:22 +00:00
|
|
|
/*!
|
|
|
|
\brief Separate a string into an array based on a character delimeter
|
|
|
|
\param buf the string to parse
|
|
|
|
\param delim the character delimeter
|
|
|
|
\param array the array to split the values into
|
|
|
|
\param arraylen the max number of elements in the array
|
|
|
|
\return the number of elements added to the array
|
|
|
|
*/
|
2005-12-06 17:18:56 +00:00
|
|
|
SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char **array, int arraylen);
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Create a set of file descriptors to poll
|
|
|
|
\param poll the polfd to create
|
|
|
|
\param sock the socket to add
|
|
|
|
\param flags the flags to modify the behaviour
|
|
|
|
\param pool the memory pool to use
|
|
|
|
\return SWITCH_STATUS_SUCCESS when successful
|
|
|
|
*/
|
2006-02-20 00:23:25 +00:00
|
|
|
SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock, switch_int16_t flags, switch_memory_pool *pool);
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Wait for a socket
|
|
|
|
\param poll the pollfd to wait on
|
|
|
|
\param ms the number of milliseconds to wait
|
|
|
|
\return the requested condition
|
|
|
|
*/
|
2005-11-19 20:07:43 +00:00
|
|
|
SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms);
|
2006-01-05 21:03:22 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Create a pointer to the file name in a given file path eliminating the directory name
|
|
|
|
\return the pointer to the next character after the final / or \\ characters
|
|
|
|
*/
|
2005-12-23 21:09:36 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_cut_path(char *in);
|
2006-01-02 17:28:59 +00:00
|
|
|
|
2005-11-19 20:07:43 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|