summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2005-02-18 04:56:16 +0000
committerJason Woodward2005-02-18 04:56:16 +0000
commit9a23c83004044f83fa3a678e9aee0e8c48647c28 (patch)
tree591f6db191934eed388bec835b7afb410cac49de /src
parent3257fe9b3b01d18905254d377fd1b792200adbf7 (diff)
downloadslapt-get-9a23c83004044f83fa3a678e9aee0e8c48647c28.tar.gz
progress_cb for the progress callback is now part of rc_config structure (libslapt)
Diffstat (limited to 'src')
-rw-r--r--src/common.h1
-rw-r--r--src/configuration.c1
-rw-r--r--src/configuration.h2
-rw-r--r--src/curl.c16
-rw-r--r--src/curl.h4
-rw-r--r--src/package.c6
6 files changed, 18 insertions, 12 deletions
diff --git a/src/common.h b/src/common.h
index fd738fb..1b53538 100644
--- a/src/common.h
+++ b/src/common.h
@@ -35,7 +35,6 @@ typedef struct {
int reg_return;
} sg_regex;
-
FILE *open_file(const char *file_name,const char *mode);
int init_regex(sg_regex *regex_t, const char *regex_string);
void execute_regex(sg_regex *regex_t,const char *string);
diff --git a/src/configuration.c b/src/configuration.c
index ba0005b..bb45122 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -45,6 +45,7 @@ rc_config *read_rc_config(const char *file_name){
global_config->exclude_list = NULL;
global_config->working_dir[0] = '\0';
global_config->remove_obsolete = FALSE;
+ global_config->progress_cb = NULL;
rc = open_file(file_name,"r");
if( rc == NULL ) exit(1);
diff --git a/src/configuration.h b/src/configuration.h
index 9f9fb36..7ac27ca 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -49,6 +49,8 @@ typedef struct {
BOOL_T print_uris;
BOOL_T dl_stats;
BOOL_T remove_obsolete;
+ int(*progress_cb)(void *,double,double,double,double);
+
} rc_config;
rc_config *read_rc_config(const char *file_name);
diff --git a/src/curl.c b/src/curl.c
index 7b9c858..06813b9 100644
--- a/src/curl.c
+++ b/src/curl.c
@@ -19,7 +19,7 @@
#include <main.h>
static size_t write_header_callback(void *buffer, size_t size, size_t nmemb, void *userp);
-int download_data(FILE *fh,const char *url,size_t bytes,int use_curl_dl_stats){
+int download_data(FILE *fh,const char *url,size_t bytes,const rc_config *global_config){
CURL *ch = NULL;
CURLcode response;
char curl_err_buff[1024];
@@ -43,8 +43,12 @@ int download_data(FILE *fh,const char *url,size_t bytes,int use_curl_dl_stats){
headers = curl_slist_append(headers, "Pragma: "); /* override no-cache */
- if( use_curl_dl_stats != 1 ){
- curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, progress_callback );
+ if( global_config->dl_stats != 1 ){
+ if( global_config->progress_cb == NULL ){
+ curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, progress_callback );
+ }else{
+ curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, global_config->progress_cb );
+ }
curl_easy_setopt(ch, CURLOPT_PROGRESSDATA, &bytes);
}
@@ -141,7 +145,7 @@ char *head_request(const char *url){
}
-int get_mirror_data_from_source(FILE *fh,int use_curl_dl_stats,const char *base_url,const char *filename){
+int get_mirror_data_from_source(FILE *fh,const rc_config *global_config,const char *base_url,const char *filename){
int return_code = 0;
char *url = NULL;
@@ -153,7 +157,7 @@ int get_mirror_data_from_source(FILE *fh,int use_curl_dl_stats,const char *base_
url[ strlen(base_url) ] = '\0';
strncat(url,filename,strlen(filename) );
- return_code = download_data(fh,url,0,use_curl_dl_stats);
+ return_code = download_data(fh,url,0,global_config);
free(url);
/* make sure we are back at the front of the file */
@@ -205,7 +209,7 @@ int download_pkg(const rc_config *global_config,pkg_info_t *pkg){
}
/* download the file to our file handle */
- dl_return = download_data(fh,url,f_size,global_config->dl_stats);
+ dl_return = download_data(fh,url,f_size,global_config);
if( dl_return == 0 ){
if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
}else if( dl_return == CURLE_HTTP_RANGE_ERROR ){
diff --git a/src/curl.h b/src/curl.h
index 8ac15b5..126a321 100644
--- a/src/curl.h
+++ b/src/curl.h
@@ -22,13 +22,13 @@ struct head_data_t {
};
/* this is the main download routine */
-int download_data(FILE *fh,const char *url,size_t bytes,int use_curl_dl_stats);
+int download_data(FILE *fh,const char *url,size_t bytes,const rc_config *global_config);
char *head_request(const char *url);
/*
this fills FILE with data from url, used for PACKAGES.TXT and CHECKSUMS
*/
-int get_mirror_data_from_source(FILE *fh,int use_curl_dl_stats,const char *base_url,const char *filename);
+int get_mirror_data_from_source(FILE *fh,const rc_config *global_config,const char *base_url,const char *filename);
/* download pkg, cals download_data */
int download_pkg(const rc_config *global_config,pkg_info_t *pkg);
diff --git a/src/package.c b/src/package.c
index d1dcad5..e38af30 100644
--- a/src/package.c
+++ b/src/package.c
@@ -1588,7 +1588,7 @@ int update_pkg_cache(const rc_config *global_config){
}else{
if( global_config->dl_stats == TRUE ) printf("\n");
if( (tmp_pkg_f = open_file(pkg_filename,"w+b")) == NULL ) exit(1);
- if( get_mirror_data_from_source(tmp_pkg_f,global_config->dl_stats,global_config->sources.url[i],PKG_LIST) == 0 ){
+ if( get_mirror_data_from_source(tmp_pkg_f,global_config,global_config->sources.url[i],PKG_LIST) == 0 ){
rewind(tmp_pkg_f); /* make sure we are back at the front of the file */
available_pkgs = parse_packages_txt(tmp_pkg_f);
if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
@@ -1623,7 +1623,7 @@ int update_pkg_cache(const rc_config *global_config){
}else{
if( global_config->dl_stats == TRUE ) printf("\n");
if( (tmp_patch_f = open_file(patch_filename,"w+b")) == NULL ) exit (1);
- if( get_mirror_data_from_source(tmp_patch_f,global_config->dl_stats,global_config->sources.url[i],PATCHES_LIST) == 0 ){
+ if( get_mirror_data_from_source(tmp_patch_f,global_config,global_config->sources.url[i],PATCHES_LIST) == 0 ){
rewind(tmp_patch_f); /* make sure we are back at the front of the file */
patch_pkgs = parse_packages_txt(tmp_patch_f);
if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
@@ -1655,7 +1655,7 @@ int update_pkg_cache(const rc_config *global_config){
if( global_config->dl_stats == TRUE ) printf("\n");
if( (tmp_checksum_f = open_file(checksum_filename,"w+b")) == NULL ) exit(1);
if( get_mirror_data_from_source(
- tmp_checksum_f,global_config->dl_stats,global_config->sources.url[i],CHECKSUM_FILE
+ tmp_checksum_f,global_config,global_config->sources.url[i],CHECKSUM_FILE
) != 0
){
source_dl_failed = 1;