diff options
Diffstat (limited to 'src/h.c')
-rw-r--r-- | src/h.c | 27 |
1 files changed, 21 insertions, 6 deletions
@@ -18,7 +18,7 @@ enum dc_status { /* theese are flags and should be and-checked */ DC_UNSET = 0, /* default value when enum is calloced */ DC_INCOMPLETE = 1 << 0, /* struct SHALL NOT be used by the ui, it is yet to be filled by api */ - DC_OK = 1 << 1, /* success status, api usually sets this after completion/filling of the strct */ + DC_OK = 1 << 1, /* success status and also ws established*/ DC_BAD_LOGIN = 1 << 2, /* login failed because of wrong credentials */ DC_VERIFICATION_NEEDED = 1 << 3, /* login: check email, click link/reg: tough luck ur IP flagd */ DC_CAPTCHA_NEEDED = 1 << 4, /* must solve captcha, tough luck, not impl, use browser login */ @@ -30,8 +30,10 @@ enum dc_status { /* theese are flags and should be and-checked */ DC_FROM_LWS = 1 << 10, /* LWS cb is the caller, so do not attempt to do lws_service (loop) */ DC_MUST_FREE = 1 << 11, /* cb pass: body must be freed when request is done with user_data */ DC_REQUEST_FAILED = 1 << 12, /* http request failed, reported to ui */ - DC_ERROR = 1 << 13 /* unknown error, non implemented non expected response */ -}; + DC_ERROR = 1 << 13, /* unknown error, non implemented non expected response */ + DC_NET_ERROR = 1 << 14, /* network failed or ws closed */ + DC_LEJP_CONSTRUCTED = 1 << 15 /* json parser was constructed */ +}; /* note: when checking status, first check for DC_OK, if it's set then disregard errors! */ enum dc_permissions { /* other permissions exist, but are not implemented/understood */ DC_ALL_PERMISSIONS = 1 << 3, /* this is incredibly retarded, why is this SEPARATE?!? - admins */ DC_CHANNEL_VIEW = 1 << 10, /* all enum fields here have values same as the server values */ @@ -63,7 +65,11 @@ enum dc_api_io_type { DC_API_LOGIN, /* i: pass a dc_client-tr1, to relogin FIX prev retd cl not create new */ /* o: the previously passed dc_client with set status, do not use yet! \/ */ DC_API_LOGIN_CB,/* i: used internally for passing response from http client to api, see source */ - /* o: to tell user that client is now fully filled and ready for use */ + /* o: to tell user that ->client is now fully filled and ready for use */ + DC_API_WS, /* i: internal, LOGIN_CB calls it to start websocket setup */ + /* o: ->status of websocket setup (DC_OK indicates success) */ + DC_API_WS_CB, /* i: internal, for passing response from ws lib to api, see source */ + /* o: N/A */ DC_API_REGISTER,/* i: pass a dc_client, to relogin FIX pr rt cl&cl->user not creat new */ /* o: the previously passed dc_client with set status */ DC_API_STATUS, /* i: N/A */ @@ -74,7 +80,7 @@ enum dc_api_io_type { /* o: prev passed dc_role but filled (or not: ->status may indicate error) */ DC_API_ATTACH /* i: attaches function to handle output types */ /* o: N/A */ -}; +}; /* do not confuse yourself, when for example login response is checked for errors, check client->status and not struct dc_api_io's member named status. that member is mostly only used internally. */ /* enum dc_status (* dc_api_attached_func) (struct dc_api_io, void * data); */ /* i tried simplifying but didn't work */ struct dc_api_io { /* output struct does NOT contain void * data (user pointer) from the input struct! */ DC_STRUCT_PREFIX /* mostly useless here but it's only a couple of bytes so wth */ @@ -108,12 +114,21 @@ char * dc_lws_headers[] = { "Authorization:", "Content-Type:" }; +enum dc_json_paths { /* lws reduces the following char array to uint8_t, so we can match easier */ + DC_JSON_OP, + DC_JSON_PATHS_LENGTH +} +char * dc_json_paths[] = { /* array of paths we are interested in */ + "op", +} struct dc_lws_pass { /* struct that is allocated for in dc_lws_cb unique per connection in void * us */ char * body; /* this contains post body and when _CB is called, it contains response */ size_t body_length; /* body is NULL terminated or NULL in case of failure */ char headers[DC_LWS_HEADERS_LENGTH][DC_LWS_MAX_HEADER_LENGTH]; /* nofree, a static 2d array */ int status; /* HTTP response code /\ headers contain request headers, then resp. */ struct dc_api_io api_io; /* so dc_api_io can decide what shall be passed into _CB */ + struct lejp_ctx json; /* holds a context for lejp */ + enum lejp_callbacks json_reason; /* holds last reason sent to json callback */ }; struct dc_client { DC_STRUCT_PREFIX @@ -300,7 +315,7 @@ void dc_attached_function_free (struct dc_attached_function * s) { } static int dc_lws_cb (struct lws *, enum lws_callback_reasons, void *, void *, size_t); static const struct lws_protocols dc_lws_protocols[] = { - {"dc", dc_lws_cb, sizeof(struct dc_lws_pass), DC_LWS_MAX_RX, 0, NULL, 0}, + {"dc", dc_lws_cb, /* sizeof(struct dc_lws_pass) */ 0 /* lws naj NE ALOCIRA */, DC_LWS_MAX_RX, 0, NULL, 0}, {NULL, NULL, 0, 0, 0, NULL, 0} }; #define DC_ISASQ(shortname) DC_ISA(struct dc_##shortname, shortname##s) /* in struct array of structs quick */ |