libwebsockets
Lightweight C library for HTML5 websockets
lws-jrpc.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lws_jrpc_method
 

Macros

#define LWSJRPCBP_REQ_START_S   "{\"jsonrpc\":\"2.0\",\"method\":\"%s\""
 
#define LWSJRPCBP_REQ_VERSION_S   ",\"version\":\"%s\""
 
#define LWSJRPCBP_REQ_PARAMS   ",\"params\":"
 
#define LWSJRPCBP_REQ_NOTIF_END   "}"
 
#define LWSJRPCBP_REQ_ID_END_S   ",\"id\":%s}"
 
#define LWSJRPCBP_RESP_RESULT   "{\"jsonrpc\":\"2.0\",\"result\":"
 
#define LWSJRPCBP_RESP_ID_END_S   ",\"id\":%s}"
 
#define LWSJRPCBP_RESP_ERROR_D   "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":%d"
 
#define LWSJRPCBP_RESP_ERROR_MSG_S   ",\"message\":\"%s\""
 
#define LWSJRPCBP_RESP_ERROR_DATA   ",\"data\":"
 
#define LWSJRPCBP_RESP_ERROR_END   "}"
 

Typedefs

typedef struct lws_jrpc_method lws_jrpc_method_t
 

Enumerations

enum  lws_jrpc_cb_return_t { LJRPC_CBRET_CONTINUE , LJRPC_CBRET_WANT_TO_EMIT , LJRPC_CBRET_FINISHED , LJRPC_CBRET_FAILED }
 
enum  {
  LWSJRPCE__NO_ERROR = 0 , LWSJRPCWKE__PARSE_ERROR = -32700 , LWSJRPCWKE__INVALID_REQUEST = -32600 , LWSJRPCWKE__METHOD_NOT_FOUND = -32601 ,
  LWSJRPCWKE__INVALID_PARAMS = -32602 , LWSJRPCWKE__INTERNAL_ERROR = -32603 , LWSJRPCWKE__SERVER_ERROR_FIRST = -32000 , LWSJRPCWKE__SERVER_ERROR_LAST = -32099 ,
  LWSJRPCE__INVALID_MEMBERS = -31000
}
 
enum  { LWSJRPC_PARSE_REQUEST , LWSJRPC_PARSE_RESPONSE }
 

Functions

LWS_VISIBLE LWS_EXTERN int lws_jrpc_obj_parse (struct lws_jrpc *jrpc, int type, void *opaque, const char *buf, size_t l, struct lws_jrpc_obj **r)
 
LWS_VISIBLE LWS_EXTERN void lws_jrpc_obj_destroy (struct lws_jrpc_obj **_r)
 
LWS_VISIBLE LWS_EXTERN void * lws_jrpc_obj_get_opaque (const struct lws_jrpc_obj *r)
 
LWS_VISIBLE LWS_EXTERN const char * lws_jrpc_obj_id (const struct lws_jrpc_obj *r)
 
LWS_VISIBLE LWS_EXTERN struct lws_jrpc * lws_jrpc_create (const lws_jrpc_method_t *methods, void *opaque)
 
LWS_VISIBLE LWS_EXTERN void lws_jrpc_destroy (struct lws_jrpc **jrpc)
 

Data Structure Documentation

◆ lws_jrpc_method

struct lws_jrpc_method

Definition at line 77 of file lws-jrpc.h.

+ Collaboration diagram for lws_jrpc_method:
Data Fields
const char * method_name
const char *const * paths
lejp_callback cb
int count_paths

Macro Definition Documentation

◆ LWSJRPCBP_REQ_START_S

#define LWSJRPCBP_REQ_START_S   "{\"jsonrpc\":\"2.0\",\"method\":\"%s\""

Definition at line 89 of file lws-jrpc.h.

◆ LWSJRPCBP_REQ_VERSION_S

#define LWSJRPCBP_REQ_VERSION_S   ",\"version\":\"%s\""

