ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
http_example.h
Go to the documentation of this file.
1 
7 #ifndef _CEPTR_TEST_HTTP_EXAMPLE_H
8 #define _CEPTR_TEST_HTTP_EXAMPLE_H
9 
10 #include "../src/ceptr.h"
11 #include "../src/receptor.h"
12 #include "../src/protocol.h"
13 #include "../src/def.h"
14 #include "../src/semtrex.h"
15 #include "spec_utils.h"
16 #include "../src/vmhost.h"
17 #include "../src/accumulator.h"
18 #include <unistd.h>
19 
21 
27  T *t = _t_clone(G_http_req_example);
28 
29  // confirm that we built the request right!
30  T *stx = _d_build_def_semtrex(G_sem,HTTP_REQUEST,0);
31  // puts(t2s(stx));
32  // puts(t2s(t));
33  // stx = _t_parse(G_sem,0,"(SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST) (SEMTREX_SEQUENCE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_LINE)) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_HEADERS) (SEMTREX_SEQUENCE (SEMTREX_ZERO_OR_MORE (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:CONTENT_ENCODING))))) (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:HTTP_REQUEST_BODY))))");
34  if (!_t_match(stx,t)) {raise_error("BAD HTTP_REQUEST semtrex");}
35  _t_free(stx);
36 
37  // all our examples are expecting the HTTP_REQUEST_LINE
38  T *c = _t_detach_by_idx(t,1);
39  _t_free(t);
40  return c;
41 }
43 
44 
46 
52  // the action simply responds back with the method that was originally sent
53  // this test should be made more real... but for now it responds back with a ping
54  // like message that contains what the first path segment was
55 
56  T *resp = _t_new_root(RESPOND);
57  _t_news(resp,CARRIER,HTTP_RESPONSE);
58  int pt1[] = {2,1,TREE_PATH_TERMINATOR};
59  _t_new(resp,PARAM_REF,pt1,sizeof(int)*3);
60 
61  Process p = _r_define_process(r,resp,"code path ping","respond with the value of the first parameter",NULL,NULL);
62  *pP = p;
63 
64  T *params = _t_build(G_sem,0,
65  PARAMS,
66  HTTP_RESPONSE,
67  HTTP_RESPONSE_STATUS,STATUS_VALUE,200,STATUS_TEXT,"OK",NULL_SYMBOL,
68  HTTP_HEADERS,
69  CONTENT_TYPE,MEDIA_TYPE_IDENT,TEXT_MEDIA_TYPE,MEDIA_SUBTYPE_IDENT,CEPTR_TEXT_MEDIA_SUBTYPE,NULL_SYMBOL,NULL_SYMBOL,
70  HTTP_RESPONSE_BODY,
71  SLOT,USAGE,HTTP_REQUEST_PATH_SEGMENT,NULL_SYMBOL,
72  NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL
73  );
74 
75 
76  /* _t_new_root(PARAMS); */
77  /* T *http_resp = _t_newr(params,HTTP_RESPONSE); */
78  /* _t_new(http_resp,HTTP_RESPONSE_CONTENT_TYPE,"CeptrSymbol/HTTP_REQUEST_PATH_SEGMENT",38); */
79  /* T *s = _t_newr(http_resp,SLOT); */
80  /* _t_news(s,USAGE,HTTP_REQUEST_PATH_SEGMENT); */
81  *paramsP = params;
82 }
84 
85 char *G_stxs = "/ASCII_CHARS/<HTTP_REQUEST:<HTTP_REQUEST_METHOD:ASCII_CHAR!=' '+>,ASCII_CHAR=' ',<HTTP_REQUEST_PATH:<HTTP_REQUEST_PATH_SEGMENTS:(ASCII_CHAR='/',<HTTP_REQUEST_PATH_SEGMENT:ASCII_CHAR!={'/','?',' '}*>)+>>,(ASCII_CHAR='?',<HTTP_REQUEST_PATH_QUERY:<HTTP_REQUEST_PATH_QUERY_PARAMS:(<HTTP_REQUEST_PATH_QUERY_PARAM:<PARAM_KEY:ASCII_CHAR!={'&',' ','='}+>,ASCII_CHAR='=',<PARAM_VALUE:ASCII_CHAR!={'&',' '}*>>,ASCII_CHAR='&'?)+>+>)?,ASCII_CHAR=' ',ASCII_CHAR='H',ASCII_CHAR='T',ASCII_CHAR='T',ASCII_CHAR='P',ASCII_CHAR='/',<HTTP_REQUEST_VERSION:<VERSION_MAJOR:ASCII_CHAR='0'>,ASCII_CHAR='.',<VERSION_MINOR:ASCII_CHAR='9'>>>";
86 
92  T *t = parseSemtrex(G_sem,G_stxs);
93  return t;
94 
95  T *stx= _sl(0,ASCII_CHARS);
96  t = _t_news(stx,SEMTREX_GROUP,HTTP_REQUEST);
97  T *sq = _t_newr(t,SEMTREX_SEQUENCE);
98  t = _t_news(sq,SEMTREX_GROUP,HTTP_REQUEST_METHOD);
99  t = _t_newr(t,SEMTREX_ONE_OR_MORE);
100  __stxcvm(t,1,1,' ');
101  __stxcv(sq,' ');
102 
103  t = _t_news(sq,SEMTREX_GROUP,HTTP_REQUEST_PATH);
104  T *sqq = _t_newr(t,SEMTREX_SEQUENCE);
105 
106  t = _t_news(sqq,SEMTREX_GROUP,HTTP_REQUEST_PATH_SEGMENTS);
107  t = _t_newr(t,SEMTREX_ONE_OR_MORE);
108  t = _t_newr(t,SEMTREX_SEQUENCE);
109  __stxcv(t,'/');
110  t = _t_news(t,SEMTREX_GROUP,HTTP_REQUEST_PATH_SEGMENT);
111  t = _t_newr(t,SEMTREX_ZERO_OR_MORE);
112  __stxcvm(t,1,3,'/','?',' ');
113 
114  /* t = _t_news(sq,SEMTREX_GROUP,HTTP_REQUEST_PATH_FILE); */
115  /* T *f = _t_newr(t,SEMTREX_SEQUENCE); */
116  /* t = _t_news(f,SEMTREX_GROUP,FILE_NAME); */
117  /* t = _t_newr(t,SEMTREX_ONE_OR_MORE); */
118  /* __stxcvm(t,1,2,'?',' '); */
119 
120  /* t = _t_newr(f,SEMTREX_ZERO_OR_ONE); */
121  /* t = _t_newr(t,SEMTREX_SEQUENCE); */
122  /* __stxcv(t,'.'); */
123  /* t = _t_news(t,SEMTREX_GROUP,FILE_EXTENSION); */
124  /* t = _t_newr(t,SEMTREX_ONE_OR_MORE); */
125  /* __stxcvm(t,1,2,'?',' '); */
126 
127  t = _t_newr(sq,SEMTREX_ZERO_OR_ONE);
128  t = _t_newr(t,SEMTREX_SEQUENCE);
129  __stxcv(t,'?');
130 
131  T *f;
132  t = _t_news(t,SEMTREX_GROUP,HTTP_REQUEST_PATH_QUERY);
133  t = _t_newr(t,SEMTREX_ONE_OR_MORE);
134  t = _t_news(t,SEMTREX_GROUP,HTTP_REQUEST_PATH_QUERY_PARAMS);
135  t = _t_newr(t,SEMTREX_ONE_OR_MORE);
136  T *qps = _t_newr(t,SEMTREX_SEQUENCE);
137  t = _t_news(qps,SEMTREX_GROUP,HTTP_REQUEST_PATH_QUERY_PARAM);
138  f = _t_newr(t,SEMTREX_SEQUENCE);
139  t = _t_news(f,SEMTREX_GROUP,PARAM_KEY);
140  t = _t_newr(t,SEMTREX_ONE_OR_MORE);
141  __stxcvm(t,1,3,'&',' ','=');
142  __stxcv(f,'=');
143  t = _t_news(f,SEMTREX_GROUP,PARAM_VALUE);
144  t = _t_newr(t,SEMTREX_ZERO_OR_MORE);
145  __stxcvm(t,1,2,'&',' ');
146 
147  t = _t_newr(qps,SEMTREX_ZERO_OR_ONE);
148  __stxcv(t,'&');
149 
150  __stxcv(sq,' ');
151 
152  __stxcv(sq,'H');
153  __stxcv(sq,'T');
154  __stxcv(sq,'T');
155  __stxcv(sq,'P');
156  __stxcv(sq,'/');
157  t = _t_news(sq,SEMTREX_GROUP,HTTP_REQUEST_VERSION);
158  t = _t_newr(t,SEMTREX_SEQUENCE);
159  f = _t_news(t,SEMTREX_GROUP,VERSION_MAJOR);
160  __stxcv(f,'0');
161  __stxcv(t,'.');
162  f = _t_news(t,SEMTREX_GROUP,VERSION_MINOR);
163  __stxcv(f,'9');
164  return stx;
165 }
166 
167 T *makeDeltaAdd(T *src,T *t) {
168  int *path = _t_get_path(src);
169  T *d = makeDelta(TREE_DELTA_ADD,path,t,0);
170  free(path);
171  return d;
172 }
173 
174 Symbol getTag(char *otag,Symbol tag_sym[],char *tag_str[]) {
175  Symbol ts = NULL_SYMBOL;
176  int i;
177  for(i=0;i<15;i++) {
178  if (!strcicmp(otag,tag_str[i])) {ts = tag_sym[i];break;}
179  }
180  if (semeq(ts,NULL_SYMBOL)) {raise_error("invalid tag: %s",otag);}
181  return ts;
182 }
183 
184 T *parseHTML(char *html) {
185 
186  Symbol G_tag_sym[] = {HTML_HTML,HTML_HEAD,HTML_TITLE,HTML_BODY,HTML_DIV,HTML_P,HTML_A,HTML_B,HTML_UL,HTML_OL,HTML_LI,HTML_SPAN,HTML_H1,HTML_H2,HTML_H3,HTML_H4,HTML_FORM};
187  char *G_tag_str[] ={"html","head","title","body","div","p","a","b","ul","ol","li","span","h1","h2","h3","h4","form"};
188 
189  Symbol G_stag_sym[] = {HTML_IMG,HTML_INPUT,HTML_BUTTON};
190  char *G_stag_str[] ={"img","input","button"};
191 
192  T *t,*h = makeASCIITree(html);
193 
195  // build the token stream out of an ascii stream
196  // PATTERN
197  T *s;
198  char *stx = "/ASCII_CHARS/<HTML_TOKENS:(ASCII_CHAR='<',<HTML_TOK_TAG_SELFCLOSE:ASCII_CHAR!={'>',' '}+>,<HTML_ATTRIBUTES:(ASCII_CHAR=' ',<HTML_ATTRIBUTE:<PARAM_KEY:ASCII_CHAR!={'>',' ','='}+>,ASCII_CHAR='=',ASCII_CHAR='\"',<PARAM_VALUE:ASCII_CHAR!='\"'+>,ASCII_CHAR='\"'>)*>,ASCII_CHAR='/',ASCII_CHAR='>'|ASCII_CHAR='<',ASCII_CHAR='/',<HTML_TOK_TAG_CLOSE:ASCII_CHAR!='>'+>,ASCII_CHAR='>'|ASCII_CHAR='<',<HTML_TOK_TAG_OPEN:ASCII_CHAR!={'>',' '}+>,<HTML_ATTRIBUTES:(ASCII_CHAR=' ',<HTML_ATTRIBUTE:<PARAM_KEY:ASCII_CHAR!={'>',' ','='}+>,ASCII_CHAR='=',ASCII_CHAR='\"',<PARAM_VALUE:ASCII_CHAR!='\"'+>,ASCII_CHAR='\"'>)*>,ASCII_CHAR='>'|<HTML_TEXT:ASCII_CHAR!='<'+>)+>";
199 
200  s = parseSemtrex(G_sem,stx);
201 
202  int fnc = 0;
203  wjson(G_sem,s,"htmlparse",-1);
204  wjson(G_sem,h,"htmlascii",-1);
205 
206  T *results,*tokens;
207  if (_t_matchr(s,h,&results)) {
208  tokens = _t_new_root(HTML_TOKENS);
209  int i,m = _t_children(results);
210  wjson(G_sem,tokens,"html",fnc++);
211  T *delta,*src;
212  for(i=4;i<=m;i++) {
213  T *c = _t_child(results,i);
214  T *sn = _t_child(c,1);
215  Symbol ts = *(Symbol *)_t_surface(sn);
216  if (semeq(ts,HTML_ATTRIBUTES)) {
217  T *a = _t_new_root(HTML_ATTRIBUTES);
218  int j,ac = _t_children(c);
219  for(j=4;j<=ac;j++) {
220  T *attr = _t_newr(a,HTML_ATTRIBUTE);
221  T *at = _t_child(c,j);
222  T *m = _t_get_match(at,PARAM_KEY);
223  asciiT_tos(h,m,attr,PARAM_KEY);
224  m = _t_get_match(at,PARAM_VALUE);
225  asciiT_tos(h,m,attr,PARAM_VALUE);
226  }
227  // we can just add the attribute directly to the previous token which will be the open tag tokens
228  src = _t_child(tokens,_t_children(tokens));
229  delta = a;
230  _t_add(src,a);
231  }
232  else {
233  src = tokens;
234  delta = asciiT_tos(h,c,tokens,ts);
235  }
236  delta = makeDeltaAdd(src,delta);
237  wjson(G_sem,delta,"html",fnc++);
238  _t_free(delta);
239  }
240  _t_free(results);
241  _t_free(s);
242 
243  s = _t_new_root(SEMTREX_WALK);
244  // T *st = _t_newr(sq,SEMTREX_ZERO_OR_MORE);
245  // _t_newr(st,SEMTREX_SYMBOL_ANY);
246  T *g = _t_news(s,SEMTREX_GROUP,HTML_TAG);
247  T *sq = _t_newr(g,SEMTREX_SEQUENCE);
248  _sl(sq,HTML_TOK_TAG_OPEN);
249  g = _t_news(sq,SEMTREX_GROUP,HTML_CONTENT);
250  T* st = _t_newr(g,SEMTREX_ZERO_OR_MORE);
251  __sl(st,1,2,HTML_TOK_TAG_OPEN,HTML_TOK_TAG_CLOSE);
252  _sl(sq,HTML_TOK_TAG_CLOSE);
253 
254  // stx = "%<HTML_TAG:HTML_TOK_TAG_OPEN,!{HTML_TOK_TAG_OPEN,HTML_TOK_TAG_CLOSE},HTML_TOK_TAG_CLOSE>";
255  //s = parseSemtrex(d,stx);
256  // return tokens;
257  while (_t_matchr(s,tokens,&results)) {
258  T *m = _t_get_match(results,HTML_TAG);
259  int *path = _t_surface(_t_child(m,2));
260  int count = *(int *)_t_surface(_t_child(results,3));
261  T *ot = _t_get(tokens,path);
262  path[_t_path_depth(path)-1] += count-1;
263  T *ct = _t_get(tokens,path);
264  char *otag = _t_surface(ot);
265  char *ctag = _t_surface(ct);
266  if (strcmp(otag,ctag)) {raise_error("Mismatched tags %s,%s",otag,ctag)};
267 
268  Symbol ts = getTag(otag,G_tag_sym,G_tag_str);
269  path[_t_path_depth(path)-1] -= count-1;
270  T *content = wrap(tokens,results,HTML_CONTENT,HTML_TAG);
271  T *attributes = _t_detach_by_idx(content,1);
272  __t_morph(content,HTML_CONTENT,0,0,0);
273  T *p = _t_parent(content);
274  _t_detach_by_ptr(p,content);
275  T *tag = _t_new_root(ts);
276  _t_add(tag,attributes);
277  _t_add(tag,content);
278  _t_insert_at(tokens,path,tag);
279  delta = makeDelta(TREE_DELTA_REPLACE,path,tag,count);
280  wjson(G_sem,delta,"html",fnc++);
281  _t_free(delta);
282  _t_free(results);
283  }
284  _t_free(s);
285 
286  s = _t_new_root(SEMTREX_WALK);
287  g = _t_news(s,SEMTREX_GROUP,HTML_TAG);
288  _sl(g,HTML_TOK_TAG_SELFCLOSE);
289  while (_t_matchr(s,tokens,&results)) {
290  T *m = _t_get_match(results,HTML_TAG);
291  int *path = _t_surface(_t_child(m,2));
292  T *t = _t_get(tokens,path);
293  char *otag = _t_surface(t);
294  Symbol ts = getTag(otag,G_stag_sym,G_stag_str);
295  __t_morph(t,ts,0,0,0);
296  _t_newr(t,HTML_CONTENT);
297  delta = makeDelta(TREE_DELTA_REPLACE,path,t,1);
298  wjson(G_sem,delta,"html",fnc++);
299  _t_free(delta);
300  _t_free(results);
301 
302  }
303  _t_free(s);
304  results = _t_detach_by_idx(tokens,1);
305  _t_free(tokens);
306  _t_free(h);
307  return results;
308  }
309  raise_error("HTML doesn't match");
310 }
311 
312 void testHTTPparseHTML() {
313  T *t = parseHTML("<html><body><div>Hello <b>world!</b></div></body></html>");
314 
315  spec_is_str_equal(t2s(t),"(HTML_HTML (HTML_ATTRIBUTES) (HTML_CONTENT (HTML_BODY (HTML_ATTRIBUTES) (HTML_CONTENT (HTML_DIV (HTML_ATTRIBUTES) (HTML_CONTENT (HTML_TEXT:Hello ) (HTML_B (HTML_ATTRIBUTES) (HTML_CONTENT (HTML_TEXT:world!)))))))))");
316 
317  _t_free(t);
318 
319 }
320 
321 //Host: fish.com\n\n
322 void *_httptester(void *arg) {
323  char *result = doSys("echo 'GET /path/to/file.ext HTTP/0.9' | nc localhost 8888");
324  spec_is_str_equal(result,"HTTP/1.1 200 OK\nContent-Type: text/ceptr\n\nsuper cept\n314159\n");
325  free(result);
326  G_done = true;
327  pthread_exit(NULL);
328 }
329 
330 void testHTTPedgeReceptor() {
331 
332  //setup vmhost instance
333  VMHost *v = G_vm = _v_new();
334  SemTable *gsem = G_sem;
335  G_sem = v->sem;
336  // _v_instantiate_builtins(G_vm);
337 
338  Symbol HTTP;
339  _sem_get_by_label(G_sem,"HTTP",&HTTP);
340 
341  T *http_def = _sem_get_def(G_sem,HTTP);
342 
343  // check the HTTP protocol definition
344  spec_is_str_equal(t2s(http_def),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:HTTP)) (PROTOCOL_SEMANTICS (GOAL:HTTP_REQUEST_HANDLER)) (INCLUSION (PNAME:REQUESTING) (LINKAGE (WHICH_ROLE (ROLE:REQUESTER) (ROLE:HTTP_CLIENT))) (LINKAGE (WHICH_ROLE (ROLE:RESPONDER) (ROLE:HTTP_SERVER))) (RESOLUTION (WHICH_SYMBOL (USAGE:REQUEST_TYPE) (ACTUAL_SYMBOL:HTTP_REQUEST))) (RESOLUTION (WHICH_SYMBOL (USAGE:RESPONSE_TYPE) (ACTUAL_SYMBOL:HTTP_RESPONSE))) (RESOLUTION (WHICH_SYMBOL (USAGE:CHANNEL) (ACTUAL_SYMBOL:HTTP_ASPECT))) (RESOLUTION (WHICH_PROCESS (GOAL:REQUEST_HANDLER) (ACTUAL_PROCESS:httpresp)))))");
345 
346  T *sem_map = _t_new_root(SEMANTIC_MAP);
347  T *t = _o_unwrap(G_sem,http_def,sem_map);
348  // and also check how it gets unwrapped because it's defined in terms of REQUESTING
349  // @todo, how come HTTP_SERVER and the two handler goals aren't added to the semantics?
350  spec_is_str_equal(t2s(t),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:HTTP)) (PROTOCOL_SEMANTICS (GOAL:HTTP_REQUEST_HANDLER) (ROLE:HTTP_CLIENT) (USAGE:RESPONSE_HANDLER_PARAMETERS)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))) (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))))");
351 
352  // the unwrapping should build up a semantic map
353  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_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:HTTP_REQUEST))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:HTTP_RESPONSE))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:HTTP_ASPECT))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:httpresp))))");
354  _t_free(sem_map);
355 
356  // create empty edge receptor
357  Receptor *r = _r_makeStreamEdgeReceptor(v->sem);
358  // instantiate it in the vmhost
359  Xaddr edge = _v_new_receptor(v,v->r,STREAM_EDGE,r);
360  // set up a socket listener that will transcode ascii to HTTP_REQUEST and send all the received requests to an HTTP aspect on the same receptor
361  T *code = _t_parse(r->sem,0,"(CONVERSE (SCOPE (ITERATE (PARAMS) (STREAM_ALIVE (PARAM_REF:/2/1)) (INITIATE_PROTOCOL (PNAME:HTTP) (WHICH_INTERACTION:backnforth) (PROTOCOL_BINDINGS (RESOLUTION (WHICH_RECEPTOR (ROLE:HTTP_CLIENT) %)) (RESOLUTION (WHICH_RECEPTOR (ROLE:HTTP_SERVER) %)) (RESOLUTION (WHICH_PROCESS (GOAL:RESPONSE_HANDLER) (ACTUAL_PROCESS:echo2stream))) (RESOLUTION (WHICH_USAGE (USAGE:RESPONSE_HANDLER_PARAMETERS) (ACTUAL_VALUE (PARAM_REF:/2/1)))) (RESOLUTION (WHICH_VALUE (ACTUAL_SYMBOL:HTTP_REQUEST) (ACTUAL_VALUE (STREAM_READ (PARAM_REF:/2/1) (RESULT_SYMBOL:HTTP_REQUEST)))))) ) ) (STREAM_CLOSE (PARAM_REF:/2/1))) (BOOLEAN:1))",__r_make_addr(0,ACTUAL_RECEPTOR,r->addr),__r_make_addr(0,ACTUAL_RECEPTOR,r->addr));
362  // add an error handler that just completes the iteration
363  T *err_handler = _t_parse(r->sem,0,"(CONTINUE (POP_PATH (PARAM_REF:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:5)) (CONTINUE_VALUE (BOOLEAN:0)))");
364 
365  SocketListener *l = _r_addListener(r,8888,code,0,err_handler,DELIM_LF);
366  _v_activate(v,edge);
367 
368  T *bindings = _t_new_root(PROTOCOL_BINDINGS);
369  T *res = _t_newr(bindings,RESOLUTION);
370  T *w = _t_newr(res,WHICH_RECEPTOR);
371  _t_news(w,ROLE,HTTP_SERVER);
372  __r_make_addr(w,ACTUAL_RECEPTOR,r->addr);
373  res = _t_newr(bindings,RESOLUTION);
374  w = _t_newr(res,WHICH_PROCESS);
375  _t_news(w,GOAL,HTTP_REQUEST_HANDLER);
376  _t_news(w,ACTUAL_PROCESS,fill_i_am);
377 
378  _o_express_role(r,HTTP,HTTP_SERVER,HTTP_ASPECT,bindings);
379  _t_free(bindings);
380 
381  // debug_enable(D_TRANSCODE+D_STEP+D_STREAM);
382  //debug_enable(D_SIGNALS+D_STEP+D_STREAM);
383  _v_start_vmhost(G_vm);
384 
385  G_done = false;
386  pthread_t thread;
387  int rc;
388  rc = pthread_create(&thread,0,_httptester,NULL);
389  if (rc){
390  raise_error("ERROR; return code from pthread_create() is %d\n", rc);
391  }
392  pthread_detach(thread);
393  if (rc){
394  raise_error("Error detaching tester thread; return code from pthread_detach() is %d\n", rc);
395  }
396  while(!G_done) sleepms(1);
397  sleepms(1);
398  debug_disable(D_STREAM+D_SIGNALS+D_TREE+D_PROTOCOL);
399  debug_disable(D_TRANSCODE+D_REDUCE+D_REDUCEV+D_STEP);
400 
401  //spec_is_str_equal(t2s(r->flux),"");
402 
403  // cleanup vmhost instance
404  __r_kill(G_vm->r);
405  // _v_join_thread(&G_vm->clock_thread);
406  _v_join_thread(&G_vm->vm_thread);
407 
408  _v_free(v);
409  G_vm = NULL;
410  G_sem = gsem;
411 
412 }
413 
414 
415 void testHTTP() {
416  testHTTPparseHTML();
417  testHTTPedgeReceptor();
418 }
419 
420 #endif
421 //
T * _t_new_root(Symbol symbol)
Definition: tree.c:160
Definition: ceptr_types.h:114
T * asciiT_tos(T *asciiT, T *match, T *t, Symbol s)
Definition: semtrex.c:1261
T * _t_get(T *t, int *p)
Definition: tree.c:1441
T * _makeHTTPRequestSemtrex()
Definition: http_example.h:91
T * _t_detach_by_idx(T *t, int i)
Definition: tree.c:278
int _t_path_depth(int *p)
Definition: tree.c:1365
int * _t_get_path(T *t)
Definition: tree.c:1384
T * _t_clone(T *t)
Definition: tree.c:589
T * __sl(T *p, bool not, int count,...)
Definition: semtrex.c:1279
T * _t_child(T *t, int i)
Definition: tree.c:1251
T * makeASCIITree(char *c)
Definition: semtrex.c:1206
T * _d_build_def_semtrex(SemTable *sem, Symbol s, T *parent)
Definition: def.c:433
void _t_insert_at(T *t, int *path, T *i)
Definition: tree.c:438
void _v_free(VMHost *v)
Definition: vmhost.c:71
ReceptorAddress addr
the address by which to get messages to this receptor instance
Definition: ceptr_types.h:241
Definition: vmhost.h:20
VMHost * _v_new()
Creates a new virtual machine host.
Definition: vmhost.c:41
int _t_match(T *semtrex, T *t)
Definition: semtrex.c:809
void * _t_surface(T *t)
Definition: tree.c:1215
T * _o_unwrap(SemTable *sem, T *def, T *sem_map)
Definition: protocol.c:262
T * _t_get_match(T *match, Symbol group)
Definition: semtrex.c:848
void _v_activate(VMHost *v, Xaddr x)
Definition: vmhost.c:172
SemTable * sem
Semantic Table for definitions on this host.
Definition: vmhost.h:44
void _makeTestHTTPResponseProcess(Receptor *r, T **paramsP, Process *pP)
[makeTestHTTPRequestTree]
Definition: http_example.h:51
T * _t_parent(T *t)
Definition: tree.c:1262
int _t_matchr(T *semtrex, T *t, T **rP)
Definition: semtrex.c:798
Definition: vmhost.h:40
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
Definition: ceptr_types.h:242
void _o_express_role(Receptor *r, Protocol protocol, Symbol role, Aspect aspect, T *bindings)
Definition: protocol.c:409
T * _makeTestHTTPRequestTree()
[makeTestHTTPRequestTree]
Definition: http_example.h:26
Receptor * r
Receptor data for this vm host.
Definition: vmhost.h:43
#define _sl(t, s)
macro to add a single symbol literal to semtrex tree
Definition: semtrex.h:122
T * parseSemtrex(SemTable *sem, char *stx)
Definition: semtrex.c:1298
T * _t_parse(SemTable *sem, T *parent, char *s,...)
Definition: tree.c:919
void _t_add(T *t, T *c)
Definition: tree.c:261
void __t_morph(T *t, Symbol s, void *surface, size_t size, int allocate)
Definition: tree.c:325
int _t_children(T *t)
Definition: tree.c:1205
char * G_stxs
[makeTestHTTPResponseProcess]
Definition: http_example.h:85
Process _r_define_process(Receptor *r, T *code, char *name, char *intention, T *signature, T *link)
Definition: receptor.c:275
void _t_detach_by_ptr(T *t, T *c)
Definition: tree.c:291
void _t_free(T *t)
Definition: tree.c:526
T * _t_build(SemTable *sem, T *parent,...)
Definition: tree.c:635