diff options
| author | Nakidai <nakidai@disroot.org> | 2024-12-15 15:10:03 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-12-15 15:10:03 +0300 |
| commit | c5ddf04afa78dc879827fce5cf50de03b35bf110 (patch) | |
| tree | 34b596d954fba13012279491c6ae67ad409ffdb0 /src/request.c | |
| parent | 6389c37dd593898a01b0159bd879ed4edc6cd6a5 (diff) | |
| download | libhttpc-c5ddf04afa78dc879827fce5cf50de03b35bf110.tar.gz libhttpc-c5ddf04afa78dc879827fce5cf50de03b35bf110.zip | |
Implement LibHTTPC_readRequest
Not complete, though
Diffstat (limited to 'src/request.c')
| -rw-r--r-- | src/request.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/request.c b/src/request.c index a0e1358..93d2421 100644 --- a/src/request.c +++ b/src/request.c @@ -4,6 +4,9 @@ #include <stddef.h> #include <string.h> +#include <sys/socket.h> +#include <sys/types.h> + struct LibHTTPC_Request *LibHTTPC_loadRequest(struct LibHTTPC_Request *request_buf, char *buf) { @@ -93,6 +96,32 @@ struct LibHTTPC_Request *LibHTTPC_loadRequest(struct LibHTTPC_Request *request_b return request_buf; } +#ifdef LibHTTPC_SOCK +struct LibHTTPC_Request *LibHTTPC_readRequest( + int sockfd, + struct LibHTTPC_Request *request_buf, + char *buf, size_t buf_len +) +{ + if (!buf) + { + /* TODO: Implement behavior when buf == NULL */ + return NULL; + } else + { + if (!buf_len) + return NULL; + + ssize_t received = recv(sockfd, buf, buf_len, 0); + if (received < 0) + return NULL; + buf[buf_len - 1] = '\0'; + + return LibHTTPC_loadRequest(request_buf, buf); + } +} +#endif + int LibHTTPC_Request_(struct LibHTTPC_Request *request) { if (!LibHTTPC_free) |