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:
Michael Jerris
2007-03-09 20:44:13 +00:00
parent 2d78da120a
commit 42e78242a3
46 changed files with 4027 additions and 2067 deletions
@@ -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;
}
+6 -6
View File
@@ -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;
+6 -6
View File
@@ -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)) {
+7 -7
View File
@@ -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,
+1 -1
View File
@@ -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:
+2 -2
View File
@@ -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;
}
+1 -7
View File
@@ -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) {