static int _ast_adsi_print(struct ast_channel *chan, char **lines, int *aligns, int voice) { unsigned char buf[4096]; int bytes = 0, res, x; for(x = 0; lines[x]; x++) bytes += ast_adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, aligns[x], 0, lines[x], ""); bytes += ast_adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1); if (voice) bytes += ast_adsi_voice_mode(buf + bytes, 0); res = ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); if (voice) /* Ignore the resulting DTMF B announcing it's in voice mode */ ast_waitfordigit(chan, 1000); return res; }
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; }