|
1 | 1 | /*- |
2 | | - * Copyright (c) 2012-2025 Rozhuk Ivan <rozhuk.im@gmail.com> |
| 2 | + * Copyright (c) 2012-2026 Rozhuk Ivan <rozhuk.im@gmail.com> |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
|
59 | 59 | #include "proto/http.h" |
60 | 60 | #include "crypto/hash/md5.h" |
61 | 61 | #include "utils/xml.h" |
| 62 | +#include "utils/strh2num.h" |
62 | 63 |
|
63 | 64 | #include "stream_mpeg2ts.h" |
64 | 65 | #include "stream_src.h" |
@@ -729,11 +730,11 @@ str_src_start(str_src_p src) { |
729 | 730 | } |
730 | 731 | } |
731 | 732 | /* Tune socket. */ |
732 | | - error = skt_opts_apply_ex(skt, SO_F_UDP_BIND_AF_MASK, |
| 733 | + error = skt_opts_apply(skt, SO_F_UDP_BIND_AF_MASK, |
733 | 734 | &s->skt_opts, conn_udp->addr.ss_family, NULL); |
734 | 735 | if (0 != error) { |
735 | 736 | SYSLOG_ERR(LOG_ERR, error, |
736 | | - "skt_opts_apply_ex(SO_F_UDP_BIND_AF_MASK) fail."); |
| 737 | + "skt_opts_apply(SO_F_UDP_BIND_AF_MASK) fail."); |
737 | 738 | goto err_out; |
738 | 739 | } |
739 | 740 | /* Create IO task for socket. */ |
@@ -940,12 +941,12 @@ str_src_connected(tp_task_p tptask, int error, void *arg) { |
940 | 941 | } |
941 | 942 | /* Connected! */ |
942 | 943 | /* Tune socket. */ |
943 | | - error = skt_opts_apply_ex(tp_task_ident_get(tptask), |
| 944 | + error = skt_opts_apply(tp_task_ident_get(tptask), |
944 | 945 | (SO_F_TCP_ES_CONN_MASK & ~SO_F_HALFCLOSE_RDWR), |
945 | 946 | &src->s.skt_opts, 0, NULL); |
946 | 947 | if (0 != error) { |
947 | 948 | SYSLOG_ERR(LOG_NOTICE, error, |
948 | | - "skt_opts_apply_ex(SO_F_TCP_ES_CONN_MASK & ~SO_F_HALFCLOSE_RDWR) fail."); |
| 949 | + "skt_opts_apply(SO_F_TCP_ES_CONN_MASK & ~SO_F_HALFCLOSE_RDWR) fail."); |
949 | 950 | goto err_out; |
950 | 951 | } |
951 | 952 |
|
@@ -1003,10 +1004,10 @@ str_src_send_http_req_done_cb(tp_task_p tptask, int error, io_buf_p buf __unused |
1003 | 1004 |
|
1004 | 1005 | tp_task_stop(tptask); |
1005 | 1006 |
|
1006 | | - error = skt_opts_apply_ex(tp_task_ident_get(tptask), |
| 1007 | + error = skt_opts_apply(tp_task_ident_get(tptask), |
1007 | 1008 | SO_F_HALFCLOSE_WR, &src->s.skt_opts, 0, NULL); |
1008 | 1009 | SYSLOG_ERR(LOG_NOTICE, error, |
1009 | | - "skt_opts_apply_ex(SO_F_HALFCLOSE_WR) fail, not fatal."); |
| 1010 | + "skt_opts_apply(SO_F_HALFCLOSE_WR) fail, not fatal."); |
1010 | 1011 |
|
1011 | 1012 | /* Convert to "ready to read notifier". */ |
1012 | 1013 | tp_task_tp_cb_func_set(tptask, tp_task_notify_handler); |
@@ -1134,6 +1135,35 @@ str_src_recv_http_cb(tp_task_p tptask, int error, uint32_t eof, |
1134 | 1135 | return (TP_TASK_CB_CONTINUE); |
1135 | 1136 | } |
1136 | 1137 |
|
| 1138 | +/* |
| 1139 | + * HexNumCRLF |
| 1140 | + * dataCRLF |
| 1141 | + * HexNum |
| 1142 | + */ |
| 1143 | +static int |
| 1144 | +http_data_chunked_size(const uint8_t *buf, const size_t buf_size, |
| 1145 | + size_t *chunk_size, size_t *chunk_marker_size) { |
| 1146 | + uint8_t *ptr_end; |
| 1147 | + |
| 1148 | + if (NULL == buf || 5 > buf_size) /* 5 - min size: CRLF + num + CRLF */ |
| 1149 | + return (EINVAL); |
| 1150 | + if ('\r' != buf[0] || '\n' != buf[1]) |
| 1151 | + return (EINVAL); |
| 1152 | + ptr_end = mem_find_off(2, buf, buf_size, CRLF, 2); |
| 1153 | + if (NULL == ptr_end || |
| 1154 | + 3 > (ptr_end - buf)) |
| 1155 | + return (EINVAL); |
| 1156 | + |
| 1157 | + if (NULL != chunk_size) { |
| 1158 | + (*chunk_size) = ustrh2usize((buf + 2), (size_t)((ptr_end - (buf + 2)))); |
| 1159 | + } |
| 1160 | + if (NULL != chunk_marker_size) { |
| 1161 | + (*chunk_marker_size) = (size_t)((ptr_end - buf) + 2); |
| 1162 | + } |
| 1163 | + |
| 1164 | + return (0); |
| 1165 | +} |
| 1166 | + |
1137 | 1167 | static int |
1138 | 1168 | str_src_recv_tcp_cb(tp_task_p tptask, int error, uint32_t eof, |
1139 | 1169 | size_t data2transfer_size, void *arg) { |
|
0 commit comments