static int get_devstate(struct cw_channel *chan, int argc, char **argv) { struct localuser *u; int res=-1; char resc[8]="-1"; LOCAL_USER_ADD(u); if (argc > 0 && argv[0][0]) res = cw_device_state(argv[0]); else cw_log(LOG_DEBUG, "Ignoring, no parameters\n"); cw_log(LOG_DEBUG, "app_getdevstate setting DEVSTATE to %d for device %s \n", res, argv[0]); snprintf(resc,sizeof(resc),"%d",res); pbx_builtin_setvar_helper(chan, "DEVSTATE", resc ); LOCAL_USER_REMOVE(u); return RESULT_SUCCESS; }
static int get_extstate(struct cw_channel *chan, int argc, char **argv) { struct localuser *u; int res=-1; char resc[8]="-1"; char hint[CW_MAX_EXTENSION] = ""; char hints[1024] = ""; char *cur, *rest; int allunavailable = 1, allbusy = 1, allfree = 1; int busy = 0, inuse = 0, ring = 0; if (argc != 2 || !argv[0][0] || !argv[1][0]) { cw_log(LOG_ERROR, "Syntax: %s\n", g_syntax); return -1; } LOCAL_USER_ADD(u); cur = argv[0]; do { rest = strchr(cur, '&'); if (rest) { *rest = 0; rest++; } cw_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, argv[1], cur); //cw_log(LOG_DEBUG,"HINT: %s Context: %s Exten: %s\n",hint,argv[1],cur); if (!cw_strlen_zero(hint)) { //let's concat hints! if ( strlen(hint)+strlen(hints)+2<sizeof(hints) ) { if ( strlen(hints) ) strcat(hints,"&"); strcat(hints,hint); } } //cw_log(LOG_DEBUG,"HINTS: %s \n",hints); cur=rest; } while (cur); //res=cw_device_state(hint); //res=cw_extension_state2(hint); cur=hints; do { rest = strchr(cur, '&'); if (rest) { *rest = 0; rest++; } res = cw_device_state(cur); //cw_log(LOG_DEBUG,"Ext: %s State: %d \n",cur,res); switch (res) { case CW_DEVICE_NOT_INUSE: allunavailable = 0; allbusy = 0; break; case CW_DEVICE_INUSE: inuse = 1; allunavailable = 0; allfree = 0; break; case CW_DEVICE_RINGING: ring = 1; allunavailable = 0; allfree = 0; break; case CW_DEVICE_BUSY: allunavailable = 0; allfree = 0; busy = 1; break; case CW_DEVICE_UNAVAILABLE: case CW_DEVICE_INVALID: allbusy = 0; allfree = 0; break; default: allunavailable = 0; allbusy = 0; allfree = 0; } cur = rest; } while (cur); // 0-idle; 1-inuse; 2-busy; 4-unavail 8-ringing //cw_log(LOG_VERBOSE, "allunavailable %d, allbusy %d, allfree %d, busy %d, inuse %d, ring %d \n", allunavailable, allbusy, allfree, busy, inuse, ring ); if (!inuse && ring) res=8; else if (inuse && ring) res=1; else if (inuse) res=1; else if (allfree) res=0; else if (allbusy) res=2; else if (allunavailable) res=4; else if (busy) res=2; else res=-1; cw_log(LOG_DEBUG, "app_getextstate setting EXTSTATE to %d for extension %s in context %s\n", res, argv[0], argv[1]); snprintf(resc,sizeof(resc),"%d",res); pbx_builtin_setvar_helper(chan, "EXTSTATE", resc ); LOCAL_USER_REMOVE(u); return RESULT_SUCCESS; }