Freeswitch-svn
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
April 2007
- 5 participants
- 221 discussions
[commit] r4850 - in freeswitch/trunk: libs/libdingaling/src src/mod/endpoints/mod_dingaling src/mod/endpoints/mod_sofia
by Freeswitch SVN 04 Apr '07
by Freeswitch SVN 04 Apr '07
04 Apr '07
Author: anthm
Date: Wed Apr 4 18:22:55 2007
New Revision: 4850
Modified:
freeswitch/trunk/libs/libdingaling/src/libdingaling.c
freeswitch/trunk/libs/libdingaling/src/libdingaling.h
freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
Log:
add avatars for dingalaing
Modified: freeswitch/trunk/libs/libdingaling/src/libdingaling.c
==============================================================================
--- freeswitch/trunk/libs/libdingaling/src/libdingaling.c (original)
+++ freeswitch/trunk/libs/libdingaling/src/libdingaling.c Wed Apr 4 18:22:55 2007
@@ -31,6 +31,11 @@
#ifndef _MSC_VER
#include <config.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#endif
#include <string.h>
@@ -74,6 +79,8 @@
static int opt_timeout = 30;
+static void sha1_hash(char *out, char *in);
+static int b64encode(unsigned char *in, uint32_t ilen, unsigned char *out, uint32_t olen);
static struct {
unsigned int flags;
@@ -82,6 +89,7 @@
apr_pool_t *memory_pool;
unsigned int id;
ldl_logger_t logger;
+ apr_hash_t *avatar_hash;
apr_thread_mutex_t *flag_mutex;
} globals;
@@ -152,6 +160,15 @@
void *private_data;
};
+struct ldl_avatar {
+ char *path;
+ char *from;
+ char *base64;
+ char hash[256];
+};
+
+typedef struct ldl_avatar ldl_avatar_t;
+
static void lowercase(char *str)
{
@@ -750,7 +767,54 @@
return IKS_FILTER_EAT;
}
-static void do_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message)
+static ldl_avatar_t *ldl_get_avatar(char *path, char *from)
+{
+ ldl_avatar_t *ap;
+ uint8_t image[8192];
+ unsigned char base64[9216] = "";
+ int fd = -1;
+ size_t bytes;
+ char *p;
+
+ if (path && (ap = (ldl_avatar_t *) apr_hash_get(globals.avatar_hash, path, APR_HASH_KEY_STRING))) {
+ return ap;
+ }
+
+ if (from && (ap = (ldl_avatar_t *) apr_hash_get(globals.avatar_hash, from, APR_HASH_KEY_STRING))) {
+ return ap;
+ }
+
+ if (!(path && from)) {
+ return NULL;
+ }
+
+ if ((fd = open(path, O_RDONLY, 0)) < 0) {
+ globals.logger(DL_LOG_ERR, "File %s does not exist!\n", path);
+ return NULL;
+ }
+
+ bytes = read(fd, image, sizeof(image));
+ close(fd);
+ fd = -1;
+
+ ap = malloc(sizeof(*ap));
+ assert(ap != NULL);
+ memset(ap, 0, sizeof(*ap));
+ sha1_hash(ap->hash, (char *)image);
+ ap->path = strdup(path);
+ ap->from = strdup(from);
+ if ((p = strchr(ap->from, '/'))) {
+ *p = '\0';
+ }
+ b64encode((unsigned char *)image, bytes, base64, sizeof(base64));
+ ap->base64 = strdup(base64);
+ apr_hash_set(globals.avatar_hash, ap->path, APR_HASH_KEY_STRING, ap);
+ apr_hash_set(globals.avatar_hash, ap->from, APR_HASH_KEY_STRING, ap);
+ return ap;
+}
+
+
+static void do_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message, char *avatar)
{
iks *pres;
char buf[512];
@@ -791,6 +855,20 @@
}
if (message || rpid) {
+ ldl_avatar_t *ap;
+
+ if (avatar) {
+ if ((ap = ldl_get_avatar(avatar, from))) {
+ if ((tag = iks_insert(pres, "x"))) {
+ iks *hash;
+ iks_insert_attrib(tag, "xmlns", "vcard-temp:x:update");
+ if ((hash = iks_insert(tag, "photo"))) {
+ iks_insert_cdata(hash, ap->hash, 0);
+ }
+ }
+ }
+ }
+
if ((tag = iks_insert(pres, "c"))) {
iks_insert_attrib(tag, "node", "http://www.freeswitch.org/xmpp/client/caps");
iks_insert_attrib(tag, "ver", "1.0.0.1");
@@ -975,7 +1053,8 @@
static const char c64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#define B64BUFFLEN 1024
-static int b64encode(unsigned char *in, uint32_t ilen, unsigned char *out, uint32_t olen) {
+static int b64encode(unsigned char *in, uint32_t ilen, unsigned char *out, uint32_t olen)
+{
int y=0,bytes=0;
uint32_t x=0;
unsigned int b=0,l=0;
@@ -988,7 +1067,7 @@
if(++y!=72) {
continue;
}
- out[bytes++] = '\n';
+ //out[bytes++] = '\n';
y=0;
}
}
@@ -1629,15 +1708,65 @@
return handle->login;
}
-void ldl_handle_send_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message)
+void ldl_handle_send_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message, char *avatar)
+{
+ do_presence(handle, from, to, type, rpid, message, avatar);
+}
+
+static void ldl_random_string(char *buf, uint16_t len, char *set)
{
- do_presence(handle, from, to, type, rpid, message);
+ char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ int max;
+ uint16_t x;
+
+ if (!set) {
+ set = chars;
+ }
+
+ max = (int) strlen(set);
+
+ srand((unsigned int) time(NULL));
+
+ for (x = 0; x < len; x++) {
+ int j = (int) (max * 1.0 * rand() / (RAND_MAX + 1.0));
+ buf[x] = set[j];
+ }
}
+
void ldl_handle_send_vcard(ldl_handle_t *handle, char *from, char *to, char *id, char *vcard)
{
iks *vxml, *iq;
int e = 0;
+ ldl_avatar_t *ap;
+
+ ap = ldl_get_avatar(NULL, from);
+
+ if (!vcard) {
+ char text[8192];
+ char *ext;
+ if (!ap) {
+ return;
+ }
+
+ if ((ext = strrchr(ap->path, '.'))) {
+ ext++;
+ } else {
+ ext = "png";
+ }
+
+ snprintf(text, sizeof(text),
+ "<vCard xmlns='vcard-temp'><PHOTO><TYPE>image/%s</TYPE><BINVAL>%s</BINVAL></PHOTO></vCard>",
+ ext,
+ ap->base64
+ );
+ vcard = text;
+ } else {
+ if (ap && (strstr(vcard, "photo") || strstr(vcard, "PHOTO"))) {
+ ldl_random_string(ap->hash, sizeof(ap->hash), NULL);
+ }
+ }
+
if (!(vxml = iks_tree(vcard, 0, &e))) {
globals.logger(DL_LOG_ERR, "Parse returned error [%d]\n", e);
@@ -2016,6 +2145,7 @@
globals.debug = debug;
globals.id = 300;
globals.logger = default_logger;
+ globals.avatar_hash = apr_hash_make(globals.memory_pool);
ldl_set_flag_locked((&globals), LDL_FLAG_INIT);
return LDL_STATUS_SUCCESS;
Modified: freeswitch/trunk/libs/libdingaling/src/libdingaling.h
==============================================================================
--- freeswitch/trunk/libs/libdingaling/src/libdingaling.h (original)
+++ freeswitch/trunk/libs/libdingaling/src/libdingaling.h Wed Apr 4 18:22:55 2007
@@ -439,8 +439,9 @@
\param type the type of presence
\param rpid data for the icon
\param message a status message
+ \param avatar the path to an avatar image
*/
-void ldl_handle_send_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message);
+void ldl_handle_send_presence(ldl_handle_t *handle, char *from, char *to, char *type, char *rpid, char *message, char *avatar);
/*!
\brief Send a vcard
Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c Wed Apr 4 18:22:55 2007
@@ -118,11 +118,17 @@
char *context;
char *timer_name;
char *dbname;
+ char *avatar;
#ifdef SWITCH_HAVE_ODBC
char *odbc_dsn;
char *odbc_user;
char *odbc_pass;
switch_odbc_handle_t *master_odbc;
+#else
+ void *filler1;
+ void *filler2;
+ void *filler3;
+ void *filler4;
#endif
switch_mutex_t *mutex;
ldl_handle_t *handle;
@@ -361,7 +367,7 @@
rpid = translate_rpid(rpid, status);
//ldl_handle_send_presence(profile->handle, sub_to, sub_from, "probe", rpid, status);
- ldl_handle_send_presence(profile->handle, sub_to, sub_from, type, rpid, status);
+ ldl_handle_send_presence(profile->handle, sub_to, sub_from, type, rpid, status, profile->avatar);
return 0;
@@ -384,7 +390,7 @@
}
}
- ldl_handle_send_presence(profile->handle, sub_to, sub_from, NULL, show, status);
+ ldl_handle_send_presence(profile->handle, sub_to, sub_from, NULL, show, status, profile->avatar);
return 0;
}
@@ -588,7 +594,7 @@
char *sub_to = argv[1];
- ldl_handle_send_presence(profile->handle, sub_to, sub_from, "unavailable", "dnd", "Bub-Bye");
+ ldl_handle_send_presence(profile->handle, sub_to, sub_from, "unavailable", "dnd", "Bub-Bye", profile->avatar);
return 0;
}
@@ -1180,7 +1186,7 @@
We should find out why.....
*/
if ((tech_pvt->profile->user_flags & LDL_FLAG_COMPONENT) && is_special(tech_pvt->them)) {
- ldl_handle_send_presence(tech_pvt->profile->handle, tech_pvt->them, tech_pvt->us, NULL, NULL, "Click To Call");
+ ldl_handle_send_presence(tech_pvt->profile->handle, tech_pvt->them, tech_pvt->us, NULL, NULL, "Click To Call", tech_pvt->profile->avatar);
}
if (tech_pvt->dlsession) {
if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
@@ -1881,6 +1887,8 @@
profile->login = switch_core_strdup(module_pool, val);
} else if (!strcasecmp(var, "password")) {
profile->password = switch_core_strdup(module_pool, val);
+ } else if (!strcasecmp(var, "avatar")) {
+ profile->avatar = switch_core_strdup(module_pool, val);
} else if (!strcasecmp(var, "odbc-dsn")) {
#ifdef SWITCH_HAVE_ODBC
profile->odbc_dsn = switch_core_strdup(module_pool, val);
@@ -2164,10 +2172,11 @@
}
-static void do_vcard(ldl_handle_t * handle, char *to, char *from, char *id)
+static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
{
char *params = NULL, *real_to, *to_user, *xmlstr = NULL, *to_host = NULL;
switch_xml_t domain, xml = NULL, user, vcard;
+ int sent = 0;
if (!strncasecmp(to, "user+", 5)) {
real_to = to + 5;
@@ -2197,17 +2206,17 @@
if (switch_xml_locate("directory", "domain", "name", to_host, &xml, &domain, params) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find domain for [%s@%s]\n", to_user, to_host);
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find domain for [%s@%s]\n", to_user, to_host);
goto end;
}
if (!(user = switch_xml_find_child(domain, "user", "id", to_user))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", to_user, to_host);
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", to_user, to_host);
goto end;
}
if (!(vcard = switch_xml_child(user, "vcard"))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find <vcard> tag for user [%s@%s]\n", to_user, to_host);
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find <vcard> tag for user [%s@%s]\n", to_user, to_host);
goto end;
}
@@ -2215,11 +2224,17 @@
if ((xmlstr = switch_xml_toxml(vcard))) {
ldl_handle_send_vcard(handle, to, from, id, xmlstr);
+ sent = 1;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
}
end:
+
+ if (!sent) {
+ ldl_handle_send_vcard(handle, to, from, id, NULL);
+ }
+
if (xml)
switch_xml_free(xml);
switch_safe_free(to_user);
@@ -2280,7 +2295,7 @@
}
switch_mutex_unlock(profile->mutex);
if (is_special(to)) {
- ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
+ ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
}
#if 0
if (is_special(to)) {
@@ -2305,7 +2320,7 @@
break;
case LDL_SIGNAL_PRESENCE_PROBE:
if (is_special(to)) {
- ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
+ ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
} else {
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
@@ -2335,7 +2350,7 @@
if (is_special(to)) {
- ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
+ ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
}
#if 0
if (is_special(to)) {
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed Apr 4 18:22:55 2007
@@ -230,6 +230,11 @@
char *odbc_user;
char *odbc_pass;
switch_odbc_handle_t *master_odbc;
+#else
+ void *filler1;
+ void *filler2;
+ void *filler3;
+ void *filler4;
#endif
};
1
0
[commit] r4849 - in freeswitch/trunk/src: . include mod/languages/mod_spidermonkey_teletone
by Freeswitch SVN 04 Apr '07
by Freeswitch SVN 04 Apr '07
04 Apr '07
Author: anthm
Date: Wed Apr 4 14:22:59 2007
New Revision: 4849
Modified:
freeswitch/trunk/src/include/switch_buffer.h
freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
freeswitch/trunk/src/switch_buffer.c
freeswitch/trunk/src/switch_ivr_originate.c
Log:
add looping buffers
Modified: freeswitch/trunk/src/include/switch_buffer.h
==============================================================================
--- freeswitch/trunk/src/include/switch_buffer.h (original)
+++ freeswitch/trunk/src/include/switch_buffer.h Wed Apr 4 14:22:59 2007
@@ -96,6 +96,21 @@
*/
SWITCH_DECLARE(switch_size_t) switch_buffer_read(switch_buffer_t *buffer, void *data, switch_size_t datalen);
+/*! \brief Read data endlessly from a switch_buffer_t
+ * \param buffer any buffer of type switch_buffer_t
+ * \param data pointer to the read data to be returned
+ * \param datalen amount of data to be returned
+ * \return int ammount of data actually read
+ * \note Once you have read all the data from the buffer it will loop around.
+ */
+SWITCH_DECLARE(switch_size_t) switch_buffer_read_loop(switch_buffer_t *buffer, void *data, switch_size_t datalen);
+
+/*! \brief Assign a number of loops to read
+ * \param buffer any buffer of type switch_buffer_t
+ * \param loops the number of loops (-1 for infinite)
+ */
+SWITCH_DECLARE(void) switch_buffer_set_loops(switch_buffer_t *buffer, int32_t loops);
+
/*! \brief Write data into a switch_buffer_t up to the length of datalen
* \param buffer any buffer of type switch_buffer_t
* \param data pointer to the data to be written
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c (original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c Wed Apr 4 14:22:59 2007
@@ -46,7 +46,6 @@
switch_core_session_t *session;
switch_codec_t codec;
switch_buffer_t *audio_buffer;
- switch_buffer_t *loop_buffer;
switch_memory_pool_t *pool;
switch_timer_t *timer;
switch_timer_t timer_base;
@@ -158,7 +157,6 @@
}
teletone_destroy_session(&tto->ts);
switch_buffer_destroy(&tto->audio_buffer);
- switch_buffer_destroy(&tto->loop_buffer);
switch_core_codec_destroy(&tto->codec);
pool = tto->pool;
tto->pool = NULL;
@@ -221,17 +219,12 @@
return JS_FALSE;
}
loops--;
- if (!tto->loop_buffer) {
- switch_buffer_create_dynamic(&tto->loop_buffer, JS_BLOCK_SIZE, JS_BUFFER_SIZE, 0);
- }
}
if (tto->audio_buffer) {
switch_buffer_zero(tto->audio_buffer);
}
- if (tto->loop_buffer) {
- switch_buffer_zero(tto->loop_buffer);
- }
+
tto->ts.debug = 1;
tto->ts.debug_stream = switch_core_get_console();
@@ -250,12 +243,16 @@
}
}
+ if (loops) {
+ switch_buffer_set_loops(tto->audio_buffer, loops);
+ }
+
for (;;) {
if (switch_test_flag(tto, TTF_DTMF)) {
char dtmf[128];
char *ret;
-
+
if (switch_channel_has_dtmf(channel)) {
uintN aargc = 0;
jsval aargv[4];
@@ -284,23 +281,9 @@
break;
}
}
- if ((write_frame.datalen = (uint32_t) switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
- if (loops) {
- switch_buffer_t *tmp;
-
- /* Switcharoo */
- tmp = tto->audio_buffer;
- tto->audio_buffer = tto->loop_buffer;
- tto->loop_buffer = tmp;
- loops--;
- /* try again */
- if ((write_frame.datalen =
- (uint32_t) switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
- break;
- }
- } else {
- break;
- }
+ if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(tto->audio_buffer,
+ fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
+ break;
}
write_frame.samples = write_frame.datalen / 2;
@@ -310,9 +293,6 @@
break;
}
}
- if (tto->loop_buffer && loops) {
- switch_buffer_write(tto->loop_buffer, write_frame.data, write_frame.datalen);
- }
}
if (tto->timer) {
Modified: freeswitch/trunk/src/switch_buffer.c
==============================================================================
--- freeswitch/trunk/src/switch_buffer.c (original)
+++ freeswitch/trunk/src/switch_buffer.c Wed Apr 4 14:22:59 2007
@@ -48,6 +48,7 @@
switch_size_t blocksize;
uint32_t flags;
uint32_t id;
+ int32_t loops;
};
SWITCH_DECLARE(switch_status_t) switch_buffer_create(switch_memory_pool_t *pool, switch_buffer_t **buffer, switch_size_t max_len)
@@ -147,6 +148,26 @@
return buffer->used;
}
+SWITCH_DECLARE(void) switch_buffer_set_loops(switch_buffer_t *buffer, int32_t loops)
+{
+ buffer->loops = loops;
+}
+
+SWITCH_DECLARE(switch_size_t) switch_buffer_read_loop(switch_buffer_t *buffer, void *data, switch_size_t datalen)
+{
+ switch_size_t len;
+ if ((len = switch_buffer_read(buffer, data, datalen)) == 0) {
+ if (buffer->loops == 0) {
+ return 0;
+ }
+ buffer->head = buffer->data;
+ buffer->used = buffer->actually_used;
+ len = switch_buffer_read(buffer, data, datalen);
+ buffer->loops--;
+ }
+ return len;
+}
+
SWITCH_DECLARE(switch_size_t) switch_buffer_read(switch_buffer_t *buffer, void *data, switch_size_t datalen)
{
switch_size_t reading = 0;
Modified: freeswitch/trunk/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_originate.c (original)
+++ freeswitch/trunk/src/switch_ivr_originate.c Wed Apr 4 14:22:59 2007
@@ -210,7 +210,6 @@
struct ringback {
switch_buffer_t *audio_buffer;
- switch_buffer_t *loop_buffer;
teletone_generation_session_t ts;
switch_file_handle_t fhb;
switch_file_handle_t *fh;
@@ -623,7 +622,7 @@
char *tmp_data = NULL;
switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
- switch_buffer_create_dynamic(&ringback.loop_buffer, 512, 1024, 0);
+ switch_buffer_set_loops(ringback.audio_buffer, -1);
if (*ringback_data == '/') {
char *ext;
@@ -665,7 +664,6 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing Tone\n");
teletone_destroy_session(&ringback.ts);
switch_buffer_destroy(&ringback.audio_buffer);
- switch_buffer_destroy(&ringback.loop_buffer);
ringback_data = NULL;
}
}
@@ -747,27 +745,16 @@
break;
}
} else if (ringback.audio_buffer) {
- if ((write_frame.datalen = (uint32_t) switch_buffer_read(ringback.audio_buffer,
- write_frame.data,
- write_frame.codec->implementation->bytes_per_frame)) <= 0) {
- switch_buffer_t *tmp;
- tmp = ringback.audio_buffer;
- ringback.audio_buffer = ringback.loop_buffer;
- ringback.loop_buffer = tmp;
- if ((write_frame.datalen = (uint32_t) switch_buffer_read(ringback.audio_buffer,
- write_frame.data,
- write_frame.codec->implementation->bytes_per_frame)) <= 0) {
- break;
- }
+ if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(ringback.audio_buffer,
+ write_frame.data,
+ write_frame.codec->implementation->bytes_per_frame)) <= 0) {
+ break;
}
}
if (switch_core_session_write_frame(session, &write_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
break;
}
- if (ringback.loop_buffer) {
- switch_buffer_write(ringback.loop_buffer, write_frame.data, write_frame.datalen);
- }
}
} else {
@@ -908,7 +895,6 @@
} else if (ringback.audio_buffer) {
teletone_destroy_session(&ringback.ts);
switch_buffer_destroy(&ringback.audio_buffer);
- switch_buffer_destroy(&ringback.loop_buffer);
}
for (i = 0; i < and_argc; i++) {
1
0
[commit] r4848 - in freeswitch/trunk: libs/libdingaling/src src/mod/endpoints/mod_dingaling
by Freeswitch SVN 04 Apr '07
by Freeswitch SVN 04 Apr '07
04 Apr '07
Author: anthm
Date: Wed Apr 4 13:32:56 2007
New Revision: 4848
Modified:
freeswitch/trunk/libs/libdingaling/src/libdingaling.h
freeswitch/trunk/src/mod/endpoints/mod_dingaling/Makefile
freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
Log:
add odbc support for dingaling
Modified: freeswitch/trunk/libs/libdingaling/src/libdingaling.h
==============================================================================
--- freeswitch/trunk/libs/libdingaling/src/libdingaling.h (original)
+++ freeswitch/trunk/libs/libdingaling/src/libdingaling.h Wed Apr 4 13:32:56 2007
@@ -222,7 +222,7 @@
} else {
len = id_a_len;
}
- printf("[%s][%s][%d]\n", id_a_host, id_b_host, len);
+
return strncasecmp(id_a_host, id_b_host, len) ? 0 : 1;
}
return -1;
Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/Makefile (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/Makefile Wed Apr 4 13:32:56 2007
@@ -2,6 +2,7 @@
LOCAL_CFLAGS = `$(BASE)/libs/apr/apr-1-config --cflags --cppflags --includes`
LOCAL_CFLAGS += `$(BASE)/libs/apr-util/apu-1-config --includes`
+LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`
IKS_DIR=$(BASE)/libs/iksemel
IKS_LA=$(IKS_DIR)/src/libiksemel.la
Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c Wed Apr 4 13:32:56 2007
@@ -31,6 +31,9 @@
*/
#include <switch.h>
#include <libdingaling.h>
+#ifdef SWITCH_HAVE_ODBC
+#include <switch_odbc.h>
+#endif
#define DL_CAND_WAIT 10000000
#define DL_CAND_INITIAL_WAIT 2000000
@@ -45,8 +48,11 @@
static switch_memory_pool_t *module_pool = NULL;
static char sub_sql[] =
- "CREATE TABLE subscriptions (\n"
- " sub_from VARCHAR(255),\n" " sub_to VARCHAR(255),\n" " show VARCHAR(255),\n" " status VARCHAR(255)\n"
+ "CREATE TABLE jabber_subscriptions (\n"
+ " sub_from VARCHAR(255),\n"
+ " sub_to VARCHAR(255),\n"
+ " show_pres VARCHAR(255),\n"
+ " status VARCHAR(255)\n"
");\n";
@@ -112,18 +118,25 @@
char *context;
char *timer_name;
char *dbname;
+#ifdef SWITCH_HAVE_ODBC
+ char *odbc_dsn;
+ char *odbc_user;
+ char *odbc_pass;
+ switch_odbc_handle_t *master_odbc;
+#endif
switch_mutex_t *mutex;
ldl_handle_t *handle;
uint32_t flags;
uint32_t user_flags;
};
+typedef struct mdl_profile mdl_profile_t;
struct private_object {
unsigned int flags;
switch_codec_t read_codec;
switch_codec_t write_codec;
switch_frame_t read_frame;
- struct mdl_profile *profile;
+ mdl_profile_t *profile;
switch_core_session_t *session;
switch_caller_profile_t *caller_profile;
unsigned short samprate;
@@ -229,9 +242,109 @@
return r;
}
+
+
+
+static void mdl_execute_sql(mdl_profile_t *profile, char *sql, switch_mutex_t *mutex)
+{
+ switch_core_db_t *db;
+
+ if (mutex) {
+ switch_mutex_lock(mutex);
+ }
+
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ SQLHSTMT stmt;
+ if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
+ char *err_str;
+ err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+ switch_safe_free(err_str);
+ }
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ } else {
+#endif
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ goto end;
+ }
+
+ switch_core_db_persistant_execute(db, sql, 25);
+ switch_core_db_close(db);
+
+#ifdef SWITCH_HAVE_ODBC
+ }
+#endif
+
+
+ end:
+ if (mutex) {
+ switch_mutex_unlock(mutex);
+ }
+}
+
+
+static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
+ switch_mutex_t *mutex,
+ char *sql,
+ switch_core_db_callback_func_t callback,
+ void *pdata)
+{
+ switch_bool_t ret = SWITCH_FALSE;
+ switch_core_db_t *db;
+ char *errmsg = NULL;
+
+ if (mutex) {
+ switch_mutex_lock(mutex);
+ }
+
+
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
+ } else {
+#endif
+
+
+
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ goto end;
+ }
+
+
+ switch_core_db_exec(db, sql, callback, pdata, &errmsg);
+
+ if (errmsg) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+ free(errmsg);
+ }
+
+ if (db) {
+ switch_core_db_close(db);
+ }
+
+#ifdef SWITCH_HAVE_ODBC
+ }
+#endif
+
+
+ end:
+
+ if (mutex) {
+ switch_mutex_unlock(mutex);
+ }
+
+
+
+ return ret;
+
+}
+
static int sub_callback(void *pArg, int argc, char **argv, char **columnNames)
{
- struct mdl_profile *profile = (struct mdl_profile *) pArg;
+ mdl_profile_t *profile = (mdl_profile_t *) pArg;
char *sub_from = argv[0];
char *sub_to = argv[1];
@@ -256,7 +369,7 @@
static int rost_callback(void *pArg, int argc, char **argv, char **columnNames)
{
- struct mdl_profile *profile = (struct mdl_profile *) pArg;
+ mdl_profile_t *profile = (mdl_profile_t *) pArg;
char *sub_from = argv[0];
char *sub_to = argv[1];
@@ -278,7 +391,7 @@
static void pres_event_handler(switch_event_t *event)
{
- struct mdl_profile *profile = NULL;
+ mdl_profile_t *profile = NULL;
switch_hash_index_t *hi;
void *val;
char *proto = switch_event_get_header(event, "proto");
@@ -287,7 +400,7 @@
char *rpid = switch_event_get_header(event, "rpid");
char *type = switch_event_get_header(event, "event_subtype");
char *sql;
- switch_core_db_t *db;
+
if (!proto) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Missing 'proto' header\n");
@@ -307,8 +420,6 @@
case SWITCH_EVENT_PRESENCE_PROBE:
if (proto) {
char *sql;
- switch_core_db_t *db;
- char *errmsg;
char *to = switch_event_get_header(event, "to");
char *f_host = NULL;
if (to) {
@@ -318,15 +429,8 @@
}
if (f_host && (profile = switch_core_hash_find(globals.profile_hash, f_host))) {
- if (to && (sql = switch_mprintf("select * from subscriptions where sub_to='%q'", to))) {
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
- return;
- }
- switch_mutex_lock(profile->mutex);
- switch_core_db_exec(db, sql, sin_callback, profile, &errmsg);
- switch_mutex_unlock(profile->mutex);
- switch_core_db_close(db);
+ if (to && (sql = switch_mprintf("select * from jabber_subscriptions where sub_to='%q'", to))) {
+ mdl_execute_sql_callback(profile, profile->mutex, sql, sin_callback, profile);
switch_safe_free(sql);
}
}
@@ -356,13 +460,12 @@
}
- sql = switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
+ sql = switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
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;
+ profile = (mdl_profile_t *) val;
if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
continue;
@@ -370,14 +473,11 @@
if (sql) {
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ switch_bool_t worked = mdl_execute_sql_callback(profile, profile->mutex, sql, sub_callback, profile);
+
+ if (!worked) {
continue;
}
- switch_mutex_lock(profile->mutex);
- switch_core_db_exec(db, sql, sub_callback, profile, &errmsg);
- switch_mutex_unlock(profile->mutex);
- switch_core_db_close(db);
}
@@ -389,7 +489,7 @@
static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
{
char *user, *host, *f_user = NULL, *ffrom = NULL, *f_host = NULL, *f_resource = NULL;
- struct mdl_profile *profile = NULL;
+ mdl_profile_t *profile = NULL;
assert(proto != NULL);
@@ -438,11 +538,11 @@
char *status = switch_event_get_header(event, "status");
char *from = switch_event_get_header(event, "from");
char *event_type = switch_event_get_header(event, "event_type");
- struct mdl_profile *profile = NULL;
+ mdl_profile_t *profile = NULL;
switch_hash_index_t *hi;
void *val;
char *sql;
- switch_core_db_t *db;
+
if (status && !strcasecmp(status, "n/a")) {
status = NULL;
@@ -453,15 +553,14 @@
}
if (from) {
- sql = switch_mprintf("select *,'%q' from subscriptions where sub_from='%q'", status ? status : "", from);
+ sql = switch_mprintf("select *,'%q' from jabber_subscriptions where sub_from='%q'", status ? status : "", from);
} else {
- sql = switch_mprintf("select *,'%q' from subscriptions", status ? status : "");
+ sql = switch_mprintf("select *,'%q' from jabber_subscriptions", status ? status : "");
}
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;
+ profile = (mdl_profile_t *) val;
if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
continue;
@@ -469,14 +568,10 @@
if (sql) {
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ switch_bool_t worked = mdl_execute_sql_callback(profile, profile->mutex, sql, rost_callback, profile);
+ if (!worked) {
continue;
}
- switch_mutex_lock(profile->mutex);
- switch_core_db_exec(db, sql, rost_callback, profile, &errmsg);
- switch_mutex_unlock(profile->mutex);
- switch_core_db_close(db);
}
}
@@ -487,7 +582,7 @@
static int so_callback(void *pArg, int argc, char **argv, char **columnNames)
{
- struct mdl_profile *profile = (struct mdl_profile *) pArg;
+ mdl_profile_t *profile = (mdl_profile_t *) pArg;
char *sub_from = argv[0];
char *sub_to = argv[1];
@@ -501,7 +596,7 @@
static int sin_callback(void *pArg, int argc, char **argv, char **columnNames)
{
- struct mdl_profile *profile = (struct mdl_profile *) pArg;
+ mdl_profile_t *profile = (mdl_profile_t *) pArg;
switch_event_t *event;
//char *sub_from = argv[0];
@@ -523,20 +618,19 @@
static void sign_off(void)
{
- struct mdl_profile *profile = NULL;
+ mdl_profile_t *profile = NULL;
switch_hash_index_t *hi;
void *val;
char *sql;
- switch_core_db_t *db;
- sql = switch_mprintf("select * from subscriptions");
+
+ sql = switch_mprintf("select * from jabber_subscriptions");
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;
+ profile = (mdl_profile_t *) val;
if (!(profile->user_flags & LDL_FLAG_COMPONENT)) {
continue;
@@ -544,14 +638,10 @@
if (sql) {
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ switch_bool_t worked = mdl_execute_sql_callback(profile, profile->mutex, sql, so_callback, profile);
+ if (!worked) {
continue;
}
- switch_mutex_lock(profile->mutex);
- switch_core_db_exec(db, sql, so_callback, profile, &errmsg);
- switch_mutex_unlock(profile->mutex);
- switch_core_db_close(db);
}
}
@@ -561,21 +651,13 @@
}
-static void sign_on(struct mdl_profile *profile)
+static void sign_on(mdl_profile_t *profile)
{
char *sql;
- switch_core_db_t *db;
- char *errmsg;
- if ((sql = switch_mprintf("select * from subscriptions where sub_to like 'ext+%%' or sub_to like 'user+%%' or sub_to like 'conf+%%'"))) {
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
- return;
- }
- switch_mutex_lock(profile->mutex);
- switch_core_db_exec(db, sql, sin_callback, profile, &errmsg);
- switch_mutex_unlock(profile->mutex);
- switch_core_db_close(db);
+
+ if ((sql = switch_mprintf("select * from jabber_subscriptions where sub_to like 'ext+%%' or sub_to like 'user+%%' or sub_to like 'conf+%%'"))) {
+ mdl_execute_sql_callback(profile, profile->mutex, sql, sin_callback, profile);
switch_safe_free(sql);
}
}
@@ -656,7 +738,7 @@
static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t * thread, void *obj)
{
ldl_handle_t *handle = obj;
- struct mdl_profile *profile = NULL;
+ mdl_profile_t *profile = NULL;
@@ -1510,7 +1592,7 @@
struct private_object *tech_pvt;
switch_channel_t *channel;
switch_caller_profile_t *caller_profile = NULL;
- struct mdl_profile *mdl_profile = NULL;
+ mdl_profile_t *mdl_profile = NULL;
ldl_session_t *dlsession = NULL;
char *profile_name;
char *callto;
@@ -1727,7 +1809,7 @@
return LDL_STATUS_SUCCESS;
}
-static switch_status_t init_profile(struct mdl_profile *profile, uint8_t login)
+static switch_status_t init_profile(mdl_profile_t *profile, uint8_t login)
{
if (profile && profile->login && profile->password && profile->dialplan && profile->message && profile->ip && profile->name && profile->exten) {
ldl_handle_t *handle;
@@ -1792,13 +1874,27 @@
}
-static void set_profile_val(struct mdl_profile *profile, char *var, char *val)
+static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
{
if (!strcasecmp(var, "login")) {
profile->login = switch_core_strdup(module_pool, val);
} else if (!strcasecmp(var, "password")) {
profile->password = switch_core_strdup(module_pool, val);
+ } else if (!strcasecmp(var, "odbc-dsn")) {
+#ifdef SWITCH_HAVE_ODBC
+ profile->odbc_dsn = switch_core_strdup(module_pool, val);
+ if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
+ *profile->odbc_user++ = '\0';
+ }
+ if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
+ *profile->odbc_pass++ = '\0';
+ }
+
+
+#else
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
+#endif
} else if (!strcasecmp(var, "use-rtp-timer") && switch_true(val)) {
switch_set_flag(profile, TFLAG_TIMER);
} else if (!strcasecmp(var, "dialplan")) {
@@ -1853,7 +1949,7 @@
static switch_status_t dl_logout(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream)
{
- struct mdl_profile *profile;
+ mdl_profile_t *profile;
if (session) {
return SWITCH_STATUS_FALSE;
@@ -1879,7 +1975,7 @@
char *argv[10] = { 0 };
int argc = 0;
char *var, *val, *myarg;
- struct mdl_profile *profile = NULL;
+ mdl_profile_t *profile = NULL;
int x;
if (session) {
@@ -1938,7 +2034,7 @@
static switch_status_t load_config(void)
{
char *cf = "dingaling.conf";
- struct mdl_profile *profile = NULL;
+ mdl_profile_t *profile = NULL;
switch_xml_t cfg, xml, settings, param, xmlint;
memset(&globals, 0, sizeof(globals));
@@ -2010,13 +2106,34 @@
snprintf(dbname, sizeof(dbname), "dingaling_%s", profile->name);
profile->dbname = switch_core_strdup(module_pool, dbname);
- if ((db = switch_core_db_open_file(profile->dbname))) {
- switch_core_db_test_reactive(db, "select * from subscriptions", sub_sql);
+
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
+ continue;
+
+ }
+ if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
+ continue;
+ }
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
+ switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
+ //mdl_execute_sql(profile, sub_sql, NULL);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
- continue;
+#endif
+ if ((db = switch_core_db_open_file(profile->dbname))) {
+ switch_core_db_test_reactive(db, "select * from jabber_subscriptions", sub_sql);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
+ continue;
+ }
+ switch_core_db_close(db);
+#ifdef SWITCH_HAVE_ODBC
}
- switch_core_db_close(db);
+#endif
}
if (profile) {
@@ -2047,28 +2164,6 @@
}
-static void execute_sql(char *dbname, char *sql, switch_mutex_t * mutex)
-{
- switch_core_db_t *db;
-
- if (mutex) {
- switch_mutex_lock(mutex);
- }
-
- if (!(db = switch_core_db_open_file(dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", dbname);
- goto end;
- }
-
- switch_core_db_persistant_execute(db, sql, 25);
- switch_core_db_close(db);
-
- end:
- if (mutex) {
- switch_mutex_unlock(mutex);
- }
-}
-
static void do_vcard(ldl_handle_t * handle, char *to, char *from, char *id)
{
char *params = NULL, *real_to, *to_user, *xmlstr = NULL, *to_host = NULL;
@@ -2135,7 +2230,7 @@
static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject,
char *msg)
{
- struct mdl_profile *profile = NULL;
+ mdl_profile_t *profile = NULL;
switch_core_session_t *session = NULL;
switch_channel_t *channel = NULL;
struct private_object *tech_pvt = NULL;
@@ -2159,8 +2254,8 @@
break;
case LDL_SIGNAL_UNSUBSCRIBE:
- if ((sql = switch_mprintf("delete from subscriptions where sub_from='%q' and sub_to='%q';", from, to))) {
- execute_sql(profile->dbname, sql, profile->mutex);
+ if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q';", from, to))) {
+ mdl_execute_sql(profile, sql, profile->mutex);
switch_core_db_free(sql);
}
@@ -2170,12 +2265,20 @@
if (profile->user_flags & LDL_FLAG_COMPONENT && ldl_jid_domcmp(from, to)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Attempt to add presence from/to our own domain [%s][%s]\n", from, to);
} else {
- if ((sql = switch_mprintf("delete from subscriptions where sub_from='%q' and sub_to='%q';\n"
- "insert into subscriptions values('%q','%q','%q','%q');\n", from, to, from, to, msg, subject))) {
- execute_sql(profile->dbname, sql, profile->mutex);
+ switch_mutex_lock(profile->mutex);
+ if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q'", from, to))) {
+ mdl_execute_sql(profile, sql, NULL);
switch_core_db_free(sql);
}
-
+ if ((sql = switch_mprintf("insert into jabber_subscriptions values('%q','%q','%q','%q');\n",
+ switch_str_nil(from),
+ switch_str_nil(to),
+ switch_str_nil(msg),
+ switch_str_nil(subject)))) {
+ mdl_execute_sql(profile, sql, NULL);
+ switch_core_db_free(sql);
+ }
+ switch_mutex_unlock(profile->mutex);
if (is_special(to)) {
ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call");
}
@@ -2215,8 +2318,9 @@
break;
case LDL_SIGNAL_PRESENCE_IN:
- if ((sql = switch_mprintf("update subscriptions set show='%q', status='%q' where sub_from='%q'", msg, subject, from))) {
- execute_sql(profile->dbname, sql, profile->mutex);
+ if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
+ switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
+ mdl_execute_sql(profile, sql, profile->mutex);
switch_core_db_free(sql);
}
@@ -2249,8 +2353,9 @@
case LDL_SIGNAL_PRESENCE_OUT:
- if ((sql = switch_mprintf("update subscriptions set show='%q', status='%q' where sub_from='%q'", msg, subject, from))) {
- execute_sql(profile->dbname, sql, profile->mutex);
+ if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
+ switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
+ mdl_execute_sql(profile, sql, profile->mutex);
switch_core_db_free(sql);
}
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
1
0
04 Apr '07
Author: anthm
Date: Wed Apr 4 12:44:08 2007
New Revision: 4847
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
Log:
make invites use the same contact as the gateway when using a gateway to make calls
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Wed Apr 4 12:44:08 2007
@@ -888,6 +888,7 @@
} else {
tech_pvt->dest = switch_core_session_sprintf(nsession, "sip:%s", dest);
}
+ tech_pvt->invite_contact = switch_core_session_strdup(nsession, gateway_ptr->register_contact);
} else {
if (!(dest = strchr(profile_name, '/'))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed Apr 4 12:44:08 2007
@@ -286,6 +286,7 @@
char *chat_to;
char *e_dest;
char *call_id;
+ char *invite_contact;
unsigned long rm_rate;
switch_payload_t pt;
switch_mutex_t *flag_mutex;
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Apr 4 12:44:08 2007
@@ -472,7 +472,7 @@
TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)),
TAG_IF(!switch_strlen_zero(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)),
- //SIPTAG_CONTACT_STR(tech_pvt->profile->url),
+ TAG_IF(tech_pvt->invite_contact, SIPTAG_CONTACT_STR(tech_pvt->invite_contact)),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE),
SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END());
1
0
[commit] r4846 - in freeswitch/trunk: . src src/include src/mod/endpoints/mod_sofia src/mod/languages/mod_spidermonkey src/mod/languages/mod_spidermonkey_odbc
by Freeswitch SVN 04 Apr '07
by Freeswitch SVN 04 Apr '07
04 Apr '07
Author: anthm
Date: Tue Apr 3 23:08:17 2007
New Revision: 4846
Added:
freeswitch/trunk/src/include/switch_odbc.h
freeswitch/trunk/src/switch_odbc.c
Modified:
freeswitch/trunk/Makefile.am
freeswitch/trunk/configure.in
freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/Makefile
freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
Log:
add core ODBC
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Tue Apr 3 23:08:17 2007
@@ -103,6 +103,11 @@
CORE_LIBS = libs/apr/libapr-1.la libs/apr-util/libaprutil-1.la
CORE_LIBS += libs/sqlite/libsqlite3.la libs/pcre/libpcre.la
CORE_LIBS += libs/srtp/libsrtp.la $(RESAMPLE_LIB)
+if ADD_ODBC
+libfreeswitch_la_SOURCES += src/switch_odbc.c
+library_include_HEADERS += src/include/switch_odbc.h
+CORE_LIBS += -lodbc
+endif
lib_LTLIBRARIES = libfreeswitch.la
libfreeswitch_la_CFLAGS = $(CORE_CFLAGS) $(AM_CFLAGS)
Modified: freeswitch/trunk/configure.in
==============================================================================
--- freeswitch/trunk/configure.in (original)
+++ freeswitch/trunk/configure.in Tue Apr 3 23:08:17 2007
@@ -314,10 +314,14 @@
AC_ARG_ENABLE(crash-protection,
[ --enable-crash-protection Compile with CRASH Protection],,[enable_crash_prot="no"])
+AC_ARG_ENABLE(core-odbc-support,
+ [ --enable-core-odbc-support Compile with ODBC Support],,[enable_core_odbc_support="no"])
+
#AX_LIB_MYSQL([MINIMUM-VERSION])
AX_LIB_MYSQL
AM_CONDITIONAL([CRASHPROT],[test "x$enable_crash_prot" != "xno"])
+AM_CONDITIONAL([ADD_ODBC],[test "x$enable_core_odbc_support" != "xno"])
AM_CONDITIONAL([HAVE_MYSQL],[test "$have_mysql" = "yes"])
AC_CONFIG_FILES([Makefile
Added: freeswitch/trunk/src/include/switch_odbc.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/include/switch_odbc.h Tue Apr 3 23:08:17 2007
@@ -0,0 +1,82 @@
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct(a)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(a)yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Anthony Minessale II <anthmct(a)yahoo.com>
+ *
+ * switch_odbc.h -- ODBC
+ *
+ */
+
+#ifndef SWITCH_ODBC_H
+#define SWITCH_ODBC_H
+
+#include <switch.h>
+#include <sql.h>
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4201)
+#include <sqlext.h>
+#pragma warning(pop)
+#else
+#include <sqlext.h>
+#endif
+#include <sqltypes.h>
+
+SWITCH_BEGIN_EXTERN_C struct switch_odbc_handle;
+
+typedef enum {
+ SWITCH_ODBC_STATE_INIT,
+ SWITCH_ODBC_STATE_DOWN,
+ SWITCH_ODBC_STATE_CONNECTED,
+ SWITCH_ODBC_STATE_ERROR
+} switch_odbc_state_t;
+typedef struct switch_odbc_handle switch_odbc_handle_t;
+
+typedef enum {
+ SWITCH_ODBC_SUCCESS = 0,
+ SWITCH_ODBC_FAIL = -1
+} switch_odbc_status_t;
+
+SWITCH_DECLARE(switch_odbc_handle_t) * switch_odbc_handle_new(char *dsn, char *username, char *password);
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_handle_t *handle);
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_handle_t *handle);
+SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep);
+SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle);
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, SQLHSTMT * rstmt);
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odbc_handle_t *handle,
+ char *sql, switch_core_db_callback_func_t callback, void *pdata);
+SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, SQLHSTMT stmt);
+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:
+ */
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile Tue Apr 3 23:08:17 2007
@@ -12,6 +12,8 @@
LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/soa -I$(SOFIAUA_DIR)/sresolv
LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/stun -I$(SOFIAUA_DIR)/su
LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/tport -I$(SOFIAUA_DIR)/url
+LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`
+
LOCAL_OBJS=sofia.o sofia_glue.o sofia_presence.o sofia_reg.o
LOCAL_SOURCES=sofia.c sofia_glue.c sofia_presense.c sofia_reg.c mod_sofia.c
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Tue Apr 3 23:08:17 2007
@@ -40,6 +40,9 @@
#define HAVE_APR
#include <switch.h>
+#ifdef SWITCH_HAVE_ODBC
+#include <switch_odbc.h>
+#endif
static const char modname[] = "mod_sofia";
static const switch_state_handler_table_t noop_state_handler = { 0 };
@@ -221,6 +224,13 @@
su_home_t *home;
switch_hash_t *profile_hash;
switch_hash_t *chat_hash;
+ switch_core_db_t *master_db;
+#ifdef SWITCH_HAVE_ODBC
+ char *odbc_dsn;
+ char *odbc_user;
+ char *odbc_pass;
+ switch_odbc_handle_t *master_odbc;
+#endif
};
@@ -328,8 +338,6 @@
uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t * sdp);
-char *sofia_reg_get_auth_data(char *dbname, char *nonce, char *npassword, size_t len, switch_mutex_t * mutex);
-
void sofia_presence_establish_presence(sofia_profile_t * profile);
void sofia_handle_sip_i_state(int status,
@@ -387,8 +395,8 @@
sofia_profile_t *sofia_glue_find_profile(char *key);
void sofia_glue_add_profile(char *key, sofia_profile_t * profile);
-void sofia_glue_execute_sql(char *dbname, char *sql, switch_mutex_t * mutex);
-void sofia_reg_check_expire(switch_core_db_t *db, sofia_profile_t * profile, time_t now);
+void sofia_glue_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex);
+void sofia_reg_check_expire(sofia_profile_t * profile, time_t now);
void sofia_reg_check_gateway(sofia_profile_t * profile, time_t now);
void sofia_reg_unregister(sofia_profile_t * profile);
switch_status_t sofia_glue_ext_address_lookup(char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool);
@@ -404,3 +412,12 @@
switch_status_t sofia_on_hangup(switch_core_session_t *session);
char *sofia_glue_get_url_from_contact(char *buf, uint8_t to_dup);
void sofia_presence_set_hash_key(char *hash_key, int32_t len, sip_t const *sip);
+void sofia_glue_sql_close(sofia_profile_t *profile);
+int sofia_glue_init_sql(sofia_profile_t *profile);
+switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
+ switch_bool_t master,
+ switch_mutex_t *mutex,
+ char *sql,
+ switch_core_db_callback_func_t callback,
+ void *pdata);
+char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Tue Apr 3 23:08:17 2007
@@ -36,41 +36,6 @@
extern su_log_t tport_log[];
-static char reg_sql[] =
- "CREATE TABLE sip_registrations (\n"
- " user VARCHAR(255),\n"
- " host VARCHAR(255),\n"
- " contact VARCHAR(1024),\n"
- " status VARCHAR(255),\n"
- " rpid VARCHAR(255),\n"
- " expires INTEGER(8)" ");\n";
-
-
-static char sub_sql[] =
- "CREATE TABLE sip_subscriptions (\n"
- " proto VARCHAR(255),\n"
- " user VARCHAR(255),\n"
- " host VARCHAR(255),\n"
- " sub_to_user VARCHAR(255),\n"
- " sub_to_host VARCHAR(255),\n"
- " event VARCHAR(255),\n"
- " contact VARCHAR(1024),\n"
- " call_id VARCHAR(255),\n"
- " full_from VARCHAR(255),\n"
- " full_via VARCHAR(255),\n"
- " expires INTEGER(8)" ");\n";
-
-
-static char auth_sql[] =
- "CREATE TABLE sip_authentication (\n"
- " user VARCHAR(255),\n"
- " host VARCHAR(255),\n"
- " passwd VARCHAR(255),\n"
- " nonce VARCHAR(255),\n"
- " expires INTEGER(8)"
- ");\n";
-
-
void sofia_event_callback(nua_event_t event,
int status,
char const *phrase,
@@ -253,7 +218,7 @@
}
if (sql) {
- sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
switch_safe_free(sql);
sql = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Propagating registration for %s@%s->%s\n", from_user, from_host, contact_str);
@@ -272,7 +237,6 @@
sip_alias_node_t *node;
uint32_t ireg_loops = 0;
uint32_t gateway_loops = 0;
- switch_core_db_t *db;
switch_event_t *s_event;
profile->s_root = su_root_create(NULL);
@@ -320,11 +284,7 @@
}
- if ((db = switch_core_db_open_file(profile->dbname))) {
- switch_core_db_test_reactive(db, "select contact from sip_registrations", reg_sql);
- switch_core_db_test_reactive(db, "select contact from sip_subscriptions", sub_sql);
- switch_core_db_test_reactive(db, "select * from sip_authentication", auth_sql);
- } else {
+ if (!sofia_glue_init_sql(profile)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
return NULL;
}
@@ -362,7 +322,7 @@
while (mod_sofia_globals.running == 1) {
if (++ireg_loops >= IREG_SECONDS) {
- sofia_reg_check_expire(db, profile, time(NULL));
+ sofia_reg_check_expire(profile, time(NULL));
ireg_loops = 0;
}
@@ -373,8 +333,9 @@
su_root_step(profile->s_root, 1000);
}
+
+ sofia_glue_sql_close(profile);
- switch_core_db_close(db);
sofia_reg_unregister(profile);
su_home_unref(profile->home);
@@ -496,6 +457,7 @@
profile->name = switch_core_strdup(profile->pool, xprofilename);
snprintf(url, sizeof(url), "sofia_reg_%s", xprofilename);
+
profile->dbname = switch_core_strdup(profile->pool, url);
switch_core_hash_init(&profile->chat_hash, profile->pool);
@@ -510,6 +472,22 @@
profile->debug = atoi(val);
} else if (!strcasecmp(var, "use-rtp-timer") && switch_true(val)) {
switch_set_flag(profile, TFLAG_TIMER);
+
+ } else if (!strcasecmp(var, "odbc-dsn")) {
+#ifdef SWITCH_HAVE_ODBC
+ profile->odbc_dsn = switch_core_strdup(profile->pool, val);
+ if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
+ *profile->odbc_user++ = '\0';
+ }
+ if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
+ *profile->odbc_pass++ = '\0';
+ }
+
+
+#else
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
+#endif
+
} else if (!strcasecmp(var, "inbound-no-media") && switch_true(val)) {
switch_set_flag(profile, TFLAG_INB_NOMEDIA);
} else if (!strcasecmp(var, "inbound-late-negotiation") && switch_true(val)) {
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Tue Apr 3 23:08:17 2007
@@ -1119,7 +1119,91 @@
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
}
-void sofia_glue_execute_sql(char *dbname, char *sql, switch_mutex_t * mutex)
+int sofia_glue_init_sql(sofia_profile_t *profile)
+{
+
+
+ char reg_sql[] =
+ "CREATE TABLE sip_registrations (\n"
+ " user VARCHAR(255),\n"
+ " host VARCHAR(255),\n"
+ " contact VARCHAR(1024),\n"
+ " status VARCHAR(255),\n"
+ " rpid VARCHAR(255),\n"
+ " expires INTEGER(8)" ");\n";
+
+
+ char sub_sql[] =
+ "CREATE TABLE sip_subscriptions (\n"
+ " proto VARCHAR(255),\n"
+ " user VARCHAR(255),\n"
+ " host VARCHAR(255),\n"
+ " sub_to_user VARCHAR(255),\n"
+ " sub_to_host VARCHAR(255),\n"
+ " event VARCHAR(255),\n"
+ " contact VARCHAR(1024),\n"
+ " call_id VARCHAR(255),\n"
+ " full_from VARCHAR(255),\n"
+ " full_via VARCHAR(255),\n"
+ " expires INTEGER(8)" ");\n";
+
+
+ char auth_sql[] =
+ "CREATE TABLE sip_authentication (\n"
+ " user VARCHAR(255),\n"
+ " host VARCHAR(255),\n"
+ " passwd VARCHAR(255),\n"
+ " nonce VARCHAR(255),\n"
+ " expires INTEGER(8)"
+ ");\n";
+
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
+ return 0;
+ }
+ if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Connecting ODBC DSN: %s\n", profile->odbc_dsn);
+ return 0;
+ }
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
+
+ switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
+ switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
+ switch_odbc_handle_exec(profile->master_odbc, auth_sql, NULL);
+ } else {
+#endif
+ if (!(profile->master_db = switch_core_db_open_file(profile->dbname))) {
+ return 0;
+ }
+
+ switch_core_db_test_reactive(profile->master_db, "select contact from sip_registrations", reg_sql);
+ switch_core_db_test_reactive(profile->master_db, "select contact from sip_subscriptions", sub_sql);
+ switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", auth_sql);
+
+#ifdef SWITCH_HAVE_ODBC
+ }
+#endif
+
+ return 1;
+}
+
+void sofia_glue_sql_close(sofia_profile_t *profile)
+{
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ switch_odbc_handle_destroy(&profile->master_odbc);
+ } else {
+#endif
+ switch_core_db_close(profile->master_db);
+#ifdef SWITCH_HAVE_ODBC
+ }
+#endif
+}
+
+
+void sofia_glue_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex)
{
switch_core_db_t *db;
@@ -1127,12 +1211,38 @@
switch_mutex_lock(mutex);
}
- if (!(db = switch_core_db_open_file(dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", dbname);
- goto end;
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ SQLHSTMT stmt;
+ if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
+ char *err_str;
+ err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+ switch_safe_free(err_str);
+ }
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ } else {
+#endif
+
+
+ if (master) {
+ db = profile->master_db;
+ } else {
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ goto end;
+ }
}
switch_core_db_persistant_execute(db, sql, 25);
- switch_core_db_close(db);
+ if (!master) {
+ switch_core_db_close(db);
+ }
+
+
+#ifdef SWITCH_HAVE_ODBC
+ }
+#endif
+
end:
if (mutex) {
@@ -1141,6 +1251,159 @@
}
+switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
+ switch_bool_t master,
+ switch_mutex_t *mutex,
+ char *sql,
+ switch_core_db_callback_func_t callback,
+ void *pdata)
+{
+ switch_bool_t ret = SWITCH_FALSE;
+ switch_core_db_t *db;
+ char *errmsg = NULL;
+
+ if (mutex) {
+ switch_mutex_lock(mutex);
+ }
+
+
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
+ } else {
+#endif
+
+
+ if (master) {
+ db = profile->master_db;
+ } else {
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ goto end;
+ }
+ }
+
+ switch_core_db_exec(db, sql, callback, pdata, &errmsg);
+
+ if (errmsg) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+ free(errmsg);
+ }
+
+ if (!master && db) {
+ switch_core_db_close(db);
+ }
+
+#ifdef SWITCH_HAVE_ODBC
+ }
+#endif
+
+
+ end:
+
+ if (mutex) {
+ switch_mutex_unlock(mutex);
+ }
+
+
+
+ return ret;
+
+}
+
+#ifdef SWITCH_HAVE_ODBC
+static char *sofia_glue_execute_sql2str_odbc(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
+{
+ char *ret = NULL;
+ SQLHSTMT stmt;
+ SQLCHAR name[1024];
+ SQLINTEGER m = 0;
+
+ if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) == SWITCH_ODBC_SUCCESS) {
+ SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
+ SQLUINTEGER ColumnSize;
+ SQLRowCount(stmt, &m);
+
+ if (m <= 0) {
+ return NULL;
+ }
+
+ if (SQLFetch(stmt) != SQL_SUCCESS) {
+ return NULL;
+ }
+
+ SQLDescribeCol(stmt, 1, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
+ SQLGetData(stmt, 1, SQL_C_CHAR, (SQLCHAR *)resbuf, len, NULL);
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ ret = resbuf;
+ }
+
+ return ret;
+}
+
+#endif
+
+char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
+{
+ switch_core_db_t *db;
+ switch_core_db_stmt_t *stmt;
+ char *ret = NULL;
+
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ return sofia_glue_execute_sql2str_odbc(profile, mutex, sql, resbuf, len);
+ }
+#endif
+
+ if (mutex) {
+ switch_mutex_lock(mutex);
+ }
+
+ if (!(db = switch_core_db_open_file(profile->dbname))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ goto end;
+ }
+
+ if (switch_core_db_prepare(db, sql, -1, &stmt, 0)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error!\n");
+ goto fail;
+ } else {
+ int running = 1;
+ int colcount;
+
+ while (running < 5000) {
+ int result = switch_core_db_step(stmt);
+
+ if (result == SWITCH_CORE_DB_ROW) {
+ if ((colcount = switch_core_db_column_count(stmt))) {
+ switch_copy_string(resbuf, (char *) switch_core_db_column_text(stmt, 0), len);
+ ret = resbuf;
+ }
+ break;
+ } else if (result == SWITCH_CORE_DB_BUSY) {
+ running++;
+ switch_yield(1000);
+ continue;
+ }
+ break;
+ }
+
+ switch_core_db_finalize(stmt);
+ }
+
+
+ fail:
+
+ switch_core_db_close(db);
+
+ end:
+ if (mutex) {
+ switch_mutex_unlock(mutex);
+ }
+
+ return ret;
+}
+
int sofia_glue_get_user_host(char *in, char **user, char **host)
{
char *p, *h, *u = in;
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Tue Apr 3 23:08:17 2007
@@ -105,8 +105,7 @@
void sofia_presence_cancel(void)
{
- char *sql, *errmsg = NULL;
- switch_core_db_t *db;
+ char *sql;
sofia_profile_t *profile;
switch_hash_index_t *hi;
void *val;
@@ -120,47 +119,30 @@
continue;
}
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_sub_callback, profile) != SWITCH_TRUE) {
continue;
}
- switch_mutex_lock(profile->ireg_mutex);
- switch_core_db_exec(db, sql, sofia_presence_sub_callback, profile, &errmsg);
- switch_mutex_unlock(profile->ireg_mutex);
- switch_core_db_close(db);
}
switch_safe_free(sql);
+ switch_mutex_unlock(mod_sofia_globals.hash_mutex);
}
- switch_mutex_unlock(mod_sofia_globals.hash_mutex);
}
void sofia_presence_establish_presence(sofia_profile_t * profile)
{
- char *sql, *errmsg = NULL;
- switch_core_db_t *db;
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
+ "select user,host,'Registered','unknown','' from sip_registrations",
+ sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
return;
}
- if ((sql = switch_mprintf("select user,host,'Registered','unknown','' sip_registrations"))) {
- switch_mutex_lock(profile->ireg_mutex);
- switch_core_db_exec(db, sql, sofia_presence_resub_callback, profile, &errmsg);
- switch_mutex_unlock(profile->ireg_mutex);
- switch_safe_free(sql);
- }
-
- if ((sql = switch_mprintf("select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
- "where proto='ext' or proto='user' or proto='conf'"))) {
- switch_mutex_lock(profile->ireg_mutex);
- switch_core_db_exec(db, sql, sofia_presence_resub_callback, profile, &errmsg);
- switch_mutex_unlock(profile->ireg_mutex);
- switch_safe_free(sql);
+ if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
+ "select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
+ "where proto='ext' or proto='user' or proto='conf'",
+ sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
+ return;
}
-
- switch_core_db_close(db);
-
}
@@ -196,9 +178,7 @@
{
char *account, *dup_account, *yn, *host, *user;
char *sql;
- switch_core_db_t *db;
sofia_profile_t *profile;
- char *errmsg = NULL;
switch_stream_handle_t stream = { 0 };
switch_event_header_t *hp;
@@ -222,13 +202,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile for host %s\n", switch_str_nil(host));
return;
}
-
-
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
- return;
- }
-
+
SWITCH_STANDARD_STREAM(stream);
for (hp = event->headers; hp; hp = hp->next) {
@@ -246,12 +220,14 @@
assert (sql != NULL);
- switch_mutex_lock(profile->ireg_mutex);
- switch_core_db_exec(db, sql, sofia_presence_mwi_callback, profile, &errmsg);
- if (errmsg) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: %s\n", errmsg);
- }
- switch_mutex_unlock(profile->ireg_mutex);
+ sofia_glue_execute_sql_callback(profile,
+ SWITCH_FALSE,
+ profile->ireg_mutex,
+ sql,
+ sofia_presence_mwi_callback,
+ profile);
+
+
switch_safe_free(sql);
switch_safe_free(dup_account);
}
@@ -269,8 +245,6 @@
//char *event_subtype = switch_event_get_header(event, "event_subtype");
char *sql = NULL;
char *euser = NULL, *user = NULL, *host = NULL;
- char *errmsg;
- switch_core_db_t *db;
if (rpid && !strcasecmp(rpid, "n/a")) {
@@ -310,7 +284,8 @@
} else {
sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence'", status, rpid);
}
-
+
+ assert(sql != NULL);
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(switch_hash_pool_get(mod_sofia_globals.profile_hash), mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
@@ -319,20 +294,18 @@
continue;
}
- if (sql) {
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
- continue;
- }
- switch_mutex_lock(profile->ireg_mutex);
- switch_core_db_exec(db, sql, sofia_presence_sub_callback, profile, &errmsg);
- switch_mutex_unlock(profile->ireg_mutex);
- switch_core_db_close(db);
- }
+
+ sofia_glue_execute_sql_callback(profile,
+ SWITCH_FALSE,
+ profile->ireg_mutex,
+ sql,
+ sofia_presence_sub_callback,
+ profile);
+
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
-
+ free(sql);
return;
}
@@ -365,7 +338,6 @@
switch (event->event_id) {
case SWITCH_EVENT_PRESENCE_PROBE:
if (proto) {
- switch_core_db_t *db = NULL;
char *to = switch_event_get_header(event, "to");
char *user, *euser, *host, *p;
@@ -382,23 +354,19 @@
}
if (euser && host &&
- (sql =
- switch_mprintf("select user,host,status,rpid,'' from sip_registrations where user='%q' and host='%q'",
- euser, host)) && (profile = sofia_glue_find_profile(host))) {
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
- switch_safe_free(user);
- switch_safe_free(sql);
- return;
- }
+ (sql = switch_mprintf("select user,host,status,rpid,'' from sip_registrations where user='%q' and host='%q'",
+ euser, host)) && (profile = sofia_glue_find_profile(host))) {
+
+ sofia_glue_execute_sql_callback(profile,
+ SWITCH_FALSE,
+ profile->ireg_mutex,
+ sql,
+ sofia_presence_resub_callback,
+ profile);
- switch_mutex_lock(profile->ireg_mutex);
- switch_core_db_exec(db, sql, sofia_presence_resub_callback, profile, &errmsg);
- switch_mutex_unlock(profile->ireg_mutex);
switch_safe_free(sql);
}
switch_safe_free(user);
- switch_core_db_close(db);
}
return;
case SWITCH_EVENT_PRESENCE_IN:
@@ -426,15 +394,13 @@
}
if (sql) {
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
- continue;
- }
- switch_mutex_lock(profile->ireg_mutex);
- switch_core_db_exec(db, sql, sofia_presence_sub_callback, profile, &errmsg);
- switch_mutex_unlock(profile->ireg_mutex);
+ sofia_glue_execute_sql_callback(profile,
+ SWITCH_FALSE,
+ profile->ireg_mutex,
+ sql,
+ sofia_presence_sub_callback,
+ profile);
- switch_core_db_close(db);
}
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
@@ -665,8 +631,6 @@
char *to_str = NULL;
char *full_from = NULL;
char *full_via = NULL;
- switch_core_db_t *db;
- char *errmsg;
char *sstr;
const char *display = "\"user\"";
switch_event_t *sevent;
@@ -762,17 +726,28 @@
from_host = "n/a";
}
- if ((sql = switch_mprintf("delete from sip_subscriptions where "
- "proto='%q' and user='%q' and host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q';\n"
- "insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
- proto,
- from_user,
- from_host,
- to_user,
- to_host, event, proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp))) {
- sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
- switch_safe_free(sql);
- }
+ switch_mutex_lock(profile->ireg_mutex);
+
+ sql = switch_mprintf("delete from sip_subscriptions where "
+ "proto='%q' and user='%q' and host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q'",
+ proto,
+ from_user,
+ from_host,
+ to_user,
+ to_host, event, proto
+ );
+
+ assert(sql != NULL);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+ free(sql);
+ sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
+ proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp);
+
+ assert(sql != NULL);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+ free(sql);
+
+ switch_mutex_unlock(profile->ireg_mutex);
sstr = switch_mprintf("active;expires=%ld", exp_raw);
@@ -784,18 +759,17 @@
switch_safe_free(sstr);
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
- goto end;
- }
if ((sql = switch_mprintf("select * from sip_subscriptions where user='%q' and host='%q'", to_user, to_host, to_user, to_host))) {
- switch_mutex_lock(profile->ireg_mutex);
- switch_core_db_exec(db, sql, sofia_presence_sub_reg_callback, profile, &errmsg);
- switch_mutex_unlock(profile->ireg_mutex);
+ sofia_glue_execute_sql_callback(profile,
+ SWITCH_FALSE,
+ profile->ireg_mutex,
+ sql,
+ sofia_presence_sub_reg_callback,
+ profile);
+
switch_safe_free(sql);
}
- switch_core_db_close(db);
- end:
+ end:
if (event) {
su_free(profile->home, event);
@@ -878,7 +852,7 @@
if ((sql =
switch_mprintf("update sip_registrations set status='%q',rpid='%q' where user='%q' and host='%q'",
note_txt, rpid, from_user, from_host))) {
- sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
switch_safe_free(sql);
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Tue Apr 3 23:08:17 2007
@@ -35,7 +35,7 @@
#include "mod_sofia.h"
-void sofia_reg_unregister(sofia_profile_t * profile)
+void sofia_reg_unregister(sofia_profile_t *profile)
{
outbound_reg_t *gateway_ptr;
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
@@ -48,7 +48,7 @@
}
}
-void sofia_reg_check_gateway(sofia_profile_t * profile, time_t now)
+void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
{
outbound_reg_t *gateway_ptr;
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
@@ -133,73 +133,74 @@
return 0;
}
-void sofia_reg_check_expire(switch_core_db_t *db, sofia_profile_t * profile, time_t now)
+void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
{
char sql[1024];
- char *errmsg;
- if (!db) {
+#ifdef SWITCH_HAVE_ODBC
+ if (profile->odbc_dsn) {
+ if (!profile->master_odbc) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+ return;
+ }
+ } else {
+#endif
+ if (!profile->master_db) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
return;
}
+#ifdef SWITCH_HAVE_ODBC
+ }
+#endif
- switch_mutex_lock(profile->ireg_mutex);
- snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0 and expires < %ld", profile->name, (long) now);
- switch_core_db_exec(db, sql, sofia_reg_del_callback, NULL, &errmsg);
-
- if (errmsg) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s][%s]\n", sql, errmsg);
- switch_safe_free(errmsg);
- errmsg = NULL;
- }
+ snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0 and expires <= %ld", profile->name, (long) now);
- snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires < %ld", (long) now);
- switch_core_db_persistant_execute(db, sql, 1000);
- snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires < %ld", (long) now);
- switch_core_db_persistant_execute(db, sql, 1000);
- snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires > 0 and expires < %ld", (long) now);
- switch_core_db_persistant_execute(db, sql, 1000);
+ switch_mutex_lock(profile->ireg_mutex);
+ sofia_glue_execute_sql_callback(profile,
+ SWITCH_TRUE,
+ NULL,
+ sql,
+ sofia_reg_del_callback,
+ NULL);
+
+ snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld", (long) now);
+ sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
+ snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld", (long) now);
+ sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
+ snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires > 0 and expires <= %ld", (long) now);
+ sofia_glue_execute_sql(profile, SWITCH_TRUE, sql, NULL);
switch_mutex_unlock(profile->ireg_mutex);
}
-char *sofia_reg_find_reg_url(sofia_profile_t * profile, const char *user, const char *host, char *val, switch_size_t len)
+char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const char *host, char *val, switch_size_t len)
{
- char *errmsg;
struct callback_t cbt = { 0 };
- switch_core_db_t *db;
if (!user) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Called with null user!\n");
return NULL;
}
- if (!(db = switch_core_db_open_file(profile->dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
- return NULL;
- }
-
cbt.val = val;
cbt.len = len;
- switch_mutex_lock(profile->ireg_mutex);
+
if (host) {
snprintf(val, len, "select contact from sip_registrations where user='%s' and host='%s'", user, host);
} else {
snprintf(val, len, "select contact from sip_registrations where user='%s'", user);
}
- switch_core_db_exec(db, val, sofia_reg_find_callback, &cbt, &errmsg);
- if (errmsg) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s][%s]\n", val, errmsg);
- switch_safe_free(errmsg);
- errmsg = NULL;
- }
+ sofia_glue_execute_sql_callback(profile,
+ SWITCH_FALSE,
+ profile->ireg_mutex,
+ val,
+ sofia_reg_find_callback,
+ &cbt);
- switch_mutex_unlock(profile->ireg_mutex);
- switch_core_db_close(db);
if (cbt.matches) {
return val;
} else {
@@ -207,73 +208,20 @@
}
}
-char *sofia_reg_get_auth_data(char *dbname, char *nonce, char *npassword, size_t len, switch_mutex_t * mutex)
+static char *sofia_reg_get_auth_data(sofia_profile_t *profile, char *nonce, char *npassword, size_t len, switch_mutex_t *mutex)
{
- switch_core_db_t *db;
- switch_core_db_stmt_t *stmt;
- char *sql = NULL, *ret = NULL;
-
- if (mutex) {
- switch_mutex_lock(mutex);
- }
-
- if (!dbname) {
- goto end;
- }
-
- if (!(db = switch_core_db_open_file(dbname))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", dbname);
- goto end;
- }
-
+ char *sql, *ret;
+
sql = switch_mprintf("select passwd from sip_authentication where nonce='%q'", nonce);
- if (switch_core_db_prepare(db, sql, -1, &stmt, 0)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error!\n");
- goto fail;
- } else {
- int running = 1;
- int colcount;
+ assert(sql != NULL);
- while (running < 5000) {
- int result = switch_core_db_step(stmt);
-
- 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 == SWITCH_CORE_DB_BUSY) {
- running++;
- switch_yield(1000);
- continue;
- }
- break;
- }
-
- switch_core_db_finalize(stmt);
- }
-
-
- fail:
-
- switch_core_db_close(db);
-
- end:
- if (mutex) {
- switch_mutex_unlock(mutex);
- }
-
- if (sql) {
- switch_safe_free(sql);
- }
+ ret = sofia_glue_execute_sql2str(profile, mutex, sql, npassword, len);
+ free(sql);
return ret;
}
-
-
-uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
+uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
uint32_t keylen)
{
sip_from_t const *from = NULL;
@@ -433,9 +381,18 @@
a1_hash = hexdigest;
}
- sql = switch_mprintf("delete from sip_authentication where user='%q' and host='%q';\n"
- "insert into sip_authentication values('%q','%q','%q','%q', %ld)",
- from_user, from_host, from_user, from_host, a1_hash, uuid_str, time(NULL) + profile->nonce_ttl);
+ switch_mutex_lock(profile->ireg_mutex);
+ sql = switch_mprintf("delete from sip_authentication where user='%q' and host='%q';", from_user, from_host);
+ assert(sql != NULL);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+ switch_safe_free(sql);
+ sql = switch_mprintf("insert into sip_authentication values('%q','%q','%q','%q', %ld)",
+ from_user, from_host, a1_hash, uuid_str, time(NULL) + profile->nonce_ttl);
+ assert(sql != NULL);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+ switch_safe_free(sql);
+ switch_mutex_unlock(profile->ireg_mutex);
+
auth_str =
switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", from_host, uuid_str, stale ? " stale=\"true\"," : "");
@@ -448,8 +405,6 @@
}
- sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
- switch_safe_free(sql);
switch_safe_free(auth_str);
ret = 1;
} else {
@@ -488,7 +443,7 @@
}
if (sql) {
- sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
switch_safe_free(sql);
sql = NULL;
}
@@ -509,7 +464,7 @@
}
} else {
if ((sql = switch_mprintf("delete from sip_subscriptions where user='%q' and host='%q'", from_user, from_host))) {
- sofia_glue_execute_sql(profile->dbname, sql, profile->ireg_mutex);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
switch_safe_free(sql);
sql = NULL;
}
@@ -542,7 +497,7 @@
-void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
+void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
{
char key[128] = "";
@@ -564,7 +519,7 @@
void sofia_reg_handle_sip_r_register(int status,
char const *phrase,
- nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
+ nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
{
if (sofia_private && sofia_private->gateway) {
switch (status) {
@@ -594,7 +549,7 @@
void sofia_reg_handle_sip_r_challenge(int status,
char const *phrase,
- nua_t * nua, sofia_profile_t * profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
+ nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
{
outbound_reg_t *gateway = NULL;
sip_www_authenticate_t const *authenticate = NULL;
@@ -698,7 +653,7 @@
}
-auth_res_t parse_auth(sofia_profile_t * profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen)
+auth_res_t parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, const char *regstr, char *np, size_t nplen)
{
int indexnum;
const char *cur;
@@ -758,7 +713,7 @@
}
if (switch_strlen_zero(np)) {
- if (!sofia_reg_get_auth_data(profile->dbname, nonce, np, nplen, profile->ireg_mutex)) {
+ if (!sofia_reg_get_auth_data(profile, nonce, np, nplen, profile->ireg_mutex)) {
ret = AUTH_STALE;
goto end;
}
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c (original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c Tue Apr 3 23:08:17 2007
@@ -2761,16 +2761,19 @@
char *account = switch_event_get_header(event, "message-account");
if (account) {
- char *text;
+ char *path, *cmd;
- text = switch_mprintf("%s%smwi.js", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR);
- assert(text != NULL);
+ path = switch_mprintf("%s%smwi.js", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR);
+ assert(path != NULL);
- if (switch_file_exists(text) == SWITCH_STATUS_SUCCESS) {
- js_thread_launch(text);
+ if (switch_file_exists(path) == SWITCH_STATUS_SUCCESS) {
+ cmd = switch_mprintf("%s %s", path, account);
+ assert(cmd != NULL);
+ js_thread_launch(cmd);
+ switch_safe_free(cmd);
}
- free(text);
+ switch_safe_free(path);
}
}
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/Makefile (original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/Makefile Tue Apr 3 23:08:17 2007
@@ -1,28 +1,4 @@
switch_srcdir=../../../..
-ODBC=unixODBC-2.2.12
-ODBC_DIR=$(switch_srcdir)/libs/$(ODBC)
-ODBCLA=libodbc.la
-
-UNINST_ODBCLA=$(ODBC_DIR)/DriverManager/$(ODBCLA)
-INST_ODBCLA=$(DESTDIR)$(PREFIX)/lib/$(ODBCLA)
-
-LOCAL_CFLAGS=-I$(ODBC_DIR)/include
-LOCAL_LDFLAGS=
-LOCAL_LIBADD=$(UNINST_ODBCLA)
-
include ../mod_spidermonkey/sm.mak
-$(ODBC_DIR):
- $(GETLIB) $(ODBC).tar.gz
- cd $(ODBC_DIR) && ./configure --prefix=$(PREFIX) --disable-gui --without-x --with-pic
-
-$(UNINST_ODBCLA): $(ODBC_DIR)
- cd $(ODBC_DIR) && $(MAKE)
- $(TOUCH_TARGET)
-
-depend_install: $(INST_ODBCLA)
-
-$(INST_ODBCLA): $(UNINST_ODBCLA)
- cd $(ODBC_DIR) && $(MAKE) install
- @$(TOUCH_TARGET)
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c (original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c Tue Apr 3 23:08:17 2007
@@ -30,48 +30,19 @@
*
*/
#include "mod_spidermonkey.h"
-
-
-#include <sql.h>
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable:4201)
-#include <sqlext.h>
-#pragma warning(pop)
-#else
-#include <sqlext.h>
-#endif
-#include <sqltypes.h>
+#include <switch_odbc.h>
static const char modname[] = "ODBC";
struct odbc_obj {
- char *dsn;
- char *username;
- char *password;
- SQLHENV env;
- SQLHDBC con;
+ switch_odbc_handle_t *handle;
SQLHSTMT stmt;
- uint32_t state;
SQLCHAR *colbuf;
int32 cblen;
SQLCHAR *code;
int32 codelen;
};
-
-typedef enum {
- ODBC_STATE_INIT,
- ODBC_STATE_DOWN,
- ODBC_STATE_CONNECTED,
- ODBC_STATE_ERROR
-} odbc_state_t;
-typedef struct odbc_obj odbc_obj_t;
-
-typedef enum {
- ODBC_SUCCESS = 0,
- ODBC_FAIL = -1
-} odbc_status_t;
-
+typedef struct odbc_obj odbc_obj_t;
static odbc_obj_t *new_odbc_obj(char *dsn, char *username, char *password)
{
@@ -81,122 +52,39 @@
goto err;
}
- if (!(new_obj->dsn = strdup(dsn))) {
+ if (!(new_obj->handle = switch_odbc_handle_new(dsn, username, password))) {
goto err;
}
-
- if (!(new_obj->username = strdup(username))) {
- goto err;
- }
-
- if (!(new_obj->password = strdup(password))) {
- goto err;
- }
-
- new_obj->env = SQL_NULL_HANDLE;
- new_obj->state = ODBC_STATE_INIT;
-
+
return new_obj;
err:
if (new_obj) {
- switch_safe_free(new_obj->dsn);
- switch_safe_free(new_obj->username);
- switch_safe_free(new_obj->password);
+ if (new_obj->handle) {
+ switch_odbc_handle_destroy(&new_obj->handle);
+ }
switch_safe_free(new_obj);
}
return NULL;
}
-odbc_status_t odbc_obj_disconnect(odbc_obj_t * obj)
+switch_odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
{
- int result;
-
- if (obj->state == ODBC_STATE_CONNECTED) {
- result = SQLDisconnect(obj->con);
- if (result == ODBC_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, obj->dsn);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", obj->dsn);
- }
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", obj->dsn);
- }
-
- obj->state = ODBC_STATE_DOWN;
-
- return ODBC_SUCCESS;
-}
-
-odbc_status_t odbc_obj_connect(odbc_obj_t * obj)
-{
- int result;
- SQLINTEGER err;
- int16_t mlen;
- unsigned char msg[200], stat[10];
-
- if (obj->env == SQL_NULL_HANDLE) {
- result = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &obj->env);
-
- if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
- return ODBC_FAIL;
- }
-
- result = SQLSetEnvAttr(obj->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
-
- if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
- SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
- return ODBC_FAIL;
- }
-
- result = SQLAllocHandle(SQL_HANDLE_DBC, obj->env, &obj->con);
-
- if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
- SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
- return ODBC_FAIL;
- }
- SQLSetConnectAttr(obj->con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *) 10, 0);
- }
- if (obj->state == ODBC_STATE_CONNECTED) {
- odbc_obj_disconnect(obj);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-connecting %s\n", obj->dsn);
- }
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting %s\n", obj->dsn);
-
- result = SQLConnect(obj->con, (SQLCHAR *) obj->dsn, SQL_NTS, (SQLCHAR *) obj->username, SQL_NTS, (SQLCHAR *) obj->password, SQL_NTS);
-
- if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
- SQLGetDiagRec(SQL_HANDLE_DBC, obj->con, 1, stat, &err, msg, 100, &mlen);
- SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SQLConnect=%d errno=%d %s\n", result, (int) err, msg);
- return ODBC_FAIL;
- } else {
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connected to [%s]\n", obj->dsn);
- obj->state = ODBC_STATE_CONNECTED;
- }
-
- return ODBC_SUCCESS;
+
+ return switch_odbc_handle_connect(obj->handle);
}
static void destroy_odbc_obj(odbc_obj_t ** objp)
{
odbc_obj_t *obj = *objp;
- odbc_obj_disconnect(obj);
-
- SQLFreeHandle(SQL_HANDLE_STMT, obj->stmt);
- SQLFreeHandle(SQL_HANDLE_DBC, obj->con);
- SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
-
- switch_safe_free(obj->dsn);
- switch_safe_free(obj->username);
- switch_safe_free(obj->password);
+ if (obj->handle) {
+ switch_odbc_handle_destroy(&obj->handle);
+ }
+ if (obj->stmt) {
+ SQLFreeHandle(SQL_HANDLE_STMT, obj->stmt);
+ }
switch_safe_free(obj->colbuf);
switch_safe_free(obj->code);
switch_safe_free(obj);
@@ -205,7 +93,7 @@
/* ODBC Object */
/*********************************************************************************/
-static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
{
odbc_obj_t *odbc_obj = NULL;
char *dsn, *username, *password;
@@ -228,7 +116,15 @@
}
}
- if (dsn && username && password) {
+ if (switch_strlen_zero(username)) {
+ username = NULL;
+ }
+
+ if (switch_strlen_zero(password)) {
+ password = NULL;
+ }
+
+ if (dsn) {
odbc_obj = new_odbc_obj(dsn, username, password);
}
@@ -266,13 +162,13 @@
}
}
-static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
JSBool tf = JS_TRUE;
if (odbc_obj) {
- if (odbc_obj_connect(odbc_obj) == ODBC_SUCCESS) {
+ if (odbc_obj_connect(odbc_obj) == SWITCH_ODBC_SUCCESS) {
tf = JS_TRUE;
} else {
tf = JS_FALSE;
@@ -284,18 +180,18 @@
return JS_TRUE;
}
-static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
char *sql;
JSBool tf = JS_FALSE;
- int result;
if (argc < 1) {
goto done;
}
- if (odbc_obj->state != ODBC_STATE_CONNECTED) {
+ if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
goto done;
}
@@ -306,17 +202,8 @@
sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
- if (SQLAllocHandle(SQL_HANDLE_STMT, odbc_obj->con, &odbc_obj->stmt) != SQL_SUCCESS) {
- goto done;
- }
-
- if (SQLPrepare(odbc_obj->stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
- goto done;
- }
-
- result = SQLExecute(odbc_obj->stmt);
- if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
+ if (switch_odbc_handle_exec(odbc_obj->handle, sql, &odbc_obj->stmt) != SWITCH_ODBC_SUCCESS) {
goto done;
}
@@ -329,13 +216,14 @@
return JS_TRUE;
}
-static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
SQLSMALLINT rows = 0;
- if (odbc_obj->state != ODBC_STATE_CONNECTED) {
+ if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
goto done;
}
@@ -352,15 +240,17 @@
}
-static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
int result = 0;
JSBool tf = JS_FALSE;
- if (odbc_obj->state != ODBC_STATE_CONNECTED) {
- goto done;
- }
+ if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
+ goto done;
+ }
+
if (odbc_obj->stmt) {
if ((result = SQLFetch(odbc_obj->stmt) == SQL_SUCCESS)) {
@@ -412,19 +302,20 @@
}
-static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval *argv, jsval *rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
JSBool tf = JS_FALSE;
- if (odbc_obj->state != ODBC_STATE_CONNECTED) {
- goto done;
- }
+ if (switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
+ goto done;
+ }
if (odbc_obj->stmt) {
SQLSMALLINT c = 0, x = 0;
- int result;
+ SQLINTEGER m = 0;
char code[66560];
snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
@@ -433,15 +324,16 @@
return JS_TRUE;
}
- result = SQLNumResultCols(odbc_obj->stmt, &c);
- if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
+ SQLNumResultCols(odbc_obj->stmt, &c);
+ SQLRowCount(odbc_obj->stmt, &m);
+ if (m > 0) {
for (x = 1; x <= c; x++) {
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
SQLUINTEGER ColumnSize;
SQLCHAR name[1024] = "";
SQLCHAR *data = odbc_obj->colbuf;
SQLCHAR *esc = NULL;
-
+
SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
Added: freeswitch/trunk/src/switch_odbc.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/switch_odbc.c Tue Apr 3 23:08:17 2007
@@ -0,0 +1,407 @@
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct(a)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(a)yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Anthony Minessale II <anthmct(a)yahoo.com>
+ *
+ * switch_odbc.c -- ODBC
+ *
+ */
+#include <switch_odbc.h>
+
+struct switch_odbc_handle {
+ char *dsn;
+ char *username;
+ char *password;
+ SQLHENV env;
+ SQLHDBC con;
+ switch_odbc_state_t state;
+};
+
+
+SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(char *dsn, char *username, char *password)
+{
+ switch_odbc_handle_t *new_handle;
+
+ if (!(new_handle = malloc(sizeof(*new_handle)))) {
+ goto err;
+ }
+
+ memset(new_handle, 0, sizeof(*new_handle));
+
+ if (!(new_handle->dsn = strdup(dsn))) {
+ goto err;
+ }
+
+ if (username) {
+ if (!(new_handle->username = strdup(username))) {
+ goto err;
+ }
+ }
+
+ if (password) {
+ if (!(new_handle->password = strdup(password))) {
+ goto err;
+ }
+ }
+
+ new_handle->env = SQL_NULL_HANDLE;
+ new_handle->state = SWITCH_ODBC_STATE_INIT;
+
+ return new_handle;
+
+ err:
+ if (new_handle) {
+ switch_safe_free(new_handle->dsn);
+ switch_safe_free(new_handle->username);
+ switch_safe_free(new_handle->password);
+ switch_safe_free(new_handle);
+ }
+
+ return NULL;
+}
+
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_handle_t *handle)
+{
+ int result;
+
+ if (handle->state == SWITCH_ODBC_STATE_CONNECTED) {
+ result = SQLDisconnect(handle->con);
+ if (result == SWITCH_ODBC_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, handle->dsn);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", handle->dsn);
+ }
+ }
+ //else {
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", handle->dsn);
+ //}
+
+ handle->state = SWITCH_ODBC_STATE_DOWN;
+
+ return SWITCH_ODBC_SUCCESS;
+}
+
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_handle_t *handle)
+{
+ int result;
+ SQLINTEGER err;
+ int16_t mlen;
+ unsigned char msg[200], stat[10];
+
+ if (handle->env == SQL_NULL_HANDLE) {
+ result = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &handle->env);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
+ return SWITCH_ODBC_FAIL;
+ }
+
+ result = SQLSetEnvAttr(handle->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
+ SQLFreeHandle(SQL_HANDLE_ENV, handle->env);
+ return SWITCH_ODBC_FAIL;
+ }
+
+ result = SQLAllocHandle(SQL_HANDLE_DBC, handle->env, &handle->con);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
+ SQLFreeHandle(SQL_HANDLE_ENV, handle->env);
+ return SWITCH_ODBC_FAIL;
+ }
+ SQLSetConnectAttr(handle->con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *) 10, 0);
+ }
+ if (handle->state == SWITCH_ODBC_STATE_CONNECTED) {
+ switch_odbc_handle_disconnect(handle);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-connecting %s\n", handle->dsn);
+ }
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting %s\n", handle->dsn);
+
+ result = SQLConnect(handle->con, (SQLCHAR *) handle->dsn, SQL_NTS, (SQLCHAR *) handle->username, SQL_NTS, (SQLCHAR *) handle->password, SQL_NTS);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
+ char *err_str;
+ if ((err_str = switch_odbc_handle_get_error(handle, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n",err_str);
+ free(err_str);
+ } else {
+ SQLGetDiagRec(SQL_HANDLE_DBC, handle->con, 1, stat, &err, msg, 100, &mlen);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error SQLConnect=%d errno=%d %s\n", result, (int) err, msg);
+ }
+ SQLFreeHandle(SQL_HANDLE_ENV, handle->env);
+ return SWITCH_ODBC_FAIL;
+ } else {
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connected to [%s]\n", handle->dsn);
+ handle->state = SWITCH_ODBC_STATE_CONNECTED;
+ return SWITCH_ODBC_SUCCESS;
+ }
+
+ return SWITCH_ODBC_FAIL;
+}
+
+static int db_is_up(switch_odbc_handle_t *handle)
+{
+ int ret = 0;
+ SQLHSTMT stmt;
+ SQLINTEGER m = 0;
+ int result;
+ switch_event_t *event;
+ switch_odbc_status_t recon;
+ char *err_str = NULL;
+ SQLCHAR sql[] = "select 1";
+
+ if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
+ goto error;
+ }
+
+ if (SQLPrepare(stmt, sql, SQL_NTS) != SQL_SUCCESS) {
+ goto error;
+ }
+
+ result = SQLExecute(stmt);
+
+ SQLRowCount(stmt, &m);
+ ret = (int) m;
+
+ goto done;
+
+ error:
+
+ recon = switch_odbc_handle_connect(handle);
+ err_str = switch_odbc_handle_get_error(handle, stmt);
+
+ if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Failure-Message", "The sql server is not responding for DSN %s [%s]",
+ switch_str_nil(handle->dsn), switch_str_nil(err_str));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The sql server is not responding for DSN %s [%s]\n",
+ switch_str_nil(handle->dsn), switch_str_nil(err_str));
+
+ if (recon == SWITCH_ODBC_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection has been re-established");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "The connection has been re-established\n");
+ } else {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection could not be re-established");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The connection could not be re-established\n");
+ }
+ switch_event_fire(&event);
+ }
+
+ done:
+
+ switch_safe_free(err_str);
+
+ if (stmt) {
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ }
+
+ return ret;
+
+}
+
+
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, SQLHSTMT *rstmt)
+{
+ SQLHSTMT stmt;
+ int result;
+
+ if (!db_is_up(handle)) {
+ goto error;
+ }
+
+ if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
+ goto error;
+ }
+
+ if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
+ goto error;
+ }
+
+ result = SQLExecute(stmt);
+
+ if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
+ goto error;
+ }
+
+ if (rstmt) {
+ *rstmt = stmt;
+ } else {
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ }
+
+ return SWITCH_ODBC_SUCCESS;
+
+ error:
+ if (rstmt) {
+ *rstmt = stmt;
+ } else if (stmt) {
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ }
+ return SWITCH_ODBC_FAIL;
+
+}
+
+
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odbc_handle_t *handle,
+ char *sql, switch_core_db_callback_func_t callback, void *pdata)
+{
+ SQLHSTMT stmt;
+ SQLSMALLINT c = 0, x = 0;
+ SQLINTEGER m = 0;
+ int result;
+
+ assert(callback != NULL);
+
+ if (!db_is_up(handle)) {
+ goto error;
+ }
+
+ if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
+ goto error;
+ }
+
+ if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
+ goto error;
+ }
+
+ result = SQLExecute(stmt);
+
+ if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
+ goto error;
+ }
+
+
+ SQLNumResultCols(stmt, &c);
+ SQLRowCount(stmt, &m);
+
+ if (m > 0) {
+ int name_len = 256;
+ char **names;
+ char **vals;
+ int y = 0;
+
+ if (!(result = SQLFetch(stmt)) == SQL_SUCCESS) {
+ goto error;
+ }
+
+ names = calloc(c, sizeof(*names));
+ vals = calloc(c, sizeof(*names));
+
+ assert(names && vals);
+
+ for (x = 1; x <= c; x++) {
+ SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
+ SQLUINTEGER ColumnSize;
+ names[y] = malloc(name_len);
+ memset(names[y], 0, name_len);
+
+ SQLDescribeCol(stmt, x, (SQLCHAR *) names[y], name_len, &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
+ ColumnSize++;
+
+ vals[y] = malloc(ColumnSize);
+ memset(vals[y], 0, ColumnSize);
+ SQLGetData(stmt, x, SQL_C_CHAR, (SQLCHAR *) vals[y], ColumnSize, NULL);
+ y++;
+ }
+
+ callback(pdata, y, vals, names);
+
+ for (x = 0; x < y; x++) {
+ free(names[x]);
+ free(vals[x]);
+ }
+ free(names);
+ free(vals);
+ }
+
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+
+ return SWITCH_ODBC_SUCCESS;
+
+ error:
+
+ if (stmt) {
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ }
+
+ return SWITCH_ODBC_FAIL;
+
+}
+
+
+SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
+{
+ switch_odbc_handle_t *handle = NULL;
+
+ if (handlep) {
+ handle = *handlep;
+ }
+
+ if (handle) {
+ switch_odbc_handle_disconnect(handle);
+
+ SQLFreeHandle(SQL_HANDLE_DBC, handle->con);
+ SQLFreeHandle(SQL_HANDLE_ENV, handle->env);
+ switch_safe_free(handle->dsn);
+ switch_safe_free(handle->username);
+ switch_safe_free(handle->password);
+ free(handle);
+ }
+}
+
+SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle)
+{
+ return handle ? handle->state : SWITCH_ODBC_STATE_INIT;
+}
+
+SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, SQLHSTMT stmt)
+{
+ char buffer[SQL_MAX_MESSAGE_LENGTH + 1];
+ char sqlstate[SQL_SQLSTATE_SIZE + 1];
+ SQLINTEGER sqlcode;
+ SQLSMALLINT length;
+ char *ret = NULL;
+
+ if (SQLError(handle->env, handle->con, stmt, (SQLCHAR *)sqlstate, &sqlcode, (SQLCHAR *)buffer, sizeof(buffer), &length) == SQL_SUCCESS) {
+ ret = switch_mprintf("STATE: %s CODE %ld ERROR: %s\n", switch_str_nil(sqlstate), sqlcode, switch_str_nil(buffer));
+ };
+
+ return ret;
+}
+
+
+/* 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
0
Author: anthm
Date: Tue Apr 3 10:04:26 2007
New Revision: 4845
Modified:
freeswitch/trunk/build/turbo_build.sh
Log:
update
Modified: freeswitch/trunk/build/turbo_build.sh
==============================================================================
--- freeswitch/trunk/build/turbo_build.sh (original)
+++ freeswitch/trunk/build/turbo_build.sh Tue Apr 3 10:04:26 2007
@@ -5,7 +5,7 @@
fi
if [ -z $arg ] ; then
- $MAKE -j20 freeswitch
+ $MAKE -j freeswitch
MODS=`cat modules.conf | grep -v \#`
for i in $MODS ; do
MOD_NAME=`echo $i | sed -e 's|^.*/||'`
@@ -42,9 +42,9 @@
echo "Making module in $MOD_NAME"
if [ -f $MOD_DIR/Makefile ] ; then
- cd $MOD_DIR && BASE=$switch_srcdir $MAKE
+ cd $MOD_DIR && BASE=$switch_srcdir $MAKE -j
else
- cd $MOD_DIR && BASE=$switch_srcdir $MAKE -f $switch_srcdir/build/modmake.rules
+ cd $MOD_DIR && BASE=$switch_srcdir $MAKE -j -f $switch_srcdir/build/modmake.rules
fi
echo "Finished making module in $MOD_NAME"
1
0
03 Apr '07
Author: mikej
Date: Tue Apr 3 09:11:57 2007
New Revision: 4844
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile
Log:
take 4 fixing dependencies for proper make -j build
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile Tue Apr 3 09:11:57 2007
@@ -13,6 +13,7 @@
LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/stun -I$(SOFIAUA_DIR)/su
LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/tport -I$(SOFIAUA_DIR)/url
LOCAL_OBJS=sofia.o sofia_glue.o sofia_presence.o sofia_reg.o
+LOCAL_SOURCES=sofia.c sofia_glue.c sofia_presense.c sofia_reg.c mod_sofia.c
SOFIALA=$(SOFIAUA_DIR)/libsofia-sip-ua.la
@@ -28,3 +29,6 @@
local_depend: $(SOFIALA)
+../../../../libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua_tag.h: $(SOFIALA)
+
+$(LOCAL_OBJS) $(LOCAL_SOURCES): ../../../../libs/sofia-sip/libsofia-sip-ua/nua/sofia-sip/nua_tag.h
1
0
03 Apr '07
Author: mikej
Date: Tue Apr 3 08:29:18 2007
New Revision: 4843
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile
Log:
another try on proper deps
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile Tue Apr 3 08:29:18 2007
@@ -14,8 +14,6 @@
LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/tport -I$(SOFIAUA_DIR)/url
LOCAL_OBJS=sofia.o sofia_glue.o sofia_presence.o sofia_reg.o
-$(LOCAL_OBJS): $(SOFIALA)
-
SOFIALA=$(SOFIAUA_DIR)/libsofia-sip-ua.la
LOCAL_LIBADD=$(SOFIALA)
@@ -27,3 +25,6 @@
$(SOFIALA): $(SOFIA_DIR) $(SOFIA_DIR)/.update
cd $(SOFIA_DIR) && $(MAKE)
$(TOUCH_TARGET)
+
+local_depend: $(SOFIALA)
+
1
0
03 Apr '07
Author: mikej
Date: Tue Apr 3 08:04:14 2007
New Revision: 4842
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile
Log:
fix dependencies to handle make -j
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/Makefile Tue Apr 3 08:04:14 2007
@@ -14,6 +14,8 @@
LOCAL_CFLAGS += -I$(SOFIAUA_DIR)/tport -I$(SOFIAUA_DIR)/url
LOCAL_OBJS=sofia.o sofia_glue.o sofia_presence.o sofia_reg.o
+$(LOCAL_OBJS): $(SOFIALA)
+
SOFIALA=$(SOFIAUA_DIR)/libsofia-sip-ua.la
LOCAL_LIBADD=$(SOFIALA)
1
0
Author: mikej
Date: Tue Apr 3 07:57:57 2007
New Revision: 4841
Modified:
freeswitch/trunk/Makefile.am
Log:
fix whoops from previous commit
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Tue Apr 3 07:57:57 2007
@@ -242,7 +242,7 @@
@am__include@ @am__quote@./$(DEPDIR)/modules.targets@am__quote@
modules.conf:
- if test -f $@; then touch $@; else cp build/modules.conf.in $@
+ if test -f $@; then touch $@; else cp build/modules.conf.in $@ ;fi
./$(DEPDIR)/modules.targets: modules.conf
mods=`cat modules.conf | sed -e 's|^.*/||'`; echo MODULE_TARGETS=\"$$mods\" > ./$(DEPDIR)/modules.targets
1
0