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
00030
00031
00032
00033 #include "asterisk.h"
00034
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00036
00037 #include "asterisk/module.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/utils.h"
00041 #include "asterisk/devicestate.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 static const char *ast_extstate_str(int state)
00067 {
00068 const char *res = "UNKNOWN";
00069
00070 switch (state) {
00071 case AST_EXTENSION_NOT_INUSE:
00072 res = "NOT_INUSE";
00073 break;
00074 case AST_EXTENSION_INUSE:
00075 res = "INUSE";
00076 break;
00077 case AST_EXTENSION_BUSY:
00078 res = "BUSY";
00079 break;
00080 case AST_EXTENSION_UNAVAILABLE:
00081 res = "UNAVAILABLE";
00082 break;
00083 case AST_EXTENSION_RINGING:
00084 res = "RINGING";
00085 break;
00086 case AST_EXTENSION_INUSE | AST_EXTENSION_RINGING:
00087 res = "RINGINUSE";
00088 break;
00089 case AST_EXTENSION_INUSE | AST_EXTENSION_ONHOLD:
00090 res = "HOLDINUSE";
00091 break;
00092 case AST_EXTENSION_ONHOLD:
00093 res = "ONHOLD";
00094 break;
00095 }
00096
00097 return res;
00098 }
00099
00100 static int extstate_read(struct ast_channel *chan, const char *cmd, char *data,
00101 char *buf, size_t len)
00102 {
00103 char *exten, *context;
00104
00105 if (ast_strlen_zero(data)) {
00106 ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
00107 return -1;
00108 }
00109
00110 context = exten = data;
00111 strsep(&context, "@");
00112 if (ast_strlen_zero(context))
00113 context = "default";
00114
00115 if (ast_strlen_zero(exten)) {
00116 ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
00117 return -1;
00118 }
00119
00120 ast_copy_string(buf,
00121 ast_extstate_str(ast_extension_state(chan, context, exten)), len);
00122
00123 return 0;
00124 }
00125
00126 static struct ast_custom_function extstate_function = {
00127 .name = "EXTENSION_STATE",
00128 .read = extstate_read,
00129 .read_max = 12,
00130 };
00131
00132 static int unload_module(void)
00133 {
00134 int res;
00135
00136 res = ast_custom_function_unregister(&extstate_function);
00137
00138 return res;
00139 }
00140
00141 static int load_module(void)
00142 {
00143 int res;
00144
00145 res = ast_custom_function_register(&extstate_function);
00146
00147 return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00148 }
00149
00150 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Gets an extension's state in the dialplan");