From c1e0d782ed0e1abed028122e08a8adde09edbcd4 Mon Sep 17 00:00:00 2001 From: solusipse Date: Fri, 6 Sep 2013 04:42:52 +0200 Subject: [PATCH] added header --- fiche.c | 31 +++++++++++++++++++++++++------ fiche.h | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/fiche.c b/fiche.c index e7c3f5e..23758da 100755 --- a/fiche.c +++ b/fiche.c @@ -1,6 +1,26 @@ /* -Fiche - terminal pastebin -Still in development, not usable! +Fiche - Command line pastebin for sharing terminal output. + +------------------------------------------------------------------------------- + +License: MIT (http://www.opensource.org/licenses/mit-license.php) +Repository: https://github.com/solusipse/fiche/ +Live example: http://code.solusipse.net/ + +------------------------------------------------------------------------------- + +usage: fiche [-bdpqs]. + [-d host_domain.com] [-p port] [-s slug_size] + [-o output_directory] [-b buffer_size] [-q queue_size] + +Compile with Makefile or manually with -O2 and -pthread flags. +To install use `make install` command. + +Use netcat to push text - example: + +$ cat fiche.c | nc localhost 9999 + +------------------------------------------------------------------------------- */ #include "fiche.h" @@ -136,8 +156,7 @@ void bind_to_port(int listen_socket, struct sockaddr_in server_address) void generate_url(char *buffer, char *slug) { - int i; - int time_seed = time(0); + int i, time_seed = time(0); memset(slug, '\0', sizeof(slug)); for (i = 0; i <= SLUG_SIZE - 1; i++) @@ -148,7 +167,7 @@ void generate_url(char *buffer, char *slug) while (create_directory(slug) == -1) { - int symbol_id = rand() % strlen(symbols); + int symbol_id = rand_r(&time_seed) % strlen(symbols); slug[strlen(slug)] = symbols[symbol_id]; } @@ -157,7 +176,7 @@ void generate_url(char *buffer, char *slug) int create_directory(char *slug) { - char *directory = malloc(100); + char *directory = malloc(strlen(BASEDIR) + strlen(slug)); strcpy(directory, BASEDIR); strcat(directory, slug); diff --git a/fiche.h b/fiche.h index c83de63..15613f4 100644 --- a/fiche.h +++ b/fiche.h @@ -1,28 +1,49 @@ /* -Fiche - terminal pastebin +Fiche - Command line pastebin for sharing terminal output. + +------------------------------------------------------------------------------- + +License: MIT (http://www.opensource.org/licenses/mit-license.php) +Repository: https://github.com/solusipse/fiche/ +Live example: http://code.solusipse.net/ + +------------------------------------------------------------------------------- + +usage: fiche [-bdpqs]. + [-d host_domain.com] [-p port] [-s slug_size] + [-o output_directory] [-b buffer_size] [-q queue_size] + +Compile with Makefile or manually with -O2 and -pthread flags. +To install use `make install` command. + +Use netcat to push text - example: + +$ cat fiche.c | nc localhost 9999 + +------------------------------------------------------------------------------- */ #ifndef FICHE_H #define FICHE_H +#include +#include #include #include #include #include -#include -#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -int BUFSIZE = 8192; -int QUEUE_SIZE = 100; +char *BASEDIR; int PORT = 9999; int SLUG_SIZE = 4; -char *BASEDIR; +int BUFSIZE = 8192; +int QUEUE_SIZE = 100; char DOMAIN[128] = "http://localhost/"; const char *symbols = "abcdefghijklmnopqrstuvwxyz0123456789";