예제 #1
0
static int cpeid_exec(struct ast_channel *chan, const char *idata)
{
	int res=0;
	unsigned char cpeid[4];
	int gotgeometry = 0;
	int gotcpeid = 0;
	int width, height, buttons;
	char *data[4];
	unsigned int x;

	for (x = 0; x < 4; x++)
		data[x] = alloca(80);

	strcpy(data[0], "** CPE Info **");
	strcpy(data[1], "Identifying CPE...");
	strcpy(data[2], "Please wait...");
	res = ast_adsi_load_session(chan, NULL, 0, 1);
	if (res > 0) {
		cpeid_setstatus(chan, data, 0);
		res = ast_adsi_get_cpeid(chan, cpeid, 0);
		if (res > 0) {
			gotcpeid = 1;
			ast_verb(3, "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n", cpeid[0], cpeid[1], cpeid[2], cpeid[3], chan->name);
		}
		if (res > -1) {
			strcpy(data[1], "Measuring CPE...");
			strcpy(data[2], "Please wait...");
			cpeid_setstatus(chan, data, 0);
			res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
			if (res > -1) {
				ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
				gotgeometry = 1;
			}
		}
		if (res > -1) {
			if (gotcpeid)
				snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
			else
				strcpy(data[1], "CPEID Unknown");
			if (gotgeometry) 
				snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
			else
				strcpy(data[2], "Geometry unknown");
			strcpy(data[3], "Press # to exit");
			cpeid_setstatus(chan, data, 1);
			for(;;) {
				res = ast_waitfordigit(chan, 1000);
				if (res < 0)
					break;
				if (res == '#') {
					res = 0;
					break;
				}
			}
			ast_adsi_unload_session(chan);
		}
	}

	return res;
}
예제 #2
0
static int adsi_prog(struct ast_channel *chan, const char *script)
{
	struct adsi_script *scr;
	int x, bytes;
	unsigned char buf[1024];

	if (!(scr = compile_script(script)))
		return -1;

	/* Start an empty ADSI Session */
	if (ast_adsi_load_session(chan, NULL, 0, 1) < 1)
		return -1;

	/* Now begin the download attempt */
	if (ast_adsi_begin_download(chan, scr->desc, scr->fdn, scr->sec, scr->ver)) {
		/* User rejected us for some reason */
		ast_verb(3, "User rejected download attempt\n");
		ast_log(LOG_NOTICE, "User rejected download on channel %s\n", chan->name);
		ast_free(scr);
		return -1;
	}

	bytes = 0;
	/* Start with key definitions */
	for (x = 0; x < scr->numkeys; x++) {
		if (bytes + scr->keys[x].retstrlen > 253) {
			/* Send what we've collected so far */
			if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
				ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
				return -1;
			}
			bytes =0;
		}
		memcpy(buf + bytes, scr->keys[x].retstr, scr->keys[x].retstrlen);
		bytes += scr->keys[x].retstrlen;
#ifdef DUMP_MESSAGES
		dump_message("Key", scr->keys[x].vname, scr->keys[x].retstr, scr->keys[x].retstrlen);
#endif
	}
	if (bytes) {
		if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
			ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
			return -1;
		}
	}

	bytes = 0;
	/* Continue with the display messages */
	for (x = 0; x < scr->numdisplays; x++) {
		if (bytes + scr->displays[x].datalen > 253) {
			/* Send what we've collected so far */
			if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
				ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
				return -1;
			}
			bytes =0;
		}
		memcpy(buf + bytes, scr->displays[x].data, scr->displays[x].datalen);
		bytes += scr->displays[x].datalen;
#ifdef DUMP_MESSAGES
		dump_message("Display", scr->displays[x].vname, scr->displays[x].data, scr->displays[x].datalen);
#endif
	}
	if (bytes) {
		if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
			ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
			return -1;
		}
	}

	bytes = 0;
	/* Send subroutines */
	for (x = 0; x < scr->numsubs; x++) {
		if (bytes + scr->subs[x].datalen > 253) {
			/* Send what we've collected so far */
			if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
				ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
				return -1;
			}
			bytes =0;
		}
		memcpy(buf + bytes, scr->subs[x].data, scr->subs[x].datalen);
		bytes += scr->subs[x].datalen;
#ifdef DUMP_MESSAGES
		dump_message("Sub", scr->subs[x].vname, scr->subs[x].data, scr->subs[x].datalen);
#endif
	}
	if (bytes) {
		if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) {
			ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x);
			return -1;
		}
	}

	bytes = 0;
	bytes += ast_adsi_display(buf, ADSI_INFO_PAGE, 1, ADSI_JUST_LEFT, 0, "Download complete.", "");
	bytes += ast_adsi_set_line(buf, ADSI_INFO_PAGE, 1);
	if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY) < 0)
		return -1;
	if (ast_adsi_end_download(chan)) {
		/* Download failed for some reason */
		ast_verb(3, "Download attempt failed\n");
		ast_log(LOG_NOTICE, "Download failed on %s\n", chan->name);
		ast_free(scr);
		return -1;
	}
	ast_free(scr);
	ast_adsi_unload_session(chan);
	return 0;
}