Modified: freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c (14898 => 14899)
--- freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c 2009-09-17 02:31:31 UTC (rev 14898)
+++ freeswitch/branches/gmaruzz/mod_celliax/mod_celliax.c 2009-09-17 11:23:29 UTC (rev 14899)
@@ -95,7 +95,7 @@
#endif //0
SWITCH_STANDARD_API(sendsms_function);
-#define SENDSMS_SYNTAX "sendsms interface_name destination_number SMS_text"
+#define SENDSMS_SYNTAX "celliax_sendsms interface_name destination_number SMS_text"
/* BEGIN: Changes here */
#define FULL_RELOAD 0
#define SOFT_RELOAD 1
@@ -1463,10 +1463,86 @@
return SWITCH_STATUS_SUCCESS;
}
+static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject, const char *body, const char *type, const char *hint)
+{
+ char *user, *host, *f_user = NULL, *f_host = NULL, *f_resource = NULL;
+ private_t * tech_pvt=NULL;
+ int i=0, found=0;
+ switch_assert(proto != NULL);
+
+ DEBUGA_CELLIAX("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", CELLIAX_P_LOG, proto, from, to, subject, body, type, hint?hint:"NULL");
+
+ if (!to || !strlen(to)) {
+ ERRORA("Missing To: header.\n", CELLIAX_P_LOG);
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ if ((!from && !hint) || (!strlen(from) && !strlen(hint)) ) {
+ ERRORA("Missing From: AND Hint: headers.\n", CELLIAX_P_LOG);
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ if (from && (f_user = strdup(from))) {
+ if ((f_host = strchr(f_user, '@'))) {
+ *f_host++ = '\0';
+ if ((f_resource = strchr(f_host, '/'))) {
+ *f_resource++ = '\0';
+ }
+ }
+ }
+
+if(!strlen(hint)){ //FIXME FIXME FIXME
+ hint=from;
+}
+ if (to && (user = strdup(to))) {
+ if ((host = strchr(user, '@'))) {
+ *host++ = '\0';
+ }
+
+ DEBUGA_CELLIAX("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=%s, hint=%s)\n", CELLIAX_P_LOG, proto, from, to, subject, body, type, hint?hint:"NULL");
+ if (hint && strlen(hint)) {
+ //in hint we receive the interface name to use
+ for (i = 0; !found && i < CELLIAX_MAX_INTERFACES; i++) {
+ if (strlen(globals.CELLIAX_INTERFACES[i].name)
+ && (strncmp(globals.CELLIAX_INTERFACES[i].name, hint, strlen(hint)) == 0)) {
+ tech_pvt = &globals.CELLIAX_INTERFACES[i];
+ DEBUGA_CELLIAX("Using interface: globals.CELLIAX_INTERFACES[%d].name=|||%s|||\n", CELLIAX_P_LOG, i, globals.CELLIAX_INTERFACES[i].name);
+ found = 1;
+ break;
+ }
+ }
+ } /* FIXME add a tech_pvt member for the SIM telephone number //else {
+ //we have no a predefined interface name to use (hint is NULL), so let's choose an interface from the username (from)
+ for (i = 0; !found && i < CELLIAX_MAX_INTERFACES; i++) {
+ if (strlen(globals.CELLIAX_INTERFACES[i].name)
+ && (strncmp(globals.CELLIAX_INTERFACES[i].skype_user, from, strlen(from)) == 0)) {
+ tech_pvt = &globals.CELLIAX_INTERFACES[i];
+ DEBUGA_CELLIAX("Using interface: globals.CELLIAX_INTERFACES[%d].name=|||%s|||\n", CELLIAX_P_LOG, i, globals.CELLIAX_INTERFACES[i].name);
+ found = 1;
+ break;
+ }
+ }
+ }
+ */
+ if (!found) {
+ ERRORA("ERROR: A Celliax interface with name='%s' or one with SIM_number='%s' was not found\n", CELLIAX_P_LOG, hint?hint:"NULL", from?from:"NULL");
+ goto end;
+ } else {
+ celliax_sendsms(tech_pvt, to, body);
+ }
+ }
+end:
+ switch_safe_free(user);
+ switch_safe_free(f_user);
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
SWITCH_MODULE_LOAD_FUNCTION(mod_celliax_load)
{
switch_api_interface_t *commands_api_interface;
+ switch_chat_interface_t *chat_interface;
celliax_module_pool = pool;
memset(&globals, '\0', sizeof(globals));
@@ -1495,7 +1571,8 @@
SWITCH_ADD_API(commands_api_interface, "sk", "Celliax console commands", sk_function, SK_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "celliax", "Celliax interface commands", celliax_function, CELLIAX_SYNTAX);
#endif //0
- SWITCH_ADD_API(commands_api_interface, "sendsms", "sendsms interface destination_number SMS_text", sendsms_function, SENDSMS_SYNTAX);
+ SWITCH_ADD_API(commands_api_interface, "celliax_sendsms", "celliax_sendsms interface destination_number SMS_text", sendsms_function, SENDSMS_SYNTAX);
+ SWITCH_ADD_CHAT(chat_interface, MDL_CHAT_PROTO, chat_send);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
@@ -1957,59 +2034,6 @@
}
#endif //0
-SWITCH_STANDARD_API(sendsms_function)
-{
- char *mycmd = NULL, *argv[3] = { 0 };
- int argc = 0;
- private_t *tech_pvt = NULL;
-
- if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
- argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
- }
-
- if (!argc) {
- stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
- goto end;
- }
-
- if (argc < 3) {
- stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
- goto end;
- }
-
- if (argv[0]) {
- int i;
- int found = 0;
-
- for (i = 0; !found && i < CELLIAX_MAX_INTERFACES; i++) {
- /* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
- if (strlen(globals.CELLIAX_INTERFACES[i].name)
- && (strncmp(globals.CELLIAX_INTERFACES[i].name, argv[0], strlen(argv[0])) == 0)) {
- tech_pvt = &globals.CELLIAX_INTERFACES[i];
- stream->write_function(stream, "Trying to send your SMS: interface=%s, dest=%s, text=%s\n", argv[0], argv[1], argv[2]);
- found = 1;
- break;
- }
-
- }
- if (!found) {
- stream->write_function(stream, "ERROR: A Celliax interface with name='%s' was not found\n", argv[0]);
- switch_safe_free(mycmd);
-
- return SWITCH_STATUS_SUCCESS;
- } else {
- celliax_sendsms(tech_pvt, (char *) argv[1], (char *) argv[2]);
- }
- } else {
- stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
- }
- end:
- switch_safe_free(mycmd);
-
- return SWITCH_STATUS_SUCCESS;
-}
-
-
int celliax_transfer(private_t * tech_pvt, char *id, char *value)
{
char msg_to_celliax[1024];
@@ -2207,7 +2231,63 @@
#endif// NOTDEF
+SWITCH_STANDARD_API(sendsms_function)
+{
+ char *mycmd = NULL, *argv[3] = { 0 };
+ int argc = 0;
+ private_t *tech_pvt = NULL;
+ if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
+ argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+ }
+
+ if (!argc) {
+ stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
+ goto end;
+ }
+
+ if (argc < 3) {
+ stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
+ goto end;
+ }
+
+ if (argv[0]) {
+ int i;
+ int found = 0;
+
+ for (i = 0; !found && i < CELLIAX_MAX_INTERFACES; i++) {
+ /* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
+ if (strlen(globals.CELLIAX_INTERFACES[i].name)
+ && (strncmp(globals.CELLIAX_INTERFACES[i].name, argv[0], strlen(argv[0])) == 0)) {
+ tech_pvt = &globals.CELLIAX_INTERFACES[i];
+ stream->write_function(stream, "Trying to send your SMS: interface=%s, dest=%s, text=%s\n", argv[0], argv[1], argv[2]);
+ found = 1;
+ break;
+ }
+
+ }
+ if (!found) {
+ stream->write_function(stream, "ERROR: A Celliax interface with name='%s' was not found\n", argv[0]);
+ switch_safe_free(mycmd);
+
+ return SWITCH_STATUS_SUCCESS;
+ } else {
+ //celliax_sendsms(tech_pvt, (char *) argv[1], (char *) argv[2]);
+ NOTICA("chat_send(proto=%s, from=%s, to=%s, subject=%s, body=%s, type=NULL, hint=%s)\n", CELLIAX_P_LOG, MDL_CHAT_PROTO, tech_pvt->name, argv[1], "SIMPLE MESSAGE", switch_str_nil(argv[2]), tech_pvt->name);
+
+ chat_send(MDL_CHAT_PROTO, tech_pvt->name, argv[1], "SIMPLE MESSAGE", switch_str_nil(argv[2]), NULL, tech_pvt->name);
+ }
+ } else {
+ stream->write_function(stream, "ERROR, usage: %s", SENDSMS_SYNTAX);
+ }
+ end:
+ switch_safe_free(mycmd);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
+
int sms_incoming(private_t * tech_pvt, char *value)
{
switch_event_t *event;