]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Allow hints to have names (bug #3471)
authorMark Spencer <markster@digium.com>
Tue, 1 Feb 2005 01:53:25 +0000 (01:53 +0000)
committerMark Spencer <markster@digium.com>
Tue, 1 Feb 2005 01:53:25 +0000 (01:53 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4938 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_dial.c
configs/extensions.conf.sample
doc/README.variables
include/asterisk/pbx.h
manager.c
pbx.c

index 0c155a9078a4d0030fdeb2b25a5bd7e84333845e..2e826475364f360a1e811d814ee42ef9c49d13e2 100755 (executable)
@@ -217,6 +217,26 @@ static int ast_onedigit_goto(struct ast_channel *chan, char *context, char exten
 }
 
 
+static char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
+{
+       char *context;
+       char *exten;
+       if (!ast_strlen_zero(chan->macrocontext))
+               context = chan->macrocontext;
+       else
+               context = chan->context;
+
+       if (!ast_strlen_zero(chan->macroexten))
+               exten = chan->macroexten;
+       else
+               exten = chan->exten;
+
+       if (ast_get_hint(NULL, 0, name, namelen, chan, context, exten))
+               return name;
+       else
+               return "";
+}
+
 static struct ast_channel *wait_for_answer(struct ast_channel *in, struct localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart, int *result)
 {
        struct localuser *o;
@@ -235,6 +255,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct localu
        int single;
        struct ast_channel *winner;
        char *context = NULL;
+       char cidname[AST_MAX_EXTENSION];
 
        single = (outgoing && !outgoing->next && !ast_test_flag(outgoing, DIAL_MUSICONHOLD | DIAL_RINGBACKONLY));
        
@@ -382,7 +403,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct localu
                                                        numnochan++;
                                                } else {
                                                        /* After calling, set callerid to extension */
-                                                       ast_set_callerid(o->chan, ast_strlen_zero(in->macroexten) ? in->exten : in->macroexten, NULL, NULL);
+                                                       ast_set_callerid(o->chan, ast_strlen_zero(in->macroexten) ? in->exten : in->macroexten, get_cid_name(cidname, sizeof(cidname), in), NULL);
                                                }
                                        }
                                        /* Hangup the original channel now, in case we needed it */
@@ -558,6 +579,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
        int cause;
        char numsubst[AST_MAX_EXTENSION];
        char restofit[AST_MAX_EXTENSION];
+       char cidname[AST_MAX_EXTENSION];
        char *transfer = NULL;
        char *newnum;
        char *l;
@@ -991,7 +1013,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
                } else {
                        if (option_verbose > 2)
                                ast_verbose(VERBOSE_PREFIX_3 "Called %s\n", numsubst);
-                       ast_set_callerid(tmp->chan, ast_strlen_zero(chan->macroexten) ? chan->exten : chan->macroexten, NULL, NULL);
+                       ast_set_callerid(tmp->chan, ast_strlen_zero(chan->macroexten) ? chan->exten : chan->macroexten, get_cid_name(cidname, sizeof(cidname), chan), NULL);
                }
                /* Put them in the list of outgoing thingies...  We're ready now. 
                   XXX If we're forcibly removed, these outgoing calls won't get
index ecbaa5a6f4d33aee648354eddd41bbd2f728b09b..dd374d34e4c8e5fdecb218b9a16631777eb4f853 100755 (executable)
@@ -392,7 +392,7 @@ include => demo
 ; overlap extensions and menu options without conflict.  You can alias them with
 ; names, too and use global variables
 
-;exten => 6245,hint,SIP/Grandstream1&SIP/Xlite1 ; Channel hints for presence
+;exten => 6245,hint,SIP/Grandstream1&SIP/Xlite1,Joe Schmoe ; Channel hints for presence
 ;exten => 6245,1,Dial(SIP/Grandstream1,20,rt)  ; permit transfer
 ;exten => 6245,n(dial),Dial(${HINT},20,rtT)            ; Use hint as listed
 ;exten => 6245,n,Voicemail(u6245)              ; Voicemail (unavailable)
index b892556c690348cc5b27955f3ee5a559a0a30437..ced8f8e90310d675bd3f9ceda6e61c342c8f1559 100755 (executable)
@@ -62,6 +62,8 @@ ${EPOCH}      Current unix style epoch
 ${EXTEN}       Current extension
 ${ENV(VAR)}    Environmental variable VAR
 ${HANGUPCAUSE} Asterisk hangup cause
+${HINT}                Channel hints for this extension
+${HINTNAME}    Suggested Caller*ID name for this extension
 ${INVALID_EXTEN}The invalid called extension (used in the "i" extension)
 ${LANGUAGE}    Current language
 ${LEN(VAR)}    String length of VAR (integer)
index 9607e852094a39d938f0d2de6ce7ef972b54c993..c45611fea39c55a70527c6edb970ad29551f167a 100755 (executable)
@@ -285,6 +285,8 @@ int ast_extension_state_del(int id, ast_state_cb_type callback);
 /*!
  * \param hint buffer for hint
  * \param maxlen size of hint buffer
+ * \param hint buffer for name portion of hint
+ * \param maxlen size of name buffer
  * \param c this is not important
  * \param context which context to look in
  * \param exten which extension to search for
@@ -292,7 +294,7 @@ int ast_extension_state_del(int id, ast_state_cb_type callback);
  * is found a non zero value will be returned.
  * Otherwise, 0 is returned.
  */
