add new chatplan concept and mod_sms. Apps for chat messages: copy new base freeswitch.xml and chatplan dir if you are upgrading on existing config base

This commit is contained in:
Anthony Minessale 2011-09-21 14:31:10 -05:00
parent 5fe3a22d83
commit 7333d46d5b
35 changed files with 3263 additions and 567 deletions

14
conf/chatplan/default.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<include>
<context name="default">
<extension name="demo">
<condition field="to" expression="^(.*)$">
<!-- <action application="lua" data="test.lua"/> -->
<action application="reply" data="Hello, you said: ${_body}"/>
</condition>
</extension>
</context>
</include>

View File

@ -46,6 +46,10 @@
<X-PRE-PROCESS cmd="include" data="dialplan/*.xml"/> <X-PRE-PROCESS cmd="include" data="dialplan/*.xml"/>
</section> </section>
<section name="chatplan" description="Regex/XML Chatplan">
<X-PRE-PROCESS cmd="include" data="chatplan/*.xml"/>
</section>
<!-- mod_dingaling is reliant on the vcard data in the "directory" section. --> <!-- mod_dingaling is reliant on the vcard data in the "directory" section. -->
<!-- mod_sofia is reliant on the user data for authorization --> <!-- mod_sofia is reliant on the user data for authorization -->
<section name="directory" description="User Directory"> <section name="directory" description="User Directory">

View File

