//------------------------------------------------------------------------------ static int uninstall_autorun(const char* clink_path, int wow64) { HKEY cmd_proc_key; char* key_value; int ret; int left, right; cmd_proc_key = open_software_key("Microsoft\\Command Processor", wow64, 1); if (cmd_proc_key == NULL) { return 0; } key_value = NULL; get_value(cmd_proc_key, "AutoRun", &key_value); ret = 1; if (key_value && find_clink_entry(key_value, &left, &right)) { const char* read; char* write; int i, n; // Copy the key value into itself, skipping clink's entry. read = write = key_value; for (i = 0, n = (int)strlen(key_value); i <= n; ++i) { if (i < left || i >= right) { *write++ = *read; } ++read; } read = get_cmd_start(key_value); if (*read == '\0') { // Empty key. We might as well delete it. if (!delete_value(cmd_proc_key, "AutoRun")) { ret = 0; } } else if (!set_value(cmd_proc_key, "AutoRun", read)) { ret = 0; } } // Delete legacy values. delete_value(cmd_proc_key, "AutoRunPreClinkInstall"); // Tidy up. close_key(cmd_proc_key); free(key_value); return ret; }
/** * Obtain matching value at 'offset'. * * @param cls the 'struct GetContext' * @param key unused * @param val the 'struct Value' * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found */ static int get_iterator (void *cls, const struct GNUNET_HashCode *key, void *val) { struct GetContext *gc = cls; struct Value *value = val; if (GNUNET_NO == match (gc, value)) return GNUNET_OK; if (0 != gc->offset--) return GNUNET_OK; if (GNUNET_NO == gc->proc (gc->proc_cls, key, value->size, &value[1], value->type, value->priority, value->anonymity, value->expiration, (uint64_t) (long) value)) delete_value (gc->plugin, value); return GNUNET_NO; }
/** * Get a random item for expiration. Call 'proc' with all values ZERO * or NULL if the datastore is empty. * * @param cls closure * @param proc function to call the value (once only). * @param proc_cls closure for proc */ static void heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, void *proc_cls) { struct Plugin *plugin = cls; struct Value *value; value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration); if (NULL == value) { proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); return; } if (GNUNET_NO == proc (proc_cls, &value->key, value->size, &value[1], value->type, value->priority, value->anonymity, value->expiration, (uint64_t) (long) value)) delete_value (plugin, value); }
//------------------------------------------------------------------------------ static int uninstall_autorun(const char* clink_path, int wow64) { HKEY cmd_proc_key; char* key_value; int ret; int left, right; cmd_proc_key = open_cmd_proc_key(g_all_users, wow64, 1); if (cmd_proc_key == nullptr) { printf("ERROR: Failed to open registry key (%d)\n", GetLastError()); return 0; } key_value = nullptr; get_value(cmd_proc_key, "AutoRun", &key_value); ret = 1; if (key_value && find_clink_entry(key_value, &left, &right)) { const char* read; char* write; int i, n; // Copy the key value into itself, skipping clink's entry. read = write = key_value; for (i = 0, n = (int)strlen(key_value); i <= n; ++i) { if (i < left || i >= right) { *write++ = *read; } ++read; } read = get_cmd_start(key_value); if (*read == '\0') { // Empty key. We might as well delete it. if (!delete_value(cmd_proc_key, "AutoRun")) { ret = 0; } } else if (!set_value(cmd_proc_key, "AutoRun", read)) { ret = 0; } } // Tidy up. close_key(cmd_proc_key); free(key_value); return ret; }
/** * Callback invoked to free all value. * * @param cls the plugin * @param key unused * @param val the value * @return GNUNET_OK (continue to iterate) */ static int free_value (void *cls, const struct GNUNET_HashCode *key, void *val) { struct Plugin *plugin = cls; struct Value *value = val; delete_value (plugin, value); return GNUNET_OK; }
/** * Call the given processor on an item with zero anonymity. * * @param cls our "struct Plugin*" * @param offset offset of the result (modulo num-results); * specific ordering does not matter for the offset * @param type entries of which type should be considered? * Use 0 for any type. * @param proc function to call on each matching value; * will be called with NULL if no value matches * @param proc_cls closure for proc */ static void heap_plugin_get_zero_anonymity (void *cls, uint64_t offset, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls) { struct Plugin *plugin = cls; struct ZeroAnonByType *zabt; struct Value *value; uint64_t count; count = 0; for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) { if ( (type != GNUNET_BLOCK_TYPE_ANY) && (type != zabt->type) ) continue; count += zabt->array_pos; } if (0 == count) { proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); return; } offset = offset % count; for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) { if ( (type != GNUNET_BLOCK_TYPE_ANY) && (type != zabt->type) ) continue; if (offset >= zabt->array_pos) { offset -= zabt->array_pos; continue; } break; } GNUNET_assert (NULL != zabt); value = zabt->array[offset]; if (GNUNET_NO == proc (proc_cls, &value->key, value->size, &value[1], value->type, value->priority, value->anonymity, value->expiration, (uint64_t) (long) value)) delete_value (plugin, value); }
BOOL generate(unit_box boxes[],INDEX index, INDEX r, INDEX c, BOOL *is_going_down) { UNIT val = 0; UNIT k = 0; if(index >= TOTAL) { if(*is_going_down == TRUE) { *is_going_down = FALSE; return FALSE; } return TRUE; } if(debug) printf("\nPROCESSING (%d,%d,%d)", index, r, c); k = val = boxes[index].value[r][c]; if(k == 0) { *is_going_down = FALSE; k = 1; } for ( ; k <= TOTAL ; k++) { INDEX newIndex = index, newr = r, newc = c+1; delete_value(boxes, index, r, c); if(debug) printf("\nINSERTING (%d,%d,%d) : %d", index, r, c, k); if(insert_value(boxes, index, k, r, c)) { if(newc >= ROW){ newr++; newc = 0;} if(newr >= COLUMN) {newIndex++; newr = 0;} if(generate(boxes, newIndex, newr, newc, is_going_down)) return TRUE; } } delete_value(boxes, index, r, c); return FALSE; }
STATUS delete_value_index_by_entry(int index, entry *target_entry) { value *found = get_value_from_entry_by_index(index, target_entry); if(!found) { DEBUG("delete_value_index_by_entry-> !found, INDEX_OUT_OF_RANGE\n"); return INDEX_OUT_OF_RANGE; } STATUS delete_status = delete_value(found); if(delete_status != OK) { DEBUG("delete_value_index_by_entry->delete_status !OK\n"); return delete_status; } return OK; }
/** * Get a random item for replication. Returns a single, not expired, * random item from those with the highest replication counters. The * item's replication counter is decremented by one IF it was positive * before. Call 'proc' with all values ZERO or NULL if the datastore * is empty. * * @param cls closure * @param proc function to call the value (once only). * @param proc_cls closure for proc */ static void heap_plugin_get_replication (void *cls, PluginDatumProcessor proc, void *proc_cls) { struct Plugin *plugin = cls; struct Value *value; value = GNUNET_CONTAINER_heap_remove_root (plugin->by_replication); if (NULL == value) { proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); return; } if (value->replication > 0) { value->replication--; value->replication_heap = GNUNET_CONTAINER_heap_insert (plugin->by_replication, value, value->replication); } else { /* need a better way to pick a random item, replication level is always 0 */ value->replication_heap = GNUNET_CONTAINER_heap_insert (plugin->by_replication, value, value->replication); value = GNUNET_CONTAINER_heap_walk_get_next (plugin->by_replication); } if (GNUNET_NO == proc (proc_cls, &value->key, value->size, &value[1], value->type, value->priority, value->anonymity, value->expiration, (uint64_t) (long) value)) delete_value (plugin, value); }
//------------------------------------------------------------------------------ static int set_autorun_value(const char* value, int wow64) { HKEY cmd_proc_key; int ret; cmd_proc_key = open_cmd_proc_key(g_all_users, wow64, 1); if (cmd_proc_key == nullptr) { printf("ERROR: Failed to open registry key (%d)\n", GetLastError()); return 0; } if (value == nullptr || *value == '\0') ret = delete_value(cmd_proc_key, "AutoRun"); else ret = set_value(cmd_proc_key, "AutoRun", value); close_key(cmd_proc_key); return ret; }
NTSTATUS NTAPI NtSetValueKey( HANDLE KeyHandle, PUNICODE_STRING ValueName, ULONG TitleIndex, ULONG Type, PVOID Data, ULONG DataSize ) { unicode_string_t us; regkey_t *key; NTSTATUS r; trace("%p %p %lu %lu %p %lu\n", KeyHandle, ValueName, TitleIndex, Type, Data, DataSize ); r = object_from_handle( key, KeyHandle, KEY_SET_VALUE ); if (r < STATUS_SUCCESS) return r; r = us.copy_from_user( ValueName ); if (r == STATUS_SUCCESS) { regval_t *val; val = new regval_t( &us, Type, DataSize ); if (val) { r = copy_from_user( val->data, Data, DataSize ); if (r == STATUS_SUCCESS) { delete_value( key, &us ); key->values.append( val ); } else delete val; } else r = STATUS_NO_MEMORY; } return r; }
NTSTATUS NTAPI NtDeleteValueKey( HANDLE KeyHandle, PUNICODE_STRING ValueName ) { unicode_string_t us; NTSTATUS r; regkey_t *key; trace("%p %p\n", KeyHandle, ValueName); r = us.copy_from_user( ValueName ); if (r < STATUS_SUCCESS) return r; r = object_from_handle( key, KeyHandle, KEY_SET_VALUE ); if (r < STATUS_SUCCESS) return r; r = delete_value( key, &us ); return r; }
STATUS delete_entry_values(entry *target_entry) { if(!target_entry) { DEBUG("delete_entry_values-> !target_entry\n"); return NO_ENTRY; } if(!target_entry->values) { DEBUG("delete_entry_values->target_entry !values, OK\n"); return OK; } value *cursor = target_entry->values->next; while(cursor) { value *next = cursor->next; delete_value(cursor); cursor = next; }; DEBUG("delete_entry_values-> OK\n"); return OK; }
STATUS print_and_remove_index_by_entry(int index, entry *target_entry) { value *target_value = get_value_from_entry_by_index(index, target_entry); if(!target_value) { DEBUG("print_and_remove_index_by_entry-> !target_value, INDEX_OUT_OF_RANGE\n"); return INDEX_OUT_OF_RANGE; } STATUS print_value_status = print_value_by_value(target_value); if(print_value_status != OK) { DEBUG("print_and_remove_index_by_entry->print_value_status !OK\n"); return print_value_status; } STATUS delete_value_status = delete_value(target_value); if(delete_value_status != OK) { DEBUG("print_and_remove_index_by_entry->delete_value_status !OK\n"); return delete_value_status; } DEBUG("print_and_remove_index_by_entry-> OK\n"); return OK; }
STATUS uniq_values_by_entry(entry *target_entry) { int prev_value; int first = 1; value *cursor = target_entry->values->next; while(cursor) { value *next = cursor->next; if(!first && prev_value == cursor->value) { delete_value(cursor); } else { prev_value = cursor->value; } cursor = next; first = 0; continue; } DEBUG("uniq_values_by_entry-> OK\n"); return OK; }
G_MODULE_EXPORT gboolean tracker_extract_get_metadata (TrackerExtractInfo *info) { GFile *file; TrackerSparqlBuilder *metadata; TrackerSparqlBuilder *preupdate; const gchar *graph; gchar *absolute_file_path; gchar *uri; AVFormatContext *format = NULL; AVStream *audio_stream = NULL; AVStream *video_stream = NULL; int audio_stream_index; int video_stream_index; AVDictionaryEntry *tag = NULL; const char *title = NULL; av_register_all (); file = tracker_extract_info_get_file (info); metadata = tracker_extract_info_get_metadata_builder (info); preupdate = tracker_extract_info_get_preupdate_builder (info); graph = tracker_extract_info_get_graph (info); uri = g_file_get_uri (file); absolute_file_path = g_file_get_path (file); if (avformat_open_input (&format, absolute_file_path, NULL, NULL)) { g_free (absolute_file_path); g_free (uri); return FALSE; } g_free (absolute_file_path); avformat_find_stream_info (format, NULL); audio_stream_index = av_find_best_stream (format, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0); if (audio_stream_index >= 0) { audio_stream = format->streams[audio_stream_index]; } video_stream_index = av_find_best_stream (format, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); if (video_stream_index >= 0) { video_stream = format->streams[video_stream_index]; } if (!audio_stream && !video_stream) { avformat_free_context (format); g_free (uri); return FALSE; } if (audio_stream) { if (audio_stream->codec->sample_rate > 0) { set_value_int64 (metadata, "nfo:sampleRate", audio_stream->codec->sample_rate); } if (audio_stream->codec->channels > 0) { set_value_int64 (metadata, "nfo:channels", audio_stream->codec->channels); } } if (video_stream) { tracker_sparql_builder_predicate (metadata, "a"); tracker_sparql_builder_object (metadata, "nmm:Video"); if (video_stream->codec->width > 0 && video_stream->codec->height > 0) { set_value_int64 (metadata, "nfo:width", video_stream->codec->width); set_value_int64 (metadata, "nfo:height", video_stream->codec->height); } if (video_stream->avg_frame_rate.num > 0) { gdouble frame_rate = (gdouble) video_stream->avg_frame_rate.num / video_stream->avg_frame_rate.den; set_value_double (metadata, "nfo:frameRate", frame_rate); } if (video_stream->duration > 0) { gint64 duration = av_rescale(video_stream->duration, video_stream->time_base.num, video_stream->time_base.den); set_value_int64 (metadata, "nfo:duration", duration); } if (video_stream->sample_aspect_ratio.num > 0) { gdouble aspect_ratio = (gdouble) video_stream->sample_aspect_ratio.num / video_stream->sample_aspect_ratio.den; set_value_double (metadata, "nfo:aspectRatio", aspect_ratio); } if (video_stream->nb_frames > 0) { set_value_int64 (metadata, "nfo:frameCount", video_stream->nb_frames); } if ((tag = av_dict_get (format->metadata, "synopsis", NULL, 0))) { set_value_string (metadata, "nmm:synopsis", tag->value); } if ((tag = av_dict_get (format->metadata, "episode_sort", NULL, 0))) { set_value_int64 (metadata, "nmm:episodeNumber", atoi(tag->value)); } if ((tag = av_dict_get (format->metadata, "season_number", NULL, 0))) { set_value_int64 (metadata, "nmm:season", atoi(tag->value)); } } else if (audio_stream) { const char *album_title = NULL; const char *album_artist = NULL; gchar *album_artist_uri = NULL; gchar *performer_uri = NULL; tracker_sparql_builder_predicate (metadata, "a"); tracker_sparql_builder_object (metadata, "nmm:MusicPiece"); tracker_sparql_builder_object (metadata, "nfo:Audio"); if (audio_stream->duration > 0) { gint64 duration = av_rescale(audio_stream->duration, audio_stream->time_base.num, audio_stream->time_base.den); set_value_int64 (metadata, "nfo:duration", duration); } if ((tag = find_tag (format, audio_stream, "track"))) { int track = atoi(tag->value); if (track > 0) { set_value_int64 (metadata, "nmm:trackNumber", track); } } if ((tag = find_tag (format, audio_stream, "album"))) { album_title = tag->value; } if (album_title && (tag = find_tag (format, audio_stream, "album_artist"))) { album_artist_uri = create_artist (preupdate, graph, tag->value); album_artist = tag->value; } if ((tag = find_tag (format, audio_stream, "artist"))) { performer_uri = create_artist (preupdate, graph, tag->value); if (!album_artist) { album_artist = tag->value; } } if (!performer_uri && (tag = find_tag (format, audio_stream, "performer"))) { performer_uri = create_artist (preupdate, graph, tag->value); if (!album_artist) { album_artist = tag->value; } } if (performer_uri) { set_value_iri (metadata, "nmm:performer", performer_uri); } else if (album_artist_uri) { set_value_iri (metadata, "nmm:performer", album_artist_uri); } if ((tag = find_tag (format, audio_stream, "composer"))) { gchar *composer_uri = create_artist (preupdate, graph, tag->value); set_value_iri (metadata, "nmm:composer", composer_uri); g_free(composer_uri); } if (album_title) { int disc = 1; gchar *disc_uri; gchar *album_uri = tracker_sparql_escape_uri_printf ("urn:album:%s", album_title); open_insert (preupdate, graph, album_uri, "nmm:MusicAlbum"); set_value_string (preupdate, "nmm:albumTitle", album_title); if (album_artist_uri) { set_value_iri (preupdate, "nmm:albumArtist", album_artist_uri); } else if (performer_uri) { set_value_iri (preupdate, "nmm:albumArtist", performer_uri); } close_insert (preupdate, graph); if ((tag = find_tag (format, audio_stream, "disc"))) { disc = atoi (tag->value); } disc_uri = tracker_sparql_escape_uri_printf ("urn:album-disc:%s:Disc%d", album_title, disc); delete_value (preupdate, disc_uri, "nmm:setNumber", "unknown"); delete_value (preupdate, disc_uri, "nmm:albumDiscAlbum", "unknown"); open_insert (preupdate, graph, disc_uri, "nmm:MusicAlbumDisc"); set_value_int64 (preupdate, "nmm:setNumber", disc); set_value_iri (preupdate, "nmm:albumDiscAlbum", album_uri); close_insert (preupdate, graph); set_value_iri (metadata, "nmm:musicAlbumDisc", disc_uri); set_value_iri (metadata, "nmm:musicAlbum", album_uri); g_free (disc_uri); g_free (album_uri); } #ifdef HAVE_LIBMEDIAART if (album_artist || album_title) { MediaArtProcess *media_art_process; GError *error = NULL; gboolean success; media_art_process = tracker_extract_info_get_media_art_process (info); success = media_art_process_file (media_art_process, MEDIA_ART_ALBUM, MEDIA_ART_PROCESS_FLAGS_NONE, file, album_artist, album_title, &error); if (!success || error) { g_warning ("Could not process media art for '%s', %s", uri, error ? error->message : "No error given"); g_clear_error (&error); } } #endif g_free(performer_uri); } if (format->bit_rate > 0) { set_value_int64 (metadata, "nfo:averageBitrate", format->bit_rate); } if ((tag = av_dict_get (format->metadata, "comment", NULL, 0))) { set_value_string (metadata, "nie:comment", tag->value); } if ((tag = av_dict_get (format->metadata, "copyright", NULL, 0))) { set_value_string (metadata, "nie:copyright", tag->value); } if ((tag = av_dict_get (format->metadata, "creation_time", NULL, 0))) { gchar *content_created = tracker_date_guess (tag->value); if (content_created) { set_value_string (metadata, "nie:contentCreated", content_created); g_free (content_created); } } if ((tag = av_dict_get (format->metadata, "description", NULL, 0))) { set_value_string (metadata, "nie:description", tag->value); } if ((tag = av_dict_get (format->metadata, "genre", NULL, 0))) { set_value_string (metadata, "nfo:genre", tag->value); } if ((tag = av_dict_get (format->metadata, "language", NULL, 0))) { set_value_string (metadata, "nfo:language", tag->value); } if ((tag = av_dict_get (format->metadata, "title", NULL, 0))) { title = tag->value; } tracker_guarantee_title_from_file (metadata, "nie:title", title, uri, NULL); g_free (uri); avformat_free_context (format); return TRUE; }
/// removes all values for the HTTP header named key inline void delete_header(const std::string& key) { delete_value(m_headers, key); }
/// clears payload content buffer inline void clear_content(void) { set_content_length(0); create_content_buffer(); delete_value(m_headers, HEADER_CONTENT_TYPE); }
/// removes all values for a cookie /// since cookie names are insensitive, key should use lowercase alpha chars inline void delete_cookie(const std::string& key) { delete_value(m_cookie_params, key); }