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)
Added splitting functions. It gets easier to write ascii line client/server app. 48e73f48d8c264e944dfd211e926ca3ad8f879d6 Catalin(ux) M. BOIE 2009-03-17 13:06:19
Do not build examples by default. 9dafc6232f426f361047a1836832e2c97823d14c Catalin(ux) M. BOIE 2009-03-17 09:59:14
Bump up the version. 47a4be6a1ae721a7b9d0e07db5a288985163758c Catalin(ux) M. BOIE 2009-03-17 09:01:10
Added Conn_addr_info - check what family an address is. 10087d1dec5592e4a5396df09aade7d963cf1ea4 Catalin(ux) M. BOIE 2009-03-17 08:55:47
Bump up the version. 4ce4f82faa025d9a386538d1db5d74a443baf62a Catalin(ux) M. BOIE 2009-03-10 09:22:37
Do not try to close free state slots. f17b6d92d668f72de10967ae9178131916db64c8 Catalin(ux) M. BOIE 2009-03-09 10:29:35
TODO: More entries added (timer optimization). 0b0be1574b15e7dae4b7dca9f02f0ff78bc02136 Catalin(ux) M. BOIE 2009-03-09 10:27:37
Raised debug level for compacting phase. d610f3d45075311f9f21c7c122dfefa773c48a64 Catalin(ux) M. BOIE 2009-03-09 10:17:41
Bump up the version. b8a55af5786f74ea38e5929af347cfc79f0d3dfd Catalin(ux) M. BOIE 2009-03-09 10:14:10
Moved free_intern in the periodic scanning to not miss connections in listen. 5fb989866b1ceb68e64e62e035610c40cf519c03 Catalin(ux) M. BOIE 2009-03-09 10:05:03
More clear logging. 3599fc41cce9bd25e5461d0c4350780f4dbc64a6 Catalin(ux) M. BOIE 2009-03-09 10:04:47
Bump up the version. 64a2ec25c265a6750b25e7bd5be85f66766e4cf4 Catalin(ux) M. BOIE 2009-03-09 08:59:22
Fixed a bug preventing a socket in listen state to be closed. 287e366451321862731e005d48391ed39149693b Catalin(ux) M. BOIE 2009-03-09 08:58:51
Duilder updates. 30f5e95e50703f2bb3e5ba6f088b09f858e0e95c Catalin(ux) M. BOIE 2009-03-09 08:58:40
Extended timeout to 1000ms from 500ms. No need to wake up too frequent. ea268527d103d09685192399bbad6ebbd22430e8 Catalin(ux) M. BOIE 2009-03-06 13:11:36
Bump version in duilder. cbe72841517c536aa714fd8dfdbe1799248664e2 Catalin(ux) M. BOIE 2009-03-05 15:35:37
Added suport to bind to a specific IP. 5de8bd574a0bd2b57cc0ea98c4c20186dcfc9d8c Catalin(ux) M. BOIE 2009-03-02 13:59:07
TODO: Added bind to ip and access control. d7dd6bd61fdb4974da679979f05913cc24c9c0ae Catalin(ux) M. BOIE 2009-03-02 13:34:13
Lot of small changes that were need to fix epoll integration. 92877346e9cbecc7bea6f6d342e6d03475349878 Catalin(ux) M. BOIE 2009-02-26 12:20:07
Fixed the server example to output a \n terminated line. ed20ea84c9c6bd5dc9a3c066d03e4c8a049e1369 Catalin(ux) M. BOIE 2009-02-26 12:16:33
Commit 48e73f48d8c264e944dfd211e926ca3ad8f879d6 - Added splitting functions. It gets easier to write ascii line client/server app.
Author: Catalin(ux) M. BOIE
Author date (UTC): 2009-03-17 13:06
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2009-03-17 13:06
Parent(s): 9dafc6232f426f361047a1836832e2c97823d14c
Signing key:
Tree: d188935621a64e8071b4b5264e70c35d469a6551
File Lines added Lines deleted
Conn_engine_core.c 204 0
Conn_engine_core.h 26 0
tests/Makefile 4 1
tests/t2.c 34 0
File Conn_engine_core.c changed (mode: 100644) (index 56045de..6a1675c)
... ... int Conn_addr_family(const char *addr)
956 956
957 957 return ret; return ret;
958 958 } }
959
960 /* Splitting stuff */
961
962 /*
963 * Cut in place the end \r and \n.
964 */
965 static void cut(char *s)
966 {
967 int pos;
968
969 pos = strlen(s) - 1;
970
971 while ((s[pos] == '\r') || (s[pos] == '\n')) {
972 s[pos] = '\0';
973 pos--;
974 }
975 }
976
977 /*
978 * Free a prealocated structure
979 */
980 void Conn_split_free(struct Conn_split **s)
981 {
982 struct Conn_split *p, *next;
983
984 if (!s)
985 return;
986
987 p = *s;
988 if (!p)
989 return;
990
991 while (p) {
992 free(p->r);
993 free(p->l);
994 next = p->next;
995 free(p);
996 p = next;
997 }
998
999 *s = NULL;
1000 }
1001
1002 /*
1003 * Split a buffer pointed by C to var,value pairs.
1004 */
1005 struct Conn_split *Conn_split(char *line)
1006 {
1007 char *p;
1008 struct Conn_split *ret = NULL, *q, *last;
1009 char l[128], r[4096];
1010 unsigned int i;
1011 char search_for;
1012
1013 cut(line);
1014
1015 /* do the spliting */
1016 p = line;
1017 while (*p != '\0') {
1018 /* skip empty space */
1019 while ((*p == ' ') || (*p == '\t'))
1020 p++;
1021
1022 /* Building left */
1023 i = 0;
1024 while ((i < sizeof(l) - 1) && (*p != '\0') && (*p != '=')
1025 && (*p != '\r')) {
1026 l[i++] = *p;
1027 p++;
1028 }
1029 l[i] = '\0';
1030
1031 /* Building right */
1032 r[0] = '\0';
1033 if (*p != '\0') {
1034 /* skip '=' */
1035 p++;
1036
1037 search_for = ' ';
1038 if (*p == '"') {
1039 search_for = '"';
1040 p++;
1041 }
1042
1043 i = 0;
1044 while ((i < sizeof(r) - 1) && (*p != '\r') && (*p != '\0')
1045 && (*p != search_for)) {
1046 r[i++] = *p;
1047 p++;
1048 }
1049 r[i] = '\0';
1050
1051 if (*p == search_for)
1052 p++;
1053 }
1054
1055 /* alloc data and fill it */
1056 q = (struct Conn_split *) calloc(1, sizeof(struct Conn_split));
1057 if (!q) {
1058 snprintf(Conn_error, sizeof(Conn_error),
1059 "cannot alloc memory!\n");
1060 goto out_free;
1061 }
1062 q->l = strdup(l);
1063 if (!q->l) {
1064 free(q);
1065 goto out_free;
1066 }
1067 q->r = strdup(r);
1068 if (!q->r) {
1069 free(q->l);
1070 free(q);
1071 goto out_free;
1072 }
1073 q->len = strlen(q->r);
1074
1075 if (ret == NULL) {
1076 ret = q;
1077 last = ret;
1078 } else {
1079 last->next = q;
1080 last = q;
1081 }
1082 }
1083
1084 return ret;
1085
1086 out_free:
1087 Conn_split_free(&ret);
1088
1089 return NULL;
1090 }
1091
1092 /*
1093 * Search for a string and return the value
1094 */
1095 char *Conn_split_get_size(const struct Conn_split *s, const char *l,
1096 unsigned int *size)
1097 {
1098 while (s) {
1099 if (strcmp(l, s->l) == 0) {
1100 if (size != NULL)
1101 *size = s->len;
1102 return s->r;
1103 }
1104 s = s->next;
1105 }
1106
1107 return NULL;
1108 }
1109
1110 /*
1111 * Search for a string and return the value
1112 */
1113 char *Conn_split_get(const struct Conn_split *s, const char *l)
1114 {
1115 return Conn_split_get_size(s, l, NULL);
1116 }
1117
1118 /*
1119 * Search for a string and return the value or "" if not found
1120 */
1121 char *Conn_split_get_e(const struct Conn_split *s, const char *l,
1122 unsigned int *size)
1123 {
1124 char *r;
1125
1126 r = Conn_split_get_size(s, l, size);
1127 if (!r)
1128 r = "";
1129
1130 return r;
1131 }
1132
1133 /*
1134 * Return a value as unsigned long
1135 */
1136 unsigned long Conn_split_get_ul(const struct Conn_split *s, const char *l,
1137 unsigned int base)
1138 {
1139 char *r;
1140 unsigned long ret = 0;
1141
1142 r = Conn_split_get(s, l);
1143 if (r)
1144 ret = strtoul(r, NULL, base);
1145
1146 return ret;
1147 }
1148
1149 /*
1150 * Return a value as double
1151 */
1152 double Conn_split_get_d(const struct Conn_split *s, const char *l)
1153 {
1154 char *r;
1155 double ret = 0;
1156
1157 r = Conn_split_get(s, l);
1158 if (r)
1159 ret = strtod(r, NULL);
1160
1161 return ret;
1162 }
File Conn_engine_core.h changed (mode: 100644) (index dab1c50..948c165)
... ... struct Conn_queue
181 181 struct Conn_queue_entry *head, *tail; struct Conn_queue_entry *head, *tail;
182 182 }; };
183 183
184
185 /* For parsing */
186 struct Conn_split
187 {
188 struct Conn_split *next;
189 char *l;
190 char *r;
191 unsigned int len;
192 };
193
194
184 195 /* Variables */ /* Variables */
185 196 extern void (*Conn_accept_cb)(struct Conn *C); extern void (*Conn_accept_cb)(struct Conn *C);
186 197 extern void (*Conn_recv_cb)(struct Conn *C); extern void (*Conn_recv_cb)(struct Conn *C);
 
