Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1594316022, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"7aaf65c4c73ef5645309bd3a4e32a778", "oid":{ "oid": "1be6b4d075e63cbe9d4c4f9696a0a7647c475068", "alias": [ "refs/heads/master"]},"blobname": "plugins/protocol_dumb_increment.c", "blob": "/*\n * ws protocol handler plugin for \u0022dumb increment\u0022\n *\n * Written in 2010-2019 by Andy Green \u003candy@warmcat.com\u003e\n *\n * This file is made available under the Creative Commons CC0 1.0\n * Universal Public Domain Dedication.\n *\n * The person who associated a work with this deed has dedicated\n * the work to the public domain by waiving all of his or her rights\n * to the work worldwide under copyright law, including all related\n * and neighboring rights, to the extent allowed by law. You can copy,\n * modify, distribute and perform the work, even for commercial purposes,\n * all without asking permission.\n *\n * These test plugins are intended to be adapted for use in your code, which\n * may be proprietary. So unlike the library itself, they are licensed\n * Public Domain.\n */\n\n#if !defined (LWS_PLUGIN_STATIC)\n#define LWS_DLL\n#define LWS_INTERNAL\n#include \u003clibwebsockets.h\u003e\n#endif\n\n#include \u003cstring.h\u003e\n\n#define DUMB_PERIOD_US 50000\n\nstruct pss__dumb_increment {\n\tint number;\n};\n\nstruct vhd__dumb_increment {\n\tconst unsigned int *options;\n};\n\nstatic int\ncallback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,\n\t\t\tvoid *user, void *in, size_t len)\n{\n\tstruct pss__dumb_increment *pss \u003d (struct pss__dumb_increment *)user;\n\tstruct vhd__dumb_increment *vhd \u003d\n\t\t\t\t(struct vhd__dumb_increment *)\n\t\t\t\tlws_protocol_vh_priv_get(lws_get_vhost(wsi),\n\t\t\t\t\t\tlws_get_protocol(wsi));\n\tuint8_t buf[LWS_PRE + 20], *p \u003d \u0026buf[LWS_PRE];\n\tconst struct lws_protocol_vhost_options *opt;\n\tint n, m;\n\n\tswitch (reason) {\n\tcase LWS_CALLBACK_PROTOCOL_INIT:\n\t\tvhd \u003d lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi),\n\t\t\tlws_get_protocol(wsi),\n\t\t\tsizeof(struct vhd__dumb_increment));\n\t\tif (!vhd)\n\t\t\treturn -1;\n\t\tif ((opt \u003d lws_pvo_search(\n\t\t\t\t(const struct lws_protocol_vhost_options *)in,\n\t\t\t\t\u0022options\u0022)))\n\t\t\tvhd-\u003eoptions \u003d (unsigned int *)opt-\u003evalue;\n\t\tbreak;\n\n\tcase LWS_CALLBACK_ESTABLISHED:\n\t\tpss-\u003enumber \u003d 0;\n\t\tif (!vhd-\u003eoptions || !((*vhd-\u003eoptions) \u0026 1))\n\t\t\tlws_set_timer_usecs(wsi, DUMB_PERIOD_US);\n\t\tbreak;\n\n\tcase LWS_CALLBACK_SERVER_WRITEABLE:\n\t\tn \u003d lws_snprintf((char *)p, sizeof(buf) - LWS_PRE, \u0022%d\u0022,\n\t\t\t\t pss-\u003enumber++);\n\t\tm \u003d lws_write(wsi, p, n, LWS_WRITE_TEXT);\n\t\tif (m \u003c n) {\n\t\t\tlwsl_err(\u0022ERROR %d writing to di socket\u005cn\u0022, n);\n\t\t\treturn -1;\n\t\t}\n\t\tbreak;\n\n\tcase LWS_CALLBACK_RECEIVE:\n\t\tif (len \u003c 6)\n\t\t\tbreak;\n\t\tif (strncmp((const char *)in, \u0022reset\u005cn\u0022, 6) \u003d\u003d 0)\n\t\t\tpss-\u003enumber \u003d 0;\n\t\tif (strncmp((const char *)in, \u0022closeme\u005cn\u0022, 8) \u003d\u003d 0) {\n\t\t\tlwsl_notice(\u0022dumb_inc: closing as requested\u005cn\u0022);\n\t\t\tlws_close_reason(wsi, LWS_CLOSE_STATUS_GOINGAWAY,\n\t\t\t\t\t (unsigned char *)\u0022seeya\u0022, 5);\n\t\t\treturn -1;\n\t\t}\n\t\tbreak;\n\n\tcase LWS_CALLBACK_TIMER:\n\t\tif (!vhd-\u003eoptions || !((*vhd-\u003eoptions) \u0026 1)) {\n\t\t\tlws_callback_on_writable_all_protocol_vhost(\n\t\t\t\tlws_get_vhost(wsi), lws_get_protocol(wsi));\n\t\t\tlws_set_timer_usecs(wsi, DUMB_PERIOD_US);\n\t\t}\n\t\tbreak;\n\n\tdefault:\n\t\tbreak;\n\t}\n\n\treturn 0;\n}\n\n#define LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT \u005c\n\t{ \u005c\n\t\t\u0022dumb-increment-protocol\u0022, \u005c\n\t\tcallback_dumb_increment, \u005c\n\t\tsizeof(struct pss__dumb_increment), \u005c\n\t\t10, /* rx buf size must be \u003e\u003d permessage-deflate rx size */ \u005c\n\t\t0, NULL, 0 \u005c\n\t}\n\n#if !defined (LWS_PLUGIN_STATIC)\n\t\t\nstatic const struct lws_protocols protocols[] \u003d {\n\tLWS_PLUGIN_PROTOCOL_DUMB_INCREMENT\n};\n\nLWS_VISIBLE int\ninit_protocol_dumb_increment(struct lws_context *context,\n\t\t\t struct lws_plugin_capability *c)\n{\n\tif (c-\u003eapi_magic !\u003d LWS_PLUGIN_API_MAGIC) {\n\t\tlwsl_err(\u0022Plugin API %d, library API %d\u0022, LWS_PLUGIN_API_MAGIC,\n\t\t\t c-\u003eapi_magic);\n\t\treturn 1;\n\t}\n\n\tc-\u003eprotocols \u003d protocols;\n\tc-\u003ecount_protocols \u003d LWS_ARRAY_SIZE(protocols);\n\tc-\u003eextensions \u003d NULL;\n\tc-\u003ecount_extensions \u003d 0;\n\n\treturn 0;\n}\n\nLWS_VISIBLE int\ndestroy_protocol_dumb_increment(struct lws_context *context)\n{\n\treturn 0;\n}\n\n#endif\n","s":{"c":1594316022,"u": 266}} ],"g": 1687,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 1, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}