Definition at line 91 of file lws-jrpc.h.

◆ LWSJRPCBP_REQ_PARAMS

#define LWSJRPCBP_REQ_PARAMS   ",\"params\":"

Definition at line 93 of file lws-jrpc.h.

◆ LWSJRPCBP_REQ_NOTIF_END

#define LWSJRPCBP_REQ_NOTIF_END   "}"

Definition at line 95 of file lws-jrpc.h.

◆ LWSJRPCBP_REQ_ID_END_S

#define LWSJRPCBP_REQ_ID_END_S   ",\"id\":%s}"

Definition at line 97 of file lws-jrpc.h.

◆ LWSJRPCBP_RESP_RESULT

#define LWSJRPCBP_RESP_RESULT   "{\"jsonrpc\":\"2.0\",\"result\":"

Definition at line 104 of file lws-jrpc.h.

◆ LWSJRPCBP_RESP_ID_END_S

#define LWSJRPCBP_RESP_ID_END_S   ",\"id\":%s}"

Definition at line 106 of file lws-jrpc.h.

◆ LWSJRPCBP_RESP_ERROR_D

#define LWSJRPCBP_RESP_ERROR_D   "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":%d"

Definition at line 109 of file lws-jrpc.h.

◆ LWSJRPCBP_RESP_ERROR_MSG_S

#define LWSJRPCBP_RESP_ERROR_MSG_S   ",\"message\":\"%s\""

Definition at line 111 of file lws-jrpc.h.

◆ LWSJRPCBP_RESP_ERROR_DATA

#define LWSJRPCBP_RESP_ERROR_DATA   ",\"data\":"

Definition at line 113 of file lws-jrpc.h.

◆ LWSJRPCBP_RESP_ERROR_END

#define LWSJRPCBP_RESP_ERROR_END   "}"

Definition at line 115 of file lws-jrpc.h.

Typedef Documentation

◆ lws_jrpc_method_t

Enumeration Type Documentation

◆ lws_jrpc_cb_return_t

Enumerator
LJRPC_CBRET_CONTINUE 
LJRPC_CBRET_WANT_TO_EMIT 
LJRPC_CBRET_FINISHED 
LJRPC_CBRET_FAILED 

Definition at line 66 of file lws-jrpc.h.

