1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
zhttp.h - http client
Copyright (C) 2012 Ladislav Vaiz <ok1zia@nagano.cz>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#ifndef __ZHTTP_H
#define __ZHTTP_H
#include <zasyncdns.h>
#include <zbinbuf.h>
#include <zselect.h>
#include <glib.h>
#ifdef Z_HAVE_GNUTLS
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#endif
enum zhttp_state{
ZHTTPST_NEW,
ZHTTPST_DNS,
ZHTTPST_CONNECTING,
ZHTTPST_TLS_HANDSHAKE,
ZHTTPST_REQUEST,
ZHTTPST_HEADER,
ZHTTPST_DATA,
ZHTTPST_DONE,
ZHTTPST_ERROR
};
struct zhttp{
void (*callback)(struct zhttp *);
void *arg;
struct zbinbuf *request;
struct zbinbuf *response;
struct zasyncdns *adns;
struct zselect *zsel;
char *url;
char *errorstr;
char *server;
char *serveraddr;
int port;
char *page;
int sock;
int status; // HTTP status
int dataofs;
int sent; // sent data
int origreqlen; // original length of request
enum zhttp_state state;
GPtrArray *posts;
GHashTable *cookies;
GHashTable *headers;
char *datastr; // decoded data, freeed with object
int connecting_timer_id;
#ifdef Z_HAVE_GNUTLS
int istls;
gnutls_session_t session;
#endif
};
struct zhttp_post_var{
char *name;
char *value;
char *filename;
char *localfilename;
};
struct zhttp *zhttp_init(void);
void zhttp_free(struct zhttp *http);
#define zhttp_free0(http) { zhttp_free(http); http = NULL; }
void zhttp_get(struct zhttp *http, struct zselect *zsel, const char *url, void (*callback)(struct zhttp *), void *arg);
void zhttp_add_header(struct zhttp *http, const char *name, const char *value);
void zhttp_post_free(struct zhttp *http);
void zhttp_post_add(struct zhttp *http, const char *name, const char *value);
void zhttp_post_add_file_mem(struct zhttp *http, const char *name, const char *filename, const char *value);
void zhttp_post_add_file_disk(struct zhttp *http, const char *name, const char *filename, const char *localfilename);
void zhttp_post(struct zhttp *http, struct zselect *zsel, const char *url, void (*callback)(struct zhttp *), void *arg);
void zhttp_raw(struct zhttp *http, struct zselect *zsel, const char *url, const char *raw_request, void (*callback)(struct zhttp *), void *arg);
void zhttp_status(struct zhttp *http, GString *gs);
int zhttp_write_data(struct zhttp *http, const char *filename);
void zhttp_store_cookies(struct zhttp *http, const char *data, int len);
char *http_get_data(struct zhttp *http);
void zhttp_post_json(struct zhttp *http, struct zselect *zsel, const char *url, const char *json, void (*callback)(struct zhttp *), void *arg);
#ifdef Z_HAVE_GNUTLS
void zhttp_init_tls(void);
#endif
char *http_get_header(struct zhttp *http, const char *header_name);
int http_is_content_type(struct zhttp *http, const char *content_type);
#endif
|