catalinux / Conn (public) (License: LGPLv2) (since 2016-03-01) (hash sha1)
Net library for easy building ipv4/ipv6 network daemons/clients
List of commits:
Subject Hash Author Date (UTC)
grid1 is working now 0370e6808f8b89fb9ae43fc139195e76247ad6c5 Catalin(ux) M. BOIE 2018-05-12 15:31:00
Added pie2 demo (svg) e8df18b15deafdd0a810a09a251593ecd5fc608f Catalin(ux) M. BOIE 2018-04-17 21:46:02
wsdemo: added Source button 010d08897f99736b9a3f5440af71c2dc40544e68 Catalin(ux) M. BOIE 2018-04-17 17:54:53
More tweaks to wsdemo 56173807662daf36b36907d98bde751749c91075 Catalin(ux) M. BOIE 2018-04-16 18:08:18
Added a callback for worker start 32a05f401d5258f06af9db15a00a615859961cc2 Catalin(ux) M. BOIE 2018-04-16 18:07:55
wsdemo improvements 3eb3efd007fc9240ea39fabcdb4729d1367ebad2 Catalin(ux) M. BOIE 2018-04-13 22:47:24
wsdemo added 2baae01f2409496f990b6d673013b66286f0a5af Catalin(ux) M. BOIE 2018-04-02 21:41:40
Various small stuff 0c551268be734dd68a59426315abfc6ef776c60a Catalin(ux) M. BOIE 2018-04-02 21:40:49
More debugging for websocket parsing 66ccde632b280f1aa450610e6b671464b7e56451 Catalin(ux) M. BOIE 2018-04-02 21:39:23
Raise to 4096 to buffer for logging a59dee1fdfe087ff13e4c7012fe29f8da99ad75c Catalin(ux) M. BOIE 2018-04-02 21:38:11
Bump version 9b635cebfffdd6971eefef0ebad395e21684bb8a Catalin(ux) M. BOIE 2018-01-13 18:07:12
Added some more compile flags and websocket1 helper files. fce47295946106956fb70da77244d77ffca09423 Catalin(ux) M. BOIE 2018-01-13 18:03:46
Lots of changes everywhere 91b9113e8f92db07c079c005273683f2e868910c Catalin(ux) M. BOIE 2018-01-12 19:06:04
Require openssl (for websocket) b4b34eb88f38bfd421187da76611cc54476d7309 Catalin(ux) M. BOIE 2017-12-30 23:44:50
Very important fixes 01e33f06a5cdc52fb3795158fd838fcca7055dda Catalin(ux) M. BOIE 2017-12-30 23:39:17
Bump version to 1.0.37 54e8f3bcaf7f7e096c454563039a545a4abb1bf0 Catalin(ux) M. BOIE 2017-12-30 22:13:12
Lots of small fixes 4894de0472e571b8c78294de527bf70089096545 Catalin(ux) M. BOIE 2017-12-30 22:11:09
Checkpoint b6bf45330f046da40d762b6fd10d1bb97bc40036 Catalin(ux) M. BOIE 2017-12-28 00:13:09
Fixed libConn*.so instalation. df1bef9190d30dd11fcd150b41810ce18278b74f Catalin(ux) M. BOIE 2015-04-25 14:43:37
libConn1.so was not included in spec file. dd99625a7fb70d66fa5a91371fb4d2eaf7a4f23d Catalin(ux) M. BOIE 2015-04-25 14:39:32
Commit 0370e6808f8b89fb9ae43fc139195e76247ad6c5 - grid1 is working now
Author: Catalin(ux) M. BOIE
Author date (UTC): 2018-05-12 15:31
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2018-05-12 15:31
Parent(s): e8df18b15deafdd0a810a09a251593ecd5fc608f
Signing key:
Tree: f508748d43e0c1177d825066c858baf137b0ecc1
File Lines added Lines deleted
examples/wsdemo.c 150 1
File examples/wsdemo.c changed (mode: 100644) (index a204181..cd18486)
12 12 #include <sys/time.h> #include <sys/time.h>
13 13 #include <sys/ioctl.h> #include <sys/ioctl.h>
14 14 #include <time.h> #include <time.h>
15 #include <ctype.h>
15 16 #include <stdarg.h> #include <stdarg.h>
16 17 #include <sys/capability.h> #include <sys/capability.h>
17 18
 
... ... struct priv {
35 36 unsigned int pie1_init:1; unsigned int pie1_init:1;
36 37 unsigned int pie2_init:1; unsigned int pie2_init:1;
37 38 unsigned int bar1_init:1; unsigned int bar1_init:1;
39 unsigned int grid1_init:1;
38 40
39 41 unsigned char per1_percent; unsigned char per1_percent;
40 42 unsigned char per2_percent; unsigned char per2_percent;
 
... ... static unsigned char band[2][BAND_VALUES];
58 60 static time_t band_last; // when the last value was updated static time_t band_last; // when the last value was updated
59 61 static int band_up = 30, band_down = 30; // fake start values static int band_up = 30, band_down = 30; // fake start values
60 62
63 /* grid1 is global */
64 static char grid1_data[3][3][64];
65
66
61 67 struct Clients struct Clients
62 68 { {
63 69 struct Conn *C; struct Conn *C;
 
... ... static void push_code(struct Conn *C, const char *code)
131 137 json_object_put(j); json_object_put(j);
132 138 } }
133 139
140 /*
141 * Send code to all other clients
142 */
143 static void push_code_broadcast(struct Conn *source, const char *code)
144 {
145 struct Clients *q;
146
147 q = Clients_head;
148 while (q) {
149 if (q->C != source)
150 push_code(q->C, code);
151 q = q->next;
152 }
153 }
154
134 155 static void notify(struct Conn *C, const char *format, ...) static void notify(struct Conn *C, const char *format, ...)
135 156 { {
136 157 char line[512]; char line[512];
 
... ... static void pie2(struct Conn *C)
771 792 push_code(C, code); push_code(C, code);
772 793 } }
773 794
795 static void grid1(struct Conn *C)
796 {
797 struct priv *p;
798 unsigned int i, j;
799 char code[128];
800
801 p = Conn_get_private(C);
802 if (!p->grid1_init) {
803 const char *u =
804 "window.wsdemo.grid1_oninput = function(id, i, j) {\n"
805 " var d = document.getElementById(id);\n"
806 " var data = { op: 'grid1_oninput', i: i, j: j, value: d.innerHTML };\n"
807 " ws.send(JSON.stringify(data));\n"
808 " console.log('grid1_oninput: id=' + id + ' i=' + i + ' j=' + j);\n"
809 "}\n"
810 "\n"
811 "window.wsdemo.grid1_update = function(i, j, value) {\n"
812 " var d = document.getElementById('grid1-' + i + '-' + j);\n"
813 " d.innerHTML = value;\n"
814 "}\n"
815 "\n"
816 "window.wsdemo.grid1_init = function(a) {\n"
817 " var i;\n"
818 " var d;\n"
819 "\n"
820 " d = document.getElementById('grid1');\n"
821 " if (d.children[0] != null)\n"
822 " return;\n"
823 "\n"
824 " var t = document.createElement('table');\n"
825 "\n"
826 " t.style.border = '1px solid black';\n"
827 " t.style.borderCollapse = 'collapse';\n"
828 " t.style.margin = '3px';\n"
829 " t.style.padding = '5px';\n"
830 " for (i = 0; i < 3; i++) {\n"
831 " var tr = t.insertRow();\n"
832 " for (j = 0; j < 3; j++) {\n"
833 " var td = tr.insertCell();\n"
834 " var v = '?';\n"
835 " td.style.border = '1px solid black';\n"
836 " td.contentEditable = true;\n"
837 " td.id = 'grid1-' + i + '-' + j;\n"
838 " var tn = document.createTextNode(v);\n"
839 " td.appendChild(tn);\n"
840 " td.setAttribute('oninput', 'window.wsdemo.grid1_oninput(this.id,' + i + ',' + j + ');');\n"
841 " }\n"
842 " }\n"
843 " d.appendChild(t);\n"
844 "}\n"
845 "\n"
846 "window.wsdemo.grid1_init();";
847 push_code(C, u);
848
849 for (i = 0; i < 3; i++) {
850 for (j = 0; j < 3; j++) {
851 snprintf(code, sizeof(code),
852 "window.wsdemo.grid1_update(%hhu, %hhu, '%s');",
853 i, j, grid1_data[i][j]);
854 push_code(C, code);
855 }
856 }
857
858 p->grid1_init = 1;
859 }
860 }
861
774 862 static void trigger(struct Conn *C) static void trigger(struct Conn *C)
775 863 { {
776 864 struct priv *p; struct priv *p;
 
... ... static void trigger(struct Conn *C)
835 923 cyl1(C); cyl1(C);
836 924 pie1(C); pie1(C);
837 925 pie2(C); pie2(C);
926 grid1(C);
838 927 } }
839 928
840 929 static const char main_screen[] = static const char main_screen[] =
 
... ... static const char main_screen[] =
967 1056 "</div>\n" "</div>\n"
968 1057 "\n" "\n"
969 1058 "<div class=\"gem\">\n" "<div class=\"gem\">\n"
1059 " Editable grid (HTML5 content editable)<br />\n"
1060 " <div id=\"grid1\"></div>\n"
1061 " <input type=\"button\" onclick=\"window.wsdemo.source('grid1');\" value=\"Source\" />\n"
1062 " <div class=\"source\" id=\"grid1_source\"></div>\n"
1063 " <div class=\"note\" width=\"200px\">"
1064 " Note: please load this page on two different devices, then try"
1065 " to change the content of a cell and watch the other device to"
1066 " see how the value changes."
1067 " </div>\n"
1068 "</div>\n"
1069 "\n"
1070 "<div class=\"gem\">\n"
970 1071 "Buttons<br />\n" "Buttons<br />\n"
971 1072 "<input type=\"button\" onclick=\"window.wsdemo.button('notify');\"" "<input type=\"button\" onclick=\"window.wsdemo.button('notify');\""
972 1073 " value=\"trigger notification\" />\n" " value=\"trigger notification\" />\n"
973 "</div>\n";
1074 "</div>\n"
1075 "\n";
974 1076
975 1077 static void accept_cb(struct Conn *C) static void accept_cb(struct Conn *C)
976 1078 { {
 
... ... static void process_json(struct Conn *C, struct json_object *j)
1043 1145 const char *s_op, *s_answer, *s_text; const char *s_op, *s_answer, *s_text;
1044 1146 struct json_object *op, *answer, *text; struct json_object *op, *answer, *text;
1045 1147 struct priv *priv; struct priv *priv;
1148 char code[4096];
1046 1149
1047 1150 Log(10, "%llu %s\n", Conn_get_id(C), __func__); Log(10, "%llu %s\n", Conn_get_id(C), __func__);
1048 1151
 
... ... static void process_json(struct Conn *C, struct json_object *j)
1106 1209 Log(10, "\tWe have a resize event [x=%u y=%u]!\n", Log(10, "\tWe have a resize event [x=%u y=%u]!\n",
1107 1210 priv->x, priv->y); priv->x, priv->y);
1108 1211
1212 json_object_put(answer);
1109 1213 return; return;
1110 1214 } }
1111 1215
 
... ... static void process_json(struct Conn *C, struct json_object *j)
1117 1221 notify(C, "Welcome to wsdemo! You can push a notification from" notify(C, "Welcome to wsdemo! You can push a notification from"
1118 1222 " the server whenever is needed."); " the server whenever is needed.");
1119 1223 } }
1224 json_object_put(answer);
1225 return;
1226 }
1227
1228 if (strcmp(s_op, "grid1_oninput") == 0) {
1229 unsigned char i, k;
1230 char *q;
1231
1232 json_object_object_get_ex(j, "i", &text);
1233 i = json_object_get_int(text);
1234
1235 json_object_object_get_ex(j, "j", &text);
1236 k = json_object_get_int(text);
1237
1238 json_object_object_get_ex(j, "value", &text);
1239 s_text = json_object_get_string(text);
1240
1241 Log(10, "\tWe have a grid1 event [i=%hhu j=%hhu value=[%s]]!\n",
1242 i, k, s_text);
1243
1244 if ((i < 3) && (k < 3))
1245 snprintf(grid1_data[i][k], sizeof(grid1_data[i][k]),
1246 "%s", s_text);
1247
1248 q = s_text;
1249 while (isalnum(*q))
1250 q++;
1251 *q = '\0';
1252
1253 snprintf(code, sizeof(code),
1254 "window.wsdemo.grid1_update(%hhu, %hhu, '%s');",
1255 i, k, s_text);
1256 push_code_broadcast(C, code);
1257
1258 json_object_put(answer);
1120 1259 return; return;
1121 1260 } }
1122 1261
 
... ... int main(void)
1222 1361 char *stats, path[256]; char *stats, path[256];
1223 1362 struct timeval now; struct timeval now;
1224 1363 struct tm tm; struct tm tm;
1364 unsigned int i, j;
1365
1366 // Global data init
1367 // Init grid1 data
1368 for (i = 0; i < 3; i++) {
1369 for (j = 0; j < 3; j++) {
1370 snprintf(grid1_data[i][j], sizeof(grid1_data[i][j]),
1371 "%ld", random() % 1000);
1372 }
1373 }
1225 1374
1226 1375 gettimeofday(&now, NULL); gettimeofday(&now, NULL);
1227 1376 localtime_r(&now.tv_sec, &tm); localtime_r(&now.tv_sec, &tm);
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/Conn

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/Conn

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/Conn

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main