func_extstate.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "asterisk.h"
00030
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89333 $")
00032
00033 #include "asterisk/module.h"
00034 #include "asterisk/channel.h"
00035 #include "asterisk/pbx.h"
00036 #include "asterisk/utils.h"
00037 #include "asterisk/devicestate.h"
00038
00039 static const char *ast_extstate_str(int state)
00040 {
00041 const char *res = "UNKNOWN";
00042
00043 switch (state) {
00044 case AST_EXTENSION_NOT_INUSE:
00045 res = "NOT_INUSE";
00046 break;
00047 case AST_EXTENSION_INUSE:
00048 res = "INUSE";
00049 break;
00050 case AST_EXTENSION_BUSY:
00051 res = "BUSY";
00052 break;
00053 case AST_EXTENSION_UNAVAILABLE:
00054 res = "UNAVAILABLE";
00055 break;
00056 case AST_EXTENSION_RINGING:
00057 res = "RINGING";
00058 break;
00059 case AST_EXTENSION_INUSE | AST_EXTENSION_RINGING:
00060 res = "RINGINUSE";
00061 break;
00062 case AST_EXTENSION_INUSE | AST_EXTENSION_ONHOLD:
00063 res = "HOLDINUSE";
00064 break;
00065 case AST_EXTENSION_ONHOLD:
00066 res = "ONHOLD";
00067 break;
00068 }
00069
00070 return res;
00071 }
00072
00073 static int extstate_read(struct ast_channel *chan, const char *cmd, char *data,
00074 char *buf, size_t len)
00075 {
00076 char *exten, *context;
00077
00078 if (ast_strlen_zero(data)) {
00079 ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
00080 return -1;
00081 }
00082
00083 context = exten = data;
00084 strsep(&context, "@");
00085 if (ast_strlen_zero(context))
00086 context = "default";
00087
00088 if (ast_strlen_zero(exten)) {
00089 ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
00090 return -1;
00091 }
00092
00093 ast_copy_string(buf,
00094 ast_extstate_str(ast_extension_state(chan, context, exten)), len);
00095
00096 return 0;
00097 }
00098
00099 static struct ast_custom_function extstate_function = {
00100 .name = "EXTENSION_STATE",
00101 .synopsis = "Get an extension's state",
00102 .syntax = "EXTENSION_STATE(extension[@context])",
00103 .desc =
00104 " The EXTENSION_STATE function can be used to retrieve the state from any\n"
00105 "hinted extension. For example:\n"
00106 " NoOp(1234@default has state ${EXTENSION_STATE(1234)})\n"
00107 " NoOp(4567@home has state ${EXTENSION_STATE(4567@home)})\n"
00108 "\n"
00109 " The possible values returned by this function are:\n"
00110 "UNKNOWN | NOT_INUSE | INUSE | BUSY | INVALID | UNAVAILABLE | RINGING\n"
00111 "RINGINUSE | HOLDINUSE | ONHOLD\n",
00112 .read = extstate_read,
00113 };
00114
00115 static int unload_module(void)
00116 {
00117 int res;
00118
00119 res = ast_custom_function_unregister(&extstate_function);
00120
00121 return res;
00122 }
00123
00124 static int load_module(void)
00125 {
00126 int res;
00127
00128 res = ast_custom_function_register(&extstate_function);
00129
00130 return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00131 }
00132
00133 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Gets an extension's state in the dialplan");