Various fixes and improvements.

This commit is contained in:
C. Guy Yarvin 2013-10-30 11:26:51 -07:00
parent b016be2a6b
commit 549d090add
3 changed files with 104 additions and 12 deletions

View File

@ -110,7 +110,7 @@
u2_hmet met_e; // method
u2_hhed* hed_u; // headers
u2_hbod* bod_u; // body
struct _u2_creq* nex_u;
struct _u2_creq* nex_u; // next in queue
} u2_creq;
/* u2_cres: response to http client.
@ -122,9 +122,7 @@
u2_bean end; // all responses added
u2_hhed* hed_u; // headers
u2_hbod* bod_u; // body parts
struct _u2_cres* nex_u; // next in request queue
u2_hbod* rub_u; // exit of write queue
u2_hbod* bur_u; // entry of write queue
struct _u2_cres* nex_u; // next in response queue
} u2_cres;
/* u2_ccon: outgoing http connection.
@ -135,7 +133,13 @@
c3_w las_w; // last active (Unix time)
c3_w coq_l; // connection number
c3_c* hos_c; // hostname
c3_s por_s; // port
u2_bean sec; // yes == https
u2_hbod* rub_u; // exit of send queue
u2_hbod* bur_u; // entry of send queue
u2_creq* ceq_u; // exit of request queue
u2_creq* qec_u; // entry of request queue
u2_cres* res_u; // current response
struct _u2_ccon* pre_u; // previous in list
struct _u2_ccon* nex_u; // next in list
} u2_ccon;
@ -143,7 +147,7 @@
/* u2_cttp: http client.
*/
typedef struct _u2_cttp {
struct _u2_ccon* con_u; // connection list
struct _u2_ccon* coc_u; // connection list
} u2_cttp;
/* u2_apac: ames packet, coming or going.

100
v/http.c
View File

@ -874,6 +874,17 @@ _http_respond(u2_hrep* rep_u)
_http_flush(hon_u);
}
/* _http_creq(): http request from noun.
*/
static u2_creq*
_http_creq_new(c3_w num_w, u2_noun req)
{
u2_creq* ceq = malloc(sizeof(u2_creq));
c3_assert(0);
return 0;
}
void
u2_http_ef_bake(void)
{
@ -882,16 +893,93 @@ u2_http_ef_bake(void)
u2_reck_plan(u2A, pax, u2nc(c3__born, u2_nul));
}
/* u2_http_ef_thus(): send %thus effect to http.
/* _http_ccon_new(): create client connection. Return 0 if url invalid.
*/
void
u2_http_ef_thus(c3_l num_l,
u2_noun req)
static u2_ccon*
_http_ccon_new(u2_bean sec, c3_s por_s, c3_c* hos_c)
{
u2_ccon* coc_u = malloc(sizeof(u2_ccon));
coc_u->nex_u = u2_Host.ctp.coc_u;
coc_u->pre_u = 0;
u2_Host.ctp.coc_u->pre_u = coc_u;
u2_Host.ctp.coc_u = coc_u;
}
/* u2_http_ef_thou(): send %thou effect to http.
/* _http_ccon_find(): find existing connection for remote server.
*/
static u2_ccon*
_http_ccon_find(u2_bean sec, c3_s por_s, c3_c* hos_c)
{
return 0;
}
/* _http_ccon(): create or allocate client connection.
*/
static void
_http_ccon(c3_c* url_c)
{
u2_bean sec, c3_s por_s, c3_c* hos_c;
struct http_parser_url url_u;
url_u.port = 0;
if ( 0 == http_parser_parse_url(url_c, strlen(url_c), 0, &url_u) ) {
return 0;
}
por_s = ((0 == url_u.port) ? 80 : url_u.port);
if ( !((1 << UF_SCHEMA) & url_u.field_set) ) {
return 0;
}
else if ( (url_u.field_data[UF_SCHEMA].len < 4) ||
strncmp("http", url_c + url_u.field_data[UF_SCHEMA].off, 4) ) {
return 0;
}
else if ( url_u->field_data[UF_SCHEMA].len == 4 ) {
sec = u2_no;
}
else if ( (url_u->field_data[UF_SCHEMA].len != 5) ||
((url_c + url_u.field_data[UF_SCHEMA].off)[4] != 's') ) {
return 0;
}
else {
sec = u2_yes;
}
if ( !((1 << UF_HOST) & url_u->field_set) ) {
return 0;
}
{
c3_w len_w = url_u.field_data[UF_HOST].len;
hos_c = malloc(1 + len_w);
strncpy(hos_c, (url_c + url_u.field_data[UF_HOST].off), len_w);
hos_c[len_w] = 0;
}
{
u2_ccon* coc_c = _http_ccon_find(sec, por_s, hos_c);
if ( 0 != coc_c ) {
free(hos_c);
return coc_c;
}
else return _http_ccon_new(sec, por_s, hos_c);
}
}
/* u2_http_ef_thus(): send %thus effect (outgoing request) to http.
*/
void
u2_http_ef_thus(c3_w num_w,
u2_noun ceq)
{
u2_creq* ceq_u = _http_creq_new(num_w, req);
u2_ccon* coc_u = _http_ccon(ceq->sec, ceq->url_c);
}
/* u2_http_ef_thou(): send %thou effect (incoming response) to http.
*/
void
u2_http_ef_thou(c3_l coq_l,

View File

@ -572,7 +572,7 @@ _reck_kick_http(u2_reck* rec_u,
case c3__thus: p_fav = u2h(u2t(fav)); q_fav = u2t(u2t(fav));
{
u2_http_ef_thus(p_fav, q_fav);
u2_http_ef_thus(u2_cr_word(0, p_fav), u2k(q_fav));
return u2_yes;
}