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; |