PSP2SDK  dirty-f9e4f2d
The free SDK for PSP2
include/psp2/net/http.h
Go to the documentation of this file.
00001 
00012 #ifndef _PSP2_NET_HTTP_H_
00013 #define _PSP2_NET_HTTP_H_
00014 
00015 #ifdef __cplusplus
00016 extern "C" {
00017 #endif
00018 
00019 /* defines */
00020 #define PSP2_HTTP_DEFAULT_RESOLVER_TIMEOUT      (1 * 1000 * 1000U)
00021 #define PSP2_HTTP_DEFAULT_RESOLVER_RETRY        (5U)
00022 #define PSP2_HTTP_DEFAULT_CONNECT_TIMEOUT       (30* 1000 * 1000U)
00023 #define PSP2_HTTP_DEFAULT_SEND_TIMEOUT          (120* 1000 * 1000U)
00024 #define PSP2_HTTP_DEFAULT_RECV_TIMEOUT          (120* 1000 * 1000U)
00025 #define PSP2_HTTP_DEFAULT_RECV_BLOCK_SIZE       (1500U)
00026 #define PSP2_HTTP_DEFAULT_RESPONSE_HEADER_MAX       (5000U)
00027 #define PSP2_HTTP_DEFAULT_REDIRECT_MAX          (6U)
00028 #define PSP2_HTTP_DEFAULT_TRY_AUTH_MAX          (6U)
00029 
00030 #define PSP2_HTTP_INVALID_ID                0
00031 
00032 #define PSP2_HTTP_ERROR_BEFORE_INIT             0x80431001
00033 #define PSP2_HTTP_ERROR_ALREADY_INITED              0x80431020
00034 #define PSP2_HTTP_ERROR_BUSY                    0x80431021
00035 #define PSP2_HTTP_ERROR_OUT_OF_MEMORY               0x80431022
00036 #define PSP2_HTTP_ERROR_NOT_FOUND               0x80431025
00037 #define PSP2_HTTP_ERROR_INVALID_VERSION             0x8043106a
00038 #define PSP2_HTTP_ERROR_INVALID_ID              0x80431100
00039 #define PSP2_HTTP_ERROR_OUT_OF_SIZE             0x80431104
00040 #define PSP2_HTTP_ERROR_INVALID_VALUE               0x804311fe
00041 
00042 #define PSP2_HTTP_ERROR_INVALID_URL             0x80433060
00043 #define PSP2_HTTP_ERROR_UNKNOWN_SCHEME              0x80431061
00044 #define PSP2_HTTP_ERROR_NETWORK                 0x80431063
00045 #define PSP2_HTTP_ERROR_BAD_RESPONSE                0x80431064
00046 #define PSP2_HTTP_ERROR_BEFORE_SEND             0x80431065
00047 #define PSP2_HTTP_ERROR_AFTER_SEND              0x80431066
00048 #define PSP2_HTTP_ERROR_TIMEOUT                 0x80431068
00049 #define PSP2_HTTP_ERROR_UNKOWN_AUTH_TYPE            0x80431069
00050 #define PSP2_HTTP_ERROR_UNKNOWN_METHOD              0x8043106b
00051 #define PSP2_HTTP_ERROR_READ_BY_HEAD_METHOD         0x8043106f
00052 #define PSP2_HTTP_ERROR_NOT_IN_COM              0x80431070
00053 #define PSP2_HTTP_ERROR_NO_CONTENT_LENGTH           0x80431071
00054 #define PSP2_HTTP_ERROR_CHUNK_ENC               0x80431072
00055 #define PSP2_HTTP_ERROR_TOO_LARGE_RESPONSE_HEADER       0x80431073
00056 #define PSP2_HTTP_ERROR_SSL                 0x80431075
00057 #define PSP2_HTTP_ERROR_ABORTED                 0x80431080
00058 #define PSP2_HTTP_ERROR_UNKNOWN                 0x80431081
00059 
00060 #define PSP2_HTTP_ERROR_PARSE_HTTP_NOT_FOUND            0x80432025
00061 #define PSP2_HTTP_ERROR_PARSE_HTTP_INVALID_RESPONSE     0x80432060
00062 #define PSP2_HTTP_ERROR_PARSE_HTTP_INVALID_VALUE        0x804321fe
00063 
00064 #define PSP2_HTTP_ERROR_RESOLVER_EPACKET            0x80436001
00065 #define PSP2_HTTP_ERROR_RESOLVER_ENODNS             0x80436002
00066 #define PSP2_HTTP_ERROR_RESOLVER_ETIMEDOUT          0x80436003
00067 #define PSP2_HTTP_ERROR_RESOLVER_ENOSUPPORT         0x80436004
00068 #define PSP2_HTTP_ERROR_RESOLVER_EFORMAT            0x80436005
00069 #define PSP2_HTTP_ERROR_RESOLVER_ESERVERFAILURE         0x80436006
00070 #define PSP2_HTTP_ERROR_RESOLVER_ENOHOST            0x80436007
00071 #define PSP2_HTTP_ERROR_RESOLVER_ENOTIMPLEMENTED        0x80436008
00072 #define PSP2_HTTP_ERROR_RESOLVER_ESERVERREFUSED         0x80436009
00073 #define PSP2_HTTP_ERROR_RESOLVER_ENORECORD          0x8043600a
00074 
00075 #define PSP2_HTTPS_ERROR_CERT                   0x80435060
00076 #define PSP2_HTTPS_ERROR_HANDSHAKE              0x80435061
00077 #define PSP2_HTTPS_ERROR_IO                 0x80435062
00078 #define PSP2_HTTPS_ERROR_INTERNAL               0x80435063
00079 #define PSP2_HTTPS_ERROR_PROXY                  0x80435064
00080 
00081 #define PSP2_HTTPS_ERROR_SSL_INTERNAL               (0x01U)
00082 #define PSP2_HTTPS_ERROR_SSL_INVALID_CERT           (0x02U)
00083 #define PSP2_HTTPS_ERROR_SSL_CN_CHECK               (0x04U)
00084 #define PSP2_HTTPS_ERROR_SSL_NOT_AFTER_CHECK            (0x08U)
00085 #define PSP2_HTTPS_ERROR_SSL_NOT_BEFORE_CHECK           (0x10U)
00086 #define PSP2_HTTPS_ERROR_SSL_UNKNOWN_CA             (0x20U)
00087 
00088 #define PSP2_HTTP_ENABLE        (1)
00089 #define PSP2_HTTP_DISABLE       (0)
00090 
00091 #define PSP2_HTTP_USERNAME_MAX_SIZE 256
00092 #define PSP2_HTTP_PASSWORD_MAX_SIZE 256
00093 
00094 #define PSP2_HTTP_STATUS_CODE_CONTINUE                  100
00095 #define PSP2_HTTP_STATUS_CODE_SWITCHING_PROTOCOLS           101
00096 #define PSP2_HTTP_STATUS_CODE_PROCESSING                102
00097 #define PSP2_HTTP_STATUS_CODE_OK                    200
00098 #define PSP2_HTTP_STATUS_CODE_CREATED                   201
00099 #define PSP2_HTTP_STATUS_CODE_ACCEPTED                  202
00100 #define PSP2_HTTP_STATUS_CODE_NON_AUTHORITATIVE_INFORMATION     203
00101 #define PSP2_HTTP_STATUS_CODE_NO_CONTENT                204
00102 #define PSP2_HTTP_STATUS_CODE_RESET_CONTENT             205
00103 #define PSP2_HTTP_STATUS_CODE_PARTIAL_CONTENT               206
00104 #define PSP2_HTTP_STATUS_CODE_MULTI_STATUS              207
00105 #define PSP2_HTTP_STATUS_CODE_MULTIPLE_CHOICES              300
00106 #define PSP2_HTTP_STATUS_CODE_MOVED_PERMANENTRY             301
00107 #define PSP2_HTTP_STATUS_CODE_MOVED_PERMANENTLY             301
00108 #define PSP2_HTTP_STATUS_CODE_FOUND                 302
00109 #define PSP2_HTTP_STATUS_CODE_SEE_OTHER                 303
00110 #define PSP2_HTTP_STATUS_CODE_NOT_MODIFIED              304
00111 #define PSP2_HTTP_STATUS_CODE_USE_PROXY                 305
00112 #define PSP2_HTTP_STATUS_CODE_TEMPORARY_REDIRECT            307
00113 #define PSP2_HTTP_STATUS_CODE_BAD_REQUEST               400
00114 #define PSP2_HTTP_STATUS_CODE_UNAUTHORIZED              401
00115 #define PSP2_HTTP_STATUS_CODE_PAYMENT_REQUIRED              402
00116 #define PSP2_HTTP_STATUS_CODE_FORBIDDDEN                403
00117 #define PSP2_HTTP_STATUS_CODE_NOT_FOUND                 404
00118 #define PSP2_HTTP_STATUS_CODE_METHOD_NOT_ALLOWED            405
00119 #define PSP2_HTTP_STATUS_CODE_NOT_ACCEPTABLE                406
00120 #define PSP2_HTTP_STATUS_CODE_PROXY_AUTHENTICATION_REQUIRED     407
00121 #define PSP2_HTTP_STATUS_CODE_REQUEST_TIME_OUT              408
00122 #define PSP2_HTTP_STATUS_CODE_CONFLICT                  409
00123 #define PSP2_HTTP_STATUS_CODE_GONE                  410
00124 #define PSP2_HTTP_STATUS_CODE_LENGTH_REQUIRED               411
00125 #define PSP2_HTTP_STATUS_CODE_PRECONDITION_FAILED           412
00126 #define PSP2_HTTP_STATUS_CODE_REQUEST_ENTITY_TOO_LARGE          413
00127 #define PSP2_HTTP_STATUS_CODE_REQUEST_URI_TOO_LARGE         414
00128 #define PSP2_HTTP_STATUS_CODE_UNSUPPORTED_MEDIA_TYPE            415
00129 #define PSP2_HTTP_STATUS_CODE_REQUEST_RANGE_NOT_SATISFIBLE      416
00130 #define PSP2_HTTP_STATUS_CODE_EXPECTATION_FAILED            417
00131 #define PSP2_HTTP_STATUS_CODE_UNPROCESSABLE_ENTITY          422
00132 #define PSP2_HTTP_STATUS_CODE_LOCKED                    423
00133 #define PSP2_HTTP_STATUS_CODE_FAILED_DEPENDENCY             424
00134 #define PSP2_HTTP_STATUS_CODE_UPGRADE_REQUIRED              426
00135 #define PSP2_HTTP_STATUS_CODE_INTERNAL_SERVER_ERROR         500
00136 #define PSP2_HTTP_STATUS_CODE_NOT_IMPLEMENTED               501
00137 #define PSP2_HTTP_STATUS_CODE_BAD_GATEWAY               502
00138 #define PSP2_HTTP_STATUS_CODE_SERVICE_UNAVAILABLE           503
00139 #define PSP2_HTTP_STATUS_CODE_GATEWAY_TIME_OUT              504
00140 #define PSP2_HTTP_STATUS_CODE_HTTP_VERSION_NOT_SUPPORTED        505
00141 #define PSP2_HTTP_STATUS_CODE_INSUFFICIENT_STORAGE          507
00142 
00143 #define PSP2_HTTP_URI_BUILD_WITH_SCHEME     0x01
00144 #define PSP2_HTTP_URI_BUILD_WITH_HOSTNAME   0x02
00145 #define PSP2_HTTP_URI_BUILD_WITH_PORT       0x04
00146 #define PSP2_HTTP_URI_BUILD_WITH_PATH       0x08
00147 #define PSP2_HTTP_URI_BUILD_WITH_USERNAME   0x10
00148 #define PSP2_HTTP_URI_BUILD_WITH_PASSWORD   0x20
00149 #define PSP2_HTTP_URI_BUILD_WITH_QUERY      0x40
00150 #define PSP2_HTTP_URI_BUILD_WITH_FRAGMENT   0x80
00151 #define PSP2_HTTP_URI_BUILD_WITH_ALL        0xFFFF
00152 
00153 #define PSP2_HTTPS_FLAG_SERVER_VERIFY       (0x01U)
00154 #define PSP2_HTTPS_FLAG_CLIENT_VERIFY       (0x02U)
00155 #define PSP2_HTTPS_FLAG_CN_CHECK        (0x04U)
00156 #define PSP2_HTTPS_FLAG_NOT_AFTER_CHECK     (0x08U)
00157 #define PSP2_HTTPS_FLAG_NOT_BEFORE_CHECK    (0x10U)
00158 #define PSP2_HTTPS_FLAG_KNOWN_CA_CHECK      (0x20U)
00159 
00160 /* struct */
00161 
00162 typedef struct SceHttpMemoryPoolStats {
00163     unsigned int poolSize;
00164     unsigned int maxInuseSize;
00165     unsigned int currentInuseSize;
00166     int reserved;
00167 } SceHttpMemoryPoolStats;
00168 
00169 typedef enum {
00170     PSP2_HTTP_METHOD_GET,
00171     PSP2_HTTP_METHOD_POST,
00172     PSP2_HTTP_METHOD_HEAD,
00173     PSP2_HTTP_METHOD_OPTIONS,
00174     PSP2_HTTP_METHOD_PUT,
00175     PSP2_HTTP_METHOD_DELETE,
00176     PSP2_HTTP_METHOD_TRACE,
00177     PSP2_HTTP_METHOD_CONNECT
00178 } SceHttpMethods;
00179 
00180 typedef struct SceHttpUriElement {
00181     int  opaque;
00182     char *scheme;
00183     char *username;
00184     char *password;
00185     char *hostname;
00186     char *path;
00187     char *query;
00188     char *fragment;
00189     unsigned short port;
00190     unsigned char  reserved[10];
00191 } SceHttpUriElement;
00192 
00193 typedef enum {
00194     PSP2_HTTP_VERSION_1_0 = 1,
00195     PSP2_HTTP_VERSION_1_1
00196 } SceHttpHttpVersion;
00197 
00198 typedef enum {
00199     PSP2_HTTP_PROXY_AUTO,
00200     PSP2_HTTP_PROXY_MANUAL
00201 } SceHttpProxyMode;
00202 
00203 typedef enum {
00204     PSP2_HTTP_HEADER_OVERWRITE,
00205     PSP2_HTTP_HEADER_ADD
00206 } SceHttpAddHeaderMode;
00207 
00208 typedef enum {
00209     PSP2_HTTP_AUTH_BASIC,
00210     PSP2_HTTP_AUTH_DIGEST,
00211     PSP2_HTTP_AUTH_RESERVED0,
00212     PSP2_HTTP_AUTH_RESERVED1,
00213     PSP2_HTTP_AUTH_RESERVED2
00214 } SceHttpAuthType;
00215 
00216 typedef enum {
00217     PSP2_HTTPS_SSLV23,
00218     PSP2_HTTPS_SSLV2,
00219     PSP2_HTTPS_SSLV3,
00220     PSP2_HTTPS_TLSV1
00221 } SceHttpSslVersion;
00222 
00223 typedef struct SceHttpsData {
00224     char *ptr;
00225     unsigned int size;
00226 } SceHttpsData;
00227 
00228 typedef struct SceHttpsCaList {
00229     void **caCerts;
00230     int caNum;
00231 } SceHttpsCaList;
00232 
00233 /* callbacks */
00234 
00235 typedef int (*SceHttpAuthInfoCallback)(
00236     int request,
00237     SceHttpAuthType authType,
00238     const char *realm,
00239     char *username,
00240     char *password,
00241     int needEntity,
00242     unsigned char **entityBody,
00243     unsigned int *entitySize,
00244     int *save,
00245     void *userArg);
00246 
00247 typedef int (*SceHttpRedirectCallback)(
00248     int request,
00249     int statusCode,
00250     int *method,
00251     const char *location,
00252     void *userArg);
00253 
00254 typedef int (*SceHttpsCallback)(
00255     unsigned int verifyEsrr,
00256     void * const sslCert[],
00257     int certNum,
00258     void *userArg);
00259 
00260 typedef int (*SceHttpCookieRecvCallback)(
00261     int request,
00262     const char *url,
00263     const char *cookieHeader,
00264     unsigned int headerLen,
00265     void *userArg);
00266 
00267 typedef int (*SceHttpCookieSendCallback)(
00268     int request,
00269     const char *url,
00270     const char *cookieHeader,
00271     void *userArg);
00272 
00273 /* protos */
00274 
00275 // libhttp
00276 int sceHttpInit(unsigned int poolSize);
00277 int sceHttpTerm(void);
00278 int sceHttpGetMemoryPoolStats(SceHttpMemoryPoolStats *currentStat);
00279 
00280 int sceHttpSetAuthInfoCallback(int id, SceHttpAuthInfoCallback cbfunc, void *userArg);
00281 int sceHttpSetAuthEnabled(int id, int enable);
00282 int sceHttpGetAuthEnabled(int id, int *enable);
00283 int sceHttpSetRedirectCallback(int id, SceHttpRedirectCallback cbfunc, void *userArg);
00284 int sceHttpSetAutoRedirect(int id, int enable);
00285 int sceHttpGetAutoRedirect(int id, int *enable);
00286 int sceHttpSetResolveTimeOut(int id, unsigned int usec);
00287 int sceHttpSetResolveRetry(int id, int retry);
00288 int sceHttpSetConnectTimeOut(int id, unsigned int usec);
00289 int sceHttpSetSendTimeOut(int id, unsigned int usec);
00290 int sceHttpSetRecvTimeOut(int id, unsigned int usec);
00291 
00292 int sceHttpSendRequest(int reqId, const void *postData, unsigned int size);
00293 int sceHttpAbortRequest(int reqId);
00294 int sceHttpGetResponseContentLength(int reqId, unsigned long long int *contentLength);
00295 int sceHttpGetStatusCode(int reqId, int *statusCode);
00296 int sceHttpGetAllResponseHeaders(int reqId, char **header, unsigned int *headerSize);
00297 int sceHttpReadData(int reqId, void *data, unsigned int size);
00298 int sceHttpAddRequestHeader(int id, const char *name, const char *value, unsigned int mode);
00299 int sceHttpRemoveRequestHeader(int id, const char *name);
00300 
00301 int sceHttpSetProxy(int id, int enableProxyFlag, int mode, const char *newProxyHost, unsigned short newProxyPort);
00302 int sceHttpGetProxy(int id, int *enabeProxyFlag, int *mode, char *proxy_host, unsigned int len, unsigned short *proxy_port);
00303 int sceHttpEnableKeepAlive(int id);
00304 int sceHttpDisableKeepAlive(int id);
00305 int sceHttpEnableHttp0_9(int id);
00306 int sceHttpDisableHttp0_9(int id);
00307 
00308 int sceHttpParseResponseHeader(const char *header, unsigned int headerLen, const char *fieldStr, const char **fieldValue, unsigned int *valueLen);
00309 int sceHttpParseStatusLine(const char *statusLine, unsigned int lineLen, int *httpMajorVer, int *httpMinorVer, int *responseCode, const char **reasonPhrase, unsigned int *phraseLen);
00310 
00311 int sceHttpCreateTemplate(const char *userAgent, int httpVer, int autoProxyConf);
00312 int sceHttpDeleteTemplate(int tmplId);
00313 int sceHttpCreateConnection(int tmplId, const char *serverName, const char *scheme, unsigned short port, int enableKeepalive);
00314 int sceHttpCreateConnectionWithURL(int tmplId, const char *url, int enableKeepalive);
00315 int sceHttpDeleteConnection(int connId);
00316 int sceHttpCreateRequest(int connId, int method, const char *path, unsigned long long int contentLength);
00317 int sceHttpCreateRequestWithURL(int connId, int method, const char *url, unsigned long long int contentLength);
00318 int sceHttpDeleteRequest(int reqId);
00319 int sceHttpSetResponseHeaderMaxSize(int id, unsigned int headerSize);
00320 int sceHttpSetRecvBlockSize(int id, unsigned int blockSize);
00321 int sceHttpSetRequestContentLength(int id, unsigned long long int contentLength);
00322 
00323 // uri
00324 int sceHttpUriEscape(char *out, unsigned int *require, unsigned int prepare, const char *in);
00325 int sceHttpUriUnescape(char *out, unsigned int *require, unsigned int prepare, const char *in);
00326 int sceHttpUriParse(SceHttpUriElement *out, const char *srcUrl, void *pool, unsigned int *require, unsigned int prepare);
00327 int sceHttpUriBuild(char *out, unsigned int *require, unsigned int prepare, const SceHttpUriElement *srcElement, unsigned int option);
00328 int sceHttpUriMerge(char *mergedUrl, const char *url, const char *relativeUrl, unsigned int *require, unsigned int prepare, unsigned int option);
00329 int sceHttpUriSweepPath(char *dst, const char *src , unsigned int srcSize);
00330 
00331 // https
00332 int sceHttpsLoadCert(int caCertNum, const SceHttpsData **caList, const SceHttpsData *cert, const SceHttpsData *privKey);
00333 int sceHttpsUnloadCert(void);
00334 int sceHttpsEnableOption(unsigned int sslFlags);
00335 int sceHttpsDisableOption(unsigned int sslFlags);
00336 int sceHttpsGetSslError(int id, int *errNum, unsigned int *detail);
00337 int sceHttpsSetSslCallback(int id, SceHttpsCallback cbfunc, void *userArg);
00338 int sceHttpsGetCaList(SceHttpsCaList* caList);
00339 int sceHttpsFreeCaList(SceHttpsCaList* caList);
00340 
00341 // cookie
00342 int sceHttpSetCookieEnabled(int id, int enable);
00343 int sceHttpGetCookieEnabled(int id, int *enable);
00344 int sceHttpGetCookie(const char *url, char *cookie, unsigned int *cookieLength,unsigned int prepare, int secure);
00345 int sceHttpAddCookie(const char *url, const char *cookie, unsigned int cookieLength);
00346 int sceHttpSetCookieRecvCallback(int id, SceHttpCookieRecvCallback cbfunc, void *userArg);
00347 int sceHttpSetCookieSendCallback(int id, SceHttpCookieSendCallback cbfunc, void *userArg);
00348 
00349 #ifdef __cplusplus
00350 }
00351 #endif
00352 
00353 #endif /* _PSP2_NET_HTTP_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines