2017-03-14 01:47:16 -03:00
|
|
|
/** libcurl based advanced IO aka ADVIO.
|
2017-03-03 20:20:13 -04:00
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
2017-04-27 12:56:43 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-03-03 20:20:13 -04:00
|
|
|
*********************************************************************************/
|
2017-01-19 23:12:52 -02:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2017-01-19 23:12:52 -02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2017-04-15 21:24:00 +02:00
|
|
|
#include "crypt.h"
|
2017-02-12 14:39:55 -03:00
|
|
|
|
2017-01-19 23:12:52 -02:00
|
|
|
struct advio {
|
|
|
|
CURL *curl;
|
|
|
|
FILE *file;
|
2017-06-17 18:54:55 +02:00
|
|
|
|
|
|
|
long uploaded; /**< Upload progress. How much has already been uploaded to the remote file. */
|
|
|
|
long downloaded; /**< Download progress. How much has already been downloaded from the remote file. */
|
|
|
|
|
|
|
|
int completed:1; /**< Was the upload completd */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-14 01:47:16 -03:00
|
|
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
2017-03-12 23:17:19 -03:00
|
|
|
|
2017-03-14 01:47:16 -03:00
|
|
|
char mode[2];
|
|
|
|
char *uri;
|
2017-01-19 23:12:52 -02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct advio AFILE;
|
|
|
|
|
2017-03-14 01:47:16 -03:00
|
|
|
/* The remaining functions from stdio are just replaced macros */
|
|
|
|
#define afeof(af) feof((af)->file)
|
|
|
|
#define aftell(af) ftell((af)->file)
|
2017-03-25 21:13:45 +01:00
|
|
|
#define afileno(af) fileno((af)->file)
|
2017-03-14 01:47:16 -03:00
|
|
|
#define afread(ptr, sz, nitems, af) fread(ptr, sz, nitems, (af)->file)
|
|
|
|
#define afwrite(ptr, sz, nitems, af) fwrite(ptr, sz, nitems, (af)->file)
|
2017-06-17 18:54:55 +02:00
|
|
|
#define afputs(ptr, af) fputs(ptr, (af)->file)
|
|
|
|
#define afprintf(af, fmt, ...) fprintf((af)->file, fmt, __VA_ARGS__)
|
|
|
|
#define afscanf(af, fmt, ...) fprintf((af)->file, fmt, __VA_ARGS__)
|
|
|
|
#define agetline(linep, linecapp, af) getline(linep, linecapp, (af)->file)
|
2017-01-19 23:12:52 -02:00
|
|
|
|
2017-03-14 01:47:16 -03:00
|
|
|
/* Extensions */
|
|
|
|
#define auri(af) ((af)->uri)
|
|
|
|
#define ahash(af) ((af)->hash)
|
2017-01-19 23:12:52 -02:00
|
|
|
|
2017-03-14 01:47:16 -03:00
|
|
|
AFILE *afopen(const char *url, const char *mode);
|
2017-01-19 23:12:52 -02:00
|
|
|
|
2017-03-14 01:47:16 -03:00
|
|
|
int afclose(AFILE *file);
|
2017-06-17 18:54:55 +02:00
|
|
|
|
2017-03-14 01:47:16 -03:00
|
|
|
int afflush(AFILE *file);
|
2017-06-17 18:54:55 +02:00
|
|
|
|
|
|
|
int afseek(AFILE *file, long offset, int origin);
|
|
|
|
|
|
|
|
void arewind(AFILE *file);
|
|
|
|
|
|
|
|
/** Download contens from remote file
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param resume Do a partial download and append to the local file
|
|
|
|
*/
|
|
|
|
int adownload(AFILE *af, int resume);
|
|
|
|
|
|
|
|
int aupload(AFILE *af, int resume);
|