From b457fec36399c1f7de093d5e92bb4fa453b79c86 Mon Sep 17 00:00:00 2001 From: Jakub Sławiński Date: Sun, 5 Feb 2006 15:14:03 +0100 Subject: v0.8 - Fixed: infinite loop after buffering message - Fixed: corrupt packets after closing connections in the stopped state - Fixed: bug in mapping user numbers between afclient and afserver - Fixed: premature close of the service connection - Fixed: invalid buffering when the connection is closing - Added: Multiple tunnels in one afclient<->afserver connection --- src/http_proxy_functions.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'src/http_proxy_functions.c') diff --git a/src/http_proxy_functions.c b/src/http_proxy_functions.c index be8f402..495d7d8 100644 --- a/src/http_proxy_functions.c +++ b/src/http_proxy_functions.c @@ -27,6 +27,17 @@ static char isseed; +/* + * Function name: myrand + * Description: Returns the pseudo-random number from the given range. + * If the lower and upper bounds are the same, the pseudo-random + * number is returned from the range (-RAND_MAX, -RAND_MAX+down) + * or (down, RAND_MAX). + * Arguments: down - the lower bound of the range + * up - the upper bound of the range + * Returns: The pseudo-random number from the given range. + */ + int myrand(int down, int up) { @@ -39,6 +50,12 @@ myrand(int down, int up) return ( down + ( rand() % (up - down + 1) ) ); } +/* + * Function name: mysleep + * Description: Sleeps for the given amount of milliseconds. + * Arguments: time - the amount of milliseconds to sleep for + */ + void mysleep(double time) { @@ -48,6 +65,14 @@ mysleep(double time) select(0, NULL, NULL, NULL, &tv); } +/* + * Function name: delete_user + * Description: Deletes the user's connection from the http proxy connections. + * Arguments: cnts - the connection to remove + * i - the user's number + * allset - the set of file descriptors + */ + void delete_user(connection* cnts, int i, fd_set* allset) { @@ -65,6 +90,17 @@ delete_user(connection* cnts, int i, fd_set* allset) cnts[i].type = 0; } +/* + * Function name: parse_header + * Description: Reads and parses the http header. + * Arguments: sf - the pointer to SslFd structure + * tab - the buffer used for reading the data + * hdr - the pointer to header structure + * https - the flag indicating if the connection is http/https + * Returns: 0 - success, + * 1 - failure. + */ + int parse_header(SslFd* sf, char* tab, header* hdr, char https) { @@ -187,6 +223,14 @@ parse_header(SslFd* sf, char* tab, header* hdr, char https) return 1; } +/* + * Function name: set_fd + * Description: Starts watching the file descriptor. + * Arguments: fd - the file descriptor + * maxfdp1 - the upper limit of the file descriptor numbers + * allset - the set of file descriptors + */ + void set_fd(int fd, int* maxfdp1, fd_set* allset) { @@ -194,12 +238,25 @@ set_fd(int fd, int* maxfdp1, fd_set* allset) (*maxfdp1) = ((*maxfdp1) > fd) ? (*maxfdp1) : (fd + 1); } +/* + * Function name: close_fd + * Description: Closes the file descriptor. + * Arguments: fd - the file descriptor to close + */ + void close_fd(int* fd) { close(*fd); } +/* + * Function name: clear_fd + * Description: Removes the file descriptor from the set and closes it. + * Arguments: fd - the file descriptor to remove and close + * set - the set of file descriptors + */ + void clear_fd(int* fd, fd_set* set) { @@ -207,6 +264,19 @@ clear_fd(int* fd, fd_set* set) close_fd(fd); } +/* + * Function name: read_message + * Description: Reads the message from the http proxy connection and writes it + * to the file descriptor. + * Arguments: fd - the file descriptor + * length - the length of the buffer + * client - the http proxy connection + * tab - the buffer with the readed data + * ptr - the offset from which the data reading will start + * Returns: 0 - success, + * 1 - failure. + */ + int read_message(int fd, int length, connection* client, char* tab, int ptr) { -- cgit v1.1