dcc_action.c (5199B)
1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ 2 /* 3 This file is part of GNU libmicrohttpd. 4 Copyright (C) 2024 Evgeny Grin (Karlson2k) 5 6 GNU libmicrohttpd is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 GNU libmicrohttpd is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 Alternatively, you can redistribute GNU libmicrohttpd and/or 17 modify it under the terms of the GNU General Public License as 18 published by the Free Software Foundation; either version 2 of 19 the License, or (at your option) any later version, together 20 with the eCos exception, as follows: 21 22 As a special exception, if other files instantiate templates or 23 use macros or inline functions from this file, or you compile this 24 file and link it with other works to produce a work based on this 25 file, this file does not by itself cause the resulting work to be 26 covered by the GNU General Public License. However the source code 27 for this file must still be made available in accordance with 28 section (3) of the GNU General Public License v2. 29 30 This exception does not invalidate any other reasons why a work 31 based on this file might be covered by the GNU General Public 32 License. 33 34 You should have received copies of the GNU Lesser General Public 35 License and the GNU General Public License along with this library; 36 if not, see <https://www.gnu.org/licenses/>. 37 */ 38 39 /** 40 * @file src/mhd2/dcc_action.c 41 * @brief The definition of the MHD_DCC_action_*() 42 * @author Karlson2k (Evgeny Grin) 43 */ 44 45 #include "mhd_sys_options.h" 46 47 #include "mhd_assert.h" 48 49 #include <string.h> 50 51 #include "mhd_dcc_action.h" 52 #include "mhd_response.h" 53 #include "mhd_reply.h" 54 #include "mhd_connection.h" 55 56 #include "mhd_public_api.h" 57 58 MHD_EXTERN_ 59 MHD_FN_PAR_NONNULL_ (1) 60 MHD_FN_PAR_CSTR_ (4) const struct MHD_DynamicContentCreatorAction * 61 MHD_DCC_action_continue_zc ( 62 struct MHD_DynamicContentCreatorContext *ctx, 63 size_t data_size, 64 const struct MHD_DynContentZCIoVec *iov_data, 65 const char *MHD_RESTRICT chunk_ext) 66 { 67 struct MHD_DynamicContentCreatorAction *ret; 68 69 ret = NULL; 70 do 71 { 72 if ((&(ctx->connection->rp.app_act_ctx)) != ctx) 73 break; 74 if (mhd_DCC_ACTION_NO_ACTION != ctx->connection->rp.app_act.act) 75 break; /* The action already has been created */ 76 if (NULL != iov_data) 77 { 78 mhd_assert (0 && "Not implemented yet"); 79 break; 80 } 81 if (0 == data_size) 82 { /* The total size must be non-zero */ 83 if (NULL == iov_data) 84 break; 85 mhd_assert (0 && "Not implemented yet"); 86 (void)iov_data->iov_count; 87 // TODO: add check for iov data total size 88 break; 89 } 90 if (NULL != chunk_ext) 91 { 92 if (ctx->connection->rp.props.chunked) 93 { 94 mhd_assert (0 && "Not implemented yet"); 95 // TODO: copy 'chunk_ext' directly to the output buffer 96 break; 97 } 98 } 99 ret = &(ctx->connection->rp.app_act); 100 ret->act = mhd_DCC_ACTION_CONTINUE; 101 ret->data.cntnue.buf_data_size = data_size; 102 ret->data.cntnue.iov_data = iov_data; 103 } while (0); 104 105 if (NULL == ret) 106 { 107 /* Call application clean-up */ 108 if ((NULL != iov_data) && (NULL != iov_data->iov_fcb)) 109 iov_data->iov_fcb (iov_data->iov_fcb_cls); 110 } 111 112 return ret; 113 } 114 115 116 MHD_EXTERN_ 117 MHD_FN_PAR_NONNULL_ (1) 118 MHD_FN_PAR_NONNULL_IF_NONZERO_ (3, 2) 119 const struct MHD_DynamicContentCreatorAction * 120 MHD_DCC_action_finish_with_footer ( 121 struct MHD_DynamicContentCreatorContext *ctx, 122 size_t num_footers, 123 const struct MHD_NameValueCStr *MHD_RESTRICT footers) 124 { 125 struct MHD_DynamicContentCreatorAction *ret; 126 127 if ((&(ctx->connection->rp.app_act_ctx)) != ctx) 128 return NULL; 129 if (mhd_DCC_ACTION_NO_ACTION != ctx->connection->rp.app_act.act) 130 return NULL; /* The action already has been created */ 131 if ((0 != num_footers) && (NULL == footers)) 132 return NULL; 133 134 if (MHD_SIZE_UNKNOWN != ctx->connection->rp.response->cntn_size) 135 { 136 mhd_assert (ctx->connection->rp.rsp_cntn_read_pos < 137 ctx->connection->rp.response->cntn_size); 138 return NULL; 139 } 140 141 if (0 != num_footers) 142 { 143 mhd_assert (0 && "Not implemented yet"); 144 // TODO: build response footer and use footers directly 145 return NULL; 146 } 147 148 ret = &(ctx->connection->rp.app_act); 149 ret->act = mhd_DCC_ACTION_FINISH; 150 151 return ret; 152 } 153 154 155 MHD_EXTERN_ 156 MHD_FN_PAR_NONNULL_ (1) const struct MHD_DynamicContentCreatorAction * 157 MHD_DCC_action_suspend (struct MHD_DynamicContentCreatorContext *ctx) 158 { 159 struct MHD_DynamicContentCreatorAction *ret; 160 161 if ((&(ctx->connection->rp.app_act_ctx)) != ctx) 162 return NULL; 163 if (mhd_DCC_ACTION_NO_ACTION != ctx->connection->rp.app_act.act) 164 return NULL; /* The action already has been created */ 165 166 ret = &(ctx->connection->rp.app_act); 167 ret->act = mhd_DCC_ACTION_SUSPEND; 168 169 return ret; 170 }