From fb49515baa75b3cc002f366496ad18aec3083046 Mon Sep 17 00:00:00 2001 From: benshi <807629978@qq.com> Date: Fri, 5 Jul 2024 20:56:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=8Emk=5Fparser=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E8=8E=B7=E5=8F=96=E6=89=80=E6=9C=89header=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20(#3692)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add mk_api: 添加从mk_parser循环获取所有header的接口 --- api/include/mk_events_objects.h | 4 ++++ api/source/mk_events_objects.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index 5d1127a3..f81cbe61 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -58,6 +58,8 @@ API_EXPORT const char *API_CALL mk_record_info_get_stream(const mk_record_info c ///////////////////////////////////////////Parser///////////////////////////////////////////// //Parser对象的C映射 typedef struct mk_parser_t *mk_parser; +//Parser对象中Headers foreach回调 +typedef void(API_CALL *on_mk_parser_header_cb)(void *user_data, const char *key, const char *val); //Parser::Method(),获取命令字,譬如GET/POST API_EXPORT const char* API_CALL mk_parser_get_method(const mk_parser ctx); //Parser::Url(),获取HTTP的访问url(不包括?后面的参数) @@ -72,6 +74,8 @@ API_EXPORT const char* API_CALL mk_parser_get_tail(const mk_parser ctx); API_EXPORT const char* API_CALL mk_parser_get_header(const mk_parser ctx,const char *key); //Parser::Content(),获取HTTP body API_EXPORT const char* API_CALL mk_parser_get_content(const mk_parser ctx, size_t *length); +//循环获取所有header +API_EXPORT void API_CALL mk_parser_headers_for_each(const mk_parser ctx, on_mk_parser_header_cb cb, void *user_data); ///////////////////////////////////////////MediaInfo///////////////////////////////////////////// //MediaInfo对象的C映射 diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 097e4201..46bc408e 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -125,6 +125,13 @@ API_EXPORT const char* API_CALL mk_parser_get_content(const mk_parser ctx, size_ } return parser->content().c_str(); } +API_EXPORT void API_CALL mk_parser_headers_for_each(const mk_parser ctx, on_mk_parser_header_cb cb, void *user_data){ + assert(ctx && cb); + Parser *parser = (Parser *)ctx; + for (auto it = parser->getHeader().begin(); it != parser->getHeader().end(); ++it) { + cb(user_data, it->first.c_str(), it->second.c_str()); + } +} ///////////////////////////////////////////MediaInfo///////////////////////////////////////////// API_EXPORT const char* API_CALL mk_media_info_get_params(const mk_media_info ctx){