mirror of
https://github.com/sheumann/NetDisk.git
synced 2025-01-04 15:30:03 +00:00
Small refactoring.
This commit is contained in:
parent
179c0afe56
commit
a485918d44
29
http.c
29
http.c
@ -33,6 +33,18 @@ enum ResponseHeader {
|
|||||||
LOCATION,
|
LOCATION,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
UpdateRequestRange(Session *sess, unsigned long start, unsigned long end) {
|
||||||
|
int count =
|
||||||
|
snprintf(sess->httpRequestRange, 10+1+10+5, "%lu-%lu\r\n\r\n", start, end);
|
||||||
|
|
||||||
|
sess->desiredStart = start;
|
||||||
|
sess->desiredEnd = end;
|
||||||
|
|
||||||
|
sess->httpRequestLen = sess->httpRequestRange - sess->httpRequest + count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Boolean BuildHTTPRequest(Session *sess, char *resourceStr) {
|
Boolean BuildHTTPRequest(Session *sess, char *resourceStr) {
|
||||||
int sizeNeeded = 0;
|
int sizeNeeded = 0;
|
||||||
int rangeOffset;
|
int rangeOffset;
|
||||||
@ -77,25 +89,16 @@ Boolean BuildHTTPRequest(Session *sess, char *resourceStr) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum RequestResult
|
||||||
void UpdateRequestRange(Session *sess, unsigned long start, unsigned long end) {
|
DoHTTPRequest(Session *sess, unsigned long start, unsigned long end) {
|
||||||
int count =
|
|
||||||
snprintf(sess->httpRequestRange, 10+1+10+5, "%lu-%lu\r\n\r\n", start, end);
|
|
||||||
|
|
||||||
sess->desiredStart = start;
|
|
||||||
sess->desiredEnd = end;
|
|
||||||
|
|
||||||
sess->httpRequestLen = sess->httpRequestRange - sess->httpRequest + count;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum RequestResult DoHTTPRequest(Session *sess) {
|
|
||||||
top:;
|
top:;
|
||||||
rlrBuff rlrBuff = {0};
|
rlrBuff rlrBuff = {0};
|
||||||
Word tcpError;
|
Word tcpError;
|
||||||
Boolean wantRedirect = FALSE, gotRedirect = FALSE;
|
Boolean wantRedirect = FALSE, gotRedirect = FALSE;
|
||||||
enum RequestResult result;
|
enum RequestResult result;
|
||||||
|
|
||||||
|
UpdateRequestRange(sess, start, end);
|
||||||
|
|
||||||
sess->responseCode = 0;
|
sess->responseCode = 0;
|
||||||
|
|
||||||
/* Send out request */
|
/* Send out request */
|
||||||
|
3
http.h
3
http.h
@ -18,7 +18,6 @@ enum RequestResult {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Boolean BuildHTTPRequest(Session *sess, char *resourceStr);
|
Boolean BuildHTTPRequest(Session *sess, char *resourceStr);
|
||||||
void UpdateRequestRange(Session *sess, unsigned long start, unsigned long end);
|
enum RequestResult DoHTTPRequest(Session *sess, unsigned long start, unsigned long end);
|
||||||
enum RequestResult DoHTTPRequest(Session *sess);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
4
main.c
4
main.c
@ -47,7 +47,6 @@ int main(int argc, char **argv) {
|
|||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
startByte = strtoul(argv[2], NULL, 0);
|
startByte = strtoul(argv[2], NULL, 0);
|
||||||
}
|
}
|
||||||
UpdateRequestRange(&sess, startByte, startByte + 511);
|
|
||||||
|
|
||||||
printf("Request:\n");
|
printf("Request:\n");
|
||||||
printf("=========\n");
|
printf("=========\n");
|
||||||
@ -60,7 +59,8 @@ int main(int argc, char **argv) {
|
|||||||
printf("=========\n");
|
printf("=========\n");
|
||||||
printf("\n", i);
|
printf("\n", i);
|
||||||
|
|
||||||
enum RequestResult requestResult = DoHTTPRequest(&sess);
|
enum RequestResult requestResult;
|
||||||
|
requestResult = DoHTTPRequest(&sess, startByte, startByte + 511);
|
||||||
printf("RequestResult %i\n", requestResult);
|
printf("RequestResult %i\n", requestResult);
|
||||||
printf("Response code %lu\n", sess.responseCode);
|
printf("Response code %lu\n", sess.responseCode);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user