From ca57d0dedae6ec8b6a467b6817c1e80de181cf03 Mon Sep 17 00:00:00 2001 From: Guillaume WELLS Date: Wed, 11 Nov 2015 12:35:19 +0100 Subject: [PATCH 1/9] objectif --- .gitignore | 2 +- objectif | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 objectif diff --git a/.gitignore b/.gitignore index d4e0bd6..8d6861e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.DS_Store +.S_Store .vagrant build Vagrantfile diff --git a/objectif b/objectif new file mode 100644 index 0000000..52ce878 --- /dev/null +++ b/objectif @@ -0,0 +1,28 @@ +Recursif ne sert a rien. + Je parcours la query de A a Z. +J'utilise une liste chaine. + Chaque noeud possede deux champs + Un path + Qui contient chaque element de la variable + &foo['toto']['bar'] = titi => foo:toto:bar + Une value qui est la valeur de la variable. +Pour chaque nouvelle variable je cree un nouveau noeud + Je check la presence de & pour savoir si il ya une nouvelle variable +A chaque nouvelle variable je parcours en peuplant le path tant que je n'ai pas vu de = qui indique la fin de ma variable + Si la variable est compose de plusieurs elements elle est compose de [ et ] je m'en sert pour definir le path. + Si c'est un tableau de chiffre + Je cree a chaque maillon vide ex : [] un index au path ex: toto:index:index + Je parcours la liste chaine et remplace les index par des valeurs numeriques grace a l'ordre. +Si le resultat est une valeur numerique j'effectut un atoi dessus. + +Je parcours la query de A a Z + si la chaine n'est pas vide je cree le premier maillon de ma chaine. + Je parcours jusqu'au egale + Si il n'y a pas de egale error + Je parcours jusqu'au [ s'il y en a + J'enregistre le premier elemtent dans path en enlevant les guillemets si pas de guillemets ouvrant fermant error + Si il y a un [ je parcours jusqu'au ] et remplis le path + Si il n'y a pas de ] error + Je fait ainsi de suite tant que [ se suivent. + +Une foonction aui recupere l'interieur des crohets et place index si la case est vide From a77ac8dc59b75cba78d104fee352686872d24b45 Mon Sep 17 00:00:00 2001 From: Guillaume WELLS Date: Wed, 11 Nov 2015 12:52:55 +0100 Subject: [PATCH 2/9] save --- include/reactive/uri/query2.hpp | 20 ++++++++++++++++++++ src/reactive/uri/query2.cpp | 18 ++++++++++++++++++ test_suite/reactive/uri/iteratif.cpp | 0 3 files changed, 38 insertions(+) create mode 100644 include/reactive/uri/query2.hpp create mode 100644 src/reactive/uri/query2.cpp create mode 100644 test_suite/reactive/uri/iteratif.cpp diff --git a/include/reactive/uri/query2.hpp b/include/reactive/uri/query2.hpp new file mode 100644 index 0000000..f66b609 --- /dev/null +++ b/include/reactive/uri/query2.hpp @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* query2.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwells +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2015/11/11 12:41:45 by gwells #+# #+# */ +/* Updated: 2015/11/11 12:44:03 by gwells ### ########.fr */ +/* */ +/* ************************************************************************** */ + +class query +{ + public: + /** + * Parse the content an put it in linked list + */ + void parse(char *query); +}; diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp new file mode 100644 index 0000000..0f7fbe4 --- /dev/null +++ b/src/reactive/uri/query2.cpp @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* query2.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwells +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2015/11/11 12:40:21 by gwells #+# #+# */ +/* Updated: 2015/11/11 12:45:45 by gwells ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void query::parse(char *query) +{ + ft_putendl("all is good"); +} diff --git a/test_suite/reactive/uri/iteratif.cpp b/test_suite/reactive/uri/iteratif.cpp new file mode 100644 index 0000000..e69de29 From abae67d8272b7edfc415c1ae65643f98a4421700 Mon Sep 17 00:00:00 2001 From: Guillaume WELLS Date: Wed, 11 Nov 2015 14:31:51 +0100 Subject: [PATCH 3/9] base --- .gitignore | 2 ++ src/reactive/uri/main.cpp | 27 ++++++++++++++++++++++++ src/reactive/uri/query2.cpp | 7 +++--- {include => src}/reactive/uri/query2.hpp | 6 ++++-- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/reactive/uri/main.cpp rename {include => src}/reactive/uri/query2.hpp (88%) diff --git a/.gitignore b/.gitignore index 8d6861e..ea5e403 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ xunit.xml *._cpp *.hpp_ *._hpp +libft.h +libft.a diff --git a/src/reactive/uri/main.cpp b/src/reactive/uri/main.cpp new file mode 100644 index 0000000..70ee529 --- /dev/null +++ b/src/reactive/uri/main.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwells +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2015/11/11 14:09:44 by gwells #+# #+# */ +/* Updated: 2015/11/11 14:29:51 by gwells ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "query2.hpp" +#include +#include "libft.h" + +int main(int argc, char **argv) +{ + if (argc != 2) + ft_quit("Enter one argument Pls", 2, EXIT_FAILURE); + + query test; + + test.parse(argv[1]); + + return (0); +} diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp index 0f7fbe4..5568a6e 100644 --- a/src/reactive/uri/query2.cpp +++ b/src/reactive/uri/query2.cpp @@ -6,13 +6,14 @@ /* By: gwells +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/11 12:40:21 by gwells #+# #+# */ -/* Updated: 2015/11/11 12:45:45 by gwells ### ########.fr */ +/* Updated: 2015/11/11 14:30:36 by gwells ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +#include "query2.hpp" -void query::parse(char *query) +void query::parse(const char *query) { - ft_putendl("all is good"); + ft_putendl(query); } diff --git a/include/reactive/uri/query2.hpp b/src/reactive/uri/query2.hpp similarity index 88% rename from include/reactive/uri/query2.hpp rename to src/reactive/uri/query2.hpp index f66b609..c6a4737 100644 --- a/include/reactive/uri/query2.hpp +++ b/src/reactive/uri/query2.hpp @@ -6,7 +6,7 @@ /* By: gwells +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/11 12:41:45 by gwells #+# #+# */ -/* Updated: 2015/11/11 12:44:03 by gwells ### ########.fr */ +/* Updated: 2015/11/11 14:29:17 by gwells ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,5 +16,7 @@ class query /** * Parse the content an put it in linked list */ - void parse(char *query); + + query() {} + void parse(const char *query); }; From c7122c238d0ef5fd73d4268f90042d841bf1994b Mon Sep 17 00:00:00 2001 From: Guillaume WELLS Date: Wed, 11 Nov 2015 17:48:38 +0100 Subject: [PATCH 4/9] first parsing --- objectif | 2 +- src/reactive/uri/query2.cpp | 57 +++++++++++++++++++++++++++++++++++-- src/reactive/uri/query2.hpp | 7 +++-- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/objectif b/objectif index 52ce878..9622158 100644 --- a/objectif +++ b/objectif @@ -20,8 +20,8 @@ Je parcours la query de A a Z Je parcours jusqu'au egale Si il n'y a pas de egale error Je parcours jusqu'au [ s'il y en a - J'enregistre le premier elemtent dans path en enlevant les guillemets si pas de guillemets ouvrant fermant error Si il y a un [ je parcours jusqu'au ] et remplis le path + Je regarde si il ya ds guillemets sinon error je recupere l'interrieur sans ceux ci Si il n'y a pas de ] error Je fait ainsi de suite tant que [ se suivent. diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp index 5568a6e..1005c64 100644 --- a/src/reactive/uri/query2.cpp +++ b/src/reactive/uri/query2.cpp @@ -6,14 +6,65 @@ /* By: gwells +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/11 12:40:21 by gwells #+# #+# */ -/* Updated: 2015/11/11 14:30:36 by gwells ### ########.fr */ +/* Updated: 2015/11/11 17:47:49 by gwells ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include "query2.hpp" +#include -void query::parse(const char *query) +t_list *query::parse(const char *query) { - ft_putendl(query); + t_list *begin; + char *path; + const char *error; + bool flag; + + + if (!ft_strlen(query)) + ft_quit("La chaine est vide", 2, EXIT_FAILURE); + + error = "Bad syntax"; + path = ft_strdup(""); + + while (*query) + { + flag = false; + if (*query != '[') + path = ft_append_char(path, *query); + if (*query == '[') + { + if (*(query + 1) == ']') + ft_strjoin(path, ":index"); + else + { + if (*(query + 1) != '\'' && *(query + 1) != '\"') + ft_quit(error, 2, EXIT_FAILURE); + else + { + query+=2; + path = ft_append_char(path, ':'); + while (*query && *query != ']') + { + path = ft_append_char(path, *query); + query++; + } + if (!*query || (*(query - 1) != '\'' && *(query - 1) != '\"')) + ft_quit(error, 2, EXIT_FAILURE); + path[ft_strlen(path) - 1] = '\0'; + } + } + flag = true; + } + if (*query && flag) + query++; + if (*query && !flag) + query++; + } + + ft_putendl(path); + return (begin); } + + diff --git a/src/reactive/uri/query2.hpp b/src/reactive/uri/query2.hpp index c6a4737..453ecfb 100644 --- a/src/reactive/uri/query2.hpp +++ b/src/reactive/uri/query2.hpp @@ -6,10 +6,12 @@ /* By: gwells +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/11 12:41:45 by gwells #+# #+# */ -/* Updated: 2015/11/11 14:29:17 by gwells ### ########.fr */ +/* Updated: 2015/11/11 15:39:51 by gwells ### ########.fr */ /* */ /* ************************************************************************** */ +#include "libft.h" + class query { public: @@ -18,5 +20,6 @@ class query */ query() {} - void parse(const char *query); + t_list *parse(const char *query); + }; From d921ea7b8fcd047db958d028244ae10750e35309 Mon Sep 17 00:00:00 2001 From: Bulliby69 Date: Mon, 16 Nov 2015 22:43:13 +0000 Subject: [PATCH 5/9] value and path --- src/reactive/uri/query2.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp index 1005c64..e4aa8dc 100644 --- a/src/reactive/uri/query2.cpp +++ b/src/reactive/uri/query2.cpp @@ -18,8 +18,10 @@ t_list *query::parse(const char *query) { t_list *begin; char *path; + char *value; const char *error; bool flag; + bool count; if (!ft_strlen(query)) @@ -27,11 +29,13 @@ t_list *query::parse(const char *query) error = "Bad syntax"; path = ft_strdup(""); + value = ft_strdup(""); + count = false; while (*query) { flag = false; - if (*query != '[') + if (*query != '[' && *query != '=') path = ft_append_char(path, *query); if (*query == '[') { @@ -50,20 +54,32 @@ t_list *query::parse(const char *query) path = ft_append_char(path, *query); query++; } - if (!*query || (*(query - 1) != '\'' && *(query - 1) != '\"')) + if (!*query || (*(query - 1) != '\'' && *(query - 1) != '\"') + || (*(query + 1) != '=' && *(query + 1) != '[' && *(query + 1))) ft_quit(error, 2, EXIT_FAILURE); path[ft_strlen(path) - 1] = '\0'; } } flag = true; } + if (*query == '=') + { + query++; + while(*query && *query != '&') + { + value = ft_append_char(value, *query); + query++; + } + ft_putendl(value); + ft_putendl(path); + } if (*query && flag) query++; if (*query && !flag) query++; } - ft_putendl(path); + //ft_putendl(path); return (begin); } From 681e5799deec00ab210272820c89b7b51ecbcd5b Mon Sep 17 00:00:00 2001 From: Bulliby69 Date: Thu, 19 Nov 2015 22:47:55 +0000 Subject: [PATCH 6/9] linked list --- src/reactive/uri/query2.cpp | 36 ++++++++++++++++++++++++++++-------- src/reactive/uri/query2.hpp | 12 +++++++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp index e4aa8dc..ec6a0bf 100644 --- a/src/reactive/uri/query2.cpp +++ b/src/reactive/uri/query2.cpp @@ -13,8 +13,24 @@ #include "libft.h" #include "query2.hpp" #include +#include -t_list *query::parse(const char *query) +void query::printlist(t_dlist *lst) +{ + t_content *content; + t_dnode *node; + + node = lst->head; + while(node) + { + content = (t_content*)node->content; + printf("Voici le path %s\n", content->path); + printf("Voici la value %s\n", content->value); + node = node->next; + } +} + +t_dlist *query::parse(const char *query) { t_list *begin; char *path; @@ -22,6 +38,9 @@ t_list *query::parse(const char *query) const char *error; bool flag; bool count; + t_content content; + t_dlist *lst; + t_dnode *node; if (!ft_strlen(query)) @@ -64,23 +83,24 @@ t_list *query::parse(const char *query) } if (*query == '=') { + query++; + lst = ft_dlstnew(); while(*query && *query != '&') { value = ft_append_char(value, *query); query++; } - ft_putendl(value); - ft_putendl(path); + content.path = path; + content.value = value; + node = ft_dlstnewnode(&content, sizeof(content)); + ft_dlstpushback(lst, node); } if (*query && flag) query++; if (*query && !flag) query++; } - - //ft_putendl(path); - return (begin); + printlist(lst); + return (lst); } - - diff --git a/src/reactive/uri/query2.hpp b/src/reactive/uri/query2.hpp index 453ecfb..cda60ce 100644 --- a/src/reactive/uri/query2.hpp +++ b/src/reactive/uri/query2.hpp @@ -14,12 +14,22 @@ class query { + private: + typedef struct s_content + { + char *path; + char *value; + } t_content; + + void printlist(t_list *lst); + public: /** * Parse the content an put it in linked list */ query() {} - t_list *parse(const char *query); + t_dlist *parse(const char *query); + void printlist(t_dlist*); }; From e3a16d7c9dcd2486c2151c5c439d13dcb6df2a1f Mon Sep 17 00:00:00 2001 From: Bulliby69 Date: Thu, 19 Nov 2015 23:35:05 +0000 Subject: [PATCH 7/9] objectif go home --- .gitignore | 1 + objectif | 28 ---------------------------- src/reactive/uri/query2.cpp | 12 +++++++++--- 3 files changed, 10 insertions(+), 31 deletions(-) delete mode 100644 objectif diff --git a/.gitignore b/.gitignore index ea5e403..f2714f3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ xunit.xml *._hpp libft.h libft.a +objectif diff --git a/objectif b/objectif deleted file mode 100644 index 9622158..0000000 --- a/objectif +++ /dev/null @@ -1,28 +0,0 @@ -Recursif ne sert a rien. - Je parcours la query de A a Z. -J'utilise une liste chaine. - Chaque noeud possede deux champs - Un path - Qui contient chaque element de la variable - &foo['toto']['bar'] = titi => foo:toto:bar - Une value qui est la valeur de la variable. -Pour chaque nouvelle variable je cree un nouveau noeud - Je check la presence de & pour savoir si il ya une nouvelle variable -A chaque nouvelle variable je parcours en peuplant le path tant que je n'ai pas vu de = qui indique la fin de ma variable - Si la variable est compose de plusieurs elements elle est compose de [ et ] je m'en sert pour definir le path. - Si c'est un tableau de chiffre - Je cree a chaque maillon vide ex : [] un index au path ex: toto:index:index - Je parcours la liste chaine et remplace les index par des valeurs numeriques grace a l'ordre. -Si le resultat est une valeur numerique j'effectut un atoi dessus. - -Je parcours la query de A a Z - si la chaine n'est pas vide je cree le premier maillon de ma chaine. - Je parcours jusqu'au egale - Si il n'y a pas de egale error - Je parcours jusqu'au [ s'il y en a - Si il y a un [ je parcours jusqu'au ] et remplis le path - Je regarde si il ya ds guillemets sinon error je recupere l'interrieur sans ceux ci - Si il n'y a pas de ] error - Je fait ainsi de suite tant que [ se suivent. - -Une foonction aui recupere l'interieur des crohets et place index si la case est vide diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp index ec6a0bf..aece198 100644 --- a/src/reactive/uri/query2.cpp +++ b/src/reactive/uri/query2.cpp @@ -50,6 +50,7 @@ t_dlist *query::parse(const char *query) path = ft_strdup(""); value = ft_strdup(""); count = false; + lst = ft_dlstnew(); while (*query) { @@ -59,7 +60,12 @@ t_dlist *query::parse(const char *query) if (*query == '[') { if (*(query + 1) == ']') - ft_strjoin(path, ":index"); + { + path = ft_strjoin(path, ":index"); + queryh=2; + if (*query != '=') + ft_quit(error, 2, EXIT_FAILURE); + } else { if (*(query + 1) != '\'' && *(query + 1) != '\"') @@ -83,9 +89,7 @@ t_dlist *query::parse(const char *query) } if (*query == '=') { - query++; - lst = ft_dlstnew(); while(*query && *query != '&') { value = ft_append_char(value, *query); @@ -95,6 +99,8 @@ t_dlist *query::parse(const char *query) content.value = value; node = ft_dlstnewnode(&content, sizeof(content)); ft_dlstpushback(lst, node); + path = ft_strdup(""); + value = ft_strdup(""); } if (*query && flag) query++; From 967ac85fc4d3e99490df344395904341cac37886 Mon Sep 17 00:00:00 2001 From: Bulliby69 Date: Sat, 21 Nov 2015 18:41:09 +0000 Subject: [PATCH 8/9] linked list done --- src/reactive/uri/main.cpp | 25 ++++++++++++++++- src/reactive/uri/query2.cpp | 56 +++++++++++++++++++------------------ src/reactive/uri/query2.hpp | 15 ++++++---- 3 files changed, 62 insertions(+), 34 deletions(-) diff --git a/src/reactive/uri/main.cpp b/src/reactive/uri/main.cpp index 70ee529..f5cc6a7 100644 --- a/src/reactive/uri/main.cpp +++ b/src/reactive/uri/main.cpp @@ -14,14 +14,37 @@ #include #include "libft.h" +typedef void (*ptrfunc)(void *, size_t); +void dellist(void *, size_t); + +typedef struct s_content +{ + char *path; + char *value; +} t_content; + int main(int argc, char **argv) { if (argc != 2) ft_quit("Enter one argument Pls", 2, EXIT_FAILURE); query test; + t_list *lst; - test.parse(argv[1]); + ptrfunc delfunc; + + delfunc = dellist; + test.parse(argv[1]); + //ft_lstdel(&lst, delfunc); return (0); } + +void dellist(void* content, size_t size) +{ + t_content *tmp; + + tmp = (t_content*)content; + free(tmp->path); + free(tmp->value); +} diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp index aece198..3e2a362 100644 --- a/src/reactive/uri/query2.cpp +++ b/src/reactive/uri/query2.cpp @@ -15,54 +15,48 @@ #include #include -void query::printlist(t_dlist *lst) +void query::printlist(t_list *lst) { t_content *content; - t_dnode *node; - node = lst->head; - while(node) + while(lst) { - content = (t_content*)node->content; + content = (t_content*)lst->content; printf("Voici le path %s\n", content->path); - printf("Voici la value %s\n", content->value); - node = node->next; + printf("Voici la value %s\n",content->value); + lst = lst->next; } } -t_dlist *query::parse(const char *query) +t_list *query::parse(const char *query) { t_list *begin; + t_list *node; char *path; char *value; const char *error; bool flag; bool count; t_content content; - t_dlist *lst; - t_dnode *node; - if (!ft_strlen(query)) - ft_quit("La chaine est vide", 2, EXIT_FAILURE); - error = "Bad syntax"; + count = false; + begin = NULL; path = ft_strdup(""); value = ft_strdup(""); - count = false; - lst = ft_dlstnew(); - + while (*query) { flag = false; if (*query != '[' && *query != '=') - path = ft_append_char(path, *query); + path = changeString(path, ft_append_char(path, *query)); if (*query == '[') { if (*(query + 1) == ']') { - path = ft_strjoin(path, ":index"); - queryh=2; + path = changeString(path, ft_strjoin(path, ":index")); + query+=2; if (*query != '=') ft_quit(error, 2, EXIT_FAILURE); } @@ -73,14 +67,14 @@ t_dlist *query::parse(const char *query) else { query+=2; - path = ft_append_char(path, ':'); + path = changeString(path, ft_append_char(path, ':')); while (*query && *query != ']') { - path = ft_append_char(path, *query); + path = changeString(path, ft_append_char(path, *query)); query++; } if (!*query || (*(query - 1) != '\'' && *(query - 1) != '\"') - || (*(query + 1) != '=' && *(query + 1) != '[' && *(query + 1))) + || (*(query + 1) != '=' && *(query + 1) != '[' && *(query + 1))) ft_quit(error, 2, EXIT_FAILURE); path[ft_strlen(path) - 1] = '\0'; } @@ -92,13 +86,15 @@ t_dlist *query::parse(const char *query) query++; while(*query && *query != '&') { - value = ft_append_char(value, *query); + value = changeString(value, ft_append_char(value, *query)); query++; } content.path = path; content.value = value; - node = ft_dlstnewnode(&content, sizeof(content)); - ft_dlstpushback(lst, node); + node = ft_lstnew(&content, sizeof(content)); + ft_lstpushback(&begin, node); + //ft_strdel(&path); + //ft_strdel(&value); path = ft_strdup(""); value = ft_strdup(""); } @@ -107,6 +103,12 @@ t_dlist *query::parse(const char *query) if (*query && !flag) query++; } - printlist(lst); - return (lst); + printlist(begin); + return (begin); +} + +char *query::changeString(char *old, char *ret) +{ + ft_strdel(&old); + return(ret); } diff --git a/src/reactive/uri/query2.hpp b/src/reactive/uri/query2.hpp index cda60ce..8d9f465 100644 --- a/src/reactive/uri/query2.hpp +++ b/src/reactive/uri/query2.hpp @@ -21,15 +21,18 @@ class query char *value; } t_content; - void printlist(t_list *lst); - - public: /** - * Parse the content an put it in linked list + * Debug function */ + void printlist(t_list* lst); + char *changeString(char* old, char *ret); + + public: query() {} - t_dlist *parse(const char *query); - void printlist(t_dlist*); + /** + * Parse the content and put it in linked list + */ + t_list *parse(const char *query); }; From 0929984851879e32c009544ad3f433d82387267b Mon Sep 17 00:00:00 2001 From: Bulliby69 Date: Sat, 21 Nov 2015 22:16:12 +0000 Subject: [PATCH 9/9] memory leaks --- src/reactive/uri/main.cpp | 5 +++-- src/reactive/uri/query2.cpp | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/reactive/uri/main.cpp b/src/reactive/uri/main.cpp index f5cc6a7..ce809b2 100644 --- a/src/reactive/uri/main.cpp +++ b/src/reactive/uri/main.cpp @@ -35,8 +35,8 @@ int main(int argc, char **argv) delfunc = dellist; - test.parse(argv[1]); - //ft_lstdel(&lst, delfunc); + lst = test.parse(argv[1]); + ft_lstdel(&lst, delfunc); return (0); } @@ -47,4 +47,5 @@ void dellist(void* content, size_t size) tmp = (t_content*)content; free(tmp->path); free(tmp->value); + free(content); } diff --git a/src/reactive/uri/query2.cpp b/src/reactive/uri/query2.cpp index 3e2a362..a10c74c 100644 --- a/src/reactive/uri/query2.cpp +++ b/src/reactive/uri/query2.cpp @@ -77,6 +77,7 @@ t_list *query::parse(const char *query) || (*(query + 1) != '=' && *(query + 1) != '[' && *(query + 1))) ft_quit(error, 2, EXIT_FAILURE); path[ft_strlen(path) - 1] = '\0'; + path = changeString(path, ft_strdup(path)); } } flag = true; @@ -89,12 +90,12 @@ t_list *query::parse(const char *query) value = changeString(value, ft_append_char(value, *query)); query++; } - content.path = path; - content.value = value; + content.path = ft_strdup(path); + content.value = ft_strdup(value); node = ft_lstnew(&content, sizeof(content)); ft_lstpushback(&begin, node); - //ft_strdel(&path); - //ft_strdel(&value); + ft_strdel(&path); + ft_strdel(&value); path = ft_strdup(""); value = ft_strdup(""); } @@ -104,6 +105,8 @@ t_list *query::parse(const char *query) query++; } printlist(begin); + ft_strdel(&path); + ft_strdel(&value); return (begin); }