MCPcopy Create free account
hub / github.com/acl-dev/acl / tpl_http_write

Function tpl_http_write

app/wizard/tpllib.cpp:1223–1264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1221
1222
1223int tpl_http_write(const tpl_t* tpl, int fd)
1224{
1225 /* Assumption: the content length can be max a 10 digit number */
1226 int length_digits = 10;
1227
1228 int header_len = sizeof(TPL_NPH_HTTP_HEADER_START)
1229 + sizeof(TPL_NPH_HTTP_HEADER_END)
1230 + length_digits;
1231
1232 int content_len = tpl_length(tpl);
1233 int tmp_len = content_len;
1234
1235 /* Long enough for both the HTTP header and content */
1236 char *response = (char*)acl_mymalloc(content_len + header_len + 1);
1237
1238 char *str_p = response;
1239
1240 (void)memcpy(str_p,
1241 TPL_NPH_HTTP_HEADER_START,
1242 sizeof(TPL_NPH_HTTP_HEADER_START) - 1);
1243
1244 str_p += sizeof(TPL_NPH_HTTP_HEADER_START) - 1;
1245
1246 M_INT_TO_STRING(str_p, length_digits, tmp_len, 0);
1247 str_p += length_digits;
1248
1249 (void)memcpy(str_p,
1250 TPL_NPH_HTTP_HEADER_END,
1251 sizeof(TPL_NPH_HTTP_HEADER_END) - 1);
1252
1253 str_p += sizeof(TPL_NPH_HTTP_HEADER_END) - 1;
1254
1255 tpl_get_content(tpl, str_p);
1256 content_len = write(fd, response, content_len
1257 + (unsigned int) (str_p - response));
1258 acl_myfree(response);
1259
1260 if (content_len < 0)
1261 return TPL_WRITE_ERROR;
1262
1263 return TPL_OK;
1264}
1265
1266void tpl_out(tpl_t *tpl, ACL_VSTREAM *out)
1267{

Callers

nothing calls this directly

Calls 4

memcpyFunction · 0.85
tpl_lengthFunction · 0.70
tpl_get_contentFunction · 0.70
writeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…