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