... ... extern int Conn_queue_add(struct Conn_queue *q,
285 296 const unsigned int slot); const unsigned int slot);
286 297 extern void Conn_queue_destroy(struct Conn_queue *q); extern void Conn_queue_destroy(struct Conn_queue *q);
287 298
299 /* splitting stuff */
300 extern struct Conn_split *Conn_split(char *line);
301 extern char *Conn_split_get_size(const struct Conn_split *s,
302 const char *l, unsigned int *len);
303 extern char *Conn_split_get(const struct Conn_split *s,
304 const char *l);
305 extern char *Conn_split_get_e(const struct Conn_split *s,
306 const char *l, unsigned int *size);
307 extern unsigned long Conn_split_get_ul(const struct Conn_split *s,
308 const char *l, unsigned int base);
309 extern double Conn_split_get_d(const struct Conn_split *s,
310 const char *l);
311 extern void Conn_split_free(struct Conn_split **s);
312
288 313 #endif #endif
314
File tests/Makefile changed (mode: 100644) (index 52a145f..ee63f6a)
1 TARGETS := t1.run
1 TARGETS := t1.run t2.run
2 2
3 3 all: $(TARGETS) all: $(TARGETS)
4 4
 
... ... DEPS := ../libConn.so.$(VER) $(OBJS)
10 10 t1.run: t1.c $(DEPS) t1.run: t1.c $(DEPS)
11 11 gcc $(CFLAGS) $(INCS) t1.c -o $@ $(LIBS) gcc $(CFLAGS) $(INCS) t1.c -o $@ $(LIBS)
12 12
13 t2.run: t2.c $(DEPS)
14 gcc $(CFLAGS) $(INCS) t2.c -o $@ $(LIBS)
15
13 16 .PHONY: clean .PHONY: clean
14 17 clean: clean:
15 18 @-rm -f $(TARGETS) *.log core @-rm -f $(TARGETS) *.log core
File tests/t2.c added (mode: 100644) (index 0000000..a5fb690)
1 /*
2 * Testing splitting functions
3 */
4
5 #include <Conn.h>
6
7 int main(void)
8 {
9 char *s = "a=b c= d= sasasasdasd=", *x;
10 int ret = 0;
11 struct Conn_split *sp;
12
13 sp = Conn_split(s);
14 if (!sp) {
15 printf("Cannot split (%s)!\n", Conn_strerror());
16 ret++;
17 } else {
18 x = Conn_split_get(sp, "a");
19 if (!x || strcmp(x, "b") != 0) {
20 printf("ERROR: a != %s.\n", x);
21 ret++;
22 }
23
24 x = Conn_split_get(sp, "c");
25 if (!x || strcmp(x, "") != 0) {
26 printf("ERROR: \"\" != \"%s\".\n", x);
27 ret++;
28 }
29 }
30
31 Conn_split_free(&sp);
32
33 return ret;
34 }
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