source: uKadecot/trunk/kadecot/wamp.c@ 108

Last change on this file since 108 was 108, checked in by coas-nagasima, 7 years ago

MIMEプロパティの変更

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr; charset=SHIFT_JIS
File size: 56.7 KB
Line 
1/*
2 * TOPPERS ECHONET Lite Communication Middleware
3 *
4 * Copyright (C) 2015 Cores Co., Ltd. Japan
5 *
6 * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
7 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
8 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
9 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
10 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
11 * スコード中に含まれていること.
12 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
13 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
14 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
15 * の無保証規定を掲載すること.
16 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
17 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
18 * と.
19 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
20 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
21 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
22 * 報告すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
26 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
27 * 免責すること.
28 *
29 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
30 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
31 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
32 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
33 * の責任を負わない.
34 *
35 * @(#) $Id: wamp.c 108 2015-06-11 09:15:46Z coas-nagasima $
36 */
37
38#include <string.h>
39#include "wamp.h"
40#include "kernel_cfg.h"
41#include "fbs_string.h"
42#include "main.h"
43
44/* パースエラー(定義のみ) */
45const char parse_error[] = "com.sonycsl.kadecot.plugin.echonetlite.error.parse_error";
46/* 無効なリクエスト(定義のみ) */
47const char invalid_request[] = "com.sonycsl.kadecot.plugin.echonetlite.error.invalid_request";
48/* 存在しないメソッド(定義のみ) */
49const char method_not_found[] = "com.sonycsl.kadecot.plugin.echonetlite.error.method_not_found";
50/* echo objectが存在しない, JSONArray形式になっていない */
51const char invalid_params[] = "com.sonycsl.kadecot.plugin.echonetlite.error.invalid_params";
52/* タイムアウト発生, コールバックが null*/
53const char internal_error[] = "com.sonycsl.kadecot.plugin.echonetlite.error.internal_error";
54
55static void wamp_idle_parse_state(wamp_state_t *s, jsonsl_action_t action,
56 struct jsonsl_state_st *state, const char *buf);
57static void wamp_code_push_parse_state(wamp_state_t *s, jsonsl_action_t action,
58 struct jsonsl_state_st *state, const char *buf);
59static void wamp_code_pop_parse_state(wamp_state_t *s, jsonsl_action_t action,
60 struct jsonsl_state_st *state, const char *buf);
61static void wamp_param_parse_state(wamp_state_t *s, jsonsl_action_t action,
62 struct jsonsl_state_st *state, const char *buf);
63static void wamp_nomore_param_parse_state(wamp_state_t *s, jsonsl_action_t action,
64 struct jsonsl_state_st *state, const char *buf);
65static void wamp_id_parse_state(wamp_state_t *s, jsonsl_action_t action,
66 struct jsonsl_state_st *state, const char *buf);
67static void wamp_list_parse_state(wamp_state_t *s, jsonsl_action_t action,
68 struct jsonsl_state_st *state, const char *buf);
69static void wamp_dict_parse_state(wamp_state_t *s, jsonsl_action_t action,
70 struct jsonsl_state_st *state, const char *buf);
71static void wamp_uri_parse_state(wamp_state_t *s, jsonsl_action_t action,
72 struct jsonsl_state_st *state, const char *buf);
73static void wamp_int_parse_state(wamp_state_t *s, jsonsl_action_t action,
74 struct jsonsl_state_st *state, const char *buf);
75static void wamp_string_parse_state(wamp_state_t *s, jsonsl_action_t action,
76 struct jsonsl_state_st *state, const char *buf);
77
78static void wamp_proc_hello_state(wamp_state_t *s, jsonsl_action_t action,
79 struct jsonsl_state_st *state, const char *buf);
80static void wamp_proc_welcome_state(wamp_state_t *s, jsonsl_action_t action,
81 struct jsonsl_state_st *state, const char *buf);
82static void wamp_proc_abort_state(wamp_state_t *s, jsonsl_action_t action,
83 struct jsonsl_state_st *state, const char *buf);
84static void wamp_proc_challenge_state(wamp_state_t *s, jsonsl_action_t action,
85 struct jsonsl_state_st *state, const char *buf);
86static void wamp_proc_authenticate_state(wamp_state_t *s, jsonsl_action_t action,
87 struct jsonsl_state_st *state, const char *buf);
88static void wamp_proc_goodbye_state(wamp_state_t *s, jsonsl_action_t action,
89 struct jsonsl_state_st *state, const char *buf);
90static void wamp_proc_error_state(wamp_state_t *s, jsonsl_action_t action,
91 struct jsonsl_state_st *state, const char *buf);
92static void wamp_proc_publish_state(wamp_state_t *s, jsonsl_action_t action,
93 struct jsonsl_state_st *state, const char *buf);
94static void wamp_proc_published_state(wamp_state_t *s, jsonsl_action_t action,
95 struct jsonsl_state_st *state, const char *buf);
96static void wamp_proc_subscribe_state(wamp_state_t *s, jsonsl_action_t action,
97 struct jsonsl_state_st *state, const char *buf);
98static void wamp_proc_subscribed_state(wamp_state_t *s, jsonsl_action_t action,
99 struct jsonsl_state_st *state, const char *buf);
100static void wamp_proc_unsubscribe_state(wamp_state_t *s, jsonsl_action_t action,
101 struct jsonsl_state_st *state, const char *buf);
102static void wamp_proc_unsubscribed_state(wamp_state_t *s, jsonsl_action_t action,
103 struct jsonsl_state_st *state, const char *buf);
104static void wamp_proc_event_state(wamp_state_t *s, jsonsl_action_t action,
105 struct jsonsl_state_st *state, const char *buf);
106static void wamp_proc_call_state(wamp_state_t *s, jsonsl_action_t action,
107 struct jsonsl_state_st *state, const char *buf);
108static void wamp_proc_cancel_state(wamp_state_t *s, jsonsl_action_t action,
109 struct jsonsl_state_st *state, const char *buf);
110static void wamp_proc_result_state(wamp_state_t *s, jsonsl_action_t action,
111 struct jsonsl_state_st *state, const char *buf);
112static void wamp_proc_register_state(wamp_state_t *s, jsonsl_action_t action,
113 struct jsonsl_state_st *state, const char *buf);
114static void wamp_proc_registered_state(wamp_state_t *s, jsonsl_action_t action,
115 struct jsonsl_state_st *state, const char *buf);
116static void wamp_proc_unregister_state(wamp_state_t *s, jsonsl_action_t action,
117 struct jsonsl_state_st *state, const char *buf);
118static void wamp_proc_unregistered_state(wamp_state_t *s, jsonsl_action_t action,
119 struct jsonsl_state_st *state, const char *buf);
120static void wamp_proc_invocation_state(wamp_state_t *s, jsonsl_action_t action,
121 struct jsonsl_state_st *state, const char *buf);
122static void wamp_proc_interrupt_state(wamp_state_t *s, jsonsl_action_t action,
123 struct jsonsl_state_st *state, const char *buf);
124static void wamp_proc_yield_state(wamp_state_t *s, jsonsl_action_t action,
125 struct jsonsl_state_st *state, const char *buf);
126
127static void wamp_param_handler(struct wamp_state *s, jsonsl_action_t action,
128 wamp_param_state_t param, const char *value);
129
130void wamp_error(wamp_state_t *s);
131void wamp_error_type(wamp_state_t *s, const char *value);
132void wamp_error_request_id(wamp_state_t *s, const char *value);
133void wamp_error_details(wamp_state_t *s, const char *value);
134void wamp_error_details_param(wamp_state_t *s, jsonsl_action_t action,
135 struct jsonsl_state_st *state, const char *buf);
136void wamp_error_uri(wamp_state_t *s, const char *value);
137void wamp_error_arguments(wamp_state_t *s, const char *value);
138void wamp_error_arguments_param(wamp_state_t *s, jsonsl_action_t action,
139 struct jsonsl_state_st *state, const char *buf);
140void wamp_error_argumentskw(wamp_state_t *s, const char *value);
141void wamp_error_argumentskw_param(wamp_state_t *s, jsonsl_action_t action,
142 struct jsonsl_state_st *state, const char *buf);
143static void wamp_error_close(wamp_state_t *s);
144
145void wamp_init(wamp_state_t *s)
146{
147 jsonsl_t jsn;
148
149 memset(s, 0, sizeof(wamp_state_t));
150 s->jsn_buf_pos = -1;
151
152 jsn = jsonsl_new((jsonsl_t)&s->jsn, JSN_NLEVELS);
153 jsn->data = s;
154 jsn->error_callback = wamp_error_callback;
155 jsn->action_callback = wamp_state_callback;
156 jsonsl_enable_all_callbacks(jsn);
157
158 s->router.s = s;
159 s->client.s = s;
160 s->broker.s = s;
161 s->dealer.s = s;
162 s->publisher.s = s;
163 s->subscriber.s = s;
164 s->caller.s = s;
165 s->callee.s = s;
166 s->param_handler = wamp_param_handler;
167
168 wamp_dealer_init(&s->dealer);
169}
170
171void wamp_put_msg(wamp_state_t *s, ECN_FBS_ID msg, ID wbsid)
172{
173 ECN_FBS_SSIZE_T len, pos;
174 uint8_t data;
175
176 s->wbsid = wbsid;
177
178 len = _ecn_fbs_get_datalen(msg);
179
180 for (pos = 0; pos < len; pos++) {
181 data = _ecn_fbs_peek(msg, pos);
182
183 if ((s->jsn_buf_pos >= 0) && (s->jsn_buf_pos < sizeof(s->jsn_buf)))
184 s->jsn_buf[s->jsn_buf_pos++] = data;
185 jsonsl_feed((jsonsl_t)s->jsn, &data, 1);
186 }
187}
188
189void wamp_state_callback(jsonsl_t jsn, jsonsl_action_t action,
190 struct jsonsl_state_st *state, const char *buf)
191{
192 wamp_state_t *s = (wamp_state_t *)jsn->data;
193 /*syslog(7, "@%5ld '%c' L%d %c%s",
194 jsn->pos,
195 *buf,
196 state->level,
197 action,
198 jsonsl_strtype(state->type));*/
199
200 switch (action) {
201 case JSONSL_ACTION_PUSH:
202 switch (state->type) {
203 case JSONSL_T_SPECIAL:
204 s->jsn_buf[0] = *buf;
205 s->jsn_buf_pos = 1;
206 break;
207 case JSONSL_T_STRING:
208 case JSONSL_T_HKEY:
209 s->jsn_buf_pos = 0;
210 break;
211 default:
212 s->jsn_buf_pos = -1;
213 }
214 break;
215 case JSONSL_ACTION_POP:
216 switch (state->type) {
217 case JSONSL_T_SPECIAL:
218 case JSONSL_T_STRING:
219 case JSONSL_T_HKEY:
220 s->jsn_buf_pos--;
221 if (s->jsn_buf_pos < sizeof(s->jsn_buf)) {
222 s->jsn_buf[s->jsn_buf_pos] = '\0';
223 }
224 break;
225 default:
226 s->jsn_buf[0] = '\0';
227 break;
228 }
229 s->jsn_buf_pos = -1;
230 break;
231 default:
232 s->jsn_buf_pos = -1;
233 break;
234 }
235
236 switch (s->state) {
237 case WAMP_PARSE_STATE_IDLE:
238 wamp_idle_parse_state(s, action, state, buf);
239 break;
240 case WAMP_PARSE_STATE_CODE_PUSH:
241 wamp_code_push_parse_state(s, action, state, buf);
242 break;
243 case WAMP_PARSE_STATE_CODE_POP:
244 wamp_code_pop_parse_state(s, action, state, buf);
245 break;
246 case WAMP_PARSE_STATE_ID_PUSH:
247 wamp_id_parse_state(s, action, state, buf);
248 break;
249 case WAMP_PARSE_STATE_LIST_PUSH:
250 wamp_list_parse_state(s, action, state, buf);
251 break;
252 case WAMP_PARSE_STATE_DICT_PUSH:
253 wamp_dict_parse_state(s, action, state, buf);
254 break;
255 case WAMP_PARSE_STATE_URI_PUSH:
256 wamp_uri_parse_state(s, action, state, buf);
257 break;
258 case WAMP_PARSE_STATE_INT_PUSH:
259 wamp_int_parse_state(s, action, state, buf);
260 break;
261 case WAMP_PARSE_STATE_STRING_PUSH:
262 wamp_string_parse_state(s, action, state, buf);
263 break;
264 case WAMP_PARSE_STATE_PARAM:
265 wamp_param_parse_state(s, action, state, buf);
266 break;
267 case WAMP_PARSE_STATE_NOMORE_PARAM:
268 wamp_nomore_param_parse_state(s, action, state, buf);
269 break;
270 default:
271 s->state = WAMP_PARSE_STATE_ERROR;
272 break;
273 }
274
275 if (s->state == WAMP_PARSE_STATE_ERROR) {
276 /* WAMPメッセージの最後だったら */
277 if ((state->level == 1) && (action == JSONSL_ACTION_POP)
278 && (state->type == JSONSL_T_LIST)) {
279 s->message_close_handler(s);
280 }
281 else {
282 s->param_handler(s, JSONSL_ACTION_ERROR, s->prmst, NULL);
283 }
284 jsonsl_reset((jsonsl_t)s->jsn);
285 s->state = WAMP_PARSE_STATE_IDLE;
286 }
287}
288
289int wamp_error_callback(jsonsl_t jsn, jsonsl_error_t err,
290struct jsonsl_state_st *state, char *errat)
291{
292 return 0;
293}
294
295static void wamp_idle_parse_state(wamp_state_t *s, jsonsl_action_t action,
296 struct jsonsl_state_st *state, const char *buf)
297{
298 /* WAMPメッセージの先頭だったら */
299 if ((state->level == 1) && (action == JSONSL_ACTION_PUSH)
300 && (state->type == JSONSL_T_LIST)) {
301 /* メッセージコード取得開始状態に移る */
302 s->state = WAMP_PARSE_STATE_CODE_PUSH;
303 }
304}
305
306static void wamp_code_push_parse_state(wamp_state_t *s, jsonsl_action_t action,
307 struct jsonsl_state_st *state, const char *buf)
308{
309 /* メッセージコードの取得開始 */
310 if ((action == JSONSL_ACTION_PUSH)
311 && (state->type == JSONSL_T_SPECIAL)) {
312 /* メッセージコード取得状態に移る */
313 s->state = WAMP_PARSE_STATE_CODE_POP;
314 }
315 else
316 /* メッセージコードが取得できなければエラー */
317 s->state = WAMP_PARSE_STATE_ERROR;
318}
319
320static void wamp_code_pop_parse_state(wamp_state_t *s, jsonsl_action_t action,
321 struct jsonsl_state_st *state, const char *buf)
322{
323 int code;
324 wamp_parse_state_t prsst = WAMP_PARSE_STATE_ERROR;
325
326 /* メッセージコードが取得でき */
327 if ((action == JSONSL_ACTION_POP)
328 && (state->type == JSONSL_T_SPECIAL)) {
329 /* メッセージコードを取得 */
330 code = atoi(s->jsn_buf);
331 switch (code) {
332 /* [HELLO, Realm|uri, Details|dict] */
333 case WAMP_CODE_HELLO:
334 wamp_router_hello(&s->router);
335 s->proc_handler = wamp_proc_hello_state;
336 s->message_close_handler = wamp_router_hello_close;
337 s->prmst = WAMP_PARAM_STATE_REALM_URI;
338 prsst = WAMP_PARSE_STATE_URI_PUSH;
339 break;
340 /* [WELCOME, Session|id, Details|dict] */
341 case WAMP_CODE_WELCOME:
342 wamp_client_welcome(&s->client);
343 s->proc_handler = wamp_proc_welcome_state;
344 s->message_close_handler = wamp_client_welcome_close;
345 s->prmst = WAMP_PARAM_STATE_SESSION_ID;
346 prsst = WAMP_PARSE_STATE_ID_PUSH;
347 break;
348 /* [ABORT, Details|dict, Reason|uri] */
349 case WAMP_CODE_ABORT:
350 wamp_client_abort(&s->client);
351 s->proc_handler = wamp_proc_abort_state;
352 s->message_close_handler = wamp_client_abort_close;
353 s->prmst = WAMP_PARAM_STATE_DETAILS_DICT;
354 prsst = WAMP_PARSE_STATE_DICT_PUSH;
355 break;
356 /* [CHALLENGE, AuthMethod|string, Extra|dict] */
357 case WAMP_CODE_CHALLENGE:
358 wamp_client_challenge(&s->client);
359 s->proc_handler = wamp_proc_challenge_state;
360 s->message_close_handler = wamp_client_challenge_close;
361 s->prmst = WAMP_PARAM_STATE_AUTHMETHOD_STRING;
362 prsst = WAMP_PARSE_STATE_STRING_PUSH;
363 break;
364 /* [AUTHENTICATE, Signature|string, Extra|dict] */
365 case WAMP_CODE_AUTHENTICATE:
366 wamp_router_authenticate(&s->router);
367 s->proc_handler = wamp_proc_authenticate_state;
368 s->message_close_handler = wamp_router_authenticate_close;
369 s->prmst = WAMP_PARAM_STATE_SIGNATURE_STRING;
370 prsst = WAMP_PARSE_STATE_STRING_PUSH;
371 break;
372 /* [GOODBYE, Details|dict, Reason|uri] */
373 case WAMP_CODE_GOODBYE:
374 wamp_router_goodbye(&s->router);
375 s->proc_handler = wamp_proc_goodbye_state;
376 s->message_close_handler = wamp_router_goodbye_close;
377 s->prmst = WAMP_PARAM_STATE_DETAILS_DICT;
378 prsst = WAMP_PARSE_STATE_DICT_PUSH;
379 break;
380 /* [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list, ArgumentsKw|dict] */
381 case WAMP_CODE_ERROR:
382 wamp_error(s);
383 s->proc_handler = wamp_proc_error_state;
384 s->message_close_handler = wamp_error_close;
385 s->prmst = WAMP_PARAM_STATE_TYPE_INT;
386 prsst = WAMP_PARSE_STATE_INT_PUSH;
387 break;
388 /* [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list, ArgumentsKw|dict] */
389 case WAMP_CODE_PUBLISH:
390 wamp_broker_publish(&s->broker);
391 s->proc_handler = wamp_proc_publish_state;
392 s->message_close_handler = wamp_broker_publish_close;
393 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
394 prsst = WAMP_PARSE_STATE_ID_PUSH;
395 break;
396 /* [PUBLISHED, PUBLISH.Request|id, Publication|id] */
397 case WAMP_CODE_PUBLISHED:
398 wamp_publisher_published(&s->publisher);
399 s->proc_handler = wamp_proc_published_state;
400 s->message_close_handler = wamp_publisher_published_close;
401 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
402 prsst = WAMP_PARSE_STATE_ID_PUSH;
403 break;
404 /* [SUBSCRIBE, Request|id, Options|dict, Topic|uri] */
405 case WAMP_CODE_SUBSCRIBE:
406 wamp_broker_subscribe(&s->broker);
407 s->proc_handler = wamp_proc_subscribe_state;
408 s->message_close_handler = wamp_broker_subscribe_close;
409 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
410 prsst = WAMP_PARSE_STATE_ID_PUSH;
411 break;
412 /* [SUBSCRIBED, SUBSCRIBE.Request|id, Subscription|id] */
413 case WAMP_CODE_SUBSCRIBED:
414 wamp_subscriber_subscribed(&s->subscriber);
415 s->proc_handler = wamp_proc_subscribed_state;
416 s->message_close_handler = wamp_subscriber_subscribed_close;
417 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
418 prsst = WAMP_PARSE_STATE_ID_PUSH;
419 break;
420 /* [UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id] */
421 case WAMP_CODE_UNSUBSCRIBE:
422 wamp_broker_unsubscribe(&s->broker);
423 s->proc_handler = wamp_proc_unsubscribe_state;
424 s->message_close_handler = wamp_broker_unsubscribe_close;
425 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
426 prsst = WAMP_PARSE_STATE_ID_PUSH;
427 break;
428 /* [UNSUBSCRIBED, UNSUBSCRIBE.Request|id] */
429 case WAMP_CODE_UNSUBSCRIBED:
430 wamp_subscriber_unsubscribed(&s->subscriber);
431 s->proc_handler = wamp_proc_unsubscribed_state;
432 s->message_close_handler = wamp_subscriber_unsubscribed_close;
433 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
434 prsst = WAMP_PARSE_STATE_ID_PUSH;
435 break;
436 /* [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list, PUBLISH.ArgumentsKw|dict] */
437 case WAMP_CODE_EVENT:
438 wamp_subscriber_event(&s->subscriber);
439 s->proc_handler = wamp_proc_event_state;
440 s->message_close_handler = wamp_subscriber_event_close;
441 s->prmst = WAMP_PARAM_STATE_SUBSCRIPTION_ID;
442 prsst = WAMP_PARSE_STATE_ID_PUSH;
443 break;
444 /* [CALL, Request|id, Options|dict, Procedure|uri, Arguments|list, ArgumentsKw|dict] */
445 case WAMP_CODE_CALL:
446 wamp_dealer_call(&s->dealer);
447 s->proc_handler = wamp_proc_call_state;
448 s->message_close_handler = wamp_dealer_call_close;
449 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
450 prsst = WAMP_PARSE_STATE_ID_PUSH;
451 break;
452 /* [CANCEL, CALL.Request|id, Options|dict] */
453 case WAMP_CODE_CANCEL:
454 wamp_dealer_cansel(&s->dealer);
455 s->proc_handler = wamp_proc_cancel_state;
456 s->message_close_handler = wamp_dealer_cansel_close;
457 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
458 prsst = WAMP_PARSE_STATE_ID_PUSH;
459 break;
460 /* [RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list, YIELD.ArgumentsKw|dict] */
461 case WAMP_CODE_RESULT:
462 wamp_caller_result(&s->caller);
463 s->proc_handler = wamp_proc_result_state;
464 s->message_close_handler = wamp_caller_result_close;
465 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
466 prsst = WAMP_PARSE_STATE_ID_PUSH;
467 break;
468 /* [REGISTER, Request|id, Options|dict, Procedure|uri] */
469 case WAMP_CODE_REGISTER:
470 wamp_dealer_register(&s->dealer);
471 s->proc_handler = wamp_proc_register_state;
472 s->message_close_handler = wamp_dealer_register_close;
473 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
474 prsst = WAMP_PARSE_STATE_ID_PUSH;
475 break;
476 /* [REGISTERED, REGISTER.Request|id, Registration|id] */
477 case WAMP_CODE_REGISTERED:
478 wamp_callee_registered(&s->callee);
479 s->proc_handler = wamp_proc_registered_state;
480 s->message_close_handler = wamp_callee_registered_close;
481 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
482 prsst = WAMP_PARSE_STATE_ID_PUSH;
483 break;
484 /* [UNREGISTER, Request|id, REGISTERED.Registration|id] */
485 case WAMP_CODE_UNREGISTER:
486 wamp_dealer_unregister(&s->dealer);
487 s->proc_handler = wamp_proc_unregister_state;
488 s->message_close_handler = wamp_dealer_unregister_close;
489 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
490 prsst = WAMP_PARSE_STATE_ID_PUSH;
491 break;
492 /* [UNREGISTERED, UNREGISTER.Request|id] */
493 case WAMP_CODE_UNREGISTERED:
494 wamp_callee_unregistered(&s->callee);
495 s->proc_handler = wamp_proc_unregistered_state;
496 s->message_close_handler = wamp_callee_unregistered_close;
497 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
498 prsst = WAMP_PARSE_STATE_ID_PUSH;
499 break;
500 /* [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict] */
501 case WAMP_CODE_INVOCATION:
502 wamp_callee_invocation(&s->callee);
503 s->proc_handler = wamp_proc_invocation_state;
504 s->message_close_handler = wamp_callee_invocation_close;
505 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
506 prsst = WAMP_PARSE_STATE_ID_PUSH;
507 break;
508 /* [INTERRUPT, INVOCATION.Request|id, Options|dict] */
509 case WAMP_CODE_INTERRUPT:
510 wamp_callee_interrupt(&s->callee);
511 s->proc_handler = wamp_proc_interrupt_state;
512 s->message_close_handler = wamp_callee_interrupt_close;
513 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
514 prsst = WAMP_PARSE_STATE_ID_PUSH;
515 break;
516 /* [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list, ArgumentsKw|dict] */
517 case WAMP_CODE_YIELD:
518 wamp_dealer_yield(&s->dealer);
519 s->proc_handler = wamp_proc_yield_state;
520 s->message_close_handler = wamp_dealer_yield_close;
521 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
522 prsst = WAMP_PARSE_STATE_ID_PUSH;
523 break;
524 default:
525 s->proc_handler = NULL;
526 break;
527 }
528
529 /* 知っているメッセージコードだったら */
530 if (s->proc_handler != NULL) {
531 /* パラメータ取得状態に移る */
532 s->code = (wamp_code_t)code;
533 }
534 }
535
536 /* メッセージコードが取得できなければエラー */
537 s->state = prsst;
538}
539
540static void wamp_id_parse_state(wamp_state_t *s, jsonsl_action_t action,
541 struct jsonsl_state_st *state, const char *buf)
542{
543 /* メッセージコードの取得開始 */
544 if ((action == JSONSL_ACTION_PUSH)
545 && (state->type == JSONSL_T_SPECIAL)) {
546 s->param_handler(s, action, s->prmst, NULL);
547 /* メッセージコード取得状態に移る */
548 s->state = WAMP_PARSE_STATE_PARAM;
549 }
550 else
551 /* メッセージコードが取得できなければエラー */
552 s->state = WAMP_PARSE_STATE_ERROR;
553}
554
555static void wamp_list_parse_state(wamp_state_t *s, jsonsl_action_t action,
556 struct jsonsl_state_st *state, const char *buf)
557{
558 /* メッセージコードの取得開始 */
559 if ((action == JSONSL_ACTION_PUSH)
560 && (state->type == JSONSL_T_LIST)) {
561 s->param_handler(s, action, s->prmst, NULL);
562 /* メッセージコード取得状態に移る */
563 s->state = WAMP_PARSE_STATE_PARAM;
564 }
565 else
566 /* メッセージコードが取得できなければエラー */
567 s->state = WAMP_PARSE_STATE_ERROR;
568}
569
570static void wamp_dict_parse_state(wamp_state_t *s, jsonsl_action_t action,
571 struct jsonsl_state_st *state, const char *buf)
572{
573 /* メッセージコードの取得開始 */
574 if ((action == JSONSL_ACTION_PUSH)
575 && (state->type == JSONSL_T_OBJECT)) {
576 s->param_handler(s, action, s->prmst, NULL);
577 /* メッセージコード取得状態に移る */
578 s->state = WAMP_PARSE_STATE_PARAM;
579 }
580 else
581 /* メッセージコードが取得できなければエラー */
582 s->state = WAMP_PARSE_STATE_ERROR;
583}
584
585static void wamp_uri_parse_state(wamp_state_t *s, jsonsl_action_t action,
586 struct jsonsl_state_st *state, const char *buf)
587{
588 /* メッセージコードの取得開始 */
589 if ((action == JSONSL_ACTION_PUSH)
590 && (state->type == JSONSL_T_STRING)) {
591 s->param_handler(s, action, s->prmst, NULL);
592 /* メッセージコード取得状態に移る */
593 s->state = WAMP_PARSE_STATE_PARAM;
594 }
595 else
596 /* メッセージコードが取得できなければエラー */
597 s->state = WAMP_PARSE_STATE_ERROR;
598}
599
600static void wamp_int_parse_state(wamp_state_t *s, jsonsl_action_t action,
601 struct jsonsl_state_st *state, const char *buf)
602{
603 /* メッセージコードの取得開始 */
604 if ((action == JSONSL_ACTION_PUSH)
605 && (state->type == JSONSL_T_SPECIAL)) {
606 s->param_handler(s, action, s->prmst, NULL);
607 /* メッセージコード取得状態に移る */
608 s->state = WAMP_PARSE_STATE_PARAM;
609 }
610 else
611 /* メッセージコードが取得できなければエラー */
612 s->state = WAMP_PARSE_STATE_ERROR;
613}
614
615static void wamp_string_parse_state(wamp_state_t *s, jsonsl_action_t action,
616 struct jsonsl_state_st *state, const char *buf)
617{
618 /* メッセージコードの取得開始 */
619 if ((action == JSONSL_ACTION_PUSH)
620 && (state->type == JSONSL_T_STRING)) {
621 s->param_handler(s, action, s->prmst, NULL);
622 /* メッセージコード取得状態に移る */
623 s->state = WAMP_PARSE_STATE_PARAM;
624 }
625 else
626 /* メッセージコードが取得できなければエラー */
627 s->state = WAMP_PARSE_STATE_ERROR;
628}
629
630static void wamp_param_parse_state(wamp_state_t *s, jsonsl_action_t action,
631 struct jsonsl_state_st *state, const char *buf)
632{
633 /* コードごとの処理を実行 */
634 s->proc_handler(s, action, state, buf);
635
636 /* WAMPメッセージの末尾だったら */
637 if ((state->level == 1) && (action == JSONSL_ACTION_POP)
638 && (state->type == JSONSL_T_LIST)) {
639 s->prmst = WAMP_PARAM_STATE_NONE;
640 s->message_close_handler(s);
641 jsonsl_reset((jsonsl_t)s->jsn);
642 /* 待機状態に移る */
643 s->state = WAMP_PARSE_STATE_IDLE;
644 }
645}
646
647static void wamp_nomore_param_parse_state(wamp_state_t *s, jsonsl_action_t action,
648 struct jsonsl_state_st *state, const char *buf)
649{
650 /* WAMPメッセージの末尾だったら */
651 if ((state->level == 1) && (action == JSONSL_ACTION_POP)
652 && (state->type == JSONSL_T_LIST)) {
653 s->message_close_handler(s);
654 jsonsl_reset((jsonsl_t)s->jsn);
655 /* 待機状態に移る */
656 s->state = WAMP_PARSE_STATE_IDLE;
657 }
658 else
659 /* メッセージコードが取得できなければエラー */
660 s->state = WAMP_PARSE_STATE_ERROR;
661}
662
663/*
664 * [HELLO, Realm|uri, Details|dict]
665 */
666static void wamp_proc_hello_state(wamp_state_t *s, jsonsl_action_t action,
667 struct jsonsl_state_st *state, const char *buf)
668{
669 switch (s->prmst) {
670 case WAMP_PARAM_STATE_REALM_URI:
671 if ((action == JSONSL_ACTION_POP)
672 && (state->type == JSONSL_T_STRING)) {
673 wamp_router_hello_realm(&s->router, s->jsn_buf);
674 s->prmst = WAMP_PARAM_STATE_DETAILS_DICT;
675 s->state = WAMP_PARSE_STATE_DICT_PUSH;
676 }
677 else
678 s->state = WAMP_PARSE_STATE_ERROR;
679 break;
680 case WAMP_PARAM_STATE_DETAILS_DICT:
681 if (state->level == 2) {
682 if ((action == JSONSL_ACTION_POP)
683 && (state->type == JSONSL_T_OBJECT)) {
684 wamp_router_hello_details(&s->router);
685 s->prmst = WAMP_PARAM_STATE_NONE;
686 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
687 }
688 else
689 s->state = WAMP_PARSE_STATE_ERROR;
690 }
691 else {
692 wamp_router_hello_details_param(&s->router, action, state, buf);
693 }
694 break;
695 default:
696 s->state = WAMP_PARSE_STATE_ERROR;
697 break;
698 }
699}
700
701/*
702 * [WELCOME, Session|id, Details|dict]
703 */
704static void wamp_proc_welcome_state(wamp_state_t *s, jsonsl_action_t action,
705 struct jsonsl_state_st *state, const char *buf)
706{
707 switch (s->prmst) {
708 case WAMP_PARAM_STATE_SESSION_ID:
709 if ((action == JSONSL_ACTION_POP)
710 && (state->type == JSONSL_T_SPECIAL)) {
711 wamp_client_welcome_client_id(&s->client, s->jsn_buf);
712 s->prmst = WAMP_PARAM_STATE_DETAILS_DICT;
713 s->state = WAMP_PARSE_STATE_DICT_PUSH;
714 }
715 else
716 s->state = WAMP_PARSE_STATE_ERROR;
717 break;
718 case WAMP_PARAM_STATE_DETAILS_DICT:
719 if (state->level == 2) {
720 if ((action == JSONSL_ACTION_POP)
721 && (state->type == JSONSL_T_OBJECT)) {
722 wamp_client_welcome_details(&s->client, s->jsn_buf);
723 s->prmst = WAMP_PARAM_STATE_NONE;
724 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
725 }
726 else
727 s->state = WAMP_PARSE_STATE_ERROR;
728 }
729 else {
730 wamp_client_welcome_details_param(&s->client, action, state, buf);
731 }
732 break;
733 default:
734 s->state = WAMP_PARSE_STATE_ERROR;
735 break;
736 }
737}
738
739/*
740 * [ABORT, Details|dict, Reason|uri]
741 */
742static void wamp_proc_abort_state(wamp_state_t *s, jsonsl_action_t action,
743 struct jsonsl_state_st *state, const char *buf)
744{
745 switch (s->prmst) {
746 case WAMP_PARAM_STATE_DETAILS_DICT:
747 if (state->level == 2) {
748 if ((action == JSONSL_ACTION_POP)
749 && (state->type == JSONSL_T_OBJECT)) {
750 wamp_client_abort_details(&s->client, s->jsn_buf);
751 s->prmst = WAMP_PARAM_STATE_REASON_URI;
752 s->state = WAMP_PARSE_STATE_URI_PUSH;
753 }
754 else
755 s->state = WAMP_PARSE_STATE_ERROR;
756 }
757 else {
758 wamp_client_abort_details_param(&s->client, action, state, buf);
759 }
760 break;
761 case WAMP_PARAM_STATE_REASON_URI:
762 if ((action == JSONSL_ACTION_POP)
763 && (state->type == JSONSL_T_STRING)) {
764 wamp_client_abort_reason(&s->client, s->jsn_buf);
765 s->prmst = WAMP_PARAM_STATE_NONE;
766 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
767 }
768 else
769 s->state = WAMP_PARSE_STATE_ERROR;
770 break;
771 default:
772 s->state = WAMP_PARSE_STATE_ERROR;
773 break;
774 }
775}
776
777/*
778 * [CHALLENGE, AuthMethod|string, Extra|dict]
779 */
780static void wamp_proc_challenge_state(wamp_state_t *s, jsonsl_action_t action,
781 struct jsonsl_state_st *state, const char *buf)
782{
783 switch (s->prmst) {
784 case WAMP_PARAM_STATE_AUTHMETHOD_STRING:
785 if ((action == JSONSL_ACTION_POP)
786 && (state->type == JSONSL_T_STRING)) {
787 wamp_client_challenge_authmethod(&s->client, s->jsn_buf);
788 s->prmst = WAMP_PARAM_STATE_EXTRA_DICT;
789 s->state = WAMP_PARSE_STATE_DICT_PUSH;
790 }
791 else
792 s->state = WAMP_PARSE_STATE_ERROR;
793 break;
794 case WAMP_PARAM_STATE_EXTRA_DICT:
795 if (state->level == 2) {
796 if ((action == JSONSL_ACTION_POP)
797 && (state->type == JSONSL_T_OBJECT)) {
798 wamp_client_challenge_extra(&s->client, s->jsn_buf);
799 s->prmst = WAMP_PARAM_STATE_NONE;
800 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
801 }
802 else
803 s->state = WAMP_PARSE_STATE_ERROR;
804 }
805 else {
806 wamp_client_challenge_extra_param(&s->client, action, state, buf);
807 }
808 break;
809 default:
810 s->state = WAMP_PARSE_STATE_ERROR;
811 break;
812 }
813}
814
815/*
816 * [AUTHENTICATE, Signature|string, Extra|dict]
817 */
818static void wamp_proc_authenticate_state(wamp_state_t *s, jsonsl_action_t action,
819 struct jsonsl_state_st *state, const char *buf)
820{
821 switch (s->prmst) {
822 case WAMP_PARAM_STATE_SIGNATURE_STRING:
823 if ((action == JSONSL_ACTION_POP)
824 && (state->type == JSONSL_T_STRING)) {
825 wamp_router_authenticate_signature(&s->router, s->jsn_buf);
826 s->prmst = WAMP_PARAM_STATE_EXTRA_DICT;
827 s->state = WAMP_PARSE_STATE_DICT_PUSH;
828 }
829 else
830 s->state = WAMP_PARSE_STATE_ERROR;
831 break;
832 case WAMP_PARAM_STATE_EXTRA_DICT:
833 if (state->level == 2) {
834 if ((action == JSONSL_ACTION_POP)
835 && (state->type == JSONSL_T_OBJECT)) {
836 wamp_router_authenticate_extra(&s->router, s->jsn_buf);
837 s->prmst = WAMP_PARAM_STATE_NONE;
838 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
839 }
840 else
841 s->state = WAMP_PARSE_STATE_ERROR;
842 }
843 else {
844 wamp_router_authenticate_extra_param(&s->router, action, state, buf);
845 }
846 break;
847 default:
848 s->state = WAMP_PARSE_STATE_ERROR;
849 break;
850 }
851}
852
853/*
854 * [GOODBYE, Details|dict, Reason|uri]
855 */
856static void wamp_proc_goodbye_state(wamp_state_t *s, jsonsl_action_t action,
857 struct jsonsl_state_st *state, const char *buf)
858{
859 switch (s->prmst) {
860 case WAMP_PARAM_STATE_DETAILS_DICT:
861 if (state->level == 2) {
862 if ((action == JSONSL_ACTION_POP)
863 && (state->type == JSONSL_T_OBJECT)) {
864 wamp_router_goodbye_details(&s->router);
865 s->prmst = WAMP_PARAM_STATE_REASON_URI;
866 s->state = WAMP_PARSE_STATE_URI_PUSH;
867 }
868 else
869 s->state = WAMP_PARSE_STATE_ERROR;
870 }
871 else {
872 wamp_router_goodbye_details_param(&s->router, action, state, buf);
873 }
874 break;
875 case WAMP_PARAM_STATE_REASON_URI:
876 if ((action == JSONSL_ACTION_POP)
877 && (state->type == JSONSL_T_STRING)) {
878 wamp_router_goodbye_reason(&s->router, s->jsn_buf);
879 s->prmst = WAMP_PARAM_STATE_NONE;
880 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
881 }
882 else
883 s->state = WAMP_PARSE_STATE_ERROR;
884 break;
885 default:
886 s->state = WAMP_PARSE_STATE_ERROR;
887 break;
888 }
889}
890
891/*
892 * [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list, ArgumentsKw|dict]
893 */
894static void wamp_proc_error_state(wamp_state_t *s, jsonsl_action_t action,
895 struct jsonsl_state_st *state, const char *buf)
896{
897 switch (s->prmst) {
898 case WAMP_PARAM_STATE_TYPE_INT:
899 if ((action == JSONSL_ACTION_POP)
900 && (state->type == JSONSL_T_SPECIAL)) {
901 wamp_error_type(s, s->jsn_buf);
902 s->prmst = WAMP_PARAM_STATE_REQUEST_ID;
903 s->state = WAMP_PARSE_STATE_ID_PUSH;
904 }
905 else
906 s->state = WAMP_PARSE_STATE_ERROR;
907 break;
908 case WAMP_PARAM_STATE_REQUEST_ID:
909 if ((action == JSONSL_ACTION_POP)
910 && (state->type == JSONSL_T_SPECIAL)) {
911 wamp_error_request_id(s, s->jsn_buf);
912 s->prmst = WAMP_PARAM_STATE_DETAILS_DICT;
913 s->state = WAMP_PARSE_STATE_DICT_PUSH;
914 }
915 else
916 s->state = WAMP_PARSE_STATE_ERROR;
917 break;
918 case WAMP_PARAM_STATE_DETAILS_DICT:
919 if (state->level == 2) {
920 if ((action == JSONSL_ACTION_POP)
921 && (state->type == JSONSL_T_OBJECT)) {
922 wamp_error_details(s, s->jsn_buf);
923 s->prmst = WAMP_PARAM_STATE_ERROR_URI;
924 s->state = WAMP_PARSE_STATE_URI_PUSH;
925 }
926 else
927 s->state = WAMP_PARSE_STATE_ERROR;
928 }
929 else {
930 wamp_error_details_param(s, action, state, buf);
931 }
932 break;
933 case WAMP_PARAM_STATE_ERROR_URI:
934 if ((action == JSONSL_ACTION_POP)
935 && (state->type == JSONSL_T_STRING)) {
936 wamp_error_uri(s, s->jsn_buf);
937 s->prmst = WAMP_PARAM_STATE_ARGUMENTS_LIST;
938 s->state = WAMP_PARSE_STATE_LIST_PUSH;
939 }
940 else
941 s->state = WAMP_PARSE_STATE_ERROR;
942 break;
943 case WAMP_PARAM_STATE_ARGUMENTS_LIST:
944 if (state->level == 2) {
945 if ((action == JSONSL_ACTION_POP)
946 && (state->type == JSONSL_T_LIST)) {
947 wamp_error_arguments(s, s->jsn_buf);
948 s->prmst = WAMP_PARAM_STATE_ARGUMENTSKW_DICT;
949 s->state = WAMP_PARSE_STATE_DICT_PUSH;
950 }
951 else
952 s->state = WAMP_PARSE_STATE_ERROR;
953 }
954 else {
955 wamp_error_arguments_param(s, action, state, buf);
956 }
957 break;
958 case WAMP_PARAM_STATE_ARGUMENTSKW_DICT:
959 if (state->level == 2) {
960 if ((action == JSONSL_ACTION_POP)
961 && (state->type == JSONSL_T_OBJECT)) {
962 wamp_error_argumentskw(s, s->jsn_buf);
963 s->prmst = WAMP_PARAM_STATE_NONE;
964 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
965 }
966 else
967 s->state = WAMP_PARSE_STATE_ERROR;
968 }
969 else {
970 wamp_error_argumentskw_param(s, action, state, buf);
971 }
972 break;
973 default:
974 s->state = WAMP_PARSE_STATE_ERROR;
975 break;
976 }
977}
978
979/*
980 * [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list, ArgumentsKw|dict]
981 */
982static void wamp_proc_publish_state(wamp_state_t *s, jsonsl_action_t action,
983 struct jsonsl_state_st *state, const char *buf)
984{
985 switch (s->prmst) {
986 case WAMP_PARAM_STATE_REQUEST_ID:
987 if ((action == JSONSL_ACTION_POP)
988 && (state->type == JSONSL_T_SPECIAL)) {
989 wamp_broker_publish_request_id(&s->broker, s->jsn_buf);
990 s->prmst = WAMP_PARAM_STATE_OPTIONS_DICT;
991 s->state = WAMP_PARSE_STATE_DICT_PUSH;
992 }
993 else
994 s->state = WAMP_PARSE_STATE_ERROR;
995 break;
996 case WAMP_PARAM_STATE_OPTIONS_DICT:
997 if (state->level == 2) {
998 if ((action == JSONSL_ACTION_POP)
999 && (state->type == JSONSL_T_OBJECT)) {
1000 wamp_broker_publish_options(&s->broker, s->jsn_buf);
1001 s->prmst = WAMP_PARAM_STATE_TOPIC_URI;
1002 s->state = WAMP_PARSE_STATE_URI_PUSH;
1003 }
1004 else
1005 s->state = WAMP_PARSE_STATE_ERROR;
1006 }
1007 else {
1008 wamp_broker_publish_options_param(&s->broker, action, state, buf);
1009 }
1010 break;
1011 case WAMP_PARAM_STATE_TOPIC_URI:
1012 if ((action == JSONSL_ACTION_POP)
1013 && (state->type == JSONSL_T_STRING)) {
1014 wamp_broker_publish_topic(&s->broker, s->jsn_buf);
1015 s->prmst = WAMP_PARAM_STATE_ARGUMENTS_LIST;
1016 s->state = WAMP_PARSE_STATE_LIST_PUSH;
1017 }
1018 else
1019 s->state = WAMP_PARSE_STATE_ERROR;
1020 break;
1021 case WAMP_PARAM_STATE_ARGUMENTS_LIST:
1022 if (state->level == 2) {
1023 if ((action == JSONSL_ACTION_POP)
1024 && (state->type == JSONSL_T_LIST)) {
1025 wamp_broker_publish_arguments(&s->broker, s->jsn_buf);
1026 s->prmst = WAMP_PARAM_STATE_ARGUMENTSKW_DICT;
1027 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1028 }
1029 else
1030 s->state = WAMP_PARSE_STATE_ERROR;
1031 }
1032 else {
1033 wamp_broker_publish_arguments_param(&s->broker, action, state, buf);
1034 }
1035 break;
1036 case WAMP_PARAM_STATE_ARGUMENTSKW_DICT:
1037 if (state->level == 2) {
1038 if ((action == JSONSL_ACTION_POP)
1039 && (state->type == JSONSL_T_OBJECT)) {
1040 wamp_broker_publish_argumentskw(&s->broker, s->jsn_buf);
1041 s->prmst = WAMP_PARAM_STATE_NONE;
1042 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1043 }
1044 else
1045 s->state = WAMP_PARSE_STATE_ERROR;
1046 }
1047 else {
1048 wamp_broker_publish_argumentskw_param(&s->broker, action, state, buf);
1049 }
1050 break;
1051 default:
1052 s->state = WAMP_PARSE_STATE_ERROR;
1053 break;
1054 }
1055}
1056
1057/*
1058 * [PUBLISHED, PUBLISH.Request|id, Publication|id]
1059 */
1060static void wamp_proc_published_state(wamp_state_t *s, jsonsl_action_t action,
1061 struct jsonsl_state_st *state, const char *buf)
1062{
1063 switch (s->prmst) {
1064 case WAMP_PARAM_STATE_REQUEST_ID:
1065 if ((action == JSONSL_ACTION_POP)
1066 && (state->type == JSONSL_T_SPECIAL)) {
1067 wamp_publisher_published_request_id(&s->publisher, s->jsn_buf);
1068 s->prmst = WAMP_PARAM_STATE_PUBLICATION_ID;
1069 s->state = WAMP_PARSE_STATE_ID_PUSH;
1070 }
1071 else
1072 s->state = WAMP_PARSE_STATE_ERROR;
1073 break;
1074 case WAMP_PARAM_STATE_PUBLICATION_ID:
1075 if ((action == JSONSL_ACTION_POP)
1076 && (state->type == JSONSL_T_SPECIAL)) {
1077 wamp_publisher_published_publication_id(&s->publisher, s->jsn_buf);
1078 s->prmst = WAMP_PARAM_STATE_NONE;
1079 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1080 }
1081 else
1082 s->state = WAMP_PARSE_STATE_ERROR;
1083 break;
1084 default:
1085 s->state = WAMP_PARSE_STATE_ERROR;
1086 break;
1087 }
1088}
1089
1090/*
1091 * [SUBSCRIBE, Request|id, Options|dict, Topic|uri]
1092 */
1093static void wamp_proc_subscribe_state(wamp_state_t *s, jsonsl_action_t action,
1094 struct jsonsl_state_st *state, const char *buf)
1095{
1096 switch (s->prmst) {
1097 case WAMP_PARAM_STATE_REQUEST_ID:
1098 if ((action == JSONSL_ACTION_POP)
1099 && (state->type == JSONSL_T_SPECIAL)) {
1100 wamp_broker_subscribe_request_id(&s->broker, s->jsn_buf);
1101 s->prmst = WAMP_PARAM_STATE_OPTIONS_DICT;
1102 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1103 }
1104 else
1105 s->state = WAMP_PARSE_STATE_ERROR;
1106 break;
1107 case WAMP_PARAM_STATE_OPTIONS_DICT:
1108 if (state->level == 2) {
1109 if ((action == JSONSL_ACTION_POP)
1110 && (state->type == JSONSL_T_OBJECT)) {
1111 wamp_broker_subscribe_options(&s->broker);
1112 s->prmst = WAMP_PARAM_STATE_TOPIC_URI;
1113 s->state = WAMP_PARSE_STATE_URI_PUSH;
1114 }
1115 else
1116 s->state = WAMP_PARSE_STATE_ERROR;
1117 }
1118 else {
1119 wamp_broker_subscribe_options_param(&s->broker, action, state, buf);
1120 }
1121 break;
1122 case WAMP_PARAM_STATE_TOPIC_URI:
1123 if ((action == JSONSL_ACTION_POP)
1124 && (state->type == JSONSL_T_STRING)) {
1125 wamp_broker_subscribe_topic(&s->broker, s->jsn_buf);
1126 s->prmst = WAMP_PARAM_STATE_NONE;
1127 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1128 }
1129 else
1130 s->state = WAMP_PARSE_STATE_ERROR;
1131 break;
1132 default:
1133 s->state = WAMP_PARSE_STATE_ERROR;
1134 break;
1135 }
1136}
1137
1138/*
1139 * [SUBSCRIBED, SUBSCRIBE.Request|id, Subscription|id]
1140 */
1141static void wamp_proc_subscribed_state(wamp_state_t *s, jsonsl_action_t action,
1142 struct jsonsl_state_st *state, const char *buf)
1143{
1144 switch (s->prmst) {
1145 case WAMP_PARAM_STATE_REQUEST_ID:
1146 if ((action == JSONSL_ACTION_POP)
1147 && (state->type == JSONSL_T_SPECIAL)) {
1148 wamp_subscriber_subscribed_request_id(&s->subscriber, s->jsn_buf);
1149 s->prmst = WAMP_PARAM_STATE_SUBSCRIPTION_ID;
1150 s->state = WAMP_PARSE_STATE_ID_PUSH;
1151 }
1152 else
1153 s->state = WAMP_PARSE_STATE_ERROR;
1154 break;
1155 case WAMP_PARAM_STATE_SUBSCRIPTION_ID:
1156 if ((action == JSONSL_ACTION_POP)
1157 && (state->type == JSONSL_T_SPECIAL)) {
1158 wamp_subscriber_subscribed_subscription_id(&s->subscriber, s->jsn_buf);
1159 s->prmst = WAMP_PARAM_STATE_NONE;
1160 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1161 }
1162 else
1163 s->state = WAMP_PARSE_STATE_ERROR;
1164 break;
1165 default:
1166 s->state = WAMP_PARSE_STATE_ERROR;
1167 break;
1168 }
1169}
1170
1171/*
1172 * [UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id]
1173 */
1174static void wamp_proc_unsubscribe_state(wamp_state_t *s, jsonsl_action_t action,
1175 struct jsonsl_state_st *state, const char *buf)
1176{
1177 switch (s->prmst) {
1178 case WAMP_PARAM_STATE_REQUEST_ID:
1179 if ((action == JSONSL_ACTION_POP)
1180 && (state->type == JSONSL_T_SPECIAL)) {
1181 wamp_broker_unsubscribe_request_id(&s->broker, s->jsn_buf);
1182 s->prmst = WAMP_PARAM_STATE_SUBSCRIPTION_ID;
1183 s->state = WAMP_PARSE_STATE_ID_PUSH;
1184 }
1185 else
1186 s->state = WAMP_PARSE_STATE_ERROR;
1187 break;
1188 case WAMP_PARAM_STATE_SUBSCRIPTION_ID:
1189 if ((action == JSONSL_ACTION_POP)
1190 && (state->type == JSONSL_T_SPECIAL)) {
1191 wamp_broker_unsubscribe_subscription_id(&s->broker, s->jsn_buf);
1192 s->prmst = WAMP_PARAM_STATE_NONE;
1193 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1194 }
1195 else
1196 s->state = WAMP_PARSE_STATE_ERROR;
1197 break;
1198 default:
1199 s->state = WAMP_PARSE_STATE_ERROR;
1200 break;
1201 }
1202}
1203
1204/*
1205 * [UNSUBSCRIBED, UNSUBSCRIBE.Request|id]
1206 */
1207static void wamp_proc_unsubscribed_state(wamp_state_t *s, jsonsl_action_t action,
1208 struct jsonsl_state_st *state, const char *buf)
1209{
1210 switch (s->prmst) {
1211 case WAMP_PARAM_STATE_REQUEST_ID:
1212 if ((action == JSONSL_ACTION_POP)
1213 && (state->type == JSONSL_T_SPECIAL)) {
1214 wamp_subscriber_unsubscribed_request_id(&s->subscriber, s->jsn_buf);
1215 s->prmst = WAMP_PARAM_STATE_NONE;
1216 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1217 }
1218 else
1219 s->state = WAMP_PARSE_STATE_ERROR;
1220 break;
1221 default:
1222 s->state = WAMP_PARSE_STATE_ERROR;
1223 break;
1224 }
1225}
1226
1227/*
1228 * [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list, PUBLISH.ArgumentsKw|dict]
1229 */
1230static void wamp_proc_event_state(wamp_state_t *s, jsonsl_action_t action,
1231 struct jsonsl_state_st *state, const char *buf)
1232{
1233 switch (s->prmst) {
1234 case WAMP_PARAM_STATE_SUBSCRIPTION_ID:
1235 if ((action == JSONSL_ACTION_POP)
1236 && (state->type == JSONSL_T_SPECIAL)) {
1237 wamp_subscriber_event_subscription_id(&s->subscriber, s->jsn_buf);
1238 s->prmst = WAMP_PARAM_STATE_PUBLICATION_ID;
1239 s->state = WAMP_PARSE_STATE_ID_PUSH;
1240 }
1241 else
1242 s->state = WAMP_PARSE_STATE_ERROR;
1243 break;
1244 case WAMP_PARAM_STATE_PUBLICATION_ID:
1245 if ((action == JSONSL_ACTION_POP)
1246 && (state->type == JSONSL_T_SPECIAL)) {
1247 wamp_subscriber_event_publication_id(&s->subscriber, s->jsn_buf);
1248 s->prmst = WAMP_PARAM_STATE_DETAILS_DICT;
1249 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1250 }
1251 else
1252 s->state = WAMP_PARSE_STATE_ERROR;
1253 break;
1254 case WAMP_PARAM_STATE_DETAILS_DICT:
1255 if (state->level == 2) {
1256 if ((action == JSONSL_ACTION_POP)
1257 && (state->type == JSONSL_T_OBJECT)) {
1258 wamp_subscriber_event_details(&s->subscriber, s->jsn_buf);
1259 s->prmst = WAMP_PARAM_STATE_ARGUMENTS_LIST;
1260 s->state = WAMP_PARSE_STATE_LIST_PUSH;
1261 }
1262 else
1263 s->state = WAMP_PARSE_STATE_ERROR;
1264 }
1265 else {
1266 wamp_subscriber_event_details_param(&s->subscriber, action, state, buf);
1267 }
1268 break;
1269 case WAMP_PARAM_STATE_ARGUMENTS_LIST:
1270 if (state->level == 2) {
1271 if ((action == JSONSL_ACTION_POP)
1272 && (state->type == JSONSL_T_LIST)) {
1273 wamp_subscriber_event_arguments(&s->subscriber, s->jsn_buf);
1274 s->prmst = WAMP_PARAM_STATE_ARGUMENTSKW_DICT;
1275 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1276 }
1277 else
1278 s->state = WAMP_PARSE_STATE_ERROR;
1279 }
1280 else {
1281 wamp_subscriber_event_arguments_param(&s->subscriber, action, state, buf);
1282 }
1283 break;
1284 case WAMP_PARAM_STATE_ARGUMENTSKW_DICT:
1285 if (state->level == 2) {
1286 if ((action == JSONSL_ACTION_POP)
1287 && (state->type == JSONSL_T_OBJECT)) {
1288 wamp_subscriber_event_argumentskw(&s->subscriber, s->jsn_buf);
1289 s->prmst = WAMP_PARAM_STATE_NONE;
1290 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1291 }
1292 else
1293 s->state = WAMP_PARSE_STATE_ERROR;
1294 }
1295 else {
1296 wamp_subscriber_event_argumentskw_param(&s->subscriber, action, state, buf);
1297 }
1298 break;
1299 default:
1300 s->state = WAMP_PARSE_STATE_ERROR;
1301 break;
1302 }
1303}
1304
1305/*
1306 * [CALL, Request|id, Options|dict, Procedure|uri, Arguments|list, ArgumentsKw|dict]
1307 */
1308static void wamp_proc_call_state(wamp_state_t *s, jsonsl_action_t action,
1309 struct jsonsl_state_st *state, const char *buf)
1310{
1311 switch (s->prmst) {
1312 case WAMP_PARAM_STATE_REQUEST_ID:
1313 if ((action == JSONSL_ACTION_POP)
1314 && (state->type == JSONSL_T_SPECIAL)) {
1315 wamp_dealer_call_request_id(&s->dealer, s->jsn_buf);
1316 s->prmst = WAMP_PARAM_STATE_OPTIONS_DICT;
1317 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1318 }
1319 else
1320 s->state = WAMP_PARSE_STATE_ERROR;
1321 break;
1322 case WAMP_PARAM_STATE_OPTIONS_DICT:
1323 if (state->level == 2) {
1324 if ((action == JSONSL_ACTION_POP)
1325 && (state->type == JSONSL_T_OBJECT)) {
1326 wamp_dealer_call_options(&s->dealer, s->jsn_buf);
1327 s->prmst = WAMP_PARAM_STATE_PROCEDURE_URI;
1328 s->state = WAMP_PARSE_STATE_URI_PUSH;
1329 }
1330 else
1331 s->state = WAMP_PARSE_STATE_ERROR;
1332 }
1333 else {
1334 wamp_dealer_call_options_param(&s->dealer, action, state, buf);
1335 }
1336 break;
1337 case WAMP_PARAM_STATE_PROCEDURE_URI:
1338 if ((action == JSONSL_ACTION_POP)
1339 && (state->type == JSONSL_T_STRING)) {
1340 wamp_dealer_call_procedure(&s->dealer, s->jsn_buf);
1341 s->prmst = WAMP_PARAM_STATE_ARGUMENTS_LIST;
1342 s->state = WAMP_PARSE_STATE_LIST_PUSH;
1343 }
1344 else
1345 s->state = WAMP_PARSE_STATE_ERROR;
1346 break;
1347 case WAMP_PARAM_STATE_ARGUMENTS_LIST:
1348 if (state->level == 2) {
1349 if ((action == JSONSL_ACTION_POP)
1350 && (state->type == JSONSL_T_LIST)) {
1351 wamp_dealer_call_arguments(&s->dealer, s->jsn_buf);
1352 s->prmst = WAMP_PARAM_STATE_ARGUMENTSKW_DICT;
1353 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1354 }
1355 else
1356 s->state = WAMP_PARSE_STATE_ERROR;
1357 }
1358 else {
1359 wamp_dealer_call_argumentskw_param(&s->dealer, action, state, buf);
1360 }
1361 break;
1362 case WAMP_PARAM_STATE_ARGUMENTSKW_DICT:
1363 if (state->level == 2) {
1364 if ((action == JSONSL_ACTION_POP)
1365 && (state->type == JSONSL_T_OBJECT)) {
1366 wamp_dealer_call_argumentskw(&s->dealer, s->jsn_buf);
1367 s->prmst = WAMP_PARAM_STATE_NONE;
1368 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1369 }
1370 else
1371 s->state = WAMP_PARSE_STATE_ERROR;
1372 }
1373 else {
1374 wamp_dealer_call_argumentskw_param(&s->dealer, action, state, buf);
1375 }
1376 break;
1377 default:
1378 s->state = WAMP_PARSE_STATE_ERROR;
1379 break;
1380 }
1381}
1382
1383/*
1384 * [CANCEL, CALL.Request|id, Options|dict]
1385 */
1386static void wamp_proc_cancel_state(wamp_state_t *s, jsonsl_action_t action,
1387 struct jsonsl_state_st *state, const char *buf)
1388{
1389 switch (s->prmst) {
1390 case WAMP_PARAM_STATE_REQUEST_ID:
1391 if ((action == JSONSL_ACTION_POP)
1392 && (state->type == JSONSL_T_SPECIAL)) {
1393 wamp_dealer_cansel_request_id(&s->dealer, s->jsn_buf);
1394 s->prmst = WAMP_PARAM_STATE_OPTIONS_DICT;
1395 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1396 }
1397 else
1398 s->state = WAMP_PARSE_STATE_ERROR;
1399 break;
1400 case WAMP_PARAM_STATE_OPTIONS_DICT:
1401 if (state->level == 2) {
1402 if ((action == JSONSL_ACTION_POP)
1403 && (state->type == JSONSL_T_OBJECT)) {
1404 wamp_dealer_cansel_options(&s->dealer, s->jsn_buf);
1405 s->prmst = WAMP_PARAM_STATE_NONE;
1406 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1407 }
1408 else
1409 s->state = WAMP_PARSE_STATE_ERROR;
1410 }
1411 else {
1412 wamp_dealer_cansel_options_param(&s->dealer, action, state, buf);
1413 }
1414 break;
1415 default:
1416 s->state = WAMP_PARSE_STATE_ERROR;
1417 break;
1418 }
1419}
1420
1421/*
1422 * [RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list, YIELD.ArgumentsKw|dict]
1423 */
1424static void wamp_proc_result_state(wamp_state_t *s, jsonsl_action_t action,
1425 struct jsonsl_state_st *state, const char *buf)
1426{
1427 switch (s->prmst) {
1428 case WAMP_PARAM_STATE_REQUEST_ID:
1429 if ((action == JSONSL_ACTION_POP)
1430 && (state->type == JSONSL_T_SPECIAL)) {
1431 wamp_caller_result_request_id(&s->caller, s->jsn_buf);
1432 s->prmst = WAMP_PARAM_STATE_DETAILS_DICT;
1433 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1434 }
1435 else
1436 s->state = WAMP_PARSE_STATE_ERROR;
1437 break;
1438 case WAMP_PARAM_STATE_DETAILS_DICT:
1439 if (state->level == 2) {
1440 if ((action == JSONSL_ACTION_POP)
1441 && (state->type == JSONSL_T_OBJECT)) {
1442 wamp_caller_result_details(&s->caller, s->jsn_buf);
1443 s->prmst = WAMP_PARAM_STATE_ARGUMENTS_LIST;
1444 s->state = WAMP_PARSE_STATE_LIST_PUSH;
1445 }
1446 else
1447 s->state = WAMP_PARSE_STATE_ERROR;
1448 }
1449 else {
1450 wamp_caller_result_details_param(&s->caller, action, state, buf);
1451 }
1452 break;
1453 case WAMP_PARAM_STATE_ARGUMENTS_LIST:
1454 if (state->level == 2) {
1455 if ((action == JSONSL_ACTION_POP)
1456 && (state->type == JSONSL_T_LIST)) {
1457 wamp_caller_result_arguments(&s->caller, s->jsn_buf);
1458 s->prmst = WAMP_PARAM_STATE_ARGUMENTSKW_DICT;
1459 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1460 }
1461 else
1462 s->state = WAMP_PARSE_STATE_ERROR;
1463 }
1464 else {
1465 wamp_caller_result_arguments_param(&s->caller, action, state, buf);
1466 }
1467 break;
1468 case WAMP_PARAM_STATE_ARGUMENTSKW_DICT:
1469 if (state->level == 2) {
1470 if ((action == JSONSL_ACTION_POP)
1471 && (state->type == JSONSL_T_OBJECT)) {
1472 wamp_caller_result_argumentskw(&s->caller, s->jsn_buf);
1473 s->prmst = WAMP_PARAM_STATE_NONE;
1474 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1475 }
1476 else
1477 s->state = WAMP_PARSE_STATE_ERROR;
1478 }
1479 else {
1480 wamp_caller_result_argumentskw_param(&s->caller, action, state, buf);
1481 }
1482 break;
1483 default:
1484 s->state = WAMP_PARSE_STATE_ERROR;
1485 break;
1486 }
1487}
1488
1489/*
1490 * [REGISTER, Request|id, Options|dict, Procedure|uri]
1491 */
1492static void wamp_proc_register_state(wamp_state_t *s, jsonsl_action_t action,
1493 struct jsonsl_state_st *state, const char *buf)
1494{
1495 switch (s->prmst) {
1496 case WAMP_PARAM_STATE_REQUEST_ID:
1497 if ((action == JSONSL_ACTION_POP)
1498 && (state->type == JSONSL_T_SPECIAL)) {
1499 wamp_dealer_register_request_id(&s->dealer, s->jsn_buf);
1500 s->prmst = WAMP_PARAM_STATE_OPTIONS_DICT;
1501 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1502 }
1503 else
1504 s->state = WAMP_PARSE_STATE_ERROR;
1505 break;
1506 case WAMP_PARAM_STATE_OPTIONS_DICT:
1507 if (state->level == 2) {
1508 if ((action == JSONSL_ACTION_POP)
1509 && (state->type == JSONSL_T_OBJECT)) {
1510 wamp_dealer_register_options(&s->dealer, s->jsn_buf);
1511 s->prmst = WAMP_PARAM_STATE_PROCEDURE_URI;
1512 s->state = WAMP_PARSE_STATE_URI_PUSH;
1513 }
1514 else
1515 s->state = WAMP_PARSE_STATE_ERROR;
1516 }
1517 else {
1518 wamp_dealer_register_options_param(&s->dealer, action, state, buf);
1519 }
1520 break;
1521 case WAMP_PARAM_STATE_PROCEDURE_URI:
1522 if ((action == JSONSL_ACTION_POP)
1523 && (state->type == JSONSL_T_STRING)) {
1524 wamp_dealer_register_procedure(&s->dealer, s->jsn_buf);
1525 s->prmst = WAMP_PARAM_STATE_NONE;
1526 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1527 }
1528 else
1529 s->state = WAMP_PARSE_STATE_ERROR;
1530 break;
1531 default:
1532 s->state = WAMP_PARSE_STATE_ERROR;
1533 break;
1534 }
1535}
1536
1537/*
1538 * [REGISTERED, REGISTER.Request|id, Registration|id]
1539 */
1540static void wamp_proc_registered_state(wamp_state_t *s, jsonsl_action_t action,
1541 struct jsonsl_state_st *state, const char *buf)
1542{
1543 switch (s->prmst) {
1544 case WAMP_PARAM_STATE_REQUEST_ID:
1545 if ((action == JSONSL_ACTION_POP)
1546 && (state->type == JSONSL_T_SPECIAL)) {
1547 wamp_callee_registered_request_id(&s->callee, s->jsn_buf);
1548 s->prmst = WAMP_PARAM_STATE_REGISTRATION_ID;
1549 s->state = WAMP_PARSE_STATE_ID_PUSH;
1550 }
1551 else
1552 s->state = WAMP_PARSE_STATE_ERROR;
1553 break;
1554 case WAMP_PARAM_STATE_REGISTRATION_ID:
1555 if ((action == JSONSL_ACTION_POP)
1556 && (state->type == JSONSL_T_SPECIAL)) {
1557 wamp_callee_registered_registration_id(&s->callee, s->jsn_buf);
1558 s->prmst = WAMP_PARAM_STATE_NONE;
1559 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1560 }
1561 else
1562 s->state = WAMP_PARSE_STATE_ERROR;
1563 break;
1564 default:
1565 s->state = WAMP_PARSE_STATE_ERROR;
1566 break;
1567 }
1568}
1569
1570/*
1571 * [UNREGISTER, Request|id, REGISTERED.Registration|id]
1572 */
1573static void wamp_proc_unregister_state(wamp_state_t *s, jsonsl_action_t action,
1574 struct jsonsl_state_st *state, const char *buf)
1575{
1576 switch (s->prmst) {
1577 case WAMP_PARAM_STATE_REQUEST_ID:
1578 if ((action == JSONSL_ACTION_POP)
1579 && (state->type == JSONSL_T_SPECIAL)) {
1580 wamp_dealer_unregister_request_id(&s->dealer, s->jsn_buf);
1581 s->prmst = WAMP_PARAM_STATE_REGISTRATION_ID;
1582 s->state = WAMP_PARSE_STATE_ID_PUSH;
1583 }
1584 else
1585 s->state = WAMP_PARSE_STATE_ERROR;
1586 break;
1587 case WAMP_PARAM_STATE_REGISTRATION_ID:
1588 if ((action == JSONSL_ACTION_POP)
1589 && (state->type == JSONSL_T_SPECIAL)) {
1590 wamp_dealer_unregister_registration_id(&s->dealer, s->jsn_buf);
1591 s->prmst = WAMP_PARAM_STATE_NONE;
1592 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1593 }
1594 else
1595 s->state = WAMP_PARSE_STATE_ERROR;
1596 break;
1597 default:
1598 s->state = WAMP_PARSE_STATE_ERROR;
1599 break;
1600 }
1601}
1602
1603/*
1604 * [UNREGISTERED, UNREGISTER.Request|id]
1605 */
1606static void wamp_proc_unregistered_state(wamp_state_t *s, jsonsl_action_t action,
1607 struct jsonsl_state_st *state, const char *buf)
1608{
1609 switch (s->prmst) {
1610 case WAMP_PARAM_STATE_REQUEST_ID:
1611 if ((action == JSONSL_ACTION_POP)
1612 && (state->type == JSONSL_T_SPECIAL)) {
1613 wamp_callee_unregistered_request_id(&s->callee, s->jsn_buf);
1614 s->prmst = WAMP_PARAM_STATE_NONE;
1615 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1616 }
1617 else
1618 s->state = WAMP_PARSE_STATE_ERROR;
1619 break;
1620 default:
1621 s->state = WAMP_PARSE_STATE_ERROR;
1622 break;
1623 }
1624}
1625
1626/*
1627 * [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict]
1628 */
1629static void wamp_proc_invocation_state(wamp_state_t *s, jsonsl_action_t action,
1630 struct jsonsl_state_st *state, const char *buf)
1631{
1632 switch (s->prmst) {
1633 case WAMP_PARAM_STATE_REQUEST_ID:
1634 if ((action == JSONSL_ACTION_POP)
1635 && (state->type == JSONSL_T_SPECIAL)) {
1636 wamp_callee_invocation_request_id(&s->callee, s->jsn_buf);
1637 s->prmst = WAMP_PARAM_STATE_REGISTRATION_ID;
1638 s->state = WAMP_PARSE_STATE_ID_PUSH;
1639 }
1640 else
1641 s->state = WAMP_PARSE_STATE_ERROR;
1642 break;
1643 case WAMP_PARAM_STATE_REGISTRATION_ID:
1644 if ((action == JSONSL_ACTION_POP)
1645 && (state->type == JSONSL_T_SPECIAL)) {
1646 wamp_callee_invocation_registration_id(&s->callee, s->jsn_buf);
1647 s->prmst = WAMP_PARAM_STATE_DETAILS_DICT;
1648 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1649 }
1650 else
1651 s->state = WAMP_PARSE_STATE_ERROR;
1652 break;
1653 case WAMP_PARAM_STATE_DETAILS_DICT:
1654 if (state->level == 2) {
1655 if ((action == JSONSL_ACTION_POP)
1656 && (state->type == JSONSL_T_OBJECT)) {
1657 wamp_callee_invocation_details(&s->callee, s->jsn_buf);
1658 s->prmst = WAMP_PARAM_STATE_ARGUMENTS_LIST;
1659 s->state = WAMP_PARSE_STATE_LIST_PUSH;
1660 }
1661 else
1662 s->state = WAMP_PARSE_STATE_ERROR;
1663 }
1664 else {
1665 wamp_callee_invocation_details_param(&s->callee, action, state, buf);
1666 }
1667 break;
1668 case WAMP_PARAM_STATE_ARGUMENTS_LIST:
1669 if (state->level == 2) {
1670 if ((action == JSONSL_ACTION_POP)
1671 && (state->type == JSONSL_T_LIST)) {
1672 wamp_callee_invocation_arguments(&s->callee, s->jsn_buf);
1673 s->prmst = WAMP_PARAM_STATE_ARGUMENTSKW_DICT;
1674 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1675 }
1676 else
1677 s->state = WAMP_PARSE_STATE_ERROR;
1678 }
1679 else {
1680 wamp_callee_invocation_arguments_param(&s->callee, action, state, buf);
1681 }
1682 break;
1683 case WAMP_PARAM_STATE_ARGUMENTSKW_DICT:
1684 if (state->level == 2) {
1685 if ((action == JSONSL_ACTION_POP)
1686 && (state->type == JSONSL_T_OBJECT)) {
1687 wamp_callee_invocation_argumentskw(&s->callee, s->jsn_buf);
1688 s->prmst = WAMP_PARAM_STATE_NONE;
1689 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1690 }
1691 else
1692 s->state = WAMP_PARSE_STATE_ERROR;
1693 }
1694 else {
1695 wamp_callee_invocation_argumentskw_param(&s->callee, action, state, buf);
1696 }
1697 break;
1698 default:
1699 s->state = WAMP_PARSE_STATE_ERROR;
1700 break;
1701 }
1702}
1703
1704/*
1705 * [INTERRUPT, INVOCATION.Request|id, Options|dict]
1706 */
1707static void wamp_proc_interrupt_state(wamp_state_t *s, jsonsl_action_t action,
1708 struct jsonsl_state_st *state, const char *buf)
1709{
1710 switch (s->prmst) {
1711 case WAMP_PARAM_STATE_REQUEST_ID:
1712 if ((action == JSONSL_ACTION_POP)
1713 && (state->type == JSONSL_T_SPECIAL)) {
1714 wamp_callee_interrupt_request_id(&s->callee, s->jsn_buf);
1715 s->prmst = WAMP_PARAM_STATE_OPTIONS_DICT;
1716 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1717 }
1718 else
1719 s->state = WAMP_PARSE_STATE_ERROR;
1720 break;
1721 case WAMP_PARAM_STATE_OPTIONS_DICT:
1722 if (state->level == 2) {
1723 if ((action == JSONSL_ACTION_POP)
1724 && (state->type == JSONSL_T_OBJECT)) {
1725 wamp_callee_interrupt_options(&s->callee, s->jsn_buf);
1726 s->prmst = WAMP_PARAM_STATE_NONE;
1727 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1728 }
1729 else
1730 s->state = WAMP_PARSE_STATE_ERROR;
1731 }
1732 else {
1733 wamp_callee_interrupt_options_param(&s->callee, action, state, buf);
1734 }
1735 break;
1736 default:
1737 s->state = WAMP_PARSE_STATE_ERROR;
1738 break;
1739 }
1740}
1741
1742/*
1743 * [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list, ArgumentsKw|dict]
1744 */
1745static void wamp_proc_yield_state(wamp_state_t *s, jsonsl_action_t action,
1746 struct jsonsl_state_st *state, const char *buf)
1747{
1748 switch (s->prmst) {
1749 case WAMP_PARAM_STATE_REQUEST_ID:
1750 if ((action == JSONSL_ACTION_POP)
1751 && (state->type == JSONSL_T_SPECIAL)) {
1752 wamp_dealer_yield_request_id(&s->dealer, s->jsn_buf);
1753 s->prmst = WAMP_PARAM_STATE_OPTIONS_DICT;
1754 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1755 }
1756 else
1757 s->state = WAMP_PARSE_STATE_ERROR;
1758 break;
1759 case WAMP_PARAM_STATE_OPTIONS_DICT:
1760 if (state->level == 2) {
1761 if ((action == JSONSL_ACTION_POP)
1762 && (state->type == JSONSL_T_OBJECT)) {
1763 wamp_dealer_yield_options(&s->dealer, s->jsn_buf);
1764 s->prmst = WAMP_PARAM_STATE_ARGUMENTS_LIST;
1765 s->state = WAMP_PARSE_STATE_LIST_PUSH;
1766 }
1767 else
1768 s->state = WAMP_PARSE_STATE_ERROR;
1769 }
1770 else {
1771 wamp_dealer_yield_options_param(&s->dealer, action, state, buf);
1772 }
1773 break;
1774 case WAMP_PARAM_STATE_ARGUMENTS_LIST:
1775 if (state->level == 2) {
1776 if ((action == JSONSL_ACTION_POP)
1777 && (state->type == JSONSL_T_LIST)) {
1778 wamp_dealer_yield_arguments(&s->dealer, s->jsn_buf);
1779 s->prmst = WAMP_PARAM_STATE_ARGUMENTSKW_DICT;
1780 s->state = WAMP_PARSE_STATE_DICT_PUSH;
1781 }
1782 else
1783 s->state = WAMP_PARSE_STATE_ERROR;
1784 }
1785 else {
1786 wamp_dealer_yield_arguments_param(&s->dealer, action, state, buf);
1787 }
1788 break;
1789 case WAMP_PARAM_STATE_ARGUMENTSKW_DICT:
1790 if (state->level == 2) {
1791 if ((action == JSONSL_ACTION_POP)
1792 && (state->type == JSONSL_T_OBJECT)) {
1793 wamp_dealer_yield_argumentskw(&s->dealer, s->jsn_buf);
1794 s->prmst = WAMP_PARAM_STATE_NONE;
1795 s->state = WAMP_PARSE_STATE_NOMORE_PARAM;
1796 }
1797 else
1798 s->state = WAMP_PARSE_STATE_ERROR;
1799 }
1800 else {
1801 wamp_dealer_yield_argumentskw_param(&s->dealer, action, state, buf);
1802 }
1803 break;
1804 default:
1805 s->state = WAMP_PARSE_STATE_ERROR;
1806 break;
1807 }
1808}
1809
1810void wamp_error(wamp_state_t *s)
1811{
1812}
1813
1814void wamp_error_type(wamp_state_t *s, const char *value)
1815{
1816}
1817
1818void wamp_error_request_id(wamp_state_t *s, const char *value)
1819{
1820}
1821
1822void wamp_error_details(wamp_state_t *s, const char *value)
1823{
1824}
1825
1826void wamp_error_details_param(wamp_state_t *s, jsonsl_action_t action,
1827 struct jsonsl_state_st *state, const char *buf)
1828{
1829}
1830
1831void wamp_error_uri(wamp_state_t *s, const char *value)
1832{
1833}
1834
1835void wamp_error_arguments(wamp_state_t *s, const char *value)
1836{
1837}
1838
1839void wamp_error_arguments_param(wamp_state_t *s, jsonsl_action_t action,
1840 struct jsonsl_state_st *state, const char *buf)
1841{
1842}
1843
1844void wamp_error_argumentskw(wamp_state_t *s, const char *value)
1845{
1846}
1847
1848void wamp_error_argumentskw_param(wamp_state_t *s, jsonsl_action_t action,
1849 struct jsonsl_state_st *state, const char *buf)
1850{
1851}
1852
1853static void wamp_error_close(wamp_state_t *s)
1854{
1855}
1856
1857static void wamp_param_handler(struct wamp_state *s, jsonsl_action_t action,
1858 wamp_param_state_t param, const char *value)
1859{
1860}
1861
1862ER wamp_send_error_res(struct wamp_state *s, wamp_code_t code, int requestId, const char *error)
1863{
1864 ECN_FBS_ID buf;
1865 ECN_FBS_SSIZE_T pos = 0;
1866 ER ret;
1867
1868 ret = _ecn_fbs_cre(1, &buf);
1869 if (ret != E_OK) {
1870 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1871 return ret;
1872 }
1873
1874 ret = fbs_printf(buf, &pos, "[8,%d,%d,{},\"%s\"]", (int)code, requestId, error);
1875 if (ret != E_OK) {
1876 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1877 _ecn_fbs_del(buf);
1878 return ret;
1879 }
1880
1881 return main_send_message(buf, s->wbsid);
1882}
Note: See TracBrowser for help on using the repository browser.