Commit 095e1ebe authored by Bernhard Link's avatar Bernhard Link

allow to TRANSFER data from REQUEST to RESPONSE on the stack

parent fb20bfeb
2011-01-28
* allow to TRANSFER data from REQUEST to RESPONSE on the stack
2010-12-22
* Add INT32_32 type for a 64 bit integer stored in two 32 bit integers
* Add SYNC extension
......
......@@ -181,6 +181,7 @@ struct expectedreply {
const struct extension *extension;
struct unknownextension *uextension;
} data;
unsigned long values[];
};
const struct extension *find_extension(const uint8_t *name,size_t len);
......@@ -1597,7 +1598,9 @@ static inline void print_client_request(struct connection *c,bool bigrequest) {
}
if( r->answers != NULL ) {
/* register an awaited response */
struct expectedreply *a = malloc(sizeof(struct expectedreply));
int vc = r->record_variables;;
struct expectedreply *a = malloc(sizeof(struct expectedreply)
+ vc * sizeof(long));
if( a == NULL )
abort();
a->next = c->expectedreplies;
......@@ -1605,6 +1608,12 @@ static inline void print_client_request(struct connection *c,bool bigrequest) {
a->from = r;
a->data_type = dt_NONE;
a->data.data = NULL;
while( vc > 0 ) {
if( stack.ofs > 0 )
a->values[--vc] = stack.base[--stack.ofs];
else
a->values[--vc] = 0;
}
if( r->request_func != NULL )
(void)r->request_func(c,false,bigrequest,a);
c->expectedreplies = a;
......@@ -1731,6 +1740,7 @@ static inline void print_server_reply(struct connection *c) {
if( !ignore ) {
const char *name = replyto->from->name;
int i;
if( name == NULL )
name = "UNKNOWN";
......@@ -1738,6 +1748,11 @@ static inline void print_server_reply(struct connection *c) {
seq,
(unsigned int)c->serverignore,
name);
for( i = 0;
i < replyto->from->record_variables;
i++ ) {
push(&stack, replyto->values[i]);
}
print_parameters(c, c->serverbuffer, len,
replyto->from->answers, false, &stack);
putc('\n',out);
......
......@@ -18,6 +18,8 @@ struct request {
request_func *request_func;
reply_func *reply_func;
/* stack values to be transfered to the reply code */
int record_variables;
};
struct event {
const char *name;
......
......@@ -181,6 +181,7 @@ struct namespace {
bool has_response;
bool unsupported;
bool special;
int record_variables;
struct variable *request, *response;
} *requests;
int num_events[event_COUNT];
......@@ -1250,6 +1251,7 @@ static void parse_request(struct parser *parser, bool template) {
struct variable *v = NULL;
bool complete = false;
struct request_data *request;
long record = 0;
name = get_const_token(parser, false);
while( (attribute = get_const_token(parser, true)) != NULL ) {
......@@ -1258,6 +1260,11 @@ static void parse_request(struct parser *parser, bool template) {
v = find_variable(parser, vt_request, t);
if( v == NULL )
return;
} else if( strncmp(attribute, "TRANSFER=", 9) == 0 ) {
char *e;
record = strtoll(attribute + 9, &e, 10);
if( *e != '\0' || record > 30 || record <= 0 )
error(parser, "Parse error: invalid number after 'TRANSFER='!");
} else {
error(parser, "Unknown REQUEST attribute '%s'!",
attribute);
......@@ -1279,6 +1286,10 @@ static void parse_request(struct parser *parser, bool template) {
error(parser, "'%s' is already listed in REQUESTS, thus cannot be a template!", name);
return;
}
if( record > 0 ) {
error(parser, "TRANSFER not possible for templated");
return;
}
} else {
if( request == NULL ) {
error(parser, "Unknow request '%s'! (Must be listed in REQUESTS or use templateREQUEST", name);
......@@ -1294,6 +1305,13 @@ static void parse_request(struct parser *parser, bool template) {
parser->current->namespace->name,
name);
}
if( record > 0 ) {
if( !request->has_response ) {
error(parser, "TRANSFER only possible if it RESPONDS!");
return;
}
request->record_variables = record;
}
request->request = v;
v->refcount ++;
}
......@@ -2330,6 +2348,7 @@ static const struct request *finalize_requests(struct parser *parser, struct nam
}
} else
assert( ns->requests[i].response == NULL);
rs[i].record_variables = ns->requests[i].record_variables;
if( !ns->requests[i].special )
continue;
assert( rs[i].name != NULL );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment