/** * Create a new Metadata struct filled with every information * obtainable. * * Filename * * Extension * * Some keywords (video, image, executable, etc) * * The (SHA1) hash * * The file is supposed to be checked for validity too (TODO). * * Side-effect: returns a new Metadata struct. */ Metadata *create_metadata_from_path(char pathFile[1000], char keywords[255]) { char *file_name; char *extension; char hash[41]; if (file_exists(pathFile)) { /** Name discovery */ char *slash = strrchr(pathFile, '/'); if (!slash || slash == pathFile) { file_name = pathFile; } else { file_name = slash+1; } /** Extension discovery */ char *dot = strrchr(file_name, '.'); if (!dot || dot == file_name) { extension = ""; } else { extension = dot+1; } /** Hash discovery */ strcpy(hash, sha1_on_file(pathFile)); // First way: use openssl/sha.h and do it manually // Second way (easier): use shell command 'sha1sum' with popen. hash[40] = '\0'; Metadata *md = new_metadata(file_name, extension, keywords, hash); return md; } else { return 0; } }
** Last update mer. juin 03 17:09:27 2015 Antoine Favarel */ #include <signal.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include "neptune/clust/dispatcher.h" static void send_data(t_dispatcher *this, t_socket *client) { t_metadata *meta; t_elem *data; meta = new_metadata(MR_DATA, MD_LIST); data = _wrap(meta, sizeof(t_metadata)); data->save(data, (t_io*)client); this->data->save(this->data, (t_io*)client); free(meta); delete_elem(data); } static void send_order(t_socket *s, t_list *list, t_list *lo) { t_metadata *meta; t_elem *data; t_elem *elem; list->rewind(list); while ((elem = list->next(list)))
sd_parser_t * sd_new_ctab_parser(void) { return sd_new_parser(line_feed, eof_feed, free_metadata, (gpointer) new_metadata()); }
** ** Started on ven. mai 29 16:17:08 2015 Antoine Favarel ** Last update mer. juin 03 16:53:00 2015 Antoine Favarel */ #include <stdlib.h> #include <stdio.h> #include "neptune/clust/dispatcher.h" static void st_elem(t_dispatcher *this, t_socket *client, t_list *lo) { t_elem *respond; t_elem *akn; respond = new_elem(); akn = _wrap(new_metadata(MR_AKN, MD_DATA), sizeof(t_metadata)); if (respond->load(respond, (t_io*)client) == EXIT_FAILURE) return ; this->responds->push(this->responds, respond->dup(respond)); lo->remove(lo, lo->get(lo, respond->id)); akn->save(akn, (t_io*)client); delete_elem(akn); delete_elem(respond); } static void st_loop(t_dispatcher *this, t_socket *c, t_list *lo, t_list *r) { t_elem *tmp; r->rewind(r); while ((tmp = r->next(r)))