You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
8.5 KiB
C

12 months ago
/*
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
*
* Use of this source code is governed by MIT-like license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MK_HTTPCLIENT_H_
#define MK_HTTPCLIENT_H_
#include "mk_common.h"
#include "mk_events_objects.h"
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////HttpDownloader/////////////////////////////////////////////
typedef struct mk_http_downloader_t *mk_http_downloader;
/**
* @param user_data
* @param code 0
* @param err_msg
* @param file_path
7 months ago
* @param user_data User data pointer
* @param code Error code, 0 represents success
* @param err_msg Error message
* @param file_path File save path
* [AUTO-TRANSLATED:8f8ed7ef]
12 months ago
*/
typedef void(API_CALL *on_mk_download_complete)(void *user_data, int code, const char *err_msg, const char *file_path);
/**
* http[s]
* @return
7 months ago
* Create http[s] downloader
* @return Downloader pointer
* [AUTO-TRANSLATED:93112194]
12 months ago
*/
API_EXPORT mk_http_downloader API_CALL mk_http_downloader_create();
/**
* http[s]
* @param ctx
7 months ago
* Destroy http[s] downloader
* @param ctx Downloader pointer
* [AUTO-TRANSLATED:8378a5a7]
12 months ago
*/
API_EXPORT void API_CALL mk_http_downloader_release(mk_http_downloader ctx);
/**
* http[s]
* @param ctx
* @param url http[s]url
* @param file
* @param cb
* @param user_data
7 months ago
* Start http[s] download
* @param ctx Downloader pointer
* @param url http[s] download url
* @param file File save path
* @param cb Callback function
* @param user_data User data pointer
* [AUTO-TRANSLATED:8a2acf02]
12 months ago
*/
API_EXPORT void API_CALL mk_http_downloader_start(mk_http_downloader ctx, const char *url, const char *file, on_mk_download_complete cb, void *user_data);
API_EXPORT void API_CALL mk_http_downloader_start2(mk_http_downloader ctx, const char *url, const char *file, on_mk_download_complete cb, void *user_data, on_user_data_free user_data_free);
///////////////////////////////////////////HttpRequester/////////////////////////////////////////////
typedef struct mk_http_requester_t *mk_http_requester;
/**
* http
* code == 0httphttp
* user_datamk_http_requester
* mk_http_requester_get_response
* mk_http_requester_release
* mk_http_requester_clear
* @param user_data
* @param code 0
* @param err_msg
7 months ago
* Http request result callback
* When code == 0, it means that the current http session is complete (http response has been received)
* Users should get the mk_http_requester object through user_data
* Then get the relevant response data through functions such as mk_http_requester_get_response
* At the end of the callback, the object should be destroyed by calling the mk_http_requester_release function
* Or reuse the object after calling the mk_http_requester_clear function
* @param user_data User data pointer
* @param code Error code, 0 represents success
* @param err_msg Error message
* [AUTO-TRANSLATED:d24408ce]
12 months ago
*/
typedef void(API_CALL *on_mk_http_requester_complete)(void *user_data, int code, const char *err_msg);
/**
* HttpRequester
7 months ago
* Create HttpRequester
* [AUTO-TRANSLATED:fa182fbc]
12 months ago
*/
API_EXPORT mk_http_requester API_CALL mk_http_requester_create();
/**
* mk_http_requester
7 months ago
* This method is only needed when reusing the mk_http_requester object
* [AUTO-TRANSLATED:6854d97f]
12 months ago
*/
API_EXPORT void API_CALL mk_http_requester_clear(mk_http_requester ctx);
/**
* HttpRequester
* mk_http_requester_starthttp
* mk_http_requester_releasehttp
7 months ago
* Destroy HttpRequester
* If the mk_http_requester_start function is called and is waiting for the http response,
* You can also call the mk_http_requester_release method to cancel the current http request
* [AUTO-TRANSLATED:5f533e28]
12 months ago
*/
API_EXPORT void API_CALL mk_http_requester_release(mk_http_requester ctx);
/**
* HTTPGET/POST
7 months ago
* Set HTTP method, such as GET/POST
* [AUTO-TRANSLATED:d4b641f1]
12 months ago
*/
API_EXPORT void API_CALL mk_http_requester_set_method(mk_http_requester ctx,const char *method);
/**
* HTTP
* @param header {"Content-Type","text/html",NULL} NULL
7 months ago
* Batch set HTTP headers
* @param header For example, {"Content-Type","text/html",NULL} must end with NULL
* [AUTO-TRANSLATED:65124347]
12 months ago
*/
API_EXPORT void API_CALL mk_http_requester_set_header(mk_http_requester ctx, const char *header[]);
/**
* HTTP
* @param key Content-Type
* @param value text/html
* @param force key
7 months ago
* Add HTTP header
* @param key For example, Content-Type
* @param value For example, text/html
* @param force If the key already exists, whether to force replacement
* [AUTO-TRANSLATED:79d32682]
12 months ago
*/
API_EXPORT void API_CALL mk_http_requester_add_header(mk_http_requester ctx,const char *key,const char *value,int force);
/**
*
* @param body mk_http_bodymk_http_body_from_string使mk_http_body_release
7 months ago
* Set message body,
* @param body mk_http_body object, generated by functions such as mk_http_body_from_string, please call mk_http_body_release to release it after use
* [AUTO-TRANSLATED:85d0f139]
12 months ago
*/
API_EXPORT void API_CALL mk_http_requester_set_body(mk_http_requester ctx, mk_http_body body);
/**
* HTTP
* @return 200 OK
7 months ago
* You can call this method to get the status code after receiving the HTTP response
* @return For example, 200 OK
* [AUTO-TRANSLATED:7757b21a]
12 months ago
*/
API_EXPORT const char* API_CALL mk_http_requester_get_response_status(mk_http_requester ctx);
/**
* HTTPHTTP
* @param key HTTP
* @return HTTP
7 months ago
* You can call this method to get the response HTTP header after receiving the HTTP response
* @param key HTTP header key name
* @return HTTP header key value
* [AUTO-TRANSLATED:10f8ae74]
12 months ago
*/
API_EXPORT const char* API_CALL mk_http_requester_get_response_header(mk_http_requester ctx,const char *key);
/**
* HTTPHTTP body
* @param length body,null
* @return body
7 months ago
* You can call this method to get the response HTTP body after receiving the HTTP response
* @param length Return body length, can be null
* @return Body pointer
* [AUTO-TRANSLATED:764dbb38]
12 months ago
*/
API_EXPORT const char* API_CALL mk_http_requester_get_response_body(mk_http_requester ctx, size_t *length);
/**
* HTTP
* @return
7 months ago
* You can call this method to get the response after receiving the HTTP response
* @return Response object
* [AUTO-TRANSLATED:3800b175]
12 months ago
*/
API_EXPORT mk_parser API_CALL mk_http_requester_get_response(mk_http_requester ctx);
/**
*
* @param cb
* @param user_data
7 months ago
* Set callback function
* @param cb Callback function, cannot be empty
* @param user_data User data pointer
* [AUTO-TRANSLATED:f04412b8]
12 months ago
*/
API_EXPORT void API_CALL mk_http_requester_set_cb(mk_http_requester ctx,on_mk_http_requester_complete cb, void *user_data);
API_EXPORT void API_CALL mk_http_requester_set_cb2(mk_http_requester ctx,on_mk_http_requester_complete cb, void *user_data, on_user_data_free user_data_free);
/**
* url
* @param url urlhttp/https
* @param timeout_second
7 months ago
* Start url request
* @param url Request url, supports http/https
* @param timeout_second Maximum timeout time
* [AUTO-TRANSLATED:36986fec]
12 months ago
*/
API_EXPORT void API_CALL mk_http_requester_start(mk_http_requester ctx,const char *url, float timeout_second);
#ifdef __cplusplus
}
#endif
#endif /* MK_HTTPCLIENT_H_ */