+static int client_make_ids(struct afb_stub_ws *stubws, struct afb_proto_ws *proto, struct afb_context *context, uint16_t *sessionid, uint16_t *tokenid)
+{
+ int rc, rc2;
+ uint16_t sid, tid;
+
+ rc = 0;
+
+ /* get the session */
+ if (!context->session)
+ sid = 0;
+ else {
+ sid = afb_session_id(context->session);
+ rc2 = u16id2bool_set(&stubws->session_flags, sid, 1);
+ if (rc2 < 0)
+ rc = rc2;
+ else if (rc2 == 0)
+ rc = afb_proto_ws_client_session_create(proto, sid, afb_session_uuid(context->session));
+ }
+
+ /* get the token */
+ if (!context->token)
+ tid = 0;
+ else {
+ tid = afb_token_id(context->token);
+ rc2 = u16id2bool_set(&stubws->token_flags, tid, 1);
+ if (rc2 < 0)
+ rc = rc2;
+ else if (rc2 == 0) {
+ rc2 = afb_proto_ws_client_token_create(proto, tid, afb_token_string(context->token));
+ if (rc2 < 0)
+ rc = rc2;
+ }
+ }
+
+ *sessionid = sid;
+ *tokenid = tid;
+ return rc;
+}
+