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)
Improved Conn_split (and remove the limitation to 4096 'right' value. ec46e3c94da65fe94ed109727fd3dcb50384a44e Catalin(ux) M. BOIE 2009-04-17 12:31:53
Removed an unsused variable. 1fa664bac9482c6e053bb3ea1d06280b66dadfed Catalin(ux) M. BOIE 2009-04-17 12:04:46
Simplified expand_buf and also fixed an out-of-bounds wrinting. a2a507f235f7847277c2a485af8efb8efaa1ffa7 Catalin(ux) M. BOIE 2009-04-17 12:03:34
Bump up the version. b720ca953940baf51a3e8263e6ec5d397a1c1ff2 Catalin(ux) M. BOIE 2009-04-14 12:39:01
Fixed Conn_rtrim. 5f12cd953b0b998db8530eaed30b91bb181b7b26 Catalin(ux) M. BOIE 2009-04-14 12:38:39
Really fixed Conn_split_get. 5ab1e0a47574fc6776e014be3d8150a048866607 Catalin(ux) M. BOIE 2009-04-14 08:34:38
Added Conn_alphanum (test if a string is alpha numeric or not). 0bb8d19eed947aa82640610a0d894141e466105a Catalin(ux) M. BOIE 2009-04-14 08:22:02
Reverse the meaning of Conn_split_get_e and Conn_split_get. 836229353a26ecc1bac762ece6cf42319113f5b1 Catalin(ux) M. BOIE 2009-04-14 08:21:35
Before calling callback in Conn_for_every_line, just trim '\r'. 51e532893e74c4bee9b6847732442536e79eb2a0 Catalin(ux) M. BOIE 2009-04-14 06:39:29
Added Conn_rtrim function. c37737a16e3d9de95cf659bae546de8808a3e3ed Catalin(ux) M. BOIE 2009-04-14 06:26:16
Revert "Conn_get_line removes also '\r' now." 9d56ef9813225fe1127a2d5800c124aa65d5e1d2 Catalin(ux) M. BOIE 2009-04-14 06:20:50
Changed Conn_split to not modify original line. 2f0d734f54b243356d0d4468691af50aad9e667a Catalin(ux) M. BOIE 2009-04-14 06:00:26
Added Conn_split_get_ull (unsigned long long). 735e92324db56d5e9875f4e123102fc1e995cb4d Catalin(ux) M. BOIE 2009-04-13 22:13:04
Conn_get_line removes also '\r' now. c1e5a9915b3ae6196a68fb1e7f73f295bef1737c Catalin(ux) M. BOIE 2009-04-13 21:56:47
Re-export Conn_get lost somehow. 293f7aaed4f39de54821c8863023adb0e00234ac Catalin(ux) M. BOIE 2009-04-13 21:33:19
Bump the version. d74d67d1327c8873c715906feeb8b4f053fff70b Catalin(ux) M. BOIE 2009-03-17 13:07:01
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
Commit ec46e3c94da65fe94ed109727fd3dcb50384a44e - Improved Conn_split (and remove the limitation to 4096 'right' value.
Author: Catalin(ux) M. BOIE
Author date (UTC): 2009-04-17 12:31
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2009-04-17 12:31
Parent(s): 1fa664bac9482c6e053bb3ea1d06280b66dadfed
Signing key:
Tree: a0ed1346270591017676c98a469c702fd65fe66d
File Lines added Lines deleted
Conn_engine_core.c 68 55
Conn_engine_core.h 10 4
File Conn_engine_core.c changed (mode: 100644) (index 8ffb888..45adb96)
... ... void Conn_rtrim(char *s, const char *chars)
987 987 */ */
988 988 void Conn_split_free(struct Conn_split **s) void Conn_split_free(struct Conn_split **s)
989 989 { {
990 struct Conn_split *p, *next;
990 struct Conn_split *p;
991 struct Conn_split_cell *q, *next;
991 992
992 993 if (!s) if (!s)
993 994 return; return;
 
... ... void Conn_split_free(struct Conn_split **s)
996 997 if (!p) if (!p)
997 998 return; return;
998 999
999 while (p) {
1000 free(p->r);
1001 free(p->l);
1002 next = p->next;
1003 free(p);
1004 p = next;
1000 q = p->head;
1001 while (q) {
1002 next = q->next;
1003 free(q);
1004 q = next;
1005 1005 } }
1006 1006
1007 *s = NULL;
1007 free(p->line);
1008
1009 free(p);
1008 1010 } }
1009 1011
1010 1012 /* /*
 
... ... void Conn_split_free(struct Conn_split **s)
1013 1015 struct Conn_split *Conn_split(const char *line0) struct Conn_split *Conn_split(const char *line0)
1014 1016 { {
1015 1017 char *p; char *p;
1016 struct Conn_split *ret = NULL, *q, *last;
1017 char l[128], r[4096];
1018 struct Conn_split *ret = NULL;
1019 struct Conn_split_cell *q;
1018 1020 unsigned int i; unsigned int i;
1019 1021 char search_for; char search_for;
1020 1022 char *line; char *line;
1023 char *left, *right;
1024 unsigned int right_len;
1021 1025
1022 line = strdup(line0);
1023 if (!line)
1026 ret = (struct Conn_split *) calloc(1, sizeof(struct Conn_split));
1027 if (!ret) {
1028 snprintf(Conn_error, sizeof(Conn_error),
1029 "cannot alloc memory for Conn_split!\n");
1024 1030 return NULL; return NULL;
1031 }
1032
1033 ret->line = strdup(line0);
1034 if (!ret->line) {
1035 snprintf(Conn_error, sizeof(Conn_error),
1036 "cannot alloc memory for line duplication!\n");
1037 goto free_ret;
1038 }
1025 1039
1026 1040 Conn_rtrim(line, "\r\n \t"); Conn_rtrim(line, "\r\n \t");
1027 1041
1028 1042 /* do the spliting */ /* do the spliting */
1029 p = line;
1043 p = ret->line;
1030 1044 while (*p != '\0') { while (*p != '\0') {
1031 1045 /* skip empty space */ /* skip empty space */
1032 1046 while ((*p == ' ') || (*p == '\t')) while ((*p == ' ') || (*p == '\t'))
1033 1047 p++; p++;
1034 1048
1049 if (*p == '\0')
1050 break;
1051
1052 /* Init */
1053 right = "";
1054 right_len = 0;
1055
1035 1056 /* Building left */ /* Building left */
1057 left = p;
1036 1058 i = 0; i = 0;
1037 while ((i < sizeof(l) - 1) && (*p != '\0') && (*p != '=')
1038 && (*p != '\r')) {
1039 l[i++] = *p;
1059 while ((*p != '\0') && (*p != '='))
1040 1060 p++; p++;
1041 }
1042 l[i] = '\0';
1043
1044 /* Building right */
1045 r[0] = '\0';
1046 1061 if (*p != '\0') { if (*p != '\0') {
1062 *p = '\0';
1063
1047 1064 /* skip '=' */ /* skip '=' */
1048 1065 p++; p++;
1049 1066
1067 /* Building right */
1068 right = p;
1069
1050 1070 search_for = ' '; search_for = ' ';
1051 1071 if (*p == '"') { if (*p == '"') {
1052 1072 search_for = '"'; search_for = '"';
 
... ... struct Conn_split *Conn_split(const char *line0)
1054 1074 } }
1055 1075
1056 1076 i = 0; i = 0;
1057 while ((i < sizeof(r) - 1) && (*p != '\r') && (*p != '\0')
1058 && (*p != search_for)) {
1059 r[i++] = *p;
1077 while ((*p != '\0') && (*p != search_for)) {
1078 right_len++;
1060 1079 p++; p++;
1061 1080 } }
1062 r[i] = '\0';
1063 1081
1064 if (*p == search_for)
1082 if (*p != '\0') {
1083 *p = '\0';
1065 1084 p++; p++;
1085 }
1066 1086 } }
1067 1087
1068 1088 /* alloc data and fill it */ /* alloc data and fill it */
1069 q = (struct Conn_split *) calloc(1, sizeof(struct Conn_split));
1089 q = (struct Conn_split_cell *) calloc(1, sizeof(struct Conn_split_cell));
1070 1090 if (!q) { if (!q) {
1071 1091 snprintf(Conn_error, sizeof(Conn_error), snprintf(Conn_error, sizeof(Conn_error),
1072 1092 "cannot alloc memory!\n"); "cannot alloc memory!\n");
1073 1093 goto out_free; goto out_free;
1074 1094 } }
1075 q->l = strdup(l);
1076 if (!q->l) {
1077 free(q);
1078 goto out_free;
1079 }
1080 q->r = strdup(r);
1081 if (!q->r) {
1082 free(q->l);
1083 free(q);
1084 goto out_free;
1085 }
1086 q->len = strlen(q->r);
1095 q->left = left;
1096 q->right = right;
1097 q->right_len = right_len;
1087 1098
1088 if (ret == NULL) {
1089 ret = q;
1090 last = ret;
1091 } else {
1092 last->next = q;
1093 last = q;
1094 }
1095 }
1099 if (ret->head == NULL)
1100 ret->head = q;
1101 else
1102 ret->head->next = q;
1096 1103
1097 free(line);
1104 ret->tail = q;
1105 }
1098 1106
1099 1107 return ret; return ret;
1100 1108
1101 1109 out_free: out_free:
1102 free(line);
1110 free(ret->line);
1111
1112 free_ret:
1103 1113 Conn_split_free(&ret); Conn_split_free(&ret);
1104 1114
1105 1115 return NULL; return NULL;
 
... ... struct Conn_split *Conn_split(const char *line0)
1108 1118 /* /*
1109 1119 * Search for a string and return the value * Search for a string and return the value
1110 1120 */ */
1111 char *Conn_split_get_size(const struct Conn_split *s, const char *l,
1121 char *Conn_split_get_size(const struct Conn_split *s, const char *left,
1112 1122 unsigned int *size) unsigned int *size)
1113 1123 { {
1114 while (s) {
1115 if (strcmp(l, s->l) == 0) {
1124 struct Conn_split_cell *p;
1125
1126 p = s->head;
1127 while (p) {
1128 if (strcmp(left, p->left) == 0) {
1116 1129 if (size != NULL) if (size != NULL)
1117 *size = s->len;
1118 return s->r;
1130 *size = p->right_len;
1131 return p->right;
1119 1132 } }
1120 s = s->next;
1133 p = p->next;
1121 1134 } }
1122 1135
1123 1136 return NULL; return NULL;
File Conn_engine_core.h changed (mode: 100644) (index cf20b84..22ae8e8)
... ... struct Conn_queue
184 184
185 185
186 186 /* For parsing */ /* For parsing */
187 struct Conn_split_cell
188 {
189 struct Conn_split_cell *next;
190 char *left;
191 char *right;
192 unsigned int right_len;
193 };
194
187 195 struct Conn_split struct Conn_split
188 196 { {
189 struct Conn_split *next;
190 char *l;
191 char *r;
192 unsigned int len;
197 struct Conn_split_cell *head, *tail;
198 char *line;
193 199 }; };
194 200
195 201
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