Skip to content

Commit

Permalink
wip #109 failing spec in place with http as extension of REQUESTING
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Feb 9, 2016
1 parent f1cc08f commit 2fa5f20
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 5 deletions.
18 changes: 18 additions & 0 deletions doxy/sys_defs.html
Original file line number Diff line number Diff line change
Expand Up @@ -3017,3 +3017,21 @@ <h4>INTERNET_CONTEXT</h4>
<div class="def-sym-def"><a href="ref_sys_structures.html#HTML_ELEMENT">HTML-ELEMENT</a></div>
<div class="def-comment"></div>
</div>
<div class="def-item def-symbol">
<div class="def-type">Symbol:</div>
<div class="def-name"><a name="HTTP_CLIENT"></a>HTTP_CLIENT</div>
<div class="def-sym-def"><a href="ref_sys_structures.html#RECEPTOR_ADDRESS">RECEPTOR-ADDRESS</a></div>
<div class="def-comment"></div>
</div>
<div class="def-item def-symbol">
<div class="def-type">Symbol:</div>
<div class="def-name"><a name="HTTP_SERVER"></a>HTTP_SERVER</div>
<div class="def-sym-def"><a href="ref_sys_structures.html#RECEPTOR_ADDRESS">RECEPTOR-ADDRESS</a></div>
<div class="def-comment"></div>
</div>
<div class="def-item def-protocol">
<div class="def-type">Protocol:</div>
<div class="def-name"><a name="HTTP"></a>HTTP</div>
<div class="def-protocol-def">http_def</div>
<div class="def-comment"></div>
</div>
2 changes: 2 additions & 0 deletions doxy/sys_symbols.html
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,6 @@
<tr><td><a name="HTML_FORM"></a>HTML_FORM</td><td><a href="ref_sys_structures.html#HTML_ELEMENT">HTML-ELEMENT</a></td><td></td></tr>
<tr><td><a name="HTML_INPUT"></a>HTML_INPUT</td><td><a href="ref_sys_structures.html#HTML_ELEMENT">HTML-ELEMENT</a></td><td></td></tr>
<tr><td><a name="HTML_BUTTON"></a>HTML_BUTTON</td><td><a href="ref_sys_structures.html#HTML_ELEMENT">HTML-ELEMENT</a></td><td></td></tr>
<tr><td><a name="HTTP_CLIENT"></a>HTTP_CLIENT</td><td><a href="ref_sys_structures.html#RECEPTOR_ADDRESS">RECEPTOR-ADDRESS</a></td><td></td></tr>
<tr><td><a name="HTTP_SERVER"></a>HTTP_SERVER</td><td><a href="ref_sys_structures.html#RECEPTOR_ADDRESS">RECEPTOR-ADDRESS</a></td><td></td></tr>
</table>
2 changes: 1 addition & 1 deletion spec/ceptr_specs.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, const char **argv) {

//**** receptor tests
testGroup();
testHTTPExample();
testHTTP();

/* /\***** examples *\/ */
testProfileExample();
Expand Down
72 changes: 71 additions & 1 deletion spec/http_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

#include "../src/ceptr.h"
#include "../src/receptor.h"
#include "../src/protocol.h"
#include "../src/def.h"
#include "../src/semtrex.h"
#include "spec_utils.h"
#include "../src/vmhost.h"
#include "../src/accumulator.h"
#include <unistd.h>

//! [makeTestHTTPRequestTree]
/**
Expand Down Expand Up @@ -285,7 +289,7 @@ T *parseHTML(char *html) {
raise_error("HTML doesn't match");
}

void testHTTPExample() {
void testHTTPparseHTML() {
T *t = parseHTML("<html><body><div>Hello <b>world!</b></div></body></html>");
T *r = _t_new_root(HTTP_RESPONSE);
T *s = _t_newr(r,HTTP_RESPONSE_STATUS);
Expand All @@ -298,6 +302,72 @@ void testHTTPExample() {
wjson(G_sem,r,"httpresp",-1);

_t_free(r);

}

void testHTTPprotocol() {
T *http = _sem_get_def(G_sem,HTTP);

// check the HTTP protocol definition
spec_is_str_equal(t2s(http),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL:HTTP) (PROTOCOL_SEMANTICS) (INCLUSION (PNAME:REQUESTING) (CONNECTION (WHICH_ROLE (ROLE:REQUESTER) (ROLE:HTTP_CLIENT))) (CONNECTION (WHICH_ROLE (ROLE:RESPONDER) (ROLE:HTTP_SERVER))) (RESOLUTION (WHICH_SYMBOL (USAGE:REQUEST_DATA) (ACTUAL_SYMBOL:HTTP_REQUEST))) (RESOLUTION (WHICH_SYMBOL (USAGE:RESPONSE_DATA) (ACTUAL_SYMBOL:HTTP_RESPONSE)))))");

T *sem_map = _t_new_root(SEMANTIC_MAP);
T *t = _o_unwrap(G_sem,http,sem_map);
// and also check how it gets unwrapped because it's defined in terms of REQUESTING
// @todo, how come HTTP_SERVER and the two handler goals aren't added to the semantics?
spec_is_str_equal(t2s(t),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL:HTTP) (PROTOCOL_SEMANTICS (ROLE:HTTP_CLIENT) (GOAL:REQUEST_HANDLER)) (backnforth (INITIATE (ROLE:HTTP_CLIENT) (DESTINATION (ROLE:HTTP_SERVER)) (ACTION:send_request)) (EXPECT (ROLE:HTTP_SERVER) (SOURCE (ROLE:HTTP_CLIENT)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST))) (ACTION:send_response))))");

// the unwrapping should build up a semantic map
spec_is_str_equal(t2s(sem_map),"(SEMANTIC_MAP (SEMANTIC_LINK (ROLE:REQUESTER) (REPLACEMENT_VALUE (ROLE:HTTP_CLIENT))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (ROLE:HTTP_SERVER))) (SEMANTIC_LINK (USAGE:REQUEST_DATA) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:HTTP_REQUEST))) (SEMANTIC_LINK (USAGE:RESPONSE_DATA) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:HTTP_RESPONSE))))");
_t_free(sem_map);

VMHost *v = G_vm = _v_new();
_v_instantiate_builtins(G_vm);

FILE *rs,*ws;
char buffer[] = "GET /test HTTP/0.9\n";

rs = fmemopen(buffer, strlen (buffer), "r");
Stream *reader_stream = _st_new_unix_stream(rs,1);

char *output_data;
size_t size;
ws = open_memstream(&output_data,&size);
Stream *writer_stream = _st_new_unix_stream(ws,0);

Receptor *w = _r_makeStreamWriterReceptor(v->sem,TEST_STREAM_SYMBOL,writer_stream);
Xaddr writer = _v_new_receptor(v,v->r,STREAM_WRITER,w);

Receptor *r = _r_makeStreamReaderReceptor(v->sem,TEST_STREAM_SYMBOL,reader_stream,w->addr);
Xaddr reader = _v_new_receptor(v,v->r,STREAM_READER,r);

// debug_enable(D_STREAM+D_SIGNALS+D_TREE+D_PROTOCOL);
_v_start_vmhost(G_vm);
sleep(1);
debug_disable(D_STREAM+D_SIGNALS+D_TREE+D_PROTOCOL);

fputs("not implemented!",ws);fflush(ws);

spec_is_true(output_data != 0); // protect against seg-faults when nothing was written to the stream...
if (output_data != 0) {
spec_is_str_equal(output_data,"<html><body><h3>you requested:</h3><div>test</divv></body></html>\n");
}
__r_kill(G_vm->r);

_v_join_thread(&G_vm->clock_thread);
_v_join_thread(&G_vm->vm_thread);

_st_free(reader_stream);
_st_free(writer_stream);
free(output_data);
_v_free(v);
G_vm = NULL;

}

void testHTTP() {
testHTTPparseHTML();
testHTTPprotocol();
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion spec/semtrex_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ void testSemtrexParseHHTPReq() {
char buf[50000];
T *stx;
stx = parseSemtrex(G_sem,stxs);
// stx = _makeHTTPRequestSemtrex();
//stx = _makeHTTPRequestSemtrex();

_t2json(G_sem,stx,INDENT,buf);
writeFile("web/httpreqstx.json",buf,strlen(buf));
Expand Down
15 changes: 15 additions & 0 deletions src/base_defs
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,18 @@ GlobalData: http_req_example,
(HTTP_REQUEST_PATH_QUERY_PARAM
(PARAM_KEY:"page")
(PARAM_VALUE:"2")))))); GET /groups/5/users.json?sort_by=last_name?page=2 HTTP/1.0

##### defs for HTTP protocol
Symbol: HTTP_CLIENT,RECEPTOR_ADDRESS;
Symbol: HTTP_SERVER,RECEPTOR_ADDRESS;

Data: http_def,(PROTOCOL_DEFINITION
(PROTOCOL_SEMANTICS)
(INCLUSION (PNAME:REQUESTING)
(CONNECTION (WHICH_ROLE (ROLE:REQUESTER) (ROLE:HTTP_CLIENT)))
(CONNECTION (WHICH_ROLE (ROLE:RESPONDER) (ROLE:HTTP_SERVER)))
(RESOLUTION (WHICH_SYMBOL (USAGE:REQUEST_DATA) (ACTUAL_SYMBOL:HTTP_REQUEST)))
(RESOLUTION (WHICH_SYMBOL (USAGE:RESPONSE_DATA) (ACTUAL_SYMBOL:HTTP_RESPONSE)))
));

Protocol: HTTP,http_def;
7 changes: 7 additions & 0 deletions src/base_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ SemanticID HTML_H4={0,0,0};
SemanticID HTML_FORM={0,0,0};
SemanticID HTML_INPUT={0,0,0};
SemanticID HTML_BUTTON={0,0,0};
SemanticID HTTP_CLIENT={0,0,0};
SemanticID HTTP_SERVER={0,0,0};
SemanticID HTTP={0,0,0};

void base_defs(SemTable *sem) {
sT(SYS_CONTEXT,BIT,1,NULL_SYMBOL);
Expand Down Expand Up @@ -1058,6 +1061,10 @@ void base_defs(SemTable *sem) {
sY(INTERNET_CONTEXT,HTML_BUTTON,HTML_ELEMENT);
sData(INTERNET_CONTEXT,http_req_example,STX_OP,HTTP_REQUEST,STX_OP,HTTP_REQUEST_VERSION,STX_OP,VERSION_MAJOR,1,STX_CP,STX_OP,VERSION_MINOR,0,STX_CP,STX_CP,STX_OP,HTTP_REQUEST_METHOD,"GET",STX_CP,STX_OP,HTTP_REQUEST_PATH,STX_OP,HTTP_REQUEST_PATH_SEGMENTS,STX_OP,HTTP_REQUEST_PATH_SEGMENT,"groups",STX_CP,STX_OP,HTTP_REQUEST_PATH_SEGMENT,"5",STX_CP,STX_CP,STX_OP,HTTP_REQUEST_PATH_FILE,STX_OP,FILE_NAME,"users",STX_CP,STX_OP,FILE_EXTENSION,"json",STX_CP,STX_CP,STX_OP,HTTP_REQUEST_PATH_QUERY,STX_OP,HTTP_REQUEST_PATH_QUERY_PARAMS,STX_OP,HTTP_REQUEST_PATH_QUERY_PARAM,STX_OP,PARAM_KEY,"sort_by",STX_CP,STX_OP,PARAM_VALUE,"last_name",STX_CP,STX_CP,STX_OP,HTTP_REQUEST_PATH_QUERY_PARAM,STX_OP,PARAM_KEY,"page",STX_CP,STX_OP,PARAM_VALUE,"2",STX_CP,STX_CP,STX_CP,STX_CP,STX_CP,STX_CP);
G_http_req_example = http_req_example;
sY(INTERNET_CONTEXT,HTTP_CLIENT,RECEPTOR_ADDRESS);
sY(INTERNET_CONTEXT,HTTP_SERVER,RECEPTOR_ADDRESS);
sData(INTERNET_CONTEXT,http_def,STX_OP,PROTOCOL_DEFINITION,STX_OP,PROTOCOL_SEMANTICS,STX_CP,STX_OP,INCLUSION,STX_OP,PNAME,REQUESTING,STX_CP,STX_OP,CONNECTION,STX_OP,WHICH_ROLE,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,ROLE,HTTP_CLIENT,STX_CP,STX_CP,STX_CP,STX_OP,CONNECTION,STX_OP,WHICH_ROLE,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,ROLE,HTTP_SERVER,STX_CP,STX_CP,STX_CP,STX_OP,RESOLUTION,STX_OP,WHICH_SYMBOL,STX_OP,USAGE,REQUEST_DATA,STX_CP,STX_OP,ACTUAL_SYMBOL,HTTP_REQUEST,STX_CP,STX_CP,STX_CP,STX_OP,RESOLUTION,STX_OP,WHICH_SYMBOL,STX_OP,USAGE,RESPONSE_DATA,STX_CP,STX_OP,ACTUAL_SYMBOL,HTTP_RESPONSE,STX_CP,STX_CP,STX_CP,STX_CP,STX_CP);
sProt(INTERNET_CONTEXT,HTTP,http_def);
}

void base_contexts(SemTable *sem) {
Expand Down
6 changes: 6 additions & 0 deletions src/base_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@ enum INTERNETSymbolIDs {
HTML_FORM_ID,
HTML_INPUT_ID,
HTML_BUTTON_ID,
HTTP_CLIENT_ID,
HTTP_SERVER_ID,
NUM_INTERNET_SYMBOLS
};
SemanticID OCTET_STREAM;
Expand Down Expand Up @@ -1186,6 +1188,8 @@ SemanticID HTML_H4;
SemanticID HTML_FORM;
SemanticID HTML_INPUT;
SemanticID HTML_BUTTON;
SemanticID HTTP_CLIENT;
SemanticID HTTP_SERVER;

/**********************************************************************************/
// INTERNET:Structure
Expand Down Expand Up @@ -1229,8 +1233,10 @@ enum INTERNETProcessIDs {
// INTERNET:Protocol
enum INTERNETProtocolIDs {
NULL_INTERNET_PROTOCOL_ID,
HTTP_ID,
NUM_INTERNET_PROTOCOLS
};
SemanticID HTTP;

//Global data from base_defs
T * G_http_req_example;
Expand Down
31 changes: 29 additions & 2 deletions web/sysdefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2541,10 +2541,37 @@
{"sem":{ "ctx":0,"type":2,"id":18 },"surface":{ "ctx":7,"type":1,"id":12 }}]},
{"sem":{ "ctx":0,"type":2,"id":20 },"children":[
{"sem":{ "ctx":0,"type":2,"id":19 },"surface":"HTML_BUTTON"},
{"sem":{ "ctx":0,"type":2,"id":18 },"surface":{ "ctx":7,"type":1,"id":12 }}]}]},
{"sem":{ "ctx":0,"type":2,"id":18 },"surface":{ "ctx":7,"type":1,"id":12 }}]},
{"sem":{ "ctx":0,"type":2,"id":20 },"children":[
{"sem":{ "ctx":0,"type":2,"id":19 },"surface":"HTTP_CLIENT"},
{"sem":{ "ctx":0,"type":2,"id":18 },"surface":{ "ctx":0,"type":1,"id":43 }}]},
{"sem":{ "ctx":0,"type":2,"id":20 },"children":[
{"sem":{ "ctx":0,"type":2,"id":19 },"surface":"HTTP_SERVER"},
{"sem":{ "ctx":0,"type":2,"id":18 },"surface":{ "ctx":0,"type":1,"id":43 }}]}]},
{"sem":{ "ctx":0,"type":2,"id":3 }},
{"sem":{ "ctx":0,"type":2,"id":5 }},
{"sem":{ "ctx":0,"type":2,"id":4 }},
{"sem":{ "ctx":0,"type":2,"id":4 },"children":[
{"sem":{ "ctx":0,"type":2,"id":140 },"children":[
{"sem":{ "ctx":0,"type":2,"id":138 },"surface":"HTTP"},
{"sem":{ "ctx":0,"type":2,"id":139 }},
{"sem":{ "ctx":0,"type":2,"id":119 },"children":[
{"sem":{ "ctx":0,"type":2,"id":118 },"surface":{ "ctx":2,"type":5,"id":1 }},
{"sem":{ "ctx":0,"type":2,"id":136 },"children":[
{"sem":{ "ctx":0,"type":2,"id":133 },"children":[
{"sem":{ "ctx":0,"type":2,"id":88 },"surface":{ "ctx":2,"type":2,"id":1 }},
{"sem":{ "ctx":0,"type":2,"id":88 },"surface":{ "ctx":7,"type":2,"id":55 }}]}]},
{"sem":{ "ctx":0,"type":2,"id":136 },"children":[
{"sem":{ "ctx":0,"type":2,"id":133 },"children":[
{"sem":{ "ctx":0,"type":2,"id":88 },"surface":{ "ctx":2,"type":2,"id":2 }},
{"sem":{ "ctx":0,"type":2,"id":88 },"surface":{ "ctx":7,"type":2,"id":56 }}]}]},
{"sem":{ "ctx":0,"type":2,"id":131 },"children":[
{"sem":{ "ctx":0,"type":2,"id":128 },"children":[
{"sem":{ "ctx":0,"type":2,"id":89 },"surface":{ "ctx":2,"type":2,"id":3 }},
{"sem":{ "ctx":0,"type":2,"id":123 },"surface":{ "ctx":7,"type":2,"id":19 }}]}]},
{"sem":{ "ctx":0,"type":2,"id":131 },"children":[
{"sem":{ "ctx":0,"type":2,"id":128 },"children":[
{"sem":{ "ctx":0,"type":2,"id":89 },"surface":{ "ctx":2,"type":2,"id":4 }},
{"sem":{ "ctx":0,"type":2,"id":123 },"surface":{ "ctx":7,"type":2,"id":24 }}]}]}]}]}]},
{"sem":{ "ctx":0,"type":2,"id":6 }}]}]}]},
{"sem":{ "ctx":0,"type":2,"id":4 }},
{"sem":{ "ctx":0,"type":2,"id":6 }}]}

0 comments on commit 2fa5f20

Please sign in to comment.