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
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
|
2006-09-07 14:23:31 +00:00
|
|
|
SWITCH_BEGIN_EXTERN_C
|
2008-02-15 23:02:06 +00:00
|
|
|
#define switch_samples_per_frame(rate, interval) ((uint32_t)((float)rate / (1000.0f / (float)interval)))
|
2006-09-09 03:39:28 +00:00
|
|
|
#define SWITCH_SMAX 32767
|
|
|
|
#define SWITCH_SMIN -32768
|
|
|
|
#define switch_normalize_to_16bit(n) if (n > SWITCH_SMAX) n = SWITCH_SMAX / 2; else if (n < SWITCH_SMIN) n = SWITCH_SMIN / 2;
|
2008-03-27 22:46:47 +00:00
|
|
|
#define switch_codec2str(codec,buf,len) snprintf(buf, len, "%s@%uh@%ui", \
|
2007-01-28 17:37:51 +00:00
|
|
|
codec->implementation->iananame, \
|
|
|
|
codec->implementation->samples_per_second, \
|
|
|
|
codec->implementation->microseconds_per_frame / 1000)
|
2007-01-11 18:14:02 +00:00
|
|
|
#ifdef WIN32
|
2007-12-30 00:22:51 +00:00
|
|
|
#define switch_is_file_path(file) (file && (*file == '\\' || *(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR)))
|
2007-01-11 18:14:02 +00:00
|
|
|
#else
|
2007-12-30 00:22:51 +00:00
|
|
|
#define switch_is_file_path(file) (file && ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)))
|
2007-01-11 18:14:02 +00:00
|
|
|
#endif
|
2008-05-15 19:38:29 +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
|
|
|
|
*/
|
|
|
|
#define switch_strlen_zero(s) (!s || *s == '\0')
|
2008-05-15 14:49:11 +00:00
|
|
|
static inline switch_bool_t switch_is_moh(const char *s)
|
|
|
|
{
|
2008-05-15 19:38:29 +00:00
|
|
|
if (switch_strlen_zero(s) || !strcasecmp(s, "silence") || !strcasecmp(s, "indicate_hold")) {
|
2008-05-15 14:49:11 +00:00
|
|
|
return SWITCH_FALSE;
|
|
|
|
}
|
|
|
|
return SWITCH_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-06 00:30:04 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen);
|
2008-01-16 06:01:53 +00:00
|
|
|
SWITCH_DECLARE(switch_size_t) switch_b64_decode(char *in, char *out, switch_size_t olen);
|
2007-12-04 16:22:02 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len);
|
2007-10-06 00:30:04 +00:00
|
|
|
|
2008-05-27 04:30:03 +00:00
|
|
|
static inline switch_bool_t switch_is_digit_string(const char *s)
|
|
|
|
{
|
2007-03-30 14:57:06 +00:00
|
|
|
|
2008-05-27 04:30:03 +00:00
|
|
|
while (s && *s) {
|
2007-03-30 14:57:06 +00:00
|
|
|
if (*s < 48 || *s > 57) {
|
|
|
|
return SWITCH_FALSE;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-11-28 22:27:33 +00:00
|
|
|
SWITCH_DECLARE(switch_size_t) switch_fd_read_line(int fd, char *buf, switch_size_t len);
|
2007-11-26 23:41:00 +00:00
|
|
|
|
2008-05-15 14:49:11 +00:00
|
|
|
|
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") ||\
|
2007-05-10 16:56:29 +00:00
|
|
|
!strcasecmp(expr, "enabled") ||\
|
|
|
|
!strcasecmp(expr, "active") ||\
|
2008-03-26 22:14:09 +00:00
|
|
|
!strcasecmp(expr, "allow") ||\
|
2006-02-23 22:41:08 +00:00
|
|
|
atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
|
2008-07-15 18:04:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Evaluate the falsefullness of a string expression
|
|
|
|
\param expr a string expression
|
|
|
|
\return true or false
|
|
|
|
*/
|
|
|
|
#define switch_false(expr)\
|
|
|
|
(expr && ( !strcasecmp(expr, "no") ||\
|
|
|
|
!strcasecmp(expr, "off") ||\
|
|
|
|
!strcasecmp(expr, "false") ||\
|
|
|
|
!strcasecmp(expr, "disabled") ||\
|
|
|
|
!strcasecmp(expr, "inactive") ||\
|
|
|
|
!strcasecmp(expr, "disallow") ||\
|
|
|
|
!atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
|
|
|
|
|
|
|
|
|
2007-01-19 22:47:51 +00:00
|
|
|
/*!
|
|
|
|
\brief find local ip of the box
|
|
|
|
\param buf the buffer to write the ip adress found into
|
|
|
|
\param len the length of the buf
|
|
|
|
\param family the address family to return (AF_INET or AF_INET6)
|
|
|
|
\return SWITCH_STATUS_SUCCESSS for success, otherwise failure
|
|
|
|
*/
|
2008-05-27 04:30:03 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_find_local_ip(_Out_opt_bytecapcount_(len)
|
|
|
|
char *buf, _In_ int len, _In_ int family);
|
2007-01-19 19:11:44 +00:00
|
|
|
|
2007-02-08 20:16:08 +00:00
|
|
|
/*!
|
|
|
|
\brief find the char representation of an ip adress
|
|
|
|
\param buf the buffer to write the ip adress found into
|
|
|
|
\param len the length of the buf
|
2008-07-03 18:50:15 +00:00
|
|
|
\param sa the struct sockaddr * to get the adress from
|
|
|
|
\param salen the length of sa
|
2007-02-08 20:16:08 +00:00
|
|
|
\return the ip adress string
|
|
|
|
*/
|
2008-07-03 18:50:15 +00:00
|
|
|
SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief get the port number of an ip address
|
|
|
|
\param sa the struct sockaddr * to get the port from
|
|
|
|
\return the ip adress string
|
|
|
|
*/
|
|
|
|
SWITCH_DECLARE(unsigned short) get_port(struct sockaddr *sa);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief flags to be used with switch_build_uri()
|
|
|
|
*/
|
|
|
|
enum switch_uri_flags {
|
|
|
|
SWITCH_URI_NUMERIC_HOST = 1,
|
|
|
|
SWITCH_URI_NUMERIC_PORT = 2,
|
|
|
|
SWITCH_URI_NO_SCOPE = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief build a URI string from components
|
|
|
|
\param uri output string
|
|
|
|
\param size maximum size of output string (including trailing null)
|
|
|
|
\param scheme URI scheme
|
|
|
|
\param user user part or null if none
|
|
|
|
\param sa host address
|
|
|
|
\param flags logical OR-ed combination of flags from \ref switch_uri_flags
|
|
|
|
\return number of characters printed (not including the trailing null)
|
|
|
|
*/
|
|
|
|
SWITCH_DECLARE(int) switch_build_uri(char *uri,
|
|
|
|
switch_size_t size,
|
|
|
|
const char *scheme,
|
|
|
|
const char *user,
|
|
|
|
const switch_sockaddr_t *sa,
|
|
|
|
int flags);
|
2007-02-08 20:16:08 +00:00
|
|
|
|
2006-08-29 20:27:43 +00:00
|
|
|
#define SWITCH_STATUS_IS_BREAK(x) (x == SWITCH_STATUS_BREAK || x == 730035 || x == 35)
|
2006-08-11 15:25:49 +00:00
|
|
|
|
2006-02-26 00:12:17 +00:00
|
|
|
/*!
|
|
|
|
\brief Return a printable name of a switch_priority_t
|
|
|
|
\param priority the priority to get the name of
|
|
|
|
\return the printable form of the priority
|
|
|
|
*/
|
2007-05-12 14:48:14 +00:00
|
|
|
SWITCH_DECLARE(const char *) switch_priority_name(switch_priority_t priority);
|
2006-02-23 22:41:08 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\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
|
2006-02-24 22:27:10 +00:00
|
|
|
\param key the charecter to encode
|
2006-02-23 22:41:08 +00:00
|
|
|
\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-05-04 17:51:53 +00:00
|
|
|
/*!
|
|
|
|
\brief determine if a character is a valid DTMF key
|
|
|
|
\param key the key to test
|
|
|
|
\return TRUE or FALSE
|
|
|
|
*/
|
2007-02-08 01:19:35 +00:00
|
|
|
#define is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119)
|
2006-05-04 17:51:53 +00:00
|
|
|
|
2008-05-22 15:24:12 +00:00
|
|
|
#define end_of(_s) *(*_s == '\0' ? _s : _s + strlen(_s) - 1)
|
|
|
|
#define end_of_p(_s) (*_s == '\0' ? _s : _s + strlen(_s) - 1)
|
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
|
|
|
|
2006-06-22 23:38:44 +00:00
|
|
|
/*!
|
|
|
|
\brief Set a flag on an arbitrary object while locked
|
|
|
|
\param obj the object to set the flags on
|
|
|
|
\param flag the or'd list of flags to set
|
|
|
|
*/
|
2006-06-23 16:59:47 +00:00
|
|
|
#define switch_set_flag_locked(obj, flag) assert(obj->flag_mutex != NULL);\
|
|
|
|
switch_mutex_lock(obj->flag_mutex);\
|
|
|
|
(obj)->flags |= (flag);\
|
|
|
|
switch_mutex_unlock(obj->flag_mutex);
|
2006-06-22 23:38:44 +00:00
|
|
|
|
2006-01-05 21:03:22 +00:00
|
|
|
/*!
|
|
|
|
\brief Clear a flag on an arbitrary object
|
|
|
|
\param obj the object to test
|
2006-06-22 23:38:44 +00:00
|
|
|
\param flag the or'd list of flags to clear
|
|
|
|
*/
|
|
|
|
#define switch_clear_flag_locked(obj, flag) switch_mutex_lock(obj->flag_mutex); (obj)->flags &= ~(flag); switch_mutex_unlock(obj->flag_mutex);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Clear a flag on an arbitrary object while locked
|
|
|
|
\param obj the object to test
|
2006-01-05 21:03:22 +00:00
|
|
|
\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
|
|
|
|
2007-06-05 15:39:56 +00:00
|
|
|
#define switch_set_string(_dst, _src) switch_copy_string(_dst, _src, sizeof(_dst))
|
2006-05-12 15:33:49 +00:00
|
|
|
|
2008-05-27 04:30:03 +00:00
|
|
|
static inline char *switch_clean_string(char *s)
|
2007-06-07 17:02:59 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
for (p = s; p && *p; p++) {
|
|
|
|
uint8_t x = (uint8_t) *p;
|
2007-08-03 16:26:32 +00:00
|
|
|
if ((x < 32 || x > 127) && x != '\n' && x != '\r') {
|
2007-06-07 17:02:59 +00:00
|
|
|
*p = ' ';
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 16:50:51 +00:00
|
|
|
|
|
|
|
return s;
|
2007-06-05 16:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-12 15:33:49 +00:00
|
|
|
/*!
|
2006-10-07 22:19:24 +00:00
|
|
|
\brief Free a pointer and set it to NULL unless it already is NULL
|
2006-05-12 15:33:49 +00:00
|
|
|
\param it the pointer
|
|
|
|
*/
|
|
|
|
#define switch_safe_free(it) if (it) {free(it);it=NULL;}
|
|
|
|
|
2007-03-30 16:41:12 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Test if one string is inside another with extra case checking
|
|
|
|
\param s the inner string
|
|
|
|
\param q the big string
|
|
|
|
\return SWITCH_TRUE or SWITCH_FALSE
|
|
|
|
*/
|
|
|
|
static inline switch_bool_t switch_strstr(char *s, char *q)
|
|
|
|
{
|
|
|
|
char *p, *S = NULL, *Q = NULL;
|
|
|
|
switch_bool_t tf = SWITCH_FALSE;
|
|
|
|
|
2007-12-11 10:47:46 +00:00
|
|
|
if (!s || !q) {
|
|
|
|
return SWITCH_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-30 16:41:12 +00:00
|
|
|
if (strstr(s, q)) {
|
|
|
|
return SWITCH_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
S = strdup(s);
|
2008-05-27 04:30:03 +00:00
|
|
|
|
2007-03-30 16:41:12 +00:00
|
|
|
assert(S != NULL);
|
|
|
|
|
|
|
|
for (p = S; p && *p; p++) {
|
2008-05-27 04:30:03 +00:00
|
|
|
*p = (char) toupper(*p);
|
2007-03-30 16:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(S, q)) {
|
|
|
|
tf = SWITCH_TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q = strdup(q);
|
|
|
|
assert(Q != NULL);
|
|
|
|
|
|
|
|
for (p = Q; p && *p; p++) {
|
2008-05-27 04:30:03 +00:00
|
|
|
*p = (char) toupper(*p);
|
2007-03-30 16:41:12 +00:00
|
|
|
}
|
2008-05-27 04:30:03 +00:00
|
|
|
|
2007-03-30 16:41:12 +00:00
|
|
|
if (strstr(s, Q)) {
|
|
|
|
tf = SWITCH_TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(S, Q)) {
|
|
|
|
tf = SWITCH_TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-05-27 04:30:03 +00:00
|
|
|
|
|
|
|
done:
|
2007-03-30 16:41:12 +00:00
|
|
|
switch_safe_free(S);
|
|
|
|
switch_safe_free(Q);
|
|
|
|
|
|
|
|
return tf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-12 18:13:14 +00:00
|
|
|
/*!
|
|
|
|
\brief Make a null string a blank string instead
|
|
|
|
\param s the string to test
|
|
|
|
\return the original string or blank string.
|
|
|
|
*/
|
|
|
|
#define switch_str_nil(s) (s ? s : "")
|
|
|
|
|
2006-01-05 21:03:22 +00:00
|
|
|
/*!
|
|
|
|
\brief Wait a desired number of microseconds and yield the CPU
|
|
|
|
*/
|
2007-03-09 20:44:13 +00:00
|
|
|
#define switch_yield(ms) switch_sleep(ms);
|
2006-01-05 21:03:22 +00:00
|
|
|
|
2007-01-03 00:21:17 +00:00
|
|
|
/*!
|
|
|
|
\brief Converts a string representation of a date into a switch_time_t
|
|
|
|
\param in the string
|
|
|
|
\return the epoch time in usec
|
|
|
|
*/
|
2007-05-12 14:48:14 +00:00
|
|
|
SWITCH_DECLARE(switch_time_t) switch_str_time(const char *in);
|
2007-01-03 00:21:17 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2006-05-12 19:28:21 +00:00
|
|
|
#define SWITCH_DECLARE_GLOBAL_STRING_FUNC(fname, vname) static void fname(char *string) { if (!string) return;\
|
2007-10-17 14:59:17 +00:00
|
|
|
if (vname) {free(vname); vname = NULL;}vname = strdup(string);} static void fname(char *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
|
|
|
|
*/
|
2008-01-17 05:52:50 +00:00
|
|
|
SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char **array, unsigned int arraylen);
|
2006-01-05 21:03:22 +00:00
|
|
|
|
2007-11-08 23:46:26 +00:00
|
|
|
SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str);
|
|
|
|
SWITCH_DECLARE(char *) switch_strip_spaces(const char *str);
|
2007-11-13 03:47:07 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_separate_paren_args(char *str);
|
2007-11-15 16:22:18 +00:00
|
|
|
SWITCH_DECLARE(const char *) switch_stristr(const char *instr, const char *str);
|
2007-11-08 23:46:26 +00:00
|
|
|
SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip);
|
2007-11-09 15:26:32 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_replace_char(char *str, char from, char to, switch_bool_t dup);
|
2007-11-09 19:25:46 +00:00
|
|
|
SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len);
|
2007-10-16 14:24:02 +00:00
|
|
|
|
2006-10-06 22:39:49 +00:00
|
|
|
/*!
|
|
|
|
\brief Escape a string by prefixing a list of characters with an escape character
|
|
|
|
\param pool a memory pool to use
|
|
|
|
\param in the string
|
|
|
|
\param delim the list of characters to escape
|
|
|
|
\param esc the escape character
|
|
|
|
\return the escaped string
|
|
|
|
*/
|
2007-05-12 14:48:14 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_escape_char(switch_memory_pool_t *pool, char *in, const char *delim, char esc);
|
2006-10-06 22:39:49 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2008-05-27 04:30:03 +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
|
|
|
|
*/
|
2007-02-13 21:03:06 +00:00
|
|
|
SWITCH_DECLARE(const char *) switch_cut_path(const char *in);
|
2006-01-02 17:28:59 +00:00
|
|
|
|
2006-04-14 16:45:31 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_string_replace(const char *string, const char *search, const char *replace);
|
2007-03-30 00:13:31 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t string_len, const char *search, size_t search_len);
|
2005-11-19 20:07:43 +00:00
|
|
|
|
2007-02-06 19:15:26 +00:00
|
|
|
#define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK)
|
2007-11-01 11:28:26 +00:00
|
|
|
SWITCH_DECLARE(size_t) switch_url_encode(const char *url, char *buf, size_t len);
|
2006-05-10 15:47:54 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_url_decode(char *s);
|
2007-11-26 17:43:42 +00:00
|
|
|
SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *from, const char *headers, const char *body, const char *file);
|
2007-12-10 21:58:40 +00:00
|
|
|
SWITCH_DECLARE(char *) switch_find_end_paren(const char *s, char open, char close);
|
2008-03-26 22:14:09 +00:00
|
|
|
|
|
|
|
SWITCH_DECLARE(int) switch_parse_cidr(const char *string, uint32_t *ip, uint32_t *mask, uint32_t *bitp);
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, switch_bool_t default_type, switch_memory_pool_t *pool);
|
2008-07-16 17:44:54 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_network_list_add_cidr_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token);
|
|
|
|
#define switch_network_list_add_cidr(_list, _cidr_str, _ok) switch_network_list_add_cidr_token(_list, _cidr_str, _ok, NULL)
|
|
|
|
|
|
|
|
|
2008-03-26 22:14:09 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_network_list_add_host_mask(switch_network_list_t *list, const char *host, const char *mask_str, switch_bool_t ok);
|
2008-07-16 17:44:54 +00:00
|
|
|
SWITCH_DECLARE(switch_bool_t) switch_network_list_validate_ip_token(switch_network_list_t *list, uint32_t ip, const char **token);
|
|
|
|
#define switch_network_list_validate_ip(_list, _ip) switch_network_list_validate_ip_token(_list, _ip, NULL);
|
|
|
|
|
2008-04-04 15:17:17 +00:00
|
|
|
#define switch_test_subnet(_ip, _net, _mask) (_mask ? ((_net & _mask) == (_ip & _mask)) : _net ? _net == _ip : 1)
|
2008-03-26 22:14:09 +00:00
|
|
|
|
2008-07-16 17:44:54 +00:00
|
|
|
int switch_inet_pton(int af, const char *src, void *dst);
|
2007-03-29 17:37:42 +00:00
|
|
|
|
|
|
|
/* malloc or DIE macros */
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
|
|
|
|
#define switch_zmalloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), memset(ptr, 0, len))
|
|
|
|
#else
|
2007-12-11 20:25:15 +00:00
|
|
|
#if (_MSC_VER >= 1500) // VC9+
|
|
|
|
#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr);__analysis_assume( ptr )
|
|
|
|
#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len));__analysis_assume( ptr )
|
|
|
|
#else
|
2007-03-29 17:37:42 +00:00
|
|
|
#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr)
|
|
|
|
#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len))
|
|
|
|
#endif
|
2007-12-11 20:25:15 +00:00
|
|
|
#endif
|
2007-03-29 17:37:42 +00:00
|
|
|
|
2006-09-07 15:15:39 +00:00
|
|
|
SWITCH_END_EXTERN_C
|
2005-11-19 20:07:43 +00:00
|
|
|
#endif
|
2006-11-27 22:30:48 +00:00
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2006-11-27 22:30:48 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2008-07-03 19:12:26 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
2006-11-27 22:30:48 +00:00
|
|
|
*/
|