@ -270,8 +270,9 @@ ESL_DECLARE(char *) esl_event_get_header_idx(esl_event_t *event, const char *hea
} }
return hp->value; return hp->value;
} else if (!strcmp(header_name, "_body")) {
} return event->body;
}
return NULL; return NULL;
} }
@ -414,6 +415,10 @@ static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t st
int index = 0; int index = 0;
char *real_header_name = NULL; char *real_header_name = NULL;
if (!strcmp(header_name, "_body")) {
esl_event_set_body(event, data);
}
if ((index_ptr = strchr(header_name, '['))) { if ((index_ptr = strchr(header_name, '['))) {
index_ptr++; index_ptr++;
index = atoi(index_ptr); index = atoi(index_ptr);
@ -604,6 +609,17 @@ ESL_DECLARE(esl_status_t) esl_event_add_header_string(esl_event_t *event, esl_st
return ESL_FAIL; return ESL_FAIL;
} }
ESL_DECLARE(esl_status_t) esl_event_set_body(esl_event_t *event, const char *body)
{
esl_safe_free(event->body);
if (body) {
event->body = DUP(body);
}
return ESL_SUCCESS;
}
ESL_DECLARE(esl_status_t) esl_event_add_body(esl_event_t *event, const char *fmt, ...) ESL_DECLARE(esl_status_t) esl_event_add_body(esl_event_t *event, const char *fmt, ...)
{ {
int ret = 0; int ret = 0;

View File

@ -298,6 +298,7 @@ ESL_DECLARE(esl_status_t) esl_event_create_json(esl_event_t **event, const char
\note the body parameter can be shadowed by the esl_event_reserve_subclass_detailed function \note the body parameter can be shadowed by the esl_event_reserve_subclass_detailed function
*/ */
ESL_DECLARE(esl_status_t) esl_event_add_body(esl_event_t *event, const char *fmt, ...); ESL_DECLARE(esl_status_t) esl_event_add_body(esl_event_t *event, const char *fmt, ...);
ESL_DECLARE(esl_status_t) esl_event_set_body(esl_event_t *event, const char *body);
/*! /*!
\brief Create a new event assuming it will not be custom event and therefore hiding the unused parameters \brief Create a new event assuming it will not be custom event and therefore hiding the unused parameters

View File

@ -2110,7 +2110,7 @@ SWITCH_DECLARE(void) switch_cond_next(void);
SWITCH_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_proto, const char *proto, const char *from, const char *to, SWITCH_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_proto, const char *proto, const char *from, const char *to,
const char *subject, const char *body, const char *type, const char *hint); const char *subject, const char *body, const char *type, const char *hint);
SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, switch_event_t *message_event); SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, switch_event_t *message_event);
SWITCH_DECLARE(switch_status_t) switch_core_chat_deliver(const char *dest_proto, switch_event_t **message_event);
SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_session_t *session, const char *cmds); SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_session_t *session, const char *cmds);

View File

@ -156,6 +156,8 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod
SWITCH_DECLARE_CONSTRUCTOR Event(const char *type, const char *subclass_name = NULL); SWITCH_DECLARE_CONSTRUCTOR Event(const char *type, const char *subclass_name = NULL);
SWITCH_DECLARE_CONSTRUCTOR Event(switch_event_t *wrap_me, int free_me = 0); SWITCH_DECLARE_CONSTRUCTOR Event(switch_event_t *wrap_me, int free_me = 0);
virtual SWITCH_DECLARE_CONSTRUCTOR ~ Event(); virtual SWITCH_DECLARE_CONSTRUCTOR ~ Event();
SWITCH_DECLARE(int) chat_execute(const char *app, const char *data = NULL);
SWITCH_DECLARE(int) chat_send(const char *dest_proto = NULL);
SWITCH_DECLARE(const char *) serialize(const char *format = NULL); SWITCH_DECLARE(const char *) serialize(const char *format = NULL);
SWITCH_DECLARE(bool) setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL); SWITCH_DECLARE(bool) setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
SWITCH_DECLARE(const char *) getHeader(const char *header_name); SWITCH_DECLARE(const char *) getHeader(const char *header_name);

View File

@ -103,7 +103,8 @@ struct switch_event {
}; };
typedef enum { typedef enum {
EF_UNIQ_HEADERS = (1 << 0) EF_UNIQ_HEADERS = (1 << 0),
EF_NO_CHAT_EXEC = (1 << 1)
} switch_event_flag_t; } switch_event_flag_t;
@ -157,6 +158,8 @@ _Ret_opt_z_ SWITCH_DECLARE(char *) switch_event_get_header_idx(switch_event_t *e
#define switch_event_get_header_nil(e, h) switch_str_nil(switch_event_get_header(e,h)) #define switch_event_get_header_nil(e, h) switch_str_nil(switch_event_get_header(e,h))
SWITCH_DECLARE(switch_status_t) switch_event_rename_header(switch_event_t *event, const char *header_name, const char *new_header_name);
/*! /*!
\brief Retrieve the body value from an event \brief Retrieve the body value from an event
\param event the event to read the body from \param event the event to read the body from
@ -207,6 +210,8 @@ SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event);
*/ */
SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_event_t *todup); SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_event_t *todup);
SWITCH_DECLARE(void) switch_event_merge(switch_event_t *event, switch_event_t *tomerge); SWITCH_DECLARE(void) switch_event_merge(switch_event_t *event, switch_event_t *tomerge);
SWITCH_DECLARE(switch_status_t) switch_event_dup_reply(switch_event_t **event, switch_event_t *todup);
/*! /*!
\brief Fire an event with full arguement list \brief Fire an event with full arguement list
\param file the calling file \param file the calling file
@ -321,6 +326,9 @@ SWITCH_DECLARE(switch_status_t) switch_event_running(void);
*/ */
SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, const char *fmt, ...) PRINTF_FUNCTION(2, 3); SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, const char *fmt, ...) PRINTF_FUNCTION(2, 3);
#endif #endif
SWITCH_DECLARE(switch_status_t) switch_event_set_body(switch_event_t *event, const char *body);
SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const char *in); SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const char *in);
SWITCH_DECLARE(switch_status_t) switch_event_create_pres_in_detailed(_In_z_ char *file, _In_z_ char *func, _In_ int line, SWITCH_DECLARE(switch_status_t) switch_event_create_pres_in_detailed(_In_z_ char *file, _In_z_ char *func, _In_ int line,

View File

@ -931,6 +931,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_release_file_handle(switch_core_sessi
SWITCH_DECLARE(switch_status_t) switch_ivr_process_fh(switch_core_session_t *session, const char *cmd, switch_file_handle_t *fhp); SWITCH_DECLARE(switch_status_t) switch_ivr_process_fh(switch_core_session_t *session, const char *cmd, switch_file_handle_t *fhp);
SWITCH_DECLARE(switch_status_t) switch_ivr_insert_file(switch_core_session_t *session, const char *file, const char *insert_file, switch_size_t sample_point); SWITCH_DECLARE(switch_status_t) switch_ivr_insert_file(switch_core_session_t *session, const char *file, const char *insert_file, switch_size_t sample_point);
SWITCH_DECLARE(switch_status_t) switch_ivr_create_message_reply(switch_event_t **reply, switch_event_t *message, const char *new_proto);
/** @} */ /** @} */
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C

View File

@ -55,33 +55,35 @@ SWITCH_BEGIN_EXTERN_C
struct switch_loadable_module_interface { struct switch_loadable_module_interface {
/*! the name of the module */ /*! the name of the module */
const char *module_name; const char *module_name;
/*! the table of endpoints the module has implmented */ /*! the table of endpoints the module has implemented */
switch_endpoint_interface_t *endpoint_interface; switch_endpoint_interface_t *endpoint_interface;
/*! the table of timers the module has implmented */ /*! the table of timers the module has implemented */
switch_timer_interface_t *timer_interface; switch_timer_interface_t *timer_interface;
/*! the table of dialplans the module has implmented */ /*! the table of dialplans the module has implemented */
switch_dialplan_interface_t *dialplan_interface; switch_dialplan_interface_t *dialplan_interface;
/*! the table of codecs the module has implmented */ /*! the table of codecs the module has implemented */
switch_codec_interface_t *codec_interface; switch_codec_interface_t *codec_interface;
/*! the table of applications the module has implmented */ /*! the table of applications the module has implemented */
switch_application_interface_t *application_interface; switch_application_interface_t *application_interface;
/*! the table of api functions the module has implmented */ /*! the table of chat applications the module has implemented */
switch_chat_application_interface_t *chat_application_interface;
/*! the table of api functions the module has implemented */
switch_api_interface_t *api_interface; switch_api_interface_t *api_interface;
/*! the table of file formats the module has implmented */ /*! the table of file formats the module has implemented */
switch_file_interface_t *file_interface; switch_file_interface_t *file_interface;
/*! the table of speech interfaces the module has implmented */ /*! the table of speech interfaces the module has implemented */
switch_speech_interface_t *speech_interface; switch_speech_interface_t *speech_interface;
/*! the table of directory interfaces the module has implmented */ /*! the table of directory interfaces the module has implemented */
switch_directory_interface_t *directory_interface; switch_directory_interface_t *directory_interface;
/*! the table of chat interfaces the module has implmented */ /*! the table of chat interfaces the module has implemented */
switch_chat_interface_t *chat_interface; switch_chat_interface_t *chat_interface;
/*! the table of say interfaces the module has implmented */ /*! the table of say interfaces the module has implemented */
switch_say_interface_t *say_interface; switch_say_interface_t *say_interface;
/*! the table of asr interfaces the module has implmented */ /*! the table of asr interfaces the module has implemented */
switch_asr_interface_t *asr_interface; switch_asr_interface_t *asr_interface;
/*! the table of management interfaces the module has implmented */ /*! the table of management interfaces the module has implemented */
switch_management_interface_t *management_interface; switch_management_interface_t *management_interface;
/*! the table of limit interfaces the module has implmented */ /*! the table of limit interfaces the module has implemented */
switch_limit_interface_t *limit_interface; switch_limit_interface_t *limit_interface;
switch_thread_rwlock_t *rwlock; switch_thread_rwlock_t *rwlock;
int refs; int refs;
@ -169,6 +171,15 @@ SWITCH_DECLARE(switch_timer_interface_t *) switch_loadable_module_get_timer_inte
*/ */
SWITCH_DECLARE(switch_application_interface_t *) switch_loadable_module_get_application_interface(const char *name); SWITCH_DECLARE(switch_application_interface_t *) switch_loadable_module_get_application_interface(const char *name);
/*!
\brief Retrieve the chat application interface by it's registered name
\param name the name of the chat application
\return the desired chat application interface
*/
SWITCH_DECLARE(switch_chat_application_interface_t *) switch_loadable_module_get_chat_application_interface(const char *name);
SWITCH_DECLARE(switch_status_t) switch_core_execute_chat_app(switch_event_t *message, const char *app, const char *data);
/*! /*!
\brief Retrieve the API interface by it's registered name \brief Retrieve the API interface by it's registered name
\param name the name of the API \param name the name of the API
@ -335,6 +346,18 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void);
break; \ break; \
} }
#define SWITCH_ADD_CHAT_APP(app_int, int_name, short_descript, long_descript, funcptr, syntax_string, app_flags) \
for (;;) { \
app_int = (switch_chat_application_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_CHAT_APPLICATION_INTERFACE); \
app_int->interface_name = int_name; \
app_int->chat_application_function = funcptr; \
app_int->short_desc = short_descript; \
app_int->long_desc = long_descript; \
app_int->syntax = syntax_string; \
app_int->flags = app_flags; \
break; \
}
#define SWITCH_ADD_DIALPLAN(dp_int, int_name, funcptr) \ #define SWITCH_ADD_DIALPLAN(dp_int, int_name, funcptr) \
for (;;) { \ for (;;) { \
dp_int = (switch_dialplan_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_DIALPLAN_INTERFACE); \ dp_int = (switch_dialplan_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_DIALPLAN_INTERFACE); \

View File

@ -681,6 +681,27 @@ struct switch_application_interface {
struct switch_application_interface *next; struct switch_application_interface *next;
}; };
/*! \brief A module interface to implement a chat application */
struct switch_chat_application_interface {
/*! the name of the interface */
const char *interface_name;
/*! function the application implements */
switch_chat_application_function_t chat_application_function;
/*! the long winded description of the application */
const char *long_desc;
/*! the short and sweet description of the application */
const char *short_desc;
/*! an example of the application syntax */
const char *syntax;
/*! flags to control behaviour */
uint32_t flags;
switch_thread_rwlock_t *rwlock;
int refs;
switch_mutex_t *reflock;
switch_loadable_module_interface_t *parent;
struct switch_chat_application_interface *next;
};
/*! \brief A module interface to implement an api function */ /*! \brief A module interface to implement an api function */
struct switch_api_interface { struct switch_api_interface {
/*! the name of the interface */ /*! the name of the interface */

View File

@ -74,6 +74,7 @@ SWITCH_DECLARE(void) switch_capture_regex(switch_regex_t *re, int match_count, c
int *ovector, const char *var, switch_cap_callback_t callback, void *user_data); int *ovector, const char *var, switch_cap_callback_t callback, void *user_data);
SWITCH_DECLARE_NONSTD(void) switch_regex_set_var_callback(const char *var, const char *val, void *user_data); SWITCH_DECLARE_NONSTD(void) switch_regex_set_var_callback(const char *var, const char *val, void *user_data);
SWITCH_DECLARE_NONSTD(void) switch_regex_set_event_header_callback(const char *var, const char *val, void *user_data);
#define switch_regex_safe_free(re) if (re) {\ #define switch_regex_safe_free(re) if (re) {\
switch_regex_free(re);\ switch_regex_free(re);\

View File

@ -325,7 +325,8 @@ typedef enum {
SWITCH_SAY_INTERFACE, SWITCH_SAY_INTERFACE,
SWITCH_ASR_INTERFACE, SWITCH_ASR_INTERFACE,
SWITCH_MANAGEMENT_INTERFACE, SWITCH_MANAGEMENT_INTERFACE,
SWITCH_LIMIT_INTERFACE SWITCH_LIMIT_INTERFACE,
SWITCH_CHAT_APPLICATION_INTERFACE
} switch_module_interface_name_t; } switch_module_interface_name_t;
typedef enum { typedef enum {
@ -495,6 +496,7 @@ typedef enum {
SWITCH_XML_SECTION_DIRECTORY = (1 << 1), SWITCH_XML_SECTION_DIRECTORY = (1 << 1),
SWITCH_XML_SECTION_DIALPLAN = (1 << 2), SWITCH_XML_SECTION_DIALPLAN = (1 << 2),
SWITCH_XML_SECTION_PHRASES = (1 << 3), SWITCH_XML_SECTION_PHRASES = (1 << 3),
SWITCH_XML_SECTION_CHATPLAN = (1 << 4),
/* Nothing after this line */ /* Nothing after this line */
SWITCH_XML_SECTION_MAX = (1 << 4) SWITCH_XML_SECTION_MAX = (1 << 4)
@ -1221,6 +1223,12 @@ typedef enum {
} switch_application_flag_enum_t; } switch_application_flag_enum_t;
typedef uint32_t switch_application_flag_t; typedef uint32_t switch_application_flag_t;
typedef enum {
SCAF_NONE = 0
} switch_chat_application_flag_enum_t;
typedef uint32_t switch_chat_application_flag_t;
/*! /*!
\enum switch_signal_t \enum switch_signal_t
\brief Signals to send to channels \brief Signals to send to channels
@ -1729,6 +1737,7 @@ typedef struct switch_timer_interface switch_timer_interface_t;
typedef struct switch_dialplan_interface switch_dialplan_interface_t; typedef struct switch_dialplan_interface switch_dialplan_interface_t;
typedef struct switch_codec_interface switch_codec_interface_t; typedef struct switch_codec_interface switch_codec_interface_t;
typedef struct switch_application_interface switch_application_interface_t; typedef struct switch_application_interface switch_application_interface_t;
typedef struct switch_chat_application_interface switch_chat_application_interface_t;
typedef struct switch_api_interface switch_api_interface_t; typedef struct switch_api_interface switch_api_interface_t;
typedef struct switch_file_interface switch_file_interface_t; typedef struct switch_file_interface switch_file_interface_t;
typedef struct switch_speech_interface switch_speech_interface_t; typedef struct switch_speech_interface switch_speech_interface_t;
@ -1780,7 +1789,8 @@ typedef switch_status_t (*switch_core_codec_fmtp_parse_func_t) (const char *fmtp
typedef switch_status_t (*switch_core_codec_destroy_func_t) (switch_codec_t *); typedef switch_status_t (*switch_core_codec_destroy_func_t) (switch_codec_t *);
typedef switch_status_t (*switch_chat_application_function_t) (switch_event_t *, const char *);
#define SWITCH_STANDARD_CHAT_APP(name) static switch_status_t name (switch_event_t *message, const char *data)
typedef void (*switch_application_function_t) (switch_core_session_t *, const char *); typedef void (*switch_application_function_t) (switch_core_session_t *, const char *);
#define SWITCH_STANDARD_APP(name) static void name (switch_core_session_t *session, const char *data) #define SWITCH_STANDARD_APP(name) static void name (switch_core_session_t *session, const char *data)

View File

@ -0,0 +1,287 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="mod_sms"
ProjectGUID="{11C9BC3D-45E9-46E3-BE84-B8CEE4685E39}"
RootNamespace="mod_sms"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\mod_sms.c"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>mod_sms</ProjectName>
<ProjectGuid>{11C9BC3D-45E9-46E3-BE84-B8CEE4685E39}</ProjectGuid>
<RootNamespace>mod_sms</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\w32\module_release.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\w32\module_debug.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\w32\module_release.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\..\w32\module_debug.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
</ClCompile>
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
</ClCompile>
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
</ClCompile>
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
</ClCompile>
<Link>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="mod_sms.c" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\w32\Library\FreeSwitchCore.2010.vcxproj">
<Project>{202d7a4e-760d-4d0e-afa1-d7459ced30ff}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,510 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2011, Anthony Minessale II <anthm@freeswitch.org>
*
* 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 <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthm@freeswitch.org>
*
* mod_sms.c -- Abstract SMS
*
*/
#include <switch.h>
#define SMS_CHAT_PROTO "GLOBAL_SMS"
#define MY_EVENT_SEND_MESSAGE "SMS::SEND_MESSAGE"
/* Prototypes */
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sms_shutdown);
SWITCH_MODULE_RUNTIME_FUNCTION(mod_sms_runtime);
SWITCH_MODULE_LOAD_FUNCTION(mod_sms_load);
SWITCH_MODULE_DEFINITION(mod_sms, mod_sms_load, mod_sms_shutdown, NULL);
static void event_handler(switch_event_t *event)
{
const char *dest_proto = switch_event_get_header(event, "dest_proto");
switch_core_chat_send(dest_proto, event);
}
typedef enum {
BREAK_ON_TRUE,
BREAK_ON_FALSE,
BREAK_ALWAYS,
BREAK_NEVER
} break_t;
static int parse_exten(switch_event_t *event, switch_xml_t xexten, switch_event_t **extension)
{
switch_xml_t xcond, xaction, xexpression;
char *exten_name = (char *) switch_xml_attr(xexten, "name");
int proceed = 0;
char *expression_expanded = NULL, *field_expanded = NULL;
switch_regex_t *re = NULL;
const char *to = switch_event_get_header(event, "to");
if (!to) {
to = "nobody";
}
if (!exten_name) {
exten_name = "_anon_";
}
for (xcond = switch_xml_child(xexten, "condition"); xcond; xcond = xcond->next) {
char *field = NULL;
char *do_break_a = NULL;
char *expression = NULL;
const char *field_data = NULL;
int ovector[30];
switch_bool_t anti_action = SWITCH_TRUE;
break_t do_break_i = BREAK_ON_FALSE;
int time_match = switch_xml_std_datetime_check(xcond);
switch_safe_free(field_expanded);
switch_safe_free(expression_expanded);
if (switch_xml_child(xcond, "condition")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Nested conditions are not allowed!\n");
proceed = 1;
goto done;
}
field = (char *) switch_xml_attr(xcond, "field");
if ((xexpression = switch_xml_child(xcond, "expression"))) {
expression = switch_str_nil(xexpression->txt);
} else {
expression = (char *) switch_xml_attr_soft(xcond, "expression");
}
if ((expression_expanded = switch_event_expand_headers(event, expression)) == expression) {
expression_expanded = NULL;
} else {
expression = expression_expanded;
}
if ((do_break_a = (char *) switch_xml_attr(xcond, "break"))) {
if (!strcasecmp(do_break_a, "on-true")) {
do_break_i = BREAK_ON_TRUE;
} else if (!strcasecmp(do_break_a, "on-false")) {
do_break_i = BREAK_ON_FALSE;
} else if (!strcasecmp(do_break_a, "always")) {
do_break_i = BREAK_ALWAYS;
} else if (!strcasecmp(do_break_a, "never")) {
do_break_i = BREAK_NEVER;
} else {
do_break_a = NULL;
}
}
if (time_match == 1) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s Date/Time Match (PASS) [%s] break=%s\n",
to, exten_name, do_break_a ? do_break_a : "on-false");
anti_action = SWITCH_FALSE;
} else if (time_match == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s Date/Time Match (FAIL) [%s] break=%s\n",
to, exten_name, do_break_a ? do_break_a : "on-false");
}
if (field) {
if (strchr(field, '$')) {
if ((field_expanded = switch_event_expand_headers(event, field)) == field) {
field_expanded = NULL;
field_data = field;
} else {
field_data = field_expanded;
}
} else {
field_data = switch_event_get_header(event, field);
}
if (!field_data) {
field_data = "";
}
if ((proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s Regex (PASS) [%s] %s(%s) =~ /%s/ break=%s\n",
to, exten_name, field, field_data, expression, do_break_a ? do_break_a : "on-false");
anti_action = SWITCH_FALSE;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s Regex (FAIL) [%s] %s(%s) =~ /%s/ break=%s\n",
to, exten_name, field, field_data, expression, do_break_a ? do_break_a : "on-false");
}
} else if (time_match == -1) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s Absolute Condition [%s]\n", to, exten_name);
anti_action = SWITCH_FALSE;
}
if (anti_action) {
for (xaction = switch_xml_child(xcond, "anti-action"); xaction; xaction = xaction->next) {
const char *application = switch_xml_attr_soft(xaction, "application");
const char *loop = switch_xml_attr(xaction, "loop");
const char *data;
const char *inline_ = switch_xml_attr_soft(xaction, "inline");
int xinline = switch_true(inline_);
int loop_count = 1;
if (!zstr(xaction->txt)) {
data = xaction->txt;
} else {
data = (char *) switch_xml_attr_soft(xaction, "data");
}
if (!*extension) {
if ((switch_event_create(extension, SWITCH_EVENT_CLONE)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
abort();
}
}
if (loop) {
loop_count = atoi(loop);
}
for (;loop_count > 0; loop_count--) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s ANTI-Action %s(%s) %s\n", to, application, data, xinline ? "INLINE" : "");
if (xinline) {
switch_core_execute_chat_app(event, application, data);
} else {
switch_event_add_header_string(*extension, SWITCH_STACK_BOTTOM, application, data);
}
}
proceed = 1;
}
} else {
if (field && strchr(expression, '(')) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "DP_MATCH", NULL);
switch_capture_regex(re, proceed, field_data, ovector, "DP_MATCH", switch_regex_set_event_header_callback, event);
}
for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
char *application = (char *) switch_xml_attr_soft(xaction, "application");
const char *loop = switch_xml_attr(xaction, "loop");
char *data = NULL;
char *substituted = NULL;
uint32_t len = 0;
char *app_data = NULL;
const char *inline_ = switch_xml_attr_soft(xaction, "inline");
int xinline = switch_true(inline_);
int loop_count = 1;
if (!zstr(xaction->txt)) {
data = xaction->txt;
} else {
data = (char *) switch_xml_attr_soft(xaction, "data");
}
if (field && strchr(expression, '(')) {
len = (uint32_t) (strlen(data) + strlen(field_data) + 10) * proceed;
if (!(substituted = malloc(len))) {
abort();
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, data, field_data, substituted, len, ovector);
app_data = substituted;
} else {
app_data = data;
}
if (!*extension) {
if ((switch_event_create(extension, SWITCH_EVENT_CLONE)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
abort();
}
}
if (loop) {
loop_count = atoi(loop);
}
for (;loop_count > 0; loop_count--) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s Action %s(%s) %s\n", to, application, app_data, xinline ? "INLINE" : "");
if (xinline) {
switch_core_execute_chat_app(event, application, app_data);
} else {
switch_event_add_header_string(*extension, SWITCH_STACK_BOTTOM, application, data);
}
}
switch_safe_free(substituted);
}
}
switch_regex_safe_free(re);
if (((anti_action == SWITCH_FALSE && do_break_i == BREAK_ON_TRUE) ||
(anti_action == SWITCH_TRUE && do_break_i == BREAK_ON_FALSE)) || do_break_i == BREAK_ALWAYS) {
break;
}
}
done:
switch_regex_safe_free(re);
switch_safe_free(field_expanded);
switch_safe_free(expression_expanded);
return proceed;
}
static switch_event_t *chatplan_hunt(switch_event_t *event)
{
switch_event_t *extension = NULL;
switch_xml_t alt_root = NULL, cfg, xml = NULL, xcontext, xexten = NULL;
const char *alt_path;
const char *context;
const char *from;
const char *to;
if (!(context = switch_event_get_header(event, "context"))) {
context = "default";
}
if (!(from = switch_event_get_header(event, "from_user"))) {
from = switch_event_get_header(event, "from");
}
if (!(to = switch_event_get_header(event, "to_user"))) {
to = switch_event_get_header(event, "to");
}
alt_path = switch_event_get_header(event, "alt_path");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing text message %s->%s in context %s\n", from, to, context);
/* get our handle to the "chatplan" section of the config */
if (!zstr(alt_path)) {
switch_xml_t conf = NULL, tag = NULL;
if (!(alt_root = switch_xml_parse_file_simple(alt_path))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of [%s] failed\n", alt_path);
goto done;
}
if ((conf = switch_xml_find_child(alt_root, "section", "name", "chatplan")) && (tag = switch_xml_find_child(conf, "chatplan", NULL, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Getting chatplan from alternate path: %s\n", alt_path);
xml = alt_root;
cfg = tag;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of chatplan failed\n");
goto done;
}
} else {
if (switch_xml_locate("chatplan", NULL, NULL, NULL, &xml, &cfg, event, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of chatplan failed\n");
goto done;
}
}
/* get a handle to the context tag */
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", context))) {
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", "global"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Context %s not found\n", context);
goto done;
}
}
xexten = switch_xml_child(xcontext, "extension");
while (xexten) {
int proceed = 0;
const char *cont = switch_xml_attr(xexten, "continue");
const char *exten_name = switch_xml_attr(xexten, "name");
if (!exten_name) {
exten_name = "UNKNOWN";
}
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG,
"Chatplan: %s parsing [%s->%s] continue=%s\n",
to, context, exten_name, cont ? cont : "false");
proceed = parse_exten(event, xexten, &extension);
if (proceed && !switch_true(cont)) {
break;
}
xexten = xexten->next;
}
switch_xml_free(xml);
xml = NULL;
done:
switch_xml_free(xml);
return extension;
}
static switch_status_t chat_send(switch_event_t *message_event)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_event_t *exten;
if ((exten = chatplan_hunt(message_event))) {
switch_event_header_t *hp;
for (hp = exten->headers; hp; hp = hp->next) {
status = switch_core_execute_chat_app(message_event, hp->name, hp->value);
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
}
switch_event_destroy(&exten);
}
status = SWITCH_STATUS_BREAK;
return status;
}
SWITCH_STANDARD_CHAT_APP(stop_function)
{
switch_set_flag(message, EF_NO_CHAT_EXEC);
return SWITCH_STATUS_FALSE;
}
SWITCH_STANDARD_CHAT_APP(send_function)
{
const char *dest_proto = data;
if (zstr(dest_proto)) {
dest_proto = switch_event_get_header(message, "dest_proto");
}
switch_core_chat_send(dest_proto, message);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_CHAT_APP(set_function)
{
char *var, *val;
if (data) {
var = strdup(data);
if ((val = strchr(var, '='))) {
*val++ = '\0';
}
if (zstr(val)) {
switch_event_del_header(message, var);
} else {
switch_event_add_header_string(message, SWITCH_STACK_BOTTOM, var, val);
}
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_CHAT_APP(fire_function)
{
switch_event_t *fireme;
switch_event_dup(&fireme, message);
switch_event_fire(&fireme);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_CHAT_APP(reply_function)
{
switch_event_t *reply;
const char *proto = switch_event_get_header(message, "proto");
if (proto) {
switch_ivr_create_message_reply(&reply, message, SMS_CHAT_PROTO);
if (!zstr(data)) {
switch_event_add_body(reply, data);
}
switch_core_chat_deliver(proto, &reply);
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_SUCCESS;
}
/* Macro expands to: switch_status_t mod_sms_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */
SWITCH_MODULE_LOAD_FUNCTION(mod_sms_load)
{
switch_chat_interface_t *chat_interface;
switch_chat_application_interface_t *chat_app_interface;
if (switch_event_bind(modname, SWITCH_EVENT_CUSTOM, MY_EVENT_SEND_MESSAGE, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CHAT(chat_interface, SMS_CHAT_PROTO, chat_send);
SWITCH_ADD_CHAT_APP(chat_app_interface, "reply", "reply to a message", "reply to a message", reply_function, "", SCAF_NONE);
SWITCH_ADD_CHAT_APP(chat_app_interface, "stop", "stop execution", "stop execution", stop_function, "", SCAF_NONE);
SWITCH_ADD_CHAT_APP(chat_app_interface, "set", "set a variable", "set a variable", set_function, "", SCAF_NONE);
SWITCH_ADD_CHAT_APP(chat_app_interface, "send", "send the message as-is", "send the message as-is", send_function, "", SCAF_NONE);
SWITCH_ADD_CHAT_APP(chat_app_interface, "fire", "fire the message", "fire the message", fire_function, "", SCAF_NONE);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
/*
Called when the system shuts down
Macro expands to: switch_status_t mod_sms_shutdown() */
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sms_shutdown)
{
switch_event_unbind_callback(event_handler);
return SWITCH_STATUS_SUCCESS;
}
/* 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
*/

View File

@ -2929,7 +2929,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
} }
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", to); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", to);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", subject); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", subject);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "normal"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "text/plain");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", hint); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", hint);
if (msg) { if (msg) {

View File

@ -99,7 +99,10 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
//const char *subject; //const char *subject;
const char *body; const char *body;
const char *type; const char *type;
const char *hint; const char *from_full;
char header[256] = "";
char *route_uri = NULL;
const char *network_ip = NULL, *network_port = NULL;
proto = switch_event_get_header(message_event, "proto"); proto = switch_event_get_header(message_event, "proto");
from = switch_event_get_header(message_event, "from"); from = switch_event_get_header(message_event, "from");
@ -107,8 +110,10 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
//subject = switch_event_get_header(message_event, "subject"); //subject = switch_event_get_header(message_event, "subject");
body = switch_event_get_body(message_event); body = switch_event_get_body(message_event);
type = switch_event_get_header(message_event, "type"); type = switch_event_get_header(message_event, "type");
hint = switch_event_get_header(message_event, "hint"); from_full = switch_event_get_header(message_event, "from_full");
network_ip = switch_event_get_header(message_event, "to_sip_ip");
network_port = switch_event_get_header(message_event, "to_sip_port");
if (!to) { if (!to) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To: header.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To: header.\n");
@ -130,6 +135,10 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
user = prof; user = prof;
prof = NULL; prof = NULL;
} }
if (!prof) {
prof = switch_event_get_header(message_event, "sip_profile");
}
if (!strncasecmp(user, "sip:", 4)) { if (!strncasecmp(user, "sip:", 4)) {
to_uri = user; to_uri = user;
@ -141,8 +150,9 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
} else { } else {
host++; host++;
} }
if (!prof) if (!prof) {
prof = host; prof = host;
}
} }
if (!prof || !(profile = sofia_glue_find_profile(prof))) { if (!prof || !(profile = sofia_glue_find_profile(prof))) {
@ -159,24 +169,34 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
} }
} }
if (to_uri) { if (to_uri) {
switch_console_push_match(&list, to_uri); switch_console_push_match(&list, to_uri);
} else if (!(list = sofia_reg_find_reg_url_multi(profile, user, host))) { } else if (!(list = sofia_reg_find_reg_url_multi(profile, user, host))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find registered user %s@%s\n", user, host); sofia_profile_t *test;
goto end;
if ((test = sofia_glue_find_profile(host))) {
sofia_glue_release_profile(test);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Not sending to local box for %s@%s\n", user, host);
/* our box let's not send it */
} else {
char *tmp;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Can't find registered user %s@%s\n", user, host);
tmp = switch_mprintf("sip:%s@%s", user, host);
switch_console_push_match(&list, tmp);
free(tmp);
}
} }
if (!strcasecmp(proto, SOFIA_CHAT_PROTO)) { if (!strcasecmp(proto, SOFIA_CHAT_PROTO)) {
from = hint; from = from_full;
} else { } else {
char *fp, *p = NULL; char *fp, *p = NULL;
fp = strdup(from); fp = strdup(from);
switch_assert(fp);
if (!fp) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
goto end;
}
if ((p = strchr(fp, '@'))) { if ((p = strchr(fp, '@'))) {
*p++ = '\0'; *p++ = '\0';
@ -189,12 +209,23 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
} }
} }
ffrom = switch_mprintf("\"%s\" <sip:%s+%s@%s>", fp, proto, fp, p); if (switch_stristr("global", proto)) {
ffrom = switch_mprintf("\"%s\" <sip:%s@%s>", fp, fp, p);
} else {
ffrom = switch_mprintf("\"%s\" <sip:%s+%s@%s>", fp, proto, fp, p);
}
from = ffrom; from = ffrom;
switch_safe_free(fp); switch_safe_free(fp);
} }
if (!list) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Chat proto [%s]\nfrom [%s]\nto [%s]\n%s\nNobody to send to: Profile %s\n", proto, from, to,
body ? body : "[no body]", prof ? prof : "NULL");
goto end;
}
for (m = list->head; m; m = m->next) { for (m = list->head; m; m = m->next) {
if (!(dst = sofia_glue_get_destination(m->val))) { if (!(dst = sofia_glue_get_destination(m->val))) {
@ -250,21 +281,34 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
/* if this cries, add contact here too, change the 1 to 0 and omit the safe_free */ /* if this cries, add contact here too, change the 1 to 0 and omit the safe_free */
//printf("DEBUG To: [%s] From: [%s] Contact: [%s] RURI [%s] ip [%s] port [%s]\n", to, from, contact, dst->route_uri, network_ip, network_port);
//DUMP_EVENT(message_event);
if (zstr(dst->route_uri) && !zstr(user) && !zstr(network_ip) && (zstr(host) || strcmp(network_ip, host))) {
route_uri = switch_mprintf("sip:%s@%s:%s", user, network_ip, network_port);
}
msg_nh = nua_handle(profile->nua, NULL, msg_nh = nua_handle(profile->nua, NULL,
TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)),
TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
SIPTAG_FROM_STR(from),
TAG_IF(contact, NUTAG_URL(contact)),
SIPTAG_TO_STR(dup_dest),
SIPTAG_CONTACT_STR(contact_str),
TAG_END()); TAG_END());
nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private); nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private);
switch_snprintf(header, sizeof(header), "X-FS-Sending-Message: %s", switch_core_get_uuid());
nua_message(msg_nh, nua_message(msg_nh,
TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)),
TAG_IF(route_uri, NUTAG_PROXY(route_uri)),
TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
SIPTAG_FROM_STR(from),
TAG_IF(contact, NUTAG_URL(contact)),
SIPTAG_TO_STR(dup_dest),
SIPTAG_CONTACT_STR(contact_str),
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)), TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_CONTENT_TYPE_STR(ct),
SIPTAG_PAYLOAD_STR(body), SIPTAG_PAYLOAD_STR(body),
SIPTAG_HEADER_STR(header),
TAG_END()); TAG_END());
sofia_glue_free_destination(dst); sofia_glue_free_destination(dst);
@ -277,6 +321,7 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event)
end: end:
switch_safe_free(contact); switch_safe_free(contact);
switch_safe_free(route_uri);
switch_safe_free(ffrom); switch_safe_free(ffrom);
switch_safe_free(dup); switch_safe_free(dup);
@ -2873,13 +2918,25 @@ void sofia_presence_handle_sip_i_message(int status,
const char *to_host = NULL; const char *to_host = NULL;
sip_payload_t *payload = sip->sip_payload; sip_payload_t *payload = sip->sip_payload;
char *msg = NULL; char *msg = NULL;
const char *us;
char network_ip[80];
int network_port = 0;
if ((us = sofia_glue_get_unknown_header(sip, "X-FS-Sending-Message")) && !strcmp(us, switch_core_get_uuid())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Not sending message to ourselves!\n");
goto end;
}
if (sip->sip_content_type && sip->sip_content_type->c_subtype) { if (sip->sip_content_type && sip->sip_content_type->c_subtype) {
if (strstr(sip->sip_content_type->c_subtype, "composing")) { if (strstr(sip->sip_content_type->c_subtype, "composing")) {
return; goto end;
} }
} }
sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), &network_port);
if (from) { if (from) {
from_user = from->a_url->url_user; from_user = from->a_url->url_user;
from_host = from->a_url->url_host; from_host = from->a_url->url_host;
@ -2891,7 +2948,7 @@ void sofia_presence_handle_sip_i_message(int status,
} }
if (!to_user) { if (!to_user) {
return; goto end;
} }
if (payload) { if (payload) {
@ -2924,7 +2981,7 @@ void sofia_presence_handle_sip_i_message(int status,
to_addr = switch_mprintf("%s@%s", to_user, to_host); to_addr = switch_mprintf("%s@%s", to_user, to_host);
} }
from_addr = switch_mprintf("%s/%s@%s", profile->name, from_user, from_host); from_addr = switch_mprintf("%s@%s", from_user, from_host);
if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT)) { if (sofia_test_pflag(profile, PFLAG_IN_DIALOG_CHAT)) {
sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip); sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
@ -2936,10 +2993,22 @@ void sofia_presence_handle_sip_i_message(int status,
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", from_addr); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", from_addr);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_user", from_user); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_user", from_user);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_host", from_host); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_host", from_host);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to_user", to_user);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to_host", to_host);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_sip_ip", network_ip);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from_sip_port", "%d", network_port);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", to_addr); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to", to_addr);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "SIMPLE MESSAGE"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "SIMPLE MESSAGE");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "normal");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hint", full_from);
if (sip->sip_content_type && sip->sip_content_type->c_subtype) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", sip->sip_content_type->c_type);
} else {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "text/plain");
}
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_full", full_from);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_profile", profile->name);
if (msg) { if (msg) {
switch_event_add_body(event, "%s", msg); switch_event_add_body(event, "%s", msg);
@ -2952,7 +3021,6 @@ void sofia_presence_handle_sip_i_message(int status,
switch_core_session_queue_event(tech_pvt->session, &event); switch_core_session_queue_event(tech_pvt->session, &event);
} else { } else {
switch_core_chat_send(proto, event); switch_core_chat_send(proto, event);
switch_core_chat_send("GLOBAL", event);
switch_event_destroy(&event); switch_event_destroy(&event);
} }
@ -2964,6 +3032,11 @@ void sofia_presence_handle_sip_i_message(int status,
} }
} }
} }
end:
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(de->data->e_msg), TAG_END());
} }
void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip) void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip)

