[axel-commits] r70 - in /branches/3.x-broken: doc/ROADMAP src/axel.c src/axel.h src/conn.c src/conn.h src/helper.c src/helper.h src/url.c
phihag-guest at users.alioth.debian.org
phihag-guest at users.alioth.debian.org
Mon Dec 22 19:18:32 UTC 2008
Author: phihag-guest
Date: Mon Dec 22 19:18:31 2008
New Revision: 70
URL: http://svn.debian.org/wsvn/axel/?sc=1&rev=70
Log:
Use own strdup variants exclusively
work on conn.*
Modified:
branches/3.x-broken/doc/ROADMAP
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
branches/3.x-broken/src/url.c
Modified: branches/3.x-broken/doc/ROADMAP
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/doc/ROADMAP?rev=70&op=diff
==============================================================================
--- branches/3.x-broken/doc/ROADMAP (original)
+++ branches/3.x-broken/doc/ROADMAP Mon Dec 22 19:18:31 2008
@@ -46,6 +46,7 @@
* Check chinese man file, correct installation
* Find out where chinese manpage should be installed
* Scrap crappy OS workaround? (Test on Windows)
+* Figure out how to pass messages
Bugs
====
Modified: branches/3.x-broken/src/axel.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/axel.c?rev=70&op=diff
==============================================================================
--- branches/3.x-broken/src/axel.c (original)
+++ branches/3.x-broken/src/axel.c Mon Dec 22 19:18:31 2008
@@ -47,7 +47,7 @@
url->priority = priority;
}
- urllist_add(& axel->urls, url);
+ urllist_add(axel->urls, url);
return 1;
}
@@ -57,7 +57,7 @@
ax->display_handler = NULL;
ax->conf = conf;
- urllist_init(& ax->urls);
+ urllist_init(ax->urls);
ax->conncount = -1;
// conn is set once we know conncount
@@ -76,7 +76,7 @@
}
void axel_destroy(axel_t* axel) {
- urllist_destroy(& axel->urls);
+ urllist_destroy(axel->urls);
free(axel->filename);
free(axel->statefilename);
@@ -122,7 +122,7 @@
if (axel->filename == NULL) {
- axel->filename = strdup(axel->conf->default_filename);
+ axel->filename = safe_strdup(axel->conf->default_filename);
}
// TODO Open outfile
@@ -186,36 +186,6 @@
static void axel_set_state(axel_t* axel, int state) {
axel->state = state;
axel_update_display();
-}
-
-/**
-* Setup a worker thread.
-*/
-// TODO define return value, NULL for delete the URL, otherwise for new value, input for unchanged?
-// TODO define param
-void* axel_thread(void *c) {
- /* TODO check the following code */
- conn_t *conn = c;
-
- /* Allow this thread to be killed at any time. */
- pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, &oldstate );
- pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate );
-
- if( conn_setup( conn ) )
- {
- conn->last_transfer = gettime();
- if( conn_exec( conn ) )
- {
- conn->last_transfer = gettime();
- conn->enabled = 1;
- conn->state = 0;
- return( NULL );
- }
- }
-
- conn_disconnect( conn );
-
- return( NULL );
}
void axel_save_state(axel_t* axel) {
Modified: branches/3.x-broken/src/axel.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/axel.h?rev=70&op=diff
==============================================================================
--- branches/3.x-broken/src/axel.h (original)
+++ branches/3.x-broken/src/axel.h Mon Dec 22 19:18:31 2008
@@ -138,7 +138,7 @@
void (*display_handler)(const struct axel_struct* axel);
const conf_t* conf; // Not owned by this structure
- urllist_t urls; // Sorted list of URLs to read
+ urllist_t urls[1]; // Sorted list of URLs to read
int conncount; // The number of connections, -1 if conn is not yet initialized
conn_t** conn; // array of connections, of size conncount. Owned by this struct.
@@ -154,8 +154,7 @@
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
- long long start_utime; // Start time in microseconds
-
+ axel_time start_utime; // Start time in microseconds
// The download's state, one of the AXEL_STATE_* constants
int state;
@@ -168,7 +167,7 @@
// Main axel API: The following methods are used by the frontend.
void axel_init(axel_t* ax, const conf_t *conf);
_Bool axel_addurlstr(axel_t* axel, const char* urlstr, int priority);
-int axel_download(axel_t* axel);
+axel_state axel_download(axel_t* axel);
void axel_destroy(axel_t* axel);
// These functions are only called from axel's core
Modified: branches/3.x-broken/src/conn.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/conn.c?rev=70&op=diff
==============================================================================
--- branches/3.x-broken/src/conn.c (original)
+++ branches/3.x-broken/src/conn.c Mon Dec 22 19:18:31 2008
@@ -35,13 +35,14 @@
c->currentbyte = startbyte;
c->endbyte = endbyte;
c->cstate = INITIALIZED;
- c->message = NULL;
-}
-
-void conn_start(conn_t* c) {
+}
+
+_Bool conn_start(conn_t* c) {
if (pthread_create(conn->thread, NULL, conn_threadstart, c) != 0) {
- // TODO pthread error
- }
+ conn->message = _("Thread creation failed");
+ return false;
+ }
+
}
@@ -53,7 +54,7 @@
if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate) != 0) ||
(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate) != 0)) {
- conn->message = _("Thread initialization failed");
+ conn->message = safe_strdup("Thread initialization failed");
conn->cstate = ERROR;
return;
}
Modified: branches/3.x-broken/src/conn.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/conn.h?rev=70&op=diff
==============================================================================
--- branches/3.x-broken/src/conn.h (original)
+++ branches/3.x-broken/src/conn.h Mon Dec 22 19:18:31 2008
@@ -43,7 +43,6 @@
long long lastbyte; // The zero-based index of the last byte we should read. CONNB_UNKWOWN if everything should be read.
volatile connstate cstate;
- char *message;
// Must only be read from other modules while cstate == DOWNLOADING
int fd;
Modified: branches/3.x-broken/src/helper.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/helper.c?rev=70&op=diff
==============================================================================
--- branches/3.x-broken/src/helper.c (original)
+++ branches/3.x-broken/src/helper.c Mon Dec 22 19:18:31 2008
@@ -31,6 +31,22 @@
}
char* helper_strdup(const char* str) {
+ if (str == NULL) {
+ return NULL;
+ }
+
+ size_t len = strlen(str);
+ char* res = malloc(len + 1);
+ if (res == NULL) {
+ return null;
+ }
+ memcpy(res, str, len);
+ res[len] = '\0';
+
+ return res;
+}
+
+char* safe_strdup(const char* str) {
if (str == NULL) {
return NULL;
}
@@ -152,12 +168,12 @@
/** time() with more precision
* @return The current time in us */
-long long getutime() {
+axel_time getutime() {
struct timeval time;
gettimeofday (&time, NULL);
- return ( (long long) time->tv_sec * 1000000 + (long long) time->tv_usec);
+ return ( (axel_time) time->tv_sec * 1000000 + (axel_time) time->tv_usec);
}
#ifdef DEBUG
Modified: branches/3.x-broken/src/helper.h
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/helper.h?rev=70&op=diff
==============================================================================
--- branches/3.x-broken/src/helper.h (original)
+++ branches/3.x-broken/src/helper.h Mon Dec 22 19:18:31 2008
@@ -3,13 +3,11 @@
#define min( a, b ) ( (a) < (b) ? (a) : (b) )
#define max( a, b ) ( (a) > (b) ? (a) : (b) )
-// C99 does not actually include strdup
-#define strdup(str) helper_strdup(str)
-
void* safe_malloc(size_t size);
void* safe_realloc(void *ptr, size_t size);
char* helper_strdup(const char* str);
+char* safe_strdup(const char* str);
const char* strchr_upto(const char* haystack, char needle, const char* upto);
void heap_strcpy(char** destptr, const char* src);
@@ -23,7 +21,8 @@
char* uitoa(unsigned int ui);
-long long getutime();
+#define axel_time long long
+axel_time getutime();
#ifdef DEBUG
void debug_print(const char* msg);
Modified: branches/3.x-broken/src/url.c
URL: http://svn.debian.org/wsvn/axel/branches/3.x-broken/src/url.c?rev=70&op=diff
==============================================================================
--- branches/3.x-broken/src/url.c (original)
+++ branches/3.x-broken/src/url.c Mon Dec 22 19:18:31 2008
@@ -147,7 +147,7 @@
// Query
char* querystart = strchr(request+1, URL_REQUEST_SEPCHAR);
if (querystart != NULL) {
- this->query = strdup(querystart+1);
+ this->query = safe_strdup(querystart+1);
}
heap_substr_upto(&(res->query), request+1, querystart);
More information about the axel-commits
mailing list