66 {
lws_jrpc_cb_return_t
Definition: lws-jrpc.h:66
@ LJRPC_CBRET_CONTINUE
Definition: lws-jrpc.h:67
@ LJRPC_CBRET_FAILED
Definition: lws-jrpc.h:70
@ LJRPC_CBRET_WANT_TO_EMIT
Definition: lws-jrpc.h:68
@ LJRPC_CBRET_FINISHED
Definition: lws-jrpc.h:69

◆ anonymous enum

anonymous enum
Enumerator
LWSJRPCE__NO_ERROR 
LWSJRPCWKE__PARSE_ERROR 
LWSJRPCWKE__INVALID_REQUEST 
LWSJRPCWKE__METHOD_NOT_FOUND 
LWSJRPCWKE__INVALID_PARAMS 
LWSJRPCWKE__INTERNAL_ERROR 
LWSJRPCWKE__SERVER_ERROR_FIRST 
LWSJRPCWKE__SERVER_ERROR_LAST 
LWSJRPCE__INVALID_MEMBERS 

Definition at line 121 of file lws-jrpc.h.

121 {
123
124 LWSJRPCWKE__PARSE_ERROR = -32700, /* invalid JSON */
125 LWSJRPCWKE__INVALID_REQUEST = -32600, /* not valid JSONRPC object */
126 LWSJRPCWKE__METHOD_NOT_FOUND = -32601, /* method not supported */
127 LWSJRPCWKE__INVALID_PARAMS = -32602, /* parameters are invalid */
128 LWSJRPCWKE__INTERNAL_ERROR = -32603, /* internal JSONRPC error */
129 LWSJRPCWKE__SERVER_ERROR_FIRST = -32000, /* implementation-defined...*/
130 LWSJRPCWKE__SERVER_ERROR_LAST = -32099, /* ... server errors range */
131
132 LWSJRPCE__INVALID_MEMBERS = -31000, /* reponse membs in req, vv */
133};
@ LWSJRPCE__NO_ERROR
Definition: lws-jrpc.h:122
@ LWSJRPCWKE__SERVER_ERROR_LAST
Definition: lws-jrpc.h:130
@ LWSJRPCE__INVALID_MEMBERS
Definition: lws-jrpc.h:132
@ LWSJRPCWKE__INVALID_REQUEST
Definition: lws-jrpc.h:125
@ LWSJRPCWKE__INVALID_PARAMS
Definition: lws-jrpc.h:127
@ LWSJRPCWKE__SERVER_ERROR_FIRST
Definition: lws-jrpc.h:129
@ LWSJRPCWKE__INTERNAL_ERROR
Definition: lws-jrpc.h:128
@ LWSJRPCWKE__METHOD_NOT_FOUND
Definition: lws-jrpc.h:126
@ LWSJRPCWKE__PARSE_ERROR
Definition: lws-jrpc.h:124

◆ anonymous enum

anonymous enum
Enumerator
LWSJRPC_PARSE_REQUEST 
LWSJRPC_PARSE_RESPONSE 

Definition at line 135 of file lws-jrpc.h.

135 {
138};
@ LWSJRPC_PARSE_RESPONSE
Definition: lws-jrpc.h:137
@ LWSJRPC_PARSE_REQUEST
Definition: lws-jrpc.h:136

Function Documentation

◆ lws_jrpc_obj_parse()

LWS_VISIBLE LWS_EXTERN int lws_jrpc_obj_parse ( struct lws_jrpc *  jrpc,
int  type,
void *  opaque,
const char *  buf,
size_t  l,
struct lws_jrpc_obj **  r 
)

lws_jrpc_obj_parse() - parse a request or response

Parameters
jrpcthe jrpc context this belongs to
typeLWSJRPC_PARSE_REQUEST or ..._RESPONSE
opaqueuser-defined pointer bound to lws_jrpc, ignored by lws
bufchunk of JSON-RPC
lremaining length of JSON (may be under or oversize)
rNULL to indicate starting new req, already set means continue parse

If necessary creates an opaque req object and starts parsing len bytes of buf. This may be undersize (more parts coming) in which case req will be set on entry next time indicating a continuation.

type and opaque are ignored if it it's not the first buffer that creates the req object.

Return code is >= 0 if completed, representing the amount of unused data in the input buffer. -1 indicates more input data needed, <-1 indicates an error from the LWSJRPCWKE_ set above, or LEJP_REJECT_UNKNOWN for OOM

◆ lws_jrpc_obj_destroy()

LWS_VISIBLE LWS_EXTERN void lws_jrpc_obj_destroy ( struct lws_jrpc_obj **  _r)

◆ lws_jrpc_obj_get_opaque()

LWS_VISIBLE LWS_EXTERN void * lws_jrpc_obj_get_opaque ( const struct lws_jrpc_obj *  r)

◆ lws_jrpc_obj_id()

LWS_VISIBLE LWS_EXTERN const char * lws_jrpc_obj_id ( const struct lws_jrpc_obj *  r)

◆ lws_jrpc_create()

LWS_VISIBLE LWS_EXTERN struct lws_jrpc * lws_jrpc_create ( const lws_jrpc_method_t methods,
void *  opaque 
)

lws_jrpc_create() - Allocate and initialize a JRPC context

Parameters
methodsthe method callbacks and names we can process
opaqueuser-defined pointer bound to lws_jrpc ignored by lws

Allocates an opaque lws_jrpc object and binds it to the given array of method names and callbacks

◆ lws_jrpc_destroy()

LWS_VISIBLE LWS_EXTERN void lws_jrpc_destroy ( struct lws_jrpc **  jrpc)