/*
 * http_request.h
 *
 * Copyright (C) 2019 OPTOELECTRONICS CO.,LTD. All rights reserved.
 */

#ifndef HTTP_REQUEST_H_
#define HTTP_REQUEST_H_

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <stdbool.h>

// Method of http of HTTP_CreateRequest()
#define	HTTP_REQ_GET	0
#define	HTTP_REQ_POST	1
#define	HTTP_REQ_DELETE	2  //Not yet supported!!!!!!

// Option flags of HTTP_CreateRequest()
#define HTTP_FLAG_BYPASSMODE	0x00000001 // Allow an opened SSL socket to bypass the X509 certificate verification process.

// Phase of Http Control returned by HTTP_GetResponse()
#define HTTP_REQUEST_INIT				0
#define HTTP_REQUEST_CONNECTED			1
#define HTTP_REQUEST_UPLOAD_COMPLETE	2
#define HTTP_REQUEST_FINISHED			3
#define HTTP_REQUEST_CONNECTION_ERROR	4
#define HTTP_REQUEST_TIMEOUT			5
#define HTTP_REQUEST_SYSTEM_ERROR	    6

typedef void * HTTP_REQUEST_HANDLE;

void HTTP_InitHttpRequest();
void HTTP_DeinitHttpRequest();
HTTP_REQUEST_HANDLE HTTP_CreateRequest(char *targetURL, char cMethod, char *uploadData, size_t uploadSize, char *extraHeader, unsigned int timeout, unsigned int option);
bool HTTP_GetResponse(HTTP_REQUEST_HANDLE handle, char *phase, unsigned int *pHttpResponse, char **ppContent, unsigned int *pContentLength, char **ppHeader, unsigned int *pHeaderLength);
void HTTP_CloseRequest(HTTP_REQUEST_HANDLE handle);

#endif /* HTTP_REQUEST_H_ */