View File

@ -1397,7 +1397,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
} }
/* Log line added to support Fail2Ban */ /* Log line added to support Fail2Ban */
if (sofia_test_pflag(profile, PFLAG_LOG_AUTH_FAIL)) { if (sofia_test_pflag(profile, PFLAG_LOG_AUTH_FAIL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SIP auth challenge (%s) on sofia profile '%s' " switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "SIP auth challenge (%s) on sofia profile '%s' "
"for [%s@%s] from ip %s\n", (regtype == REG_INVITE) ? "INVITE" : "REGISTER", "for [%s@%s] from ip %s\n", (regtype == REG_INVITE) ? "INVITE" : "REGISTER",
profile->name, to_user, to_host, network_ip); profile->name, to_user, to_host, network_ip);
} }

View File

@ -66,6 +66,14 @@ public class Event {
this(freeswitchJNI.new_Event__SWIG_1(SWIGTYPE_p_switch_event_t.getCPtr(wrap_me), free_me), true); this(freeswitchJNI.new_Event__SWIG_1(SWIGTYPE_p_switch_event_t.getCPtr(wrap_me), free_me), true);
} }
public int chat_execute(String app, String data) {
return freeswitchJNI.Event_chat_execute(swigCPtr, this, app, data);
}
public int chat_send(String dest_proto) {
return freeswitchJNI.Event_chat_send(swigCPtr, this, dest_proto);
}
public String serialize(String format) { public String serialize(String format) {
return freeswitchJNI.Event_serialize(swigCPtr, this, format); return freeswitchJNI.Event_serialize(swigCPtr, this, format);
} }

