mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 20:51:58 +00:00
add wrapper code to fully encapsulate apr, apr-utils, pcre, and sqlite. fully use switch_ namespace in modules, create our own format and type defines. follow up commit for unix autotools coming soon after this. PLEASE NOTE: you will NEED to do a make megaclean and run configure again after this update (and the following commit) or it will not build.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4494 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
+20
-4
@@ -51,12 +51,29 @@
|
||||
#define FREESWITCH_MIB ".1.3.6.1.4.1." FREESWITCH_PEN
|
||||
#define FREESWITCH_ITAD "543"
|
||||
|
||||
#include <switch_platform.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include <setjmp.h>
|
||||
#include <switch_apr.h>
|
||||
#include <switch_sqlite.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <switch_platform.h>
|
||||
#include <switch_types.h>
|
||||
#include <switch_apr.h>
|
||||
|
||||
#include <switch_core_db.h>
|
||||
#include <switch_regex.h>
|
||||
#include <switch_core.h>
|
||||
#include <switch_loadable_module.h>
|
||||
#include <switch_console.h>
|
||||
@@ -74,7 +91,6 @@
|
||||
#include <switch_stun.h>
|
||||
#include <switch_log.h>
|
||||
#include <switch_xml.h>
|
||||
#include <pcre.h>
|
||||
|
||||
|
||||
/** \mainpage FreeSWITCH
|
||||
|
||||
@@ -1,131 +1,18 @@
|
||||
/* src/include/switch_am_config.h.in. Generated from configure.in by autoheader. */
|
||||
#ifndef SWITCH_AM_CONFIG_H
|
||||
#define SWITCH_AM_CONFIG_H
|
||||
|
||||
/* Enable extra debugging. */
|
||||
#undef DEBUG
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_DIRENT_H
|
||||
#define SWITCH_INT_16 @short_value@
|
||||
#define SWITCH_INT_32 @int_value@
|
||||
#define SWITCH_INT_64 @long_value@
|
||||
#define SWITCH_SIZE_T @size_t_value@
|
||||
#define SWITCH_SSIZE_T @ssize_t_value@
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
#define SWITCH_SIZEOF_VOIDP @voidp_size@
|
||||
|
||||
/* Define to 1 if you have the `gethostname' function. */
|
||||
#undef HAVE_GETHOSTNAME
|
||||
@ssize_t_fmt@
|
||||
@size_t_fmt@
|
||||
@int64_t_fmt@
|
||||
@uint64_t_fmt@
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#undef HAVE_MALLOC
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `mlock' function. */
|
||||
#undef HAVE_MLOCK
|
||||
|
||||
/* Define to 1 if you have the `mlockall' function. */
|
||||
#undef HAVE_MLOCKALL
|
||||
|
||||
/* Define to 1 if you have the `mmap' function. */
|
||||
#undef HAVE_MMAP
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
#undef HAVE_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strftime' function. */
|
||||
#undef HAVE_STRFTIME
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_DIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the `usleep' function. */
|
||||
#undef HAVE_USLEEP
|
||||
|
||||
/* Define to 1 if you have the `vasprintf' function. */
|
||||
#undef HAVE_VASPRINTF
|
||||
|
||||
/* Enable Optimization. */
|
||||
#undef OPTIMZER
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Little Endian */
|
||||
#undef SWITCH_BYTE_ORDER
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
|
||||
#undef TM_IN_SYS_TIME
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* sunpro is bad at inline */
|
||||
#undef __inline__
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
#undef malloc
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
||||
+698
-1012
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,378 @@
|
||||
/*
|
||||
* 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>
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
*
|
||||
* switch_core_db.h -- Sqlite wrapper and extensions Header
|
||||
*
|
||||
*/
|
||||
/*! \file switch_core_db.h
|
||||
\brief Core DB Header
|
||||
*/
|
||||
#ifndef SWITCH_CORE_DB_H
|
||||
#define SWITCH_CORE_DB_H
|
||||
|
||||
SWITCH_BEGIN_EXTERN_C
|
||||
|
||||
/**
|
||||
* @defgroup switch_sqlite_top Brought To You By SQLite
|
||||
* @ingroup FREESWITCH
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup switch_core_db Database Routines
|
||||
* @ingroup switch_sqlite_top
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Each open database is represented by an instance of the
|
||||
* following opaque structure.
|
||||
*/
|
||||
|
||||
typedef struct sqlite3 switch_core_db_t;
|
||||
typedef struct sqlite3_stmt switch_core_db_stmt_t;
|
||||
|
||||
typedef int (*switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames);
|
||||
|
||||
/**
|
||||
* A function to close the database.
|
||||
*
|
||||
* Call this function with a pointer to a structure that was previously
|
||||
* returned from switch_core_db_open() and the corresponding database will by closed.
|
||||
*
|
||||
* All SQL statements prepared using switch_core_db_prepare()
|
||||
* must be deallocated using switch_core_db_finalize() before
|
||||
* this routine is called. Otherwise, SWITCH_CORE_DB_BUSY is returned and the
|
||||
* database connection remains open.
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_core_db_close(switch_core_db_t *db);
|
||||
|
||||
/**
|
||||
* Open the database file "filename". The "filename" is UTF-8
|
||||
* encoded. A switch_core_db_t* handle is returned in *Db, even
|
||||
* if an error occurs. If the database is opened (or created) successfully,
|
||||
* then SWITCH_CORE_DB_OK is returned. Otherwise an error code is returned. The
|
||||
* switch_core_db_errmsg() routine can be used to obtain
|
||||
* an English language description of the error.
|
||||
*
|
||||
* If the database file does not exist, then a new database is created.
|
||||
* The encoding for the database is UTF-8.
|
||||
*
|
||||
* Whether or not an error occurs when it is opened, resources associated
|
||||
* with the switch_core_db_t* handle should be released by passing it to
|
||||
* switch_core_db_close() when it is no longer required.
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_core_db_open(const char *filename, switch_core_db_t **ppDb);
|
||||
|
||||
/**
|
||||
* The next group of routines returns information about the information
|
||||
* in a single column of the current result row of a query. In every
|
||||
* case the first parameter is a pointer to the SQL statement that is being
|
||||
* executed (the switch_core_db_stmt_t* that was returned from switch_core_db_prepare()) and
|
||||
* the second argument is the index of the column for which information
|
||||
* should be returned. iCol is zero-indexed. The left-most column as an
|
||||
* index of 0.
|
||||
*
|
||||
* If the SQL statement is not currently point to a valid row, or if the
|
||||
* the colulmn index is out of range, the result is undefined.
|
||||
*
|
||||
* These routines attempt to convert the value where appropriate. For
|
||||
* example, if the internal representation is FLOAT and a text result
|
||||
* is requested, sprintf() is used internally to do the conversion
|
||||
* automatically. The following table details the conversions that
|
||||
* are applied:
|
||||
*
|
||||
* Internal Type Requested Type Conversion
|
||||
* ------------- -------------- --------------------------
|
||||
* NULL INTEGER Result is 0
|
||||
* NULL FLOAT Result is 0.0
|
||||
* NULL TEXT Result is an empty string
|
||||
* NULL BLOB Result is a zero-length BLOB
|
||||
* INTEGER FLOAT Convert from integer to float
|
||||
* INTEGER TEXT ASCII rendering of the integer
|
||||
* INTEGER BLOB Same as for INTEGER->TEXT
|
||||
* FLOAT INTEGER Convert from float to integer
|
||||
* FLOAT TEXT ASCII rendering of the float
|
||||
* FLOAT BLOB Same as FLOAT->TEXT
|
||||
* TEXT INTEGER Use atoi()
|
||||
* TEXT FLOAT Use atof()
|
||||
* TEXT BLOB No change
|
||||
* BLOB INTEGER Convert to TEXT then use atoi()
|
||||
* BLOB FLOAT Convert to TEXT then use atof()
|
||||
* BLOB TEXT Add a "\000" terminator if needed
|
||||
*
|
||||
* Return the value as UTF-8 text.
|
||||
*/
|
||||
SWITCH_DECLARE(const unsigned char *)switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol);
|
||||
|
||||
/**
|
||||
* The first parameter is a compiled SQL statement. This function returns
|
||||
* the column heading for the Nth column of that statement, where N is the
|
||||
* second function parameter. The string returned is UTF-8.
|
||||
*/
|
||||
SWITCH_DECLARE(const char *)switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N);
|
||||
|
||||
/**
|
||||
* Return the number of columns in the result set returned by the compiled
|
||||
* SQL statement. This routine returns 0 if pStmt is an SQL statement
|
||||
* that does not return data (for example an UPDATE).
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_core_db_column_count(switch_core_db_stmt_t *pStmt);
|
||||
|
||||
/**
|
||||
* Return a pointer to a UTF-8 encoded string describing in english the
|
||||
* error condition for the most recent switch_core_db_* API call. The returned
|
||||
* string is always terminated by an 0x00 byte.
|
||||
*
|
||||
* The string "not an error" is returned when the most recent API call was
|
||||
* successful.
|
||||
*/
|
||||
SWITCH_DECLARE(const char *)switch_core_db_errmsg(switch_core_db_t *db);
|
||||
|
||||
/**
|
||||
* A function to executes one or more statements of SQL.
|
||||
*
|
||||
* If one or more of the SQL statements are queries, then
|
||||
* the callback function specified by the 3rd parameter is
|
||||
* invoked once for each row of the query result. This callback
|
||||
* should normally return 0. If the callback returns a non-zero
|
||||
* value then the query is aborted, all subsequent SQL statements
|
||||
* are skipped and the switch_core_db_exec() function returns the SWITCH_CORE_DB_ABORT.
|
||||
*
|
||||
* The 4th parameter is an arbitrary pointer that is passed
|
||||
* to the callback function as its first parameter.
|
||||
*
|
||||
* The 2nd parameter to the callback function is the number of
|
||||
* columns in the query result. The 3rd parameter to the callback
|
||||
* is an array of strings holding the values for each column.
|
||||
* The 4th parameter to the callback is an array of strings holding
|
||||
* the names of each column.
|
||||
*
|
||||
* The callback function may be NULL, even for queries. A NULL
|
||||
* callback is not an error. It just means that no callback
|
||||
* will be invoked.
|
||||
*
|
||||
* If an error occurs while parsing or evaluating the SQL (but
|
||||
* not while executing the callback) then an appropriate error
|
||||
* message is written into memory obtained from malloc() and
|
||||
* *errmsg is made to point to that message. The calling function
|
||||
* is responsible for freeing the memory that holds the error
|
||||
* message. Use switch_core_db_free() for this. If errmsg==NULL,
|
||||
* then no error message is ever written.
|
||||
*
|
||||
* The return value is is SWITCH_CORE_DB_OK if there are no errors and
|
||||
* some other return code if there is an error. The particular
|
||||
* return value depends on the type of error.
|
||||
*
|
||||
* If the query could not be executed because a database file is
|
||||
* locked or busy, then this function returns SWITCH_CORE_DB_BUSY. (This
|
||||
* behavior can be modified somewhat using the sswitch_core_db_busy_handler()
|
||||
* and switch_core_db_busy_timeout() functions below.)
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db,
|
||||
const char *sql,
|
||||
switch_core_db_callback_func_t callback,
|
||||
void *data,
|
||||
char **errmsg);
|
||||
|
||||
/**
|
||||
* This function is called to delete a compiled
|
||||
* SQL statement obtained by a previous call to switch_core_db_prepare().
|
||||
* If the statement was executed successfully, or
|
||||
* not executed at all, then SWITCH_CORE_DB_OK is returned. If execution of the
|
||||
* statement failed then an error code is returned.
|
||||
*
|
||||
* This routine can be called at any point during the execution of the
|
||||
* virtual machine. If the virtual machine has not completed execution
|
||||
* when this routine is called, that is like encountering an error or
|
||||
* an interrupt. (See switch_core_db_interrupt().) Incomplete updates may be
|
||||
* rolled back and transactions cancelled, depending on the circumstances,
|
||||
* and the result code returned will be SWITCH_CORE_DB_ABORT.
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_core_db_finalize(switch_core_db_stmt_t *pStmt);
|
||||
|
||||
/**
|
||||
* To execute an SQL query, it must first be compiled into a byte-code
|
||||
* program using the following routine.
|
||||
*
|
||||
* The first parameter "db" is an SQLite database handle. The second
|
||||
* parameter "zSql" is the statement to be compiled, encoded as
|
||||
* UTF-8. If the next parameter, "nBytes", is less
|
||||
* than zero, then zSql is read up to the first nul terminator. If
|
||||
* "nBytes" is not less than zero, then it is the length of the string zSql
|
||||
* in bytes (not characters).
|
||||
*
|
||||
* *pzTail is made to point to the first byte past the end of the first
|
||||
* SQL statement in zSql. This routine only compiles the first statement
|
||||
* in zSql, so *pzTail is left pointing to what remains uncompiled.
|
||||
*
|
||||
* *ppStmt is left pointing to a compiled SQL statement that can be
|
||||
* executed using switch_core_db_step(). Or if there is an error, *ppStmt may be
|
||||
* set to NULL. If the input text contained no SQL (if the input is and
|
||||
* empty string or a comment) then *ppStmt is set to NULL.
|
||||
*
|
||||
* On success, SWITCH_CORE_DB_OK is returned. Otherwise an error code is returned.
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_core_db_prepare(switch_core_db_t *db,
|
||||
const char *zSql,
|
||||
int nBytes,
|
||||
switch_core_db_stmt_t **ppStmt,
|
||||
const char **pzTail);
|
||||
|
||||
/**
|
||||
* After an SQL query has been compiled with a call to either
|
||||
* switch_core_db_prepare(), then this function must be
|
||||
* called one or more times to execute the statement.
|
||||
*
|
||||
* The return value will be either SWITCH_CORE_DB_BUSY, SWITCH_CORE_DB_DONE,
|
||||
* SWITCH_CORE_DB_ROW, SWITCH_CORE_DB_ERROR, or SWITCH_CORE_DB_MISUSE.
|
||||
*
|
||||
* SWITCH_CORE_DB_BUSY means that the database engine attempted to open
|
||||
* a locked database and there is no busy callback registered.
|
||||
* Call switch_core_db_step() again to retry the open.
|
||||
*
|
||||
* SWITCH_CORE_DB_DONE means that the statement has finished executing
|
||||
* successfully. switch_core_db_step() should not be called again on this virtual
|
||||
* machine.
|
||||
*
|
||||
* If the SQL statement being executed returns any data, then
|
||||
* SWITCH_CORE_DB_ROW is returned each time a new row of data is ready
|
||||
* for processing by the caller. The values may be accessed using
|
||||
* the switch_core_db_column_*() functions described below. switch_core_db_step()
|
||||
* is called again to retrieve the next row of data.
|
||||
*
|
||||
* SWITCH_CORE_DB_ERROR means that a run-time error (such as a constraint
|
||||
* violation) has occurred. switch_core_db_step() should not be called again on
|
||||
* the VM. More information may be found by calling switch_core_db_errmsg().
|
||||
*
|
||||
* SWITCH_CORE_DB_MISUSE means that the this routine was called inappropriately.
|
||||
* Perhaps it was called on a virtual machine that had already been
|
||||
* finalized or on one that had previously returned SWITCH_CORE_DB_ERROR or
|
||||
* SWITCH_CORE_DB_DONE. Or it could be the case the the same database connection
|
||||
* is being used simulataneously by two or more threads.
|
||||
*/
|
||||
SWITCH_DECLARE(int) switch_core_db_step(switch_core_db_stmt_t *stmt);
|
||||
|
||||
/**
|
||||
* Call this routine to free the memory that switch_core_db_get_table() allocated.
|
||||
*/
|
||||
SWITCH_DECLARE(void) switch_core_db_free(char *z);
|
||||
|
||||
/** Return values for switch_core_db_exec() and switch_core_db_step()*/
|
||||
#define SWITCH_CORE_DB_OK 0 /* Successful result */
|
||||
/* beginning-of-error-codes */
|
||||
#define SWITCH_CORE_DB_ERROR 1 /* SQL error or missing database */
|
||||
#define SWITCH_CORE_DB_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */
|
||||
#define SWITCH_CORE_DB_PERM 3 /* Access permission denied */
|
||||
#define SWITCH_CORE_DB_ABORT 4 /* Callback routine requested an abort */
|
||||
#define SWITCH_CORE_DB_BUSY 5 /* The database file is locked */
|
||||
#define SWITCH_CORE_DB_LOCKED 6 /* A table in the database is locked */
|
||||
#define SWITCH_CORE_DB_NOMEM 7 /* A malloc() failed */
|
||||
#define SWITCH_CORE_DB_READONLY 8 /* Attempt to write a readonly database */
|
||||
#define SWITCH_CORE_DB_INTERRUPT 9 /* Operation terminated by switch_core_db_interrupt()*/
|
||||
#define SWITCH_CORE_DB_IOERR 10 /* Some kind of disk I/O error occurred */
|
||||
#define SWITCH_CORE_DB_CORRUPT 11 /* The database disk image is malformed */
|
||||
#define SWITCH_CORE_DB_NOTFOUND 12 /* NOT USED. Table or record not found */
|
||||
#define SWITCH_CORE_DB_FULL 13 /* Insertion failed because database is full */
|
||||
#define SWITCH_CORE_DB_CANTOPEN 14 /* Unable to open the database file */
|
||||
#define SWITCH_CORE_DB_PROTOCOL 15 /* Database lock protocol error */
|
||||
#define SWITCH_CORE_DB_EMPTY 16 /* Database is empty */
|
||||
#define SWITCH_CORE_DB_SCHEMA 17 /* The database schema changed */
|
||||
#define SWITCH_CORE_DB_TOOBIG 18 /* NOT USED. Too much data for one row */
|
||||
#define SWITCH_CORE_DB_CONSTRAINT 19 /* Abort due to contraint violation */
|
||||
#define SWITCH_CORE_DB_MISMATCH 20 /* Data type mismatch */
|
||||
#define SWITCH_CORE_DB_MISUSE 21 /* Library used incorrectly */
|
||||
#define SWITCH_CORE_DB_NOLFS 22 /* Uses OS features not supported on host */
|
||||
#define SWITCH_CORE_DB_AUTH 23 /* Authorization denied */
|
||||
#define SWITCH_CORE_DB_FORMAT 24 /* Auxiliary database format error */
|
||||
#define SWITCH_CORE_DB_RANGE 25 /* 2nd parameter to switch_core_db_bind out of range */
|
||||
#define SWITCH_CORE_DB_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SWITCH_CORE_DB_ROW 100 /* switch_core_db_step() has another row ready */
|
||||
#define SWITCH_CORE_DB_DONE 101 /* switch_core_db_step() has finished executing */
|
||||
/* end-of-error-codes */
|
||||
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
/**
|
||||
* This routine is a variant of the "sprintf()" from the
|
||||
* standard C library. The resulting string is written into memory
|
||||
* obtained from malloc() so that there is never a possiblity of buffer
|
||||
* overflow. This routine also implement some additional formatting
|
||||
* options that are useful for constructing SQL statements.
|
||||
*
|
||||
* The strings returned by this routine should be freed by calling
|
||||
* switch_core_db_free().
|
||||
*
|
||||
* All of the usual printf formatting options apply. In addition, there
|
||||
* is a "%q" option. %q works like %s in that it substitutes a null-terminated
|
||||
* string from the argument list. But %q also doubles every '\'' character.
|
||||
* %q is designed for use inside a string literal. By doubling each '\''
|
||||
* character it escapes that character and allows it to be inserted into
|
||||
* the string.
|
||||
*
|
||||
* For example, so some string variable contains text as follows:
|
||||
*
|
||||
* char *zText = "It's a happy day!";
|
||||
*
|
||||
* We can use this text in an SQL statement as follows:
|
||||
*
|
||||
* char *z = switch_core_db_mprintf("INSERT INTO TABLES('%q')", zText);
|
||||
* switch_core_db_exec(db, z, callback1, 0, 0);
|
||||
* switch_core_db_free(z);
|
||||
*
|
||||
* Because the %q format string is used, the '\'' character in zText
|
||||
* is escaped and the SQL generated is as follows:
|
||||
*
|
||||
* INSERT INTO table1 VALUES('It''s a happy day!')
|
||||
*
|
||||
* This is correct. Had we used %s instead of %q, the generated SQL
|
||||
* would have looked like this:
|
||||
*
|
||||
* INSERT INTO table1 VALUES('It's a happy day!');
|
||||
*
|
||||
* This second example is an SQL syntax error. As a general rule you
|
||||
* should always use %q instead of %s when inserting text into a string
|
||||
* literal.
|
||||
*/
|
||||
SWITCH_DECLARE(char *)switch_mprintf(const char *zFormat,...);
|
||||
|
||||
SWITCH_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
||||
*/
|
||||
@@ -221,13 +221,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
||||
switch_input_args_t *args,
|
||||
uint32_t limit);
|
||||
|
||||
/*!
|
||||
\brief Function to evaluate an expression against a string
|
||||
\param target The string to find a match in
|
||||
\param expression The regular expression to run against the string
|
||||
\return Boolean if a match was found or not
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_regex_match(char *target, char *expression);
|
||||
|
||||
/*!
|
||||
\brief Play a sound and gather digits with the number of retries specified if the user doesn't give digits in the set time
|
||||
|
||||
@@ -48,6 +48,7 @@ SWITCH_BEGIN_EXTERN_C
|
||||
#define __SWITCH_FUNC__ (const char *)__func__
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
|
||||
@@ -62,7 +63,7 @@ SWITCH_BEGIN_EXTERN_C
|
||||
* C4512: assignment operator could not be generated
|
||||
* C4610: struct can never be instantiated - user defined constructor required
|
||||
*/
|
||||
#pragma warning(disable:4100 4200 4204 4706 4819 4132 4510 4512 4610)
|
||||
#pragma warning(disable:4100 4200 4204 4706 4819 4132 4510 4512 4610 4996)
|
||||
|
||||
#if (_MSC_VER >= 1400) // VC8+
|
||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
||||
@@ -93,20 +94,21 @@ typedef __int32 int32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned long in_addr_t;
|
||||
#endif
|
||||
typedef int pid_t;
|
||||
typedef int uid_t;
|
||||
typedef int gid_t;
|
||||
#define PACKED
|
||||
#include <io.h>
|
||||
#define strcasecmp(s1, s2) stricmp(s1, s2)
|
||||
#define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
|
||||
#else
|
||||
/* packed attribute */
|
||||
#ifndef PACKED
|
||||
#define PACKED __attribute__ ((__packed__))
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif // _MSC_VER
|
||||
|
||||
#ifndef __LITTLE_ENDIAN
|
||||
@@ -124,6 +126,7 @@ typedef unsigned long in_addr_t;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#if defined(SWITCH_CORE_DECLARE_STATIC)
|
||||
#define SWITCH_DECLARE(type) type __stdcall
|
||||
#define SWITCH_DECLARE_NONSTD(type) type __cdecl
|
||||
@@ -152,11 +155,13 @@ typedef unsigned long in_addr_t;
|
||||
#ifndef S_IWUSR
|
||||
#define S_IWUSR _S_IWRITE
|
||||
#endif
|
||||
#define SWITCH_THREAD_FUNC __stdcall
|
||||
#else //not win32
|
||||
#define SWITCH_DECLARE(type) type
|
||||
#define SWITCH_DECLARE_NONSTD(type) type
|
||||
#define SWITCH_MOD_DECLARE(type) type
|
||||
#define SWITCH_DECLARE_DATA
|
||||
#define SWITCH_THREAD_FUNC
|
||||
#endif
|
||||
|
||||
#ifdef DOXYGEN
|
||||
@@ -171,10 +176,115 @@ typedef unsigned long in_addr_t;
|
||||
#define PRINTF_FUNCTION(fmtstr,vars)
|
||||
#endif
|
||||
|
||||
SWITCH_END_EXTERN_C
|
||||
#ifdef SWITCH_INT32
|
||||
typedef SWITCH_INT32 switch_int32_t;
|
||||
#else
|
||||
typedef int32_t switch_int32_t;
|
||||
#endif
|
||||
|
||||
#ifdef SWITCH_SIZE_T
|
||||
typedef SWITCH_SIZE_T switch_size_t;
|
||||
#else
|
||||
typedef uintptr_t switch_size_t;
|
||||
#endif
|
||||
|
||||
#ifdef SWITCH_SSIZE_T
|
||||
typedef SWITCH_SSIZE_T switch_ssize_t;
|
||||
#else
|
||||
typedef intptr_t switch_ssize_t;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#ifdef WIN64
|
||||
#define SWITCH_SSIZE_T_FMT "%I64d"
|
||||
#define SWITCH_SIZE_T_FMT "%I64d"
|
||||
#else
|
||||
#define SWITCH_SSIZE_T_FMT "%d"
|
||||
#define SWITCH_SIZE_T_FMT "%d"
|
||||
#endif
|
||||
|
||||
#define SWITCH_INT64_T_FMT "%I64d"
|
||||
#define SWITCH_UINT64_T_FMT "%I64u"
|
||||
|
||||
#else
|
||||
#ifndef SWITCH_SSIZE_T_FMT
|
||||
#define SWITCH_SSIZE_T_FMT (sizeof (switch_ssize_t) == sizeof (long) ? "%ld" : sizeof (switch_ssize_t) == sizeof (int) ? "%d" : "%lld")
|
||||
#endif
|
||||
|
||||
#ifndef SWITCH_SIZE_T_FMT
|
||||
#define SWITCH_SIZE_T_FMT (sizeof (switch_size_t) == sizeof (long) ? "%lu" : sizeof (switch_size_t) == sizeof (int) ? "%u" : "%llu")
|
||||
#endif
|
||||
|
||||
#ifndef SWITCH_INT64_T_FMT
|
||||
#define SWITCH_INT64_T_FMT (sizeof (long) == 8 ? "%ld" : "%lld")
|
||||
#endif
|
||||
|
||||
#ifndef SWITCH_UINT64_T_FMT
|
||||
#define SWITCH_UINT64_T_FMT (sizeof (long) == 8 ? "%lu" : "%llu")
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define SWITCH_TIME_T_FMT SWITCH_INT64_T_FMT
|
||||
|
||||
SWITCH_END_EXTERN_C
|
||||
|
||||
/* these includes must be outside the extern "C" block on windows or it will break compatibility with c++ modules*/
|
||||
#ifdef WIN32
|
||||
/* Has windows.h already been included? If so, our preferences don't matter,
|
||||
* but we will still need the winsock things no matter what was included.
|
||||
* If not, include a restricted set of windows headers to our tastes.
|
||||
*/
|
||||
#ifndef _WINDOWS_
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#ifndef _WIN32_WINNT
|
||||
|
||||
/* Restrict the server to a subset of Windows NT 4.0 header files by default
|
||||
*/
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#endif
|
||||
#ifndef NOUSER
|
||||
#define NOUSER
|
||||
#endif
|
||||
#ifndef NOMCX
|
||||
#define NOMCX
|
||||
#endif
|
||||
#ifndef NOIME
|
||||
#define NOIME
|
||||
#endif
|
||||
#include <windows.h>
|
||||
/*
|
||||
* Add a _very_few_ declarations missing from the restricted set of headers
|
||||
* (If this list becomes extensive, re-enable the required headers above!)
|
||||
* winsock headers were excluded by WIN32_LEAN_AND_MEAN, so include them now
|
||||
*/
|
||||
#define SW_HIDE 0
|
||||
#ifndef _WIN32_WCE
|
||||
#include <winsock2.h>
|
||||
#include <mswsock.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#endif /* !_WINDOWS_ */
|
||||
#include <process.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/* src/include/switch_private.h.in. Generated from configure.in by autoheader. */
|
||||
|
||||
/* Enable extra debugging. */
|
||||
#undef DEBUG
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_DIRENT_H
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the `gethostname' function. */
|
||||
#undef HAVE_GETHOSTNAME
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#undef HAVE_MALLOC
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `mlock' function. */
|
||||
#undef HAVE_MLOCK
|
||||
|
||||
/* Define to 1 if you have the `mlockall' function. */
|
||||
#undef HAVE_MLOCKALL
|
||||
|
||||
/* Define to 1 if you have the `mmap' function. */
|
||||
#undef HAVE_MMAP
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
#undef HAVE_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strftime' function. */
|
||||
#undef HAVE_STRFTIME
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_DIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#undef HAVE_SYS_NDIR_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the `usleep' function. */
|
||||
#undef HAVE_USLEEP
|
||||
|
||||
/* Define to 1 if you have the `vasprintf' function. */
|
||||
#undef HAVE_VASPRINTF
|
||||
|
||||
/* Enable Optimization. */
|
||||
#undef OPTIMZER
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* The size of a `char', as computed by sizeof. */
|
||||
#undef SIZEOF_CHAR
|
||||
|
||||
/* The size of a `int', as computed by sizeof. */
|
||||
#undef SIZEOF_INT
|
||||
|
||||
/* The size of a `long', as computed by sizeof. */
|
||||
#undef SIZEOF_LONG
|
||||
|
||||
/* The size of a `long long', as computed by sizeof. */
|
||||
#undef SIZEOF_LONG_LONG
|
||||
|
||||
/* The size of a `short', as computed by sizeof. */
|
||||
#undef SIZEOF_SHORT
|
||||
|
||||
/* The size of size_t */
|
||||
#undef SIZEOF_SIZE_T
|
||||
|
||||
/* The size of ssize_t */
|
||||
#undef SIZEOF_SSIZE_T
|
||||
|
||||
/* The size of a `void*', as computed by sizeof. */
|
||||
#undef SIZEOF_VOIDP
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Little Endian */
|
||||
#undef SWITCH_BYTE_ORDER
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
|
||||
#undef TM_IN_SYS_TIME
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* sunpro is bad at inline */
|
||||
#undef __inline__
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
#undef malloc
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef ssize_t
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
* Portions created by the Initial Developer are Copyright (C)
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
*
|
||||
* switch_regex.h -- pcre wrapper and extensions Header
|
||||
*
|
||||
*/
|
||||
/*! \file switch_regex.h
|
||||
\brief Regex Header
|
||||
*/
|
||||
#ifndef SWITCH_REGEX_H
|
||||
#define SWITCH_REGEX_H
|
||||
|
||||
SWITCH_BEGIN_EXTERN_C
|
||||
|
||||
/**
|
||||
* @defgroup switch_regex
|
||||
* @ingroup FREESWITCH
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct real_pcre switch_regex_t;
|
||||
|
||||
SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
|
||||
int options,
|
||||
const char **errorptr,
|
||||
int *erroroffset,
|
||||
const unsigned char *tables);
|
||||
|
||||
SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject,
|
||||
int *ovector,
|
||||
int stringcount,
|
||||
int stringnumber,
|
||||
char *buffer,
|
||||
int size);
|
||||
|
||||
SWITCH_DECLARE(void) switch_regex_free(void *data);
|
||||
|
||||
SWITCH_DECLARE(int) switch_regex_perform(char *field, char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen);
|
||||
SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, char *data, char *field_data, char *substituted, uint32_t len, int *ovector);
|
||||
|
||||
/*!
|
||||
\brief Function to evaluate an expression against a string
|
||||
\param target The string to find a match in
|
||||
\param expression The regular expression to run against the string
|
||||
\return Boolean if a match was found or not
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_regex_match(char *target, char *expression);
|
||||
|
||||
#define switch_regex_safe_free(re) if (re) {\
|
||||
switch_regex_free(re);\
|
||||
re = NULL;\
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
SWITCH_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
||||
*/
|
||||
@@ -45,7 +45,6 @@
|
||||
|
||||
#include <switch.h>
|
||||
SWITCH_BEGIN_EXTERN_C
|
||||
#include <stdlib.h>
|
||||
|
||||
/*!
|
||||
\defgroup resamp Audio Resample Functions
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#define SWITCH_TYPES_H
|
||||
|
||||
#include <switch.h>
|
||||
#include <ctype.h>
|
||||
SWITCH_BEGIN_EXTERN_C
|
||||
|
||||
#define SWITCH_SEQ_ESC "\033["
|
||||
@@ -503,7 +502,6 @@ typedef enum {
|
||||
SCSMF_DYNAMIC = (1 << 0)
|
||||
} switch_core_session_message_flag_t;
|
||||
|
||||
#define SWITCH_UUID_FORMATTED_LENGTH APR_UUID_FORMATTED_LENGTH
|
||||
#define SWITCH_CHANNEL_LOG SWITCH_CHANNEL_ID_LOG, __FILE__, __SWITCH_FUNC__, __LINE__
|
||||
#define SWITCH_CHANNEL_LOG_CLEAN SWITCH_CHANNEL_ID_LOG_CLEAN, __FILE__, __SWITCH_FUNC__, __LINE__
|
||||
#define SWITCH_CHANNEL_EVENT SWITCH_CHANNEL_ID_EVENT, __FILE__, __SWITCH_FUNC__, __LINE__
|
||||
@@ -944,6 +942,7 @@ typedef enum {
|
||||
SCSC_CHECK_RUNNING
|
||||
} switch_session_ctl_t;
|
||||
|
||||
typedef uint16_t switch_port_t;
|
||||
typedef uint8_t switch_payload_t;
|
||||
typedef struct switch_rtp switch_rtp_t;
|
||||
typedef struct switch_core_session_message switch_core_session_message_t;
|
||||
@@ -1032,7 +1031,6 @@ typedef switch_status_t (*switch_say_callback_t)(switch_core_session_t *session,
|
||||
switch_say_type_t type,
|
||||
switch_say_method_t method,
|
||||
switch_input_args_t *args);
|
||||
typedef int (*switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames);
|
||||
typedef switch_status_t (*switch_module_load_t) (switch_loadable_module_interface_t **, char *);
|
||||
typedef switch_status_t (*switch_module_reload_t) (void);
|
||||
typedef switch_status_t (*switch_module_pause_t) (void);
|
||||
|
||||
@@ -39,30 +39,15 @@
|
||||
#define SWITCH_UTILS_H
|
||||
|
||||
#include <switch.h>
|
||||
#include <pcre.h>
|
||||
|
||||
SWITCH_BEGIN_EXTERN_C
|
||||
|
||||
#ifndef snprintf
|
||||
#define snprintf apr_snprintf
|
||||
#endif
|
||||
#ifndef vsnprintf
|
||||
#define vsnprintf apr_vsnprintf
|
||||
#endif
|
||||
|
||||
#define switch_bytes_per_frame(rate, interval) ((uint32_t)((float)rate / (1000.0f / (float)interval)))
|
||||
|
||||
#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;
|
||||
|
||||
SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in);
|
||||
|
||||
SWITCH_DECLARE(apr_status_t) switch_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock,
|
||||
apr_int32_t flags, char *buf,
|
||||
apr_size_t *len);
|
||||
|
||||
|
||||
#define switch_codec2str(codec,buf,len) snprintf(buf, len, "%s@%uk@%ui", \
|
||||
codec->implementation->iananame, \
|
||||
codec->implementation->samples_per_second, \
|
||||
@@ -133,10 +118,6 @@ SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key);
|
||||
*/
|
||||
#define is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119)
|
||||
|
||||
/*!
|
||||
\brief Duplicate a string
|
||||
*/
|
||||
#define switch_copy_string apr_cpystrn
|
||||
|
||||
/*!
|
||||
\brief Test for the existance of a flag on an arbitary object
|
||||
@@ -209,13 +190,7 @@ switch_mutex_unlock(obj->flag_mutex);
|
||||
/*!
|
||||
\brief Wait a desired number of microseconds and yield the CPU
|
||||
*/
|
||||
#if defined(HAVE_USLEEP)
|
||||
#define switch_yield(ms) usleep(ms);
|
||||
#elif defined(WIN32)
|
||||
#define switch_yield(ms) Sleep((DWORD)((ms) / 1000));
|
||||
#else
|
||||
#define switch_yield(ms) apr_sleep(ms); //apr_thread_yield();
|
||||
#endif
|
||||
#define switch_yield(ms) switch_sleep(ms);
|
||||
|
||||
/*!
|
||||
\brief Converts a string representation of a date into a switch_time_t
|
||||
@@ -252,16 +227,6 @@ SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char
|
||||
*/
|
||||
SWITCH_DECLARE(char *) switch_escape_char(switch_memory_pool_t *pool, char *in, char *delim, char esc);
|
||||
|
||||
/*!
|
||||
\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
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock, switch_int16_t flags, switch_memory_pool_t *pool);
|
||||
|
||||
/*!
|
||||
\brief Wait for a socket
|
||||
\param poll the pollfd to wait on
|
||||
@@ -276,20 +241,12 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms);
|
||||
*/
|
||||
SWITCH_DECLARE(const char *) switch_cut_path(const char *in);
|
||||
|
||||
#define switch_clean_re(re) if (re) {\
|
||||
pcre_free(re);\
|
||||
re = NULL;\
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char *) switch_string_replace(const char *string, const char *search, const char *replace);
|
||||
SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t string_len, const char *search, size_t search_len);
|
||||
SWITCH_DECLARE(int) switch_perform_regex(char *field, char *expression, pcre **new_re, int *ovector, uint32_t olen);
|
||||
SWITCH_DECLARE(void) switch_perform_substitution(pcre *re, int match_count, char *data, char *field_data, char *substituted, uint32_t len, int *ovector);
|
||||
|
||||
#define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK)
|
||||
SWITCH_DECLARE(size_t) switch_url_encode(char *url, char *buf, size_t len);
|
||||
SWITCH_DECLARE(char *) switch_url_decode(char *s);
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename);
|
||||
SWITCH_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
@@ -55,11 +55,7 @@
|
||||
|
||||
#ifndef _SWITCH_XML_H
|
||||
#define _SWITCH_XML_H
|
||||
#include <switch_types.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
#include <switch.h>
|
||||
|
||||
|
||||
///\defgroup xml1 XML Library Functions
|
||||
|
||||
@@ -374,7 +374,7 @@ static switch_status_t strepoch_api_function(char *data, switch_core_session_t *
|
||||
out = switch_str_time(data);
|
||||
}
|
||||
|
||||
stream->write_function(stream, "%d", (uint32_t)apr_time_sec(out));
|
||||
stream->write_function(stream, "%d", (uint32_t)((out) / (int64_t)(1000000)) );
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -315,16 +315,16 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
|
||||
}
|
||||
|
||||
if (flags && service && regex && replace) {
|
||||
pcre *re = NULL;
|
||||
switch_regex_t *re = NULL;
|
||||
int proceed = 0, ovector[30];
|
||||
char substituted[1024] = "";
|
||||
char rbuf[1024] = "";
|
||||
char *uri;
|
||||
enum_route_t *route;
|
||||
|
||||
switch_clean_re(re);
|
||||
switch_regex_safe_free(re);
|
||||
|
||||
if ((proceed = switch_perform_regex(q->number, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if ((proceed = switch_regex_perform(q->number, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if (strchr(regex, '(')) {
|
||||
switch_perform_substitution(re, proceed, replace, q->number, substituted, sizeof(substituted), ovector);
|
||||
uri = substituted;
|
||||
@@ -333,8 +333,8 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
|
||||
}
|
||||
|
||||
if ((route = (enum_route_t *) switch_core_hash_find(globals.routes, service))){
|
||||
switch_clean_re(re);
|
||||
if ((proceed = switch_perform_regex(uri, route->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
switch_regex_safe_free(re);
|
||||
if ((proceed = switch_regex_perform(uri, route->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if (strchr(route->regex, '(')) {
|
||||
switch_perform_substitution(re, proceed, route->replace, uri, rbuf, sizeof(rbuf), ovector);
|
||||
uri = rbuf;
|
||||
@@ -347,7 +347,7 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
|
||||
add_result(q, order, preference, service, uri);
|
||||
}
|
||||
|
||||
switch_clean_re(re);
|
||||
switch_regex_safe_free(re);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -63,7 +63,7 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
|
||||
char *do_break_a = NULL;
|
||||
char *expression = NULL;
|
||||
char *field_data = NULL;
|
||||
pcre *re = NULL;
|
||||
switch_regex_t *re = NULL;
|
||||
int ovector[30];
|
||||
break_t do_break_i = BREAK_ON_FALSE;
|
||||
|
||||
@@ -118,7 +118,7 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
|
||||
field_data = "";
|
||||
}
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field, field_data, expression);
|
||||
if (!(proceed = switch_perform_regex(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if (!(proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Regex mismatch\n");
|
||||
|
||||
for (xaction = switch_xml_child(xcond, "anti-action"); xaction; xaction = xaction->next) {
|
||||
@@ -181,7 +181,7 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
|
||||
switch_safe_free(substituted);
|
||||
}
|
||||
|
||||
switch_clean_re(re);
|
||||
switch_regex_safe_free(re);
|
||||
|
||||
if (do_break_i == BREAK_ON_TRUE || do_break_i == BREAK_ALWAYS) {
|
||||
break;
|
||||
|
||||
@@ -363,7 +363,7 @@ static void pres_event_handler(switch_event_t *event)
|
||||
type, rpid, status, proto, from);
|
||||
|
||||
|
||||
for (hi = switch_hash_first(apr_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
char *errmsg;
|
||||
switch_hash_this(hi, NULL, NULL, &val);
|
||||
profile = (struct mdl_profile *) val;
|
||||
@@ -462,7 +462,7 @@ static void roster_event_handler(switch_event_t *event)
|
||||
sql = switch_mprintf("select *,'%q' from subscriptions", status ? status : "");
|
||||
}
|
||||
|
||||
for (hi = switch_hash_first(apr_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
char *errmsg;
|
||||
switch_hash_this(hi, NULL, NULL, &val);
|
||||
profile = (struct mdl_profile *) val;
|
||||
@@ -537,7 +537,7 @@ static void sign_off(void)
|
||||
sql = switch_mprintf("select * from subscriptions");
|
||||
|
||||
|
||||
for (hi = switch_hash_first(apr_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
char *errmsg;
|
||||
switch_hash_this(hi, NULL, NULL, &val);
|
||||
profile = (struct mdl_profile *) val;
|
||||
|
||||
@@ -717,7 +717,7 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
|
||||
|
||||
snprintf(buf, sizeof(buf),
|
||||
"v=0\n"
|
||||
"o=FreeSWITCH %d%"APR_TIME_T_FMT" %d%"APR_TIME_T_FMT" IN IP4 %s\n"
|
||||
"o=FreeSWITCH %d%"SWITCH_TIME_T_FMT" %d%"SWITCH_TIME_T_FMT" IN IP4 %s\n"
|
||||
"s=FreeSWITCH\n"
|
||||
"c=IN IP4 %s\n"
|
||||
"t=0 0\n"
|
||||
@@ -3219,13 +3219,13 @@ static char *get_auth_data(char *dbname, char *nonce, char *npassword, size_t le
|
||||
while (running < 5000) {
|
||||
int result = switch_core_db_step(stmt);
|
||||
|
||||
if (result == SQLITE_ROW) {
|
||||
if (result == SWITCH_CORE_DB_ROW) {
|
||||
if ((colcount = switch_core_db_column_count(stmt))) {
|
||||
switch_copy_string(npassword, (char *)switch_core_db_column_text(stmt, 0), len);
|
||||
ret = npassword;
|
||||
}
|
||||
break;
|
||||
} else if (result == SQLITE_BUSY) {
|
||||
} else if (result == SWITCH_CORE_DB_BUSY) {
|
||||
running++;
|
||||
switch_yield(1000);
|
||||
continue;
|
||||
@@ -5639,7 +5639,7 @@ static void cancel_presence(void)
|
||||
void *val;
|
||||
|
||||
if ((sql = switch_mprintf("select 0,'unavailable','unavailable',* from sip_subscriptions where event='presence'"))) {
|
||||
for (hi = switch_hash_first(apr_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, NULL, NULL, &val);
|
||||
profile = (sofia_profile_t *) val;
|
||||
if (!(profile->pflags & PFLAG_PRESENCE)) {
|
||||
@@ -5773,7 +5773,7 @@ static void pres_event_handler(switch_event_t *event)
|
||||
sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence'", status, rpid);
|
||||
}
|
||||
|
||||
for (hi = switch_hash_first(apr_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, NULL, NULL, &val);
|
||||
profile = (sofia_profile_t *) val;
|
||||
if (!(profile->pflags & PFLAG_PRESENCE)) {
|
||||
@@ -5872,7 +5872,7 @@ static void pres_event_handler(switch_event_t *event)
|
||||
break;
|
||||
}
|
||||
|
||||
for (hi = switch_hash_first(apr_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
for (hi = switch_hash_first(switch_hash_pool_get(globals.profile_hash), globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, NULL, NULL, &val);
|
||||
profile = (sofia_profile_t *) val;
|
||||
if (!(profile->pflags & PFLAG_PRESENCE)) {
|
||||
|
||||
@@ -117,7 +117,7 @@ struct woomera_event_queue {
|
||||
struct woomera_profile {
|
||||
char *name;
|
||||
switch_socket_t *woomera_socket;
|
||||
apr_thread_mutex_t *iolock;
|
||||
switch_mutex_t *iolock;
|
||||
char woomera_host[WOOMERA_STRLEN];
|
||||
switch_port_t woomera_port;
|
||||
char audio_ip[WOOMERA_STRLEN];
|
||||
@@ -134,9 +134,9 @@ struct private_object {
|
||||
switch_codec_t read_codec;
|
||||
switch_codec_t write_codec;
|
||||
switch_core_session_t *session;
|
||||
switch_pollfd_t read_poll;
|
||||
switch_pollfd_t write_poll;
|
||||
switch_pollfd_t command_poll;
|
||||
switch_pollfd_t *read_poll;
|
||||
switch_pollfd_t *write_poll;
|
||||
switch_pollfd_t *command_poll;
|
||||
char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE];
|
||||
switch_mutex_t *iolock;
|
||||
switch_sockaddr_t *udpread;
|
||||
@@ -306,7 +306,7 @@ static void woomera_socket_close(switch_socket_t **socket)
|
||||
static void udp_socket_close(struct private_object *tech_pvt)
|
||||
{
|
||||
if (tech_pvt->udp_socket) {
|
||||
apr_socket_shutdown(tech_pvt->udp_socket, APR_SHUTDOWN_READWRITE);
|
||||
switch_socket_shutdown(tech_pvt->udp_socket, SWITCH_SHUTDOWN_READWRITE);
|
||||
woomera_socket_close(&tech_pvt->udp_socket);
|
||||
}
|
||||
}
|
||||
@@ -364,7 +364,7 @@ static switch_status_t woomera_waitfor_read(switch_core_session_t *session, int
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
assert(tech_pvt != NULL);
|
||||
|
||||
return switch_socket_waitfor(&tech_pvt->read_poll, ms) ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
|
||||
return switch_socket_waitfor(tech_pvt->read_poll, ms) ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t woomera_waitfor_write(switch_core_session_t *session, int ms, int stream_id)
|
||||
@@ -375,7 +375,7 @@ static switch_status_t woomera_waitfor_write(switch_core_session_t *session, int
|
||||
assert(tech_pvt != NULL);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
// return switch_socket_waitfor(&tech_pvt->write_poll, ms);
|
||||
// return switch_socket_waitfor(tech_pvt->write_poll, ms);
|
||||
}
|
||||
|
||||
static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
|
||||
|
||||
@@ -65,7 +65,7 @@ enum switch_mod_cdr_sql_types_t { CDR_INTEGER,CDR_STRING,CDR_DECIMAL,CDR_DOUBLE,
|
||||
#define STDCALL
|
||||
#endif
|
||||
|
||||
typedef apr_status_t (STDCALL *modcdr_time_convert_t)(apr_time_exp_t*,apr_time_t);
|
||||
typedef switch_status_t (STDCALL *modcdr_time_convert_t)(switch_time_exp_t*,switch_time_t);
|
||||
|
||||
class BaseCDR {
|
||||
public:
|
||||
|
||||
@@ -67,7 +67,7 @@ CsvCDR::CsvCDR(switch_mod_cdr_newchannel_t *newchannel) : BaseCDR(newchannel)
|
||||
convert_time(&tempcallend, callenddate);
|
||||
|
||||
// Format the times
|
||||
apr_size_t retsizecsd, retsizecad, retsizectd, retsizeced; //csd == callstartdate, cad == callanswerdate, ced == callenddate, ceff == callenddate_forfile
|
||||
switch_size_t retsizecsd, retsizecad, retsizectd, retsizeced; //csd == callstartdate, cad == callanswerdate, ced == callenddate, ceff == callenddate_forfile
|
||||
char format[] = "%Y-%m-%d %H:%M:%S";
|
||||
switch_strftime(formattedcallstartdate,&retsizecsd,sizeof(formattedcallstartdate),format,&tempcallstart);
|
||||
switch_strftime(formattedcallanswerdate,&retsizecad,sizeof(formattedcallanswerdate),format,&tempcallanswer);
|
||||
@@ -213,7 +213,7 @@ void CsvCDR::open_file()
|
||||
|
||||
switch_time_exp_lt(&now_converted,now);
|
||||
|
||||
apr_size_t retsize;
|
||||
switch_size_t retsize;
|
||||
char format[] = "%Y-%m-%d-%H-%M-%S";
|
||||
char formatteddate[100];
|
||||
memset(formatteddate,0,100);
|
||||
|
||||
@@ -65,10 +65,10 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
|
||||
char *next, *cur;
|
||||
uint32_t count = 0;
|
||||
uint8_t custom = 0;
|
||||
apr_ssize_t hlen = APR_HASH_KEY_STRING;
|
||||
switch_ssize_t hlen = SWITCH_HASH_KEY_STRING;
|
||||
|
||||
gethostname(globals.hostname, sizeof(globals.hostname));
|
||||
globals.host_hash = apr_hashfunc_default(globals.hostname, &hlen);
|
||||
globals.host_hash = switch_hashfunc_default(globals.hostname, &hlen);
|
||||
globals.key_count = 0;
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
@@ -256,7 +256,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
switch_socket_shutdown(globals.udp_socket, APR_SHUTDOWN_READWRITE);
|
||||
switch_socket_shutdown(globals.udp_socket, SWITCH_SHUTDOWN_READWRITE);
|
||||
globals.running = -1;
|
||||
while(x < 100000 && globals.running) {
|
||||
x++;
|
||||
|
||||
@@ -194,7 +194,7 @@ static void socket_function(switch_core_session_t *session, char *data)
|
||||
return;
|
||||
}
|
||||
|
||||
if (switch_socket_create(&new_sock, AF_INET, SOCK_STREAM, APR_PROTO_TCP, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_socket_create(&new_sock, AF_INET, SOCK_STREAM, SWITCH_PROTO_TCP, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error!\n");
|
||||
return;
|
||||
}
|
||||
@@ -271,7 +271,7 @@ static switch_loadable_module_interface_t event_socket_module_interface = {
|
||||
static void close_socket(switch_socket_t **sock) {
|
||||
switch_mutex_lock(listen_list.sock_mutex);
|
||||
if (*sock) {
|
||||
apr_socket_shutdown(*sock, APR_SHUTDOWN_READWRITE);
|
||||
switch_socket_shutdown(*sock, SWITCH_SHUTDOWN_READWRITE);
|
||||
switch_socket_close(*sock);
|
||||
*sock = NULL;
|
||||
}
|
||||
@@ -449,7 +449,7 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
|
||||
|
||||
|
||||
if (data) {
|
||||
snprintf(buf, sizeof(buf), "Content-Type: log/data\nContent-Length: %"APR_SSIZE_T_FMT"\n\n", strlen(data));
|
||||
snprintf(buf, sizeof(buf), "Content-Type: log/data\nContent-Length: %"SWITCH_SSIZE_T_FMT"\n\n", strlen(data));
|
||||
len = strlen(buf);
|
||||
switch_socket_send(listener->sock, buf, &len);
|
||||
len = strlen(data);
|
||||
@@ -486,7 +486,7 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
|
||||
|
||||
len = strlen(listener->ebuf);
|
||||
|
||||
snprintf(hbuf, sizeof(hbuf), "Content-Length: %"APR_SSIZE_T_FMT"\n"
|
||||
snprintf(hbuf, sizeof(hbuf), "Content-Length: %"SWITCH_SSIZE_T_FMT"\n"
|
||||
"Content-Type: text/event-%s\n"
|
||||
"\n", len, etype);
|
||||
|
||||
@@ -558,7 +558,7 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
|
||||
switch_size_t rlen, blen;
|
||||
char buf[1024] = "";
|
||||
rlen = strlen(reply);
|
||||
snprintf(buf, sizeof(buf), "Content-Type: api/response\nContent-Length: %"APR_SSIZE_T_FMT"\n\n", rlen);
|
||||
snprintf(buf, sizeof(buf), "Content-Type: api/response\nContent-Length: %"SWITCH_SSIZE_T_FMT"\n\n", rlen);
|
||||
blen = strlen(buf);
|
||||
switch_socket_send(acs->listener->sock, buf, &blen);
|
||||
switch_socket_send(acs->listener->sock, reply, &rlen);
|
||||
@@ -1006,7 +1006,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open\n");
|
||||
|
||||
switch_socket_opt_set(listener->sock, APR_SO_NONBLOCK, TRUE);
|
||||
switch_socket_opt_set(listener->sock, SWITCH_SO_NONBLOCK, TRUE);
|
||||
switch_set_flag_locked(listener, LFLAG_RUNNING);
|
||||
add_listener(listener);
|
||||
|
||||
@@ -1210,9 +1210,9 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
|
||||
|
||||
|
||||
for(;;) {
|
||||
rv = switch_sockaddr_info_get(&sa, prefs.ip, APR_INET, prefs.port, 0, pool);
|
||||
rv = switch_sockaddr_info_get(&sa, prefs.ip, SWITCH_INET, prefs.port, 0, pool);
|
||||
if (rv) goto fail;
|
||||
rv = switch_socket_create(&listen_list.sock, sa->family, SOCK_STREAM, APR_PROTO_TCP, pool);
|
||||
rv = switch_socket_create(&listen_list.sock, switch_sockaddr_get_family(sa), SOCK_STREAM, SWITCH_PROTO_TCP, pool);
|
||||
if (rv) goto sock_fail;
|
||||
rv = switch_socket_opt_set(listen_list.sock, SWITCH_SO_REUSEADDR, 1);
|
||||
if (rv) goto sock_fail;
|
||||
|
||||
@@ -438,9 +438,9 @@ static void js_error(JSContext *cx, const char *message, JSErrorReport *report)
|
||||
static switch_status_t sm_load_file(char *filename)
|
||||
{
|
||||
sm_loadable_module_t *module = NULL;
|
||||
apr_dso_handle_t *dso = NULL;
|
||||
apr_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
apr_dso_handle_sym_t function_handle = NULL;
|
||||
switch_dso_handle_t *dso = NULL;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
switch_dso_handle_sym_t function_handle = NULL;
|
||||
spidermonkey_init_t spidermonkey_init = NULL;
|
||||
const sm_module_interface_t *module_interface = NULL, *mp;
|
||||
|
||||
@@ -450,16 +450,16 @@ static switch_status_t sm_load_file(char *filename)
|
||||
|
||||
assert(filename != NULL);
|
||||
|
||||
status = apr_dso_load(&dso, filename, module_manager.pool);
|
||||
status = switch_dso_load(&dso, filename, module_manager.pool);
|
||||
|
||||
while (loading) {
|
||||
if (status != APR_SUCCESS) {
|
||||
apr_dso_error(dso, derr, sizeof(derr));
|
||||
if (status != SWITCH_STATUS_SUCCESS) {
|
||||
switch_dso_error(dso, derr, sizeof(derr));
|
||||
err = derr;
|
||||
break;
|
||||
}
|
||||
|
||||
status = apr_dso_sym(&function_handle, dso, "spidermonkey_init");
|
||||
status = switch_dso_sym(&function_handle, dso, "spidermonkey_init");
|
||||
spidermonkey_init = (spidermonkey_init_t)(intptr_t) function_handle;
|
||||
|
||||
if (spidermonkey_init == NULL) {
|
||||
|
||||
@@ -153,10 +153,10 @@ static JSBool db_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
|
||||
int running = 1;
|
||||
while (running < 5000) {
|
||||
int result = switch_core_db_step(dbo->stmt);
|
||||
if (result == SQLITE_ROW) {
|
||||
if (result == SWITCH_CORE_DB_ROW) {
|
||||
*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
|
||||
break;
|
||||
} else if (result == SQLITE_BUSY) {
|
||||
} else if (result == SWITCH_CORE_DB_BUSY) {
|
||||
running++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -134,13 +134,7 @@ static switch_status_t http_stream_write(switch_stream_handle_t *handle, const c
|
||||
char *data;
|
||||
|
||||
va_start(ap, fmt);
|
||||
#ifdef HAVE_VASPRINTF
|
||||
ret = vasprintf(&data, fmt, ap);
|
||||
#else
|
||||
if ((data = (char *) malloc(2048))) {
|
||||
vsnprintf(data, 2048, fmt, ap);
|
||||
}
|
||||
#endif
|
||||
ret = switch_vasprintf(&data, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (data) {
|
||||
|
||||
@@ -0,0 +1,675 @@
|
||||
/*
|
||||
* 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/F
|
||||
*
|
||||
* 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
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
* Portions created by the Initial Developer are Copyright (C)
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
*
|
||||
*
|
||||
* switch_apr.c -- apr wrappers and extensions
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#ifndef WIN32
|
||||
#include <switch_private.h>
|
||||
#endif
|
||||
|
||||
/* apr headers*/
|
||||
#include <apr.h>
|
||||
#include <apr_pools.h>
|
||||
#include <apr_hash.h>
|
||||
#include <apr_network_io.h>
|
||||
#include <apr_errno.h>
|
||||
#include <apr_thread_proc.h>
|
||||
#include <apr_portable.h>
|
||||
#include <apr_thread_mutex.h>
|
||||
#include <apr_thread_cond.h>
|
||||
#include <apr_thread_rwlock.h>
|
||||
#include <apr_file_io.h>
|
||||
#include <apr_poll.h>
|
||||
#include <apr_dso.h>
|
||||
#include <apr_strings.h>
|
||||
#define APR_WANT_STDIO
|
||||
#define APR_WANT_STRFUNC
|
||||
#include <apr_want.h>
|
||||
|
||||
/* apr_vformatter_buff_t definition*/
|
||||
#include <apr_lib.h>
|
||||
|
||||
/* apr-util headers */
|
||||
#include <apr_queue.h>
|
||||
#include <apr_uuid.h>
|
||||
|
||||
/* apr stubs */
|
||||
|
||||
/* Memory Pools */
|
||||
|
||||
SWITCH_DECLARE(void) switch_pool_clear(switch_memory_pool_t *p)
|
||||
{
|
||||
apr_pool_clear(p);
|
||||
}
|
||||
|
||||
/* Hash tables */
|
||||
|
||||
SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(switch_memory_pool_t *p, switch_hash_t *ht)
|
||||
{
|
||||
return apr_hash_first(p, ht);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(switch_hash_index_t *ht)
|
||||
{
|
||||
return apr_hash_next(ht);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t *hi, const void **key, switch_ssize_t *klen, void **val)
|
||||
{
|
||||
apr_hash_this(hi, key, klen, val);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(unsigned int) switch_hashfunc_default(const char *key, switch_ssize_t *klen)
|
||||
{
|
||||
return apr_hashfunc_default(key, klen);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_memory_pool_t *) switch_hash_pool_get(switch_hash_t *ht)
|
||||
{
|
||||
return apr_hash_pool_get(ht);
|
||||
}
|
||||
|
||||
/* DSO functions */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t **res_handle,
|
||||
const char *path, switch_memory_pool_t *ctx)
|
||||
{
|
||||
return apr_dso_load(res_handle, path, ctx);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t *handle)
|
||||
{
|
||||
return apr_dso_unload(handle);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t *ressym,
|
||||
switch_dso_handle_t *handle,
|
||||
const char *symname)
|
||||
{
|
||||
return apr_dso_sym(ressym, handle, symname);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t *dso, char *buf, size_t bufsize)
|
||||
{
|
||||
return apr_dso_error(dso, buf, bufsize);
|
||||
}
|
||||
|
||||
|
||||
/* string functions */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_strftime(char *s,
|
||||
switch_size_t *retsize,
|
||||
switch_size_t max,
|
||||
const char *format,
|
||||
switch_time_exp_t *tm)
|
||||
{
|
||||
return apr_strftime(s, retsize, max, format, (apr_time_exp_t *)tm);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_snprintf(char *buf, switch_size_t len, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
va_start(ap, format);
|
||||
ret = apr_vsnprintf(buf, len, format, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_vsnprintf(char *buf, switch_size_t len, const char *format, va_list ap)
|
||||
{
|
||||
return apr_vsnprintf(buf, len, format, ap);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char *) switch_copy_string(char *dst, const char *src, switch_size_t dst_size)
|
||||
{
|
||||
return apr_cpystrn(dst, src, dst_size);
|
||||
}
|
||||
|
||||
/* thread read write lock functions */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock,
|
||||
switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_thread_rwlock_create(rwlock, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_destroy(switch_thread_rwlock_t *rwlock)
|
||||
{
|
||||
return apr_thread_rwlock_destroy(rwlock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_memory_pool_t *) switch_thread_rwlock_pool_get(switch_thread_rwlock_t *rwlock)
|
||||
{
|
||||
return apr_thread_rwlock_pool_get(rwlock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
|
||||
{
|
||||
return apr_thread_rwlock_rdlock(rwlock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock)
|
||||
{
|
||||
return apr_thread_rwlock_tryrdlock(rwlock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
|
||||
{
|
||||
return apr_thread_rwlock_wrlock(rwlock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t *rwlock)
|
||||
{
|
||||
return apr_thread_rwlock_trywrlock(rwlock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
|
||||
{
|
||||
return apr_thread_rwlock_unlock(rwlock);
|
||||
}
|
||||
|
||||
/* thread mutex functions */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t **lock,
|
||||
unsigned int flags,
|
||||
switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_thread_mutex_create(lock, flags, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t *lock)
|
||||
{
|
||||
return apr_thread_mutex_destroy(lock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t *lock)
|
||||
{
|
||||
return apr_thread_mutex_lock(lock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t *lock)
|
||||
{
|
||||
return apr_thread_mutex_unlock(lock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t *lock)
|
||||
{
|
||||
return apr_thread_mutex_trylock(lock);
|
||||
}
|
||||
|
||||
/* time function stubs */
|
||||
|
||||
SWITCH_DECLARE(switch_time_t) switch_time_now(void)
|
||||
{
|
||||
return (switch_time_t)apr_time_now();
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t *result, switch_time_exp_t *input)
|
||||
{
|
||||
return apr_time_exp_gmt_get(result, (apr_time_exp_t *)input);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t *result, switch_time_exp_t *input)
|
||||
{
|
||||
return apr_time_exp_get(result, (apr_time_exp_t *)input);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
|
||||
{
|
||||
return apr_time_exp_lt((apr_time_exp_t *)result, input);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input)
|
||||
{
|
||||
return apr_time_exp_gmt((apr_time_exp_t *)result, input);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
|
||||
{
|
||||
#if defined(HAVE_USLEEP)
|
||||
usleep(t);
|
||||
#elif defined(WIN32)
|
||||
Sleep((DWORD)((t) / 1000));
|
||||
#else
|
||||
apr_sleep(t);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_rfc822_date(char *date_str, switch_time_t t)
|
||||
{
|
||||
return apr_rfc822_date(date_str, t);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_time_t) switch_time_make(switch_time_t sec, int32_t usec)
|
||||
{
|
||||
return ((switch_time_t)(sec) * APR_USEC_PER_SEC + (switch_time_t)(usec));
|
||||
}
|
||||
|
||||
|
||||
/* Thread condition locks */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_thread_cond_create(cond, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
|
||||
{
|
||||
return apr_thread_cond_wait(cond, mutex);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, switch_interval_time_t timeout)
|
||||
{
|
||||
return apr_thread_cond_timedwait(cond, mutex, timeout);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t *cond)
|
||||
{
|
||||
return apr_thread_cond_signal(cond);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t *cond)
|
||||
{
|
||||
return apr_thread_cond_broadcast(cond);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t *cond)
|
||||
{
|
||||
return apr_thread_cond_destroy(cond);
|
||||
}
|
||||
|
||||
/* file i/o stubs */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t **newf, const char *fname, int32_t flag, switch_fileperms_t perm, switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_file_open(newf, fname, flag, perm, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_seek(switch_file_t *thefile, switch_seek_where_t where, int64_t *offset)
|
||||
{
|
||||
apr_status_t rv;
|
||||
apr_off_t off = (apr_off_t)(*offset);
|
||||
rv = apr_file_seek(thefile, where, &off);
|
||||
*offset = (int64_t)off;
|
||||
return rv;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t *thefile)
|
||||
{
|
||||
return apr_file_close(thefile);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_remove(const char *path, switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_file_remove(path, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t *thefile, void *buf, switch_size_t *nbytes)
|
||||
{
|
||||
return apr_file_read(thefile, buf, nbytes);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t *thefile, const void *buf, switch_size_t *nbytes)
|
||||
{
|
||||
return apr_file_write(thefile, buf, nbytes);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename)
|
||||
{
|
||||
int32_t wanted = APR_FINFO_TYPE;
|
||||
apr_finfo_t info = {0};
|
||||
if (filename) {
|
||||
apr_stat(&info, filename, wanted, NULL);
|
||||
if (info.filetype != APR_NOFILE) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
/* thread stubs */
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_threadattr_create(new_attr, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
|
||||
{
|
||||
return apr_threadattr_detach_set(attr, on);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
|
||||
{
|
||||
return apr_threadattr_stacksize_set(attr, stacksize);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
|
||||
{
|
||||
return apr_thread_create(new_thread, attr, func, data, cont);
|
||||
}
|
||||
|
||||
/* socket stubs */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_socket_create(new_sock, family, type, protocol, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
|
||||
{
|
||||
return apr_socket_shutdown(sock, how);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t *sock)
|
||||
{
|
||||
return apr_socket_close(sock);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
|
||||
{
|
||||
return apr_socket_bind(sock, sa);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t *sock, int32_t backlog)
|
||||
{
|
||||
return apr_socket_listen(sock, backlog);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t **new_sock, switch_socket_t *sock, switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_socket_accept(new_sock, sock, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t *sock, switch_sockaddr_t *sa)
|
||||
{
|
||||
return apr_socket_connect(sock, sa);
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const char *buf, switch_size_t *len)
|
||||
{
|
||||
return apr_socket_send(sock, buf, len);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
|
||||
{
|
||||
return apr_socket_sendto(sock, where, flags, buf, len);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len)
|
||||
{
|
||||
return apr_socket_recv(sock, buf, len);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_sockaddr_info_get(sa, hostname, family, port, flags, pool);
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
|
||||
{
|
||||
return apr_socket_opt_set(sock, opt, on);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t *sock, switch_interval_time_t t)
|
||||
{
|
||||
return apr_socket_timeout_set(sock, t);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t *sa)
|
||||
{
|
||||
return apr_sockaddr_ip_get(addr, sa);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source)
|
||||
{
|
||||
return apr_mcast_join(sock, join, iface, source);
|
||||
}
|
||||
|
||||
|
||||
/* socket functions */
|
||||
|
||||
SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
|
||||
{
|
||||
return get_addr(buf, len, &in->sa.sin.sin_addr);
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa)
|
||||
{
|
||||
return sa->port;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t *sa)
|
||||
{
|
||||
return sa->family;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock,
|
||||
int32_t flags, char *buf,
|
||||
size_t *len)
|
||||
{
|
||||
apr_status_t r;
|
||||
|
||||
if ((r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) {
|
||||
from->port = ntohs(from->sa.sin.sin_port);
|
||||
/* from->ipaddr_ptr = &(from->sa.sin.sin_addr);
|
||||
* from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr);
|
||||
*/
|
||||
}
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
/* poll stubs */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t **pollset,
|
||||
uint32_t size,
|
||||
switch_memory_pool_t *p,
|
||||
uint32_t flags)
|
||||
{
|
||||
return apr_pollset_create(pollset, size, p, flags);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t *pollset,
|
||||
const switch_pollfd_t *descriptor)
|
||||
{
|
||||
return apr_pollset_add(pollset, descriptor);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t *aprset,
|
||||
int32_t numsock,
|
||||
int32_t *nsds,
|
||||
switch_interval_time_t timeout)
|
||||
{
|
||||
return apr_poll(aprset, numsock, nsds, timeout);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t **poll, switch_socket_t *sock,
|
||||
int16_t flags, switch_memory_pool_t *pool)
|
||||
{
|
||||
switch_pollset_t *pollset;
|
||||
|
||||
void *ptr = NULL;
|
||||
|
||||
if ((ptr = apr_palloc(pool, sizeof(switch_pollfd_t))) == 0) {
|
||||
return SWITCH_STATUS_MEMERR;
|
||||
}
|
||||
|
||||
if (switch_pollset_create(&pollset, 1, pool, flags) != SWITCH_STATUS_SUCCESS) {
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
memset(ptr, 0, sizeof(switch_pollfd_t));
|
||||
*poll = ptr;
|
||||
|
||||
(*poll)->desc_type = APR_POLL_SOCKET;
|
||||
(*poll)->reqevents = flags;
|
||||
(*poll)->desc.s = sock;
|
||||
(*poll)->client_data = sock;
|
||||
|
||||
if (switch_pollset_add(pollset, *poll) != SWITCH_STATUS_SUCCESS) {
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* apr-util stubs */
|
||||
|
||||
/* UUID Handling (apr-util) */
|
||||
|
||||
|
||||
SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
|
||||
{
|
||||
apr_uuid_format(buffer, (const apr_uuid_t *)uuid);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t *uuid)
|
||||
{
|
||||
apr_uuid_get((apr_uuid_t *)uuid);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t *uuid, const char *uuid_str)
|
||||
{
|
||||
return apr_uuid_parse((apr_uuid_t *)uuid, uuid_str);
|
||||
}
|
||||
|
||||
|
||||
/* FIFO queues (apr-util) */
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t **queue,
|
||||
unsigned int queue_capacity,
|
||||
switch_memory_pool_t *pool)
|
||||
{
|
||||
return apr_queue_create(queue, queue_capacity, pool);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t *queue)
|
||||
{
|
||||
return apr_queue_size(queue);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t *queue, void **data)
|
||||
{
|
||||
return apr_queue_pop(queue, data);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t *queue, void *data)
|
||||
{
|
||||
return apr_queue_push(queue, data);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t *queue, void **data)
|
||||
{
|
||||
return apr_queue_trypop(queue, data);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t *queue, void *data)
|
||||
{
|
||||
return apr_queue_trypush(queue, data);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Utility functions */
|
||||
struct switch_vasprintf_data {
|
||||
apr_vformatter_buff_t vbuff;
|
||||
switch_size_t len;
|
||||
switch_size_t block_size;
|
||||
char *buf;
|
||||
};
|
||||
|
||||
static int vasprintf_flush(apr_vformatter_buff_t *buff)
|
||||
{
|
||||
struct switch_vasprintf_data *data = (struct switch_vasprintf_data *)buff;
|
||||
|
||||
char *temp;
|
||||
switch_size_t len = data->vbuff.curpos - data->buf;
|
||||
|
||||
if ((temp = realloc(data->buf, data->len + data->block_size))) {
|
||||
data->buf = temp;
|
||||
data->vbuff.curpos = data->buf + len;
|
||||
data->len = data->len + data->block_size;
|
||||
data->vbuff.endpos = data->buf + data->len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
SWITCH_DECLARE(int) switch_vasprintf(char **buf, const char *format, va_list ap)
|
||||
{
|
||||
#if 0
|
||||
struct switch_vasprintf_data data;
|
||||
|
||||
data.block_size = 1024;
|
||||
data.buf = malloc(data.block_size);
|
||||
|
||||
if (data.buf == NULL) {
|
||||
*buf = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
data.vbuff.curpos = data.buf;
|
||||
data.vbuff.endpos = data.buf + data.block_size;
|
||||
|
||||
return apr_vformatter(vasprintf_flush, (apr_vformatter_buff_t *)&data, format, ap);
|
||||
#endif
|
||||
#ifdef HAVE_VASPRINTF
|
||||
return vasprintf(buf, format, ap);
|
||||
#else
|
||||
*buf = (char *) malloc(2048);
|
||||
return vsnprintf(*buf, 2048, format, ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
||||
*/
|
||||
+2
-13
@@ -48,13 +48,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_stream_write(switch_stream_handle
|
||||
}
|
||||
|
||||
va_start(ap, fmt);
|
||||
#ifdef HAVE_VASPRINTF
|
||||
ret = vasprintf(&data, fmt, ap);
|
||||
#else
|
||||
if ((data = (char *) malloc(2048))) {
|
||||
ret = vsnprintf(data, 2048, fmt, ap);
|
||||
}
|
||||
#endif
|
||||
ret = switch_vasprintf(&data, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (data) {
|
||||
@@ -145,12 +139,7 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const
|
||||
|
||||
handle = switch_core_data_channel(channel);
|
||||
|
||||
#ifdef HAVE_VASPRINTF
|
||||
ret = vasprintf(&data, fmt, ap);
|
||||
#else
|
||||
data = (char *) malloc(2048);
|
||||
ret = vsnprintf(data, 2048, fmt, ap);
|
||||
#endif
|
||||
ret = switch_vasprintf(&data, fmt, ap);
|
||||
va_end(ap);
|
||||
if (ret == -1) {
|
||||
fprintf(stderr, "Memory Error\n");
|
||||
|
||||
+24
-1
@@ -33,8 +33,31 @@
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <stdio.h>
|
||||
#include <switch_version.h>
|
||||
#ifndef WIN32
|
||||
#include <switch_private.h>
|
||||
#endif
|
||||
|
||||
/* for apr_pool_create and apr_pool_destroy */
|
||||
/* functions only used in this file so not exposed */
|
||||
#include <apr_pools.h>
|
||||
|
||||
/* for apr_hash_make, apr_hash_pool_get, apr_hash_set */
|
||||
/* functions only used in this file so not exposed */
|
||||
#include <apr_hash.h>
|
||||
|
||||
/* for apr_pvsprintf */
|
||||
/* function only used in this file so not exposed */
|
||||
#include <apr_strings.h>
|
||||
|
||||
/* for apr_initialize and apr_terminate */
|
||||
/* function only used in this file so not exposed */
|
||||
#include <apr_general.h>
|
||||
|
||||
#include <apr_portable.h>
|
||||
typedef apr_os_thread_t switch_thread_id_t;
|
||||
#define switch_thread_self apr_os_thread_current
|
||||
|
||||
|
||||
#ifdef HAVE_MLOCKALL
|
||||
#include <sys/mman.h>
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
* Portions created by the Initial Developer are Copyright (C)
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
*
|
||||
*
|
||||
* switch_core_db.c -- sqlite wrapper and extensions
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
SWITCH_DECLARE(int) switch_core_db_open(const char *filename, switch_core_db_t **ppDb)
|
||||
{
|
||||
return sqlite3_open(filename, ppDb);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_core_db_close(switch_core_db_t *db)
|
||||
{
|
||||
return sqlite3_close(db);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(const unsigned char *)switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol)
|
||||
{
|
||||
return sqlite3_column_text(stmt, iCol);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(const char *)switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N)
|
||||
{
|
||||
return sqlite3_column_name(stmt, N);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_core_db_column_count(switch_core_db_stmt_t *pStmt)
|
||||
{
|
||||
return sqlite3_column_count(pStmt);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(const char *)switch_core_db_errmsg(switch_core_db_t *db)
|
||||
{
|
||||
return sqlite3_errmsg(db);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db,
|
||||
const char *sql,
|
||||
switch_core_db_callback_func_t callback,
|
||||
void *data,
|
||||
char **errmsg)
|
||||
{
|
||||
return sqlite3_exec(db, sql, callback, data, errmsg);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_core_db_finalize(switch_core_db_stmt_t *pStmt)
|
||||
{
|
||||
return sqlite3_finalize(pStmt);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_core_db_prepare(switch_core_db_t *db,
|
||||
const char *zSql,
|
||||
int nBytes,
|
||||
switch_core_db_stmt_t **ppStmt,
|
||||
const char **pzTail)
|
||||
{
|
||||
return sqlite3_prepare(db, zSql, nBytes, ppStmt, pzTail);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_core_db_step(switch_core_db_stmt_t *stmt)
|
||||
{
|
||||
return sqlite3_step(stmt);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_core_db_free(char *z)
|
||||
{
|
||||
sqlite3_free(z);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char *)switch_mprintf(const char *zFormat,...)
|
||||
{
|
||||
va_list ap;
|
||||
char *z;
|
||||
va_start(ap, zFormat);
|
||||
z = sqlite3_vmprintf(zFormat, ap);
|
||||
va_end(ap);
|
||||
return z;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
||||
*/
|
||||
+1
-6
@@ -532,12 +532,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, con
|
||||
va_list ap;
|
||||
if (fmt) {
|
||||
va_start(ap, fmt);
|
||||
#ifdef HAVE_VASPRINTF
|
||||
ret = vasprintf(&data, fmt, ap);
|
||||
#else
|
||||
data = (char *) malloc(2048);
|
||||
ret = vsnprintf(data, 2048, fmt, ap);
|
||||
#endif
|
||||
ret = switch_vasprintf(&data, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (ret == -1) {
|
||||
|
||||
+13
-57
@@ -92,10 +92,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
char *cmd = switch_event_get_header(event, "call-command");
|
||||
unsigned long cmd_hash;
|
||||
apr_ssize_t hlen = APR_HASH_KEY_STRING;
|
||||
unsigned long CMD_EXECUTE = apr_hashfunc_default("execute", &hlen);
|
||||
unsigned long CMD_HANGUP = apr_hashfunc_default("hangup", &hlen);
|
||||
unsigned long CMD_NOMEDIA = apr_hashfunc_default("nomedia", &hlen);
|
||||
switch_ssize_t hlen = SWITCH_HASH_KEY_STRING;
|
||||
unsigned long CMD_EXECUTE = switch_hashfunc_default("execute", &hlen);
|
||||
unsigned long CMD_HANGUP = switch_hashfunc_default("hangup", &hlen);
|
||||
unsigned long CMD_NOMEDIA = switch_hashfunc_default("nomedia", &hlen);
|
||||
|
||||
assert(channel != NULL);
|
||||
assert(event != NULL);
|
||||
@@ -106,7 +106,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
|
||||
}
|
||||
|
||||
hlen = (switch_size_t) strlen(cmd);
|
||||
cmd_hash = apr_hashfunc_default(cmd, &hlen);
|
||||
cmd_hash = switch_hashfunc_default(cmd, &hlen);
|
||||
|
||||
switch_channel_set_flag(channel, CF_EVENT_PARSE);
|
||||
|
||||
@@ -1476,50 +1476,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
|
||||
return status;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_regex_match(char *target, char *expression) {
|
||||
const char* error = NULL; //Used to hold any errors
|
||||
int error_offset = 0; //Holds the offset of an error
|
||||
pcre* pcre_prepared = NULL; //Holds the compiled regex
|
||||
int match_count = 0; //Number of times the regex was matched
|
||||
int offset_vectors[2]; //not used, but has to exist or pcre won't even try to find a match
|
||||
|
||||
//Compile the expression
|
||||
pcre_prepared = pcre_compile(expression, 0, &error, &error_offset, NULL);
|
||||
|
||||
//See if there was an error in the expression
|
||||
if (error != NULL) {
|
||||
//Clean up after ourselves
|
||||
if (pcre_prepared) {
|
||||
pcre_free(pcre_prepared);
|
||||
pcre_prepared = NULL;
|
||||
}
|
||||
|
||||
//Note our error
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Regular Expression Error expression[%s] error[%s] location[%d]\n", expression, error, error_offset);
|
||||
|
||||
//We definitely didn't match anything
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
//So far so good, run the regex
|
||||
match_count = pcre_exec(pcre_prepared, NULL, target, (int) strlen(target), 0, 0, offset_vectors, sizeof(offset_vectors) / sizeof(offset_vectors[0]));
|
||||
|
||||
//Clean up
|
||||
if (pcre_prepared) {
|
||||
pcre_free(pcre_prepared);
|
||||
pcre_prepared = NULL;
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "number of matches: %d\n", match_count);
|
||||
|
||||
//Was it a match made in heaven?
|
||||
if (match_count > 0) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
} else {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t *session,
|
||||
uint32_t min_digits,
|
||||
uint32_t max_digits,
|
||||
@@ -4830,7 +4786,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
|
||||
char *pattern = (char *) switch_xml_attr(input, "pattern");
|
||||
|
||||
if (pattern) {
|
||||
pcre *re = NULL;
|
||||
switch_regex_t *re = NULL;
|
||||
int proceed = 0, ovector[30];
|
||||
char *substituted = NULL;
|
||||
uint32_t len = 0;
|
||||
@@ -4838,7 +4794,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
|
||||
char *expanded = NULL;
|
||||
switch_xml_t match = NULL;
|
||||
|
||||
if ((proceed = switch_perform_regex(data, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if ((proceed = switch_regex_perform(data, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
match = switch_xml_child(input, "match");
|
||||
} else {
|
||||
match = switch_xml_child(input, "nomatch");
|
||||
@@ -4854,7 +4810,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
|
||||
len = (uint32_t)(strlen(data) + strlen(adata) + 10);
|
||||
if (!(substituted = malloc(len))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
|
||||
switch_clean_re(re);
|
||||
switch_regex_safe_free(re);
|
||||
switch_safe_free(expanded);
|
||||
goto done;
|
||||
}
|
||||
@@ -4907,7 +4863,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
|
||||
}
|
||||
}
|
||||
|
||||
switch_clean_re(re);
|
||||
switch_regex_safe_free(re);
|
||||
switch_safe_free(expanded);
|
||||
switch_safe_free(substituted);
|
||||
}
|
||||
@@ -5111,25 +5067,25 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
|
||||
if (!(time_tag = switch_xml_add_child_d(x_times, "created_time", t_off++))) {
|
||||
goto error;
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp), "%"APR_TIME_T_FMT, caller_profile->times->created);
|
||||
snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, caller_profile->times->created);
|
||||
switch_xml_set_txt_d(time_tag, tmp);
|
||||
|
||||
if (!(time_tag = switch_xml_add_child_d(x_times, "answered_time", t_off++))) {
|
||||
goto error;
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp), "%"APR_TIME_T_FMT, caller_profile->times->answered);
|
||||
snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, caller_profile->times->answered);
|
||||
switch_xml_set_txt_d(time_tag, tmp);
|
||||
|
||||
if (!(time_tag = switch_xml_add_child_d(x_times, "hangup_time", t_off++))) {
|
||||
goto error;
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp), "%"APR_TIME_T_FMT, caller_profile->times->hungup);
|
||||
snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, caller_profile->times->hungup);
|
||||
switch_xml_set_txt_d(time_tag, tmp);
|
||||
|
||||
if (!(time_tag = switch_xml_add_child_d(x_times, "transfer_time", t_off++))) {
|
||||
goto error;
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp), "%"APR_TIME_T_FMT, caller_profile->times->transferred);
|
||||
snprintf(tmp, sizeof(tmp), "%"SWITCH_TIME_T_FMT, caller_profile->times->transferred);
|
||||
switch_xml_set_txt_d(time_tag, tmp);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,15 @@
|
||||
*
|
||||
*/
|
||||
#include <switch.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* for apr_pstrcat */
|
||||
#include <apr_strings.h>
|
||||
|
||||
/* for apr_env_get and apr_env_set */
|
||||
#include <apr_env.h>
|
||||
|
||||
/* for apr file and directory handling */
|
||||
#include <apr_file_io.h>
|
||||
|
||||
struct switch_loadable_module {
|
||||
char *filename;
|
||||
@@ -360,11 +368,11 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
|
||||
static switch_status_t switch_loadable_module_load_file(char *filename, switch_loadable_module_t **new_module)
|
||||
{
|
||||
switch_loadable_module_t *module = NULL;
|
||||
apr_dso_handle_t *dso = NULL;
|
||||
switch_dso_handle_t *dso = NULL;
|
||||
apr_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
apr_dso_handle_sym_t load_function_handle = NULL;
|
||||
apr_dso_handle_sym_t shutdown_function_handle = NULL;
|
||||
apr_dso_handle_sym_t runtime_function_handle = NULL;
|
||||
switch_dso_handle_sym_t load_function_handle = NULL;
|
||||
switch_dso_handle_sym_t shutdown_function_handle = NULL;
|
||||
switch_dso_handle_sym_t runtime_function_handle = NULL;
|
||||
switch_module_load_t load_func_ptr = NULL;
|
||||
int loading = 1;
|
||||
const char *err = NULL;
|
||||
@@ -374,16 +382,16 @@ static switch_status_t switch_loadable_module_load_file(char *filename, switch_l
|
||||
assert(filename != NULL);
|
||||
|
||||
*new_module = NULL;
|
||||
status = apr_dso_load(&dso, filename, loadable_modules.pool);
|
||||
status = switch_dso_load(&dso, filename, loadable_modules.pool);
|
||||
|
||||
while (loading) {
|
||||
if (status != APR_SUCCESS) {
|
||||
apr_dso_error(dso, derr, sizeof(derr));
|
||||
switch_dso_error(dso, derr, sizeof(derr));
|
||||
err = derr;
|
||||
break;
|
||||
}
|
||||
|
||||
status = apr_dso_sym(&load_function_handle, dso, "switch_module_load");
|
||||
status = switch_dso_sym(&load_function_handle, dso, "switch_module_load");
|
||||
load_func_ptr = (switch_module_load_t)(intptr_t) load_function_handle;
|
||||
|
||||
if (load_func_ptr == NULL) {
|
||||
@@ -414,9 +422,9 @@ static switch_status_t switch_loadable_module_load_file(char *filename, switch_l
|
||||
module->module_interface = module_interface;
|
||||
module->switch_module_load = load_func_ptr;
|
||||
|
||||
apr_dso_sym(&shutdown_function_handle, dso, "switch_module_shutdown");
|
||||
switch_dso_sym(&shutdown_function_handle, dso, "switch_module_shutdown");
|
||||
module->switch_module_shutdown = (switch_module_shutdown_t)(intptr_t) shutdown_function_handle;
|
||||
apr_dso_sym(&runtime_function_handle, dso, "switch_module_runtime");
|
||||
switch_dso_sym(&runtime_function_handle, dso, "switch_module_runtime");
|
||||
module->switch_module_runtime = (switch_module_runtime_t)(intptr_t) runtime_function_handle;
|
||||
|
||||
module->lib = dso;
|
||||
@@ -700,7 +708,7 @@ SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping: %s\n", module->module_interface->module_name);
|
||||
if (module->switch_module_shutdown() == SWITCH_STATUS_UNLOAD) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s unloaded.\n", module->module_interface->module_name);
|
||||
apr_dso_unload(module->lib);
|
||||
switch_dso_unload(module->lib);
|
||||
module->lib = NULL;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s shutdown.\n", module->module_interface->module_name);
|
||||
|
||||
+1
-6
@@ -193,12 +193,7 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
|
||||
fmt = new_fmt;
|
||||
}
|
||||
|
||||
#ifdef HAVE_VASPRINTF
|
||||
ret = vasprintf(&data, fmt, ap);
|
||||
#else
|
||||
data = (char *) malloc(2048);
|
||||
ret = vsnprintf(data, 2048, fmt, ap);
|
||||
#endif
|
||||
ret = switch_vasprintf(&data, fmt, ap);
|
||||
va_end(ap);
|
||||
if (ret == -1) {
|
||||
fprintf(stderr, "Memory Error\n");
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* 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
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
* Portions created by the Initial Developer are Copyright (C)
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
*
|
||||
*
|
||||
* switch_regex.c -- PCRE wrapper
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <pcre.h>
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
|
||||
int options,
|
||||
const char **errorptr,
|
||||
int *erroroffset,
|
||||
const unsigned char *tables)
|
||||
{
|
||||
return pcre_compile(pattern, options, errorptr, erroroffset, tables);
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_regex_copy_substring(const char *subject,
|
||||
int *ovector,
|
||||
int stringcount,
|
||||
int stringnumber,
|
||||
char *buffer,
|
||||
int size)
|
||||
{
|
||||
return pcre_copy_substring(subject, ovector, stringcount, stringnumber, buffer, size);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(void) switch_regex_free(void *data)
|
||||
{
|
||||
pcre_free(data);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_regex_perform(char *field, char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
|
||||
{
|
||||
const char *error = NULL;
|
||||
int erroffset = 0;
|
||||
pcre *re = NULL;
|
||||
int match_count = 0;
|
||||
|
||||
if (!(field && expression)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
re = pcre_compile(expression, /* the pattern */
|
||||
0, /* default options */
|
||||
&error, /* for error message */
|
||||
&erroffset, /* for error offset */
|
||||
NULL); /* use default character tables */
|
||||
if (error) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s]\n", erroffset, error);
|
||||
switch_regex_safe_free(re);
|
||||
return 0;
|
||||
}
|
||||
|
||||
match_count = pcre_exec(re, /* result of pcre_compile() */
|
||||
NULL, /* we didn't study the pattern */
|
||||
field, /* the subject string */
|
||||
(int) strlen(field), /* the length of the subject string */
|
||||
0, /* start at offset 0 in the subject */
|
||||
0, /* default options */
|
||||
ovector, /* vector of integers for substring information */
|
||||
olen); /* number of elements (NOT size in bytes) */
|
||||
|
||||
if (match_count <= 0) {
|
||||
switch_regex_safe_free(re);
|
||||
match_count = 0;
|
||||
}
|
||||
|
||||
*new_re = (switch_regex_t *)re;
|
||||
|
||||
return match_count;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(void) switch_perform_substitution(switch_regex_t *re, int match_count, char *data, char *field_data, char *substituted, uint32_t len, int *ovector)
|
||||
{
|
||||
char index[10] = "";
|
||||
char replace[1024] = "";
|
||||
uint32_t x, y = 0, z = 0, num = 0;
|
||||
|
||||
for (x = 0; x < (len-1) && x < strlen(data);) {
|
||||
if (data[x] == '$') {
|
||||
x++;
|
||||
|
||||
if (!(data[x] > 47 && data[x] < 58)) {
|
||||
substituted[y++] = data[x-1];
|
||||
continue;
|
||||
}
|
||||
|
||||
while (data[x] > 47 && data[x] < 58) {
|
||||
index[z++] = data[x];
|
||||
x++;
|
||||
}
|
||||
index[z++] = '\0';
|
||||
z = 0;
|
||||
num = atoi(index);
|
||||
|
||||
if (pcre_copy_substring(field_data,
|
||||
ovector,
|
||||
match_count,
|
||||
num,
|
||||
replace,
|
||||
sizeof(replace)) > 0) {
|
||||
unsigned int r;
|
||||
for (r = 0; r < strlen(replace); r++) {
|
||||
substituted[y++] = replace[r];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
substituted[y++] = data[x];
|
||||
x++;
|
||||
}
|
||||
}
|
||||
substituted[y++] = '\0';
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_regex_match(char *target, char *expression) {
|
||||
const char* error = NULL; //Used to hold any errors
|
||||
int error_offset = 0; //Holds the offset of an error
|
||||
pcre* pcre_prepared = NULL; //Holds the compiled regex
|
||||
int match_count = 0; //Number of times the regex was matched
|
||||
int offset_vectors[2]; //not used, but has to exist or pcre won't even try to find a match
|
||||
|
||||
//Compile the expression
|
||||
pcre_prepared = pcre_compile(expression, 0, &error, &error_offset, NULL);
|
||||
|
||||
//See if there was an error in the expression
|
||||
if (error != NULL) {
|
||||
//Clean up after ourselves
|
||||
if (pcre_prepared) {
|
||||
pcre_free(pcre_prepared);
|
||||
pcre_prepared = NULL;
|
||||
}
|
||||
|
||||
//Note our error
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Regular Expression Error expression[%s] error[%s] location[%d]\n", expression, error, error_offset);
|
||||
|
||||
//We definitely didn't match anything
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
//So far so good, run the regex
|
||||
match_count = pcre_exec(pcre_prepared, NULL, target, (int) strlen(target), 0, 0, offset_vectors, sizeof(offset_vectors) / sizeof(offset_vectors[0]));
|
||||
|
||||
//Clean up
|
||||
if (pcre_prepared) {
|
||||
pcre_free(pcre_prepared);
|
||||
pcre_prepared = NULL;
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "number of matches: %d\n", match_count);
|
||||
|
||||
//Was it a match made in heaven?
|
||||
if (match_count > 0) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
} else {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
||||
*/
|
||||
+8
-8
@@ -242,7 +242,7 @@ static void handle_ice(switch_rtp_t *rtp_session, void *data, switch_size_t len)
|
||||
remote_ip = switch_get_addr(ipbuf, sizeof(ipbuf), rtp_session->from_addr);
|
||||
|
||||
|
||||
switch_stun_packet_attribute_add_binded_address(rpacket, remote_ip, rtp_session->from_addr->port);
|
||||
switch_stun_packet_attribute_add_binded_address(rpacket, remote_ip, switch_sockaddr_get_port(rtp_session->from_addr));
|
||||
bytes = switch_stun_packet_length(rpacket);
|
||||
switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void*)rpacket, &bytes);
|
||||
}
|
||||
@@ -310,7 +310,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s
|
||||
new_sock = NULL;
|
||||
|
||||
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
|
||||
switch_socket_opt_set(rtp_session->sock, APR_SO_NONBLOCK, TRUE);
|
||||
switch_socket_opt_set(rtp_session->sock, SWITCH_SO_NONBLOCK, TRUE);
|
||||
switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session)
|
||||
switch_mutex_lock(rtp_session->flag_mutex);
|
||||
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
|
||||
assert(rtp_session->sock != NULL);
|
||||
apr_socket_shutdown(rtp_session->sock, APR_SHUTDOWN_READWRITE);
|
||||
switch_socket_shutdown(rtp_session->sock, SWITCH_SHUTDOWN_READWRITE);
|
||||
switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_IO);
|
||||
}
|
||||
switch_mutex_unlock(rtp_session->flag_mutex);
|
||||
@@ -869,21 +869,21 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
|
||||
|
||||
|
||||
if (rtp_session->recv_msg.header.version) {
|
||||
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && rtp_session->from_addr->port) {
|
||||
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
|
||||
char *tx_host;
|
||||
char *old_host;
|
||||
char bufa[30], bufb[30];
|
||||
tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
|
||||
old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
|
||||
|
||||
if ((rtp_session->from_addr->port != rtp_session->remote_port) || strcmp(tx_host, old_host)) {
|
||||
if ((switch_sockaddr_get_port(rtp_session->from_addr) != rtp_session->remote_port) || strcmp(tx_host, old_host)) {
|
||||
const char *err;
|
||||
uint32_t old = rtp_session->remote_port;
|
||||
|
||||
if (!switch_strlen_zero(tx_host) && rtp_session->from_addr->port > 0) {
|
||||
if (!switch_strlen_zero(tx_host) && switch_sockaddr_get_port(rtp_session->from_addr) > 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Auto Changing port from %s:%u to %s:%u\n",
|
||||
old_host, old, tx_host, rtp_session->from_addr->port);
|
||||
switch_rtp_set_remote_address(rtp_session, tx_host, rtp_session->from_addr->port, &err);
|
||||
old_host, old, tx_host, switch_sockaddr_get_port(rtp_session->from_addr));
|
||||
switch_rtp_set_remote_address(rtp_session, tx_host, switch_sockaddr_get_port(rtp_session->from_addr), &err);
|
||||
}
|
||||
}
|
||||
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
|
||||
|
||||
+3
-3
@@ -100,7 +100,7 @@ SWITCH_DECLARE(void) switch_stun_random_string(char *buf, uint16_t len, char *se
|
||||
|
||||
max = (int)strlen(set);
|
||||
|
||||
srand((unsigned int)apr_time_now());
|
||||
srand((unsigned int)switch_time_now());
|
||||
|
||||
for(x = 0; x < len; x++) {
|
||||
int j = (int)(max*1.0*rand()/(RAND_MAX+1.0));
|
||||
@@ -313,7 +313,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup (char **ip,
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
switch_socket_opt_set(sock, APR_SO_NONBLOCK, TRUE);
|
||||
switch_socket_opt_set(sock, SWITCH_SO_NONBLOCK, TRUE);
|
||||
packet = switch_stun_packet_build_header(SWITCH_STUN_BINDING_REQUEST, NULL, buf);
|
||||
switch_stun_random_string(username, 32, NULL);
|
||||
switch_stun_packet_attribute_add_username(packet, username, 32);
|
||||
@@ -333,7 +333,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup (char **ip,
|
||||
|
||||
if ((elapsed = (unsigned int)((switch_time_now() - started) / 1000)) > 5000) {
|
||||
*err = "Timeout";
|
||||
switch_socket_shutdown(sock, APR_SHUTDOWN_READWRITE);
|
||||
switch_socket_shutdown(sock, SWITCH_SHUTDOWN_READWRITE);
|
||||
switch_socket_close(sock);
|
||||
return SWITCH_STATUS_TIMEOUT;
|
||||
}
|
||||
|
||||
+9
-164
@@ -30,9 +30,6 @@
|
||||
*
|
||||
*/
|
||||
#include <switch.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef WIN32
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
@@ -193,97 +190,12 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int fam
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(int) switch_perform_regex(char *field, char *expression, pcre **new_re, int *ovector, uint32_t olen)
|
||||
{
|
||||
const char *error = NULL;
|
||||
int erroffset = 0;
|
||||
pcre *re = NULL;
|
||||
int match_count = 0;
|
||||
|
||||
if (!(field && expression)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
re = pcre_compile(expression, /* the pattern */
|
||||
0, /* default options */
|
||||
&error, /* for error message */
|
||||
&erroffset, /* for error offset */
|
||||
NULL); /* use default character tables */
|
||||
if (error) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s]\n", erroffset, error);
|
||||
switch_clean_re(re);
|
||||
return 0;
|
||||
}
|
||||
|
||||
match_count = pcre_exec(re, /* result of pcre_compile() */
|
||||
NULL, /* we didn't study the pattern */
|
||||
field, /* the subject string */
|
||||
(int) strlen(field), /* the length of the subject string */
|
||||
0, /* start at offset 0 in the subject */
|
||||
0, /* default options */
|
||||
ovector, /* vector of integers for substring information */
|
||||
olen); /* number of elements (NOT size in bytes) */
|
||||
|
||||
if (match_count <= 0) {
|
||||
switch_clean_re(re);
|
||||
match_count = 0;
|
||||
}
|
||||
|
||||
*new_re = re;
|
||||
|
||||
return match_count;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(void) switch_perform_substitution(pcre *re, int match_count, char *data, char *field_data, char *substituted, uint32_t len, int *ovector)
|
||||
{
|
||||
char index[10] = "";
|
||||
char replace[1024] = "";
|
||||
uint32_t x, y = 0, z = 0, num = 0;
|
||||
|
||||
for (x = 0; x < (len-1) && x < strlen(data);) {
|
||||
if (data[x] == '$') {
|
||||
x++;
|
||||
|
||||
if (!(data[x] > 47 && data[x] < 58)) {
|
||||
substituted[y++] = data[x-1];
|
||||
continue;
|
||||
}
|
||||
|
||||
while (data[x] > 47 && data[x] < 58) {
|
||||
index[z++] = data[x];
|
||||
x++;
|
||||
}
|
||||
index[z++] = '\0';
|
||||
z = 0;
|
||||
num = atoi(index);
|
||||
|
||||
if (pcre_copy_substring(field_data,
|
||||
ovector,
|
||||
match_count,
|
||||
num,
|
||||
replace,
|
||||
sizeof(replace)) > 0) {
|
||||
unsigned int r;
|
||||
for (r = 0; r < strlen(replace); r++) {
|
||||
substituted[y++] = replace[r];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
substituted[y++] = data[x];
|
||||
x++;
|
||||
}
|
||||
}
|
||||
substituted[y++] = '\0';
|
||||
}
|
||||
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_time_t) switch_str_time(char *in)
|
||||
{
|
||||
switch_time_exp_t tm = {0};
|
||||
int proceed = 0, ovector[30];
|
||||
pcre *re = NULL;
|
||||
switch_regex_t *re = NULL;
|
||||
char replace[1024] = "";
|
||||
switch_time_t ret = 0;
|
||||
char *pattern = "^(\\d+)-(\\d+)-(\\d+)\\s*(\\d*):{0,1}(\\d*):{0,1}(\\d*)";
|
||||
@@ -291,39 +203,39 @@ SWITCH_DECLARE(switch_time_t) switch_str_time(char *in)
|
||||
switch_time_exp_lt(&tm, switch_time_now());
|
||||
tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
|
||||
|
||||
if ((proceed = switch_perform_regex(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
if ((proceed = switch_regex_perform(in, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
|
||||
|
||||
if (proceed > 1) {
|
||||
pcre_copy_substring(in, ovector, proceed, 1, replace, sizeof(replace));
|
||||
switch_regex_copy_substring(in, ovector, proceed, 1, replace, sizeof(replace));
|
||||
tm.tm_year = atoi(replace) - 1900;
|
||||
}
|
||||
|
||||
if (proceed > 2) {
|
||||
pcre_copy_substring(in, ovector, proceed, 2, replace, sizeof(replace));
|
||||
switch_regex_copy_substring(in, ovector, proceed, 2, replace, sizeof(replace));
|
||||
tm.tm_mon = atoi(replace) - 1;
|
||||
}
|
||||
|
||||
if (proceed > 3) {
|
||||
pcre_copy_substring(in, ovector, proceed, 3, replace, sizeof(replace));
|
||||
switch_regex_copy_substring(in, ovector, proceed, 3, replace, sizeof(replace));
|
||||
tm.tm_mday = atoi(replace);
|
||||
}
|
||||
|
||||
if (proceed > 4) {
|
||||
pcre_copy_substring(in, ovector, proceed, 4, replace, sizeof(replace));
|
||||
switch_regex_copy_substring(in, ovector, proceed, 4, replace, sizeof(replace));
|
||||
tm.tm_hour = atoi(replace);
|
||||
}
|
||||
|
||||
if (proceed > 5) {
|
||||
pcre_copy_substring(in, ovector, proceed, 5, replace, sizeof(replace));
|
||||
switch_regex_copy_substring(in, ovector, proceed, 5, replace, sizeof(replace));
|
||||
tm.tm_min = atoi(replace);
|
||||
}
|
||||
|
||||
if (proceed > 6) {
|
||||
pcre_copy_substring(in, ovector, proceed, 6, replace, sizeof(replace));
|
||||
switch_regex_copy_substring(in, ovector, proceed, 6, replace, sizeof(replace));
|
||||
tm.tm_sec = atoi(replace);
|
||||
}
|
||||
|
||||
apr_time_exp_gmt_get(&ret, &tm);
|
||||
switch_time_exp_gmt_get(&ret, &tm);
|
||||
return ret;
|
||||
} /* possible else with more patterns later */
|
||||
|
||||
@@ -331,20 +243,6 @@ SWITCH_DECLARE(switch_time_t) switch_str_time(char *in)
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename)
|
||||
{
|
||||
int32_t wanted = APR_FINFO_TYPE;
|
||||
apr_finfo_t info = {0};
|
||||
if (filename) {
|
||||
apr_stat(&info, filename, wanted, NULL);
|
||||
if (info.filetype != APR_NOFILE) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority)
|
||||
{
|
||||
switch(priority) { /*lol*/
|
||||
@@ -377,28 +275,6 @@ SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct in_addr *in
|
||||
return buf;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
|
||||
{
|
||||
return get_addr(buf, len, &in->sa.sin.sin_addr);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(apr_status_t) switch_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock,
|
||||
apr_int32_t flags, char *buf,
|
||||
apr_size_t *len)
|
||||
{
|
||||
apr_status_t r;
|
||||
|
||||
if ((r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) {
|
||||
from->port = ntohs(from->sa.sin.sin_port);
|
||||
/* from->ipaddr_ptr = &(from->sa.sin.sin_addr);
|
||||
* from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr);
|
||||
*/
|
||||
}
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char) switch_rfc2833_to_char(int event)
|
||||
{
|
||||
if (event > -1 && event < (int32_t) sizeof(RFC2833_CHARS)) {
|
||||
@@ -530,26 +406,6 @@ SWITCH_DECLARE(const char *) switch_cut_path(const char *in)
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_socket_t *sock,
|
||||
switch_int16_t flags, switch_memory_pool_t *pool)
|
||||
{
|
||||
switch_pollset_t *pollset;
|
||||
|
||||
if (switch_pollset_create(&pollset, 1, pool, flags) != SWITCH_STATUS_SUCCESS) {
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
poll->desc_type = SWITCH_POLL_SOCKET;
|
||||
poll->reqevents = flags;
|
||||
poll->desc.s = sock;
|
||||
poll->client_data = sock;
|
||||
|
||||
if (switch_pollset_add(pollset, poll) != SWITCH_STATUS_SUCCESS) {
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t string_len, const char *search, size_t search_len)
|
||||
{
|
||||
@@ -661,17 +517,6 @@ SWITCH_DECLARE(char *) switch_url_decode(char *s)
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
/* this forces certain symbols to not be optimized out of the dll */
|
||||
void include_me(void)
|
||||
{
|
||||
apr_socket_shutdown(NULL, 0);
|
||||
apr_socket_recvfrom(NULL, NULL, 0, NULL, NULL);
|
||||
apr_mcast_join(NULL, NULL, NULL, NULL);
|
||||
apr_socket_opt_set(NULL, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
|
||||
+4
-2
@@ -54,8 +54,10 @@
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef WIN32
|
||||
#include <switch_private.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user