| 28 |
28 |
| 29 #include "../public/nsapi.h" |
29 #include "../public/nsapi.h" |
| 30 |
30 |
| 31 #include "session.h" |
31 #include "session.h" |
| 32 |
32 |
| |
33 NSAPISession* nsapisession_create(pool_handle_t *pool) { |
| |
34 NSAPISession *sn = pool_malloc(pool, sizeof(NSAPISession)); |
| |
35 if(!sn) { |
| |
36 return NULL; |
| |
37 } |
| |
38 |
| |
39 ZERO(sn, sizeof(NSAPISession)); |
| |
40 |
| |
41 sn->sn.pool = pool; |
| |
42 |
| |
43 sn->sn.client = pblock_create_pool(sn->sn.pool, 8); |
| |
44 if(!sn->sn.client) { |
| |
45 pool_free(pool, sn); |
| |
46 return NULL; |
| |
47 } |
| |
48 sn->sn.fill = 1; |
| |
49 |
| |
50 return sn; |
| |
51 } |
| |
52 |
| |
53 int nsapisession_setconnection(NSAPISession *sn, Connection *conn, netbuf *inbuf, IOStream **io) { |
| |
54 SessionHandler *sh = conn->session_handler; |
| |
55 WSBool ssl; |
| |
56 IOStream *sio = sh->create_iostream(sh, conn, sn->sn.pool, &ssl); |
| |
57 if(!sio) { |
| |
58 return 1; |
| |
59 } |
| |
60 *io = sio; |
| |
61 IOStream *http = httpstream_new(sn->sn.pool, sio); |
| |
62 if(!http) { |
| |
63 return 1; |
| |
64 } |
| |
65 sn->connection = conn; |
| |
66 sn->netbuf = inbuf; |
| |
67 sn->sn.csd = http; |
| |
68 sn->sn.ssl = ssl; |
| |
69 sn->sn.inbuf = inbuf; |
| |
70 sn->sn.inbuf->sd = http; |
| |
71 return 0; |
| |
72 } |
| |
73 |
| |
74 int nsapisession_set_stream(NSAPISession *sn, SYS_NETFD csd) { |
| |
75 IOStream *http = httpstream_new(sn->sn.pool, csd); |
| |
76 if(!http) { |
| |
77 return 1; |
| |
78 } |
| |
79 netbuf *inbuf = netbuf_open(csd, 1024); |
| |
80 if(!inbuf) { |
| |
81 return 1; |
| |
82 } |
| |
83 sn->sn.csd = http; |
| |
84 sn->sn.inbuf = inbuf; |
| |
85 sn->netbuf = inbuf; |
| |
86 return 0; |
| |
87 } |
| |
88 |
| |
89 NSAPI_PUBLIC Session *session_create(SYS_NETFD csd, struct sockaddr_in *sac) { |
| |
90 pool_handle_t *pool = pool_create(); |
| |
91 if(!pool) { |
| |
92 return NULL; |
| |
93 } |
| |
94 |
| |
95 NSAPISession *sn = nsapisession_create(pool); |
| |
96 if(!sn) { |
| |
97 pool_destroy(pool); |
| |
98 return NULL; |
| |
99 } |
| |
100 |
| |
101 if(nsapisession_set_stream(sn, csd)) { |
| |
102 pool_destroy(pool); |
| |
103 return NULL; |
| |
104 } |
| |
105 |
| |
106 sn->sn.iaddr = sac->sin_addr; |
| |
107 sn->sn.csd_open = 1; |
| |
108 sn->sn.fill = 0; |
| |
109 sn->sn.ssl = 0; |
| |
110 sn->sn.clientauth = 0; |
| |
111 |
| |
112 return (Session*)sn; |
| |
113 } |
| |
114 |
| 33 NSAPI_PUBLIC char *session_dns_lookup(Session *s, int verify) { |
115 NSAPI_PUBLIC char *session_dns_lookup(Session *s, int verify) { |
| 34 // TODO: implement |
116 // TODO: implement |
| 35 return NULL; |
117 return NULL; |
| 36 } |
118 } |
| 37 |
119 |