View File

@ -54,6 +54,8 @@ class freeswitchJNI {
public final static native long new_Event__SWIG_0(String jarg1, String jarg2); public final static native long new_Event__SWIG_0(String jarg1, String jarg2);
public final static native long new_Event__SWIG_1(long jarg1, int jarg2); public final static native long new_Event__SWIG_1(long jarg1, int jarg2);
public final static native void delete_Event(long jarg1); public final static native void delete_Event(long jarg1);
public final static native int Event_chat_execute(long jarg1, Event jarg1_, String jarg2, String jarg3);
public final static native int Event_chat_send(long jarg1, Event jarg1_, String jarg2);
public final static native String Event_serialize(long jarg1, Event jarg1_, String jarg2); public final static native String Event_serialize(long jarg1, Event jarg1_, String jarg2);
public final static native boolean Event_setPriority(long jarg1, Event jarg1_, long jarg2); public final static native boolean Event_setPriority(long jarg1, Event jarg1_, long jarg2);
public final static native String Event_getHeader(long jarg1, Event jarg1_, String jarg2); public final static native String Event_getHeader(long jarg1, Event jarg1_, String jarg2);

View File

@ -1054,6 +1054,57 @@ SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_delete_1Event(JNI
} }
SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_Event_1chat_1execute(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jstring jarg3) {
jint jresult = 0 ;
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) NULL ;
int result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(Event **)&jarg1;
arg2 = 0;
if (jarg2) {
arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0);
if (!arg2) return 0;
}
arg3 = 0;
if (jarg3) {
arg3 = (char *)jenv->GetStringUTFChars(jarg3, 0);
if (!arg3) return 0;
}
result = (int)(arg1)->chat_execute((char const *)arg2,(char const *)arg3);
jresult = (jint)result;
if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2);
if (arg3) jenv->ReleaseStringUTFChars(jarg3, (const char *)arg3);
return jresult;
}
SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_Event_1chat_1send(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
jint jresult = 0 ;
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) NULL ;
int result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(Event **)&jarg1;
arg2 = 0;
if (jarg2) {
arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0);
if (!arg2) return 0;
}
result = (int)(arg1)->chat_send((char const *)arg2);
jresult = (jint)result;
if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2);
return jresult;
}
SWIGEXPORT jstring JNICALL Java_org_freeswitch_swig_freeswitchJNI_Event_1serialize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) { SWIGEXPORT jstring JNICALL Java_org_freeswitch_swig_freeswitchJNI_Event_1serialize(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
jstring jresult = 0 ; jstring jresult = 0 ;
Event *arg1 = (Event *) 0 ; Event *arg1 = (Event *) 0 ;

View File

@ -430,6 +430,24 @@ SWITCH_STANDARD_API(luarun_api_function)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_STANDARD_CHAT_APP(lua_chat_function)
{
lua_State *L = lua_init();
char *dup = NULL;
if (data) {
dup = strdup(data);
}
mod_lua_conjure_event(L, message, "message", 1);
lua_parse_and_execute(L, (char *)dup);
lua_uninit(L);
switch_safe_free(dup);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(lua_api_function) SWITCH_STANDARD_API(lua_api_function)
{ {
@ -591,6 +609,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
switch_api_interface_t *api_interface; switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface; switch_application_interface_t *app_interface;
switch_dialplan_interface_t *dp_interface; switch_dialplan_interface_t *dp_interface;
switch_chat_application_interface_t *chat_app_interface;
/* connect my internal structure to the blank pointer passed to me */ /* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *module_interface = switch_loadable_module_create_module_interface(pool, modname);
@ -600,6 +619,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_DIALPLAN(dp_interface, "LUA", lua_dialplan_hunt); SWITCH_ADD_DIALPLAN(dp_interface, "LUA", lua_dialplan_hunt);
SWITCH_ADD_CHAT_APP(chat_app_interface, "lua", "execute a lua script", "execute a lua script", lua_chat_function, "<script>", SCAF_NONE);
globals.pool = pool; globals.pool = pool;

View File

@ -2890,6 +2890,69 @@ fail:
} }
static int _wrap_Event_chat_execute(lua_State* L) {
int SWIG_arg = -1;
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) NULL ;
int result;
SWIG_check_num_args("chat_execute",2,3)
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("chat_execute",1,"Event *");
if(!lua_isstring(L,2)) SWIG_fail_arg("chat_execute",2,"char const *");
if(lua_gettop(L)>=3 && !lua_isstring(L,3)) SWIG_fail_arg("chat_execute",3,"char const *");
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
SWIG_fail_ptr("Event_chat_execute",1,SWIGTYPE_p_Event);
}
arg2 = (char *)lua_tostring(L, 2);
if(lua_gettop(L)>=3){
arg3 = (char *)lua_tostring(L, 3);
}
result = (int)(arg1)->chat_execute((char const *)arg2,(char const *)arg3);
SWIG_arg=0;
lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap_Event_chat_send(lua_State* L) {
int SWIG_arg = -1;
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) NULL ;
int result;
SWIG_check_num_args("chat_send",1,2)
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("chat_send",1,"Event *");
if(lua_gettop(L)>=2 && !lua_isstring(L,2)) SWIG_fail_arg("chat_send",2,"char const *");
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
SWIG_fail_ptr("Event_chat_send",1,SWIGTYPE_p_Event);
}
if(lua_gettop(L)>=2){
arg2 = (char *)lua_tostring(L, 2);
}
result = (int)(arg1)->chat_send((char const *)arg2);
SWIG_arg=0;
lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
return SWIG_arg;
if(0) SWIG_fail;
fail:
lua_error(L);
return SWIG_arg;
}
static int _wrap_Event_serialize(lua_State* L) { static int _wrap_Event_serialize(lua_State* L) {
int SWIG_arg = -1; int SWIG_arg = -1;
Event *arg1 = (Event *) 0 ; Event *arg1 = (Event *) 0 ;
@ -3149,6 +3212,8 @@ Event *arg1 = (Event *) obj;
delete arg1; delete arg1;
} }
static swig_lua_method swig_Event_methods[] = { static swig_lua_method swig_Event_methods[] = {
{"chat_execute", _wrap_Event_chat_execute},
{"chat_send", _wrap_Event_chat_send},
{"serialize", _wrap_Event_serialize}, {"serialize", _wrap_Event_serialize},
{"setPriority", _wrap_Event_setPriority}, {"setPriority", _wrap_Event_setPriority},
{"getHeader", _wrap_Event_getHeader}, {"getHeader", _wrap_Event_getHeader},

View File

@ -5590,6 +5590,18 @@ SWIGEXPORT void SWIGSTDCALL CSharp_switch_regex_set_var_callback(char * jarg1, c
} }
SWIGEXPORT void SWIGSTDCALL CSharp_switch_regex_set_event_header_callback(char * jarg1, char * jarg2, void * jarg3) {
char *arg1 = (char *) 0 ;
char *arg2 = (char *) 0 ;
void *arg3 = (void *) 0 ;
arg1 = (char *)jarg1;
arg2 = (char *)jarg2;
arg3 = (void *)jarg3;
switch_regex_set_event_header_callback((char const *)arg1,(char const *)arg2,arg3);
}
SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_MAX_CORE_THREAD_SESSION_OBJS_get() { SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_MAX_CORE_THREAD_SESSION_OBJS_get() {
int jresult ; int jresult ;
int result; int result;
@ -10542,6 +10554,20 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_chat_send(char * jarg1, void * jar
} }
SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_chat_deliver(char * jarg1, void * jarg2) {
int jresult ;
char *arg1 = (char *) 0 ;
switch_event_t **arg2 = (switch_event_t **) 0 ;
switch_status_t result;
arg1 = (char *)jarg1;
arg2 = (switch_event_t **)jarg2;
result = (switch_status_t)switch_core_chat_deliver((char const *)arg1,arg2);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_preprocess_session(void * jarg1, char * jarg2) { SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_preprocess_session(void * jarg1, char * jarg2) {
int jresult ; int jresult ;
switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
@ -11388,6 +11414,29 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_loadable_module_interface_applicatio
} }
SWIGEXPORT void SWIGSTDCALL CSharp_switch_loadable_module_interface_chat_application_interface_set(void * jarg1, void * jarg2) {
switch_loadable_module_interface *arg1 = (switch_loadable_module_interface *) 0 ;
switch_chat_application_interface_t *arg2 = (switch_chat_application_interface_t *) 0 ;
arg1 = (switch_loadable_module_interface *)jarg1;
arg2 = (switch_chat_application_interface_t *)jarg2;
if (arg1) (arg1)->chat_application_interface = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_loadable_module_interface_chat_application_interface_get(void * jarg1) {
void * jresult ;
switch_loadable_module_interface *arg1 = (switch_loadable_module_interface *) 0 ;
switch_chat_application_interface_t *result = 0 ;
arg1 = (switch_loadable_module_interface *)jarg1;
result = (switch_chat_application_interface_t *) ((arg1)->chat_application_interface);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_loadable_module_interface_api_interface_set(void * jarg1, void * jarg2) { SWIGEXPORT void SWIGSTDCALL CSharp_switch_loadable_module_interface_api_interface_set(void * jarg1, void * jarg2) {
switch_loadable_module_interface *arg1 = (switch_loadable_module_interface *) 0 ; switch_loadable_module_interface *arg1 = (switch_loadable_module_interface *) 0 ;
switch_api_interface_t *arg2 = (switch_api_interface_t *) 0 ; switch_api_interface_t *arg2 = (switch_api_interface_t *) 0 ;
@ -11810,6 +11859,34 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_switch_loadable_module_get_application_inte
} }
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_loadable_module_get_chat_application_interface(char * jarg1) {
void * jresult ;
char *arg1 = (char *) 0 ;
switch_chat_application_interface_t *result = 0 ;
arg1 = (char *)jarg1;
result = (switch_chat_application_interface_t *)switch_loadable_module_get_chat_application_interface((char const *)arg1);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_execute_chat_app(void * jarg1, char * jarg2, char * jarg3) {
int jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
switch_status_t result;
arg1 = (switch_event_t *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
result = (switch_status_t)switch_core_execute_chat_app(arg1,(char const *)arg2,(char const *)arg3);
jresult = result;
return jresult;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_loadable_module_get_api_interface(char * jarg1) { SWIGEXPORT void * SWIGSTDCALL CSharp_switch_loadable_module_get_api_interface(char * jarg1) {
void * jresult ; void * jresult ;
char *arg1 = (char *) 0 ; char *arg1 = (char *) 0 ;
@ -23227,6 +23304,302 @@ SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_application_interface(void * ja
} }
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_interface_name_set(void * jarg1, char * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
char *arg2 = (char *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (char *)jarg2;
{
if (arg2) {
arg1->interface_name = (char const *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->interface_name, (const char *)arg2);
} else {
arg1->interface_name = 0;
}
}
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_chat_application_interface_interface_name_get(void * jarg1) {
char * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
char *result = 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
result = (char *) ((arg1)->interface_name);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_chat_application_function_set(void * jarg1, void * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_chat_application_function_t arg2 = (switch_chat_application_function_t) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (switch_chat_application_function_t)jarg2;
if (arg1) (arg1)->chat_application_function = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_chat_application_interface_chat_application_function_get(void * jarg1) {
void * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_chat_application_function_t result;
arg1 = (switch_chat_application_interface *)jarg1;
result = (switch_chat_application_function_t) ((arg1)->chat_application_function);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_long_desc_set(void * jarg1, char * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
char *arg2 = (char *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (char *)jarg2;
{
if (arg2) {
arg1->long_desc = (char const *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->long_desc, (const char *)arg2);
} else {
arg1->long_desc = 0;
}
}
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_chat_application_interface_long_desc_get(void * jarg1) {
char * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
char *result = 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
result = (char *) ((arg1)->long_desc);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_short_desc_set(void * jarg1, char * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
char *arg2 = (char *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (char *)jarg2;
{
if (arg2) {
arg1->short_desc = (char const *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->short_desc, (const char *)arg2);
} else {
arg1->short_desc = 0;
}
}
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_chat_application_interface_short_desc_get(void * jarg1) {
char * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
char *result = 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
result = (char *) ((arg1)->short_desc);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_syntax_set(void * jarg1, char * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
char *arg2 = (char *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (char *)jarg2;
{
if (arg2) {
arg1->syntax = (char const *) (new char[strlen((const char *)arg2)+1]);
strcpy((char *)arg1->syntax, (const char *)arg2);
} else {
arg1->syntax = 0;
}
}
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_chat_application_interface_syntax_get(void * jarg1) {
char * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
char *result = 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
result = (char *) ((arg1)->syntax);
jresult = SWIG_csharp_string_callback((const char *)result);
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_flags_set(void * jarg1, unsigned long jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
uint32_t arg2 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (uint32_t)jarg2;
if (arg1) (arg1)->flags = arg2;
}
SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_chat_application_interface_flags_get(void * jarg1) {
unsigned long jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
uint32_t result;
arg1 = (switch_chat_application_interface *)jarg1;
result = (uint32_t) ((arg1)->flags);
jresult = (unsigned long)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_rwlock_set(void * jarg1, void * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_thread_rwlock_t *arg2 = (switch_thread_rwlock_t *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (switch_thread_rwlock_t *)jarg2;
if (arg1) (arg1)->rwlock = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_chat_application_interface_rwlock_get(void * jarg1) {
void * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_thread_rwlock_t *result = 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
result = (switch_thread_rwlock_t *) ((arg1)->rwlock);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_refs_set(void * jarg1, int jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
int arg2 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (int)jarg2;
if (arg1) (arg1)->refs = arg2;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_chat_application_interface_refs_get(void * jarg1) {
int jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
int result;
arg1 = (switch_chat_application_interface *)jarg1;
result = (int) ((arg1)->refs);
jresult = result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_reflock_set(void * jarg1, void * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_mutex_t *arg2 = (switch_mutex_t *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (switch_mutex_t *)jarg2;
if (arg1) (arg1)->reflock = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_chat_application_interface_reflock_get(void * jarg1) {
void * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_mutex_t *result = 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
result = (switch_mutex_t *) ((arg1)->reflock);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_parent_set(void * jarg1, void * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_loadable_module_interface_t *arg2 = (switch_loadable_module_interface_t *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (switch_loadable_module_interface_t *)jarg2;
if (arg1) (arg1)->parent = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_chat_application_interface_parent_get(void * jarg1) {
void * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_loadable_module_interface_t *result = 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
result = (switch_loadable_module_interface_t *) ((arg1)->parent);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_chat_application_interface_next_set(void * jarg1, void * jarg2) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_chat_application_interface *arg2 = (switch_chat_application_interface *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
arg2 = (switch_chat_application_interface *)jarg2;
if (arg1) (arg1)->next = arg2;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_switch_chat_application_interface_next_get(void * jarg1) {
void * jresult ;
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
switch_chat_application_interface *result = 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
result = (switch_chat_application_interface *) ((arg1)->next);
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void * SWIGSTDCALL CSharp_new_switch_chat_application_interface() {
void * jresult ;
switch_chat_application_interface *result = 0 ;
result = (switch_chat_application_interface *)new switch_chat_application_interface();
jresult = (void *)result;
return jresult;
}
SWIGEXPORT void SWIGSTDCALL CSharp_delete_switch_chat_application_interface(void * jarg1) {
switch_chat_application_interface *arg1 = (switch_chat_application_interface *) 0 ;
arg1 = (switch_chat_application_interface *)jarg1;
delete arg1;
}
SWIGEXPORT void SWIGSTDCALL CSharp_switch_api_interface_interface_name_set(void * jarg1, char * jarg2) { SWIGEXPORT void SWIGSTDCALL CSharp_switch_api_interface_interface_name_set(void * jarg1, char * jarg2) {
switch_api_interface *arg1 = (switch_api_interface *) 0 ; switch_api_interface *arg1 = (switch_api_interface *) 0 ;
char *arg2 = (char *) 0 ; char *arg2 = (char *) 0 ;
@ -26443,6 +26816,22 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_get_header_idx(void * jarg1, c
} }
SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_rename_header(void * jarg1, char * jarg2, char * jarg3) {
int jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
switch_status_t result;
arg1 = (switch_event_t *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
result = (switch_status_t)switch_event_rename_header(arg1,(char const *)arg2,(char const *)arg3);
jresult = result;
return jresult;
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_get_body(void * jarg1) { SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_get_body(void * jarg1) {
char * jresult ; char * jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ; switch_event_t *arg1 = (switch_event_t *) 0 ;
@ -26551,6 +26940,20 @@ SWIGEXPORT void SWIGSTDCALL CSharp_switch_event_merge(void * jarg1, void * jarg2
} }
SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_dup_reply(void * jarg1, void * jarg2) {
int jresult ;
switch_event_t **arg1 = (switch_event_t **) 0 ;
switch_event_t *arg2 = (switch_event_t *) 0 ;
switch_status_t result;
arg1 = (switch_event_t **)jarg1;
arg2 = (switch_event_t *)jarg2;
result = (switch_status_t)switch_event_dup_reply(arg1,arg2);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_fire_detailed(char * jarg1, char * jarg2, int jarg3, void * jarg4, void * jarg5) { SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_fire_detailed(char * jarg1, char * jarg2, int jarg3, void * jarg4, void * jarg5) {
int jresult ; int jresult ;
char *arg1 = (char *) 0 ; char *arg1 = (char *) 0 ;
@ -26783,6 +27186,20 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_running() {
} }
SWIGEXPORT int SWIGSTDCALL CSharp_switch_event_set_body(void * jarg1, char * jarg2) {
int jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ;
char *arg2 = (char *) 0 ;
switch_status_t result;
arg1 = (switch_event_t *)jarg1;
arg2 = (char *)jarg2;
result = (switch_status_t)switch_event_set_body(arg1,(char const *)arg2);
jresult = result;
return jresult;
}
SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_expand_headers(void * jarg1, char * jarg2) { SWIGEXPORT char * SWIGSTDCALL CSharp_switch_event_expand_headers(void * jarg1, char * jarg2) {
char * jresult ; char * jresult ;
switch_event_t *arg1 = (switch_event_t *) 0 ; switch_event_t *arg1 = (switch_event_t *) 0 ;
@ -29763,6 +30180,22 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_insert_file(void * jarg1, char * ja
} }
SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_create_message_reply(void * jarg1, void * jarg2, char * jarg3) {
int jresult ;
switch_event_t **arg1 = (switch_event_t **) 0 ;
switch_event_t *arg2 = (switch_event_t *) 0 ;
char *arg3 = (char *) 0 ;
switch_status_t result;
arg1 = (switch_event_t **)jarg1;
arg2 = (switch_event_t *)jarg2;
arg3 = (char *)jarg3;
result = (switch_status_t)switch_ivr_create_message_reply(arg1,arg2,(char const *)arg3);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_RTP_MAX_BUF_LEN_get() { SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_RTP_MAX_BUF_LEN_get() {
int jresult ; int jresult ;
int result; int result;
@ -34872,6 +35305,36 @@ SWIGEXPORT void SWIGSTDCALL CSharp_delete_Event(void * jarg1) {
} }
SWIGEXPORT int SWIGSTDCALL CSharp_Event_chat_execute(void * jarg1, char * jarg2, char * jarg3) {
int jresult ;
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) NULL ;
int result;
arg1 = (Event *)jarg1;
arg2 = (char *)jarg2;
arg3 = (char *)jarg3;
result = (int)(arg1)->chat_execute((char const *)arg2,(char const *)arg3);
jresult = result;
return jresult;
}
SWIGEXPORT int SWIGSTDCALL CSharp_Event_chat_send(void * jarg1, char * jarg2) {
int jresult ;
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) NULL ;
int result;
arg1 = (Event *)jarg1;
arg2 = (char *)jarg2;
result = (int)(arg1)->chat_send((char const *)arg2);
jresult = result;
return jresult;
}
SWIGEXPORT char * SWIGSTDCALL CSharp_Event_Serialize(void * jarg1, char * jarg2) { SWIGEXPORT char * SWIGSTDCALL CSharp_Event_Serialize(void * jarg1, char * jarg2) {
char * jresult ; char * jresult ;
Event *arg1 = (Event *) 0 ; Event *arg1 = (Event *) 0 ;

File diff suppressed because it is too large Load Diff

View File

@ -292,6 +292,8 @@ sub DESTROY {
} }
} }
*chat_execute = *freeswitchc::Event_chat_execute;
*chat_send = *freeswitchc::Event_chat_send;
*serialize = *freeswitchc::Event_serialize; *serialize = *freeswitchc::Event_serialize;
*setPriority = *freeswitchc::Event_setPriority; *setPriority = *freeswitchc::Event_setPriority;
*getHeader = *freeswitchc::Event_getHeader; *getHeader = *freeswitchc::Event_getHeader;

View File

@ -3679,6 +3679,99 @@ XS(_wrap_delete_Event) {
} }
XS(_wrap_Event_chat_execute) {
{
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) NULL ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int res3 ;
char *buf3 = 0 ;
int alloc3 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 2) || (items > 3)) {
SWIG_croak("Usage: Event_chat_execute(self,app,data);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_chat_execute" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_chat_execute" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
if (items > 2) {
res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3);
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Event_chat_execute" "', argument " "3"" of type '" "char const *""'");
}
arg3 = reinterpret_cast< char * >(buf3);
}
result = (int)(arg1)->chat_execute((char const *)arg2,(char const *)arg3);
ST(argvi) = SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
XSRETURN(argvi);
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
SWIG_croak_null();
}
}
XS(_wrap_Event_chat_send) {
{
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) NULL ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int argvi = 0;
dXSARGS;
if ((items < 1) || (items > 2)) {
SWIG_croak("Usage: Event_chat_send(self,dest_proto);");
}
res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_chat_send" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
if (items > 1) {
res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_chat_send" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
}
result = (int)(arg1)->chat_send((char const *)arg2);
ST(argvi) = SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ;
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
XSRETURN(argvi);
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
SWIG_croak_null();
}
}
XS(_wrap_Event_serialize) { XS(_wrap_Event_serialize) {
{ {
Event *arg1 = (Event *) 0 ; Event *arg1 = (Event *) 0 ;
@ -9492,6 +9585,8 @@ static swig_command_info swig_commands[] = {
{"freeswitchc::Event_mine_get", _wrap_Event_mine_get}, {"freeswitchc::Event_mine_get", _wrap_Event_mine_get},
{"freeswitchc::new_Event", _wrap_new_Event}, {"freeswitchc::new_Event", _wrap_new_Event},
{"freeswitchc::delete_Event", _wrap_delete_Event}, {"freeswitchc::delete_Event", _wrap_delete_Event},
{"freeswitchc::Event_chat_execute", _wrap_Event_chat_execute},
{"freeswitchc::Event_chat_send", _wrap_Event_chat_send},
{"freeswitchc::Event_serialize", _wrap_Event_serialize}, {"freeswitchc::Event_serialize", _wrap_Event_serialize},
{"freeswitchc::Event_setPriority", _wrap_Event_setPriority}, {"freeswitchc::Event_setPriority", _wrap_Event_setPriority},
{"freeswitchc::Event_getHeader", _wrap_Event_getHeader}, {"freeswitchc::Event_getHeader", _wrap_Event_getHeader},

View File

@ -175,6 +175,8 @@ class Event(_object):
except: self.this = this except: self.this = this
__swig_destroy__ = _freeswitch.delete_Event __swig_destroy__ = _freeswitch.delete_Event
__del__ = lambda self : None; __del__ = lambda self : None;
def chat_execute(*args): return _freeswitch.Event_chat_execute(*args)
def chat_send(*args): return _freeswitch.Event_chat_send(*args)
def serialize(*args): return _freeswitch.Event_serialize(*args) def serialize(*args): return _freeswitch.Event_serialize(*args)
def setPriority(*args): return _freeswitch.Event_setPriority(*args) def setPriority(*args): return _freeswitch.Event_setPriority(*args)
def getHeader(*args): return _freeswitch.Event_getHeader(*args) def getHeader(*args): return _freeswitch.Event_getHeader(*args)

View File

@ -4541,6 +4541,90 @@ fail:
} }
SWIGINTERN PyObject *_wrap_Event_chat_execute(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) NULL ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
int res3 ;
char *buf3 = 0 ;
int alloc3 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
if (!PyArg_ParseTuple(args,(char *)"OO|O:Event_chat_execute",&obj0,&obj1,&obj2)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_chat_execute" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_chat_execute" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
if (obj2) {
res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3);
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Event_chat_execute" "', argument " "3"" of type '" "char const *""'");
}
arg3 = reinterpret_cast< char * >(buf3);
}
result = (int)(arg1)->chat_execute((char const *)arg2,(char const *)arg3);
resultobj = SWIG_From_int(static_cast< int >(result));
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
return resultobj;
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
return NULL;
}
SWIGINTERN PyObject *_wrap_Event_chat_send(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
Event *arg1 = (Event *) 0 ;
char *arg2 = (char *) NULL ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
if (!PyArg_ParseTuple(args,(char *)"O|O:Event_chat_send",&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Event, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_chat_send" "', argument " "1"" of type '" "Event *""'");
}
arg1 = reinterpret_cast< Event * >(argp1);
if (obj1) {
res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_chat_send" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
}
result = (int)(arg1)->chat_send((char const *)arg2);
resultobj = SWIG_From_int(static_cast< int >(result));
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
return resultobj;
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
return NULL;
}
SWIGINTERN PyObject *_wrap_Event_serialize(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { SWIGINTERN PyObject *_wrap_Event_serialize(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0; PyObject *resultobj = 0;
Event *arg1 = (Event *) 0 ; Event *arg1 = (Event *) 0 ;
@ -9042,6 +9126,8 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"Event_mine_get", _wrap_Event_mine_get, METH_VARARGS, NULL}, { (char *)"Event_mine_get", _wrap_Event_mine_get, METH_VARARGS, NULL},
{ (char *)"new_Event", _wrap_new_Event, METH_VARARGS, NULL}, { (char *)"new_Event", _wrap_new_Event, METH_VARARGS, NULL},
{ (char *)"delete_Event", _wrap_delete_Event, METH_VARARGS, NULL}, { (char *)"delete_Event", _wrap_delete_Event, METH_VARARGS, NULL},
{ (char *)"Event_chat_execute", _wrap_Event_chat_execute, METH_VARARGS, NULL},
{ (char *)"Event_chat_send", _wrap_Event_chat_send, METH_VARARGS, NULL},
{ (char *)"Event_serialize", _wrap_Event_serialize, METH_VARARGS, NULL}, { (char *)"Event_serialize", _wrap_Event_serialize, METH_VARARGS, NULL},
{ (char *)"Event_setPriority", _wrap_Event_setPriority, METH_VARARGS, NULL}, { (char *)"Event_setPriority", _wrap_Event_setPriority, METH_VARARGS, NULL},
{ (char *)"Event_getHeader", _wrap_Event_getHeader, METH_VARARGS, NULL}, { (char *)"Event_getHeader", _wrap_Event_getHeader, METH_VARARGS, NULL},

View File

@ -284,6 +284,19 @@ SWITCH_DECLARE_CONSTRUCTOR Event::~Event()
} }
} }
SWITCH_DECLARE(int)Event::chat_execute(const char *app, const char *data)
{
return (int) switch_core_execute_chat_app(event, app, data);
}
SWITCH_DECLARE(int)Event::chat_send(const char *dest_proto)
{
if (zstr(dest_proto)) {
dest_proto = switch_event_get_header(event, "dest_proto");
}
return (int) switch_core_chat_send(dest_proto, event);
}
SWITCH_DECLARE(const char *)Event::serialize(const char *format) SWITCH_DECLARE(const char *)Event::serialize(const char *format)
{ {

View File

@ -697,7 +697,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_subclass_detailed(const char
memset(*event, 0, sizeof(switch_event_t)); memset(*event, 0, sizeof(switch_event_t));
if (event_id == SWITCH_EVENT_REQUEST_PARAMS || event_id == SWITCH_EVENT_CHANNEL_DATA) { if (event_id == SWITCH_EVENT_REQUEST_PARAMS || event_id == SWITCH_EVENT_CHANNEL_DATA || event_id == SWITCH_EVENT_MESSAGE) {
(*event)->flags |= EF_UNIQ_HEADERS; (*event)->flags |= EF_UNIQ_HEADERS;
} }
@ -721,6 +721,35 @@ SWITCH_DECLARE(switch_status_t) switch_event_set_priority(switch_event_t *event,
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_event_rename_header(switch_event_t *event, const char *header_name, const char *new_header_name)
{
switch_event_header_t *hp;
switch_ssize_t hlen = -1;
unsigned long hash = 0;
int x = 0;
switch_assert(event);
if (!header_name) {
return SWITCH_STATUS_FALSE;
}
hash = switch_ci_hashfunc_default(header_name, &hlen);
for (hp = event->headers; hp; hp = hp->next) {
if ((!hp->hash || hash == hp->hash) && !strcasecmp(hp->name, header_name)) {
FREE(hp->name);
hp->name = DUP(new_header_name);
hlen = -1;
hp->hash = switch_ci_hashfunc_default(hp->name, &hlen);
x++;
}
}
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_event_header_t *) switch_event_get_header_ptr(switch_event_t *event, const char *header_name) SWITCH_DECLARE(switch_event_header_t *) switch_event_get_header_ptr(switch_event_t *event, const char *header_name)
{ {
switch_event_header_t *hp; switch_event_header_t *hp;
@ -756,6 +785,8 @@ SWITCH_DECLARE(char *) switch_event_get_header_idx(switch_event_t *event, const
} }
return hp->value; return hp->value;
} else if (!strcmp(header_name, "_body")) {
return event->body;
} }
return NULL; return NULL;
@ -900,6 +931,11 @@ static switch_status_t switch_event_base_add_header(switch_event_t *event, switc
int index = 0; int index = 0;
char *real_header_name = NULL; char *real_header_name = NULL;
if (!strcmp(header_name, "_body")) {
switch_event_set_body(event, data);
}
if ((index_ptr = strchr(header_name, '['))) { if ((index_ptr = strchr(header_name, '['))) {
index_ptr++; index_ptr++;
index = atoi(index_ptr); index = atoi(index_ptr);
@ -1102,6 +1138,17 @@ SWITCH_DECLARE(switch_status_t) switch_event_add_header_string(switch_event_t *e
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
SWITCH_DECLARE(switch_status_t) switch_event_set_body(switch_event_t *event, const char *body)
{
switch_safe_free(event->body);
if (body) {
event->body = DUP(body);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, const char *fmt, ...) SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, const char *fmt, ...)
{ {
int ret = 0; int ret = 0;
@ -1228,6 +1275,64 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_event_dup_reply(switch_event_t **event, switch_event_t *todup)
{
switch_event_header_t *hp;
char hname[1024] = "";
char *p;
if (switch_event_create_subclass(event, SWITCH_EVENT_CLONE, todup->subclass_name) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}
(*event)->event_id = todup->event_id;
(*event)->event_user_data = todup->event_user_data;
(*event)->bind_user_data = todup->bind_user_data;
(*event)->flags = todup->flags;
for (hp = todup->headers; hp; hp = hp->next) {
char *name = hp->name, *value = hp->value;
if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
continue;
}
if (!strncasecmp(hp->name, "from_", 5)) {
p = hp->name + 5;
switch_snprintf(hname, sizeof(hname), "to_%s", p);
name = hname;
} else if (!strncasecmp(hp->name, "to_", 3)) {
p = hp->name + 3;
switch_snprintf(hname, sizeof(hname), "from_%s", p);
name = hname;
} else if (!strcasecmp(name, "to")) {
name = "from";
} else if (!strcasecmp(name, "from")) {
name = "to";
}
if (hp->idx) {
int i;
for (i = 0; i < hp->idx; i++) {
switch_event_add_header_string(*event, SWITCH_STACK_PUSH, name, hp->array[i]);
}
} else {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, name, value);
}
}
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "replying", "true");
if (todup->body) {
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "orig_body", todup->body);
}
(*event)->key = todup->key;
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode) SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode)
{ {
switch_size_t len = 0; switch_size_t len = 0;

View File

@ -3102,6 +3102,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_insert_file(switch_core_session_t *se
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_create_message_reply(switch_event_t **reply, switch_event_t *message, const char *new_proto)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
if ((status = switch_event_dup_reply(reply, message) != SWITCH_STATUS_SUCCESS)) {
abort();
}
switch_event_add_header_string(*reply, SWITCH_STACK_BOTTOM, "proto", new_proto);
return status;
}
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:

View File

@ -63,6 +63,7 @@ struct switch_loadable_module_container {
switch_hash_t *dialplan_hash; switch_hash_t *dialplan_hash;
switch_hash_t *timer_hash; switch_hash_t *timer_hash;
switch_hash_t *application_hash; switch_hash_t *application_hash;
switch_hash_t *chat_application_hash;
switch_hash_t *api_hash; switch_hash_t *api_hash;
switch_hash_t *file_hash; switch_hash_t *file_hash;
switch_hash_t *speech_hash; switch_hash_t *speech_hash;
@ -265,6 +266,28 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
} }
} }
if (new_module->module_interface->chat_application_interface) {
const switch_chat_application_interface_t *ptr;
for (ptr = new_module->module_interface->chat_application_interface; ptr; ptr = ptr->next) {
if (!ptr->interface_name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to load application interface from %s due to no interface name.\n", key);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Chat Application '%s'\n", ptr->interface_name);
if (switch_event_create(&event, SWITCH_EVENT_MODULE_LOAD) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "application");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "description", switch_str_nil(ptr->short_desc));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "syntax", switch_str_nil(ptr->syntax));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", new_module->key);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "filename", new_module->filename);
switch_event_fire(&event);
}
switch_core_hash_insert(loadable_modules.chat_application_hash, ptr->interface_name, (const void *) ptr);
}
}
}
if (new_module->module_interface->api_interface) { if (new_module->module_interface->api_interface) {
const switch_api_interface_t *ptr; const switch_api_interface_t *ptr;
@ -468,6 +491,239 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
} }
#define CHAT_MAX_MSG_QUEUE 101
#define CHAT_QUEUE_SIZE 5000
static struct {
switch_queue_t *msg_queue[CHAT_MAX_MSG_QUEUE];
switch_thread_t *msg_queue_thread[CHAT_MAX_MSG_QUEUE];
int msg_queue_len;
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
int running;
} chat_globals;
static int IDX = 0;
static switch_status_t do_chat_send(switch_event_t *message_event)
{
switch_chat_interface_t *ci;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_hash_index_t *hi;
const void *var;
void *val;
const char *proto;
const char *replying;
const char *dest_proto;
int do_skip = 0;
/*
const char *from;
const char *to;
const char *subject;
const char *body;
const char *type;
const char *hint;
*/
dest_proto = switch_event_get_header(message_event, "dest_proto");
if (!dest_proto) {
return SWITCH_STATUS_FALSE;
}
/*
from = switch_event_get_header(message_event, "from");
to = switch_event_get_header(message_event, "to");
subject = switch_event_get_header(message_event, "subject");
body = switch_event_get_body(message_event);
type = switch_event_get_header(message_event, "type");
hint = switch_event_get_header(message_event, "hint");
*/
proto = switch_event_get_header(message_event, "proto");
replying = switch_event_get_header(message_event, "replying");
if (!switch_true(replying) && !switch_stristr("global", proto)) {
switch_mutex_lock(loadable_modules.mutex);
for (hi = switch_hash_first(NULL, loadable_modules.chat_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
if ((ci = (switch_chat_interface_t *) val)) {
if (ci->chat_send && !strncasecmp(ci->interface_name, "GLOBAL_", 7)) {
status = ci->chat_send(message_event);
if (status == SWITCH_STATUS_BREAK) {
do_skip = 1;
}
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Chat Interface Error [%s]!\n", dest_proto);
break;
}
}
}
}
switch_mutex_unlock(loadable_modules.mutex);
}
if (!do_skip && !switch_stristr("GLOBAL", dest_proto)) {
if (!(ci = switch_loadable_module_get_chat_interface(dest_proto)) || !ci->chat_send) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid chat interface [%s]!\n", dest_proto);
return SWITCH_STATUS_FALSE;
}
status = ci->chat_send(message_event);
UNPROTECT_INTERFACE(ci);
}
return status;
}
static void chat_process_event(switch_event_t **eventp)
{
switch_event_t *event;
switch_assert(eventp);
event = *eventp;
*eventp = NULL;
do_chat_send(event);
switch_event_destroy(&event);
}
void *SWITCH_THREAD_FUNC chat_thread_run(switch_thread_t *thread, void *obj)
{
void *pop;
switch_queue_t *q = (switch_queue_t *) obj;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Chat Thread Started\n");
while(switch_queue_pop(q, &pop) == SWITCH_STATUS_SUCCESS && pop) {
switch_event_t *event = (switch_event_t *) pop;
chat_process_event(&event);
switch_cond_next();
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Chat Thread Ended\n");
return NULL;
}
static void chat_thread_start(int idx)
{
if (idx >= CHAT_MAX_MSG_QUEUE || (idx < chat_globals.msg_queue_len && chat_globals.msg_queue_thread[idx])) {
return;
}
switch_mutex_lock(chat_globals.mutex);
if (idx >= chat_globals.msg_queue_len) {
int i;
chat_globals.msg_queue_len = idx + 1;
for (i = 0; i < chat_globals.msg_queue_len; i++) {
if (!chat_globals.msg_queue[i]) {
switch_threadattr_t *thd_attr = NULL;
switch_queue_create(&chat_globals.msg_queue[i], CHAT_QUEUE_SIZE, chat_globals.pool);
switch_threadattr_create(&thd_attr, chat_globals.pool);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
//switch_threadattr_priority_increase(thd_attr);
switch_thread_create(&chat_globals.msg_queue_thread[i],
thd_attr,
chat_thread_run,
chat_globals.msg_queue[i],
chat_globals.pool);
}
}
}
switch_mutex_unlock(chat_globals.mutex);
}
static void chat_queue_message(switch_event_t **eventp)
{
int idx = 0;
switch_event_t *event;
switch_assert(eventp);
event = *eventp;
*eventp = NULL;
if (chat_globals.running == 0) {
chat_process_event(&event);
return;
}
again:
switch_mutex_lock(chat_globals.mutex);
idx = IDX;
IDX++;
if (IDX >= chat_globals.msg_queue_len) IDX = 0;
switch_mutex_unlock(chat_globals.mutex);
chat_thread_start(idx);
if (switch_queue_trypush(chat_globals.msg_queue[idx], event) != SWITCH_STATUS_SUCCESS) {
if (chat_globals.msg_queue_len < CHAT_MAX_MSG_QUEUE) {
chat_thread_start(idx + 1);
goto again;
} else {
switch_queue_push(chat_globals.msg_queue[idx], event);
}
}
}
SWITCH_DECLARE(switch_status_t) switch_core_execute_chat_app(switch_event_t *message, const char *app, const char *data)
{
switch_chat_application_interface_t *cai;
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *expanded;
if (!(cai = switch_loadable_module_get_chat_application_interface(app)) || !cai->chat_application_function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid chat application interface [%s]!\n", app);
return SWITCH_STATUS_FALSE;
}
if (switch_test_flag(message, EF_NO_CHAT_EXEC)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Message is not allowed to execute apps\n");
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
expanded = switch_event_expand_headers(message, data);
status = cai->chat_application_function(message, expanded);
if (expanded != data) {
free(expanded);
}
end:
UNPROTECT_INTERFACE(cai);
return status;
}
SWITCH_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_proto, const char *proto, const char *from, const char *to, SWITCH_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_proto, const char *proto, const char *from, const char *to,
const char *subject, const char *body, const char *type, const char *hint) const char *subject, const char *body, const char *type, const char *hint)
{ {
@ -489,73 +745,43 @@ SWITCH_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_prot
abort(); abort();
} }
status = switch_core_chat_send(dest_proto, message_event); if (dest_proto) {
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
}
switch_event_destroy(&message_event); chat_queue_message(&message_event);
status = SWITCH_STATUS_SUCCESS;
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, switch_event_t *message_event) SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, switch_event_t *message_event)
{ {
switch_chat_interface_t *ci; switch_event_t *dup;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_hash_index_t *hi;
const void *var;
void *val;
/* switch_event_dup(&dup, message_event);
const char *proto;
const char *from;
const char *to;
const char *subject;
const char *body;
const char *type;
const char *hint;
*/
if (!dest_proto) { if (dest_proto) {
return SWITCH_STATUS_FALSE; switch_event_add_header_string(dup, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
} }
/* chat_queue_message(&dup);
proto = switch_event_get_header(message_event, "proto"); return SWITCH_STATUS_SUCCESS;
from = switch_event_get_header(message_event, "from"); }
to = switch_event_get_header(message_event, "to");
subject = switch_event_get_header(message_event, "subject");
body = switch_event_get_body(message_event);
type = switch_event_get_header(message_event, "type");
hint = switch_event_get_header(message_event, "hint");
*/
if (!strcasecmp(dest_proto, "GLOBAL")) { SWITCH_DECLARE(switch_status_t) switch_core_chat_deliver(const char *dest_proto, switch_event_t **message_event)
switch_mutex_lock(loadable_modules.mutex); {
for (hi = switch_hash_first(NULL, loadable_modules.chat_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val); if (dest_proto) {
switch_event_add_header_string(*message_event, SWITCH_STACK_BOTTOM, "dest_proto", dest_proto);
if ((ci = (switch_chat_interface_t *) val)) {
if (ci->chat_send && !strncasecmp(ci->interface_name, "GLOBAL_", 7)) {
if ((status = ci->chat_send(message_event)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Chat Interface Error [%s]!\n", dest_proto);
break;
}
}
}
}
switch_mutex_unlock(loadable_modules.mutex);
} else {
if (!(ci = switch_loadable_module_get_chat_interface(dest_proto)) || !ci->chat_send) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid chat interface [%s]!\n", dest_proto);
return SWITCH_STATUS_FALSE;
}
status = ci->chat_send(message_event);
UNPROTECT_INTERFACE(ci);
} }
return status; chat_queue_message(message_event);
return SWITCH_STATUS_SUCCESS;
} }
@ -684,6 +910,32 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
} }
} }
if (old_module->module_interface->chat_application_interface) {
const switch_chat_application_interface_t *ptr;
for (ptr = old_module->module_interface->chat_application_interface; ptr; ptr = ptr->next) {
if (ptr->interface_name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Application '%s'\n", ptr->interface_name);
switch_core_session_hupall_matching_var(SWITCH_CURRENT_APPLICATION_VARIABLE, ptr->interface_name, SWITCH_CAUSE_MANAGER_REQUEST);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
ptr->interface_name);
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
}
if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "application");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "description", switch_str_nil(ptr->short_desc));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "syntax", switch_str_nil(ptr->syntax));
switch_event_fire(&event);
}
switch_core_hash_delete(loadable_modules.chat_application_hash, ptr->interface_name);
}
}
}
if (old_module->module_interface->api_interface) { if (old_module->module_interface->api_interface) {
const switch_api_interface_t *ptr; const switch_api_interface_t *ptr;
@ -1355,6 +1607,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init(switch_bool_t autolo
switch_core_hash_init_nocase(&loadable_modules.codec_hash, loadable_modules.pool); switch_core_hash_init_nocase(&loadable_modules.codec_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.timer_hash, loadable_modules.pool); switch_core_hash_init_nocase(&loadable_modules.timer_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.application_hash, loadable_modules.pool); switch_core_hash_init_nocase(&loadable_modules.application_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.chat_application_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.api_hash, loadable_modules.pool); switch_core_hash_init_nocase(&loadable_modules.api_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool); switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool);
switch_core_hash_init_nocase(&loadable_modules.speech_hash, loadable_modules.pool); switch_core_hash_init_nocase(&loadable_modules.speech_hash, loadable_modules.pool);
@ -1470,6 +1723,13 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init(switch_bool_t autolo
switch_loadable_module_runtime(); switch_loadable_module_runtime();
chat_globals.running = 1;
memset(&chat_globals, 0, sizeof(chat_globals));
chat_globals.pool = loadable_modules.pool;
switch_mutex_init(&chat_globals.mutex, SWITCH_MUTEX_NESTED, chat_globals.pool);
chat_thread_start(1);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -1529,11 +1789,24 @@ SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
switch_hash_index_t *hi; switch_hash_index_t *hi;
void *val; void *val;
switch_loadable_module_t *module; switch_loadable_module_t *module;
int i;
if (!loadable_modules.module_hash) { if (!loadable_modules.module_hash) {
return; return;
} }
chat_globals.running = 0;
for (i = 0; i < chat_globals.msg_queue_len; i++) {
switch_queue_push(chat_globals.msg_queue[i], NULL);
}
for (i = 0; i < chat_globals.msg_queue_len; i++) {
switch_status_t st;
switch_thread_join(&st, chat_globals.msg_queue_thread[i]);
}
for (hi = switch_hash_first(NULL, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) { for (hi = switch_hash_first(NULL, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val); switch_hash_this(hi, NULL, NULL, &val);
module = (switch_loadable_module_t *) val; module = (switch_loadable_module_t *) val;
@ -1557,6 +1830,7 @@ SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
switch_core_hash_destroy(&loadable_modules.codec_hash); switch_core_hash_destroy(&loadable_modules.codec_hash);
switch_core_hash_destroy(&loadable_modules.timer_hash); switch_core_hash_destroy(&loadable_modules.timer_hash);
switch_core_hash_destroy(&loadable_modules.application_hash); switch_core_hash_destroy(&loadable_modules.application_hash);
switch_core_hash_destroy(&loadable_modules.chat_application_hash);
switch_core_hash_destroy(&loadable_modules.api_hash); switch_core_hash_destroy(&loadable_modules.api_hash);
switch_core_hash_destroy(&loadable_modules.file_hash); switch_core_hash_destroy(&loadable_modules.file_hash);
switch_core_hash_destroy(&loadable_modules.speech_hash); switch_core_hash_destroy(&loadable_modules.speech_hash);
@ -1625,6 +1899,7 @@ SWITCH_DECLARE(switch_codec_interface_t *) switch_loadable_module_get_codec_inte
HASH_FUNC(dialplan) HASH_FUNC(dialplan)
HASH_FUNC(timer) HASH_FUNC(timer)
HASH_FUNC(application) HASH_FUNC(application)
HASH_FUNC(chat_application)
HASH_FUNC(api) HASH_FUNC(api)
HASH_FUNC(file) HASH_FUNC(file)
HASH_FUNC(speech) HASH_FUNC(speech)
@ -1978,6 +2253,9 @@ SWITCH_DECLARE(void *) switch_loadable_module_create_interface(switch_loadable_m
case SWITCH_APPLICATION_INTERFACE: case SWITCH_APPLICATION_INTERFACE:
ALLOC_INTERFACE(application) ALLOC_INTERFACE(application)
case SWITCH_CHAT_APPLICATION_INTERFACE:
ALLOC_INTERFACE(chat_application)
case SWITCH_API_INTERFACE: case SWITCH_API_INTERFACE:
ALLOC_INTERFACE(api) ALLOC_INTERFACE(api)

View File

@ -256,6 +256,13 @@ SWITCH_DECLARE_NONSTD(void) switch_regex_set_var_callback(const char *var, const
switch_channel_add_variable_var_check(channel, var, val, SWITCH_FALSE, SWITCH_STACK_PUSH); switch_channel_add_variable_var_check(channel, var, val, SWITCH_FALSE, SWITCH_STACK_PUSH);
} }
SWITCH_DECLARE_NONSTD(void) switch_regex_set_event_header_callback(const char *var, const char *val, void *user_data)
{
switch_event_t *event = (switch_event_t *) user_data;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, var, val);
}
/* For Emacs: /* For Emacs:

View File

@ -160,6 +160,7 @@ static struct xml_section_t SECTIONS[] = {
{"directory", SWITCH_XML_SECTION_DIRECTORY}, {"directory", SWITCH_XML_SECTION_DIRECTORY},
{"dialplan", SWITCH_XML_SECTION_DIALPLAN}, {"dialplan", SWITCH_XML_SECTION_DIALPLAN},
{"phrases", SWITCH_XML_SECTION_PHRASES}, {"phrases", SWITCH_XML_SECTION_PHRASES},
{"chatplan", SWITCH_XML_SECTION_CHATPLAN},
{NULL, 0} {NULL, 0}
}; };