static void gxi_check_file (GncXmlImportData *data) { if (!data->encodings) { gboolean is_utf8; const gchar *locale_enc; gchar *enc_string, **enc_array, **enc_cursor; gpointer enc_ptr; GIConv iconv; /* first locale encoding */ is_utf8 = g_get_charset (&locale_enc); enc_string = g_ascii_strup (locale_enc, -1); enc_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string)); g_free (enc_string); data->encodings = g_list_append (NULL, enc_ptr); /* add utf-8 */ if (!is_utf8) { enc_ptr = GUINT_TO_POINTER (g_quark_from_string ("UTF-8")); data->encodings = g_list_append (data->encodings, enc_ptr); } /* Translators: Please insert encodings here that are typically used in your * locale, separated by spaces. No need for ASCII or UTF-8, check `locale -m` * for assistance with spelling. */ enc_array = g_strsplit (_("ISO-8859-1 KOI8-U"), " ", 0); /* loop through typical encodings */ for (enc_cursor = enc_array; *enc_cursor; enc_cursor++) { if (!**enc_cursor) continue; enc_string = g_ascii_strup (*enc_cursor, -1); enc_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string)); if (!g_list_find (data->encodings, enc_ptr)) { /* test whether we like this encoding */ iconv = g_iconv_open ("UTF-8", enc_string); if (iconv != (GIConv) - 1) /* we like it */ data->encodings = g_list_append (data->encodings, enc_ptr); g_iconv_close (iconv); } g_free (enc_string); } g_strfreev (enc_array); } if (!data->default_encoding) { /* choose top one */ data->default_encoding = GPOINTER_TO_UINT (data->encodings->data); } if (!data->choices) { data->choices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) conv_free); } gxi_ambiguous_info_destroy (data); /* analyze file */ data->n_impossible = gnc_xml2_find_ambiguous ( data->filename, data->encodings, &data->unique, &data->ambiguous_ht, NULL); if (data->n_impossible != -1) { /* sort ambiguous words */ g_hash_table_foreach (data->ambiguous_ht, (GHFunc)ambiguous_list_insert, data); gxi_sort_ambiguous_list (data); } }
static GwyContainer* zeiss_load_tiff(const GwyTIFF *tiff, GError **error) { GwyContainer *container = NULL, *meta = NULL; GwyDataField *dfield; GwySIUnit *siunit; GwyTIFFImageReader *reader = NULL; GHashTable *hash = NULL; gint i, power10; gchar *value, *end, *comment = NULL; gdouble *data; gboolean new_file; double factor, dx; /* Comment with parameters is common for all data fields */ if (!gwy_tiff_get_string0(tiff, ZEISS_HEADER_TAG, &comment)) { err_FILE_TYPE(error, "Carl Zeiss SEM"); goto fail; } if (strstr(comment, MAGIC_COMMENT)) new_file = TRUE; else if (g_str_has_prefix(comment, SOMEWHAT_LESS_MAGIC_COMMENT)) new_file = FALSE; else { err_FILE_TYPE(error, "Carl Zeiss SEM"); goto fail; } /* Read the comment header. */ if (new_file) { hash = parse_comment(comment); if ((value = g_hash_table_lookup(hash, "Image Pixel Size"))) { gwy_debug("Using dx from Image Pixel Size: %s", value); } else if ((value = g_hash_table_lookup(hash, "Pixel Size"))) { gwy_debug("Using dx from Pixel Size: %s", value); } else { err_MISSING_FIELD(error, "Pixel Size"); goto fail; } } else { /* The first thing is the pixel size, apparently. */ value = comment + strlen(SOMEWHAT_LESS_MAGIC_COMMENT); gwy_debug("Using dx from old-style comment: %s", value); } dx = g_ascii_strtod(value, &end); /* Use negated positive conditions to catch NaNs */ if (!((dx = fabs(dx)) > 0)) { g_warning("Real pixel size is 0.0, fixing to 1.0"); dx = 1.0; } if (!new_file) end = "m"; /* Request a reader, this ensures dimensions and stuff are defined. * NB: Newer versions store the image as RGB. Not useful here; just * average the channels. */ if (!(reader = gwy_tiff_get_image_reader(tiff, 0, 3, error))) goto fail; siunit = gwy_si_unit_new_parse(end, &power10); factor = pow10(power10); dfield = gwy_data_field_new(reader->width, reader->height, reader->width * factor * dx, reader->height * factor * dx, FALSE); gwy_data_field_set_si_unit_xy(dfield, siunit); g_object_unref(siunit); data = gwy_data_field_get_data(dfield); if (reader->samples_per_pixel > 1) { gdouble *datarow = g_new(gdouble, reader->width); gint ch, j, spp = reader->samples_per_pixel; gwy_data_field_clear(dfield); for (i = 0; i < reader->height; i++) { for (ch = 0; ch < spp; ch++) { gwy_tiff_read_image_row(tiff, reader, 0, i, 1.0, 0.0, datarow); for (j = 0; j < reader->width; j++) data[i*reader->width + j] += datarow[j]; } } g_free(datarow); gwy_data_field_multiply(dfield, 1.0/spp); gwy_data_field_invalidate(dfield); } else { for (i = 0; i < reader->height; i++) gwy_tiff_read_image_row(tiff, reader, 0, i, 1.0, 0.0, data + i*reader->width); } container = gwy_container_new(); gwy_container_set_object_by_name(container, "/0/data", dfield); g_object_unref(dfield); gwy_container_set_string_by_name(container, "/0/data/title", g_strdup("Secondary electron count")); if (new_file) { meta = gwy_container_new(); g_hash_table_foreach(hash, add_meta, meta); if (gwy_container_get_n_items(meta)) gwy_container_set_object_by_name(container, "/0/meta", meta); g_object_unref(meta); } fail: if (hash) g_hash_table_destroy(hash); g_free(comment); return container; }
static gboolean unload_plugin(PurplePlugin *plugin) { int i; GList *current; twitter_debug("called\n"); /* disconnect from signal */ purple_signal_disconnect(purple_conversations_get_handle(), "writing-im-msg", plugin, PURPLE_CALLBACK(writing_im_cb)); purple_signal_disconnect(purple_conversations_get_handle(), "sending-im-msg", plugin, PURPLE_CALLBACK(sending_im_cb)); purple_signal_disconnect(purple_conversations_get_handle(), "conversation-created", plugin, PURPLE_CALLBACK(conv_created_cb)); purple_signal_disconnect(pidgin_conversations_get_handle(), "displaying-im-msg", plugin, PURPLE_CALLBACK(displaying_im_cb)); purple_signal_disconnect(pidgin_conversations_get_handle(), "displayed-im-msg", plugin, PURPLE_CALLBACK(displayed_im_cb)); purple_signal_disconnect(purple_conversations_get_handle(), "receiving-im-msg", plugin, PURPLE_CALLBACK(receiving_im_cb)); purple_signal_disconnect(purple_conversations_get_handle(), "deleting-conversation", plugin, PURPLE_CALLBACK(deleting_conv_cb)); purple_signal_disconnect(purple_connections_get_handle(), "signed-on", plugin, PURPLE_CALLBACK(signed_on_cb)); /* unreference regp */ for(i = 0; i < NUM_REGPS; i++) { g_regex_unref(regp[i]); } /* remove mark list in each hash entry */ /* cancel request that has not been finished yet */ for(i = twitter_service; i < NUM_SERVICES; i++) { /* delete mark list and stop requeset for each hash table */ g_hash_table_foreach(icon_hash[i], (GHFunc)cleanup_hash_entry_func, NULL); /* destroy hash table for icon_data */ g_hash_table_destroy(icon_hash[i]); } g_hash_table_destroy(conv_hash); /* detach from twitter window */ detach_from_window(); /* free wassr_parrot_list */ current = g_list_first(wassr_parrot_list); while(current) { GList *next; next = g_list_next(current); g_free(current->data); wassr_parrot_list = g_list_delete_link(wassr_parrot_list, current); current = next; } g_list_free(wassr_parrot_list); wassr_parrot_list = NULL; /* free identica_parot_list */ current = g_list_first(identica_parrot_list); while(current) { GList *next; next = g_list_next(current); g_free(current->data); identica_parrot_list = g_list_delete_link(identica_parrot_list, current); current = next; } g_list_free(identica_parrot_list); identica_parrot_list = NULL; return TRUE; }
void testcase_frequent_words(gchar* logs, guint support, gchar *expected) { int i, twopass; gchar **expecteds; GHashTable *wordlist; loglinesType *logmessages; logmessages = testcase_get_logmessages(logs); expecteds = g_strsplit(expected, ",", 0); for (twopass = 1; twopass <= 2; ++twopass) { wordlist = ptz_find_frequent_words(logmessages->logmessages, support, twopass == 1); for (i = 0; expecteds[i]; ++i) { char **expected_item; char *expected_word; int expected_occurance; guint ret; gpointer retp; expected_item = g_strsplit(expecteds[i], ":", 2); expected_word = expected_item[0]; sscanf(expected_item[1], "%d", &expected_occurance); retp = g_hash_table_lookup(wordlist, expected_word); if (retp) { ret = *((guint*) retp); } else { ret = 0; } if (ret != (guint) expected_occurance) { fail = TRUE; fprintf(stderr, "Frequent words test case failed; word: '%s', expected=%d, got=%d, support=%d\n", expected_word, expected_occurance, ret, support); fprintf(stderr, "Input:\n%s\n", logs); fprintf(stderr, "Full results:\n"); g_hash_table_foreach(wordlist, _debug_print, NULL); } g_free(expected_item); } } // cleanup g_strfreev(expecteds); for (i = 0; i < logmessages->num_of_logs; ++i) log_msg_unref((LogMessage *) g_ptr_array_index(logmessages->logmessages, i)); g_ptr_array_free(logmessages->logmessages, TRUE); g_free(logmessages); }
/* read all the queued TPDUs */ CamReturn cam_tl_read_all (CamTL * tl, gboolean poll) { CamReturn ret = CAM_RETURN_OK; CamTLConnection *connection; GList *connections = NULL; GList *walk; gboolean done = FALSE; while (!done) { while (tl->expected_tpdus) { /* read the next TPDU from the connection */ ret = cam_tl_read_tpdu_next (tl, &connection); if (CAM_FAILED (ret)) { GST_ERROR ("error reading TPDU from module: %d", ret); goto out; } switch (tl->buffer[2]) { case TAG_C_T_C_REPLY: case TAG_D_T_C_REPLY: connection->empty_data = 0; ret = handle_control_tpdu (tl, connection); break; case TAG_DATA_MORE: case TAG_DATA_LAST: connection->empty_data = 0; ret = handle_data_tpdu (tl, connection); break; case TAG_SB: /* this is handled by tpdu_next */ break; } if (CAM_FAILED (ret)) goto out; } done = TRUE; connections = NULL; g_hash_table_foreach (tl->connections, foreach_connection_get, &connections); for (walk = connections; walk; walk = walk->next) { CamTLConnection *connection = CAM_TL_CONNECTION (walk->data); if (connection->has_data == TRUE && connection->empty_data < 10) { ret = cam_tl_connection_write_control_tpdu (connection, TAG_RCV); if (CAM_FAILED (ret)) { g_list_free (connections); goto out; } /* increment the empty_data counter. If we get data, this will be reset * to 0 */ connection->empty_data++; done = FALSE; } else if (poll) { ret = cam_tl_connection_poll (connection, FALSE); if (ret == CAM_RETURN_TRANSPORT_POLL) continue; if (CAM_FAILED (ret)) { g_list_free (connections); goto out; } done = FALSE; } } g_list_free (connections); } out: return ret; }
static void setup_theme_selector (GvcSoundThemeChooser *chooser) { GHashTable *hash; GtkListStore *store; GtkCellRenderer *renderer; const char * const *data_dirs; const char *data_dir; char *dir; guint i; /* Add the theme names and their display name to a hash table, * makes it easy to avoid duplicate themes */ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); data_dirs = g_get_system_data_dirs (); for (i = 0; data_dirs[i] != NULL; i++) { dir = g_build_filename (data_dirs[i], "sounds", NULL); sound_theme_in_dir (hash, dir); g_free (dir); } data_dir = g_get_user_data_dir (); dir = g_build_filename (data_dir, "sounds", NULL); sound_theme_in_dir (hash, dir); g_free (dir); /* If there isn't at least one theme, make everything * insensitive, LAME! */ if (g_hash_table_size (hash) == 0) { gtk_widget_set_sensitive (GTK_WIDGET (chooser), FALSE); g_warning ("Bad setup, install the freedesktop sound theme"); g_hash_table_destroy (hash); return; } /* Setup the tree model, 3 columns: * - internal theme name/directory * - display theme name * - the internal id for the parent theme, used for the custom theme */ store = gtk_list_store_new (THEME_NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); /* Add the themes to a combobox */ gtk_list_store_insert_with_values (store, NULL, G_MAXINT, THEME_DISPLAY_COL, _("No sounds"), THEME_IDENTIFIER_COL, "__no_sounds", THEME_PARENT_ID_COL, NULL, -1); g_hash_table_foreach (hash, (GHFunc) add_theme_to_store, store); g_hash_table_destroy (hash); /* Set the display */ gtk_combo_box_set_model (GTK_COMBO_BOX (chooser->priv->combo_box), GTK_TREE_MODEL (store)); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (chooser->priv->combo_box), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser->priv->combo_box), renderer, "text", THEME_DISPLAY_COL, NULL); g_signal_connect (G_OBJECT (chooser->priv->combo_box), "changed", G_CALLBACK (on_combobox_changed), chooser); }
gboolean write_smtp_reply (struct smtp_session *session) { gchar logbuf[1024], *new_subject; const gchar *old_subject; struct smtp_metric_callback_data cd; GMimeStream *stream; gint old_fd, sublen; /* Check metrics */ cd.session = session; cd.action = METRIC_ACTION_NOACTION; cd.res = NULL; cd.log_buf = logbuf; cd.log_offset = rspamd_snprintf (logbuf, sizeof (logbuf), "id: <%s>, qid: <%s>, ", session->task->message_id, session->task->queue_id); cd.log_size = sizeof (logbuf); if (session->task->user) { cd.log_offset += rspamd_snprintf (logbuf + cd.log_offset, sizeof (logbuf) - cd.log_offset, "user: %s, ", session->task->user); } g_hash_table_foreach (session->task->results, smtp_metric_callback, &cd); msg_info ("%s", logbuf); if (cd.action <= METRIC_ACTION_REJECT) { if (!rspamd_dispatcher_write (session->dispatcher, session->ctx->reject_message, 0, FALSE, TRUE)) { return FALSE; } if (!rspamd_dispatcher_write (session->dispatcher, CRLF, sizeof (CRLF) - 1, FALSE, TRUE)) { return FALSE; } rspamd_session_destroy (session->s); return FALSE; } else if (cd.action <= METRIC_ACTION_ADD_HEADER || cd.action <= METRIC_ACTION_REWRITE_SUBJECT) { old_fd = session->temp_fd; if (!make_smtp_tempfile (session)) { session->error = SMTP_ERROR_FILE; session->state = SMTP_STATE_CRITICAL_ERROR; rspamd_dispatcher_restore (session->dispatcher); if (!rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE)) { goto err; } rspamd_session_destroy (session->s); return FALSE; } if (cd.action <= METRIC_ACTION_REWRITE_SUBJECT) { /* XXX: add this action */ old_subject = g_mime_message_get_subject (session->task->message); if (old_subject != NULL) { sublen = strlen (old_subject) + sizeof (SPAM_SUBJECT); new_subject = rspamd_mempool_alloc (session->pool, sublen); rspamd_snprintf (new_subject, sublen, "%s%s", SPAM_SUBJECT, old_subject); } else { new_subject = SPAM_SUBJECT; } g_mime_message_set_subject (session->task->message, new_subject); } else if (cd.action <= METRIC_ACTION_ADD_HEADER) { #ifndef GMIME24 g_mime_message_add_header (session->task->message, "X-Spam", "true"); #else g_mime_object_append_header (GMIME_OBJECT ( session->task->message), "X-Spam", "true"); #endif } stream = g_mime_stream_fs_new (session->temp_fd); g_mime_stream_fs_set_owner (GMIME_STREAM_FS (stream), FALSE); close (old_fd); if (g_mime_object_write_to_stream (GMIME_OBJECT (session->task->message), stream) == -1) { msg_err ("cannot write MIME object to stream: %s", strerror (errno)); session->error = SMTP_ERROR_FILE; session->state = SMTP_STATE_CRITICAL_ERROR; rspamd_dispatcher_restore (session->dispatcher); if (!rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE)) { goto err; } rspamd_session_destroy (session->s); return FALSE; } g_object_unref (stream); } /* XXX: Add other actions */ return smtp_send_upstream_message (session); err: session->error = SMTP_ERROR_FILE; session->state = SMTP_STATE_CRITICAL_ERROR; if (!rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE)) { return FALSE; } rspamd_session_destroy (session->s); return FALSE; }
const char *gnt_key_lookup(const char *key) { gntkey k = {NULL, key}; g_hash_table_foreach(specials, get_key_name, &k); return k.name; }
/** * Correlate the image to any track within the TrackWaypoint layer */ static void trw_layer_geotag_process ( geotag_options_t *options ) { if ( !options->vtl || !IS_VIK_LAYER(options->vtl) ) return; if ( !options->image ) return; gboolean has_gps_exif = FALSE; gchar* datetime = a_geotag_get_exif_date_from_file ( options->image, &has_gps_exif ); if ( datetime ) { // If image already has gps info - don't attempt to change it. if ( !options->ov.overwrite_gps_exif && has_gps_exif ) { if ( options->ov.create_waypoints ) { // Create waypoint with file information gchar *name = NULL; VikWaypoint *wp = a_geotag_create_waypoint_from_file ( options->image, vik_trw_layer_get_coord_mode (options->vtl), &name ); if ( !name ) name = g_strdup ( a_file_basename ( options->image ) ); vik_trw_layer_filein_add_waypoint ( options->vtl, name, wp ); g_free ( name ); // Mark for redraw options->redraw = TRUE; } g_free ( datetime ); return; } options->PhotoTime = ConvertToUnixTime ( datetime, EXIF_DATE_FORMAT, options->ov.TimeZoneHours, options->ov.TimeZoneMins); g_free ( datetime ); // Apply any offset options->PhotoTime = options->PhotoTime + options->ov.time_offset; options->found_match = FALSE; if ( options->track ) { // Single specified track // NB Doesn't care about track name trw_layer_geotag_track ( NULL, options->track, options ); } else { // Try all tracks GHashTable *tracks = vik_trw_layer_get_tracks ( options->vtl ); if ( g_hash_table_size (tracks) > 0 ) { g_hash_table_foreach ( tracks, (GHFunc) trw_layer_geotag_track, options ); } } // Match found ? if ( options->found_match ) { if ( options->ov.create_waypoints ) { // Create waypoint with found position gchar *name = NULL; VikWaypoint *wp = a_geotag_create_waypoint_positioned ( options->image, options->coord, options->altitude, &name ); if ( !name ) name = g_strdup ( a_file_basename ( options->image ) ); vik_trw_layer_filein_add_waypoint ( options->vtl, name, wp ); g_free ( name ); // Mark for redraw options->redraw = TRUE; } // Write EXIF if specified if ( options->ov.write_exif ) { a_geotag_write_exif_gps ( options->image, options->coord, options->altitude, options->ov.no_change_mtime ); } } } }
static void dictionary_to_vorbis_comment (vorbis_comment * vc, GHashTable * dict) { vorbis_comment_clear(vc); g_hash_table_foreach (dict, add_tag_cb, vc); }
/** * gts_graph_bisection_bkl_refine: * @bg: a #GtsGraphBisection. * @mmax: the maximum number of unsuccessful successive moves. * @imbalance: the maximum relative imbalance allowed between the * weights of both halves of the partition. * * An implementation of the simplified boundary Kernighan-Lin * algorithm for graph bisection refinement as described in Karypis * and Kumar (1997). * * The algorithm stops if @mmax consecutive modes do not lead to a * decrease in the number of edges cut. This last @mmax moves are * undone. * * Returns: the decrease in the weight of the edges cut by the bisection. */ gdouble gts_graph_bisection_bkl_refine (GtsGraphBisection * bg, guint mmax, gfloat imbalance) { GtsEHeap * h1, * h2; GtsGNode * n; guint nm = 0, i; GtsGNode ** moves; gdouble bestcost = 0., totalcost = 0., best_balance; gboolean balanced = FALSE; g_return_val_if_fail (bg != NULL, 0.); g_return_val_if_fail (mmax > 0, 0.); g_return_val_if_fail (imbalance >= 0. && imbalance <= 1., 0.); h1 = gts_eheap_new ((GtsKeyFunc) node_move_cost1, bg); gts_eheap_freeze (h1); g_hash_table_foreach (bg->bg1, (GHFunc) build_bheap, h1); gts_eheap_thaw (h1); h2 = gts_eheap_new ((GtsKeyFunc) node_move_cost2, bg); gts_eheap_freeze (h2); g_hash_table_foreach (bg->bg2, (GHFunc) build_bheap, h2); gts_eheap_thaw (h2); moves = g_malloc (sizeof (GtsGNode *)*mmax); imbalance *= gts_graph_weight (bg->g); best_balance = fabs (gts_graph_weight (bg->g1) - gts_graph_weight (bg->g2)); if (best_balance <= imbalance) balanced = TRUE; do { GtsGraph * g1, * g2; GHashTable * bg1, * bg2; gdouble cost; if (gts_graph_weight (bg->g1) > gts_graph_weight (bg->g2)) { n = gts_eheap_remove_top (h1, &cost); g1 = bg->g1; g2 = bg->g2; bg1 = bg->bg1; bg2 = bg->bg2; } else { n = gts_eheap_remove_top (h2, &cost); g1 = bg->g2; g2 = bg->g1; bg1 = bg->bg2; bg2 = bg->bg1; } if (n) { gdouble balance; GTS_OBJECT (n)->reserved = n; gts_container_add (GTS_CONTAINER (g2), GTS_CONTAINEE (n)); gts_container_remove (GTS_CONTAINER (g1), GTS_CONTAINEE (n)); g_hash_table_remove (bg1, n); if (gts_gnode_degree (n, g1)) g_hash_table_insert (bg2, n, n); update_neighbors (n, bg, h1, h2); totalcost += cost; balance = fabs (gts_graph_weight (g1) - gts_graph_weight (g2)); if (!balanced && balance <= imbalance) { bestcost = totalcost; best_balance = balance; balanced = TRUE; nm = 0; } else if (totalcost < bestcost && (balance < best_balance || balance <= imbalance)) { bestcost = totalcost; best_balance = balance; nm = 0; } else if (totalcost == bestcost && balance < best_balance) { best_balance = balance; nm = 0; } else moves[nm++] = n; } } while (n && nm < mmax); gts_container_foreach (GTS_CONTAINER (bg->g), (GtsFunc) gts_object_reset_reserved, NULL); gts_eheap_destroy (h1); gts_eheap_destroy (h2); /* undo last nm moves */ for (i = 0; i < nm; i++) { GtsGNode * n = moves[i]; GtsGraph * g1, * g2; GHashTable * bg1, * bg2; if (gts_containee_is_contained (GTS_CONTAINEE (n), GTS_CONTAINER (bg->g1))) { g1 = bg->g1; g2 = bg->g2; bg1 = bg->bg1; bg2 = bg->bg2; } else { g1 = bg->g2; g2 = bg->g1; bg1 = bg->bg2; bg2 = bg->bg1; } gts_container_add (GTS_CONTAINER (g2), GTS_CONTAINEE (n)); gts_container_remove (GTS_CONTAINER (g1), GTS_CONTAINEE (n)); g_hash_table_remove (bg1, n); if (gts_gnode_degree (n, g1)) g_hash_table_insert (bg2, n, n); update_neighbors (n, bg, NULL, NULL); } g_free (moves); return bestcost; }
static gboolean check_action_definition(resource_t *rsc, node_t *active_node, xmlNode *xml_op, pe_working_set_t *data_set) { char *key = NULL; int interval = 0; const char *interval_s = NULL; gboolean did_change = FALSE; xmlNode *params_all = NULL; xmlNode *params_restart = NULL; GHashTable *local_rsc_params = NULL; char *digest_all_calc = NULL; const char *digest_all = NULL; const char *restart_list = NULL; const char *digest_restart = NULL; char *digest_restart_calc = NULL; action_t *action = NULL; const char *task = crm_element_value(xml_op, XML_LRM_ATTR_TASK); const char *op_version = crm_element_value(xml_op, XML_ATTR_CRM_VERSION); CRM_CHECK(active_node != NULL, return FALSE); if(safe_str_eq(task, RSC_STOP)) { return FALSE; } interval_s = crm_element_value(xml_op, XML_LRM_ATTR_INTERVAL); interval = crm_parse_int(interval_s, "0"); /* we need to reconstruct the key because of the way we used to construct resource IDs */ key = generate_op_key(rsc->id, task, interval); if(interval > 0) { xmlNode *op_match = NULL; crm_debug_2("Checking parameters for %s", key); op_match = find_rsc_op_entry(rsc, key); if(op_match == NULL && is_set(data_set->flags, pe_flag_stop_action_orphans)) { CancelXmlOp(rsc, xml_op, active_node, "orphan", data_set); crm_free(key); return TRUE; } else if(op_match == NULL) { crm_debug("Orphan action detected: %s on %s", key, active_node->details->uname); crm_free(key); return TRUE; } } action = custom_action(rsc, key, task, active_node, TRUE, FALSE, data_set); /* key is free'd by custom_action() */ local_rsc_params = g_hash_table_new_full( g_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str); get_rsc_attributes(local_rsc_params, rsc, active_node, data_set); params_all = create_xml_node(NULL, XML_TAG_PARAMS); g_hash_table_foreach(local_rsc_params, hash2field, params_all); g_hash_table_foreach(action->extra, hash2field, params_all); g_hash_table_foreach(rsc->parameters, hash2field, params_all); g_hash_table_foreach(action->meta, hash2metafield, params_all); filter_action_parameters(params_all, op_version); digest_all_calc = calculate_xml_digest(params_all, TRUE, FALSE); digest_all = crm_element_value(xml_op, XML_LRM_ATTR_OP_DIGEST); digest_restart = crm_element_value(xml_op, XML_LRM_ATTR_RESTART_DIGEST); restart_list = crm_element_value(xml_op, XML_LRM_ATTR_OP_RESTART); if(interval == 0 && safe_str_eq(task, RSC_STATUS)) { /* Reload based on the start action not a probe */ task = RSC_START; } if(digest_restart) { /* Changes that force a restart */ params_restart = copy_xml(params_all); if(restart_list) { filter_reload_parameters(params_restart, restart_list); } digest_restart_calc = calculate_xml_digest(params_restart, TRUE, FALSE); if(safe_str_neq(digest_restart_calc, digest_restart)) { did_change = TRUE; key = generate_op_key(rsc->id, task, interval); crm_log_xml_info(params_restart, "params:restart"); crm_info("Parameters to %s on %s changed: recorded %s vs. %s (restart:%s) %s", key, active_node->details->uname, crm_str(digest_restart), digest_restart_calc, op_version, crm_element_value(xml_op, XML_ATTR_TRANSITION_MAGIC)); custom_action(rsc, key, task, NULL, FALSE, TRUE, data_set); goto cleanup; } } if(safe_str_neq(digest_all_calc, digest_all)) { /* Changes that can potentially be handled by a reload */ did_change = TRUE; crm_log_xml_info(params_all, "params:reload"); key = generate_op_key(rsc->id, task, interval); crm_info("Parameters to %s on %s changed: recorded %s vs. %s (reload:%s) %s", key, active_node->details->uname, crm_str(digest_all), digest_all_calc, op_version, crm_element_value(xml_op, XML_ATTR_TRANSITION_MAGIC)); if(interval > 0) { action_t *op = NULL; #if 0 /* Always reload/restart the entire resource */ op = custom_action(rsc, start_key(rsc), RSC_START, NULL, FALSE, TRUE, data_set); update_action_flags(op, pe_action_allow_reload_conversion); #else /* Re-sending the recurring op is sufficient - the old one will be cancelled automatically */ op = custom_action(rsc, key, task, NULL, FALSE, TRUE, data_set); custom_action_order(rsc, start_key(rsc), NULL, NULL, NULL, op, pe_order_runnable_left, data_set); #endif } else if(digest_restart) { crm_debug_2("Reloading '%s' action for resource %s", task, rsc->id); /* Allow this resource to reload - unless something else causes a full restart */ set_bit(rsc->flags, pe_rsc_try_reload); /* Create these for now, it keeps the action IDs the same in the regression outputs */ custom_action(rsc, key, task, NULL, TRUE, TRUE, data_set); } else { crm_debug_2("Resource %s doesn't know how to reload", rsc->id); /* Re-send the start/demote/promote op * Recurring ops will be detected independantly */ custom_action(rsc, key, task, NULL, FALSE, TRUE, data_set); } } cleanup: free_xml(params_all); free_xml(params_restart); crm_free(digest_all_calc); crm_free(digest_restart_calc); g_hash_table_destroy(local_rsc_params); pe_free_action(action); return did_change; }
void sd_maincfg_print_to_log(void) { LOGDEBUG("MainCFG:"); g_hash_table_foreach(Cfg, _print, NULL); }
void gTree::addColumn() { g_hash_table_foreach(datakey,(GHFunc)gTree_addColumn,NULL); }
void remove_tid_data_by_fd(int fd) { pthread_mutex_lock(&mtx_tid); g_hash_table_foreach(threads_list, (GFunc) func_remove, (gpointer) &fd); pthread_mutex_unlock(&mtx_tid); }
/* A_DC_JOIN_OFFER_ONE */ void do_dc_join_offer_one(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data) { crm_node_t *member; ha_msg_input_t *welcome = NULL; const char *op = NULL; const char *join_to = NULL; if (msg_data->data) { welcome = fsa_typed_data(fsa_dt_ha_msg); } else { crm_info("An unknown node joined - (re-)offer to any unconfirmed nodes"); g_hash_table_foreach(crm_peer_cache, join_make_offer, &member); check_join_state(cur_state, __FUNCTION__); return; } if (welcome == NULL) { crm_err("Attempt to send welcome message without a message to reply to!"); return; } join_to = crm_element_value(welcome->msg, F_CRM_HOST_FROM); if (join_to == NULL) { crm_err("Attempt to send welcome message without a host to reply to!"); return; } member = crm_get_peer(0, join_to); op = crm_element_value(welcome->msg, F_CRM_TASK); if (join_to != NULL && (cur_state == S_INTEGRATION || cur_state == S_FINALIZE_JOIN)) { /* note: it _is_ possible that a node will have been * sick or starting up when the original offer was made. * however, it will either re-announce itself in due course * _or_ we can re-store the original offer on the client. */ crm_trace("(Re-)offering membership to %s...", join_to); } crm_info("join-%d: Processing %s request from %s in state %s", current_join_id, op, join_to, fsa_state2string(cur_state)); crm_update_peer_join(__FUNCTION__, member, crm_join_none); join_make_offer(NULL, member, NULL); /* always offer to the DC (ourselves) * this ensures the correct value for max_generation_from */ member = crm_get_peer(0, fsa_our_uname); join_make_offer(NULL, member, NULL); /* this was a genuine join request, cancel any existing * transition and invoke the PE */ abort_transition(INFINITY, tg_restart, "Node join", NULL); /* don't waste time by invoking the PE yet; */ crm_debug("Waiting on %d outstanding join acks for join-%d", crmd_join_phase_count(crm_join_welcomed), current_join_id); }
static void on_theme_changed( GtkIconTheme *icon_theme, gpointer user_data ) { g_hash_table_foreach( dir_hash, (GHFunc)reload_icons, NULL ); }
void load_workflow_config_data_from_user_storage(GHashTable *workflows) { g_hash_table_foreach(workflows, (GHFunc)load_events_foreach_workflow, NULL); }
static void smtp_metric_callback (gpointer key, gpointer value, gpointer ud) { struct smtp_metric_callback_data *cd = ud; struct metric_result *metric_res = value; enum rspamd_metric_action action = METRIC_ACTION_NOACTION; double ms = 0, rs = 0; gboolean is_spam = FALSE; struct rspamd_task *task; task = cd->session->task; /* XXX rewrite */ ms = metric_res->metric->actions[METRIC_ACTION_REJECT].score; rs = metric_res->metric->actions[METRIC_ACTION_REJECT].score; #if 0 if (!check_metric_settings (metric_res, &ms, &rs)) { ms = metric_res->metric->actions[METRIC_ACTION_REJECT].score; rs = metric_res->metric->actions[METRIC_ACTION_REJECT].score; } if (!check_metric_action_settings (task, metric_res, metric_res->score, &action)) { action = check_metric_action (metric_res->score, ms, metric_res->metric); } #endif if (metric_res->score >= ms) { is_spam = 1; } if (action < cd->action) { cd->action = action; cd->res = metric_res; } if (!RSPAMD_TASK_IS_SKIPPED (task)) { cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %c (%s): [%.2f/%.2f/%.2f] [", (gchar *)key, is_spam ? 'T' : 'F', rspamd_action_to_str (action), metric_res->score, ms, rs); } else { cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %c (default): [%.2f/%.2f/%.2f] [", (gchar *)key, 'S', metric_res->score, ms, rs); } g_hash_table_foreach (metric_res->symbols, smtp_metric_symbols_callback, cd); /* Remove last , from log buf */ if (cd->log_buf[cd->log_offset - 1] == ',') { cd->log_buf[--cd->log_offset] = '\0'; } cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %z, time: %s,", task->msg.len, rspamd_log_check_time (task->time_real, task->time_virtual, task->cfg->clock_res)); }
void save_data_from_worfklow_dialog(gpointer data, /* not needed */ const char *name) { g_hash_table_foreach((GHashTable *)data, (GHFunc)save_event_config_data_foreach, NULL); }
void testcase_find_clusters_slct(gchar* logs, guint support, gchar *expected) { int i,j; gchar **expecteds; loglinesType *logmessages; clusterfindData *find_data; GHashTable *clusters; Cluster *test_cluster; logmessages = testcase_get_logmessages(logs); clusters = ptz_find_clusters_slct(logmessages->logmessages, support, 0); expecteds = g_strsplit(expected, "|", 0); for (i = 0; expecteds[i]; ++i) { gchar **expected_item, **expected_lines_s; guint expected_lines[100]; guint num_of_expected_lines = 0; guint expected_support; expected_item = g_strsplit(expecteds[i], ":", 0); sscanf(expected_item[1], "%d", &expected_support); expected_lines_s = g_strsplit(expected_item[0], ",", 0); for (j = 0; expected_lines_s[j]; ++j) { sscanf(expected_lines_s[j], "%d", &expected_lines[j]); ++num_of_expected_lines; } find_data = g_new(clusterfindData, 1); find_data->lines = expected_lines; find_data->num_of_lines = num_of_expected_lines; find_data->logs = logmessages->logmessages; test_cluster = (Cluster *) g_hash_table_find(clusters, test_clusters_find, find_data); if (!test_cluster || test_cluster->loglines->len != expected_support) { if (!test_cluster) fprintf(stderr, "No cluster found;"); else fprintf(stderr, "Support value does not match;"); fprintf(stderr, " expected_cluster='%s', expected_support='%d'\n", expected_item[0], expected_support); fprintf(stderr, "Input:\n%s\n", logs); fprintf(stderr, "Got clusters:\n"); g_hash_table_foreach(clusters, _debug_print2, NULL); fail = TRUE; } g_free(find_data); // g_strfreev(expected_line_strings); // FIXME: this segfaults, so let's leak it instead :) g_strfreev(expected_item); g_strfreev(expected_lines_s); } g_hash_table_unref(clusters); for (i = 0; i < logmessages->num_of_logs; ++i) log_msg_unref((LogMessage *) g_ptr_array_index(logmessages->logmessages, i)); g_ptr_array_free(logmessages->logmessages, TRUE); g_free(logmessages); g_strfreev(expecteds); }
static void on_list_files_done (GObject *object, GAsyncResult *res, gpointer user_data) { ListServicesData *data = user_data; GError *error = NULL; data->files = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error); if (error) { end_invocation_take_gerror (data->invocation, error); g_variant_unref (data->units); g_free (data); return; } data->result = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, listed_service_free); gs_free_variant_iter GVariantIter *unit_iter = NULL; const gchar *name, *description, *load_state, *active_state, *sub_state, *file_state; g_variant_get (data->units, "(a*)", &unit_iter); while (g_variant_iter_next (unit_iter, "(&s&s&s&s&s&s&ou&s&o)", &name, &description, &load_state, &active_state, &sub_state, NULL, // follow unit NULL, // object path NULL, // job id NULL, // job type NULL)) // job object path { if (!g_hash_table_lookup (data->result, name)) { ListedService *s = listed_service_new (); s->name = name; s->description = description; s->load_state = load_state; s->active_state = active_state; s->sub_state = sub_state; s->file_state = ""; g_hash_table_insert (data->result, (void *)name, s); } } gs_free_variant_iter GVariantIter *file_iter = NULL; g_variant_get (data->files, "(a*)", &file_iter); while (g_variant_iter_next (file_iter, "(&s&s)", &name, &file_state)) { gchar *base = g_path_get_basename (name); ListedService *s = g_hash_table_lookup (data->result, base); if (s) s->file_state = file_state; else { ListedService *s = listed_service_new (); s->name = base; s->description = get_service_description (name); s->load_state = ""; s->active_state = ""; s->sub_state = ""; s->file_state = file_state; s->needs_free = TRUE; g_hash_table_insert (data->result, (void *)base, s); } } GVariantBuilder bob; g_variant_builder_init (&bob, G_VARIANT_TYPE("a(ssssss)")); g_hash_table_foreach (data->result, add_listed_service_to_builder, &bob); cockpit_services_complete_list_services (COCKPIT_SERVICES (data->services), data->invocation, g_variant_builder_end (&bob)); g_variant_unref (data->units); g_variant_unref (data->files); g_hash_table_destroy (data->result); g_free (data); }
static GdaLdapClass * worker_gdaprov_ldap_get_class_info (WorkerLdapClassInfoData *data, GError **error) { GdaLdapClass *retval = NULL; /* initialize known classes */ data->cdata->classes_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) ldap_class_free); LDAPMessage *msg, *entry; int res; gchar *subschema = NULL; char *subschemasubentry[] = {"subschemaSubentry", NULL}; char *schema_attrs[] = {"objectClasses", NULL}; /* look for subschema */ if (! gda_ldap_ensure_bound (data->cnc, NULL)) return NULL; gda_ldap_execution_slowdown (data->cnc); res = ldap_search_ext_s (data->cdata->handle, "", LDAP_SCOPE_BASE, "(objectclass=*)", subschemasubentry, 0, NULL, NULL, NULL, 0, &msg); if (res != LDAP_SUCCESS) { gda_ldap_may_unbind (data->cnc); return NULL; } if ((entry = ldap_first_entry (data->cdata->handle, msg))) { char *attr; BerElement *ber; if ((attr = ldap_first_attribute (data->cdata->handle, entry, &ber))) { BerValue **bvals; if ((bvals = ldap_get_values_len (data->cdata->handle, entry, attr))) { subschema = g_strdup (bvals[0]->bv_val); ldap_value_free_len (bvals); } ldap_memfree (attr); } if (ber) ber_free (ber, 0); } ldap_msgfree (msg); if (! subschema) { gda_ldap_may_unbind (data->cnc); return NULL; } /* look for attributeTypes */ gda_ldap_execution_slowdown (data->cnc); res = ldap_search_ext_s (data->cdata->handle, subschema, LDAP_SCOPE_BASE, "(objectclass=*)", schema_attrs, 0, NULL, NULL, NULL, 0, &msg); g_free (subschema); if (res != LDAP_SUCCESS) { gda_ldap_may_unbind (data->cnc); return NULL; } GHashTable *h_refs; h_refs = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_strfreev); for (entry = ldap_first_entry (data->cdata->handle, msg); entry; entry = ldap_next_entry (data->cdata->handle, msg)) { char *attr; BerElement *ber; for (attr = ldap_first_attribute (data->cdata->handle, msg, &ber); attr; attr = ldap_next_attribute (data->cdata->handle, msg, ber)) { if (strcasecmp(attr, "objectClasses")) { ldap_memfree (attr); continue; } BerValue **bvals; bvals = ldap_get_values_len (data->cdata->handle, entry, attr); if (bvals) { gint i; for (i = 0; bvals[i]; i++) { LDAPObjectClass *oc; const char *errp; int retcode; oc = ldap_str2objectclass (bvals[i]->bv_val, &retcode, &errp, LDAP_SCHEMA_ALLOW_ALL); if (oc && oc->oc_oid && oc->oc_names && oc->oc_names[0]) { GdaLdapClass *lcl; guint k; lcl = g_new0 (GdaLdapClass, 1); lcl->oid = g_strdup (oc->oc_oid); //#define CLASS_DEBUG #ifdef CLASS_DEBUG g_print ("FOUND CLASS\n"); #endif lcl->names = make_array_from_strv (oc->oc_names, &(lcl->nb_names)); for (k = 0; lcl->names[k]; k++) { #ifdef CLASS_DEBUG g_print (" oc_names[%d] = %s\n", k, lcl->names[k]); #endif g_hash_table_insert (data->cdata->classes_hash, lcl->names[k], lcl); } if (oc->oc_desc) { #ifdef CLASS_DEBUG g_print (" oc_desc = %s\n", oc->oc_desc); #endif lcl->description = g_strdup (oc->oc_desc); } #ifdef CLASS_DEBUG g_print (" oc_kind = %d\n", oc->oc_kind); #endif switch (oc->oc_kind) { case 0: lcl->kind = GDA_LDAP_CLASS_KIND_ABSTRACT; break; case 1: lcl->kind = GDA_LDAP_CLASS_KIND_STRUTURAL; break; case 2: lcl->kind = GDA_LDAP_CLASS_KIND_AUXILIARY; break; default: lcl->kind = GDA_LDAP_CLASS_KIND_UNKNOWN; break; } lcl->obsolete = oc->oc_obsolete; #ifdef CLASS_DEBUG g_print (" oc_obsolete = %d\n", oc->oc_obsolete); #endif gchar **refs; refs = make_array_from_strv (oc->oc_sup_oids, NULL); if (refs) g_hash_table_insert (h_refs, lcl, refs); else data->cdata->top_classes = g_slist_insert_sorted (data->cdata->top_classes, lcl, (GCompareFunc) classes_sort); #ifdef CLASS_DEBUG for (k = 0; oc->oc_sup_oids && oc->oc_sup_oids[k]; k++) g_print (" oc_sup_oids[0] = %s\n", oc->oc_sup_oids[k]); #endif lcl->req_attributes = make_array_from_strv (oc->oc_at_oids_must, &(lcl->nb_req_attributes)); #ifdef CLASS_DEBUG for (k = 0; oc->oc_at_oids_must && oc->oc_at_oids_must[k]; k++) g_print (" oc_at_oids_must[0] = %s\n", oc->oc_at_oids_must[k]); #endif lcl->opt_attributes = make_array_from_strv (oc->oc_at_oids_may, &(lcl->nb_opt_attributes)); #ifdef CLASS_DEBUG for (k = 0; oc->oc_at_oids_may && oc->oc_at_oids_may[k]; k++) g_print (" oc_at_oids_may[0] = %s\n", oc->oc_at_oids_may[k]); #endif } if (oc) ldap_memfree (oc); } ldap_value_free_len (bvals); } ldap_memfree (attr); } if (ber) ber_free (ber, 0); } ldap_msgfree (msg); /* create hierarchy */ g_hash_table_foreach (h_refs, (GHFunc) classes_h_func, data->cdata); g_hash_table_destroy (h_refs); retval = g_hash_table_lookup (data->cdata->classes_hash, data->classname); gda_ldap_may_unbind (data->cnc); return retval; }
static void generate_report_frequent (int uid, const char *seat, const char *session_type) { GHashTable *counts; GList *l; GList *user_counts; /* FIXME: we can probably do this more efficiently */ counts = g_hash_table_new (NULL, NULL); for (l = g_list_first (all_events); l != NULL; l = l->next) { CkLogEvent *event; CkLogSeatSessionAddedEvent *e; guint count; gpointer val; event = l->data; if (event->type != CK_LOG_EVENT_SEAT_SESSION_ADDED) { continue; } e = (CkLogSeatSessionAddedEvent *)event; if (uid >= 0 && e->session_unix_user != uid) { continue; } if (seat != NULL && e->seat_id != NULL && strcmp (e->seat_id, seat) != 0) { continue; } if (session_type != NULL && e->session_type != NULL && strcmp (e->session_type, session_type) != 0) { continue; } val = g_hash_table_lookup (counts, GINT_TO_POINTER (e->session_unix_user)); if (val != NULL) { count = GPOINTER_TO_INT (val); } else { count = 0; } g_hash_table_insert (counts, GINT_TO_POINTER (e->session_unix_user), GUINT_TO_POINTER (count + 1)); } user_counts = NULL; g_hash_table_foreach (counts, (GHFunc)listify_counts, &user_counts); g_hash_table_destroy (counts); if (user_counts == NULL) { return; } user_counts = g_list_sort (user_counts, (GCompareFunc)counts_compare); while (user_counts != NULL) { CountData *data; char *username; data = user_counts->data; username = get_user_name_for_uid (data->uid); g_print ("%-"USERNAME_MAX"s %u\n", username, data->count); g_free (data); user_counts = g_list_delete_link (user_counts, user_counts); g_free (username); } g_list_free (user_counts); }
GHashTable *gaym_properties_new(const gchar * str) { gchar *tmpstr = NULL; gchar **tmparr = NULL; gchar **proparr = NULL; int i = 0; GHashTable *props = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); /** * convert ascii-escaped to native */ tmpstr = ascii2native(str); /** * strip out continuation character followed by newline */ // tmparr = g_strsplit(tmpstr, "\\\n", -1); // g_free(tmpstr); // tmpstr = g_strjoinv(NULL, tmparr); // g_strfreev(tmparr); /** * Since the properties get stripped of spaces later, * just replace \\\n with <space>\n in-place, for speed. * */ char *pos = tmpstr; while ((pos = strstr(pos, "\\\n"))) { *pos = ' '; *(++pos) = ' '; } /** * We're getting close. Now we need an array as follows: * * property=value * property=value * ... */ tmparr = g_strsplit(tmpstr, "\n", -1); for (i = 0; tmparr[i] != NULL; i++) { /** * do nothing if this is a blank line */ if (strlen(g_strstrip(tmparr[i])) == 0) { continue; } /** * do nothing if this is a comment line */ if (tmparr[i][0] == '#') { continue; } /** * this must be a property=value string, so we make * it into a 2-element array: * * property * value * * but we won't store it in our hash table unless both * have real values after stripping whitespace */ proparr = g_strsplit(tmparr[i], "=", 2); if (proparr[0] && strlen(g_strstrip(proparr[0])) > 0 && proparr[1] && strlen(g_strstrip(proparr[1])) > 0) { // gaim_debug_misc("properties","Inserted // %s=%s\n",proparr[0],proparr[1]); g_hash_table_insert(props, g_strdup(proparr[0]), g_strdup(proparr[1])); } g_strfreev(proparr); } g_strfreev(tmparr); g_hash_table_foreach(props, replace_dollar_n, NULL); return props; }
int xpidl_process_idl(char *filename, IncludePathEntry *include_path, char *file_basename, char* package, ModeData *mode) { char *tmp, *outname, *real_outname = NULL; IDL_tree top; TreeState state; int rv; input_callback_state callback_state; gboolean ok = TRUE; backend *emitter; memset(&state, 0, sizeof(state)); callback_state.input_stack = NULL; callback_state.base_includes = NULL; callback_state.include_path = include_path; callback_state.already_included = g_hash_table_new(g_str_hash, g_str_equal); if (!callback_state.already_included) { fprintf(stderr, "failed to create hashtable. out of memory?\n"); return 0; } state.basename = xpidl_strdup(filename); if (package) state.package = xpidl_strdup(package); /* if basename has an .extension, truncate it. */ tmp = strrchr(state.basename, '.'); if (tmp) *tmp = '\0'; if (!file_basename) outname = xpidl_strdup(state.basename); else outname = xpidl_strdup(file_basename); /* so we don't include it again! */ g_hash_table_insert(callback_state.already_included, xpidl_strdup(filename), (void *)TRUE); parsed_empty_file = FALSE; rv = IDL_parse_filename_with_input(filename, input_callback, &callback_state, msg_callback, &top, &state.ns, IDLF_IGNORE_FORWARDS | IDLF_XPIDL, enable_warnings ? IDL_WARNING1 : IDL_ERROR); if (parsed_empty_file) { /* * If we've detected (via hack in msg_callback) that libIDL returned * failure because it found a file with no IDL, set the parse tree to * null and proceed. Allowing this is useful to permit .idl files that * collect #includes. */ top = NULL; state.ns = NULL; } else if (rv != IDL_SUCCESS) { if (rv == -1) { g_warning("Parse of %s failed: %s", filename, g_strerror(errno)); } else { g_warning("Parse of %s failed", filename); } return 0; } state.basename = xpidl_strdup(filename); tmp = strrchr(state.basename, '.'); if (tmp) *tmp = '\0'; /* so xpidl_header.c can use it to generate a list of #include directives */ state.base_includes = callback_state.base_includes; emitter = mode->factory(); state.dispatch = emitter->dispatch_table; if (strcmp(outname, "-")) { const char *fopen_mode; const char *out_basename; /* explicit_output_filename can't be true without a filename */ if (explicit_output_filename) { real_outname = g_strdup(outname); } else { /* *This combination seems a little strange, what about OS/2? * Assume it's some build issue */ #if defined(XP_UNIX) || defined(XP_WIN) if (!file_basename) { out_basename = xpidl_basename(outname); } else { out_basename = outname; } #else out_basename = outname; #endif real_outname = g_strdup_printf("%s.%s", out_basename, mode->suffix); } /* don't create/open file here for Java */ if (strcmp(mode->mode, "java") == 0) { state.filename = real_outname; } else { /* Use binary write for typelib mode */ fopen_mode = (strcmp(mode->mode, "typelib")) ? "w" : "wb"; state.file = fopen(real_outname, fopen_mode); if (!state.file) { perror("error opening output file"); return 0; } } } else { state.file = stdout; } state.tree = top; if (emitter->emit_prolog) emitter->emit_prolog(&state); if (state.tree) /* Only if we have a tree to process. */ ok = xpidl_process_node(&state); if (emitter->emit_epilog) emitter->emit_epilog(&state); if (strcmp(mode->mode, "java") != 0) { if (state.file != stdout) fclose(state.file); } free(state.basename); free(state.package); free(outname); g_hash_table_foreach(callback_state.already_included, free_ghash_key, NULL); g_hash_table_destroy(callback_state.already_included); g_slist_foreach(callback_state.base_includes, free_gslist_data, NULL); if (state.ns) IDL_ns_free(state.ns); if (top) IDL_tree_free(top); if (real_outname != NULL) { /* * Delete partial output file on failure. (Mac does this in the plugin * driver code, if the compiler returns failure.) */ #if defined(XP_UNIX) || defined(XP_WIN) if (!ok) unlink(real_outname); #endif g_free(real_outname); } return ok; }
gboolean lookuptable_change(GtkCellRenderer *renderer, gchar *path, gchar * new_text, gpointer data) { GtkListStore *store = NULL; GtkTreeIter iter; GtkTreeModel *model = data; ConfigFile *cfgfile = NULL; gchar * int_name = NULL; gchar * old = NULL; gchar * new_name = NULL; gchar ** vector = NULL; gboolean restart_tickler = FALSE; extern gint realtime_id; extern GHashTable *lookuptables; extern GAsyncQueue *io_data_queue; extern Firmware_Details *firmware; gint count = 0; LookupTable *lookuptable = NULL; /* Get combo box model so we can set the combo to this new value */ g_object_get(G_OBJECT(renderer),"model",&store,NULL); gtk_tree_model_get_iter_from_string(model,&iter,path); gtk_tree_model_get(model,&iter,INTERNAL_NAME_COL,&int_name,FILENAME_COL,&old,-1); if (g_strcasecmp(old,new_text) == 0) /* If no change, return */ return TRUE; if (g_strcasecmp(new_text,"Personal") == 0) return TRUE; if (g_strcasecmp(new_text,"System") == 0) return TRUE; if (realtime_id) { restart_tickler = TRUE; stop_tickler(RTV_TICKLER); count = 0; while ((g_async_queue_length(io_data_queue) > 0) && (count < 30)) { dbg_func(CRITICAL,g_strdup_printf(__FILE__": LEAVE() draining I/O Queue, current length %i\n",g_async_queue_length(io_data_queue))); while (gtk_events_pending()) gtk_main_iteration(); count++; } } lookuptable = (LookupTable *)g_hash_table_lookup(lookuptables,int_name); if (!lookuptable) printf(_("No lookuptable found! expect a crash!!\n")); g_free(lookuptable->array); /* Free the old one */ g_free(lookuptable->filename); /* Free the old one */ g_free(lookuptable); /* Free the old one */ get_table(int_name,new_text,NULL); /* Load the new one in it's place */ gtk_list_store_set(GTK_LIST_STORE(model),&iter, FILENAME_COL, new_text,-1); if (restart_tickler) start_tickler(RTV_TICKLER); cfgfile = cfg_open_file(firmware->profile_filename); if (!cfgfile) return FALSE; g_hash_table_foreach(lookuptables,update_lt_config,cfgfile); if (g_strrstr(firmware->profile_filename,".MegaTunix")) cfg_write_file(cfgfile, firmware->profile_filename); else { vector = g_strsplit(firmware->profile_filename,PSEP,-1); new_name = g_build_filename(HOME(),".MegaTunix",INTERROGATOR_DATA_DIR,"Profiles",vector[g_strv_length(vector)-1],NULL); g_strfreev(vector); cfg_write_file(cfgfile, new_name); g_free(firmware->profile_filename); firmware->profile_filename=g_strdup(new_name); g_free(new_name); } cfg_free(cfgfile); /*printf("internal name %s, old table %s, new table %s\n",int_name,old,new_text);*/ return TRUE; }
void cbox_document_dump(struct cbox_document *document) { g_hash_table_foreach(document->classes_per_document, iter_func, document); g_hash_table_foreach(document->services_per_document, iter_func2, document); }
static GtkWidget * create_column_properties (TablePreferences *tpref) { GtkWidget *combo, *label, *grid; GtkCellRenderer *renderer; grid = gtk_grid_new (); gtk_grid_set_row_spacing (GTK_GRID (grid), 5); gtk_grid_set_column_spacing (GTK_GRID (grid), 5); /* plugins combo */ tpref->priv->plugins_model = GTK_TREE_MODEL (gtk_list_store_new (PL_NUM_COLUMNS, G_TYPE_POINTER, G_TYPE_STRING)); ForeachData data; data.type = 0; data.store = GTK_LIST_STORE (tpref->priv->plugins_model); g_hash_table_foreach (gdaui_plugins_hash, (GHFunc) plugin_hash_foreach_func, &data); combo = gtk_combo_box_new_with_model (tpref->priv->plugins_model); gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0); tpref->priv->plugins_combo = combo; renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", PL_COLUMN_DESCR, NULL); g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (plugins_combo_changed_cb), tpref); gtk_grid_attach (GTK_GRID (grid), combo, 1, 0, 1, 1); label = gtk_label_new (_("Data entry type:")); gtk_widget_set_tooltip_text (label, _("Defines how data for the selected column\n" "will be displayed in forms. Leave 'Default' to have\n" "the default display")); gtk_misc_set_alignment (GTK_MISC (label), 0., -1); gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); /* plugin options */ tpref->priv->options_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_grid_attach (GTK_GRID (grid), tpref->priv->options_vbox, 1, 1, 1, 1); tpref->priv->options_none = gtk_label_new (_("none")); gtk_misc_set_alignment (GTK_MISC (tpref->priv->options_none), 0., -1); gtk_box_pack_start (GTK_BOX (tpref->priv->options_vbox), tpref->priv->options_none, FALSE, FALSE, 0); label = gtk_label_new (_("Options:")); gtk_misc_set_alignment (GTK_MISC (label), 0., -1); gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1); /* plugin preview */ tpref->priv->preview_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_grid_attach (GTK_GRID (grid), tpref->priv->preview_vbox, 1, 2, 1, 1); tpref->priv->preview_none = gtk_label_new (_("none")); gtk_misc_set_alignment (GTK_MISC (tpref->priv->preview_none), 0., -1); gtk_box_pack_start (GTK_BOX (tpref->priv->preview_vbox), tpref->priv->preview_none, FALSE, FALSE, 0); label = gtk_label_new (_("Preview:")); gtk_widget_set_tooltip_text (label, _("Free form to test the configured\n" "data entry")); gtk_misc_set_alignment (GTK_MISC (label), 0., -1); gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1); gtk_widget_show_all (grid); return grid; }
static gboolean gxi_parse_file (GncXmlImportData *data) { QofSession *session = NULL; QofBook *book; QofBackend *backend; QofBackendError io_err = ERR_BACKEND_NO_ERR; gchar *message = NULL; gboolean success = FALSE; if (data->n_unassigned || data->n_impossible) goto cleanup_parse_file; /* fill subst hash table with byte sequence substitutions */ data->subst = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); g_hash_table_foreach (data->ambiguous_ht, (GHFunc) subst_insert_amb, data); g_hash_table_foreach (data->unique, (GHFunc) subst_insert_unique, data); if (!data->subst) goto cleanup_parse_file; /* create a temporary QofSession */ gxi_session_destroy (data); session = qof_session_new (); data->session = session; qof_session_begin (session, data->filename, TRUE, FALSE, FALSE); io_err = qof_session_get_error (session); if (io_err != ERR_BACKEND_NO_ERR) { message = _("The file could not be reopened."); goto cleanup_parse_file; } xaccLogDisable (); gxi_update_progress_bar (_("Reading file..."), 0.0); qof_session_load (session, gxi_update_progress_bar); gxi_update_progress_bar (NULL, -1.0); xaccLogEnable (); io_err = qof_session_get_error (session); if (io_err == ERR_BACKEND_NO_ERR) { /* loaded sucessfully now. strange, but ok */ success = TRUE; goto cleanup_parse_file; } else if (io_err != ERR_FILEIO_NO_ENCODING) { /* another error, cannot handle this here */ message = _("The file could not be reopened."); goto cleanup_parse_file; } qof_session_pop_error (session); book = qof_session_get_book (session); backend = qof_book_get_backend (book); gxi_update_progress_bar (_("Parsing file..."), 0.0); success = gnc_xml2_parse_with_subst (backend, book, data->subst); gxi_update_progress_bar (NULL, -1.0); if (success) data->session = session; else message = _("There was an error parsing the file."); cleanup_parse_file: if (data->subst) { g_hash_table_destroy (data->subst); data->subst = NULL; } if (message) { gnc_error_dialog (data->assistant, "%s", message); } if (!success) gxi_session_destroy (data); return success; }