diff options
author | Daniel Stenberg <daniel@haxx.se> | 2000-10-02 06:28:55 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2000-10-02 06:28:55 +0000 |
commit | d5ad450db606822b06f07ef43559e8b006e45f0d (patch) | |
tree | af9aab92d461d8b2902fd1b5d2a749e94a2dcc92 /lib | |
parent | b0274a553b33bf6f4fc0a114bfd267ab3a5532e4 (diff) |
getinfo.c replaces the former writeout.c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/getinfo.c | 118 | ||||
-rw-r--r-- | lib/writeout.c | 180 | ||||
-rw-r--r-- | lib/writeout.h | 47 |
3 files changed, 118 insertions, 227 deletions
diff --git a/lib/getinfo.c b/lib/getinfo.c new file mode 100644 index 000000000..a356741b0 --- /dev/null +++ b/lib/getinfo.c @@ -0,0 +1,118 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Curl. + * + * The Initial Developer of the Original Code is Daniel Stenberg. + * + * Portions created by the Initial Developer are Copyright (C) 1999. + * All Rights Reserved. + * + * ------------------------------------------------------------ + * Main author: + * - Daniel Stenberg <daniel@haxx.se> + * + * http://curl.haxx.se + * + * $Source$ + * $Revision$ + * $Date$ + * $Author$ + * $State$ + * $Locker$ + * + * ------------------------------------------------------------ + ****************************************************************************/ + +#include "setup.h" + +#include <curl/curl.h> + +#include "urldata.h" + +#include <stdio.h> +#include <string.h> +#include <stdarg.h> + +CURLcode curl_getinfo(CURL *curl, CURLINFO info, ...) +{ + va_list arg; + long *param_longp; + double *param_doublep; + char **param_charp; + struct UrlData *data = (struct UrlData *)curl; + va_start(arg, info); + + switch(info&CURLINFO_TYPEMASK) { + default: + return CURLE_BAD_FUNCTION_ARGUMENT; + case CURLINFO_STRING: + param_charp = va_arg(arg, char **); + if(NULL == param_charp) + return CURLE_BAD_FUNCTION_ARGUMENT; + break; + case CURLINFO_LONG: + param_longp = va_arg(arg, long *); + if(NULL == param_longp) + return CURLE_BAD_FUNCTION_ARGUMENT; + break; + case CURLINFO_DOUBLE: + param_doublep = va_arg(arg, double *); + if(NULL == param_doublep) + return CURLE_BAD_FUNCTION_ARGUMENT; + break; + } + + switch(info) { + case CURLINFO_EFFECTIVE_URL: + *param_charp = data->url?data->url:""; + break; + case CURLINFO_HTTP_CODE: + *param_longp = data->progress.httpcode; + break; + case CURLINFO_TOTAL_TIME: + *param_doublep = data->progress.timespent; + break; + case CURLINFO_NAMELOOKUP_TIME: + *param_doublep = tvdiff(data->progress.t_nslookup, + data->progress.start); + break; + case CURLINFO_CONNECT_TIME: + *param_doublep = tvdiff(data->progress.t_connect, + data->progress.start); + break; + case CURLINFO_PRETRANSFER_TIME: + *param_doublep = tvdiff(data->progress.t_pretransfer, + data->progress.start); + break; + case CURLINFO_SIZE_UPLOAD: + *param_doublep = data->progress.uploaded; + break; + case CURLINFO_SIZE_DOWNLOAD: + *param_doublep = data->progress.downloaded; + break; + case CURLINFO_SPEED_DOWNLOAD: + *param_doublep = data->progress.dlspeed; + break; + case CURLINFO_SPEED_UPLOAD: + *param_doublep = data->progress.ulspeed; + break; + default: + return CURLE_BAD_FUNCTION_ARGUMENT; + } + return CURLE_OK; +} diff --git a/lib/writeout.c b/lib/writeout.c deleted file mode 100644 index 21603d0cb..000000000 --- a/lib/writeout.c +++ /dev/null @@ -1,180 +0,0 @@ -/***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Curl. - * - * The Initial Developer of the Original Code is Daniel Stenberg. - * - * Portions created by the Initial Developer are Copyright (C) 1999. - * All Rights Reserved. - * - * ------------------------------------------------------------ - * Main author: - * - Daniel Stenberg <daniel@haxx.se> - * - * http://curl.haxx.se - * - * $Source$ - * $Revision$ - * $Date$ - * $Author$ - * $State$ - * $Locker$ - * - * ------------------------------------------------------------ - ****************************************************************************/ - -#include "setup.h" - -#include <stdio.h> -#include <string.h> - -#include "strequal.h" -#include "writeout.h" - -typedef enum { - VAR_NONE, /* must be the first */ - VAR_TOTAL_TIME, - VAR_NAMELOOKUP_TIME, - VAR_CONNECT_TIME, - VAR_PRETRANSFER_TIME, - VAR_SIZE_DOWNLOAD, - VAR_SIZE_UPLOAD, - VAR_SPEED_DOWNLOAD, - VAR_SPEED_UPLOAD, - VAR_HTTP_CODE, - VAR_EFFECTIVE_URL, - VAR_NUM_OF_VARS /* must be the last */ -} replaceid; - -struct variable { - char *name; - replaceid id; -}; - - -static struct variable replacements[]={ - {"url_effective", VAR_EFFECTIVE_URL}, - {"http_code", VAR_HTTP_CODE}, - {"time_total", VAR_TOTAL_TIME}, - {"time_namelookup", VAR_NAMELOOKUP_TIME}, - {"time_connect", VAR_CONNECT_TIME}, - {"time_pretransfer", VAR_PRETRANSFER_TIME}, - {"size_download", VAR_SIZE_DOWNLOAD}, - {"size_upload", VAR_SIZE_UPLOAD}, - {"speed_download", VAR_SPEED_DOWNLOAD}, - {"speed_upload", VAR_SPEED_UPLOAD}, - {NULL} -}; - -void WriteOut(struct UrlData *data) -{ - FILE *stream = stdout; - char *ptr=data->writeinfo; - while(*ptr) { - if('%' == *ptr) { - if('%' == ptr[1]) { - /* an escaped %-letter */ - fputc('%', stream); - ptr+=2; - } - else { - /* this is meant as a variable to output */ - char *end; - char keepit; - int i; - if(('{' == ptr[1]) && (end=strchr(ptr, '}'))) { - ptr+=2; /* pass the % and the { */ - keepit=*end; - *end=0; /* zero terminate */ - for(i=0; replacements[i].name; i++) { - if(strequal(ptr, replacements[i].name)) { - switch(replacements[i].id) { - case VAR_EFFECTIVE_URL: - fprintf(stream, "%s", data->url?data->url:""); - break; - case VAR_HTTP_CODE: - fprintf(stream, "%03d", data->progress.httpcode); - break; - case VAR_TOTAL_TIME: - fprintf(stream, "%.3f", data->progress.timespent); - break; - case VAR_NAMELOOKUP_TIME: - fprintf(stream, "%.3f", tvdiff(data->progress.t_nslookup, - data->progress.start)); - break; - case VAR_CONNECT_TIME: - fprintf(stream, "%.3f", tvdiff(data->progress.t_connect, - data->progress.start)); - break; - case VAR_PRETRANSFER_TIME: - fprintf(stream, "%.3f", tvdiff(data->progress.t_pretransfer, - data->progress.start)); - break; - case VAR_SIZE_UPLOAD: - fprintf(stream, "%.0f", data->progress.uploaded); - break; - case VAR_SIZE_DOWNLOAD: - fprintf(stream, "%.0f", data->progress.downloaded); - break; - case VAR_SPEED_DOWNLOAD: - fprintf(stream, "%.2f", data->progress.dlspeed); - break; - case VAR_SPEED_UPLOAD: - fprintf(stream, "%.2f", data->progress.ulspeed); - break; - } - break; - } - } - ptr=end+1; /* pass the end */ - *end = keepit; - } - else { - /* illegal syntax, then just output the characters that are used */ - fputc('%', stream); - fputc(ptr[1], stream); - ptr+=2; - } - } - } - else if('\\' == *ptr) { - switch(ptr[1]) { - case 'r': - fputc('\r', stream); - break; - case 'n': - fputc('\n', stream); - break; - case 't': - fputc('\t', stream); - break; - default: - /* unknown, just output this */ - fputc(*ptr, stream); - fputc(ptr[1], stream); - break; - } - ptr+=2; - } - else { - fputc(*ptr, stream); - ptr++; - } - } - -} diff --git a/lib/writeout.h b/lib/writeout.h deleted file mode 100644 index d223a35b4..000000000 --- a/lib/writeout.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __WRITEOUT_H -#define __WRITEOUT_H -/***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * The Original Code is Curl. - * - * The Initial Developer of the Original Code is Daniel Stenberg. - * - * Portions created by the Initial Developer are Copyright (C) 1999. - * All Rights Reserved. - * - * ------------------------------------------------------------ - * Main author: - * - Daniel Stenberg <daniel@haxx.se> - * - * http://curl.haxx.se - * - * $Source$ - * $Revision$ - * $Date$ - * $Author$ - * $State$ - * $Locker$ - * - * ------------------------------------------------------------ - ****************************************************************************/ - -#include "urldata.h" - -void WriteOut(struct UrlData *data); - -#endif |