static int adb_receive(Plug plug, int urgent, char *data, int len) { Adb adb = (Adb) plug; if (adb->state == STATE_SENT_HELLO) { if (data[0]=='O') { // OKAY sk_write(adb->s,"0006shell:",10); adb->state = STATE_ASKED_FOR_SHELL; // wait for shell start response } else { if (data[0]=='F') { handle_fail(adb, data, len); } else { connection_fatal(adb->frontend, "Bad response after initial send"); } return 0; } } else if (adb->state == STATE_ASKED_FOR_SHELL) { if (data[0]=='O') { //OKAY adb->state = STATE_CONNECTED; // shell started, switch to terminal mode } else { if (data[0]=='F') { handle_fail(adb, data, len); } else { connection_fatal(adb->frontend, "Bad response waiting for shell start"); } return 0; } } else if (adb->state == STATE_WAITING_FOR_ERROR_MESSAGE) { do_fatal(adb, data, len); } else { c_write(adb, data, len); } return 1; }
const char *hscReasonphrase( HttpStatuscode status ) { const char *str; switch ( status ) { case STATUS_OK: str = "OK"; break; case STATUS_NOT_FOUND: str = "Not Found"; break; case STATUS_MOVED_PERM: str = "Moved Permanently"; break; case STATUS_FOUND: str = "Found"; break; case STATUS_BAD_REQUEST: str = "Bad Request"; break; case STATUS_FORBIDDEN: str = "Forbidden"; break; default: status =(HttpStatuscode) ( 1 / (int) status); handle_fail( "hscReasonphrase: statuscode not implemented" ); } return str; }
ServerConfigs *srvCfgLoad( ServerConfigs *cfg, int argc, char *argv[] ) { cfg->port = 8888; int c; while( ( c = getopt( argc, argv, "hp:" ) ) >= 0 ) { switch ( ( char )c ) { case 'p': errno = 0; long val = strtol( optarg, 0, 10 ); if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) || (errno != 0 && val == 0)) { handle_error( "port parameter parsing" ); } if ( ( val < 0 ) || ( val > 65535 ) ) handle_fail( "port parameter out of range - must be between 0 .. 65535" ); cfg->port = val; break; case 'h': printHelp(); return 0; break; case '?': if ( ( char )optopt == 'p' ) //Portangabe vergessen { //handle_error("-p requires an argument"); printHelp(); //exit(EXIT_FAILURE); } //else //unbekannte Optionen - einfach ignorieren break; default://unbekannte Optionen - einfach ignorieren break; } } cfg->readBufferSize = 200; cfg->writeBufferSize = 200; cfg->fileBufferSize = 200; cfg->publicDir = "./htdocs"; cfg->indexFile = "index.html"; cfg->httpversion = "HTTP/1.1"; cfg->serverDomain = "http://xaedes.dyndns.org:8888/"; ctAdd( cfg->contentTypes, "png", "image" ); ctAdd( cfg->contentTypes, "jpg", "image" ); ctAdd( cfg->contentTypes, "ico", "image" ); ctAdd( cfg->contentTypes, "html", "text" ); ctAdd( cfg->contentTypes, "css", "text" ); ctAdd( cfg->contentTypes, "", "application" ); return cfg; }
const char *httpVersionToString( HttpVersion hv ) { switch ( hv ) { case HTTP_VERSION_INVALID: return "Invalid"; case HTTP_VERSION_1_0: return "HTTP/1.0"; case HTTP_VERSION_1_1: return "HTTP/1.1"; } handle_fail( "httpVersionToString: unimplemented http version" ); }