#ifndef _CUPS_HTTP_H_
# define _CUPS_HTTP_H_
# include "versioning.h"
# include <string.h>
# include <time.h>
# include <sys/types.h>
# ifdef WIN32
# ifndef __CUPS_SSIZE_T_DEFINED
# define __CUPS_SSIZE_T_DEFINED
typedef off_t ssize_t;
# endif
# include <winsock2.h>
# include <ws2tcpip.h>
# else
# ifdef __sgi
# define INET6
# endif
# include <unistd.h>
# include <sys/time.h>
# include <sys/socket.h>
# include <netdb.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netinet/in_systm.h>
# include <netinet/ip.h>
# if !defined(__APPLE__) || !defined(TCP_NODELAY)
# include <netinet/tcp.h>
# endif
# if defined(AF_UNIX) && !defined(AF_LOCAL)
# define AF_LOCAL AF_UNIX
# endif
# ifdef AF_LOCAL
# include <sys/un.h>
# endif
# if defined(LOCAL_PEERCRED) && !defined(SO_PEERCRED)
# define SO_PEERCRED LOCAL_PEERCRED
# endif
# endif
# ifdef __cplusplus
extern "C" {
# endif
#if defined(AF_INET6) && !defined(s6_addr32)
# if defined(__sun)
# define s6_addr32 _S6_un._S6_u32
# elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
# define s6_addr32 __u6_addr.__u6_addr32
# elif defined(__osf__)
# define s6_addr32 s6_un.sa6_laddr
# elif defined(WIN32)
# define s6_addr32 error_need_win32_specific_code
# endif
#endif
# define HTTP_MAX_URI 1024
# define HTTP_MAX_HOST 256
# define HTTP_MAX_BUFFER 2048
# define HTTP_MAX_VALUE 256
typedef enum http_auth_e
{
HTTP_AUTH_NONE,
HTTP_AUTH_BASIC,
HTTP_AUTH_MD5,
HTTP_AUTH_MD5_SESS,
HTTP_AUTH_MD5_INT,
HTTP_AUTH_MD5_SESS_INT,
HTTP_AUTH_NEGOTIATE
} http_auth_t;
typedef enum http_encoding_e
{
HTTP_ENCODE_LENGTH,
HTTP_ENCODE_CHUNKED,
HTTP_ENCODE_FIELDS
} http_encoding_t;
typedef enum http_encryption_e
{
HTTP_ENCRYPT_IF_REQUESTED,
HTTP_ENCRYPT_NEVER,
HTTP_ENCRYPT_REQUIRED,
HTTP_ENCRYPT_ALWAYS
} http_encryption_t;
typedef enum http_field_e
{
HTTP_FIELD_UNKNOWN = -1,
HTTP_FIELD_ACCEPT_LANGUAGE,
HTTP_FIELD_ACCEPT_RANGES,
HTTP_FIELD_AUTHORIZATION,
HTTP_FIELD_CONNECTION,
HTTP_FIELD_CONTENT_ENCODING,
HTTP_FIELD_CONTENT_LANGUAGE,
HTTP_FIELD_CONTENT_LENGTH,
HTTP_FIELD_CONTENT_LOCATION,
HTTP_FIELD_CONTENT_MD5,
HTTP_FIELD_CONTENT_RANGE,
HTTP_FIELD_CONTENT_TYPE,
HTTP_FIELD_CONTENT_VERSION,
HTTP_FIELD_DATE,
HTTP_FIELD_HOST,
HTTP_FIELD_IF_MODIFIED_SINCE,
HTTP_FIELD_IF_UNMODIFIED_SINCE,
HTTP_FIELD_KEEP_ALIVE,
HTTP_FIELD_LAST_MODIFIED,
HTTP_FIELD_LINK,
HTTP_FIELD_LOCATION,
HTTP_FIELD_RANGE,
HTTP_FIELD_REFERER,
HTTP_FIELD_RETRY_AFTER,
HTTP_FIELD_TRANSFER_ENCODING,
HTTP_FIELD_UPGRADE,
HTTP_FIELD_USER_AGENT,
HTTP_FIELD_WWW_AUTHENTICATE,
HTTP_FIELD_MAX
} http_field_t;
typedef enum http_keepalive_e
{
HTTP_KEEPALIVE_OFF = 0,
HTTP_KEEPALIVE_ON
} http_keepalive_t;
typedef enum http_state_e
{
HTTP_WAITING,
HTTP_OPTIONS,
HTTP_GET,
HTTP_GET_SEND,
HTTP_HEAD,
HTTP_POST,
HTTP_POST_RECV,
HTTP_POST_SEND,
HTTP_PUT,
HTTP_PUT_RECV,
HTTP_DELETE,
HTTP_TRACE,
HTTP_CLOSE,
HTTP_STATUS
} http_state_t;
typedef enum http_status_e
{
HTTP_ERROR = -1,
HTTP_CONTINUE = 100,
HTTP_SWITCHING_PROTOCOLS,
HTTP_OK = 200,
HTTP_CREATED,
HTTP_ACCEPTED,
HTTP_NOT_AUTHORITATIVE,
HTTP_NO_CONTENT,
HTTP_RESET_CONTENT,
HTTP_PARTIAL_CONTENT,
HTTP_MULTIPLE_CHOICES = 300,
HTTP_MOVED_PERMANENTLY,
HTTP_MOVED_TEMPORARILY,
HTTP_SEE_OTHER,
HTTP_NOT_MODIFIED,
HTTP_USE_PROXY,
HTTP_BAD_REQUEST = 400,
HTTP_UNAUTHORIZED,
HTTP_PAYMENT_REQUIRED,
HTTP_FORBIDDEN,
HTTP_NOT_FOUND,
HTTP_METHOD_NOT_ALLOWED,
HTTP_NOT_ACCEPTABLE,
HTTP_PROXY_AUTHENTICATION,
HTTP_REQUEST_TIMEOUT,
HTTP_CONFLICT,
HTTP_GONE,
HTTP_LENGTH_REQUIRED,
HTTP_PRECONDITION,
HTTP_REQUEST_TOO_LARGE,
HTTP_URI_TOO_LONG,
HTTP_UNSUPPORTED_MEDIATYPE,
HTTP_REQUESTED_RANGE,
HTTP_EXPECTATION_FAILED,
HTTP_UPGRADE_REQUIRED = 426,
HTTP_SERVER_ERROR = 500,
HTTP_NOT_IMPLEMENTED,
HTTP_BAD_GATEWAY,
HTTP_SERVICE_UNAVAILABLE,
HTTP_GATEWAY_TIMEOUT,
HTTP_NOT_SUPPORTED,
HTTP_AUTHORIZATION_CANCELED = 1000
} http_status_t;
typedef enum http_uri_status_e
{
HTTP_URI_OVERFLOW = -8,
HTTP_URI_BAD_ARGUMENTS = -7,
HTTP_URI_BAD_RESOURCE = -6,
HTTP_URI_BAD_PORT = -5,
HTTP_URI_BAD_HOSTNAME = -4,
HTTP_URI_BAD_USERNAME = -3,
HTTP_URI_BAD_SCHEME = -2,
HTTP_URI_BAD_URI = -1,
HTTP_URI_OK = 0,
HTTP_URI_MISSING_SCHEME,
HTTP_URI_UNKNOWN_SCHEME,
HTTP_URI_MISSING_RESOURCE
} http_uri_status_t;
typedef enum http_uri_coding_e
{
HTTP_URI_CODING_NONE = 0,
HTTP_URI_CODING_USERNAME = 1,
HTTP_URI_CODING_HOSTNAME = 2,
HTTP_URI_CODING_RESOURCE = 4,
HTTP_URI_CODING_MOST = 7,
HTTP_URI_CODING_QUERY = 8,
HTTP_URI_CODING_ALL = 15
} http_uri_coding_t;
typedef enum http_version_e
{
HTTP_0_9 = 9,
HTTP_1_0 = 100,
HTTP_1_1 = 101
} http_version_t;
typedef union _http_addr_u
{
struct sockaddr addr;
struct sockaddr_in ipv4;
#ifdef AF_INET6
struct sockaddr_in6 ipv6;
#endif
#ifdef AF_LOCAL
struct sockaddr_un un;
#endif
char pad[256];
} http_addr_t;
typedef struct http_addrlist_s
{
struct http_addrlist_s *next;
http_addr_t addr;
} http_addrlist_t;
typedef struct _http_s http_t;
extern void httpBlocking(http_t *http, int b);
extern int httpCheck(http_t *http);
extern void httpClearFields(http_t *http);
extern void httpClose(http_t *http);
extern http_t *httpConnect(const char *host, int port);
extern http_t *httpConnectEncrypt(const char *host, int port,
http_encryption_t encryption);
extern int httpDelete(http_t *http, const char *uri);
extern int httpEncryption(http_t *http, http_encryption_t e);
extern int httpError(http_t *http);
extern void httpFlush(http_t *http);
extern int httpGet(http_t *http, const char *uri);
extern char *httpGets(char *line, int length, http_t *http);
extern const char *httpGetDateString(time_t t);
extern time_t httpGetDateTime(const char *s);
extern const char *httpGetField(http_t *http, http_field_t field);
extern struct hostent *httpGetHostByName(const char *name);
extern char *httpGetSubField(http_t *http, http_field_t field,
const char *name, char *value);
extern int httpHead(http_t *http, const char *uri);
extern void httpInitialize(void);
extern int httpOptions(http_t *http, const char *uri);
extern int httpPost(http_t *http, const char *uri);
extern int httpPrintf(http_t *http, const char *format, ...)
# ifdef __GNUC__
__attribute__ ((__format__ (__printf__, 2, 3)))
# endif
;
extern int httpPut(http_t *http, const char *uri);
extern int httpRead(http_t *http, char *buffer, int length) _CUPS_DEPRECATED;
extern int httpReconnect(http_t *http);
extern void httpSeparate(const char *uri, char *method,
char *username, char *host, int *port,
char *resource) _CUPS_DEPRECATED;
extern void httpSetField(http_t *http, http_field_t field,
const char *value);
extern const char *httpStatus(http_status_t status);
extern int httpTrace(http_t *http, const char *uri);
extern http_status_t httpUpdate(http_t *http);
extern int httpWrite(http_t *http, const char *buffer, int length) _CUPS_DEPRECATED;
extern char *httpEncode64(char *out, const char *in) _CUPS_DEPRECATED;
extern char *httpDecode64(char *out, const char *in) _CUPS_DEPRECATED;
extern int httpGetLength(http_t *http) _CUPS_DEPRECATED;
extern char *httpMD5(const char *, const char *, const char *,
char [33]);
extern char *httpMD5Final(const char *, const char *, const char *,
char [33]);
extern char *httpMD5String(const unsigned char *, char [33]);
extern void httpClearCookie(http_t *http) _CUPS_API_1_1_19;
extern const char *httpGetCookie(http_t *http) _CUPS_API_1_1_19;
extern void httpSetCookie(http_t *http, const char *cookie) _CUPS_API_1_1_19;
extern int httpWait(http_t *http, int msec) _CUPS_API_1_1_19;
extern char *httpDecode64_2(char *out, int *outlen, const char *in) _CUPS_API_1_1_21;
extern char *httpEncode64_2(char *out, int outlen, const char *in,
int inlen) _CUPS_API_1_1_21;
extern void httpSeparate2(const char *uri,
char *method, int methodlen,
char *username, int usernamelen,
char *host, int hostlen, int *port,
char *resource, int resourcelen) _CUPS_DEPRECATED;
extern int httpAddrAny(const http_addr_t *addr) _CUPS_API_1_2;
extern http_addrlist_t *httpAddrConnect(http_addrlist_t *addrlist, int *sock) _CUPS_API_1_2;
extern int httpAddrEqual(const http_addr_t *addr1,
const http_addr_t *addr2) _CUPS_API_1_2;
extern void httpAddrFreeList(http_addrlist_t *addrlist) _CUPS_API_1_2;
extern http_addrlist_t *httpAddrGetList(const char *hostname, int family,
const char *service) _CUPS_API_1_2;
extern int httpAddrLength(const http_addr_t *addr) _CUPS_API_1_2;
extern int httpAddrLocalhost(const http_addr_t *addr) _CUPS_API_1_2;
extern char *httpAddrLookup(const http_addr_t *addr,
char *name, int namelen) _CUPS_API_1_2;
extern char *httpAddrString(const http_addr_t *addr,
char *s, int slen) _CUPS_API_1_2;
extern http_uri_status_t httpAssembleURI(http_uri_coding_t encoding,
char *uri, int urilen,
const char *scheme,
const char *username,
const char *host, int port,
const char *resource) _CUPS_API_1_2;
extern http_uri_status_t httpAssembleURIf(http_uri_coding_t encoding,
char *uri, int urilen,
const char *scheme,
const char *username,
const char *host, int port,
const char *resourcef, ...) _CUPS_API_1_2;
extern int httpFlushWrite(http_t *http) _CUPS_API_1_2;
extern int httpGetBlocking(http_t *http) _CUPS_API_1_2;
extern const char *httpGetDateString2(time_t t, char *s, int slen) _CUPS_API_1_2;
extern int httpGetFd(http_t *http) _CUPS_API_1_2;
extern const char *httpGetHostname(http_t *http, char *s, int slen) _CUPS_API_1_2;
extern off_t httpGetLength2(http_t *http) _CUPS_API_1_2;
extern http_status_t httpGetStatus(http_t *http) _CUPS_API_1_2;
extern char *httpGetSubField2(http_t *http, http_field_t field,
const char *name, char *value,
int valuelen) _CUPS_API_1_2;
extern ssize_t httpRead2(http_t *http, char *buffer, size_t length) _CUPS_API_1_2;
extern http_uri_status_t httpSeparateURI(http_uri_coding_t decoding,
const char *uri,
char *scheme, int schemelen,
char *username, int usernamelen,
char *host, int hostlen, int *port,
char *resource, int resourcelen) _CUPS_API_1_2;
extern void httpSetExpect(http_t *http, http_status_t expect) _CUPS_API_1_2;
extern void httpSetLength(http_t *http, size_t length) _CUPS_API_1_2;
extern ssize_t httpWrite2(http_t *http, const char *buffer,
size_t length) _CUPS_API_1_2;
extern char *httpGetAuthString(http_t *http) _CUPS_API_1_3;
extern void httpSetAuthString(http_t *http, const char *scheme,
const char *data) _CUPS_API_1_3;
# ifdef __cplusplus
}
# endif
#endif