From 8ef297351419b9e044f6bf1ff5cbb9909238341e Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Wed, 6 Aug 2008 17:41:13 +0300 Subject: [PATCH] Support sending a message through a call-file Add two extra optional fields: 'Message' and 'PDU'. Either of them is an alternative to application or context/extension. Uses the send_message method of the channel. --- pbx/pbx_spool.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pbx/pbx_spool.c b/pbx/pbx_spool.c index 53211917d..ef3d91d54 100644 --- a/pbx/pbx_spool.c +++ b/pbx/pbx_spool.c @@ -89,6 +89,10 @@ struct outgoing { char app[256]; char data[256]; + /* If SMS */ + char message[256]; + char pdu[256]; + /* If extension/context/priority */ char exten[256]; char context[256]; @@ -188,6 +192,10 @@ static int apply_outgoing(struct outgoing *o, char *fn, FILE *f) ast_copy_string(o->app, c, sizeof(o->app)); } else if (!strcasecmp(buf, "data")) { ast_copy_string(o->data, c, sizeof(o->data)); + } else if (!strcasecmp(buf, "message")) { + ast_copy_string(o->message, c, sizeof(o->message)); + } else if (!strcasecmp(buf, "pdu")) { + ast_copy_string(o->pdu, c, sizeof(o->pdu)); } else if (!strcasecmp(buf, "maxretries")) { if (sscanf(c, "%d", &o->maxretries) != 1) { ast_log(LOG_WARNING, "Invalid max retries at line %d of %s\n", lineno, fn); @@ -255,8 +263,8 @@ static int apply_outgoing(struct outgoing *o, char *fn, FILE *f) } } ast_copy_string(o->fn, fn, sizeof(o->fn)); - if (ast_strlen_zero(o->tech) || ast_strlen_zero(o->dest) || (ast_strlen_zero(o->app) && ast_strlen_zero(o->exten))) { - ast_log(LOG_WARNING, "At least one of app or extension must be specified, along with tech and dest in file %s\n", fn); + if (ast_strlen_zero(o->tech) || ast_strlen_zero(o->dest) || (ast_strlen_zero(o->app) && ast_strlen_zero(o->exten)) || (ast_strlen_zero(o->message) && ast_strlen_zero(o->pdu))) { + ast_log(LOG_WARNING, "At least one of app or extension (or keyword message/pdu) must be specified, along with tech and dest in file %s\n", fn); return -1; } return 0; @@ -338,14 +346,34 @@ static int remove_from_queue(struct outgoing *o, const char *status) return 0; } +enum outgoing_target { + OUTGOING_TARGET_UNKNOWN = 0, + OUTGOING_TARGET_CHANNEL, + OUTGOING_TARGET_APP, + OUTGOING_TARGET_MESSAGE, + OUTGOING_TARGET_PDU, +}; + static void *attempt_thread(void *data) { struct outgoing *o = data; int res, reason; + enum outgoing_target target_type = OUTGOING_TARGET_CHANNEL; if (!ast_strlen_zero(o->app)) { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for application %s(%s) (Retry %d)\n", o->tech, o->dest, o->app, o->data, o->retries); res = ast_pbx_outgoing_app(o->tech, o->format, o->dest, o->waittime * 1000, o->app, o->data, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL); + target_type = OUTGOING_TARGET_APP; + } else if (!ast_strlen_zero(o->message)) { + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Attempting to send message on %s/%s (Retry %d)\n", o->tech, o->dest, o->retries); + res = ast_send_message(o->tech, o->dest, o->dest, (ast_strlen_zero(o->cid_name) ? o->cid_num : o->cid_name), o->message, 0); + target_type = OUTGOING_TARGET_MESSAGE; + } else if (!ast_strlen_zero(o->pdu)) { + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Attempting to send message in PDU format on %s/%s (Retry %d)\n", o->tech, o->dest, o->retries); + res = ast_send_message(o->tech, o->dest, o->dest, (ast_strlen_zero(o->cid_name) ? o->cid_num : o->cid_name), o->pdu, 1); + target_type = OUTGOING_TARGET_PDU; } else { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for %s@%s:%d (Retry %d)\n", o->tech, o->dest, o->exten, o->context,o->priority, o->retries); @@ -362,6 +390,8 @@ static void *attempt_thread(void *data) safe_append(o, time(NULL), "EndRetry"); } } else { + /*! \todo Use a different log message if destination is not a channel. + * (use target_type) */ ast_log(LOG_NOTICE, "Call completed to %s/%s\n", o->tech, o->dest); ast_log(LOG_EVENT, "Queued call to %s/%s completed\n", o->tech, o->dest); remove_from_queue(o, "Completed"); -- 2.11.4.GIT