1 /***********************************************************************************************************************************
2 HTTP Session
3 ***********************************************************************************************************************************/
4 #include "build.auto.h"
5
6 #include "common/debug.h"
7 #include "common/io/http/session.h"
8 #include "common/io/io.h"
9 #include "common/log.h"
10 #include "common/memContext.h"
11
12 /***********************************************************************************************************************************
13 Object type
14 ***********************************************************************************************************************************/
15 struct HttpSession
16 {
17 MemContext *memContext; // Mem context
18 HttpClient *httpClient; // HTTP client
19 IoSession *ioSession; // IO session
20 };
21
22 /**********************************************************************************************************************************/
23 HttpSession *
httpSessionNew(HttpClient * httpClient,IoSession * ioSession)24 httpSessionNew(HttpClient *httpClient, IoSession *ioSession)
25 {
26 FUNCTION_LOG_BEGIN(logLevelDebug)
27 FUNCTION_LOG_PARAM(HTTP_CLIENT, httpClient);
28 FUNCTION_LOG_PARAM(IO_SESSION, ioSession);
29 FUNCTION_LOG_END();
30
31 ASSERT(httpClient != NULL);
32 ASSERT(ioSession != NULL);
33
34 HttpSession *this = NULL;
35
36 MEM_CONTEXT_NEW_BEGIN("HttpSession")
37 {
38 this = memNew(sizeof(HttpSession));
39
40 *this = (HttpSession)
41 {
42 .memContext = MEM_CONTEXT_NEW(),
43 .httpClient = httpClient,
44 .ioSession = ioSessionMove(ioSession, memContextCurrent()),
45 };
46 }
47 MEM_CONTEXT_NEW_END();
48
49 FUNCTION_LOG_RETURN(HTTP_SESSION, this);
50 }
51
52 /**********************************************************************************************************************************/
53 void
httpSessionDone(HttpSession * this)54 httpSessionDone(HttpSession *this)
55 {
56 FUNCTION_LOG_BEGIN(logLevelDebug)
57 FUNCTION_LOG_PARAM(HTTP_SESSION, this);
58 FUNCTION_LOG_END();
59
60 ASSERT(this != NULL);
61
62 httpClientReuse(this->httpClient, this);
63
64 FUNCTION_LOG_RETURN_VOID();
65 }
66
67 /**********************************************************************************************************************************/
68 IoRead *
httpSessionIoRead(HttpSession * this)69 httpSessionIoRead(HttpSession *this)
70 {
71 FUNCTION_TEST_BEGIN();
72 FUNCTION_TEST_PARAM(HTTP_SESSION, this);
73 FUNCTION_TEST_END();
74
75 ASSERT(this != NULL);
76
77 FUNCTION_TEST_RETURN(ioSessionIoRead(this->ioSession));
78 }
79
80 /**********************************************************************************************************************************/
81 IoWrite *
httpSessionIoWrite(HttpSession * this)82 httpSessionIoWrite(HttpSession *this)
83 {
84 FUNCTION_TEST_BEGIN();
85 FUNCTION_TEST_PARAM(HTTP_SESSION, this);
86 FUNCTION_TEST_END();
87
88 ASSERT(this != NULL);
89
90 FUNCTION_TEST_RETURN(ioSessionIoWrite(this->ioSession));
91 }
92