first commit
This commit is contained in:
13
CS4210/Project 3/CVS/Entries
Normal file
13
CS4210/Project 3/CVS/Entries
Normal file
@@ -0,0 +1,13 @@
|
||||
D/asn////
|
||||
D/client////
|
||||
D/common////
|
||||
D/proxy_server////
|
||||
D/server////
|
||||
D/test_files////
|
||||
/cleanup.sh/1.3/Sun Apr 2 09:58:50 2006//
|
||||
D/jpeg_resizer////
|
||||
D/images////
|
||||
D/Report////
|
||||
D/wget_tests////
|
||||
/Caban_Lotfi_proj3.zip/1.2/Tue Apr 25 02:48:07 2006/-kb/
|
||||
/README.txt/1.4/Tue Apr 25 02:47:51 2006//
|
||||
13
CS4210/Project 3/CVS/Entries.Extra
Normal file
13
CS4210/Project 3/CVS/Entries.Extra
Normal file
@@ -0,0 +1,13 @@
|
||||
D/asn///////
|
||||
D/client///////
|
||||
D/common///////
|
||||
D/proxy_server///////
|
||||
D/server///////
|
||||
D/test_files///////
|
||||
/cleanup.sh////*///
|
||||
D/jpeg_resizer///////
|
||||
D/images///////
|
||||
D/Report///////
|
||||
D/wget_tests///////
|
||||
/Caban_Lotfi_proj3.zip////*///
|
||||
/README.txt////*///
|
||||
13
CS4210/Project 3/CVS/Entries.Extra.Old
Normal file
13
CS4210/Project 3/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,13 @@
|
||||
D/asn///////
|
||||
D/client///////
|
||||
D/common///////
|
||||
D/proxy_server///////
|
||||
D/server///////
|
||||
D/test_files///////
|
||||
/cleanup.sh////*///
|
||||
D/jpeg_resizer///////
|
||||
D/images///////
|
||||
D/Report///////
|
||||
/README.txt////*///
|
||||
D/wget_tests///////
|
||||
/Caban_Lotfi_proj3.zip////*///
|
||||
13
CS4210/Project 3/CVS/Entries.Old
Normal file
13
CS4210/Project 3/CVS/Entries.Old
Normal file
@@ -0,0 +1,13 @@
|
||||
D/asn////
|
||||
D/client////
|
||||
D/common////
|
||||
D/proxy_server////
|
||||
D/server////
|
||||
D/test_files////
|
||||
/cleanup.sh/1.3/Sun Apr 2 09:58:50 2006//
|
||||
D/jpeg_resizer////
|
||||
D/images////
|
||||
D/Report////
|
||||
/README.txt/1.3/Tue Apr 25 02:30:55 2006//
|
||||
D/wget_tests////
|
||||
/Caban_Lotfi_proj3.zip/1.1/Tue Apr 25 02:33:35 2006/-kb/
|
||||
1
CS4210/Project 3/CVS/Repository
Normal file
1
CS4210/Project 3/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3
|
||||
1
CS4210/Project 3/CVS/Root
Normal file
1
CS4210/Project 3/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
BIN
CS4210/Project 3/Caban_Lotfi_proj3.zip
Normal file
BIN
CS4210/Project 3/Caban_Lotfi_proj3.zip
Normal file
Binary file not shown.
54
CS4210/Project 3/README.txt
Normal file
54
CS4210/Project 3/README.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
|
||||
l33t Server Project 3
|
||||
|
||||
Note: May have to run dos2unix on configure
|
||||
|
||||
Building the necessary stuff:
|
||||
-----------------------------
|
||||
|
||||
% cd Project\ 3/
|
||||
% mkdir bin
|
||||
% mkdir bin/rpc_server/
|
||||
|
||||
# Building the JPEG Library
|
||||
% cd jpeg_resizer/jpeg-6b
|
||||
% ./configure
|
||||
% make
|
||||
|
||||
# Building the RPC Server
|
||||
% cd ../rpc_server
|
||||
% make -f Makefile
|
||||
% make -f Makefile.rpc
|
||||
|
||||
#Building the Proxy
|
||||
% cd ../../proxy_server/
|
||||
% make
|
||||
|
||||
|
||||
Running the stuff:
|
||||
------------------
|
||||
|
||||
# The RPC Server can be run on whatever system you want:
|
||||
% cd Project\ 3/jpeg_resizer/rpc_server
|
||||
% ./jpeg_server
|
||||
|
||||
# Running the proxy
|
||||
## Without the RPC Server, straight up hosting:
|
||||
% cd Project\ 3/proxy_server
|
||||
% ../bin/proxy/l33t_proxy 0
|
||||
|
||||
## With the RPC Server, assuming an RPC on localhost
|
||||
% cd Project\ 3/proxy_server
|
||||
% ../bin/proxy/l33t_proxy 1 127.0.0.1
|
||||
|
||||
## Assuming many RPC Servers
|
||||
% cd Project\ 3/proxy_server
|
||||
% ../bin/proxy/l33t_proxy 1 127.0.0.1 128.61.42.147 10.10.10.1 192.168.0.2
|
||||
|
||||
Notes:
|
||||
------
|
||||
|
||||
- If you're browsing the web with a browser, ensure that the browser has persistant connections disabled (this is in the proxy menu in Konqueror).
|
||||
|
||||
- Requests made to localhost are assumed to be meant for l33t_server and will access on port 1337. Error correction/robustness was not considered an issue in this case, so the effects of not having l33t_server running may or may not be bad.
|
||||
|
||||
4
CS4210/Project 3/Report/CVS/Entries
Normal file
4
CS4210/Project 3/Report/CVS/Entries
Normal file
@@ -0,0 +1,4 @@
|
||||
/Report.doc/1.4/Tue Apr 25 02:28:31 2006/-kb/
|
||||
/Proj3.xls/1.1/Tue Apr 25 02:19:36 2006/-kb/
|
||||
/Report.pdf/1.3/Tue Apr 25 02:30:16 2006/-kb/
|
||||
D
|
||||
3
CS4210/Project 3/Report/CVS/Entries.Extra
Normal file
3
CS4210/Project 3/Report/CVS/Entries.Extra
Normal file
@@ -0,0 +1,3 @@
|
||||
/Report.doc////*///
|
||||
/Proj3.xls////*///
|
||||
/Report.pdf////*///
|
||||
3
CS4210/Project 3/Report/CVS/Entries.Extra.Old
Normal file
3
CS4210/Project 3/Report/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/Report.doc////*///
|
||||
/Proj3.xls////*///
|
||||
/Report.pdf////*///
|
||||
4
CS4210/Project 3/Report/CVS/Entries.Old
Normal file
4
CS4210/Project 3/Report/CVS/Entries.Old
Normal file
@@ -0,0 +1,4 @@
|
||||
/Report.doc/1.4/Tue Apr 25 02:28:31 2006/-kb/
|
||||
/Proj3.xls/1.1/Tue Apr 25 02:19:36 2006/-kb/
|
||||
/Report.pdf/0/dummy timestamp/-kb/
|
||||
D
|
||||
1
CS4210/Project 3/Report/CVS/Repository
Normal file
1
CS4210/Project 3/Report/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/Report
|
||||
1
CS4210/Project 3/Report/CVS/Root
Normal file
1
CS4210/Project 3/Report/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
BIN
CS4210/Project 3/Report/Proj3.xls
Normal file
BIN
CS4210/Project 3/Report/Proj3.xls
Normal file
Binary file not shown.
BIN
CS4210/Project 3/Report/Report.doc
Normal file
BIN
CS4210/Project 3/Report/Report.doc
Normal file
Binary file not shown.
BIN
CS4210/Project 3/Report/Report.pdf
Normal file
BIN
CS4210/Project 3/Report/Report.pdf
Normal file
Binary file not shown.
2
CS4210/Project 3/asn/CVS/Entries
Normal file
2
CS4210/Project 3/asn/CVS/Entries
Normal file
@@ -0,0 +1,2 @@
|
||||
/Project3.pdf/1.1/Fri Apr 14 22:30:12 2006/-kb/
|
||||
D
|
||||
1
CS4210/Project 3/asn/CVS/Entries.Extra
Normal file
1
CS4210/Project 3/asn/CVS/Entries.Extra
Normal file
@@ -0,0 +1 @@
|
||||
/Project3.pdf////*///
|
||||
1
CS4210/Project 3/asn/CVS/Entries.Extra.Old
Normal file
1
CS4210/Project 3/asn/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1 @@
|
||||
/Project3.pdf////*///
|
||||
2
CS4210/Project 3/asn/CVS/Entries.Old
Normal file
2
CS4210/Project 3/asn/CVS/Entries.Old
Normal file
@@ -0,0 +1,2 @@
|
||||
/Project3.pdf/0/dummy timestamp/-kb/
|
||||
D
|
||||
1
CS4210/Project 3/asn/CVS/Repository
Normal file
1
CS4210/Project 3/asn/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/asn
|
||||
1
CS4210/Project 3/asn/CVS/Root
Normal file
1
CS4210/Project 3/asn/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
BIN
CS4210/Project 3/asn/Project3.pdf
Normal file
BIN
CS4210/Project 3/asn/Project3.pdf
Normal file
Binary file not shown.
13
CS4210/Project 3/cleanup.sh
Normal file
13
CS4210/Project 3/cleanup.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script will cleanup the keys in memory from a
|
||||
# kill that was unmasked and thus left stuff in memory
|
||||
|
||||
ipcrm -M 7890
|
||||
ipcrm -M 7891
|
||||
ipcrm -M 7892
|
||||
ipcrm -M 7893
|
||||
|
||||
ipcrm -S 7892
|
||||
ipcrm -S 7891
|
||||
|
||||
3
CS4210/Project 3/client/CVS/Entries
Normal file
3
CS4210/Project 3/client/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
D/src////
|
||||
/Makefile/1.3/Sun Apr 2 10:03:00 2006//
|
||||
D/tests////
|
||||
3
CS4210/Project 3/client/CVS/Entries.Extra
Normal file
3
CS4210/Project 3/client/CVS/Entries.Extra
Normal file
@@ -0,0 +1,3 @@
|
||||
D/src///////
|
||||
/Makefile////*///
|
||||
D/tests///////
|
||||
4
CS4210/Project 3/client/CVS/Entries.Extra.Old
Normal file
4
CS4210/Project 3/client/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,4 @@
|
||||
D/src///////
|
||||
/Makefile////*///
|
||||
D/tests///////
|
||||
D/results///////
|
||||
4
CS4210/Project 3/client/CVS/Entries.Old
Normal file
4
CS4210/Project 3/client/CVS/Entries.Old
Normal file
@@ -0,0 +1,4 @@
|
||||
D/src////
|
||||
/Makefile/1.3/Sun Apr 2 10:03:00 2006//
|
||||
D/tests////
|
||||
D/results////
|
||||
1
CS4210/Project 3/client/CVS/Repository
Normal file
1
CS4210/Project 3/client/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/client
|
||||
1
CS4210/Project 3/client/CVS/Root
Normal file
1
CS4210/Project 3/client/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
35
CS4210/Project 3/client/Makefile
Normal file
35
CS4210/Project 3/client/Makefile
Normal file
@@ -0,0 +1,35 @@
|
||||
CC = gcc
|
||||
OPT = -O3 -fomit-frame-pointer -march=i686
|
||||
LIBS = -lpthread
|
||||
TARGET = l33t_client
|
||||
MISC = makefile
|
||||
INCDIR = src/include
|
||||
SRCDIR = src
|
||||
BINDIR = bin
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(BINDIR)/ezxml.o $(BINDIR)/parser.o $(BINDIR)/networking.o $(BINDIR)/threads.o $(BINDIR)/main.o
|
||||
$(CC) $(OPT) $(LIBS) -o $(BINDIR)/$(TARGET) $(BINDIR)/*.o
|
||||
|
||||
$(BINDIR)/ezxml.o: $(SRCDIR)/ezxml/ezxml.h $(SRCDIR)/ezxml/ezxml.c
|
||||
-mkdir bin > /dev/null
|
||||
$(CC) $(OPT) $(LIBS) -c -o $(BINDIR)/ezxml.o $(SRCDIR)/ezxml/ezxml.c
|
||||
|
||||
$(BINDIR)/parser.o: $(SRCDIR)/parser.c $(INCDIR)/parser.h
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/parser.o $(SRCDIR)/parser.c
|
||||
|
||||
$(BINDIR)/networking.o: $(SRCDIR)/networking.c $(INCDIR)/networking.h
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/networking.o $(SRCDIR)/networking.c
|
||||
|
||||
$(BINDIR)/threads.o: $(SRCDIR)/threads.c $(INCDIR)/threads.h
|
||||
$(CC) $(OPT) -c -o $(BINDIR)/threads.o $(SRCDIR)/threads.c
|
||||
|
||||
$(BINDIR)/main.o: $(SRCDIR)/main.c $(INCDIR)/test.h
|
||||
$(CC) $(OPT) $(LIBS) -c -o $(BINDIR)/main.o $(SRCDIR)/main.c
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p bin
|
||||
|
||||
clean:
|
||||
rm -rf $(BINDIR)/*.o $(BINDIR)/$(TARGET) $(BINDIR)
|
||||
7
CS4210/Project 3/client/src/CVS/Entries
Normal file
7
CS4210/Project 3/client/src/CVS/Entries
Normal file
@@ -0,0 +1,7 @@
|
||||
D/ezxml////
|
||||
D/include////
|
||||
/main.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
/networking.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
/parser.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
/snprintf.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
/threads.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
7
CS4210/Project 3/client/src/CVS/Entries.Extra
Normal file
7
CS4210/Project 3/client/src/CVS/Entries.Extra
Normal file
@@ -0,0 +1,7 @@
|
||||
D/ezxml///////
|
||||
D/include///////
|
||||
/main.c////*///
|
||||
/networking.c////*///
|
||||
/parser.c////*///
|
||||
/snprintf.c////*///
|
||||
/threads.c////*///
|
||||
8
CS4210/Project 3/client/src/CVS/Entries.Extra.Old
Normal file
8
CS4210/Project 3/client/src/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,8 @@
|
||||
D/ezxml///////
|
||||
D/include///////
|
||||
/main.c////*///
|
||||
/networking.c////*///
|
||||
/parser.c////*///
|
||||
/snprintf.c////*///
|
||||
/threads.c////*///
|
||||
D/pthreads///////
|
||||
8
CS4210/Project 3/client/src/CVS/Entries.Old
Normal file
8
CS4210/Project 3/client/src/CVS/Entries.Old
Normal file
@@ -0,0 +1,8 @@
|
||||
D/ezxml////
|
||||
D/include////
|
||||
/main.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
/networking.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
/parser.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
/snprintf.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
/threads.c/1.3/Sun Apr 2 10:02:18 2006//
|
||||
D/pthreads////
|
||||
1
CS4210/Project 3/client/src/CVS/Repository
Normal file
1
CS4210/Project 3/client/src/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/client/src
|
||||
1
CS4210/Project 3/client/src/CVS/Root
Normal file
1
CS4210/Project 3/client/src/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
3
CS4210/Project 3/client/src/ezxml/CVS/Entries
Normal file
3
CS4210/Project 3/client/src/ezxml/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
/ezxml.c/1.3/Sun Apr 2 10:02:11 2006//
|
||||
/ezxml.h/1.3/Sun Apr 2 10:02:11 2006//
|
||||
D
|
||||
2
CS4210/Project 3/client/src/ezxml/CVS/Entries.Extra
Normal file
2
CS4210/Project 3/client/src/ezxml/CVS/Entries.Extra
Normal file
@@ -0,0 +1,2 @@
|
||||
/ezxml.c////*///
|
||||
/ezxml.h////*///
|
||||
2
CS4210/Project 3/client/src/ezxml/CVS/Entries.Extra.Old
Normal file
2
CS4210/Project 3/client/src/ezxml/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,2 @@
|
||||
/ezxml.c////*///
|
||||
/ezxml.h////*///
|
||||
3
CS4210/Project 3/client/src/ezxml/CVS/Entries.Old
Normal file
3
CS4210/Project 3/client/src/ezxml/CVS/Entries.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/ezxml.c/0/dummy timestamp//
|
||||
/ezxml.h/0/dummy timestamp//
|
||||
D
|
||||
1
CS4210/Project 3/client/src/ezxml/CVS/Repository
Normal file
1
CS4210/Project 3/client/src/ezxml/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/client/src/ezxml
|
||||
1
CS4210/Project 3/client/src/ezxml/CVS/Root
Normal file
1
CS4210/Project 3/client/src/ezxml/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
1021
CS4210/Project 3/client/src/ezxml/ezxml.c
Normal file
1021
CS4210/Project 3/client/src/ezxml/ezxml.c
Normal file
File diff suppressed because it is too large
Load Diff
157
CS4210/Project 3/client/src/ezxml/ezxml.h
Normal file
157
CS4210/Project 3/client/src/ezxml/ezxml.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/* ezxml.h
|
||||
*
|
||||
* Copyright 2004, 2005 Aaron Voisine <aaron@voisine.org>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _EZXML_H
|
||||
#define _EZXML_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define EZXML_BUFSIZE 1024 // size of internal memory buffers
|
||||
#define EZXML_NAMEM 0x80 // name is malloced
|
||||
#define EZXML_TXTM 0x40 // txt is malloced
|
||||
#define EZXML_DUP 0x20 // attribute name and value are strduped
|
||||
|
||||
typedef struct ezxml *ezxml_t;
|
||||
struct ezxml {
|
||||
char *name; // tag name
|
||||
char **attr; // tag attributes { name, value, name, value, ... NULL }
|
||||
char *txt; // tag character content, empty string if none
|
||||
size_t off; // tag offset from start of parent tag character content
|
||||
ezxml_t next; // next tag with same name in this section at this depth
|
||||
ezxml_t sibling; // next tag with different name in same section and depth
|
||||
ezxml_t ordered; // next tag, same section and depth, in original order
|
||||
ezxml_t child; // head of sub tag list, NULL if none
|
||||
ezxml_t parent; // parent tag, NULL if current tag is root tag
|
||||
short flags; // additional information
|
||||
};
|
||||
|
||||
// Given a string of xml data and its length, parses it and creates an ezxml
|
||||
// structure. For efficiency, modifies the data by adding null terminators
|
||||
// and decoding ampersand sequences. If you don't want this, copy the data and
|
||||
// pass in the copy. Returns NULL on failure.
|
||||
ezxml_t ezxml_parse_str(char *s, size_t len);
|
||||
|
||||
// A wrapper for ezxml_parse_str() that accepts a file descriptor. First
|
||||
// attempts to mem map the file. Failing that, reads the file into memory.
|
||||
// Returns NULL on failure.
|
||||
ezxml_t ezxml_parse_fd(int fd);
|
||||
|
||||
// a wrapper for ezxml_parse_fd() that accepts a file name
|
||||
ezxml_t ezxml_parse_file(const char *file);
|
||||
|
||||
// Wrapper for ezxml_parse_str() that accepts a file stream. Reads the entire
|
||||
// stream into memory and then parses it. For xml files, use ezxml_parse_file()
|
||||
// or ezxml_parse_fd()
|
||||
ezxml_t ezxml_parse_fp(FILE *fp);
|
||||
|
||||
// returns the first child tag (one level deeper) with the given name or NULL
|
||||
// if not found
|
||||
ezxml_t ezxml_child(ezxml_t xml, const char *name);
|
||||
|
||||
// returns the next tag of the same name in the same section and depth or NULL
|
||||
// if not found
|
||||
#define ezxml_next(xml) ((xml) ? xml->next : NULL)
|
||||
|
||||
// Returns the Nth tag with the same name in the same section at the same depth
|
||||
// or NULL if not found. An index of 0 returns the tag given.
|
||||
ezxml_t ezxml_idx(ezxml_t xml, int idx);
|
||||
|
||||
// returns the name of the given tag
|
||||
#define ezxml_name(xml) ((xml) ? xml->name : NULL)
|
||||
|
||||
// returns the given tag's character content or empty string if none
|
||||
#define ezxml_txt(xml) ((xml) ? xml->txt : "")
|
||||
|
||||
// returns the value of the requested tag attribute, or NULL if not found
|
||||
const char *ezxml_attr(ezxml_t xml, const char *attr);
|
||||
|
||||
// Traverses the ezxml sturcture to retrieve a specific subtag. Takes a
|
||||
// variable length list of tag names and indexes. The argument list must be
|
||||
// terminated by either an index of -1 or an empty string tag name. Example:
|
||||
// title = ezxml_get(library, "shelf", 0, "book", 2, "title", -1);
|
||||
// This retrieves the title of the 3rd book on the 1st shelf of library.
|
||||
// Returns NULL if not found.
|
||||
ezxml_t ezxml_get(ezxml_t xml, ...);
|
||||
|
||||
// Converts an ezxml structure back to xml. Returns a string of xml data that
|
||||
// must be freed.
|
||||
char *ezxml_toxml(ezxml_t xml);
|
||||
|
||||
// returns a NULL terminated array of processing instructions for the given
|
||||
// target
|
||||
const char **ezxml_pi(ezxml_t xml, const char *target);
|
||||
|
||||
// frees the memory allocated for an ezxml structure
|
||||
void ezxml_free(ezxml_t xml);
|
||||
|
||||
// returns parser error message or empty string if none
|
||||
const char *ezxml_error(ezxml_t xml);
|
||||
|
||||
// returns a new empty ezxml structure with the given root tag name
|
||||
ezxml_t ezxml_new(const char *name);
|
||||
|
||||
// wrapper for ezxml_new() that strdup()s name
|
||||
#define ezxml_new_d(name) ezxml_set_flag(ezxml_new(strdup(name)), EZXML_NAMEM)
|
||||
|
||||
// Adds a child tag. off is the offset of the child tag relative to the start
|
||||
// of the parent tag's character content. Returns the child tag.
|
||||
ezxml_t ezxml_add_child(ezxml_t xml, const char *name, size_t off);
|
||||
|
||||
// wrapper for ezxml_add_child() that strdup()s name
|
||||
#define ezxml_add_child_d(xml, name, off) \
|
||||
ezxml_set_flag(ezxml_add_child(xml, strdup(name), off), EZXML_NAMEM)
|
||||
|
||||
// sets the character content for the given tag and returns the tag
|
||||
ezxml_t ezxml_set_txt(ezxml_t xml, const char *txt);
|
||||
|
||||
// wrapper for ezxml_set_txt() that strdup()s txt
|
||||
#define ezxml_set_txt_d(xml, txt) \
|
||||
ezxml_set_flag(ezxml_set_txt(xml, strdup(txt)), EZXML_TXTM)
|
||||
|
||||
// Sets the given tag attribute or adds a new attribute if not found. A value
|
||||
// of NULL will remove the specified attribute.
|
||||
void ezxml_set_attr(ezxml_t xml, const char *name, const char *value);
|
||||
|
||||
// Wrapper for ezxml_set_attr() that strdup()s name/value. Value cannot be NULL
|
||||
#define ezxml_set_attr_d(xml, name, value) \
|
||||
ezxml_set_attr(ezxml_set_flag(xml, EZXML_DUP), strdup(name), strdup(value))
|
||||
|
||||
// sets a flag for the given tag and returns the tag
|
||||
ezxml_t ezxml_set_flag(ezxml_t xml, short flag);
|
||||
|
||||
// removes a tag along with all its subtags
|
||||
void ezxml_remove(ezxml_t xml);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _EZXML_H
|
||||
7
CS4210/Project 3/client/src/include/CVS/Entries
Normal file
7
CS4210/Project 3/client/src/include/CVS/Entries
Normal file
@@ -0,0 +1,7 @@
|
||||
/defs.h/1.3/Sun Apr 2 10:02:02 2006//
|
||||
/networking.h/1.3/Sun Apr 2 10:02:02 2006//
|
||||
/parser.h/1.3/Sun Apr 2 10:02:02 2006//
|
||||
/snprintf.h/1.3/Sun Apr 2 10:02:02 2006//
|
||||
/test.h/1.3/Sun Apr 2 10:02:02 2006//
|
||||
/threads.h/1.3/Sun Apr 2 10:02:02 2006//
|
||||
D
|
||||
6
CS4210/Project 3/client/src/include/CVS/Entries.Extra
Normal file
6
CS4210/Project 3/client/src/include/CVS/Entries.Extra
Normal file
@@ -0,0 +1,6 @@
|
||||
/defs.h////*///
|
||||
/networking.h////*///
|
||||
/parser.h////*///
|
||||
/snprintf.h////*///
|
||||
/test.h////*///
|
||||
/threads.h////*///
|
||||
@@ -0,0 +1,6 @@
|
||||
/defs.h////*///
|
||||
/networking.h////*///
|
||||
/parser.h////*///
|
||||
/snprintf.h////*///
|
||||
/test.h////*///
|
||||
/threads.h////*///
|
||||
7
CS4210/Project 3/client/src/include/CVS/Entries.Old
Normal file
7
CS4210/Project 3/client/src/include/CVS/Entries.Old
Normal file
@@ -0,0 +1,7 @@
|
||||
/defs.h/0/dummy timestamp//
|
||||
/networking.h/0/dummy timestamp//
|
||||
/parser.h/0/dummy timestamp//
|
||||
/snprintf.h/0/dummy timestamp//
|
||||
/test.h/0/dummy timestamp//
|
||||
/threads.h/0/dummy timestamp//
|
||||
D
|
||||
1
CS4210/Project 3/client/src/include/CVS/Repository
Normal file
1
CS4210/Project 3/client/src/include/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/client/src/include
|
||||
1
CS4210/Project 3/client/src/include/CVS/Root
Normal file
1
CS4210/Project 3/client/src/include/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
15
CS4210/Project 3/client/src/include/defs.h
Normal file
15
CS4210/Project 3/client/src/include/defs.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _DEFS_H_
|
||||
#define _DEFS_H_
|
||||
|
||||
/* Turn off deprecation warnings to avoid use of "safe" strings in Win32 */
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE 1
|
||||
#define HTTP_REQUEST_SIZE 2024
|
||||
#define RECV_SIZE 64
|
||||
#define timenormal(sec,usec) if(0>usec){sec--; usec+=1000000;}
|
||||
#define DieWithError(msg) { \
|
||||
fprintf(stderr, "%s: PwnT! Error on line %d.\n", (msg), __LINE__); \
|
||||
perror(msg); \
|
||||
exit(EXIT_FAILURE);}
|
||||
|
||||
#endif
|
||||
11
CS4210/Project 3/client/src/include/networking.h
Normal file
11
CS4210/Project 3/client/src/include/networking.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _NETWORKING_H_
|
||||
#define _NETWORKING_H_
|
||||
|
||||
/*
|
||||
* Open a TCP Socket connection with:
|
||||
* ipaddr: Remote IP Address
|
||||
* server_port: Port to open on
|
||||
*/
|
||||
int createTCPSocket(char *ipaddr, unsigned short server_port);
|
||||
|
||||
#endif
|
||||
16
CS4210/Project 3/client/src/include/parser.h
Normal file
16
CS4210/Project 3/client/src/include/parser.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _PARSER_H_
|
||||
#define _PARSER_H_
|
||||
|
||||
#include "test.h"
|
||||
|
||||
/*
|
||||
* Parse the Tests from the testFile
|
||||
*/
|
||||
int parseTests(Test** testListPtr, char* fileName);
|
||||
|
||||
/*
|
||||
* Print the tests that were read in
|
||||
*/
|
||||
void printTests(Test* testList, int count);
|
||||
|
||||
#endif
|
||||
29
CS4210/Project 3/client/src/include/snprintf.h
Normal file
29
CS4210/Project 3/client/src/include/snprintf.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _PORTABLE_SNPRINTF_H_
|
||||
#define _PORTABLE_SNPRINTF_H_
|
||||
|
||||
#define PORTABLE_SNPRINTF_VERSION_MAJOR 2
|
||||
#define PORTABLE_SNPRINTF_VERSION_MINOR 2
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef HAVE_SNPRINTF
|
||||
#include <stdio.h>
|
||||
#else
|
||||
extern int snprintf(char *, size_t, const char *, /*args*/ ...);
|
||||
extern int vsnprintf(char *, size_t, const char *, va_list);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
|
||||
extern int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
|
||||
extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
|
||||
#define snprintf portable_snprintf
|
||||
#define vsnprintf portable_vsnprintf
|
||||
#endif
|
||||
|
||||
extern int asprintf (char **ptr, const char *fmt, /*args*/ ...);
|
||||
extern int vasprintf (char **ptr, const char *fmt, va_list ap);
|
||||
extern int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
|
||||
extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap);
|
||||
|
||||
#endif
|
||||
20
CS4210/Project 3/client/src/include/test.h
Normal file
20
CS4210/Project 3/client/src/include/test.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef _TEST_H_
|
||||
#define _TEST_H_
|
||||
|
||||
typedef struct {
|
||||
char** fileList;
|
||||
char* name;
|
||||
int numThreads;
|
||||
int iterations;
|
||||
int fileCount;
|
||||
} Test;
|
||||
|
||||
typedef struct {
|
||||
char *fileName;
|
||||
char *hostName;
|
||||
unsigned short port_number;
|
||||
int iterations;
|
||||
} Request;
|
||||
|
||||
#endif
|
||||
|
||||
9
CS4210/Project 3/client/src/include/threads.h
Normal file
9
CS4210/Project 3/client/src/include/threads.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _THREADS_H_
|
||||
#define _THREADS_H_
|
||||
|
||||
#include "test.h"
|
||||
|
||||
void init_threads(int numThreads, Request** rList, int numFiles);
|
||||
extern int threads;
|
||||
|
||||
#endif
|
||||
60
CS4210/Project 3/client/src/main.c
Normal file
60
CS4210/Project 3/client/src/main.c
Normal file
@@ -0,0 +1,60 @@
|
||||
// ANSI C89 Stuff
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// l33t_client Stuff
|
||||
#include "include/test.h"
|
||||
#include "include/parser.h"
|
||||
#include "include/networking.h"
|
||||
#include "include/defs.h"
|
||||
|
||||
|
||||
/*
|
||||
* l33t_client Main, builds Requests and sends them to the threads
|
||||
*/
|
||||
int main(int argc, char** argv) {
|
||||
Test* testList = NULL;
|
||||
int numTests;
|
||||
int i, j, k;
|
||||
Request *r = malloc(sizeof(Request));
|
||||
Request **rList = NULL;
|
||||
|
||||
// Scan command line
|
||||
if (argc < 3) {
|
||||
printf("Improper usage\n");
|
||||
printf(" ./l33t_client IP_ADDRESS PORT_NUM TESTFILE\n");
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
r->hostName = argv[1];
|
||||
r->port_number = atoi(argv[2]);
|
||||
|
||||
printf("Accessing %s:%d\n",r->hostName, r->port_number);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
numTests = parseTests(&testList, (argc > 3) ? argv[3] : "testFile.xml");
|
||||
|
||||
// Create the requests
|
||||
for (i=0; i<testList[0].fileCount; i++) {
|
||||
rList = realloc(rList, sizeof(Request*)*(i+1));
|
||||
rList[i] = malloc(sizeof(Request));
|
||||
|
||||
memcpy(rList[i], r, sizeof(Request));
|
||||
rList[i]->fileName = testList[0].fileList[i];
|
||||
rList[i]->iterations = testList[0].iterations;
|
||||
}
|
||||
|
||||
// TODO: Alter this such that the threads wait
|
||||
init_threads(testList[0].numThreads, rList, testList[0].fileCount);
|
||||
|
||||
printf(" fileName | iterations | diff_secs | diff_usecs | sock fails | total_bytes_recv\n");
|
||||
|
||||
// TODO: Wait for threads to exit properly
|
||||
for(;getchar()!='q';) {
|
||||
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
44
CS4210/Project 3/client/src/networking.c
Normal file
44
CS4210/Project 3/client/src/networking.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "include/networking.h"
|
||||
#include "include/defs.h"
|
||||
|
||||
//C89 stuff
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//Networking Stuff
|
||||
#ifdef _WIN32
|
||||
#include <winsock.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
int createTCPSocket(char *ipaddr, unsigned short server_port)
|
||||
{
|
||||
|
||||
int sock; /* Socket descriptor */
|
||||
struct sockaddr_in ServAddr; /* Address Structure */
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData; /* Winsock struct. */
|
||||
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)/* Winsock 2.0 DLL. */
|
||||
DieWithError("WSAStartup() failed");
|
||||
#endif
|
||||
|
||||
if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
|
||||
DieWithError("socket() failed");
|
||||
|
||||
memset(&ServAddr, 0, sizeof(ServAddr));
|
||||
ServAddr.sin_family = AF_INET;
|
||||
ServAddr.sin_addr.s_addr = inet_addr(ipaddr);
|
||||
ServAddr.sin_port = htons(server_port);
|
||||
|
||||
if (connect(sock, (struct sockaddr *) &ServAddr, sizeof(ServAddr)) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return sock;
|
||||
}
|
||||
}
|
||||
91
CS4210/Project 3/client/src/parser.c
Normal file
91
CS4210/Project 3/client/src/parser.c
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "include/parser.h"
|
||||
#include "include/test.h"
|
||||
#include "ezxml/ezxml.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int parseTests(Test** testListPtr, char* fileName) {
|
||||
ezxml_t xmlFile = ezxml_parse_file(fileName);
|
||||
ezxml_t current;
|
||||
Test* testList;
|
||||
int index;
|
||||
|
||||
if (!xmlFile) {
|
||||
printf("Couldn't load testFile.xml\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
current = xmlFile->child;
|
||||
|
||||
for (index = 0 ;current; index++, current = current->sibling ) {
|
||||
ezxml_t child;
|
||||
|
||||
*testListPtr = realloc(*testListPtr, (index+1)*sizeof(Test));
|
||||
testList = *testListPtr;
|
||||
|
||||
//No Checks!!!! Buffer Overflow capable!!!!
|
||||
testList[index].name = malloc(sizeof(char)*(strlen(current->name)+1));
|
||||
strcpy(testList[index].name, current->name);
|
||||
|
||||
for (child = current->child; child; child = child->sibling ) {
|
||||
|
||||
if (!strcmp(child->name,"numthreads")) {
|
||||
testList[index].numThreads = atoi(child->txt);
|
||||
|
||||
} else if (!strcmp(child->name, "iterations")) {
|
||||
testList[index].iterations = atoi(child->txt);
|
||||
|
||||
} else if (!strcmp(child->name, "filesToRetrieve")) {
|
||||
|
||||
ezxml_t files = child->child;
|
||||
int* fileCount = &(testList[index].fileCount);
|
||||
|
||||
*fileCount = 0;
|
||||
testList[index].fileList = NULL;
|
||||
|
||||
|
||||
while (files) {
|
||||
|
||||
//Increase length of flleList
|
||||
testList[index].fileList
|
||||
= realloc(testList[index].fileList
|
||||
, sizeof(char*) * (*fileCount+1));
|
||||
|
||||
//Allocate space for contents
|
||||
testList[index].fileList[*fileCount]
|
||||
= malloc(sizeof(char) * (strlen(files->txt)+1));
|
||||
|
||||
//Copy contents into structure
|
||||
strcpy(testList[index].fileList[*fileCount], files->txt);
|
||||
|
||||
files = files->next;
|
||||
(*fileCount)++;
|
||||
}
|
||||
|
||||
}
|
||||
} // end while(child)
|
||||
} //end for(current)
|
||||
|
||||
ezxml_free(xmlFile);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
void printTests(Test* testList, int count) {
|
||||
int index;
|
||||
|
||||
for (index = 0; index < count; index++) {
|
||||
printf("\n-- Test: %s \n", testList[index].name);
|
||||
printf("--- number of threads: %d \n",
|
||||
testList[index].numThreads);
|
||||
printf("--- number of iterations: %d \n",
|
||||
testList[index].iterations);
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<testList[index].fileCount; i++) {
|
||||
printf("--- Load File: %s \n",
|
||||
testList[index].fileList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1025
CS4210/Project 3/client/src/snprintf.c
Normal file
1025
CS4210/Project 3/client/src/snprintf.c
Normal file
File diff suppressed because it is too large
Load Diff
126
CS4210/Project 3/client/src/threads.c
Normal file
126
CS4210/Project 3/client/src/threads.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "include/threads.h"
|
||||
#include "include/defs.h"
|
||||
#include "include/networking.h"
|
||||
#include "include/test.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int threads = 0;
|
||||
char ready;
|
||||
|
||||
void *makeRequest(void *in) {
|
||||
int i;
|
||||
int sock_fail=0;
|
||||
int total_bytes_received;
|
||||
int sendlen;
|
||||
char http_request[HTTP_REQUEST_SIZE];
|
||||
Request *r = (Request*)in;
|
||||
long diff_secs, diff_usecs;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
//Detach thread
|
||||
pthread_detach(pthread_self());
|
||||
|
||||
while(ready != 1);
|
||||
|
||||
//printf("Thread %d starting\n", pthread_self());
|
||||
|
||||
//Timing stuff
|
||||
gettimeofday(&tv, &tz);
|
||||
diff_secs = tv.tv_sec;
|
||||
diff_usecs = tv.tv_usec;
|
||||
|
||||
|
||||
for (i=0, sock_fail=0; i < r->iterations; i++) {
|
||||
int sock;
|
||||
|
||||
for(;;){
|
||||
sock = createTCPSocket(r->hostName, r->port_number);
|
||||
if(sock<0) {
|
||||
sock_fail++;
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memset(http_request, 0, sizeof(char)*HTTP_REQUEST_SIZE);
|
||||
|
||||
sprintf(http_request, "GET %s HTTP/1.1\r\n\r\n\0" , r->fileName);
|
||||
sendlen=strlen(http_request) + 1;
|
||||
|
||||
// printf("Requesting: %s\n", http_request);
|
||||
|
||||
if(send(sock, http_request, sendlen, 0) != sendlen)
|
||||
{
|
||||
DieWithError("send() failed");
|
||||
}
|
||||
|
||||
{
|
||||
int bytes_received = 0;
|
||||
char get_buffer[RECV_SIZE];
|
||||
|
||||
total_bytes_received=0;
|
||||
|
||||
for(;;) {
|
||||
memset(get_buffer, 0, sizeof(char)*RECV_SIZE);
|
||||
bytes_received = recv(sock, get_buffer, RECV_SIZE, 0);
|
||||
|
||||
/* printf("Bytes gotten: %d\n", bytes_received); */
|
||||
|
||||
if(bytes_received < 0) {
|
||||
continue;
|
||||
} else if (bytes_received == 0) {
|
||||
break;
|
||||
} else {
|
||||
total_bytes_received += bytes_received;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
closesocket(sock);
|
||||
#else
|
||||
close(sock);
|
||||
#endif
|
||||
|
||||
// printf("Finished receiving File.\n");
|
||||
}
|
||||
|
||||
|
||||
gettimeofday(&tv, &tz);
|
||||
diff_secs = tv.tv_sec - diff_secs;
|
||||
diff_usecs = tv.tv_usec - diff_usecs;
|
||||
timenormal(diff_secs,diff_usecs)
|
||||
|
||||
printf("%s, %d, %ld, %ld, %d, %d\n",r->fileName, r->iterations,
|
||||
diff_secs, diff_usecs, sock_fail,
|
||||
total_bytes_received);
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void init_threads(int numThreads, Request** rList, int numFiles) {
|
||||
int i, j;
|
||||
|
||||
ready = 0;
|
||||
|
||||
for (i=0, j=0; i < numThreads; i++, j++) {
|
||||
if (j >= numFiles) {
|
||||
j = 0;
|
||||
}
|
||||
pthread_create(malloc(sizeof(pthread_t)),NULL,makeRequest,rList[j]);
|
||||
}
|
||||
|
||||
ready = 1;
|
||||
}
|
||||
3
CS4210/Project 3/client/tests/CVS/Entries
Normal file
3
CS4210/Project 3/client/tests/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
/latency_test_proxy.xml/1.7/Tue Apr 25 02:30:55 2006//
|
||||
/throughput_test_proxy.xml/1.5/Tue Apr 25 02:30:55 2006//
|
||||
D
|
||||
2
CS4210/Project 3/client/tests/CVS/Entries.Extra
Normal file
2
CS4210/Project 3/client/tests/CVS/Entries.Extra
Normal file
@@ -0,0 +1,2 @@
|
||||
/latency_test_proxy.xml////*///
|
||||
/throughput_test_proxy.xml////*///
|
||||
3
CS4210/Project 3/client/tests/CVS/Entries.Extra.Old
Normal file
3
CS4210/Project 3/client/tests/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/latency_test_proxy.xml////*///
|
||||
/throughput_test_proxy.xml////*///
|
||||
D/adv///////
|
||||
3
CS4210/Project 3/client/tests/CVS/Entries.Old
Normal file
3
CS4210/Project 3/client/tests/CVS/Entries.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/latency_test_proxy.xml/1.7/Tue Apr 25 02:30:55 2006//
|
||||
/throughput_test_proxy.xml/1.5/Tue Apr 25 02:30:55 2006//
|
||||
D/adv////
|
||||
1
CS4210/Project 3/client/tests/CVS/Repository
Normal file
1
CS4210/Project 3/client/tests/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/client/tests
|
||||
1
CS4210/Project 3/client/tests/CVS/Root
Normal file
1
CS4210/Project 3/client/tests/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
23
CS4210/Project 3/client/tests/latency_test_proxy.xml
Normal file
23
CS4210/Project 3/client/tests/latency_test_proxy.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- XML File for test execution-->
|
||||
|
||||
<Tests>
|
||||
<simpleTest>
|
||||
<!-- The number of threads to spawn to make requests -->
|
||||
<numthreads>1</numthreads>
|
||||
|
||||
<!-- The number of times the request will be made per threads -->
|
||||
<iterations>1</iterations>
|
||||
|
||||
<!-- The files to retrieve -->
|
||||
<filesToRetrieve>
|
||||
|
||||
<!-- The file names, use / for directories -->
|
||||
<file>http://asskoala.servebeer.com/~nayupuyan/small_one.jpg</file>
|
||||
<file>http://asskoala.servebeer.com/~nayupuyan/small_two.jpg</file>
|
||||
<file>http://asskoala.servebeer.com/~nayupuyan/small_three.jpg</file>
|
||||
<file>http://asskoala.servebeer.com/~nayupuyan/small_four.jpg</file>
|
||||
|
||||
</filesToRetrieve>
|
||||
</simpleTest>
|
||||
</Tests>
|
||||
23
CS4210/Project 3/client/tests/throughput_test_proxy.xml
Normal file
23
CS4210/Project 3/client/tests/throughput_test_proxy.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- XML File for test execution-->
|
||||
|
||||
<Tests>
|
||||
<simpleTest>
|
||||
<!-- The number of threads to spawn to make requests -->
|
||||
<numthreads>12</numthreads>
|
||||
|
||||
<!-- The number of times the request will be made per threads -->
|
||||
<iterations>3</iterations>
|
||||
|
||||
<!-- The files to retrieve -->
|
||||
<filesToRetrieve>
|
||||
|
||||
<!-- The file names, use / for directories -->
|
||||
<file>http://www-static.cc.gatech.edu/~puyan/large_one.jpg</file>
|
||||
<file>http://www-static.cc.gatech.edu/~puyan/large_two.jpg</file>
|
||||
<file>http://www-static.cc.gatech.edu/~puyan/large_three.jpg</file>
|
||||
<file>http://www-static.cc.gatech.edu/~puyan/large_four.jpg</file>
|
||||
|
||||
</filesToRetrieve>
|
||||
</simpleTest>
|
||||
</Tests>
|
||||
8
CS4210/Project 3/common/CVS/Entries
Normal file
8
CS4210/Project 3/common/CVS/Entries
Normal file
@@ -0,0 +1,8 @@
|
||||
D/config_parser////
|
||||
D/http////
|
||||
D/message////
|
||||
D/networking////
|
||||
D/shared_memory////
|
||||
D/strtok_r////
|
||||
D/thread_pool////
|
||||
/defs.h/1.5/Wed Apr 19 03:53:59 2006//
|
||||
8
CS4210/Project 3/common/CVS/Entries.Extra
Normal file
8
CS4210/Project 3/common/CVS/Entries.Extra
Normal file
@@ -0,0 +1,8 @@
|
||||
D/config_parser///////
|
||||
D/http///////
|
||||
D/message///////
|
||||
D/networking///////
|
||||
D/shared_memory///////
|
||||
D/strtok_r///////
|
||||
D/thread_pool///////
|
||||
/defs.h////*///
|
||||
8
CS4210/Project 3/common/CVS/Entries.Extra.Old
Normal file
8
CS4210/Project 3/common/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,8 @@
|
||||
D/config_parser///////
|
||||
D/http///////
|
||||
D/message///////
|
||||
D/networking///////
|
||||
D/shared_memory///////
|
||||
D/strtok_r///////
|
||||
D/thread_pool///////
|
||||
/defs.h////*///
|
||||
8
CS4210/Project 3/common/CVS/Entries.Old
Normal file
8
CS4210/Project 3/common/CVS/Entries.Old
Normal file
@@ -0,0 +1,8 @@
|
||||
D/config_parser////
|
||||
D/http////
|
||||
D/message////
|
||||
D/networking////
|
||||
D/shared_memory////
|
||||
D/strtok_r////
|
||||
D/thread_pool////
|
||||
/defs.h/1.3/Sun Apr 2 10:07:02 2006//
|
||||
1
CS4210/Project 3/common/CVS/Repository
Normal file
1
CS4210/Project 3/common/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/common
|
||||
1
CS4210/Project 3/common/CVS/Root
Normal file
1
CS4210/Project 3/common/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
3
CS4210/Project 3/common/config_parser/CVS/Entries
Normal file
3
CS4210/Project 3/common/config_parser/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
/parser.c/1.3/Sun Apr 2 10:06:57 2006//
|
||||
/parser.h/1.3/Sun Apr 2 10:06:57 2006//
|
||||
D
|
||||
2
CS4210/Project 3/common/config_parser/CVS/Entries.Extra
Normal file
2
CS4210/Project 3/common/config_parser/CVS/Entries.Extra
Normal file
@@ -0,0 +1,2 @@
|
||||
/parser.c////*///
|
||||
/parser.h////*///
|
||||
@@ -0,0 +1,2 @@
|
||||
/parser.c////*///
|
||||
/parser.h////*///
|
||||
3
CS4210/Project 3/common/config_parser/CVS/Entries.Old
Normal file
3
CS4210/Project 3/common/config_parser/CVS/Entries.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/parser.c/0/dummy timestamp//
|
||||
/parser.h/0/dummy timestamp//
|
||||
D
|
||||
1
CS4210/Project 3/common/config_parser/CVS/Repository
Normal file
1
CS4210/Project 3/common/config_parser/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/common/config_parser
|
||||
1
CS4210/Project 3/common/config_parser/CVS/Root
Normal file
1
CS4210/Project 3/common/config_parser/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
85
CS4210/Project 3/common/config_parser/parser.c
Normal file
85
CS4210/Project 3/common/config_parser/parser.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "parser.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static char* getNextLine(char arr[160], FILE* stream) {
|
||||
while (fgets(arr, 160, stream)) {
|
||||
if (arr[0] == '#' || !isalnum(arr[0])) {
|
||||
continue;
|
||||
} else {
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Load fileName and return a FILE*
|
||||
*/
|
||||
ConfigFile* loadFile(char* fileName) {
|
||||
ConfigFile* newConfig = NULL;
|
||||
|
||||
newConfig = malloc(sizeof(ConfigFile));
|
||||
if (!newConfig) {
|
||||
printf("Memory Allocation Failed in _FILE_ line: _LINE_\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newConfig->file = fopen(fileName, "r");
|
||||
|
||||
if (!newConfig->file) {
|
||||
free(newConfig);
|
||||
printf("Failed to Open File in _FILE_: _LINE_\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void releaseConfig(ConfigFile** configFile) {
|
||||
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
if ((*configFile)->file) {
|
||||
fclose((*configFile)->file);
|
||||
}
|
||||
free(*configFile);
|
||||
*configFile = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int nextSet(ConfigFile* config) {
|
||||
char temp[160];
|
||||
char* pc;
|
||||
int i;
|
||||
|
||||
if (!getNextLine(temp, config->file)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pc = strtok(temp,":");
|
||||
|
||||
strncpy(config->currentParamter, pc, 80);
|
||||
|
||||
pc = strtok(NULL,":");
|
||||
|
||||
for (i=0; pc[i] != '\0'; i++) {
|
||||
if (isspace(pc[i])) {
|
||||
pc[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(config->currentValue, pc, 80);
|
||||
|
||||
return 1;
|
||||
}
|
||||
22
CS4210/Project 3/common/config_parser/parser.h
Normal file
22
CS4210/Project 3/common/config_parser/parser.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef _PARSER_H_
|
||||
#define _PARSER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct SCONFIGFILE {
|
||||
char currentParamter[80];
|
||||
char currentValue[80];
|
||||
FILE* file;
|
||||
} ConfigFile;
|
||||
|
||||
/*
|
||||
* Load a file
|
||||
*/
|
||||
ConfigFile* loadFile(char* fileName);
|
||||
void releaseConfig(ConfigFile**);
|
||||
|
||||
int nextSet(ConfigFile*);
|
||||
|
||||
#endif
|
||||
|
||||
20
CS4210/Project 3/common/defs.h
Normal file
20
CS4210/Project 3/common/defs.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef _DEFS_H_
|
||||
#define _DEFS_H_
|
||||
|
||||
#define _VERBOSE_ 0 // Print out generally useless stuff
|
||||
#define _LOG_ 0 // Print out loging output, turn off for speed
|
||||
#define VPRINTF(x) if(_VERBOSE_) printf x;
|
||||
#define BZERO(x,z) memset(x,0,z)
|
||||
|
||||
#define _THREAD_POOL_ //Whether to spwan new threads for each connection
|
||||
//or use pooling
|
||||
|
||||
#define LOCAL_GET "LOCAL_GET"
|
||||
|
||||
#define DieWithError(msg) { \
|
||||
fprintf(stderr, "%s: PwnT! Error on line %d.\n", (msg), __LINE__); \
|
||||
perror(msg); \
|
||||
exit(EXIT_FAILURE);}
|
||||
|
||||
#endif
|
||||
|
||||
3
CS4210/Project 3/common/http/CVS/Entries
Normal file
3
CS4210/Project 3/common/http/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
/http.c/1.3/Sun Apr 2 10:06:57 2006//
|
||||
/http.h/1.3/Sun Apr 2 10:06:57 2006//
|
||||
D
|
||||
2
CS4210/Project 3/common/http/CVS/Entries.Extra
Normal file
2
CS4210/Project 3/common/http/CVS/Entries.Extra
Normal file
@@ -0,0 +1,2 @@
|
||||
/http.c////*///
|
||||
/http.h////*///
|
||||
2
CS4210/Project 3/common/http/CVS/Entries.Extra.Old
Normal file
2
CS4210/Project 3/common/http/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,2 @@
|
||||
/http.c////*///
|
||||
/http.h////*///
|
||||
3
CS4210/Project 3/common/http/CVS/Entries.Old
Normal file
3
CS4210/Project 3/common/http/CVS/Entries.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/http.c/0/dummy timestamp//
|
||||
/http.h/0/dummy timestamp//
|
||||
D
|
||||
1
CS4210/Project 3/common/http/CVS/Repository
Normal file
1
CS4210/Project 3/common/http/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/common/http
|
||||
1
CS4210/Project 3/common/http/CVS/Root
Normal file
1
CS4210/Project 3/common/http/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
419
CS4210/Project 3/common/http/http.c
Normal file
419
CS4210/Project 3/common/http/http.c
Normal file
@@ -0,0 +1,419 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include "http.h"
|
||||
#include "../defs.h"
|
||||
|
||||
#define SERVER_NAME "ubermicro_httpd"
|
||||
#define SERVER_URL "http://www.puyan.org"
|
||||
#define PROTOCOL "HTTP/1.1"
|
||||
#define RFC1123FMT "%a, %d %b %Y %H:%M:%S GMT"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define S_ISDIR(a) (a & S_IFDIR)
|
||||
char lower(const char a);
|
||||
int strcasecmp(const char *s1, const char *s2);
|
||||
#endif
|
||||
|
||||
static void file_details( char* dir, char* name , FILE *socket_file);
|
||||
static void send_error( int status, char* title, char* extra_header, char* text, FILE *socket_file );
|
||||
static void send_headers( int status, char* title, char* extra_header, char* mime_type, off_t length, time_t mod, FILE *socket_file );
|
||||
static char* get_mime_type( char* name );
|
||||
static void strdecode( char* to, char* from );
|
||||
static int hexit( char c );
|
||||
static void strencode( char* to, size_t tosize, const char* from );
|
||||
|
||||
int parse_request(char *request, http_request *package) {
|
||||
if ( sscanf(request, "%[^ ] %[^ ] %[^ ]", package->method, package->path, package->protocol ) != 3 ) {
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
return EXIT_FAILURE; // Never Reached
|
||||
}
|
||||
|
||||
void http_proto(int socket, char *request) {
|
||||
char idx[2000], location[2000];
|
||||
char *method, *path, *protocol;
|
||||
char* file;
|
||||
size_t len;
|
||||
int ich;
|
||||
struct stat sb;
|
||||
FILE* fp;
|
||||
FILE* socket_file;
|
||||
struct dirent **dl;
|
||||
int i, n;
|
||||
char *brkt;
|
||||
char *true_request;
|
||||
http_request request_package;
|
||||
|
||||
VPRINTF(("\n\nStart http proc\n"));
|
||||
|
||||
VPRINTF(("Full Request:\n%s\n", request));
|
||||
|
||||
true_request=strtok_r(request,"\r", &brkt);
|
||||
|
||||
VPRINTF(("Request size: %d\n", strlen(request)));
|
||||
VPRINTF(("Small Request: \n%s\n", true_request));
|
||||
VPRINTF(("1 error on line %d\n", __LINE__));
|
||||
|
||||
socket_file = fdopen(socket, "w");
|
||||
fflush( socket_file ); //FIXME: May not be necessary, nothing written yet
|
||||
|
||||
if(strlen(request) >= BUFFERSIZE) {
|
||||
send_error( 403, "Bad Request", (char*) 0, "No request found." , socket_file );
|
||||
goto complete;
|
||||
}
|
||||
|
||||
if (EXIT_FAILURE == parse_request(request, &request_package)) {
|
||||
send_error( 400, "Bad Request", (char*) 0, "Can't parse request." , socket_file );
|
||||
goto complete;
|
||||
} else {
|
||||
method = request_package.method;
|
||||
path = request_package.path;
|
||||
protocol = request_package.protocol;
|
||||
}
|
||||
|
||||
VPRINTF(("Method: %s\n", method));
|
||||
VPRINTF(("Path: %s\n", path));
|
||||
VPRINTF(("Protocol: %s\n", protocol));
|
||||
VPRINTF(("2 error on line %d\n", __LINE__));
|
||||
|
||||
if ( strcasecmp( method, "get" ) != 0 ) {
|
||||
send_error( 501, "Not Implemented", (char*) 0, "That method is not implemented." , socket_file );
|
||||
goto complete;
|
||||
}
|
||||
|
||||
VPRINTF(("3 error on line %d\n", __LINE__));
|
||||
|
||||
if ( path[0] != '/' ) {
|
||||
send_error( 400, "Bad Request", (char*) 0, "Bad filename." , socket_file );
|
||||
goto complete;
|
||||
}
|
||||
|
||||
file = &(path[1]);
|
||||
strdecode( file, file );
|
||||
|
||||
if ( file[0] == '\0' ) {
|
||||
file = "./";
|
||||
}
|
||||
|
||||
len = strlen( file );
|
||||
|
||||
VPRINTF(("4 error on line %d\n", __LINE__));
|
||||
|
||||
if ( file[0] == '/'
|
||||
|| strcmp( file, ".." ) == 0
|
||||
|| strncmp( file, "../", 3 ) == 0
|
||||
|| strstr( file, "/../" ) != (char*) 0
|
||||
|| strcmp( &(file[len-3]), "/.." ) == 0 )
|
||||
{
|
||||
send_error( 400, "Bad Request", (char*) 0, "Illegal filename." , socket_file );
|
||||
goto complete;
|
||||
}
|
||||
|
||||
if ( stat( file, &sb ) < 0 ) {
|
||||
send_error( 404, "Not Found", (char*) 0, "File not found." , socket_file );
|
||||
goto complete;
|
||||
}
|
||||
|
||||
if ( S_ISDIR( sb.st_mode ) ) {
|
||||
if ( file[len-1] != '/' ) {
|
||||
snprintf(location, sizeof(location), "Location: %s/", path );
|
||||
send_error( 302, "Found", location, "Directories must end with a slash." , socket_file );
|
||||
goto complete;
|
||||
}
|
||||
|
||||
snprintf( idx, sizeof(idx), "%sindex.html", file );
|
||||
|
||||
if ( stat( idx, &sb ) >= 0 )
|
||||
{
|
||||
file = idx;
|
||||
goto do_file; //asshole
|
||||
}
|
||||
|
||||
/* IMPORTANT */
|
||||
send_headers( 200, "Ok", (char*) 0, "text/html", -1, sb.st_mtime , socket_file );
|
||||
|
||||
fprintf(socket_file,
|
||||
"<html><head><title>Index of %s</title></head>\n<body bgcolor=\"lightblue\"><h4>Index of %s</h4>\n<pre>\n",
|
||||
file, file
|
||||
);
|
||||
|
||||
n = scandir( file, &dl, NULL, alphasort ); /* IMPORTANT */
|
||||
|
||||
if ( n < 0 ) {
|
||||
perror( "scandir" );
|
||||
} else {
|
||||
for ( i = 0; i < n; ++i ) {
|
||||
/* IMPORTANT */
|
||||
file_details( file, dl[i]->d_name, socket_file );
|
||||
free(dl[i]);
|
||||
/* the guy that wrote this was a n00b */
|
||||
}
|
||||
free(dl); /* Must kill this guy */
|
||||
}
|
||||
|
||||
|
||||
fprintf(socket_file,
|
||||
"</pre>\n<hr>\n<address><a href=\"%s\">%s</a></address>\n</body></html>\n",
|
||||
SERVER_URL, SERVER_NAME
|
||||
);
|
||||
} else {
|
||||
do_file:
|
||||
fp = fopen( file, "r" );
|
||||
|
||||
if ( fp == (FILE*) 0 ) {
|
||||
send_error( 403, "Forbidden", (char*) 0, "File is protected.", socket_file );
|
||||
goto complete;
|
||||
}
|
||||
|
||||
/* IMPORTANT */
|
||||
send_headers( 200, "Ok", (char*) 0, get_mime_type( file ), sb.st_size, sb.st_mtime , socket_file );
|
||||
|
||||
while (fp && ( ich = getc( fp ) ) != EOF ) {
|
||||
fprintf(socket_file,"%c", ich );
|
||||
}
|
||||
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
|
||||
complete: //because this guy wrote terrible code, goto is necessary
|
||||
|
||||
fflush( socket_file );
|
||||
|
||||
fclose(socket_file);
|
||||
}
|
||||
|
||||
|
||||
static void file_details( char* dir, char* name, FILE *socket_file )
|
||||
{
|
||||
static char encoded_name[1000];
|
||||
static char path[2000];
|
||||
struct stat sb;
|
||||
char timestr[16];
|
||||
|
||||
strencode( encoded_name, sizeof(encoded_name), name );
|
||||
snprintf( path, sizeof(path), "%s/%s", dir, name );
|
||||
|
||||
#ifdef _WIN32
|
||||
if ( stat( path, &sb ) < 0 ) {
|
||||
#else
|
||||
if ( lstat( path, &sb ) < 0 ) {
|
||||
#endif
|
||||
fprintf(socket_file, "<a href=\"%s\">%-32.32s</a> ???\n", encoded_name, name );
|
||||
} else {
|
||||
strftime(timestr, sizeof(timestr),
|
||||
"%d%b%Y %H:%M", localtime( &sb.st_mtime )
|
||||
);
|
||||
fprintf(socket_file,
|
||||
"<a href=\"%s\">%-32.32s</a> %15s %14lld\n", encoded_name,
|
||||
name, timestr, (int64_t) sb.st_size
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void send_error( int status, char* title, char* extra_header, char* text, FILE *socket_file )
|
||||
{
|
||||
send_headers( status, title, extra_header, "text/html", -1, -1, socket_file );
|
||||
|
||||
fprintf(socket_file,
|
||||
"<html><head><title>%d %s</title></head>\n<body bgcolor=\"#cc9999\"><h4>%d %s</h4>\n",
|
||||
status, title, status, title
|
||||
);
|
||||
|
||||
fprintf(socket_file, "%s\n", text );
|
||||
fprintf(socket_file, "<hr>\n<address><a href=\"%s\">%s</a></address>\n", SERVER_URL, SERVER_NAME);
|
||||
//fprintf(socket_file, "<img src=\"/pwner.jpg\">\n");
|
||||
fprintf(socket_file, "</body></html>\n");
|
||||
|
||||
fflush( socket_file ); //flush socket
|
||||
}
|
||||
|
||||
|
||||
static void send_headers( int status, char* title, char* extra_header, char* mime_type, off_t length, time_t mod , FILE *socket_file)
|
||||
{
|
||||
time_t now;
|
||||
char timebuf[100];
|
||||
|
||||
fprintf(socket_file, "%s %d %s\015\012", PROTOCOL, status, title );
|
||||
fprintf(socket_file, "Server: %s\015\012", SERVER_NAME );
|
||||
|
||||
now = time( (time_t*) 0 );
|
||||
|
||||
strftime( timebuf, sizeof(timebuf), RFC1123FMT, gmtime( &now ) );
|
||||
fprintf(socket_file, "Date: %s\015\012", timebuf );
|
||||
|
||||
if ( extra_header != (char*) 0 ) {
|
||||
fprintf(socket_file, "%s\015\012", extra_header );
|
||||
}
|
||||
if ( mime_type != (char*) 0 ) {
|
||||
fprintf(socket_file, "Content-Type: %s\015\012", mime_type );
|
||||
}
|
||||
if ( length >= 0 ) {
|
||||
fprintf(socket_file, "Content-Length: %lld\015\012", (int64_t) length );
|
||||
}
|
||||
if ( mod != (time_t) -1 )
|
||||
{
|
||||
strftime( timebuf, sizeof(timebuf), RFC1123FMT, gmtime( &mod ) );
|
||||
fprintf(socket_file, "Last-Modified: %s\015\012", timebuf );
|
||||
}
|
||||
fprintf(socket_file, "Connection: close\015\012" );
|
||||
fprintf(socket_file, "\015\012" );
|
||||
}
|
||||
|
||||
|
||||
static char* get_mime_type( char* name )
|
||||
{
|
||||
char* dot;
|
||||
|
||||
dot = strrchr( name, '.' );
|
||||
|
||||
if ( dot == (char*) 0 )
|
||||
return "text/plain; charset=iso-8859-1";
|
||||
|
||||
if ( strcmp( dot, ".html" ) == 0 || strcmp( dot, ".htm" ) == 0 )
|
||||
return "text/html; charset=iso-8859-1";
|
||||
|
||||
if ( strcmp( dot, ".jpg" ) == 0 || strcmp( dot, ".jpeg" ) == 0 )
|
||||
return "image/jpeg";
|
||||
|
||||
if ( strcmp( dot, ".gif" ) == 0 )
|
||||
return "image/gif";
|
||||
|
||||
if ( strcmp( dot, ".png" ) == 0 )
|
||||
return "image/png";
|
||||
|
||||
if ( strcmp( dot, ".css" ) == 0 )
|
||||
return "text/css";
|
||||
|
||||
if ( strcmp( dot, ".au" ) == 0 )
|
||||
return "audio/basic";
|
||||
|
||||
if ( strcmp( dot, ".wav" ) == 0 )
|
||||
return "audio/wav";
|
||||
|
||||
if ( strcmp( dot, ".avi" ) == 0 )
|
||||
return "video/x-msvideo";
|
||||
|
||||
if ( strcmp( dot, ".mov" ) == 0 || strcmp( dot, ".qt" ) == 0 )
|
||||
return "video/quicktime";
|
||||
|
||||
if ( strcmp( dot, ".mpeg" ) == 0 || strcmp( dot, ".mpe" ) == 0 )
|
||||
return "video/mpeg";
|
||||
|
||||
if ( strcmp( dot, ".vrml" ) == 0 || strcmp( dot, ".wrl" ) == 0 )
|
||||
return "model/vrml";
|
||||
|
||||
if ( strcmp( dot, ".midi" ) == 0 || strcmp( dot, ".mid" ) == 0 )
|
||||
return "audio/midi";
|
||||
|
||||
if ( strcmp( dot, ".mp3" ) == 0 )
|
||||
return "audio/mpeg";
|
||||
|
||||
if ( strcmp( dot, ".m4a" ) == 0 )
|
||||
return "audio/mp4";
|
||||
|
||||
if ( strcmp( dot, ".pdf" ) == 0 )
|
||||
return "application/pdf";
|
||||
|
||||
if ( strcmp( dot, ".ogg" ) == 0 )
|
||||
return "application/ogg";
|
||||
|
||||
if ( strcmp( dot, ".pac" ) == 0 )
|
||||
return "application/x-ns-proxy-autoconfig";
|
||||
|
||||
return "text/plain; charset=iso-8859-1";
|
||||
}
|
||||
|
||||
|
||||
static void strdecode( char* to, char* from )
|
||||
{
|
||||
for ( ; *from != '\0'; ++to, ++from )
|
||||
{
|
||||
if ( from[0] == '%' && isxdigit( from[1] ) && isxdigit( from[2] ) )
|
||||
{
|
||||
*to = hexit( from[1] ) * 16 + hexit( from[2] );
|
||||
from += 2;
|
||||
}
|
||||
else
|
||||
*to = *from;
|
||||
}
|
||||
*to = '\0';
|
||||
}
|
||||
|
||||
|
||||
static int hexit( char c )
|
||||
{
|
||||
if ( c >= '0' && c <= '9' )
|
||||
return c - '0';
|
||||
|
||||
if ( c >= 'a' && c <= 'f' )
|
||||
return c - 'a' + 10;
|
||||
|
||||
if ( c >= 'A' && c <= 'F' )
|
||||
return c - 'A' + 10;
|
||||
|
||||
//default
|
||||
return 0; /* shouldn't happen, we're guarded by isxdigit() */
|
||||
}
|
||||
|
||||
|
||||
static void strencode( char* to, size_t tosize, const char* from )
|
||||
{
|
||||
int tolen;
|
||||
|
||||
for ( tolen = 0; *from != '\0' && tolen + 4 < tosize; ++from )
|
||||
{
|
||||
if ( isalnum(*from) || strchr( "/_.-~", *from ) != (char*) 0 )
|
||||
{
|
||||
*to = *from;
|
||||
++to;
|
||||
++tolen;
|
||||
} else {
|
||||
sprintf( to, "%%%02x", (int) *from & 0xff );
|
||||
to += 3;
|
||||
tolen += 3;
|
||||
}
|
||||
}
|
||||
|
||||
*to = '\0';
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
char lower(const char a) {
|
||||
if (!isalpha(a)) return a;
|
||||
|
||||
if (!(a < 'z' && a > 'a')) {
|
||||
return a+32;
|
||||
} else {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
/* strcasecmp is not ANSI */
|
||||
int strcasecmp(const char *s1, const char *s2){
|
||||
size_t i;
|
||||
|
||||
for(i=0;; i++){
|
||||
if(!(lower(*(s1+i)) == lower(*(s2+i)) ) ) {
|
||||
return *(s1+i) - *(s2+i);
|
||||
}
|
||||
if(*(s1+i) == '\0'){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
25
CS4210/Project 3/common/http/http.h
Normal file
25
CS4210/Project 3/common/http/http.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <sys/types.h>
|
||||
#define BUFFERSIZE 1024 /* max size for recv buffer */
|
||||
#define LOOP_BOUNDS 2 // Tolerance of the recv() loop.
|
||||
|
||||
typedef struct _http_request {
|
||||
char method[10];
|
||||
char path[BUFFERSIZE];
|
||||
char protocol[15];
|
||||
} http_request;
|
||||
|
||||
|
||||
/* Forwards. */
|
||||
/* Note to Puyan: you do not declare static functions in the header file, kkthx */
|
||||
/*static void file_details( char* dir, char* name , FILE *socket_file);
|
||||
static void send_error( int status, char* title, char* extra_header, char* text, FILE *socket_file );
|
||||
static void send_headers( int status, char* title, char* extra_header, char* mime_type, off_t length, time_t mod, FILE *socket_file );
|
||||
static char* get_mime_type( char* name );
|
||||
static void strdecode( char* to, char* from );
|
||||
static int hexit( char c );
|
||||
static void strencode( char* to, size_t tosize, const char* from );*/
|
||||
|
||||
|
||||
void http_proto(int socket, char *request);
|
||||
int parse_request(char *request, http_request *package);
|
||||
|
||||
3
CS4210/Project 3/common/message/CVS/Entries
Normal file
3
CS4210/Project 3/common/message/CVS/Entries
Normal file
@@ -0,0 +1,3 @@
|
||||
/message.c/1.3/Sun Apr 2 10:06:57 2006//
|
||||
/message.h/1.3/Sun Apr 2 10:06:57 2006//
|
||||
D
|
||||
2
CS4210/Project 3/common/message/CVS/Entries.Extra
Normal file
2
CS4210/Project 3/common/message/CVS/Entries.Extra
Normal file
@@ -0,0 +1,2 @@
|
||||
/message.c////*///
|
||||
/message.h////*///
|
||||
2
CS4210/Project 3/common/message/CVS/Entries.Extra.Old
Normal file
2
CS4210/Project 3/common/message/CVS/Entries.Extra.Old
Normal file
@@ -0,0 +1,2 @@
|
||||
/message.c////*///
|
||||
/message.h////*///
|
||||
3
CS4210/Project 3/common/message/CVS/Entries.Old
Normal file
3
CS4210/Project 3/common/message/CVS/Entries.Old
Normal file
@@ -0,0 +1,3 @@
|
||||
/message.c/0/dummy timestamp//
|
||||
/message.h/0/dummy timestamp//
|
||||
D
|
||||
1
CS4210/Project 3/common/message/CVS/Repository
Normal file
1
CS4210/Project 3/common/message/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
CS4210/Project 3/common/message
|
||||
1
CS4210/Project 3/common/message/CVS/Root
Normal file
1
CS4210/Project 3/common/message/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:ext:asskoala@192.168.0.3:/usr/_CVS
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user