mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
a minor step forwards
This commit is contained in:
parent
a8c3431ae9
commit
485edb777f
@ -7,6 +7,27 @@
|
|||||||
#define EAT_SPACE(ptr) while( ptr && *ptr && isspace(*ptr) ) ptr++
|
#define EAT_SPACE(ptr) while( ptr && *ptr && isspace(*ptr) ) ptr++
|
||||||
#define EAT_WORD(ptr) while( ptr && *ptr && !isspace(*ptr) && ('>' != *ptr)) ptr++
|
#define EAT_WORD(ptr) while( ptr && *ptr && !isspace(*ptr) && ('>' != *ptr)) ptr++
|
||||||
|
|
||||||
|
char *appendstring(char *string, /* original string */
|
||||||
|
char *buffer, /* to append */
|
||||||
|
int *stringlen, int *stralloc)
|
||||||
|
{
|
||||||
|
int len = strlen(buffer);
|
||||||
|
|
||||||
|
if((len + *stringlen) > *stralloc) {
|
||||||
|
char *newptr= realloc(string, *stralloc*2);
|
||||||
|
if(newptr) {
|
||||||
|
string = newptr;
|
||||||
|
*stralloc *= 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strcpy(&string[*stringlen], buffer);
|
||||||
|
*stringlen += len;
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
char *spitout(FILE *stream, char *main, char *sub, int *size)
|
char *spitout(FILE *stream, char *main, char *sub, int *size)
|
||||||
{
|
{
|
||||||
char buffer[8192]; /* big enough for anything */
|
char buffer[8192]; /* big enough for anything */
|
||||||
@ -19,6 +40,7 @@ char *spitout(FILE *stream, char *main, char *sub, int *size)
|
|||||||
char *string;
|
char *string;
|
||||||
int stringlen=0;
|
int stringlen=0;
|
||||||
int stralloc=256;
|
int stralloc=256;
|
||||||
|
int len;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
STATE_OUTSIDE,
|
STATE_OUTSIDE,
|
||||||
@ -38,22 +60,9 @@ char *spitout(FILE *stream, char *main, char *sub, int *size)
|
|||||||
|
|
||||||
if('<' != *ptr) {
|
if('<' != *ptr) {
|
||||||
if(display) {
|
if(display) {
|
||||||
int len;
|
|
||||||
printf("=> %s", buffer);
|
printf("=> %s", buffer);
|
||||||
|
string = appendstring(string, buffer, &stringlen, &stralloc);
|
||||||
len = strlen(buffer);
|
printf("* %s\n", buffer);
|
||||||
|
|
||||||
if((len + stringlen) > stralloc) {
|
|
||||||
char *newptr= realloc(string, stralloc*2);
|
|
||||||
if(newptr) {
|
|
||||||
string = newptr;
|
|
||||||
stralloc *= 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcpy(&string[stringlen], buffer);
|
|
||||||
stringlen += len;
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -75,15 +84,17 @@ char *spitout(FILE *stream, char *main, char *sub, int *size)
|
|||||||
/* this is the end of the currently read sub section */
|
/* this is the end of the currently read sub section */
|
||||||
state--;
|
state--;
|
||||||
csub[0]=0; /* no sub anymore */
|
csub[0]=0; /* no sub anymore */
|
||||||
|
display=0;
|
||||||
}
|
}
|
||||||
else if((state == STATE_INMAIN) &&
|
else if((state == STATE_INMAIN) &&
|
||||||
!strcmp(cmain, ptr)) {
|
!strcmp(cmain, ptr)) {
|
||||||
/* this is the end of the currently read main section */
|
/* this is the end of the currently read main section */
|
||||||
state--;
|
state--;
|
||||||
cmain[0]=0; /* no main anymore */
|
cmain[0]=0; /* no main anymore */
|
||||||
|
display=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if(!display) {
|
||||||
/* this is the beginning of a section */
|
/* this is the beginning of a section */
|
||||||
end = ptr;
|
end = ptr;
|
||||||
EAT_WORD(end);
|
EAT_WORD(end);
|
||||||
@ -100,11 +111,15 @@ char *spitout(FILE *stream, char *main, char *sub, int *size)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(display) {
|
||||||
|
string = appendstring(string, buffer, &stringlen, &stralloc);
|
||||||
|
printf("* %s\n", buffer);
|
||||||
|
}
|
||||||
|
|
||||||
if((STATE_INSUB == state) &&
|
if((STATE_INSUB == state) &&
|
||||||
!strcmp(cmain, main) &&
|
!strcmp(cmain, main) &&
|
||||||
!strcmp(csub, sub)) {
|
!strcmp(csub, sub)) {
|
||||||
printf("* %s\n", buffer);
|
printf("* (%d bytes) %s\n", stringlen, buffer);
|
||||||
display = 1; /* start displaying */
|
display = 1; /* start displaying */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#define TEST_DATA_PATH "data/test%d"
|
#define TEST_DATA_PATH "data/test%d"
|
||||||
|
|
||||||
|
static char *docfriends = "WE ROOLZ\r\n";
|
||||||
static char *doc404 = "HTTP/1.1 404 Not Found\n"
|
static char *doc404 = "HTTP/1.1 404 Not Found\n"
|
||||||
"Server: " VERSION "\n"
|
"Server: " VERSION "\n"
|
||||||
"Connection: close\n"
|
"Connection: close\n"
|
||||||
@ -184,12 +185,18 @@ static int get_request(int sock)
|
|||||||
|
|
||||||
/* get the number after it */
|
/* get the number after it */
|
||||||
if(ptr) {
|
if(ptr) {
|
||||||
|
if(!strcmp("/verifiedserver", ptr)) {
|
||||||
|
logmsg("Are-we-friendly question received");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
test_no = strtol(ptr+1, &ptr, 10);
|
test_no = strtol(ptr+1, &ptr, 10);
|
||||||
|
|
||||||
logmsg("Found test number in PATH");
|
logmsg("Found test number in PATH");
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
|
|
||||||
logmsg("Did not find test number in PATH");
|
logmsg("Did not find test number in PATH");
|
||||||
|
}
|
||||||
|
|
||||||
return test_no;
|
return test_no;
|
||||||
}
|
}
|
||||||
@ -211,7 +218,11 @@ static int send_doc(int sock, int doc)
|
|||||||
char filename[256];
|
char filename[256];
|
||||||
|
|
||||||
if(doc < 0) {
|
if(doc < 0) {
|
||||||
buffer = doc404;
|
if(-2 == doc)
|
||||||
|
/* we got a "friends?" question, reply back that we sure are */
|
||||||
|
buffer = docfriends;
|
||||||
|
else
|
||||||
|
buffer = doc404;
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
stream=NULL;
|
stream=NULL;
|
||||||
}
|
}
|
||||||
@ -257,6 +268,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
logfile = "logfile";
|
logfile = "logfile";
|
||||||
|
|
||||||
|
/* FIX: write our pid to a file name */
|
||||||
|
|
||||||
logfp = fopen(logfile, "a");
|
logfp = fopen(logfile, "a");
|
||||||
if (!logfp) {
|
if (!logfp) {
|
||||||
perror(logfile);
|
perror(logfile);
|
||||||
@ -317,10 +330,7 @@ int main(int argc, char *argv[])
|
|||||||
logmsg("New client connected");
|
logmsg("New client connected");
|
||||||
|
|
||||||
doc = get_request(msgsock);
|
doc = get_request(msgsock);
|
||||||
if (doc > 0)
|
send_doc(msgsock, doc);
|
||||||
send_doc(msgsock, doc);
|
|
||||||
else
|
|
||||||
send_doc(msgsock, -1);
|
|
||||||
|
|
||||||
close(msgsock);
|
close(msgsock);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user