Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions | Variables
netfile.c File Reference
#include <curl/curl.h>
#include "fcintl.h"
#include "ioz.h"
#include "mem.h"
#include "rand.h"
#include "registry.h"
#include "netfile.h"

Go to the source code of this file.

Data Structures

struct  netfile_post
 

Typedefs

typedef size_t(* netfile_write_cb) (char *ptr, size_t size, size_t nmemb, void *userdata)
 

Functions

static CURLnetfile_init_handle (void)
 
static size_t netfile_memwrite_cb (char *ptr, size_t size, size_t nmemb, void *userdata)
 
static bool netfile_download_file_core (const char *URL, FILE *fp, struct netfile_write_cb_data *mem_data, nf_errmsg cb, void *data)
 
struct section_filenetfile_get_section_file (const char *URL, nf_errmsg cb, void *data)
 
bool netfile_download_file (const char *URL, const char *filename, nf_errmsg cb, void *data)
 
struct netfile_postnetfile_start_post (void)
 
void netfile_add_form_str (struct netfile_post *post, const char *name, const char *val)
 
void netfile_add_form_int (struct netfile_post *post, const char *name, const int val)
 
void netfile_close_post (struct netfile_post *post)
 
static size_t dummy_write (void *buffer, size_t size, size_t nmemb, void *userp)
 
bool netfile_send_post (const char *URL, struct netfile_post *post, FILE *reply_fp, struct netfile_write_cb_data *mem_data, const char *addr)
 
void netfile_free (void)
 

Variables

static char error_buf_curl [CURL_ERROR_SIZE]
 
static CURLchandle = nullptr
 

Typedef Documentation

◆ netfile_write_cb

typedef size_t(* netfile_write_cb) (char *ptr, size_t size, size_t nmemb, void *userdata)

Definition at line 48 of file netfile.c.

Function Documentation

◆ dummy_write()

static size_t dummy_write ( void buffer,
size_t  size,
size_t  nmemb,
void userp 
)
static

Dummy write callback used only to make sure curl's default write function does not get used as we don't want reply to stdout

Definition at line 261 of file netfile.c.

Referenced by netfile_send_post().

◆ netfile_add_form_int()

void netfile_add_form_int ( struct netfile_post post,
const char name,
const int  val 
)

Add one integer entry to netfile post form

Definition at line 234 of file netfile.c.

◆ netfile_add_form_str()

void netfile_add_form_str ( struct netfile_post post,
const char name,
const char val 
)

Add one entry to netfile post form

Definition at line 213 of file netfile.c.

Referenced by netfile_add_form_int().

◆ netfile_close_post()

void netfile_close_post ( struct netfile_post post)

Free netfile_post resources

Definition at line 246 of file netfile.c.

◆ netfile_download_file()

bool netfile_download_file ( const char URL,
const char filename,
nf_errmsg  cb,
void data 
)

Fetch file from given URL and save as given filename.

Definition at line 170 of file netfile.c.

Referenced by download_modpack_recursive().

◆ netfile_download_file_core()

static bool netfile_download_file_core ( const char URL,
FILE fp,
struct netfile_write_cb_data mem_data,
nf_errmsg  cb,
void data 
)
static

Fetch file from given URL to given file stream. This is the core function of netfile module.

Definition at line 98 of file netfile.c.

Referenced by netfile_download_file(), and netfile_get_section_file().

◆ netfile_free()

void netfile_free ( void  )

Free resources reserved by the netfile system

Definition at line 329 of file netfile.c.

Referenced by libfreeciv_free().

◆ netfile_get_section_file()

struct section_file * netfile_get_section_file ( const char URL,
nf_errmsg  cb,
void data 
)

Fetch section file from net

Definition at line 148 of file netfile.c.

Referenced by download_modpack_list(), and download_modpack_recursive().

◆ netfile_init_handle()

static CURL * netfile_init_handle ( void  )
static

Set handle to usable state.

Definition at line 59 of file netfile.c.

Referenced by netfile_download_file_core(), and netfile_send_post().

◆ netfile_memwrite_cb()

static size_t netfile_memwrite_cb ( char ptr,
size_t  size,
size_t  nmemb,
void userdata 
)
static

Curl write callback to store received file to memory.

Definition at line 80 of file netfile.c.

Referenced by netfile_download_file_core(), and netfile_send_post().

◆ netfile_send_post()

bool netfile_send_post ( const char URL,
struct netfile_post post,
FILE reply_fp,
struct netfile_write_cb_data mem_data,
const char addr 
)

Send HTTP POST

Definition at line 270 of file netfile.c.

◆ netfile_start_post()

struct netfile_post * netfile_start_post ( void  )

Allocate netfile_post

Definition at line 199 of file netfile.c.

Variable Documentation

◆ chandle

CURL* chandle = nullptr
static

Definition at line 54 of file netfile.c.

Referenced by netfile_free(), netfile_init_handle(), and netfile_start_post().

◆ error_buf_curl

char error_buf_curl[CURL_ERROR_SIZE]
static

Definition at line 51 of file netfile.c.

Referenced by netfile_download_file_core(), and netfile_init_handle().