static void metadata_add_file (struct ushare_t *ut, struct upnp_entry_t *entry, const char *file, const char *name, struct stat *st_ptr) { if (!entry || !file || !name) return; #ifdef HAVE_DLNA if (ut->dlna_enabled || is_valid_extension (getExtension (file))) #else if (is_valid_extension (getExtension (file))) #endif { struct upnp_entry_t *child = NULL; child = upnp_entry_new (ut, name, file, entry, st_ptr->st_size, false); if (child) upnp_entry_add_child (ut, entry, child); } }
int aifp_check_files_cb_foreach(playlist_t * pl, GtkTreeIter * iter, void * data) { struct stat statbuf; playlist_data_t * pldata; gtk_tree_model_get(GTK_TREE_MODEL(pl->store), iter, PL_COL_DATA, &pldata, -1); if (g_stat(pldata->file, &statbuf) != -1) { valid_files += is_valid_extension(valid_extensions_ifp, pldata->file, 0); } return 0; }
gpointer* add_file_to_playqueue(gpointer* data){ char* filepath = (char*)data; if ((is_valid_extension(filepath))) send_cmd("ADDS",standard_name(filepath),TP_LOW); return NULL; }
unsigned int bottom_up_computation_vertex_cover(G_t &G, T_t &T, treedec::app::detail::Intermediate_Results<T_t> &iRes, bool use_cache_weight_traversal=false) { std::stack<typename boost::graph_traits<T_t>::vertex_descriptor> S; if(use_cache_weight_traversal){ treedec::nice::min_weight_traversal(T, S); } else{ treedec::nice::postorder_traversal(T, S); } typename boost::graph_traits<T_t>::vertex_descriptor cur; while(!S.empty()){ cur = S.top(); S.pop(); treedec::nice::enum_node_type node_type = treedec::nice::get_type(cur, T); if(node_type == treedec::nice::LEAF){ //Store both possibilities (the empty set and the set containing one vertex). iRes.add(cur, 0, 0); iRes.add(cur, 1, 1); } else if(node_type == treedec::nice::INTRODUCE){ typename boost::graph_traits<T_t>::vertex_descriptor child = *(boost::adjacent_vertices(cur, T).first); typename boost::graph_traits<G_t>::vertex_descriptor new_vertex = treedec::nice::get_introduced_vertex(cur, T); //check if old VC is still valid, if new_vertex is added to the considered graph for(typename std::map<unsigned, int>::iterator it = iRes._results[child].begin(); it != iRes._results[child].end(); it++) { unsigned old_encoded = it->first; typename treedec_traits<T_t>::bag_type decoded_set; //TODO: get rid of this iRes.decode(child, old_encoded, decoded_set); unsigned new_encoded = iRes.encode(cur, decoded_set); auto &b = bag(cur, T); if(is_valid_extension(G, b, decoded_set, new_vertex)){ iRes.add(cur, new_encoded, iRes.get(child, old_encoded)); } else{ iRes.add(cur, new_encoded, -1); } } //check for new set in new graph for(typename std::map<unsigned, int>::iterator it = iRes._results[child].begin(); it != iRes._results[child].end(); it++) { unsigned old_encoded = it->first; encoded_iterator<typename treedec_traits<T_t>::bag_type::iterator> encIt(old_encoded, bag(child, T).begin(), bag(child, T).end()); unsigned new_encoded = iRes.encode_more(cur, child, encIt, new_vertex); if(it->second != -1){ iRes.add(cur, new_encoded, it->second + 1); } else{ //TODO: is this really correct?! /* typename treedec_traits<T_t>::bag_type new_set; iRes.decode(child, old_encoded, new_set); new_set.insert(new_vertex); if(is_vertex_cover2(G, bag(cur, T), new_set)){ iRes.add(cur, new_encoded, new_set.size()); } else{ */ iRes.add(cur, new_encoded, -1); // } } } } else if(node_type == treedec::nice::FORGET){ typename boost::graph_traits<T_t>::vertex_descriptor child = *(boost::adjacent_vertices(cur, T).first); typename boost::graph_traits<G_t>::vertex_descriptor forgotten_vertex = treedec::nice::get_forgotten_vertex(cur, T); BOOST_AUTO(subset_iters_it, make_subsets_range(bag(cur, T).begin(), bag(cur, T).end(), 0, bag(cur, T).size()).first); for(; subset_iters_it != bag(cur, T).end(); ++subset_iters_it){ unsigned old_encoded1 = iRes.encode(child, (*subset_iters_it).first, (*subset_iters_it).second); unsigned old_encoded2 = iRes.update_encoding(child, old_encoded1, forgotten_vertex); int val_without = iRes.get(child, old_encoded1); int val_with = iRes.get(child, old_encoded2); unsigned new_encoded = iRes.encode(cur, (*subset_iters_it).first, (*subset_iters_it).second); if(val_with == -1){ iRes.add(cur, new_encoded, val_without); } else if(val_without == -1){ iRes.add(cur, new_encoded, val_with); } else{ if(val_with <= val_without){ iRes.add(cur, new_encoded, val_with); } else{ iRes.add(cur, new_encoded, val_without); } } } } else if(node_type == treedec::nice::JOIN){ typename boost::graph_traits<T_t>::vertex_descriptor child1 = *(boost::adjacent_vertices(cur, T).first); typename boost::graph_traits<T_t>::vertex_descriptor child2 = *(++boost::adjacent_vertices(cur, T).first); for(typename std::map<unsigned, int>::iterator it = iRes._results[child1].begin(); it != iRes._results[child1].end(); it++) { unsigned encoded = it->first; if(iRes.get(child1, encoded) < 0 || iRes.get(child2, encoded) < 0){ iRes.add(cur, encoded, -1); } else{ unsigned subset_size = iRes.get_size(child1, encoded); iRes.add(cur, encoded, iRes.get(child1, encoded) + iRes.get(child2, encoded) - subset_size); } } } } typename boost::graph_traits<T_t>::vertex_descriptor root = find_root(T); return (unsigned int) iRes.get(root, 0); }
/* If `name' has a correct extension, try to list its contents and search for the first file with a proper extension; if found, extract it. If this succeeds, return the name of the temporary file; if the archive file is valid but `write_mode' is non-zero, return a zero-length string; in all the other cases, return NULL. */ static char *try_uncompress_archive(const char *name, int write_mode, const char *program, const char *listopts, const char *extractopts, const char *extension, const char *search) { char *tmp_name = NULL; size_t l = strlen(name), len, nameoffset; int found = 0; int exit_status; char *argv[8]; FILE *fd; char tmp[1024]; /* Do we have correct extension? */ len = strlen(extension); if (l <= len || strcasecmp(name + l - len, extension) != 0) { return NULL; } /* First run listing and search for first recognizeable extension. */ argv[0] = lib_stralloc(program); argv[1] = lib_stralloc(listopts); argv[2] = archdep_filename_parameter(name); argv[3] = NULL; ZDEBUG(("try_uncompress_archive: spawning `%s %s %s'", program, listopts, name)); exit_status = archdep_spawn(program, argv, &tmp_name, NULL); lib_free(argv[0]); lib_free(argv[1]); lib_free(argv[2]); /* No luck? */ if (exit_status != 0) { ZDEBUG(("try_uncompress_archive: `%s %s' failed.", program, listopts)); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } ZDEBUG(("try_uncompress_archive: `%s %s' successful.", program, listopts)); fd = fopen(tmp_name, MODE_READ); if (!fd) { ZDEBUG(("try_uncompress_archive: cannot read `%s %s' output.", program, tmp_name)); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } ZDEBUG(("try_uncompress_archive: searching for the first valid file.")); /* Search for `search' first (if any) to see the offset where filename begins, then search for first recognizeable file. */ nameoffset = search ? -1 : 0; len = search ? strlen(search) : 0; while (!feof(fd) && !found) { if (fgets(tmp, 1024, fd) == NULL) { break; } l = strlen(tmp); while (l > 0) { tmp[--l] = 0; if (((nameoffset < 0) || (nameoffset > 1024)) && l >= len && !strcasecmp(tmp + l - len, search) != 0) { nameoffset = l - 4; } if (nameoffset >= 0 && nameoffset <= 1024 && is_valid_extension(tmp, l, nameoffset)) { ZDEBUG(("try_uncompress_archive: found `%s'.", tmp + nameoffset)); found = 1; break; } } } fclose(fd); ioutil_remove(tmp_name); if (!found) { ZDEBUG(("try_uncompress_archive: no valid file found.")); lib_free(tmp_name); return NULL; } /* This would be a valid ZIP file, but we cannot handle ZIP files in write mode. Return a null temporary file name to report this. */ if (write_mode) { ZDEBUG(("try_uncompress_archive: cannot open file in write mode.")); lib_free(tmp_name); return ""; } /* And then file inside zip. If we have a zipcode extract all of them to the same file. */ argv[0] = lib_stralloc(program); argv[1] = lib_stralloc(extractopts); argv[2] = archdep_filename_parameter(name); if (is_zipcode_name(tmp + nameoffset)) { argv[3] = lib_stralloc(tmp + nameoffset); argv[4] = lib_stralloc(tmp + nameoffset); argv[5] = lib_stralloc(tmp + nameoffset); argv[6] = lib_stralloc(tmp + nameoffset); argv[7] = NULL; argv[3][0] = '1'; argv[4][0] = '2'; argv[5][0] = '3'; argv[6][0] = '4'; } else { argv[3] = archdep_quote_parameter(tmp + nameoffset); argv[4] = NULL; } ZDEBUG(("try_uncompress_archive: spawning `%s %s %s %s'.", program, extractopts, name, tmp + nameoffset)); exit_status = archdep_spawn(program, argv, &tmp_name, NULL); lib_free(argv[0]); lib_free(argv[1]); lib_free(argv[2]); lib_free(argv[3]); if (is_zipcode_name(tmp + nameoffset)) { lib_free(argv[4]); lib_free(argv[5]); lib_free(argv[6]); } if (exit_status != 0) { ZDEBUG(("try_uncompress_archive: `%s %s' failed.", program, extractopts)); ioutil_remove(tmp_name); lib_free(tmp_name); return NULL; } ZDEBUG(("try_uncompress_archive: `%s %s' successful.", program, tmp_name)); return tmp_name; }
int loadPresetDir(char * dir) { struct dirent ** name_list; char * preset_name; int i, j, dir_size; if (dir == NULL) return ERROR; if (chrono_order_preset_name_tree != NULL) { if (PRESET_DEBUG) printf("loadPresetDir: previous directory doesn't appear to be closed!\n"); /* Let this slide for now */ } /* Scan the entire directory, storing each entry in a dirent struct array that needs to be freed later. For more information, consult scandir(3) in the man pages */ if ((dir_size = scandir(dir, &name_list, 0, alphasort)) < 0) { if (PRESET_DEBUG) printf("loadPresetDir: failed to open directory \"%s\"\n", dir); return ERROR; } chrono_order_preset_name_tree = create_splaytree(compare_int, copy_int, free_int); /* Iterate through entire dirent name list, adding to the preset name list if it is valid */ for (i = 0; ((i < dir_size) && (i < MAX_PRESETS_IN_DIR));i++) { /* Only perform the next set of operations if the preset name contains a valid extension */ if (is_valid_extension(name_list[i]->d_name)) { /* Handle the out of memory case. My guess is xmms would crash before this program would, but whatever...*/ if ((preset_name = (char*)malloc(MAX_PATH_SIZE)) == NULL) { if (PRESET_DEBUG) printf("loadPresetDir: out of memory! \n"); /* Free the rest of the dirent name list */ for (j = i; j < dir_size; j++) free(name_list[j]); destroy_splaytree(chrono_order_preset_name_tree); return OUTOFMEM_ERROR; } /* Now create the full path */ if (get_preset_path(&preset_name, dir, name_list[i]->d_name) < 0) { if (PRESET_DEBUG) printf("loadPresetDir: failed to generate full preset path name!\n"); /* Free the rest of the dirent name list */ for (j = i; j < dir_size; j++) free(name_list[j]); destroy_splaytree(chrono_order_preset_name_tree); return OUTOFMEM_ERROR; } /* Insert the character string into the splay tree, with the key being its sequence number */ splay_insert(preset_name, &preset_name_buffer_size, chrono_order_preset_name_tree); preset_name_buffer_size++; } /* Free the dirent struct */ free(name_list[i]); } free(name_list); /* No valid files in directory! */ if (chrono_order_preset_name_tree->root == NULL) { if (PRESET_DEBUG) printf("loadPresetDir: no valid files in directory \"%s\"\n", dir); destroy_splaytree(chrono_order_preset_name_tree); chrono_order_preset_name_tree = NULL; return FAILURE; } /* Start the prefix index right before the first entry, so next preset starts at the top of the list */ preset_index = -1; /* Start the first preset */ switchPreset(ALPHA_NEXT, HARD_CUT); return SUCCESS; }