[axel-commits] r73 - in /branches/3.x-broken: doc/CHANGES src/axel.c src/axel.h src/conn.c src/conn.h src/helper.c src/helper.h src/libs.h src/messages.c src/messages.h
phihag-guest at users.alioth.debian.org
phihag-guest at users.alioth.debian.org
Mon Dec 29 11:55:57 UTC 2008
Author: phihag-guest
Date: Mon Dec 29 11:55:56 2008
New Revision: 73
URL: http://svn.debian.org/wsvn/axel/?sc=1&rev=73
Log:
- Moved includes of standard libraries to libs.h to reduce size of axel.h
- Use AXEL_SIZE for all file size variables
Added:
branches/3.x-broken/src/libs.h
branches/3.x-broken/src/messages.c
branches/3.x-broken/src/messages.h
Modified:
branches/3.x-broken/doc/CHANGES
branches/3.x-broken/src/axel.c
branches/3.x-broken/src/axel.h
branches/3.x-broken/src/conn.c
branches/3.x-broken/src/conn.h
branches/3.x-broken/src/helper.c
branches/3.x-broken/src/helper.h
Modified: branches/3.x-broken/doc/CHANGES
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/doc/CHANGES?rev=73&op=diff
==============================================================================
--- branches/3.x-broken/doc/CHANGES (original)
+++ branches/3.x-broken/doc/CHANGES Mon Dec 29 11:55:56 2008
@@ -3,7 +3,8 @@
- Complete overhaul of the whole code structure
- New folder structure: src/ contains all *.c and *.h files, test/ CUnit test files, all compiled files reside in out/, all configured files in cfg/
- Default protocol is now HTTP
-- if_t, url_t, message_t removed from axel.h (replaced by aptly named types)
+- if_t, url_tremoved from axel.h (replaced by aptly named types)
+- message_t incorporates a priority
- new url.* files for working with URLs, new url_t representing a URL (from conn.*, http.*)
- new proto.* files for protocol IDs and protocol detection (from conn.*)
- new helper.* files for axel-independent helper macros and functions (from axel.h)
@@ -17,6 +18,8 @@
- C99 compatible, gcc checks C99 compatibility level now
- Removed double usage in favor of a single warning if NOGETOPTLONG is defined
- Splitted usage text (=> simplifies i18n)
+- Moved includes of standard libraries to libs.h to reduce size of axel.h
+- Use AXEL_SIZE for all file size variables
- Temporarily thrown out: ftp, search
Modified: branches/3.x-broken/src/axel.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/axel.c?rev=73&op=diff
==============================================================================
--- branches/3.x-broken/src/axel.c (original)
+++ branches/3.x-broken/src/axel.c Mon Dec 29 11:55:56 2008
@@ -73,6 +73,9 @@
ax->state = AXEL_STATE_INIT;
ax->delay_time = 0;
+
+ pthread_mutex_init(ax->msgmtx);
+ messageq_init(ax->msgs);
}
void axel_destroy(axel_t* axel) {
@@ -80,6 +83,9 @@
free(axel->filename);
free(axel->statefilename);
+
+ pthread_mutex_destroy(msgmtx);
+ messaq_destroy(ax->msgs);
}
/**
@@ -139,8 +145,8 @@
axel->start_utime = getutime();
axel_set_state(axel, AXEL_STATE_DOWNLOADING);
+ // TODO set conncount according to conf
// TODO start threads
- // TODO set conncount according to conf
}
/**
@@ -154,27 +160,44 @@
}
/**
+* Send a message from the main thread
* @param message The message to send. Note that this must be freed by the caller
*/
-void axel_message(const axel_t* axel, int verbosity, const char* message) {
- if (axel->message_handler != NULL) {
- axel->message_handler(axel, verbosity, message);
- }
- axel_update_display();
+void axel_message(const axel_t* axel, message_t* msg) {
+ message_t* msg = safe_malloc(sizeof(message_t));
+
+ msg->
+
+ axel_message(axel, msg);
+}
+
+/**
+* @param message The message, will be freed by this method
+*/
+void axel_message_detail(const axel_t* axel, int verbosity, char* message, _Bool msgOnHeap) {
+
}
void axel_message_fmt(const axel_t *axel, int verbosity, const char *format, ...) {
const MAX_MSG_SIZE = 1024;
- char* buf = alloca(MAX_MSG_SIZE);
+ char* buf = malloc(MAX_MSG_SIZE);
va_list params;
va_start(params, format);
vsnprintf(buf, MAX_MSG_SIZE, format, params );
va_end(params);
- axel_message(axel, verbosity, buf);
-
- free(buf);
+ axel_message_heap(axel, verbosity, buf);
+}
+
+/**
+* Display a message. Must only be called from the main thread.
+*/
+void axel_message(const axel_t* axel, const axel_message_t* msg) {
+ if (axel->message_handler != NULL) {
+ axel->message_handler(axel, msg->verbosity, msg->message);
+ }
+ axel_update_display();
}
static void axel_update_display(const axel_t* axel) {
@@ -188,9 +211,6 @@
axel_update_display();
}
-void axel_save_state(axel_t* axel) {
- // TODO copy stuff from save_state, sanitize
-}
Modified: branches/3.x-broken/src/axel.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/axel.h?rev=73&op=diff
==============================================================================
--- branches/3.x-broken/src/axel.h (original)
+++ branches/3.x-broken/src/axel.h Mon Dec 29 11:55:56 2008
@@ -25,49 +25,15 @@
#include "../cfg/config.h"
-#include <time.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include <netdb.h>
-#ifndef NOGETOPTLONG
-#define _GNU_SOURCE
-#include <getopt.h>
-#endif
-#include <limits.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <pthread.h>
+// Include system libraries
+#include "libs.h"
-/* Internationalization */
-#ifdef I18N
-#define PACKAGE "axel"
-#define _( x ) gettext( x )
-#include <libintl.h>
-#include <locale.h>
-#else
-#define _( x ) x
-#endif
-
-/* Compiled-in settings */
+// Compiled-in settings
#define MAX_REDIR 5
#define AXEL_VERSION_STRING "3.0_rc1"
#define DEFAULT_USER_AGENT "Axel " AXEL_VERSION_STRING " (" ARCH ")"
#define STATEFILE_SUFFIX ".st"
+#define AXEL_FILESIZE long long int
#include "helper.h"
#include "url.h"
@@ -79,11 +45,6 @@
#include "conn.h"
#include "search.h"
#include "urllist.h"
-
-// Message relevance
-#define VERBOSITY_VERBOSE 2
-#define VERBOSITY_NORMAL 1
-#define VERBOSITY_QUIET 0
// Emergency error codes
#define AXEL_EXIT_MALLOC_FAIL 91
@@ -153,14 +114,18 @@
char* statefilename; // Name of the state file, NULL for no state file
- long long size; // The full file size in Byte, or AXEL_SIZE_UNDETERMINED if the file size is not yet determined or undeterminable
- axel_time start_utime; // Start time in microseconds
+ AXEL_FILESIZE size; // The full file size in Byte, or AXEL_SIZE_UNDETERMINED if the file size is not yet determined or undeterminable
+ AXEL_TIME start_utime; // Start time in microseconds
// The download's state, one of the AXEL_STATE_* constants
int state;
// Time to wait because of speed limit.
int delay_time;
+
+ // Messages
+ message_queue_t msgs[1];
+ pthread_mutex_t msgmtx[1];
};
typedef struct axel_struct axel_t;
@@ -173,3 +138,4 @@
// These functions are only called from axel's core
void axel_message(const axel_t* axel, int verbosity, const char* message);
void axel_message_fmt(const axel_t *axel, int verbosity, const char *format, ... );
+void axel_message_heap(const axel_t* axel, int verbosity, const char* message);
Modified: branches/3.x-broken/src/conn.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/conn.c?rev=73&op=diff
==============================================================================
--- branches/3.x-broken/src/conn.c (original)
+++ branches/3.x-broken/src/conn.c Mon Dec 29 11:55:56 2008
@@ -27,7 +27,7 @@
static void conn_start_threadstart(void* conn);
-void conn_init(conn_t *c, const url_t* url, const conf_t* conf, long long startbyte, long long endbyte) {
+void conn_init(conn_t *c, const url_t* url, const axel_t* axel, AXEL_SIZE startbyte, AXEL_SIZE endbyte) {
c->conf = conf;
c->url = url;
@@ -37,18 +37,18 @@
c->cstate = INITIALIZED;
}
+// Start a new thread.
_Bool conn_start(conn_t* c) {
if (pthread_create(conn->thread, NULL, conn_threadstart, c) != 0) {
- conn->message = _("Thread creation failed");
+ axel_message(conn->axel, _("Thread creation failed"));
return false;
}
-
+ return true;
}
// Entry point for the created thread
void conn_threadstart(void* conn_void) {
- conn_t* conn = conn_void;
int oldstate; // Dummy
if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate) != 0) ||
@@ -59,7 +59,7 @@
return;
}
-
+ conn_readheaders((conn_t*) conn_void);
}
// Reads all headers, blocks until read. cstate is guaranteed to be either DOWNLOADING or FINISHED afterwards.
Modified: branches/3.x-broken/src/conn.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/conn.h?rev=73&op=diff
==============================================================================
--- branches/3.x-broken/src/conn.h (original)
+++ branches/3.x-broken/src/conn.h Mon Dec 29 11:55:56 2008
@@ -34,13 +34,13 @@
};
typedef struct {
- const conf_t *conf;
+ const axel_t *axel;
const url_t* url; /* The URL to download from. Not owned by this struct */
proto_t[1] proto;
- long long currentbyte; // The index of the byte we're currently reading, starting with zero.
- long long lastbyte; // The zero-based index of the last byte we should read. CONNB_UNKWOWN if everything should be read.
+ AXEL_SIZE currentbyte; // The index of the byte we're currently reading, starting with zero.
+ AXEL_SIZE lastbyte; // The zero-based index of the last byte we should read. CONNB_UNKWOWN if everything should be read.
volatile connstate cstate;
@@ -55,7 +55,7 @@
pthread_t[1] thread;
} conn_t;
-void conn_init(conn_t *conn, const url_t* url, const conf_t* conf, long long startbyte, long long endbyte);
+void conn_init(conn_t *conn, const url_t* url, const axel_t* axel, AXEL_SIZE startbyte, AXEL_SIZE endbyte);
// Start a thread that initiates downloading
void conn_start(conn_t* conn);
// Reads all headers, blocks until read. cstate is guaranteed to be either DOWNLOADING or FINISHED afterwards.
Modified: branches/3.x-broken/src/helper.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/helper.c?rev=73&op=diff
==============================================================================
--- branches/3.x-broken/src/helper.c (original)
+++ branches/3.x-broken/src/helper.c Mon Dec 29 11:55:56 2008
@@ -168,12 +168,12 @@
/** time() with more precision
* @return The current time in us */
-axel_time getutime() {
+AXEL_TIME getutime() {
struct timeval time;
gettimeofday (&time, NULL);
- return ( (axel_time) time->tv_sec * 1000000 + (axel_time) time->tv_usec);
+ return ( (AXEL_TIME) time->tv_sec * 1000000 + (AXEL_TIME) time->tv_usec);
}
#ifdef DEBUG
@@ -189,3 +189,4 @@
va_end(params);
}
#endif
+
Modified: branches/3.x-broken/src/helper.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/helper.h?rev=73&op=diff
==============================================================================
--- branches/3.x-broken/src/helper.h (original)
+++ branches/3.x-broken/src/helper.h Mon Dec 29 11:55:56 2008
@@ -21,8 +21,8 @@
char* uitoa(unsigned int ui);
-#define axel_time long long
-axel_time getutime();
+#define AXEL_TIME long long int
+AXEL_TIME getutime();
#ifdef DEBUG
void debug_print(const char* msg);
Added: branches/3.x-broken/src/libs.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/libs.h?rev=73&op=file
==============================================================================
--- branches/3.x-broken/src/libs.h (added)
+++ branches/3.x-broken/src/libs.h Mon Dec 29 11:55:56 2008
@@ -1,0 +1,39 @@
+// Include all system libraries
+
+#include <time.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <netdb.h>
+#ifndef NOGETOPTLONG
+#define _GNU_SOURCE
+#include <getopt.h>
+#endif
+#include <limits.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+#include <stdarg.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <netinet/in_systm.h>
+#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <pthread.h>
+
+/* Internationalization */
+#ifdef I18N
+#define PACKAGE "axel"
+#define _( x ) gettext( x )
+#include <libintl.h>
+#include <locale.h>
+#else
+#define _( x ) x
+#endif
Added: branches/3.x-broken/src/messages.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/messages.c?rev=73&op=file
==============================================================================
--- branches/3.x-broken/src/messages.c (added)
+++ branches/3.x-broken/src/messages.c Mon Dec 29 11:55:56 2008
@@ -1,0 +1,2 @@
+/* Textual messages within axel */
+
Added: branches/3.x-broken/src/messages.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/messages.h?rev=73&op=file
==============================================================================
--- branches/3.x-broken/src/messages.h (added)
+++ branches/3.x-broken/src/messages.h Mon Dec 29 11:55:56 2008
@@ -1,0 +1,19 @@
+/* Textual messages within axel */
+
+enum message_relevance {
+ chatter,
+ status,
+ warning,
+ error,
+ critical
+};
+
+struct {
+ char* msg; // The message text, on the heap.
+ _Bool onheap; // True iff the message is stored on the heap (and must be freed by this module)
+ message_relevance rel;
+ struct message_struct* next;
+} message_struct;
+
+typedef struct message_struct message_t;
+
More information about the axel-commits
mailing list