-int ast_get_hint(char *hint, int maxlen, struct ast_channel *c, const char *context, const char *exten);
+int ast_get_hint(char *hint, int maxlen, char *name, int maxnamelen, struct ast_channel *c, const char *context, const char *exten);
 
 /*! If an extension exists, return non-zero */
 /*  work */
index a8eba2594a8fc63b213614a158444813846be47c..856f9294eb45e3ac37dec72b19bd4b8f7fb6863e 100755 (executable)
--- a/manager.c
+++ b/manager.c
@@ -1042,7 +1042,7 @@ static int action_extensionstate(struct mansession *s, struct message *m)
        if (!context || ast_strlen_zero(context))
                context = "default";
        status = ast_extension_state(NULL, context, exten);
-       ast_get_hint(hint, sizeof(hint) - 1, NULL, context, exten);
+       ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
         if (id && !ast_strlen_zero(id)) {
                 snprintf(idText,256,"ActionID: %s\r\n",id);
         }
diff --git a/pbx.c b/pbx.c
index bbc61d7f24c9645cc00f03b8fe9c389d03964e74..0e4d8eeb107c194bc4bfc6914b148a1305eacbf8 100755 (executable)
--- a/pbx.c
+++ b/pbx.c
@@ -900,7 +900,12 @@ void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, c
                } else
                        *ret = NULL;
        } else if (c && !strcmp(var, "HINT")) {
-               if (!ast_get_hint(workspace, workspacelen, c, c->context, c->exten))
+               if (!ast_get_hint(workspace, workspacelen, NULL, 0, c, c->context, c->exten))
+                       *ret = NULL;
+               else
+                       *ret = workspace;
+       } else if (c && !strcmp(var, "HINTNAME")) {
+               if (!ast_get_hint(NULL, 0, workspace, workspacelen, c, c->context, c->exten))
                        *ret = NULL;
                else
                        *ret = workspace;
@@ -1787,19 +1792,26 @@ static int ast_remove_hint(struct ast_exten *e)
                        prev = list;
                        list = list->next;    
                }
-       }
+       }
 
        ast_mutex_unlock(&hintlock);
        return -1;
 }
 
 
-int ast_get_hint(char *hint, int hintsize, struct ast_channel *c, const char *context, const char *exten)
+int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
 {
        struct ast_exten *e;
+       void *tmp;
        e = ast_hint_extension(c, context, exten);
-       if (e) {        
-           strncpy(hint, ast_get_extension_app(e), hintsize - 1);
+       if (e) {
+               if (hint) 
+                   strncpy(hint, ast_get_extension_app(e), hintsize - 1);
+               if (name) {
+                       tmp = ast_get_extension_app_data(e);
+                       if (tmp)
+                               strncpy(name, (char *)tmp, namesize - 1);
+               }
            return -1;
        }
        return 0;