* Host "127.0.0.1"
* Port "8021"
* Pass "ClueCon"
- * <Command "sofia status profile res-public">
+ * <Command "api sofia status profile res-public">
* Instance "profile-sofia-res-public"
* <Match>
* Regex "\\<CALLS-IN\s+(\d+)\\>"
typedef struct fs_command_s fs_command_t;
struct fs_command_s
{
- char *line; // "sofia status profile res-public"
+ char *line; // "api sofia status profile res-public"
char *instance; // "profile-sofia-res-public"
char *buffer; // <output from esl command as a char*>
size_t buffer_size; // sizeof(*buffer)
sfree (fm);
} /* void fs_match_free */
+static void fs_command_free (fs_command_t *fc)
+{
+ if (fc == NULL)
+ return;
+
+ sfree (fc->line);
+ sfree (fc->instance);
+ sfree (fc->buffer);
+ fs_match_free (fc->matches);
+ fs_command_free (fc->next);
+ sfree (fc);
+} /* void fs_command_free */
+
static int fs_config_add_match_dstype (int *dstype_ret, oconfig_item_t *ci)
{
+ DEBUG ("freeswitch plugin: in fs_config_add_match_dstype");
+
int dstype;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
static int fs_config_add_match (fs_command_t *fs_command, oconfig_item_t *ci)
{
+ DEBUG ("freeswitch plugin: in fs_config_add_match");
+
fs_match_t *fs_match;
int status;
int i;
static int fs_config_add_command (oconfig_item_t *ci)
{
+ DEBUG ("freeswitch plugin: in fs_config_add_command");
+
fs_command_t *command;
int status;
int i;
return (-1);
}
memset (command, 0, sizeof (*command));
+
command->line = NULL;
+ command->line = strdup (ci->values[0].value.string);
- command->instance = strdup (ci->values[0].value.string);
- if (command->instance == NULL)
+ if (command->line == NULL)
{
ERROR ("freeswitch plugin: strdup failed.");
sfree (command);
{
oconfig_item_t *child = ci->children + i;
- if (strcasecmp ("Match", child->key) == 0)
+ if (strcasecmp ("Instance", child->key) == 0)
+ status = fs_config_add_string ("Instance", &command->instance, child);
+ else if (strcasecmp ("Match", child->key) == 0)
fs_config_add_match (command, child);
else
{
break;
}
+ if (status != 0)
+ {
+ fs_command_free (command);
+ return (status);
+ }
+
/* Add the new command to the linked list */
if (fs_commands_g == NULL)
fs_commands_g = command;
int status;
int i;
+ DEBUG ("freeswitch plugin: reading config");
+
success = 0;
errors = 0;
} /* int fs_complex_config */
static void fs_submit (const fs_command_t *fc,
- const fs_match_t *fm, const cu_match_value_t *fmv)
+ const fs_match_t *fm, const cu_match_value_t *mv)
{
+ DEBUG ("freeswitch plugin: in fs_submit");
+
+ DEBUG ("fc->instance");
+ DEBUG (fc->instance);
+
+ DEBUG ("fm->type");
+ DEBUG (fm->type);
+
+ DEBUG ("mv->value");
+ DEBUG (mv->value);
+
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
- values[0] = fmv->value;
+ values[0] = mv->value;
vl.values = values;
vl.values_len = 1;
static int fs_read_command (fs_command_t *fc)
{
+ DEBUG ("freeswitch plugin: in fs_read_command");
+
fs_match_t *fm;
int status;
+ /* can't the following be done nicer ? */
+ char *line;
+ line = (char *) malloc (strlen(fc->line)+3);
+ snprintf(line, strlen(fc->line)+3, "%s\n\n", fc->line);
+ esl_send_recv(&esl_handle, line);
+
fc->buffer_fill = 0;
- esl_send_recv(&esl_handle, fc->line); /////////////////// NOTICE NO \n\n IS GIVEN AFTER fc->line !!!!!!!!!!!!!!!!!! THIS WON'T WORK!!!!!!!!!!
if (esl_handle.last_sr_event && esl_handle.last_sr_event->body)
{
- DEBUG ("OUTPUT FROM FS:\n%s\n\n", esl_handle.last_sr_event->body);
+ DEBUG ("freeswitch plugin: output from esl (truncated):\n%s\n\n", esl_handle.last_sr_event->body);
sfree(fc->buffer);
fc->buffer = strdup(esl_handle.last_sr_event->body);
- fc->buffer_fill = 1; // ??
+ fc->buffer_size = strlen(fc->buffer);
+ fc->buffer_fill = 1;
}
for (fm = fc->matches; fm != NULL; fm = fm->next)
{
fs_command_t *fc;
+ DEBUG ("freeswitch plugin: read poll");
+
for (fc = fs_commands_g; fc != NULL; fc = fc->next)
fs_read_command (fc);
if (fs_pass == NULL) fs_pass = FS_DEF_PASS;
/* Connect to FreeSWITCH over ESL */
- DEBUG ("Making ESL connection to %s %s %s\n", fs_host, fs_port, fs_pass);
+ DEBUG ("freeswitch plugin: making ESL connection to %s %s %s\n", fs_host, fs_port, fs_pass);
esl_connect(&esl_handle, fs_host, atoi(fs_port), fs_pass);
/* Start a seperate thread for incoming events here */
static int fs_shutdown (void)
{
+ DEBUG ("freeswitch plugin: disconnecting");
esl_disconnect(&esl_handle);
+ fs_command_free (fs_commands_g);
+ fs_commands_g = NULL;
return (0);
} /* int fs_shutdown */