Skip to content

Commit

Permalink
""
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Lightfoot committed Aug 12, 2003
1 parent 86b1436 commit 968a9e3
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 9 deletions.
4 changes: 3 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TODO for driftnet
$Id: TODO,v 1.11 2003/05/20 16:49:08 chris Exp $
$Id: TODO,v 1.12 2003/08/12 14:13:14 chris Exp $

* PNG files.

Expand All @@ -26,3 +26,5 @@ $Id: TODO,v 1.11 2003/05/20 16:49:08 chris Exp $

* PID file?

* Delay between reading packets from dump file?

124 changes: 124 additions & 0 deletions http.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* http.c:
* Look for HTTP requests in buffers.
*
* We look for GET requests only, and only if the response is of type
* text/html.
*
* Copyright (c) 2003 Chris Lightfoot. All rights reserved.
* Email: chris@ex-parrot.com; WWW: http://www.ex-parrot.com/~chris/
*
*/

static const char rcsid[] = "$Id: http.c,v 1.1 2003/08/12 14:14:15 chris Exp $";

#include <sys/types.h>

#include <stdlib.h>
#include <string.h>

#include "driftnet.h"

/* find_http_req DATA LEN FOUND FOUNDLEN
* Look for an HTTP request and response in buffer DATA of length LEN. The
* return value is a pointer into DATA suitable for a subsequent call to this
* function; *FOUND is either NULL, or a pointer to the start of an HTTP
* request; in the latter case, *FOUNDLEN is the length of the match
* containing enough information to obtain the URL. */
unsigned char *find_http_req(const unsigned char *data, const size_t len, unsigned char **http, size_t *httplen) {
unsigned char *req, *le, *blankline, *hosthdr;

#define remaining(x) (len - (data - (x)))
#define MAX_REQ 16384

/* HTTP requests look like:
*
* GET {path} HTTP/1.(0|1)\r\n
* header: value\r\n
* ...
* \r\n
*
* We may care about the Host: header in the request. */
if (len < 40)
return (unsigned char*)data;

if (!(req = memstr(data, len, "GET ", 4)))
return (unsigned char*)(data + len - 4);

/* Find the end of the request line. */
if (!(le = memstr(req + 4, remaining(req + 4), "\r\n", 2))) {
if (remaining(req + 4) > MAX_REQ)
return (unsigned char*)(req + 4);
else
return (unsigned char*)req;
}

/* Not enough space for a path. */
if (le < req + 5)
return le + 2;

/* Not an HTTP request, just a line starting GET.... */
if (memcmp(le - 9, " HTTP/1.", 8) || !strchr("01", (int)*(le - 1)))
return le + 2;

/* Find the end of the request headers. */
if (!(blankline = memstr(le + 2, remaining(le + 2), "\r\n\r\n", 4))) {
if (remaining(le + 2) > MAX_REQ)
return (unsigned char*)(data + len - 4);
else
return req;
}

if (memcmp(req + 4, "http://", 7) == 0)
/* Probably a cache request; in any case, don't need to look for a Host:. */
goto found;

/* Is there a Host: header? */
if (!(hosthdr = memstr(le, blankline - le + 2, "\r\nHost: ", 8))) {
return blankline + 4;
}

found:

*http = req;
*httplen = blankline - req;

return blankline + 4;
}

void dispatch_http_req(const char *mname, const unsigned char *data, const size_t len) {
char *url;
const char *path, *host;
int pathlen, hostlen;
const unsigned char *p;

if (!(p = memstr(data, len, "\r\n", 2)))
return;

path = (const char*)(data + 4);
pathlen = (p - 9) - (unsigned char*)path;

if (memcmp(path, "http://", 7) == 0) {
url = malloc(pathlen + 1);
sprintf(url, "%.*s", pathlen, path);
} else {

if (!(p = memstr(p, len - (p - data), "\r\nHost: ", 8)))
return;

host = (const char*)(p + 8);

if (!(p = memstr(p + 8, len - (p + 8 - data), "\r\n", 2)))
return;
hostlen = p - (const unsigned char*)host;

if (hostlen == 0)
return;

url = malloc(hostlen + pathlen + 9);
sprintf(url, "http://%.*s%.*s", hostlen, host, pathlen, path);
}

fprintf(stderr, "\n\n %s\n\n", url);
free(url);
}
7 changes: 4 additions & 3 deletions jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

#ifndef NO_DISPLAY_WINDOW

static const char rcsid[] = "$Id: jpeg.c,v 1.5 2002/07/08 20:57:17 chris Exp $";
static const char rcsid[] = "$Id: jpeg.c,v 1.6 2003/08/12 14:09:57 chris Exp $";

#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <jpeglib.h>

#include "driftnet.h"
#include "img.h"

/* struct my_error_mgr:
Expand All @@ -38,9 +39,9 @@ static void my_error_exit(j_common_ptr cinfo) {
int jpeg_load_hdr(img I) {
struct jpeg_decompress_struct *cinfo;
struct my_error_mgr *jerr;
cinfo = (struct jpeg_decompress_struct*)calloc(sizeof(struct jpeg_decompress_struct), 1);
alloc_struct(jpeg_decompress_struct, cinfo);
I->us = cinfo;
jerr = (struct my_error_mgr*)calloc(sizeof(struct my_error_mgr), 1);
alloc_struct(my_error_mgr, jerr);
cinfo->err = jpeg_std_error(&jerr->pub);
jerr->pub.error_exit = my_error_exit;
if (setjmp(jerr->jb)) {
Expand Down
10 changes: 5 additions & 5 deletions playaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

static const char rcsid[] = "$Id: playaudio.c,v 1.4 2002/06/04 19:09:02 chris Exp $";
static const char rcsid[] = "$Id: playaudio.c,v 1.5 2003/08/12 14:12:29 chris Exp $";

#include <sys/types.h>

Expand Down Expand Up @@ -57,10 +57,10 @@ static audiochunk list, wr, rd;
* Allocate a buffer and copy some data into it. */
static audiochunk audiochunk_new(const unsigned char *data, const size_t len) {
audiochunk A;
A = calloc(1, sizeof *A);
alloc_struct(_audiochunk, A);
A->len = len;
if (data) {
A->data = malloc(len);
A->data = xmalloc(len);
memcpy(A->data, data, len);
}
return A;
Expand All @@ -69,8 +69,8 @@ static audiochunk audiochunk_new(const unsigned char *data, const size_t len) {
/* audiochunk_delete:
* Free memory from an audiochunk. */
static void audiochunk_delete(audiochunk A) {
free(A->data);
free(A);
xfree(A->data);
xfree(A);
}

/* audiochunk_write:
Expand Down

0 comments on commit 968a9e3

Please sign in to comment.