mirror of
git://git.psyced.org/git/psyced
synced 2024-08-15 03:25:10 +00:00
spyc/parser reorg - moved old code to the bottom
This commit is contained in:
parent
9ded39dbdb
commit
7453aaf395
2 changed files with 68 additions and 64 deletions
|
@ -176,7 +176,7 @@ void dispatch(mapping rvars, mapping evars, mixed method, mixed body) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC
|
||||||
if (!process_var_types(evars))t
|
if (!process_var_types(evars))
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,14 @@ int may_parse_more;
|
||||||
private string body_buffer;
|
private string body_buffer;
|
||||||
int body_len;
|
int body_len;
|
||||||
|
|
||||||
// tempoary used to hold assigment lists vname -> ({ glyph, state, vvalue })
|
// temporary used to hold assigment lists vname -> ({ glyph, state, vvalue })
|
||||||
|
// this won't work anymore, dispatch now expects two mappings: rvars & evars
|
||||||
array(mixed) tvars;
|
array(mixed) tvars;
|
||||||
mapping hvars;
|
mapping hvars;
|
||||||
#endif
|
// prototypes
|
||||||
|
parse_header();
|
||||||
|
buffer_content();
|
||||||
|
#endif // LIBPSYC
|
||||||
|
|
||||||
// being faded out in favor of regular croak()
|
// being faded out in favor of regular croak()
|
||||||
#define PARSEERROR(reason) { \
|
#define PARSEERROR(reason) { \
|
||||||
|
@ -61,6 +65,32 @@ void parser_init() {
|
||||||
state = PSYCPARSE_STATE_GREET; // AFTER reset
|
state = PSYCPARSE_STATE_GREET; // AFTER reset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// it is sometimes useful to stop parsing
|
||||||
|
void interrupt_parse() {
|
||||||
|
state = PSYCPARSE_STATE_BLOCKED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// and resume after some blocking operation is done
|
||||||
|
void resume_parse() {
|
||||||
|
state = PSYCPARSE_STATE_HEADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// called when a complete packet has arrived
|
||||||
|
void dispatch(mapping rvars, mapping evars, mixed method, mixed body) {
|
||||||
|
#ifndef LIBPSYC
|
||||||
|
parser_reset();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void psyc_dispatch(mixed p) {
|
||||||
|
dispatch(p[PACKET_ROUTING], p[PACKET_ENTITY], p[PACKET_METHOD], p[PACKET_BODY]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// respond to the first empty packet
|
||||||
|
void first_response() {
|
||||||
|
P0(("parser::first_response called. overload this!"))
|
||||||
|
}
|
||||||
|
|
||||||
// input data to the buffer
|
// input data to the buffer
|
||||||
void feed(string data) {
|
void feed(string data) {
|
||||||
P4((">> feed: %O\n", data));
|
P4((">> feed: %O\n", data));
|
||||||
|
@ -113,16 +143,45 @@ void feed(string data) {
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when a complete packet has arrived
|
// parser stepping function
|
||||||
void dispatch(mixed header_vars, mixed varops, mixed method, mixed body) {
|
void step() {
|
||||||
|
P3(("%O step: state %O, buffer %O\n", ME, state, buffer))
|
||||||
|
if (!strlen(buffer))
|
||||||
|
return;
|
||||||
|
switch(state) {
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC
|
||||||
parser_reset();
|
case PSYCPARSE_STATE_HEADER:
|
||||||
|
parse_header();
|
||||||
|
break;
|
||||||
|
case PSYCPARSE_STATE_CONTENT:
|
||||||
|
buffer_content();
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case PSYCPARSE_STATE_BLOCKED:
|
||||||
|
// someone requested to stop parsing - e.g. _request_features circuit
|
||||||
|
// message
|
||||||
|
break;
|
||||||
|
case PSYCPARSE_STATE_GREET: // wait for greeting
|
||||||
|
if (strlen(buffer) < 2)
|
||||||
|
return;
|
||||||
|
if (buffer[0..1] == DELIM) {
|
||||||
|
state = PSYCPARSE_STATE_HEADER;
|
||||||
|
buffer = buffer[2 ..];
|
||||||
|
first_response();
|
||||||
|
#ifndef LIBPSYC
|
||||||
|
step();
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
croak("_error_syntax_initialization");
|
||||||
|
// "The new protocol begins with a pipe and a line feed.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: // uhm... if we ever get here this is the programmers fault
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void psyc_dispatch(mixed p) {
|
// EOF for LIBPSYC
|
||||||
dispatch(p[PACKET_ROUTING], p[PACKET_ENTITY], p[PACKET_METHOD], p[PACKET_BODY]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC
|
||||||
// processes routing header variable assignments
|
// processes routing header variable assignments
|
||||||
|
@ -371,52 +430,7 @@ void buffer_content() {
|
||||||
P4(("buffer_content: waiting for more plain data. buffer %O vs %O\n", to_array(buffer), to_array("\n" DELIM)))
|
P4(("buffer_content: waiting for more plain data. buffer %O vs %O\n", to_array(buffer), to_array("\n" DELIM)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // LIBPSYC
|
|
||||||
|
|
||||||
// respond to the first empty packet
|
|
||||||
void first_response() {
|
|
||||||
P0(("parser::first_response called. overload this!"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// parser stepping function
|
|
||||||
void step() {
|
|
||||||
P3(("%O step: state %O, buffer %O\n", ME, state, buffer))
|
|
||||||
if (!strlen(buffer))
|
|
||||||
return;
|
|
||||||
switch(state) {
|
|
||||||
#ifndef LIBPSYC
|
|
||||||
case PSYCPARSE_STATE_HEADER:
|
|
||||||
parse_header();
|
|
||||||
break;
|
|
||||||
case PSYCPARSE_STATE_CONTENT:
|
|
||||||
buffer_content();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case PSYCPARSE_STATE_BLOCKED:
|
|
||||||
// someone requested to stop parsing - e.g. _request_features circuit
|
|
||||||
// message
|
|
||||||
break;
|
|
||||||
case PSYCPARSE_STATE_GREET: // wait for greeting
|
|
||||||
if (strlen(buffer) < 2)
|
|
||||||
return;
|
|
||||||
if (buffer[0..1] == DELIM) {
|
|
||||||
state = PSYCPARSE_STATE_HEADER;
|
|
||||||
buffer = buffer[2 ..];
|
|
||||||
first_response();
|
|
||||||
#ifndef LIBPSYC
|
|
||||||
step();
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
croak("_error_syntax_initialization");
|
|
||||||
// "The new protocol begins with a pipe and a line feed.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: // uhm... if we ever get here this is the programmers fault
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef LIBPSYC
|
|
||||||
// FIXME should be in a standalone module
|
// FIXME should be in a standalone module
|
||||||
//#define PARSEERROR(args) debug_message(sprintf("LIST PARSE ERROR: " args));
|
//#define PARSEERROR(args) debug_message(sprintf("LIST PARSE ERROR: " args));
|
||||||
#define LISTSEP '|'
|
#define LISTSEP '|'
|
||||||
|
@ -456,13 +470,3 @@ test() {
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
#endif // !LIBPSYC
|
#endif // !LIBPSYC
|
||||||
|
|
||||||
// it is sometimes useful to stop parsing
|
|
||||||
void interrupt_parse() {
|
|
||||||
state = PSYCPARSE_STATE_BLOCKED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// and resume after some blocking operation is done
|
|
||||||
void resume_parse() {
|
|
||||||
state = PSYCPARSE_STATE_HEADER;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue