static void * start_fuse_thread(void * other) { int fuseargc=0; const char *fuseargv[200]; #define mountstring_len (AFP_SERVER_NAME_LEN+1+AFP_VOLUME_NAME_LEN+1) char mountstring[mountstring_len]; struct start_fuse_thread_arg * arg = other; struct afp_volume * volume = arg->volume; struct fuse_client * c = arg->client; struct afp_server * server = volume->server; /* Check to see if we have permissions to access the mountpoint */ snprintf(mountstring,mountstring_len,"%s:%s", server->server_name_printable, volume->volume_name_printable); fuseargc=0; fuseargv[0]=mountstring; fuseargc++; fuseargv[1]=volume->mountpoint; fuseargc++; if (get_debug_mode()) { fuseargv[fuseargc]="-d"; fuseargc++; } else { fuseargv[fuseargc]="-f"; fuseargc++; } if (arg->changeuid) { fuseargv[fuseargc]="-o"; fuseargc++; fuseargv[fuseargc]="allow_other"; fuseargc++; } /* #ifdef USE_SINGLE_THREAD */ fuseargv[fuseargc]="-s"; fuseargc++; /* #endif */ global_volume=volume; arg->fuse_result= afp_register_fuse(fuseargc, (char **) fuseargv,volume); arg->fuse_errno=errno; arg->wait=0; pthread_cond_signal(&volume->startup_condition_cond); log_for_client((void *) c,AFPFSD,LOG_WARNING, "Unmounting volume %s from %s\n", volume->volume_name_printable, volume->mountpoint); return NULL; }
/** * Function to process get requests received from clients. * @param server_struct is the main structure for the server. * @param connection is the connection in MHD * @param url is the requested url * @param con_cls is a pointer used to know if this is the first call or not * @returns an int that is either MHD_NO or MHD_YES upon failure or not. */ static int process_get_request(server_struct_t *server_struct, struct MHD_Connection *connection, const char *url, void **con_cls) { static int aptr = 0; int success = MHD_NO; gchar *answer = NULL; if (&aptr != *con_cls) { /* do never respond on first call */ *con_cls = &aptr; success = MHD_YES; } else { if (get_debug_mode() == TRUE) { print_debug(_("Requested get url: %s\n"), url); print_headers(connection); } if (g_str_has_suffix(url, ".json")) { /* A json format answer was requested */ answer = get_json_answer(server_struct, connection, url); } else { /* An "unformatted" answer was requested */ answer = get_unformatted_answer(server_struct, url); } /* reset when done */ *con_cls = NULL; /* Do not free answer variable as MHD will do it for us ! */ success = create_MHD_response(connection, answer); } return success; }
/** * Function that process the received data from the POST command and * answers to the client. * Here we may do something with this data (we may want to store it * somewhere). * * @param server_struct is the main structure for the server. * @param connection is the connection in MHD * @param url is the requested url * @param received_data is a gchar * string to the data that was received * by the POST request. */ static int process_received_data(server_struct_t *server_struct, struct MHD_Connection *connection, const char *url, gchar *received_data) { gchar *answer = NULL; /** gchar *answer : Do not free answer variable as MHD will do it for us ! */ int success = MHD_NO; gboolean debug = FALSE; hash_data_t *hash_data = NULL; json_t *root = NULL; GList *hash_data_list = NULL; GList *head = NULL; a_clock_t *elapsed = NULL; if (g_strcmp0(url, "/Meta.json") == 0 && received_data != NULL) { success = answer_meta_json_post_request(server_struct, connection, received_data); } else if (g_strcmp0(url, "/Hash_Array.json") == 0 && received_data != NULL) { success = answer_hash_array_post_request(server_struct, connection, received_data); /* Here we will try to answer which hashs are needed and then * send thoses hashs back in the answer */ } else if (g_strcmp0(url, "/Data.json") == 0 && received_data != NULL) { hash_data = convert_string_to_hash_data(received_data); if (get_debug_mode() == TRUE) { print_received_data_for_hash(hash_data->hash, hash_data->read); } /** * Sending received_data into the queue in order to be treated by * the corresponding thread. hash_data is freed by data_thread * and should not be used after this "call" here. */ g_async_queue_push(server_struct->data_queue, hash_data); /** * creating an answer for the client to say that everything went Ok! */ answer = g_strdup_printf(_("Ok!")); success = create_MHD_response(connection, answer); } else if (g_strcmp0(url, "/Data_Array.json") == 0 && received_data != NULL) { /* print_debug("/Data_Array.json: %s\n", received_data); */ elapsed = new_clock_t(); root = load_json(received_data); end_clock(elapsed, "load_json"); hash_data_list = extract_glist_from_array(root, "data_array", FALSE); head = hash_data_list; json_decref(root); debug = get_debug_mode(); while (hash_data_list != NULL) { hash_data = hash_data_list->data; if (debug == TRUE) { /* Only for debbugging ! */ print_received_data_for_hash(hash_data->hash, hash_data->read); } /** Sending hash_data into the queue. */ g_async_queue_push(server_struct->data_queue, hash_data); hash_data_list = g_list_next(hash_data_list); } g_list_free(head); /** * creating an answer for the client to say that everything went Ok! */ answer = g_strdup_printf(_("Ok!")); success = create_MHD_response(connection, answer); } else { /* The url is unknown to the server and we can not process the request ! */ print_error(__FILE__, __LINE__, "Error: invalid url: %s\n", url); answer = g_strdup_printf(_("Error: invalid url!\n")); success = create_MHD_response(connection, answer); } return success; }
GSList *quick_search_filter(QuickSearch *qsearch, QSearchCondType type, const gchar *key) { SummaryView *summaryview = qsearch->summaryview; FilterCondType ftype; FilterRule *status_rule = NULL; FilterRule *rule = NULL; FilterCond *cond; FilterInfo fltinfo; GSList *cond_list = NULL; GSList *rule_list = NULL; GSList *flt_mlist = NULL; GSList *cur; gint count = 0, total = 0; gchar status_text[1024]; gboolean dmode; if (!summaryview->all_mlist) return NULL; debug_print("quick_search_filter: filtering summary (type: %d)\n", type); switch (type) { case QS_UNREAD: case QS_MARK: case QS_CLABEL: case QS_MIME: ftype = qsearch_cond_types[type].ftype; cond = filter_cond_new(ftype, 0, 0, NULL, NULL); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_W1DAY: cond = filter_cond_new(FLT_COND_AGE_GREATER, 0, FLT_NOT_MATCH, NULL, "1"); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_LAST5: cond = filter_cond_new(FLT_COND_AGE_GREATER, 0, FLT_NOT_MATCH, NULL, "5"); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_LAST7: cond = filter_cond_new(FLT_COND_AGE_GREATER, 0, FLT_NOT_MATCH, NULL, "7"); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_LAST30: cond = filter_cond_new(FLT_COND_AGE_GREATER, 0, FLT_NOT_MATCH, NULL, "30"); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_IN_ADDRESSBOOK: cond = filter_cond_new(FLT_COND_HEADER, FLT_IN_ADDRESSBOOK, 0, "From", NULL); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_ALL: default: break; } if (key) { gchar **keys; gint i; keys = g_strsplit(key, " ", -1); for (i = 0; keys[i] != NULL; i++) { cond_list = NULL; if (keys[i] == '\0') continue; cond = filter_cond_new(FLT_COND_HEADER, FLT_CONTAIN, 0, "Subject", keys[i]); cond_list = g_slist_append(cond_list, cond); cond = filter_cond_new(FLT_COND_HEADER, FLT_CONTAIN, 0, "From", keys[i]); cond_list = g_slist_append(cond_list, cond); if (FOLDER_ITEM_IS_SENT_FOLDER(summaryview->folder_item)) { cond = filter_cond_new(FLT_COND_TO_OR_CC, FLT_CONTAIN, 0, NULL, keys[i]); cond_list = g_slist_append(cond_list, cond); } if (cond_list) { rule = filter_rule_new("Quick search rule", FLT_OR, cond_list, NULL); rule_list = g_slist_append(rule_list, rule); } } g_strfreev(keys); } memset(&fltinfo, 0, sizeof(FilterInfo)); dmode = get_debug_mode(); set_debug_mode(FALSE); for (cur = summaryview->all_mlist; cur != NULL; cur = cur->next) { MsgInfo *msginfo = (MsgInfo *)cur->data; GSList *hlist = NULL; gboolean matched = TRUE; total++; if (status_rule) { if (type == QS_IN_ADDRESSBOOK) hlist = procheader_get_header_list_from_msginfo (msginfo); if (!filter_match_rule(status_rule, msginfo, hlist, &fltinfo)) { if (hlist) procheader_header_list_destroy(hlist); continue; } } if (rule_list) { GSList *rcur; if (!hlist) hlist = procheader_get_header_list_from_msginfo (msginfo); /* AND keyword match */ for (rcur = rule_list; rcur != NULL; rcur = rcur->next) { rule = (FilterRule *)rcur->data; if (!filter_match_rule(rule, msginfo, hlist, &fltinfo)) { matched = FALSE; break; } } } if (matched) { flt_mlist = g_slist_prepend(flt_mlist, msginfo); count++; } if (hlist) procheader_header_list_destroy(hlist); } flt_mlist = g_slist_reverse(flt_mlist); set_debug_mode(dmode); if (status_rule || rule) { if (count > 0) g_snprintf(status_text, sizeof(status_text), _("%1$d in %2$d matched"), count, total); else g_snprintf(status_text, sizeof(status_text), _("No messages matched")); gtk_label_set_text(GTK_LABEL(qsearch->status_label), status_text); } else gtk_label_set_text(GTK_LABEL(qsearch->status_label), ""); filter_rule_list_free(rule_list); filter_rule_free(status_rule); return flt_mlist; }