int main(int argc, char *argv[]) { if (argc != 2 || !strlen(argv[1])) { fprintf(stderr, "%s [client name]\n", argv[0]); return 1; } if (!set_program_name(argv[0]) || !initialize_client()) { fprintf(stderr, "%s: could not initialize client\n", argv[0]); client_cleanup(); return 1; } load_internal_plugins(); if (!start_message_queue()) { fprintf(stderr, "%s: could not start message queue\n", argv[0]); client_cleanup(); return 1; } if (!register_resource_client(NULL)) { fprintf(stderr, "%s: could not register client\n", argv[0]); stop_message_queue(); client_cleanup(); return 1; } command_handle new_service = register_service(argv[1], PARAM_ECHO_TYPE); command_reference service_status = 0; if ( !new_service || !(service_status = send_command(new_service)) || !(wait_command_event(service_status, event_complete, local_default_timeout()) & event_complete) ) { fprintf(stderr, "%s: could not register service\n", argv[0]); if (new_service) destroy_command(new_service); if (service_status) clear_command_status(service_status); stop_message_queue(); client_cleanup(); return 1; } destroy_command(new_service); clear_command_status(service_status); set_log_client_name(argv[1]); if (!stop_message_queue()) { client_cleanup(); return 1; } set_queue_event_hook(&message_queue_hook); result outcome = inline_message_queue(); client_cleanup(); return outcome? 0 : 1; }
void PrimeSession::modify_cursor_left_edge (void) { send_command (PRIME_MODIFY_CURSOR_LEFT_EDGE); }
void PrimeSession::modify_cursor_expand (void) { send_command (PRIME_MODIFY_CURSOR_EXPAND); }
// change radio state, e.g. from receive to ready void radio_change_state(uint8_t next_state) { radio_buffer.data[0] = next_state; send_command(CMD_CHANGE_STATE, radio_buffer.data, 1, 0); }
void PrimeSession::edit_undo (void) { send_command (PRIME_EDIT_UNDO); }
// retrieve radio FIFO information void radio_fifo_info(uint8_t reset_fifo) { radio_buffer.data[0] = reset_fifo; send_command(CMD_FIFO_INFO, radio_buffer.data, 1, sizeof(radio_buffer.fifo_info)); }
// retrieve radio modem status information void radio_get_modem_status(uint8_t clr_pending) { radio_buffer.data[0] = clr_pending; send_command(CMD_GET_MODEM_STATUS, radio_buffer.data, 1, sizeof(radio_buffer.modem_status)); }
void test_xml(void) { assert_send_command("table_create Users TABLE_HASH_KEY ShortText"); assert_send_command("column_create Users age COLUMN_SCALAR UInt32"); assert_send_command("column_create Users comment COLUMN_SCALAR Text"); cut_assert_equal_string( cut_take_printf("<COLUMN_LIST>\n" "<HEADER>\n" "<PROPERTY>\n" "<TEXT>id</TEXT>\n" "<TEXT>UInt32</TEXT></PROPERTY>\n" "<PROPERTY>\n" "<TEXT>name</TEXT>\n" "<TEXT>ShortText</TEXT></PROPERTY>\n" "<PROPERTY>\n" "<TEXT>path</TEXT>\n" "<TEXT>ShortText</TEXT></PROPERTY>\n" "<PROPERTY>\n" "<TEXT>type</TEXT>\n" "<TEXT>ShortText</TEXT></PROPERTY>\n" "<PROPERTY>\n" "<TEXT>flags</TEXT>\n" "<TEXT>ShortText</TEXT></PROPERTY>\n" "<PROPERTY>\n" "<TEXT>domain</TEXT>\n" "<TEXT>ShortText</TEXT></PROPERTY>\n" "<PROPERTY>\n" "<TEXT>range</TEXT>\n" "<TEXT>ShortText</TEXT></PROPERTY>\n" "<PROPERTY>\n" "<TEXT>source</TEXT>\n" "<TEXT>ShortText</TEXT></PROPERTY></HEADER>\n" "<COLUMN>\n" "<INT>%u</INT>\n" "<TEXT>_key</TEXT>\n" "<TEXT></TEXT>\n" "<TEXT></TEXT>\n" "<TEXT>COLUMN_SCALAR</TEXT>\n" "<TEXT>Users</TEXT>\n" "<TEXT>ShortText</TEXT>\n" "<SOURCES></SOURCES></COLUMN>\n" "<COLUMN>\n" "<INT>%u</INT>\n" "<TEXT>comment</TEXT>\n" "<TEXT>%s.0000102</TEXT>\n" "<TEXT>var</TEXT>\n" "<TEXT>COLUMN_SCALAR|PERSISTENT</TEXT>\n" "<TEXT>Users</TEXT>\n" "<TEXT>Text</TEXT>\n" "<SOURCES></SOURCES></COLUMN>\n" "<COLUMN>\n" "<INT>%u</INT>\n" "<TEXT>age</TEXT>\n" "<TEXT>%s.0000101</TEXT>\n" "<TEXT>fix</TEXT>\n" "<TEXT>COLUMN_SCALAR|PERSISTENT</TEXT>\n" "<TEXT>Users</TEXT>\n" "<TEXT>UInt32</TEXT>\n" "<SOURCES></SOURCES></COLUMN></COLUMN_LIST>", grn_obj_id(context, get("Users")), grn_obj_id(context, get("Users.comment")), database_path, grn_obj_id(context, get("Users.age")), database_path), send_command("column_list Users --output_type xml")); }
static void process_events(PluginData* data, PDReader* reader, PDWriter* writer) { uint32_t event; while ((event = PDRead_get_event(reader))) { switch (event) { //case PDEventType_getExceptionLocation : setExceptionLocation(plugin, writer); break; //case PDEventType_getCallstack : set_callstack(plugin, writer); break; case PDEventType_GetRegisters: { get_registers(data); break; } case PDEventType_GetCallstack: { if (should_send_command(data)) set_callstack(data, reader, writer); break; } case PDEventType_GetDisassembly: { if (should_send_command(data)) get_disassembly(data, reader, writer); break; } case PDEventType_GetMemory: { if (should_send_command(data)) get_memory(data, reader, writer); break; } case PDEventType_MenuEvent: { on_menu(data, reader); break; } case PDEventType_SetBreakpoint: { set_breakpoint(data, reader, writer); // if we add a breakpoint to VICE it will always stop but if we are already running when // adding the breakpoint we just force VICE to run again if (data->state == PDDebugState_Running) send_command(data, "ret\n"); break; } case PDEventType_DeleteBreakpoint: { del_breakpoint(data, reader, writer); break; } case PDEventType_SetExecutable: { //if (should_send_command(data)) set_executable(data, reader); break; } } } }
int gdbr_write_registers(libgdbr_t* g, char* registers) { // read current register set gdbr_read_registers(g); unsigned int x, len = strlen(registers); char* buff = calloc(len, sizeof(char)); if (!buff) return -1; memcpy(buff, registers, len); char* reg = strtok(buff, ","); while ( reg != NULL ) { char* name_end = strchr(reg, '='); if (name_end == NULL) { printf("Malformed argument: %s\n", reg); free(buff); return -1; } *name_end = '\0'; // change '=' to '\0' // time to find the current register int i = 0; while ( g->registers[i].size > 0) { if (strcmp(g->registers[i].name, reg) == 0) { const uint64_t register_size = g->registers[i].size; const uint64_t offset = g->registers[i].offset; char* value = malloc (register_size * 2); if (!value) { free (buff); return -1; } memset (value, '0', register_size * 2); name_end++; // be able to take hex with and without 0x if (name_end[1] == 'x' || name_end[1] == 'X') name_end += 2; const int val_len = strlen (name_end); // size of the rest strcpy (value+(register_size * 2 - val_len), name_end); for (x=0; x < register_size; x++) { g->data[offset + register_size - x - 1] = hex2char(&value[x * 2]); } free(value); } i++; } reg = strtok(NULL, " ,"); } free(buff); uint64_t buffer_size = g->data_len * 2 + 8; int ret; char* command = calloc(buffer_size, sizeof(char)); if (!command) return -1; snprintf (command, buffer_size, "%s", CMD_WRITEREGS); pack_hex (g->data, g->data_len, command+1); ret = send_command (g, command); if (ret < 0) { free (command); return ret; } read_packet (g); free (command); handle_G (g); return 0; }
int main(int argc, char **argv) { /* local client data */ int sockfd; /* file descriptor for endpoint */ struct sockaddr_in client_sockaddr; /* address/port pair */ struct in_addr client_addr; /* network-format address */ char client_dotted[INET_ADDRSTRLEN];/* human-readable address */ int client_port; /* local port */ /* remote server data */ char *server_dotted; /* human-readable address */ int server_port; /* remote port */ /* the request */ char *filename; /* filename to request */ /* read arguments */ if (argc != 5) { fprintf(stderr, "client: wrong number of arguments\n"); client_usage(); exit(1); } server_dotted = argv[1]; server_port = atoi(argv[2]); client_port = atoi(argv[3]); filename = argv[4]; if (!client_arguments_valid( server_dotted, server_port, client_port, filename)) { client_usage(); exit(1); } /* get the primary IP address of this host */ get_primary_addr(&client_addr); inet_ntop(AF_INET, &client_addr, client_dotted, INET_ADDRSTRLEN); /* construct an endpoint address with primary address and desired port */ memset(&client_sockaddr, 0, sizeof(client_sockaddr)); client_sockaddr.sin_family = PF_INET; memcpy(&client_sockaddr.sin_addr,&client_addr,sizeof(struct in_addr)); client_sockaddr.sin_port = htons(client_port); /* make a socket*/ sockfd = socket(PF_INET, SOCK_DGRAM, 0); if (sockfd<0) { perror("can't open socket"); exit(1); } /* bind it to an appropriate local address and port */ if (bind(sockfd, (struct sockaddr *) &client_sockaddr, sizeof(client_sockaddr))<0) { perror("can't bind local address"); exit(1); } fprintf(stderr, "client: Receiving on %s, port %d\n", client_dotted, client_port); /* send a command */ send_command(sockfd, server_dotted, server_port, filename, 0, MAXINT); fprintf(stderr, "client: requesting %s blocks %d-%d\n", filename, 0, MAXINT); /* receive the whole document and make naive assumptions */ int done = FALSE; // set to TRUE when you think you're done int init = TRUE; /* create a bit array to test which blocks have been received */ struct bits blocksRecv; /* open a file to write to in the current directory */ FILE *download = fopen(filename, "w"); fclose(download); int outfd = open(filename, O_RDWR); while (!done) { int retval; again: if ((retval = select_block(sockfd, 0, 20000))==0) { /* timeout */ struct range nBlocks[12]; int currentRange = 0; int i; int check = 0; int numBlocks = blocksRecv.nbits; for(i = 0; i < numBlocks; i++){ /* look for the start of a missed block */ if(check == 0 && bits_testbit(&blocksRecv, i)){ nBlocks[currentRange].first_block = i; nBlocks[currentRange].last_block = numBlocks-1; check++; } /* look for the end of a missed block */ else if(check == 1 && !(bits_testbit(&blocksRecv, i))){ nBlocks[currentRange].last_block = i-1; currentRange ++; /* if you have found 12 missed blocks, send_commands */ if(currentRange == 12){ send_commands(sockfd, server_dotted, server_port, filename, nBlocks, currentRange); currentRange = 0; } check = 0; } } /* send any left over blocks from the loop above */ send_commands(sockfd, server_dotted, server_port, filename, nBlocks, currentRange); if(bits_empty(&blocksRecv)){ done = TRUE; } } else if (retval<0) { /* error */ perror("select"); fprintf(stderr, "client: receive error\n"); } else { /* input is waiting, read it */ struct sockaddr_in resp_sockaddr; /* address/port pair */ int resp_len; /* length used */ char resp_dotted[INET_ADDRSTRLEN]; /* human-readable address */ int resp_port; /* port */ int resp_mesglen; /* length of message */ struct block one_block; /* use helper routine to receive a block */ recv_block(sockfd, &one_block, &resp_sockaddr); /* get human-readable internet address */ inet_ntop(AF_INET, (void *)&(resp_sockaddr.sin_addr.s_addr), resp_dotted, INET_ADDRSTRLEN); resp_port = ntohs(resp_sockaddr.sin_port); fprintf(stderr, "client: %s:%d sent %s block %d (range 0-%d)\n", resp_dotted, resp_port, one_block.filename, one_block.which_block, one_block.total_blocks); /* check block data for errors */ if (strcmp(filename, one_block.filename)!=0) { fprintf(stderr, "client: received block with incorrect filename %s\n", one_block.filename); goto again; } /* init the bit array once you know how many blocks the file contains */ if(init){ //fprintf(stderr, "total blocks: %d\n", one_block.total_blocks); bits_alloc(&blocksRecv, one_block.total_blocks); bits_setrange(&blocksRecv, 0, one_block.total_blocks - 1); init = FALSE; } /* if you have not received the current block, write it and flag it as received */ if(bits_testbit(&blocksRecv, one_block.which_block)){ bits_clearbit(&blocksRecv, one_block.which_block); lseek(outfd, one_block.which_block*PAYLOADSIZE, SEEK_SET); write(outfd, one_block.payload, one_block.paysize); } /* if all blocks have been received, done */ if(bits_empty(&blocksRecv)){ done = TRUE; } } } /* close the file stream */ close(outfd); }
static int dus3000_read(struct tslib_module_info *m, struct ts_sample *samples, int maxSamples) { struct tslib_dus3000 *const d = (struct tslib_dus3000 *)m; const int fd = m->dev->fd; int i = 0; for (i = 0; i < maxSamples; ) { // - Read until we have at least four bytes, which is <= minimum reply length and also // sufficient to determine the final length of all kinds of replies // then... code: if (!read_to_pos(fd, d, 4)) { break; } if (d->rxPosition >= 4) { if (d->rxBuffer[0] == 0x01) { if (!read_to_pos(fd, d, 6)) { break; } // read finger up / down and coordinates samples[i].pressure = d->rxBuffer[1] ? 255 : 0; samples[i].x = ((int)d->rxBuffer[2]) | (((int)d->rxBuffer[3]) << 8); samples[i].y = ((int)d->rxBuffer[4]) | (((int)d->rxBuffer[5]) << 8); i++; d->rxPosition = 0; // message complete } else if (d->rxBuffer[0] == 0x02 && d->rxBuffer[1] == 0x4c) { const ssize_t fullRequiredLength = 3 + d->rxBuffer[2]; if (!read_to_pos(fd, d, fullRequiredLength)) { break; } d->rxPosition = 0; // message complete switch (d->rxBuffer[3]) { case tr_id_vers_info: // "acquisition of version information" response // get rest of message. length is stored in m_RxBuf[2] #ifdef DEBUG d->rxBuffer[fullRequiredLength] = '\0'; fprintf(stderr, "Version information: %s\n", d->rxBuffer + 3); #endif break; case tr_id_firmw_info: // "firmware detailed information" response #ifdef DEBUG d->rxBuffer[fullRequiredLength] = '\0'; fprintf(stderr, "Firmware information: %s\n", d->rxBuffer); #endif break; case tr_id_adj_offset: // "adjust offset" response if (d->state == AdjustOffset && d->rxBuffer[4] != 0) { #ifdef DEBUG fprintf(stderr, "Adjust offset succeeded!\n"); #endif } else { // abort calibration if command transmission failed continue; } if (!send_command(fd, tm_calibrate_offset)) { fprintf(stderr, "Calibrate offset command transmission failed!\n"); continue; } d->state = CalibrateOffset; break; case tr_id_cal_offset: // "calibrate offset" response if (d->state == CalibrateOffset && d->rxBuffer[4] != 0) { #ifdef DEBUG fprintf(stderr, "Calibrate offset succeeded!\n"); #endif } else { // abort calibration if command transmission failed fprintf(stderr, "Calibrate offset failed!\n"); continue; } // calibration done, restart coordinate transmission if (!send_command(fd, tm_coordinates_on)) { fprintf(stderr, "Enable coordinates command transmission failed!\n"); continue; } d->state = Coordinates; #ifdef DEBUG fprintf(stderr, "Calibration finished!\n"); #endif break; } // switch } else { fprintf(stderr, "DUS3000: unknown response 0x %02x %02x %02x %02x - resynchronizing!\n", d->rxBuffer[0], d->rxBuffer[1], d->rxBuffer[2], d->rxBuffer[3]); // stop coordinate transmission, flush buffers, and re-enable send_command(fd, tm_coordinates_off); usleep (50000); // let all pending data arrive in our buffer tcflush(fd, TCIOFLUSH); // clear buffers d->rxPosition = 0; d->state = Coordinates; send_command(fd, tm_coordinates_on); } } } return i; }
void send_write_command(unsigned char *command, int command_length) { send_command(command, command_length); }
void send_read_command(unsigned char command) { send_command(&command, 1); }
// retrieve radio device information (e.g. chip model) void radio_part_info(void) { send_command(CMD_PART_INFO, 0, 0, sizeof(radio_buffer.part_info)); }
static void launch_vice_with_config(PluginData* data) { int r, cmdIndex = 1; uv_process_options_t options = { 0 }; log_debug("spawning vice...\n", ""); char* args[10]; args[0] = (char*)data->config.vice_exe; // TODO: Must generate the breakpoint file from the json one args[cmdIndex++] = "-remotemonitor"; if (data->config.breakpoint_file) { //args[cmdIndex++] = "-moncommands"; //args[cmdIndex++] = "examples/c64_vice/test_mon.txt"; } //args[cmdIndex++] = (char*)data->config.prg_file; args[cmdIndex++] = NULL; options.exit_cb = 0; options.file = data->config.vice_exe; options.args = args; if ((r = uv_spawn(uv_default_loop(), &data->process, &options))) { MESSAGE_FUNCS->error("Unable to launch VICE", uv_strerror(r)); return; } sleepMs(3000); connect_to_local_host(data); // if connected we load the image and make sure we get a reply back if (VICEConnection_isConnected(data->conn)) { log_debug("connected to vice...\n", ""); if (!load_image(data, data->config.prg_file)) { return; } log_debug("image loaded ...\n", ""); // parse the parse_mon_file(data, data->config.breakpoint_file); log_debug("start from basic...\n", ""); // start vice! log_debug("started from basic\n", ""); uint16_t address = 0; //get_basic_start(data); parse_mon_file(data, data->config.breakpoint_file); if (address != 0) { log_debug("start from %x\n", address); send_command(data, "g %x\n", address); } return; } log_debug("unable to make connection with vice\n", ""); }
// retrieve radio function revision information void radio_func_info(void) { send_command(CMD_FUNC_INFO, 0, 0, sizeof(radio_buffer.func_info)); }
// DO NOT TRANSLATE ANY STRINGS IN THIS FUNCTION! int process_response(const char *cmd_sent, char *msg_received) { int i = 0; char *msg = msg_received; int echo_on = TRUE; //echo status int is_hex_num = TRUE; char temp_buf[80]; if (cmd_sent) { for(i = 0; cmd_sent[i]; i++) { if (cmd_sent[i] != *msg) // if the characters are not the same, { echo_on = FALSE; // say that echo is off break; // break out of the loop } msg++; } if (echo_on == TRUE) //if echo is on { send_command("ate0"); // turn off the echo start_serial_timer(AT_TIMEOUT); // wait for chip response or timeout while ((read_comport(temp_buf) != PROMPT) && !serial_time_out) ; stop_serial_timer(); if (!serial_time_out) { send_command("atl0"); // turn off linefeeds start_serial_timer(AT_TIMEOUT); // wait for chip response or timeout while ((read_comport(temp_buf) != PROMPT) && !serial_time_out) ; stop_serial_timer(); } } else //if echo is off msg = msg_received; } while(*msg && (*msg <= ' ')) msg++; if (strncmp(msg, "SEARCHING...", 12) == 0) msg += 13; else if (strncmp(msg, "BUS INIT: OK", 12) == 0) msg += 13; else if (strncmp(msg, "BUS INIT: ...OK", 15) == 0) msg += 16; for(i = 0; *msg; msg++) //loop to copy data { if (*msg > ' ') // if the character is not a special character or space { if (*msg == '<') // Detect <DATA_ERROR { if (strncmp(msg, "<DATA ERROR", 10) == 0) return DATA_ERROR2; else return RUBBISH; } msg_received[i] = *msg; // rewrite response if (!isxdigit(*msg) && *msg != ':') is_hex_num = FALSE; i++; } else if (((*msg == '\n') || (*msg == '\r')) && (msg_received[i-1] != SPECIAL_DELIMITER)) // if the character is a CR or LF msg_received[i++] = SPECIAL_DELIMITER; // replace CR with SPECIAL_DELIMITER } if (i > 0) if (msg_received[i-1] == SPECIAL_DELIMITER) i--; msg_received[i] = '\0'; // terminate the string if (is_hex_num) return HEX_DATA; if (strcmp(msg_received, "NODATA") == 0) return ERR_NO_DATA; if (strcmp(msg_received + strlen(msg_received) - 15, "UNABLETOCONNECT") == 0) return UNABLE_TO_CONNECT; if (strcmp(msg_received + strlen(msg_received) - 7, "BUSBUSY") == 0) return BUS_BUSY; if (strcmp(msg_received + strlen(msg_received) - 9, "DATAERROR") == 0) return DATA_ERROR; if (strcmp(msg_received + strlen(msg_received) - 8, "BUSERROR") == 0 || strcmp(msg_received + strlen(msg_received) - 7, "FBERROR") == 0) return BUS_ERROR; if (strcmp(msg_received + strlen(msg_received) - 8, "CANERROR") == 0) return CAN_ERROR; if (strcmp(msg_received + strlen(msg_received) - 10, "BUFFERFULL") == 0) return BUFFER_FULL; if (strncmp(msg_received, "BUSINIT:", 8) == 0) { if (strcmp(msg_received + strlen(msg_received) - 5, "ERROR") == 0) return BUS_INIT_ERROR; else return SERIAL_ERROR; } if (strcmp(msg_received, "?") == 0) return UNKNOWN_CMD; if (strncmp(msg_received, "ELM320", 6) == 0) return INTERFACE_ELM320; if (strncmp(msg_received, "ELM322", 6) == 0) return INTERFACE_ELM322; if (strncmp(msg_received, "ELM323", 6) == 0) return INTERFACE_ELM323; if (strncmp(msg_received, "ELM327", 6) == 0) return INTERFACE_ELM327; if (strncmp(msg_received, "OBDLink", 7) == 0 || strncmp(msg_received, "STN1000", 7) == 0 || strncmp(msg_received, "STN11", 5) == 0) return INTERFACE_OBDLINK; if (strncmp(msg_received, "SCANTOOL.NET", 12) == 0) return STN_MFR_STRING; if (strcmp(msg_received, "OBDIItoRS232Interpreter") == 0) return ELM_MFR_STRING; return RUBBISH; }
// retrieve radio chip status information void radio_get_chip_status(uint8_t clr_pending) { radio_buffer.data[0] = clr_pending; send_command(CMD_GET_CHIP_STATUS, radio_buffer.data, 1, sizeof(radio_buffer.chip_status)); }
int main(int argc, char ** argv) { char *term = NULL; unsigned int k; int ttype; uint32_t option = 0, done = 0, sb_mode = 0; /* Various pieces for the telnet communication */ unsigned char sb[1024] = {0}; unsigned short sb_len = 0; /* Whether or not to show the MOTD intro */ char show_intro = 0; char skip_intro = 0; /* Long option names */ static struct option long_opts[] = { {"help", no_argument, 0, 'h'}, {"telnet", no_argument, 0, 't'}, {"intro", no_argument, 0, 'i'}, {"skip-intro", no_argument, 0, 'I'}, {"no-counter", no_argument, 0, 'n'}, {"no-title", no_argument, 0, 's'}, {"no-clear", no_argument, 0, 'e'}, {"frames", required_argument, 0, 'f'}, {"min-rows", required_argument, 0, 'r'}, {"max-rows", required_argument, 0, 'R'}, {"min-cols", required_argument, 0, 'c'}, {"max-cols", required_argument, 0, 'C'}, {"width", required_argument, 0, 'W'}, {"height", required_argument, 0, 'H'}, {0,0,0,0} }; /* Process arguments */ int index, c; while ((c = getopt_long(argc, argv, "eshiItnf:r:R:c:C:W:H:", long_opts, &index)) != -1) { if (!c) { if (long_opts[index].flag == 0) { c = long_opts[index].val; } } switch (c) { case 'e': clear_screen = 0; break; case 's': set_title = 0; break; case 'i': /* Show introduction */ show_intro = 1; break; case 'I': skip_intro = 1; break; case 't': /* Expect telnet bits */ telnet = 1; break; case 'h': /* Show help and exit */ usage(argv); exit(0); break; case 'n': show_counter = 0; break; case 'f': frame_count = atoi(optarg); break; case 'r': min_row = atoi(optarg); break; case 'R': max_row = atoi(optarg); break; case 'c': min_col = atoi(optarg); break; case 'C': max_col = atoi(optarg); break; case 'W': min_col = (FRAME_WIDTH - atoi(optarg)) / 2; max_col = (FRAME_WIDTH + atoi(optarg)) / 2; break; case 'H': min_row = (FRAME_HEIGHT - atoi(optarg)) / 2; max_row = (FRAME_HEIGHT + atoi(optarg)) / 2; break; default: break; } } if (telnet) { /* Telnet mode */ /* show_intro is implied unless skip_intro was set */ show_intro = (skip_intro == 0) ? 1 : 0; /* Set the default options */ set_options(); /* Let the client know what we're using */ for (option = 0; option < 256; option++) { if (telnet_options[option]) { send_command(telnet_options[option], option); fflush(stdout); } } for (option = 0; option < 256; option++) { if (telnet_willack[option]) { send_command(telnet_willack[option], option); fflush(stdout); } } /* Set the alarm handler to execute the longjmp */ signal(SIGALRM, SIGALRM_handler); /* Negotiate options */ if (!setjmp(environment)) { /* We will stop handling options after one second */ alarm(1); /* Let's do this */ while (!feof(stdin) && done < 2) { /* Get either IAC (start command) or a regular character (break, unless in SB mode) */ unsigned char i = getchar(); unsigned char opt = 0; if (i == IAC) { /* If IAC, get the command */ i = getchar(); switch (i) { case SE: /* End of extended option mode */ sb_mode = 0; if (sb[0] == TTYPE) { /* This was a response to the TTYPE command, meaning * that this should be a terminal type */ alarm(2); term = strndup((char *)&sb[2], sizeof(sb)-2); done++; } else if (sb[0] == NAWS) { /* This was a response to the NAWS command, meaning * that this should be a window size */ alarm(2); terminal_width = (sb[1] << 8) | sb[2]; terminal_height = (sb[3] << 8) | sb[4]; done++; } break; case NOP: /* No Op */ send_command(NOP, 0); fflush(stdout); break; case WILL: case WONT: /* Will / Won't Negotiation */ opt = getchar(); if (!telnet_willack[opt]) { /* We default to WONT */ telnet_willack[opt] = WONT; } send_command(telnet_willack[opt], opt); fflush(stdout); if ((i == WILL) && (opt == TTYPE)) { /* WILL TTYPE? Great, let's do that now! */ printf("%c%c%c%c%c%c", IAC, SB, TTYPE, SEND, IAC, SE); fflush(stdout); } break; case DO: case DONT: /* Do / Don't Negotiation */ opt = getchar(); if (!telnet_options[opt]) { /* We default to DONT */ telnet_options[opt] = DONT; } send_command(telnet_options[opt], opt); fflush(stdout); break; case SB: /* Begin Extended Option Mode */ sb_mode = 1; sb_len = 0; memset(sb, 0, sizeof(sb)); break; case IAC: /* IAC IAC? That's probably not right. */ done = 2; break; default: break; } } else if (sb_mode) { /* Extended Option Mode -> Accept character */ if (sb_len < sizeof(sb) - 1) { /* Append this character to the SB string, * but only if it doesn't put us over * our limit; honestly, we shouldn't hit * the limit, as we're only collecting characters * for a terminal type or window size, but better safe than * sorry (and vulnerable). */ sb[sb_len] = i; sb_len++; } } } } alarm(0); } else { /* We are running standalone, retrieve the * terminal type from the environment. */ term = getenv("TERM"); /* Also get the number of columns */ struct winsize w; ioctl(0, TIOCGWINSZ, &w); terminal_width = w.ws_col; terminal_height = w.ws_row; } /* Default ttype */ ttype = 2; if (term) { /* Convert the entire terminal string to lower case */ for (k = 0; k < strlen(term); ++k) { term[k] = tolower(term[k]); } /* Do our terminal detection */ if (strstr(term, "xterm")) { ttype = 1; /* 256-color, spaces */ } else if (strstr(term, "toaru")) { ttype = 1; /* emulates xterm */ } else if (strstr(term, "linux")) { ttype = 3; /* Spaces and blink attribute */ } else if (strstr(term, "vtnt")) { ttype = 5; /* Extended ASCII fallback == Windows */ } else if (strstr(term, "cygwin")) { ttype = 5; /* Extended ASCII fallback == Windows */ } else if (strstr(term, "vt220")) { ttype = 6; /* No color support */ } else if (strstr(term, "fallback")) { ttype = 4; /* Unicode fallback */ } else if (strstr(term, "rxvt-256color")) { ttype = 1; /* xterm 256-color compatible */ } else if (strstr(term, "rxvt")) { ttype = 3; /* Accepts LINUX mode */ } else if (strstr(term, "vt100") && terminal_width == 40) { ttype = 7; /* No color support, only 40 columns */ } else if (!strncmp(term, "st", 2)) { ttype = 1; /* suckless simple terminal is xterm-256color-compatible */ } } int always_escape = 0; /* Used for text mode */ /* Accept ^C -> restore cursor */ signal(SIGINT, SIGINT_handler); /* Handle loss of stdout */ signal(SIGPIPE, SIGPIPE_handler); /* Handle window changes */ if (!telnet) { signal(SIGWINCH, SIGWINCH_handler); } switch (ttype) { case 1: colors[','] = "\033[48;5;17m"; /* Blue background */ colors['.'] = "\033[48;5;231m"; /* White stars */ colors['\''] = "\033[48;5;16m"; /* Black border */ colors['@'] = "\033[48;5;230m"; /* Tan poptart */ colors['$'] = "\033[48;5;175m"; /* Pink poptart */ colors['-'] = "\033[48;5;162m"; /* Red poptart */ colors['>'] = "\033[48;5;196m"; /* Red rainbow */ colors['&'] = "\033[48;5;214m"; /* Orange rainbow */ colors['+'] = "\033[48;5;226m"; /* Yellow Rainbow */ colors['#'] = "\033[48;5;118m"; /* Green rainbow */ colors['='] = "\033[48;5;33m"; /* Light blue rainbow */ colors[';'] = "\033[48;5;19m"; /* Dark blue rainbow */ colors['*'] = "\033[48;5;240m"; /* Gray cat face */ colors['%'] = "\033[48;5;175m"; /* Pink cheeks */ break; case 2: colors[','] = "\033[104m"; /* Blue background */ colors['.'] = "\033[107m"; /* White stars */ colors['\''] = "\033[40m"; /* Black border */ colors['@'] = "\033[47m"; /* Tan poptart */ colors['$'] = "\033[105m"; /* Pink poptart */ colors['-'] = "\033[101m"; /* Red poptart */ colors['>'] = "\033[101m"; /* Red rainbow */ colors['&'] = "\033[43m"; /* Orange rainbow */ colors['+'] = "\033[103m"; /* Yellow Rainbow */ colors['#'] = "\033[102m"; /* Green rainbow */ colors['='] = "\033[104m"; /* Light blue rainbow */ colors[';'] = "\033[44m"; /* Dark blue rainbow */ colors['*'] = "\033[100m"; /* Gray cat face */ colors['%'] = "\033[105m"; /* Pink cheeks */ break; case 3: colors[','] = "\033[25;44m"; /* Blue background */ colors['.'] = "\033[5;47m"; /* White stars */ colors['\''] = "\033[25;40m"; /* Black border */ colors['@'] = "\033[5;47m"; /* Tan poptart */ colors['$'] = "\033[5;45m"; /* Pink poptart */ colors['-'] = "\033[5;41m"; /* Red poptart */ colors['>'] = "\033[5;41m"; /* Red rainbow */ colors['&'] = "\033[25;43m"; /* Orange rainbow */ colors['+'] = "\033[5;43m"; /* Yellow Rainbow */ colors['#'] = "\033[5;42m"; /* Green rainbow */ colors['='] = "\033[25;44m"; /* Light blue rainbow */ colors[';'] = "\033[5;44m"; /* Dark blue rainbow */ colors['*'] = "\033[5;40m"; /* Gray cat face */ colors['%'] = "\033[5;45m"; /* Pink cheeks */ break; case 4: colors[','] = "\033[0;34;44m"; /* Blue background */ colors['.'] = "\033[1;37;47m"; /* White stars */ colors['\''] = "\033[0;30;40m"; /* Black border */ colors['@'] = "\033[1;37;47m"; /* Tan poptart */ colors['$'] = "\033[1;35;45m"; /* Pink poptart */ colors['-'] = "\033[1;31;41m"; /* Red poptart */ colors['>'] = "\033[1;31;41m"; /* Red rainbow */ colors['&'] = "\033[0;33;43m"; /* Orange rainbow */ colors['+'] = "\033[1;33;43m"; /* Yellow Rainbow */ colors['#'] = "\033[1;32;42m"; /* Green rainbow */ colors['='] = "\033[1;34;44m"; /* Light blue rainbow */ colors[';'] = "\033[0;34;44m"; /* Dark blue rainbow */ colors['*'] = "\033[1;30;40m"; /* Gray cat face */ colors['%'] = "\033[1;35;45m"; /* Pink cheeks */ output = "██"; break; case 5: colors[','] = "\033[0;34;44m"; /* Blue background */ colors['.'] = "\033[1;37;47m"; /* White stars */ colors['\''] = "\033[0;30;40m"; /* Black border */ colors['@'] = "\033[1;37;47m"; /* Tan poptart */ colors['$'] = "\033[1;35;45m"; /* Pink poptart */ colors['-'] = "\033[1;31;41m"; /* Red poptart */ colors['>'] = "\033[1;31;41m"; /* Red rainbow */ colors['&'] = "\033[0;33;43m"; /* Orange rainbow */ colors['+'] = "\033[1;33;43m"; /* Yellow Rainbow */ colors['#'] = "\033[1;32;42m"; /* Green rainbow */ colors['='] = "\033[1;34;44m"; /* Light blue rainbow */ colors[';'] = "\033[0;34;44m"; /* Dark blue rainbow */ colors['*'] = "\033[1;30;40m"; /* Gray cat face */ colors['%'] = "\033[1;35;45m"; /* Pink cheeks */ output = "\333\333"; break; case 6: colors[','] = "::"; /* Blue background */ colors['.'] = "@@"; /* White stars */ colors['\''] = " "; /* Black border */ colors['@'] = "##"; /* Tan poptart */ colors['$'] = "??"; /* Pink poptart */ colors['-'] = "<>"; /* Red poptart */ colors['>'] = "##"; /* Red rainbow */ colors['&'] = "=="; /* Orange rainbow */ colors['+'] = "--"; /* Yellow Rainbow */ colors['#'] = "++"; /* Green rainbow */ colors['='] = "~~"; /* Light blue rainbow */ colors[';'] = "$$"; /* Dark blue rainbow */ colors['*'] = ";;"; /* Gray cat face */ colors['%'] = "()"; /* Pink cheeks */ always_escape = 1; break; case 7: colors[','] = "."; /* Blue background */ colors['.'] = "@"; /* White stars */ colors['\''] = " "; /* Black border */ colors['@'] = "#"; /* Tan poptart */ colors['$'] = "?"; /* Pink poptart */ colors['-'] = "O"; /* Red poptart */ colors['>'] = "#"; /* Red rainbow */ colors['&'] = "="; /* Orange rainbow */ colors['+'] = "-"; /* Yellow Rainbow */ colors['#'] = "+"; /* Green rainbow */ colors['='] = "~"; /* Light blue rainbow */ colors[';'] = "$"; /* Dark blue rainbow */ colors['*'] = ";"; /* Gray cat face */ colors['%'] = "o"; /* Pink cheeks */ always_escape = 1; terminal_width = 40; break; default: break; } if (min_col == max_col) { min_col = (FRAME_WIDTH - terminal_width/2) / 2; max_col = (FRAME_WIDTH + terminal_width/2) / 2; using_automatic_width = 1; } if (min_row == max_row) { min_row = (FRAME_HEIGHT - (terminal_height-1)) / 2; max_row = (FRAME_HEIGHT + (terminal_height-1)) / 2; using_automatic_height = 1; } /* Attempt to set terminal title */ if (set_title) { printf("\033kNyanyanyanyanyanyanya...\033\134"); printf("\033]1;Nyanyanyanyanyanyanya...\007"); printf("\033]2;Nyanyanyanyanyanyanya...\007"); } if (clear_screen) { /* Clear the screen */ printf("\033[H\033[2J\033[?25l"); } else { printf("\033[s"); } if (show_intro) { /* Display the MOTD */ unsigned int countdown_clock = 5; for (k = 0; k < countdown_clock; ++k) { newline(3); printf(" \033[1mNyancat Telnet Server\033[0m"); newline(2); printf(" written and run by \033[1;32mKevin Lange\033[1;34m @kevinlange\033[0m"); newline(2); printf(" If things don't look right, try:"); newline(1); printf(" TERM=fallback telnet ..."); newline(2); printf(" Or on Windows:"); newline(1); printf(" telnet -t vtnt ..."); newline(2); printf(" Problems? Check the website:"); newline(1); printf(" \033[1;34mhttp://nyancat.dakko.us\033[0m"); newline(2); printf(" This is a telnet server, remember your escape keys!"); newline(1); printf(" \033[1;31m^]quit\033[0m to exit"); newline(2); printf(" Starting in %d... \n", countdown_clock-k); fflush(stdout); usleep(400000); if (clear_screen) { printf("\033[H"); /* Reset cursor */ } else { printf("\033[u"); } } if (clear_screen) { /* Clear the screen again */ printf("\033[H\033[2J\033[?25l"); } } /* Store the start time */ time_t start, current; time(&start); int playing = 1; /* Animation should continue [left here for modifications] */ size_t i = 0; /* Current frame # */ unsigned int f = 0; /* Total frames passed */ char last = 0; /* Last color index rendered */ int y, x; /* x/y coordinates of what we're drawing */ while (playing) { /* Reset cursor */ if (clear_screen) { printf("\033[H"); } else { printf("\033[u"); } /* Render the frame */ for (y = min_row; y < max_row; ++y) { for (x = min_col; x < max_col; ++x) { char color; if (y > 23 && y < 43 && x < 0) { /* * Generate the rainbow tail. * * This is done with a pretty simplistic square wave. */ int mod_x = ((-x+2) % 16) / 8; if ((i / 2) % 2) { mod_x = 1 - mod_x; } /* * Our rainbow, with some padding. */ const char *rainbow = ",,>>&&&+++###==;;;,,"; color = rainbow[mod_x + y-23]; if (color == 0) color = ','; } else if (x < 0 || y < 0 || y >= FRAME_HEIGHT || x >= FRAME_WIDTH) { /* Fill all other areas with background */ color = ','; } else { /* Otherwise, get the color from the animation frame. */ color = frames[i][y][x]; } if (always_escape) { /* Text mode (or "Always Send Color Escapes") */ printf("%s", colors[(int)color]); } else { if (color != last && colors[(int)color]) { /* Normal Mode, send escape (because the color changed) */ last = color; printf("%s%s", colors[(int)color], output); } else { /* Same color, just send the output characters */ printf("%s", output); } } } /* End of row, send newline */ newline(1); } if (show_counter) { /* Get the current time for the "You have nyaned..." string */ time(¤t); double diff = difftime(current, start); /* Now count the length of the time difference so we can center */ int nLen = digits((int)diff); /* * 29 = the length of the rest of the string; * XXX: Replace this was actually checking the written bytes from a * call to sprintf or something */ int width = (terminal_width - 29 - nLen) / 2; /* Spit out some spaces so that we're actually centered */ while (width > 0) { printf(" "); width--; } /* You have nyaned for [n] seconds! * The \033[J ensures that the rest of the line has the dark blue * background, and the \033[1;37m ensures that our text is bright white. * The \033[0m prevents the Apple ][ from flipping everything, but * makes the whole nyancat less bright on the vt220 */ printf("\033[1;37mYou have nyaned for %0.0f seconds!\033[J\033[0m", diff); } /* Reset the last color so that the escape sequences rewrite */ last = 0; /* Update frame count */ ++f; if (frame_count != 0 && f == frame_count) { finish(); } ++i; if (!frames[i]) { /* Loop animation */ i = 0; } /* Wait */ usleep(90000); } return 0; }
// read radio state void radio_request_device_state(void) { send_command(CMD_REQUEST_DEVICE_STATE, 0, 0, sizeof(radio_buffer.device_state)); }
/* State machine to do the calling and hangup procedure */ static void process_event(struct cardstate *cs, struct event_t *ev) { struct bc_state *bcs; char *p_command = NULL; struct reply_t *rep; int rcode; int genresp = 0; int resp_code = RSP_ERROR; int sendcid; struct at_state_t *at_state; int index; int curact; unsigned long flags; if (ev->cid >= 0) { at_state = at_state_from_cid(cs, ev->cid); if (!at_state) { gig_dbg(DEBUG_EVENT, "event %d for invalid cid %d", ev->type, ev->cid); gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID, NULL, 0, NULL); return; } } else { at_state = ev->at_state; if (at_state_invalid(cs, at_state)) { gig_dbg(DEBUG_EVENT, "event for invalid at_state %p", at_state); return; } } gig_dbg(DEBUG_EVENT, "connection state %d, event %d", at_state->ConState, ev->type); bcs = at_state->bcs; sendcid = at_state->cid; /* Setting the pointer to the dial array */ rep = at_state->replystruct; spin_lock_irqsave(&cs->lock, flags); if (ev->type == EV_TIMEOUT) { if (ev->parameter != at_state->timer_index || !at_state->timer_active) { ev->type = RSP_NONE; /* old timeout */ gig_dbg(DEBUG_EVENT, "old timeout"); } else if (!at_state->waiting) gig_dbg(DEBUG_EVENT, "timeout occurred"); else gig_dbg(DEBUG_EVENT, "stopped waiting"); } spin_unlock_irqrestore(&cs->lock, flags); /* if the response belongs to a variable in at_state->int_var[VAR_XXXX] or at_state->str_var[STR_XXXX], set it */ if (ev->type >= RSP_VAR && ev->type < RSP_VAR + VAR_NUM) { index = ev->type - RSP_VAR; at_state->int_var[index] = ev->parameter; } else if (ev->type >= RSP_STR && ev->type < RSP_STR + STR_NUM) { index = ev->type - RSP_STR; kfree(at_state->str_var[index]); at_state->str_var[index] = ev->ptr; ev->ptr = NULL; /* prevent process_events() from deallocating ptr */ } if (ev->type == EV_TIMEOUT || ev->type == RSP_STRING) at_state->getstring = 0; /* Search row in dial array which matches modem response and current constate */ for (;; rep++) { rcode = rep->resp_code; if (rcode == RSP_LAST) { /* found nothing...*/ dev_warn(cs->dev, "%s: rcode=RSP_LAST: " "resp_code %d in ConState %d!\n", __func__, ev->type, at_state->ConState); return; } if ((rcode == RSP_ANY || rcode == ev->type) && ((int) at_state->ConState >= rep->min_ConState) && (rep->max_ConState < 0 || (int) at_state->ConState <= rep->max_ConState) && (rep->parameter < 0 || rep->parameter == ev->parameter)) break; } p_command = rep->command; at_state->waiting = 0; for (curact = 0; curact < MAXACT; ++curact) { /* The row tells us what we should do .. */ do_action(rep->action[curact], cs, bcs, &at_state, &p_command, &genresp, &resp_code, ev); if (!at_state) break; /* may be freed after disconnect */ } if (at_state) { /* Jump to the next con-state regarding the array */ if (rep->new_ConState >= 0) at_state->ConState = rep->new_ConState; if (genresp) { spin_lock_irqsave(&cs->lock, flags); at_state->timer_expires = 0; at_state->timer_active = 0; spin_unlock_irqrestore(&cs->lock, flags); gigaset_add_event(cs, at_state, resp_code, NULL, 0, NULL); } else { /* Send command to modem if not NULL... */ if (p_command) { if (cs->connected) send_command(cs, p_command, sendcid, cs->dle, GFP_ATOMIC); else gigaset_add_event(cs, at_state, RSP_NODEV, NULL, 0, NULL); } spin_lock_irqsave(&cs->lock, flags); if (!rep->timeout) { at_state->timer_expires = 0; at_state->timer_active = 0; } else if (rep->timeout > 0) { /* new timeout */ at_state->timer_expires = rep->timeout * 10; at_state->timer_active = 1; ++at_state->timer_index; } spin_unlock_irqrestore(&cs->lock, flags); } } }
void PrimeSession::edit_insert (const char *str) { send_command (PRIME_EDIT_INSERT, str); }
int do_psync_account_teams(psync_userid_t teamids[], int nids, result_visitor vis, void *param) { psync_socket *sock; binresult *bres; char *ids = NULL; char *idsp = 0; int k,i; const binresult *users; if (nids) { ids = (char *) psync_malloc(nids*FOLDERID_ENTRY_SIZE); idsp = ids; for (i = 0; i < nids; ++i) { k = sprintf(idsp, "%lld", (long long) teamids[i]); if (unlikely(k <= 0 )) break; idsp[k] = ','; idsp = idsp + k + 1; } if (i > 0) *(idsp - 1) = '\0'; //debug(D_NOTICE, "Account_teams numids %d\n", nids); binparam params[] = {P_STR("auth", psync_my_auth), P_STR("timeformat", "timestamp"), P_STR("teamids", ids), P_STR("showeveryone", "1")}; sock = psync_apipool_get(); bres = send_command(sock, "account_teams", params); } else { if (psync_my_auth[0]) { binparam params[] = {P_STR("auth", psync_my_auth), P_STR("timeformat", "timestamp"), P_STR("showeveryone", "1")}; sock = psync_apipool_get(); bres = send_command(sock, "account_teams", params); } else if (psync_my_user && psync_my_pass) { binparam params[] = {P_STR("username", psync_my_user), P_STR("password", psync_my_pass), P_STR("timeformat", "timestamp"), P_STR("showeveryone", "1")}; sock = psync_apipool_get(); bres = send_command(sock, "account_teams", params); } else return -1; } if (likely(bres)) psync_apipool_release(sock); else { psync_apipool_release_bad(sock); debug(D_WARNING, "Send command returned in valid result.\n"); return -1; } users = psync_find_result(bres, "teams", PARAM_ARRAY); //debug(D_NOTICE, "Result contains %d teams\n", users->length); if (!users->length){ psync_free(bres); psync_free(ids); debug(D_WARNING, "Account_teams returned empty result!\n"); return -2; } else { for (i = 0; i < users->length; ++i) vis(i, users->array[i], param); } psync_free(bres); psync_free(ids); return 0; }
void PrimeSession::modify_start (void) { send_command (PRIME_MODIFY_START); }
SPEC_RET spec_guard( CHAR_DATA *ch ) { CHAR_DATA *victim; CHAR_DATA *v_next; CHAR_DATA *ech; char *crime; char buf[MSL]; int max_evil; if ( !is_awake(ch) ) return FALSE; if ( ch->fighting ) return FALSE; max_evil = 300; ech = NULL; crime = ""; for ( victim = ch->in_room->first_person; victim; victim = v_next ) { v_next = victim->next_in_room; if ( !victim->fighting ) continue; if ( who_fighting(victim) == ch ) continue; if ( IS_PG(victim) && HAS_BIT_PLR(victim, PLAYER_KILLER) ) { crime = "assassino"; break; } if ( IS_PG(victim) && HAS_BIT_PLR(victim, PLAYER_THIEF) ) { crime = "ladro"; break; } if ( victim->alignment < max_evil ) { max_evil = victim->alignment; ech = victim; } } if ( victim && HAS_BIT(ch->in_room->flags, ROOM_SAFE) ) { sprintf( buf, "yell codardo di un %s!", crime ); /* (GR) articolo */ send_command( ch, buf, CO ); return TRUE; } if ( victim ) { sprintf( buf, "yell Proteggiamo l'innocente dal %s!!", crime ); /* (GR) articolo dal dall' */ send_command( ch, buf, CO ); multi_hit( ch, victim, TYPE_UNDEFINED ); return TRUE; } if ( ech ) { act( AT_YELL, "$n urla 'Proteggiamo l'innocente!'", ch, NULL, NULL, TO_ROOM ); multi_hit( ch, ech, TYPE_UNDEFINED ); return TRUE; } return FALSE; }
void PrimeSession::modify_cursor_right_edge (void) { send_command (PRIME_MODIFY_CURSOR_RIGHT_EDGE); }
SPEC_RET spec_mayor( CHAR_DATA *ch ) { static const char open_path[] = "W3a3003b33000c111d0d111Oe333333Oe22c222112212111a1S."; static const char close_path[] = "W3a3003b33000c111d0d111CE333333CE22c222112212111a1S."; static const char *path; static int pos; static bool move; if ( !move ) { if ( calendar.hour == 6 ) { path = open_path; move = TRUE; pos = 0; } if ( calendar.hour == 20 ) { path = close_path; move = TRUE; pos = 0; } } if ( ch->fighting ) return spec_cast_cleric( ch ); if ( !move || ch->position < POSITION_SLEEP ) return FALSE; /* (TR) */ switch ( path[pos] ) { case '0': case '1': case '2': case '3': move_char( ch, get_exit(ch->in_room, path[pos] - '0'), 0, FALSE ); break; case 'W': ch->position = POSITION_STAND; act( AT_ACTION, "$n awakens and groans loudly.", ch, NULL, NULL, TO_ROOM ); break; case 'S': ch->position = POSITION_SLEEP; act( AT_ACTION, "$n lies down and falls asleep.", ch, NULL, NULL, TO_ROOM ); break; case 'a': act( AT_SAY, "$n says 'Hello Honey!'", ch, NULL, NULL, TO_ROOM ); break; case 'b': act( AT_SAY, "$n says 'What a view! I must do something about that dump!'", ch, NULL, NULL, TO_ROOM ); break; case 'c': act( AT_SAY, "$n says 'Vandals! Youngsters have no respect for anything!'", ch, NULL, NULL, TO_ROOM ); break; case 'd': act( AT_SAY, "$n says 'Good day, citizens!'", ch, NULL, NULL, TO_ROOM ); break; case 'e': act( AT_SAY, "$n says 'I hereby declare the town of Darkhaven open!'", ch, NULL, NULL, TO_ROOM ); break; case 'E': act( AT_SAY, "$n says 'I hereby declare the town of Darkhaven closed!'", ch, NULL, NULL, TO_ROOM ); break; case 'O': send_command( ch, "unlock gate", CO ); send_command( ch, "open gate", CO ); break; case 'C': send_command( ch, "close gate", CO ); send_command( ch, "lock gate", CO ); break; case '.' : move = FALSE; break; } pos++; return FALSE; }
void PrimeSession::modify_cursor_shrink (void) { send_command (PRIME_MODIFY_CURSOR_SHRINK); }
int mailpop3_auth(mailpop3 * f, const char * auth_type, const char * server_fqdn, const char * local_ip_port, const char * remote_ip_port, const char * login, const char * auth_name, const char * password, const char * realm) { #ifdef USE_SASL int r; char command[POP3_STRING_SIZE]; sasl_callback_t sasl_callback[5]; const char * sasl_out; unsigned sasl_out_len; const char * mechusing; sasl_secret_t * secret; int res; size_t len; char * encoded; unsigned int encoded_len; unsigned int max_encoded; sasl_callback[0].id = SASL_CB_GETREALM; sasl_callback[0].proc = sasl_getrealm; sasl_callback[0].context = f; sasl_callback[1].id = SASL_CB_USER; sasl_callback[1].proc = sasl_getsimple; sasl_callback[1].context = f; sasl_callback[2].id = SASL_CB_AUTHNAME; sasl_callback[2].proc = sasl_getsimple; sasl_callback[2].context = f; sasl_callback[3].id = SASL_CB_PASS; sasl_callback[3].proc = sasl_getsecret; sasl_callback[3].context = f; sasl_callback[4].id = SASL_CB_LIST_END; sasl_callback[4].proc = NULL; sasl_callback[4].context = NULL; len = strlen(password); secret = malloc(sizeof(* secret) + len); if (secret == NULL) { res = MAILPOP3_ERROR_MEMORY; goto err; } secret->len = len; memcpy(secret->data, password, len + 1); f->pop3_sasl.sasl_server_fqdn = server_fqdn; f->pop3_sasl.sasl_login = login; f->pop3_sasl.sasl_auth_name = auth_name; f->pop3_sasl.sasl_password = password; f->pop3_sasl.sasl_realm = realm; f->pop3_sasl.sasl_secret = secret; /* init SASL */ if (f->pop3_sasl.sasl_conn != NULL) { sasl_dispose((sasl_conn_t **) &f->pop3_sasl.sasl_conn); f->pop3_sasl.sasl_conn = NULL; } else { mailsasl_ref(); } r = sasl_client_new("pop", server_fqdn, local_ip_port, remote_ip_port, sasl_callback, 0, (sasl_conn_t **) &f->pop3_sasl.sasl_conn); if (r != SASL_OK) { res = MAILPOP3_ERROR_BAD_USER; goto free_secret; } r = sasl_client_start(f->pop3_sasl.sasl_conn, auth_type, NULL, &sasl_out, &sasl_out_len, &mechusing); if ((r != SASL_CONTINUE) && (r != SASL_OK)) { res = MAILPOP3_ERROR_BAD_USER; goto free_sasl_conn; } snprintf(command, POP3_STRING_SIZE, "AUTH %s\r\n", auth_type); r = send_command(f, command); if (r == -1) { res = MAILPOP3_ERROR_STREAM; goto free_sasl_conn; } while (1) { char * response; response = read_line(f); r = parse_auth(f, response); switch (r) { case RESPONSE_OK: f->pop3_state = POP3_STATE_TRANSACTION; res = MAILPOP3_NO_ERROR; goto free_sasl_conn; case RESPONSE_ERR: res = MAILPOP3_ERROR_BAD_USER; goto free_sasl_conn; case RESPONSE_AUTH_CONT: { size_t response_len; char * decoded; unsigned int decoded_len; unsigned int max_decoded; int got_response; got_response = 1; if (* f->pop3_response == '\0') got_response = 0; if (got_response) { char * p; p = strchr(f->pop3_response, '\r'); if (p != NULL) { * p = '\0'; } p = strchr(f->pop3_response, '\n'); if (p != NULL) { * p = '\0'; } response_len = strlen(f->pop3_response); max_decoded = response_len * 3 / 4; decoded = malloc(max_decoded + 1); if (decoded == NULL) { res = MAILPOP3_ERROR_MEMORY; goto free_sasl_conn; } r = sasl_decode64(f->pop3_response, response_len, decoded, max_decoded + 1, &decoded_len); if (r != SASL_OK) { free(decoded); res = MAILPOP3_ERROR_MEMORY; goto free_sasl_conn; } r = sasl_client_step(f->pop3_sasl.sasl_conn, decoded, decoded_len, NULL, &sasl_out, &sasl_out_len); free(decoded); if ((r != SASL_CONTINUE) && (r != SASL_OK)) { res = MAILPOP3_ERROR_BAD_USER; goto free_sasl_conn; } } max_encoded = ((sasl_out_len + 2) / 3) * 4; encoded = malloc(max_encoded + 1); if (encoded == NULL) { res = MAILPOP3_ERROR_MEMORY; goto free_sasl_conn; } r = sasl_encode64(sasl_out, sasl_out_len, encoded, max_encoded + 1, &encoded_len); if (r != SASL_OK) { free(encoded); res = MAILPOP3_ERROR_MEMORY; goto free_sasl_conn; } snprintf(command, POP3_STRING_SIZE, "%s\r\n", encoded); r = send_command(f, command); free(encoded); if (r == -1) { res = MAILPOP3_ERROR_STREAM; goto free_sasl_conn; } } break; } } f->pop3_state = POP3_STATE_TRANSACTION; res = MAILPOP3_NO_ERROR; free_sasl_conn: sasl_dispose((sasl_conn_t **) &f->pop3_sasl.sasl_conn); f->pop3_sasl.sasl_conn = NULL; mailsasl_unref(); free_secret: free(f->pop3_sasl.sasl_secret); f->pop3_sasl.sasl_secret = NULL; err: return res; #else return MAILPOP3_ERROR_BAD_USER; #endif }