/***************************************************************************\ ** ** ** htdump ** ** ** ** Program to make http requests and redirect, save or pipe the output. ** ** Ideal for automation and debugging. ** ** ** ** ** ** By Ren Hoek (ren@arak.cs.hro.nl) Under Artistic License, 2000 ** ** ** \***************************************************************************/ /***************************************************************************/ /** Defines **/ #include "global.h" /***************************************************************************\ ** ** ** BuildRequest() ** ** ** ** ** ** Process the commandline options. ** ** ** ** ** ** ** \***************************************************************************/ void BuildRequest(void) { UINT t; UCHAR buffer[512]; /***************************************************************************/ /** Check the arguments **/ if(CONFIG.new_argc!=1) Usage(); /***************************************************************************/ /** Get the prefix **/ if(strncmp("http://", CONFIG.new_argv[0], 7) == 0) { ArgCopy(&CONFIG.url_service, "80"); CONFIG.ssl=0; DelNChar(CONFIG.new_argv[0], 0, 7); } if(strncmp("https://", CONFIG.new_argv[0], 8) == 0) { ArgCopy(&CONFIG.url_service, "443"); CONFIG.ssl=1; DelNChar(CONFIG.new_argv[0], 0, 8); } /***************************************************************************/ /** Disect the URL **/ for(t=0; ; t++) { if(CONFIG.new_argv[0][t]=='\0') { /* If we come to the end of the string, that means no path is given */ /* Also means we reached the end of the host string */ ArgCopy(&CONFIG.url_host, CONFIG.new_argv[0]); ArgCopy(&CONFIG.url_path, "/"); break; } if(CONFIG.new_argv[0][t]==':') { if(strchr(CONFIG.new_argv[0], '@')) { CONFIG.new_argv[0][t]='\0'; ArgCopy(&CONFIG.url_username, CONFIG.new_argv[0]); } else { CONFIG.new_argv[0][t]='\0'; ArgCopy(&CONFIG.url_host, CONFIG.new_argv[0]); } DelNChar(CONFIG.new_argv[0], 0, t+1); t=0; } if(CONFIG.new_argv[0][t]=='@') { CONFIG.new_argv[0][t]='\0'; ArgCopy(&CONFIG.url_password, CONFIG.new_argv[0]); DelNChar(CONFIG.new_argv[0], 0, t+1); t=0; } if(CONFIG.new_argv[0][t]=='/') { CONFIG.new_argv[0][t]='\0'; if(CONFIG.url_host) ArgCopy(&CONFIG.url_service, CONFIG.new_argv[0]); else ArgCopy(&CONFIG.url_host, CONFIG.new_argv[0]); CONFIG.new_argv[0][t]='/'; DelNChar(CONFIG.new_argv[0], 0, t); ArgCopy(&CONFIG.url_path, CONFIG.new_argv[0]); break; } } if(CONFIG.url_username) ArgCopy(&CONFIG.url_b64_password, Encode_Password(CONFIG.url_username, CONFIG.url_password )); /***************************************************************************/ /** Construct request buffer **/ sprintf(CONFIG.request, "%s %s", CONFIG.hdr_command, CONFIG.url_path); switch(CONFIG.hdr_version) { case 0: strcat(CONFIG.request, "\n"); break; case 1: strcat(CONFIG.request, " HTTP/1.0\n"); break; case 2: strcat(CONFIG.request, " HTTP/1.1\n"); break; } if(CONFIG.hdr_version==2 || CONFIG.hdr_host) { if(CONFIG.hdr_host) sprintf(buffer, "Host: %s\n", CONFIG.hdr_host); else sprintf(buffer, "Host: %s\n", CONFIG.url_host); strcat(CONFIG.request, buffer); } if(CONFIG.url_b64_password) { sprintf(buffer, "Authorization: Basic %s\n", CONFIG.url_b64_password); strcat(CONFIG.request, buffer); } if(CONFIG.hdr_range) { sprintf(buffer, "Range: bytes=%s\n", CONFIG.hdr_range); strcat(CONFIG.request, buffer); } if(CONFIG.hdr_accept) { sprintf(buffer, "Accept: %s\n", CONFIG.hdr_accept); strcat(CONFIG.request, buffer); } if(CONFIG.hdr_from) { sprintf(buffer, "From: %s\n", CONFIG.hdr_from); strcat(CONFIG.request, buffer); } if(CONFIG.hdr_referer) { sprintf(buffer, "Referer: %s\n", CONFIG.hdr_referer); strcat(CONFIG.request, buffer); } if(CONFIG.hdr_cookie) { sprintf(buffer, "Cookie: %s\n", CONFIG.hdr_cookie); strcat(CONFIG.request, buffer); } if(CONFIG.hdr_agent) { sprintf(buffer, "User-Agent: %s\n", CONFIG.hdr_agent); strcat(CONFIG.request, buffer); } if(CONFIG.post_content) { sprintf(buffer, "Content-type: application/x-www-form-urlencoded\n" "Content-length: %u\n" "\n" "%s" ,strlen(CONFIG.post_content) ,CONFIG.post_content ); strcat(CONFIG.request, buffer); ArgCopy(&CONFIG.hdr_command, "POST"); } strcat(CONFIG.request, "\n"); } /* End of ProcessArguments() */