#include "http_trans.h"
#include "ghttp.h" /* for getting headers */
/* for the definition of ghttp_request numeration */
#include <string.h>
#include <test.priv.h>
#include <ncurses.h> /* ncurses.h includes stdio.h */
#include <stdlib.h>
#include <errno.h>
#include "utilfcns.h"
char data[16];
static int new_command(char *buffer, WINDOW * win);
int main(int argc, char * argv[]) {
int code;
int ch;
/* This is the http request object */
ghttp_request *request = NULL;
/* Allocate a new empty request object */
char buffer[80];
char * body;
int xmax, ymax;
WINDOW *topwin,*pwin, *top2win, *towin;
app_init();
crmode();
cbreak();
noecho();
keypad(stdscr, TRUE);
getmaxyx(stdscr, ymax, xmax);
if ((topwin = subwin(stdscr,1,xmax,0,0)) == NULL) err_quit("topwin");
if ((top2win = subwin(stdscr,2,xmax,0,0)) == NULL) err_quit("top2win");
if ((towin = subwin(stdscr,ymax-6,xmax-5,6,2)) == NULL) printf("towin");
if((pwin = subwin(stdscr,(ymax-15),xmax-8,10, 3)) == NULL) err_quit ("subwin");
box(towin,ACS_VLINE,ACS_HLINE);
wprintw(topwin,"g)go to url h)header manipulation menu F1) exit program");
wrefresh(topwin);
while ((ch = getch()) != KEY_F(1)) {
wclear(pwin);
switch (ch) {
case 'g':
wclear(topwin);
wprintw(topwin,"g)go to url h)header manipulation menu F1)exit program");
wrefresh(topwin);
new_command(buffer, top2win);
request = ghttp_request_new();
/* Set the URI for the request object */
ghttp_set_uri(request, buffer);
/* Close the connection after you are done. */
ghttp_set_header(request, http_hdr_Connection, "close");
ghttp_set_header(request, http_hdr_User_Agent, "libghttp_tester");
/* http_req_prepare calls http_hdr_set_value */
/* Prepare the connection */
ghttp_prepare(request);
code = ghttp_process(request);
if (code == -1) {
mvwprintw(pwin, +1,+1,"the url \"%s\" that you typed gave an error in ghttp_process", buffer);
} else {
body = ghttp_get_body(request);
wprintw(pwin, body);
}
case 'h':
/* make a new panel */
/* do header menu */
case 'KEY_DL':
delch();
break;
wclear(top2win);
wrefresh(pwin);
}
ghttp_request_destroy(request);
delwin(topwin);
delwin(top2win);
delwin(pwin);
app_exit();
}
static int new_command(char *buffer, WINDOW * win)
{
int c,i=0;
mvwprintw(win,+1,0, "url to be entered: ");
wrefresh(win);
while((c = getch()) != '\n' && i < 80) {
buffer[i++] = c;
waddch(win, c);
wrefresh(win);
}
buffer[i] = '\0';
return 0;
}
/* from ghttp.c line 499 */
/* need set the value of a_hdr */
/* buf = ghttp_get_header(ghttp_request *a_request, const char *a_hdr); */
/* Write out the body. Note that the body of the request */
/* may not be null terminated so we have to be careful of the length. */
/* fwrite(ghttp_get_body(request), */
/* Destroy the request. This closes any file descriptors that */
/* may be open and will free any memory associated with the request. */
/* where does the response object come into play? */
return to top