static gint OssoDbusCallback(const gchar *interface, const gchar *method, GArray *arguments, gpointer data, osso_rpc_t *retval) { retval->type = DBUS_TYPE_INVALID; // The "top_application" method just wants us to focus the top-most window. if (!strcmp("top_application", method)) { nsCOMPtr<nsIDOMWindow> window; GetMostRecentWindow(NS_LITERAL_STRING("").get(), getter_AddRefs(window)); if (window) window->Focus(); return OSSO_OK; } if (!strcmp("quit", method)) { nsCOMPtr<nsIAppStartup> appService = do_GetService("@mozilla.org/toolkit/app-startup;1"); if (appService) appService->Quit(nsIAppStartup::eForceQuit); return OSSO_OK; } // Other methods can have arguments, which we convert and send to commandline // handlers. nsCOMPtr<nsICommandLineRunner> cmdLine (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); nsCOMPtr<nsIFile> workingDir; NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(workingDir)); char** argv = 0; int argc = 0; // Not all DBus methods pass arguments if (arguments && arguments->len > 0) { // Create argument list with a dummy argv[0] argc = arguments->len + 1; argv = (char**)calloc(1, argc * sizeof(*argv)); // Start at 1 to skip the dummy argv[0] for (int i = 1; i < argc; i++) { osso_rpc_t* entry = (osso_rpc_t*)&g_array_index(arguments, osso_rpc_t, i - 1); if (entry->type != DBUS_TYPE_STRING) continue; argv[i] = strdup(entry->value.s); } } cmdLine->Init(argc, argv, workingDir, nsICommandLine::STATE_REMOTE_AUTO); // Cleanup argument list while (argc) { free(argv[--argc]); } free(argv); cmdLine->Run(); return OSSO_OK; }
void xml_loadsave_users_write(const gchar *prefix) { #ifdef DEBUG printf("xml_loadsave_users_write\n"); #endif gint i, j, k; gchar buf[SMALL]; FILE *fil = NULL; for(i=0;i<users->len;i++) { sprintf(buf, "%s___user_%02d_options", prefix, i); file_save_opt_file(buf, &usr(i).options); sprintf(buf, "%s___user_%02d_live_game.xml", prefix, i); xml_loadsave_live_game_write(buf, &usr(i).live_game); } sprintf(buf, "%s___users.xml", prefix); file_my_fopen(buf, "w", &fil, TRUE); fprintf(fil, "<_%d>\n", TAG_USERS); for(i=0;i<users->len;i++) { fprintf(fil, "<_%d>\n", TAG_USER); xml_write_string(fil, usr(i).name, TAG_NAME, I1); xml_write_int(fil, usr(i).team_id, TAG_TEAM_ID, I1); xml_write_int(fil, usr(i).money, TAG_USER_MONEY, I1); xml_write_int(fil, usr(i).debt, TAG_USER_DEBT, I1); xml_write_float(fil, usr(i).debt_interest, TAG_USER_DEBT_INTEREST, I1); xml_write_int(fil, usr(i).alr_start_week, TAG_USER_ALR_START_WEEK, I1); xml_write_int(fil, usr(i).alr_weekly_installment, TAG_USER_ALR_WEEKLY_INSTALLMENT, I1); xml_write_int(fil, usr(i).scout, TAG_USER_SCOUT, I1); xml_write_int(fil, usr(i).physio, TAG_USER_PHYSIO, I1); strcpy(buf, usr(i).sponsor.name->str); misc_string_replace_token(buf, "&", "AND"); xml_write_string(fil, buf, TAG_USER_SPONSOR_NAME, I1); xml_write_int(fil, usr(i).sponsor.contract, TAG_USER_SPONSOR_CONTRACT, I1); xml_write_int(fil, usr(i).sponsor.benefit, TAG_USER_SPONSOR_BENEFIT, I1); xml_user_write_history(fil, usr(i).history); xml_user_write_events(fil, usr(i).events); xml_user_write_bets(fil, usr(i).bets); for(j=0;j<COUNT_USER_END;j++) xml_write_int(fil, usr(i).counters[j], TAG_USER_COUNTER, I1); for(j=0;j<2;j++) { fprintf(fil, "%s<_%d>\n", I1, TAG_USER_MONEY_INS); for(k=0;k<MON_IN_END;k++) xml_write_int(fil, usr(i).money_in[j][k], TAG_USER_MONEY_IN, I2); fprintf(fil, "%s</_%d>\n", I1, TAG_USER_MONEY_INS); } for(j=0;j<2;j++) { fprintf(fil, "%s<_%d>\n", I1, TAG_USER_MONEY_OUTS); for(k=0;k<MON_OUT_END;k++) xml_write_int(fil, usr(i).money_out[j][k], TAG_USER_MONEY_OUT, I2); fprintf(fil, "%s</_%d>\n", I1, TAG_USER_MONEY_OUTS); } xml_write_int(fil, usr(i).youth_academy.coach, TAG_USER_YA_COACH, I1); xml_write_int(fil, usr(i).youth_academy.percentage, TAG_USER_YA_PERCENTAGE, I1); xml_write_float(fil, usr(i).youth_academy.av_coach, TAG_USER_YA_AV_COACH, I1); xml_write_float(fil, usr(i).youth_academy.av_percentage, TAG_USER_YA_AV_PERCENTAGE, I1); xml_write_float(fil, usr(i).youth_academy.counter_youth, TAG_USER_YA_COUNTER, I1); xml_write_int(fil, usr(i).youth_academy.pos_pref, TAG_USER_YA_PREFERENCE, I1); for (j=0; j < usr(i).default_team->len; j++){ xml_write_int(fil, g_array_index(usr(i).default_team, gint, j), TAG_USER_DEFAULT_TEAM, I1); } xml_write_int(fil, usr(i).default_structure, TAG_USER_DEFAULT_STRUCTURE, I1); xml_write_int(fil, usr(i).default_style, TAG_USER_DEFAULT_STYLE, I1); xml_write_int(fil, usr(i).default_boost, TAG_USER_DEFAULT_BOOST, I1); xml_loadsave_players_write(fil, usr(i).youth_academy.players); fprintf(fil, "</_%d>\n", TAG_USER); } fprintf(fil, "</_%d>\n", TAG_USERS); fclose(fil); }
static void gtk_css_image_radial_draw (GtkCssImage *image, cairo_t *cr, double width, double height) { GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image); cairo_pattern_t *pattern; cairo_matrix_t matrix; double x, y; double radius, yscale; double start, end; double r1, r2, r3, r4, r; double offset; int i, last; x = _gtk_css_position_value_get_x (radial->position, width); y = _gtk_css_position_value_get_y (radial->position, height); if (radial->circle) { switch (radial->size) { case GTK_CSS_EXPLICIT_SIZE: radius = _gtk_css_number_value_get (radial->sizes[0], width); break; case GTK_CSS_CLOSEST_SIDE: radius = MIN (MIN (x, width - x), MIN (y, height - y)); break; case GTK_CSS_FARTHEST_SIDE: radius = MAX (MAX (x, width - x), MAX (y, height - y)); break; case GTK_CSS_CLOSEST_CORNER: case GTK_CSS_FARTHEST_CORNER: r1 = x*x + y*y; r2 = x*x + (height - y)*(height - y); r3 = (width - x)*(width - x) + y*y; r4 = (width - x)*(width - x) + (height - y)*(height - y); if (radial->size == GTK_CSS_CLOSEST_CORNER) r = MIN ( MIN (r1, r2), MIN (r3, r4)); else r = MAX ( MAX (r1, r2), MAX (r3, r4)); radius = sqrt (r); break; default: g_assert_not_reached (); } radius = MAX (1.0, radius); yscale = 1.0; } else { double hradius, vradius; switch (radial->size) { case GTK_CSS_EXPLICIT_SIZE: hradius = _gtk_css_number_value_get (radial->sizes[0], width); vradius = _gtk_css_number_value_get (radial->sizes[1], height); break; case GTK_CSS_CLOSEST_SIDE: hradius = MIN (x, width - x); vradius = MIN (y, height - y); break; case GTK_CSS_FARTHEST_SIDE: hradius = MAX (x, width - x); vradius = MAX (y, height - y); break; case GTK_CSS_CLOSEST_CORNER: hradius = M_SQRT2 * MIN (x, width - x); vradius = M_SQRT2 * MIN (y, height - y); break; case GTK_CSS_FARTHEST_CORNER: hradius = M_SQRT2 * MAX (x, width - x); vradius = M_SQRT2 * MAX (y, height - y); break; default: g_assert_not_reached (); } hradius = MAX (1.0, hradius); vradius = MAX (1.0, vradius); radius = hradius; yscale = vradius / hradius; } gtk_css_image_radial_get_start_end (radial, radius, &start, &end); pattern = cairo_pattern_create_radial (0, 0, 0, 0, 0, radius); if (yscale != 1.0) { cairo_matrix_init_scale (&matrix, 1.0, 1.0 / yscale); cairo_pattern_set_matrix (pattern, &matrix); } if (radial->repeating) cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); else cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD); offset = start; last = -1; for (i = 0; i < radial->stops->len; i++) { GtkCssImageRadialColorStop *stop; double pos, step; stop = &g_array_index (radial->stops, GtkCssImageRadialColorStop, i); if (stop->offset == NULL) { if (i == 0) pos = 0.0; else if (i + 1 == radial->stops->len) pos = 1.0; else continue; } else pos = _gtk_css_number_value_get (stop->offset, radius) / radius; pos = MAX (pos, 0); step = pos / (i - last); for (last = last + 1; last <= i; last++) { const GdkRGBA *rgba; stop = &g_array_index (radial->stops, GtkCssImageRadialColorStop, last); rgba = _gtk_css_rgba_value_get_rgba (stop->color); offset += step; cairo_pattern_add_color_stop_rgba (pattern, (offset - start) / (end - start), rgba->red, rgba->green, rgba->blue, rgba->alpha); } offset = pos; last = i; } cairo_rectangle (cr, 0, 0, width, height); cairo_translate (cr, x, y); cairo_set_source (cr, pattern); cairo_fill (cr); cairo_pattern_destroy (pattern); }
static void handle_nonlocal_move (NemoIconContainer *container, GdkDragAction action, int x, int y, const char *target_uri, gboolean icon_hit) { GList *source_uris, *p; GArray *source_item_locations; gboolean free_target_uri, is_rtl; int index, item_x; GtkAllocation allocation; if (container->details->dnd_info->drag_info.selection_list == NULL) { return; } source_uris = NULL; for (p = container->details->dnd_info->drag_info.selection_list; p != NULL; p = p->next) { /* do a shallow copy of all the uri strings of the copied files */ source_uris = g_list_prepend (source_uris, ((NemoDragSelectionItem *)p->data)->uri); } source_uris = g_list_reverse (source_uris); is_rtl = nemo_icon_container_is_layout_rtl (container); source_item_locations = g_array_new (FALSE, TRUE, sizeof (GdkPoint)); if (!icon_hit) { /* Drop onto a container. Pass along the item points to allow placing * the items in their same relative positions in the new container. */ source_item_locations = g_array_set_size (source_item_locations, g_list_length (container->details->dnd_info->drag_info.selection_list)); for (index = 0, p = container->details->dnd_info->drag_info.selection_list; p != NULL; index++, p = p->next) { item_x = ((NemoDragSelectionItem *)p->data)->icon_x; if (is_rtl) item_x = -item_x - ((NemoDragSelectionItem *)p->data)->icon_width; g_array_index (source_item_locations, GdkPoint, index).x = item_x; g_array_index (source_item_locations, GdkPoint, index).y = ((NemoDragSelectionItem *)p->data)->icon_y; } } free_target_uri = FALSE; /* Rewrite internal desktop URIs to the normal target uri */ if (eel_uri_is_desktop (target_uri)) { target_uri = nemo_get_desktop_directory_uri (); free_target_uri = TRUE; } if (is_rtl) { gtk_widget_get_allocation (GTK_WIDGET (container), &allocation); x = CANVAS_WIDTH (container, allocation) - x; } /* start the copy */ g_signal_emit_by_name (container, "move_copy_items", source_uris, source_item_locations, target_uri, action, x, y); if (free_target_uri) { g_free ((char *)target_uri); } g_list_free (source_uris); g_array_free (source_item_locations, TRUE); }
/* creates a section header block for the new output file */ static GArray* create_shb_header(const merge_in_file_t *in_files, const guint in_file_count, const gchar *app_name) { GArray *shb_hdrs; wtap_block_t shb_hdr; GString *comment_gstr; GString *os_info_str; guint i; char* shb_comment = NULL; wtapng_mandatory_section_t* shb_data; gsize opt_len; gchar *opt_str; shb_hdrs = wtap_file_get_shb_for_new_file(in_files[0].wth); shb_hdr = g_array_index(shb_hdrs, wtap_block_t, 0); comment_gstr = g_string_new(""); /* * TODO: merge comments from all files * * XXX - do we want some way to record which comments, hardware/OS/app * descriptions, IDBs, etc.? came from which files? * * XXX - fix this to handle multiple comments from a single file. */ if (wtap_block_get_nth_string_option_value(shb_hdr, OPT_COMMENT, 0, &shb_comment) == WTAP_OPTTYPE_SUCCESS && strlen(shb_comment) > 0) { /* very lame way to save comments - does not save them from the other files */ g_string_append_printf(comment_gstr, "%s \n",shb_comment); } g_string_append_printf(comment_gstr, "File created by merging: \n"); for (i = 0; i < in_file_count; i++) { g_string_append_printf(comment_gstr, "File%d: %s \n",i+1,in_files[i].filename); } os_info_str = g_string_new(""); get_os_version_info(os_info_str); shb_data = (wtapng_mandatory_section_t*)wtap_block_get_mandatory_data(shb_hdr); shb_data->section_length = -1; /* TODO: handle comments from each file being merged */ opt_len = comment_gstr->len; opt_str = g_string_free(comment_gstr, FALSE); wtap_block_set_nth_string_option_value(shb_hdr, OPT_COMMENT, 0, opt_str, opt_len); /* section comment */ g_free(opt_str); /* * XXX - and how do we preserve all the OPT_SHB_HARDWARE, OPT_SHB_OS, * and OPT_SHB_USERAPPL values from all the previous files? */ wtap_block_remove_option(shb_hdr, OPT_SHB_HARDWARE); opt_len = os_info_str->len; opt_str = g_string_free(os_info_str, FALSE); if (opt_str) { wtap_block_set_string_option_value(shb_hdr, OPT_SHB_OS, opt_str, opt_len); /* UTF-8 string containing the name */ /* of the operating system used to create this section. */ g_free(opt_str); } else { /* * No OS information; remove the old version. */ wtap_block_remove_option(shb_hdr, OPT_SHB_OS); } wtap_block_set_string_option_value(shb_hdr, OPT_SHB_USERAPPL, app_name, app_name ? strlen(app_name): 0 ); /* NULL if not available, UTF-8 string containing the name */ /* of the application used to create this section. */ return shb_hdrs; }
static void clutter_flow_layout_allocate (ClutterLayoutManager *manager, ClutterContainer *container, const ClutterActorBox *allocation, ClutterAllocationFlags flags) { ClutterFlowLayoutPrivate *priv = CLUTTER_FLOW_LAYOUT (manager)->priv; GList *l, *children = clutter_container_get_children (container); gfloat avail_width, avail_height; gfloat item_x, item_y; gint line_item_count; gint items_per_line; gint line_index; if (children == NULL) return; clutter_actor_box_get_size (allocation, &avail_width, &avail_height); items_per_line = compute_lines (CLUTTER_FLOW_LAYOUT (manager), avail_width, avail_height); item_x = item_y = 0; line_item_count = 0; line_index = 0; for (l = children; l != NULL; l = l->next) { ClutterActor *child = l->data; ClutterActorBox child_alloc; gfloat item_width, item_height; gfloat new_x, new_y; if (!CLUTTER_ACTOR_IS_VISIBLE (child)) continue; new_x = new_y = 0; if (priv->orientation == CLUTTER_FLOW_HORIZONTAL) { if (line_item_count == items_per_line && line_item_count > 0) { item_y += g_array_index (priv->line_natural, gfloat, line_index); if (line_index >= 0) item_y += priv->row_spacing; line_item_count = 0; line_index += 1; item_x = 0; } new_x = ((line_item_count + 1) * (avail_width + priv->col_spacing)) / items_per_line; item_width = new_x - item_x - priv->col_spacing; item_height = g_array_index (priv->line_natural, gfloat, line_index); if (!priv->is_homogeneous) { gfloat child_min, child_natural; clutter_actor_get_preferred_width (child, item_height, &child_min, &child_natural); item_width = MIN (item_width, child_natural); clutter_actor_get_preferred_height (child, item_width, &child_min, &child_natural); item_height = MIN (item_height, child_natural); } } else { if (line_item_count == items_per_line && line_item_count > 0) { item_x += g_array_index (priv->line_natural, gfloat, line_index); if (line_index >= 0) item_x += priv->col_spacing; line_item_count = 0; line_index += 1; item_y = 0; } new_y = ((line_item_count + 1) * (avail_height + priv->row_spacing)) / items_per_line; item_height = new_y - item_y - priv->row_spacing; item_width = g_array_index (priv->line_natural, gfloat, line_index); if (!priv->is_homogeneous) { gfloat child_min, child_natural; clutter_actor_get_preferred_width (child, item_height, &child_min, &child_natural); item_width = MIN (item_width, child_natural); clutter_actor_get_preferred_height (child, item_width, &child_min, &child_natural); item_height = MIN (item_height, child_natural); } } CLUTTER_NOTE (LAYOUT, "flow[line:%d, item:%d/%d] =" "{ %.2f, %.2f, %.2f, %.2f }", line_index, line_item_count + 1, items_per_line, item_x, item_y, item_width, item_height); child_alloc.x1 = ceil (item_x); child_alloc.y1 = ceil (item_y); child_alloc.x2 = ceil (child_alloc.x1 + item_width); child_alloc.y2 = ceil (child_alloc.y1 + item_height); clutter_actor_allocate (child, &child_alloc, flags); if (priv->orientation == CLUTTER_FLOW_HORIZONTAL) item_x = new_x; else item_y = new_y; line_item_count += 1; } g_list_free (children); }
static GString *al_format_log(liVRequest *vr, al_data *ald, GArray *format) { GString *str = g_string_sized_new(255); liResponse *resp = &vr->response; liRequest *req = &vr->request; liPhysical *phys = &vr->physical; for (guint i = 0; i < format->len; i++) { GString *tmp_gstr2 = NULL; gchar *tmp_str = NULL; guint len = 0; al_format_entry *e = &g_array_index(format, al_format_entry, i); if (e->type == AL_ENTRY_FORMAT) { switch (e->format.type) { case AL_FORMAT_PERCENT: g_string_append_c(str, '%'); break; case AL_FORMAT_REMOTE_ADDR: g_string_append_len(str, GSTR_LEN(vr->coninfo->remote_addr_str)); break; case AL_FORMAT_LOCAL_ADDR: g_string_append_len(str, GSTR_LEN(vr->coninfo->local_addr_str)); break; case AL_FORMAT_BYTES_RESPONSE: li_string_append_int(str, vr->vr_out->bytes_out); break; case AL_FORMAT_BYTES_RESPONSE_CLF: if (vr->vr_out->bytes_out) li_string_append_int(str, vr->vr_out->bytes_out); else g_string_append_c(str, '-'); break; case AL_FORMAT_DURATION_MICROSECONDS: li_string_append_int(str, (CUR_TS(vr->wrk) - vr->ts_started) * 1000 * 1000); break; case AL_FORMAT_ENV: tmp_gstr2 = li_environment_get(&vr->env, GSTR_LEN(e->key)); if (tmp_gstr2) al_append_escaped(str, tmp_gstr2); else g_string_append_c(str, '-'); break; case AL_FORMAT_FILENAME: if (phys->path->len) g_string_append_len(str, GSTR_LEN(phys->path)); else g_string_append_c(str, '-'); break; case AL_FORMAT_REQUEST_HEADER: li_http_header_get_all(vr->wrk->tmp_str, req->headers, GSTR_LEN(e->key)); if (vr->wrk->tmp_str->len) al_append_escaped(str, vr->wrk->tmp_str); else g_string_append_c(str, '-'); break; case AL_FORMAT_METHOD: g_string_append_len(str, GSTR_LEN(req->http_method_str)); break; case AL_FORMAT_RESPONSE_HEADER: li_http_header_get_all(vr->wrk->tmp_str, resp->headers, GSTR_LEN(e->key)); if (vr->wrk->tmp_str->len) al_append_escaped(str, vr->wrk->tmp_str); else g_string_append_c(str, '-'); break; case AL_FORMAT_LOCAL_PORT: switch (vr->coninfo->local_addr.addr->plain.sa_family) { case AF_INET: li_string_append_int(str, ntohs(vr->coninfo->local_addr.addr->ipv4.sin_port)); break; #ifdef HAVE_IPV6 case AF_INET6: li_string_append_int(str, ntohs(vr->coninfo->local_addr.addr->ipv6.sin6_port)); break; #endif default: g_string_append_c(str, '-'); break; } break; case AL_FORMAT_QUERY_STRING: if (req->uri.query->len) al_append_escaped(str, req->uri.query); else g_string_append_c(str, '-'); break; case AL_FORMAT_FIRST_LINE: g_string_append_len(str, GSTR_LEN(req->http_method_str)); g_string_append_c(str, ' '); al_append_escaped(str, req->uri.raw_orig_path); g_string_append_c(str, ' '); tmp_str = li_http_version_string(req->http_version, &len); g_string_append_len(str, tmp_str, len); break; case AL_FORMAT_STATUS_CODE: li_string_append_int(str, resp->http_status); break; case AL_FORMAT_TIME: /* todo: implement format string */ tmp_gstr2 = li_worker_current_timestamp(vr->wrk, LI_LOCALTIME, ald->ts_ndx); g_string_append_len(str, GSTR_LEN(tmp_gstr2)); break; case AL_FORMAT_DURATION_SECONDS: li_string_append_int(str, CUR_TS(vr->wrk) - vr->ts_started); break; case AL_FORMAT_AUTHED_USER: tmp_gstr2 = li_environment_get(&vr->env, CONST_STR_LEN("REMOTE_USER")); if (tmp_gstr2) g_string_append_len(str, GSTR_LEN(tmp_gstr2)); else g_string_append_c(str, '-'); break; case AL_FORMAT_PATH: g_string_append_len(str, GSTR_LEN(req->uri.path)); break; case AL_FORMAT_SERVER_NAME: if (CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_NAME).string) g_string_append_len(str, GSTR_LEN(CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_NAME).string)); else g_string_append_len(str, GSTR_LEN(req->uri.host)); break; case AL_FORMAT_HOSTNAME: if (req->uri.host->len) g_string_append_len(str, GSTR_LEN(req->uri.host)); else g_string_append_c(str, '-'); break; case AL_FORMAT_CONNECTION_STATUS: { /* was request completed? */ liConnection *con = li_connection_from_vrequest(vr); /* try to get a connection object */ if (con && (con->in->is_closed && con->raw_out->is_closed && 0 == con->raw_out->length)) { g_string_append_c(str, 'X'); } else { g_string_append_c(str, vr->coninfo->keep_alive ? '+' : '-'); } } break; case AL_FORMAT_BYTES_IN: li_string_append_int(str, vr->coninfo->stats.bytes_in); break; case AL_FORMAT_BYTES_OUT: li_string_append_int(str, vr->coninfo->stats.bytes_out); break; default: /* not implemented: { 'C', FALSE, AL_FORMAT_COOKIE } { 't', FALSE, AL_FORMAT_TIME }, (partially implemented) */ g_string_append_c(str, '?'); break; } } else { /* append normal string */ g_string_append_len(str, GSTR_LEN(e->key)); } } return str; }
std::unique_ptr<FieldInfos> TraceSet::getFieldInfos(const ::tibee_bt_declaration* tibeeBtDecl, std::string name, field_index_t index) { if (!tibeeBtDecl) { return nullptr; } // do not pick the first '_' character in the name if (name.at(0) == '_') { name = name.substr(1); } if (tibeeBtDecl->id != ::CTF_TYPE_STRUCT) { // no field map return std::unique_ptr<FieldInfos> { new FieldInfos { index, name, nullptr } }; } auto tibeeDeclStruct = reinterpret_cast<const ::tibee_declaration_struct*>(tibeeBtDecl); std::unique_ptr<FieldInfos::FieldMap> fieldMap {new FieldInfos::FieldMap}; if (!tibeeDeclStruct->fields) { // structure has uninitialized "fields" member (weird) return std::unique_ptr<FieldInfos> { new FieldInfos { index, name, nullptr } }; } // iterate structure fields auto tibeeDeclStructFields = tibeeDeclStruct->fields; for (std::size_t x = 0; x < tibeeDeclStructFields->len; ++x) { // get declaration field from array auto tibeeDeclField = &g_array_index(tibeeDeclStructFields, ::tibee_declaration_field, x); // get declaration auto fieldTibeeBtDecl = tibeeDeclField->declaration; // get name auto fieldName = static_cast<const char*>(::g_quark_to_string(tibeeDeclField->name)); // ready for recursion! auto fieldInfos = TraceSet::getFieldInfos(fieldTibeeBtDecl, fieldName, x); // set it now (*fieldMap)[fieldName] = std::move(fieldInfos); } return std::unique_ptr<FieldInfos> { new FieldInfos { index, name, std::move(fieldMap) } }; }
void ManageInterfacesDialog::pipeAccepted() { interface_t device; // First clear the current pipes for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); /* Continue if capture device is hidden or not a pipe */ if (device.hidden || device.type != IF_PIPE) { continue; } global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); } // Next rebuild a fresh list QTreeWidgetItemIterator it(ui->pipeList); while (*it) { QString pipe_name = (*it)->text(col_p_pipe_); if (pipe_name.isEmpty() || pipe_name == new_pipe_default_) { ++it; continue; } for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { // Instead of just deleting the device we might want to add a hint label // and let the user know what's going to happen. device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); if (pipe_name.compare(device.name) == 0) { // Duplicate ++it; continue; } } device.name = qstring_strdup(pipe_name); device.display_name = g_strdup(device.name); device.hidden = FALSE; device.selected = TRUE; device.type = IF_PIPE; device.pmode = global_capture_opts.default_options.promisc_mode; device.has_snaplen = global_capture_opts.default_options.has_snaplen; device.snaplen = global_capture_opts.default_options.snaplen; device.cfilter = g_strdup(global_capture_opts.default_options.cfilter); device.addresses = NULL; device.no_addresses = 0; device.last_packets = 0; device.links = NULL; #if defined(_WIN32) || defined(HAVE_PCAP_CREATE) device.buffer = DEFAULT_CAPTURE_BUFFER_SIZE; #endif device.active_dlt = -1; device.locked = FALSE; device.if_info.name = g_strdup(device.name); device.if_info.friendly_name = NULL; device.if_info.vendor_description = NULL; device.if_info.addrs = NULL; device.if_info.loopback = FALSE; device.if_info.type = IF_PIPE; #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = FALSE; device.monitor_mode_supported = FALSE; #endif global_capture_opts.num_selected++; g_array_append_val(global_capture_opts.all_ifaces, device); ++it; } }
static void week_view_event_item_draw (GnomeCanvasItem *canvas_item, cairo_t *cr, gint x, gint y, gint width, gint height) { EWeekViewEventItem *event_item; EWeekView *week_view; EWeekViewEvent *event; EWeekViewEventSpan *span; ECalModel *model; GtkWidget *parent; gint x1, y1, x2, y2, time_x, time_y; gint icon_x, icon_y, time_width, min_end_time_x, max_icon_x; gint rect_x, rect_w, rect_x2 = 0; gboolean one_day_event, editing_span = FALSE; gint start_hour, start_minute, end_hour, end_minute; gboolean draw_start, draw_end; gboolean draw_start_triangle = FALSE, draw_end_triangle = FALSE; GdkColor bg_color; cairo_pattern_t *pat; guint16 red, green, blue; gdouble radius, cx0, cy0, rect_height, rect_width; gdouble cc = 65535.0; cairo_region_t *draw_region; GdkRectangle rect; const gchar *color_spec; event_item = E_WEEK_VIEW_EVENT_ITEM (canvas_item); parent = gtk_widget_get_parent (GTK_WIDGET (canvas_item->canvas)); g_return_if_fail (E_IS_WEEK_VIEW (parent)); week_view = E_WEEK_VIEW (parent); if (event_item->priv->event_num == -1 || event_item->priv->span_num == -1) return; g_return_if_fail (event_item->priv->event_num < week_view->events->len); if (!is_array_index_in_bounds (week_view->events, event_item->priv->event_num)) return; event = &g_array_index (week_view->events, EWeekViewEvent, event_item->priv->event_num); if (!is_comp_data_valid (event)) return; g_return_if_fail ( event->spans_index + event_item->priv->span_num < week_view->spans->len); if (!is_array_index_in_bounds ( week_view->spans, event->spans_index + event_item->priv->span_num)) return; span = &g_array_index ( week_view->spans, EWeekViewEventSpan, event->spans_index + event_item->priv->span_num); x1 = canvas_item->x1 - x; y1 = canvas_item->y1 - y; x2 = canvas_item->x2 - x; y2 = canvas_item->y2 - y; if (x1 == x2 || y1 == y2) return; rect.x = 0; rect.y = 0; rect.width = width; rect.height = height; if (rect.width > 0 && rect.height > 0) draw_region = cairo_region_create_rectangle (&rect); else draw_region = cairo_region_create (); if (!can_draw_in_region (draw_region, x1, y1, x2 - x1, y2 - y1)) { cairo_region_destroy (draw_region); return; } icon_y = y1 + E_WEEK_VIEW_EVENT_BORDER_HEIGHT + E_WEEK_VIEW_ICON_Y_PAD; /* Get the start & end times in 24-hour format. */ start_hour = event->start_minute / 60; start_minute = event->start_minute % 60; /* Modulo 24 because a midnight end time will be '24' */ end_hour = (event->end_minute / 60) % 24; end_minute = event->end_minute % 60; time_y = y1 + E_WEEK_VIEW_EVENT_BORDER_HEIGHT + E_WEEK_VIEW_EVENT_TEXT_Y_PAD; time_width = e_week_view_get_time_string_width (week_view); one_day_event = e_week_view_is_one_day_event ( week_view, event_item->priv->event_num); model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)); color_spec = e_cal_model_get_color_for_component (model, event->comp_data); bg_color = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]; if (!gdk_color_parse (color_spec, &bg_color)) { bg_color = week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]; } red = bg_color.red; green = bg_color.green; blue = bg_color.blue; if (one_day_event) { time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD + 1; rect_x = x1 + E_WEEK_VIEW_EVENT_L_PAD; rect_w = x2 - x1 - E_WEEK_VIEW_EVENT_L_PAD - E_WEEK_VIEW_EVENT_R_PAD + 1; /* Here we draw the border around the event*/ cx0 = rect_x; cy0 = y1 + 1; rect_width = rect_w; rect_height = y2 - y1 - 1; radius = 12; if (can_draw_in_region (draw_region, cx0, cy0, rect_width, rect_height)) { cairo_save (cr); draw_curved_rectangle (cr, cx0, cy0, rect_width, rect_height, radius); cairo_set_line_width (cr, 2.0); cairo_set_source_rgb (cr, red / cc, green / cc, blue / cc); cairo_stroke (cr); cairo_restore (cr); } /* Fill it in the Event */ cx0 = rect_x + 1.5; cy0 = y1 + 2.75; rect_width = rect_w - 3.; rect_height = y2 - y1 - 4.5; radius = 8; if (can_draw_in_region (draw_region, cx0, cy0, rect_width, rect_height)) { cairo_save (cr); draw_curved_rectangle ( cr, cx0, cy0, rect_width, rect_height, radius); pat = cairo_pattern_create_linear ( rect_x + 2, y1 + 1, rect_x + 2, y2 - 7.25); cairo_pattern_add_color_stop_rgba ( pat, 1, red / cc, green / cc, blue / cc, 0.8); cairo_pattern_add_color_stop_rgba ( pat, 0, red / cc, green / cc, blue / cc, 0.4); cairo_set_source (cr, pat); cairo_fill_preserve (cr); cairo_pattern_destroy (pat); cairo_set_source_rgba (cr, red / cc, green / cc, blue / cc, 0.2); cairo_set_line_width (cr, 0.5); cairo_stroke (cr); cairo_restore (cr); } /* Draw the start and end times, as required. */ switch (week_view->time_format) { case E_WEEK_VIEW_TIME_BOTH_SMALL_MIN: case E_WEEK_VIEW_TIME_BOTH: draw_start = TRUE; draw_end = TRUE; break; case E_WEEK_VIEW_TIME_START_SMALL_MIN: case E_WEEK_VIEW_TIME_START: draw_start = TRUE; draw_end = FALSE; break; case E_WEEK_VIEW_TIME_NONE: draw_start = FALSE; draw_end = FALSE; break; default: g_return_if_reached (); draw_start = FALSE; draw_end = FALSE; break; } if (draw_start) { week_view_draw_time ( week_view, cr, time_x, time_y, start_hour, start_minute); time_x += time_width; } if (draw_end) { time_x += E_WEEK_VIEW_EVENT_TIME_SPACING; week_view_draw_time ( week_view, cr, time_x, time_y, end_hour, end_minute); time_x += time_width; } icon_x = time_x; if (draw_start) icon_x += E_WEEK_VIEW_EVENT_TIME_X_PAD; /* Draw the icons. */ week_view_event_item_draw_icons ( event_item, cr, icon_x, icon_y, x2, FALSE, draw_region); } else { rect_x = x1 + E_WEEK_VIEW_EVENT_L_PAD; rect_w = x2 - x1 - E_WEEK_VIEW_EVENT_L_PAD - E_WEEK_VIEW_EVENT_R_PAD + 1; /* Draw the triangles at the start & end, if needed. * They also use the first few pixels at the edge of the * event so we update rect_x & rect_w so we don't draw over * them. */ if (event->start < week_view->day_starts[span->start_day]) { draw_start_triangle = TRUE; rect_x += 2; rect_w -= 2; } if (event->end > week_view->day_starts[span->start_day + span->num_days]) { draw_end_triangle = TRUE; rect_w -= 2; } /* Here we draw the border around the event */ cx0 = rect_x; cy0 = y1 + 1; rect_width = rect_w; rect_height = y2 - y1 - 1; radius = 12; if (can_draw_in_region (draw_region, cx0, cy0, rect_width, rect_height)) { cairo_save (cr); draw_curved_rectangle (cr, cx0, cy0, rect_width, rect_height, radius); cairo_set_line_width (cr, 2.0); cairo_set_source_rgb (cr, red / cc, green / cc, blue / cc); cairo_stroke (cr); cairo_restore (cr); } /* Here we fill it in the event*/ cx0 = rect_x + 1.5; cy0 = y1 + 2.75; rect_width = rect_w - 3.; rect_height = y2 - y1 - 4.5; radius = 8; if (can_draw_in_region (draw_region, cx0, cy0, rect_width, rect_height)) { cairo_save (cr); draw_curved_rectangle ( cr, cx0, cy0, rect_width, rect_height, radius); pat = cairo_pattern_create_linear ( rect_x + 2, y1 + 1, rect_x + 2, y2 - 7.25); cairo_pattern_add_color_stop_rgba ( pat, 1, red / cc, green / cc, blue / cc, 0.8); cairo_pattern_add_color_stop_rgba ( pat, 0, red / cc, green / cc, blue / cc, 0.4); cairo_set_source (cr, pat); cairo_fill_preserve (cr); cairo_pattern_destroy (pat); cairo_set_source_rgba (cr, red / cc, green / cc, blue / cc, 0.2); cairo_set_line_width (cr, 0.5); cairo_stroke (cr); cairo_restore (cr); } if (draw_start_triangle) { week_view_event_item_draw_triangle ( event_item, cr, bg_color, x1 + E_WEEK_VIEW_EVENT_L_PAD + 2, y1, -3, y2 - y1 + 1, draw_region); } else if (can_draw_in_region (draw_region, rect_x, y1, 1, y2 - y1)) { EWeekViewColors wvc; GdkColor *color; wvc = E_WEEK_VIEW_COLOR_EVENT_BORDER; color = &week_view->colors[wvc]; cairo_save (cr); gdk_cairo_set_source_color (cr, color); cairo_set_line_width (cr, 0.7); cairo_move_to (cr, rect_x, y1); cairo_line_to (cr, rect_x, y2); cairo_stroke (cr); cairo_restore (cr); } if (draw_end_triangle) { week_view_event_item_draw_triangle ( event_item, cr, bg_color, x2 - E_WEEK_VIEW_EVENT_R_PAD - 2, y1, 3, y2 - y1 + 1, draw_region); } else if (can_draw_in_region (draw_region, rect_x2, y2, 1, 1)) { EWeekViewColors wvc; GdkColor *color; wvc = E_WEEK_VIEW_COLOR_EVENT_BORDER; color = &week_view->colors[wvc]; cairo_save (cr); gdk_cairo_set_source_color (cr, color); cairo_set_line_width (cr, 0.7); /* rect_x2 is used uninitialized here */ cairo_move_to (cr, rect_x2, y2); cairo_line_to (cr, rect_x2, y2); cairo_stroke (cr); cairo_restore (cr); } if (span->text_item && E_TEXT (span->text_item)->editing) editing_span = TRUE; /* Draw the start & end times, if they are not on day * boundaries. The start time would always be shown if it was * needed, though it may be clipped as the window shrinks. * The end time is only displayed if there is enough room. * We calculate the minimum position for the end time, which * depends on whether the start time is displayed. If the end * time doesn't fit, then we don't draw it. */ min_end_time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD + E_WEEK_VIEW_EVENT_BORDER_WIDTH + E_WEEK_VIEW_EVENT_EDGE_X_PAD; if (!editing_span && event->start > week_view->day_starts[span->start_day]) { time_x = x1 + E_WEEK_VIEW_EVENT_L_PAD + E_WEEK_VIEW_EVENT_BORDER_WIDTH + E_WEEK_VIEW_EVENT_EDGE_X_PAD; cairo_save (cr); cairo_rectangle (cr, x1, y1, x2 - x1 - E_WEEK_VIEW_EVENT_R_PAD - E_WEEK_VIEW_EVENT_BORDER_WIDTH + 1, y2 - y1 + 1); cairo_clip (cr); week_view_draw_time ( week_view, cr, time_x, time_y, start_hour, start_minute); cairo_restore (cr); /* We don't want the end time to be drawn over the * start time, so we increase the minimum position. */ min_end_time_x += time_width + E_WEEK_VIEW_EVENT_TIME_X_PAD; } max_icon_x = x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD - E_WEEK_VIEW_EVENT_BORDER_WIDTH - E_WEEK_VIEW_EVENT_EDGE_X_PAD; if (!editing_span && event->end < week_view->day_starts[span->start_day + span->num_days]) { /* Calculate where the end time should be displayed. */ time_x = x2 + 1 - E_WEEK_VIEW_EVENT_R_PAD - E_WEEK_VIEW_EVENT_BORDER_WIDTH - E_WEEK_VIEW_EVENT_EDGE_X_PAD - time_width; /* Draw the end time, if the position is greater than * the minimum calculated above. */ if (time_x >= min_end_time_x) { week_view_draw_time ( week_view, cr, time_x, time_y, end_hour, end_minute); max_icon_x -= time_width + E_WEEK_VIEW_EVENT_TIME_X_PAD; } } /* Draw the icons. */ if (span->text_item && (week_view->editing_event_num != event_item->priv->event_num || week_view->editing_span_num != event_item->priv->span_num)) { icon_x = span->text_item->x1 - E_WEEK_VIEW_ICON_R_PAD - x; week_view_event_item_draw_icons ( event_item, cr, icon_x, icon_y, max_icon_x, TRUE, draw_region); } } cairo_region_destroy (draw_region); }
int main(int argc, char **argv) { static const char *metric = NULL; static const char *metric_description = NULL; static const char *identifier = NULL; static const char *priority_str = NULL; static gboolean finished = FALSE; static gboolean shutdown = FALSE; int priority = LOG_INFO; static GOptionEntry entries[] = { { "identifier", 't', 0, G_OPTION_ARG_STRING, &identifier, "Source of the log message", "IDENTIFIER" }, { "priority", 'p', 0, G_OPTION_ARG_STRING, &priority_str, "Priority (emerg|alert|crit|err|warning|notice|info|debug|0..7) - default info", "PRIORITY" }, { "metric", 0, 0, G_OPTION_ARG_STRING, &metric, "Log a metric", "NAME=VALUE[UNITS]" }, { "metric-description", 0, 0, G_OPTION_ARG_STRING, &metric_description, "Description of metric", "DESC" }, { "finished", 0, 0, G_OPTION_ARG_NONE, &finished, "Indicate that a task has finished" }, { "shutdown", 0, 0, G_OPTION_ARG_NONE, &shutdown, "Indicate that that the system is shutting down" }, }; GOptionContext *context; GError *error = NULL; GArray *send_iov; int i; context = g_option_context_new ("FIELD1=VALUE1 FIELD2=VALUE2..."); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); return 1; } send_offsets = g_array_new (FALSE, FALSE, sizeof (SendOffset)); buffer = g_string_new (NULL); if (identifier != NULL) add_fieldf("SYSLOG_IDENTIFIER=%s", identifier); if (priority_str != NULL) { for (i = 0; priorities[i]; i++) { if (strcmp (priorities[i], priority_str) == 0) { priority = i; break; } } if (priorities[i] == NULL) { if (priority_str[0] >= '0' && priority_str[0] <= '7' && priority_str[1] == 0) { priority = priority_str[0] - '0'; } else { g_printerr ("Unknown priority '%s'\n", priority_str); return 1; } } } add_fieldf("PRIORITY=%d", priority); if ((metric ? 1 : 0) + (finished ? 1 : 0) + (shutdown ? 1 : 0) > 1) { g_printerr ("Only one of --metric, --finished, and --shutdown can be specified\n"); return 1; } if (metric) { const char *equals; char *metric_name; char *metric_value; const char *metric_units = NULL; char *endptr; double value G_GNUC_UNUSED; equals = strchr (metric, '='); if (equals == NULL) { g_printerr ("--metric argument should be of the form NAME=VALUE[UNITS]\n"); return 1; } metric_name = g_strndup (metric, equals - metric); value = g_ascii_strtod (equals + 1, &endptr); if (endptr == equals + 1) { g_printerr ("--metric argument should be of the form NAME=VALUE[UNITS]\n"); return 1; } metric_value = g_strndup (equals + 1, endptr - (equals + 1)); if (*endptr) metric_units = endptr; add_fieldf ("MESSAGE_ID=5eb90e0f00a247d68d95f630814de243"); add_fieldf ("METRIC_NAME=%s", metric_name); add_fieldf ("METRIC_VALUE=%s", metric_value); if (metric_units) add_fieldf ("METRIC_UNITS=%s", metric_units); } if (metric_description) { if (!metric) { g_printerr("--metric-description requires --metric\n"); return 1; } add_fieldf("METRIC_DESCRIPTION=%s", metric); } if (metric_description) add_fieldf("MESSAGE=%s (%s)", metric, metric_description); else if (metric) add_fieldf("MESSAGE=%s", metric); if (finished) { add_fieldf ("MESSAGE_ID=26a5224162874504864dfa03bf255c8d"); add_fieldf ("MESSAGE=Finished"); } if (shutdown) { add_fieldf ("MESSAGE_ID=545cc8baba1d4493916a334258c83be0"); add_fieldf ("MESSAGE=System shutdown"); } for (i = 1; i < argc; i++) { const char *equals = strchr (argv[i], '='); const char *p; if (equals == NULL) { g_printerr ("argument '%s' should be of the form FIELD=VALUE\n", argv[i]); return 1; } for (p = argv[i]; p != equals; p++) { if (!((*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || (p != argv[i] && *p == '_'))) { g_printerr ("Field name should consist of upper-case letters, digits, and underscores, and not start with an underscore\n"); return 1; } } add_field (argv[i]); } send_iov = g_array_new (FALSE, FALSE, sizeof (struct iovec)); for (i = 0; i < send_offsets->len; i++) { SendOffset *offset = &g_array_index (send_offsets, SendOffset, i); struct iovec iov; iov.iov_base = buffer->str + offset->offset; iov.iov_len = offset->len; g_array_append_val (send_iov, iov); } sd_journal_sendv ((struct iovec *)send_iov->data, send_iov->len); return 0; }
/* This draws a little triangle to indicate that an event extends past * the days visible on screen. */ static void week_view_event_item_draw_triangle (EWeekViewEventItem *event_item, cairo_t *cr, GdkColor bg_color, gint x, gint y, gint w, gint h, cairo_region_t *draw_region) { ECalModel *model; EWeekView *week_view; EWeekViewEvent *event; GnomeCanvas *canvas; GtkWidget *parent; GdkPoint points[3]; const gchar *color_spec; gint c1, c2; if (!can_draw_in_region (draw_region, x, y, w, h)) return; canvas = GNOME_CANVAS_ITEM (event_item)->canvas; parent = gtk_widget_get_parent (GTK_WIDGET (canvas)); week_view = E_WEEK_VIEW (parent); if (!is_array_index_in_bounds (week_view->events, event_item->priv->event_num)) return; event = &g_array_index (week_view->events, EWeekViewEvent, event_item->priv->event_num); if (!is_comp_data_valid (event)) return; points[0].x = x; points[0].y = y; points[1].x = x + w; points[1].y = y + (h / 2); points[2].x = x; points[2].y = y + h - 1; model = e_calendar_view_get_model (E_CALENDAR_VIEW (week_view)); color_spec = e_cal_model_get_color_for_component (model, event->comp_data); if (gdk_color_parse (color_spec, &bg_color)) { gdk_cairo_set_source_color (cr, &bg_color); } else { EWeekViewColors wvc; GdkColor *color; wvc = E_WEEK_VIEW_COLOR_EVENT_BACKGROUND; color = &week_view->colors[wvc]; gdk_cairo_set_source_color (cr, color); } cairo_save (cr); cairo_set_line_width (cr, 0.7); cairo_move_to (cr, points[0].x, points[0].y); cairo_line_to (cr, points[1].x, points[1].y); cairo_line_to (cr, points[2].x, points[2].y); cairo_line_to (cr, points[0].x, points[0].y); cairo_fill (cr); cairo_restore (cr); cairo_save (cr); gdk_cairo_set_source_color ( cr, &week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER]); /* If the height is odd we can use the same central point for both * lines. If it is even we use different end-points. */ c1 = c2 = y + (h / 2); if (h % 2 == 0) c1--; cairo_set_line_width (cr, 0.7); cairo_move_to (cr, x, y); cairo_line_to (cr, x + w, c1); cairo_move_to (cr, x, y + h - 1); cairo_line_to (cr, x + w, c2); cairo_restore (cr); }
static void week_view_event_item_draw_icons (EWeekViewEventItem *event_item, cairo_t *cr, gint icon_x, gint icon_y, gint x2, gboolean right_align, cairo_region_t *draw_region) { EWeekView *week_view; EWeekViewEvent *event; ECalComponent *comp; GnomeCanvas *canvas; GtkWidget *parent; gint num_icons = 0, icon_x_inc; gboolean draw_reminder_icon = FALSE, draw_recurrence_icon = FALSE; gboolean draw_timezone_icon = FALSE, draw_attach_icon = FALSE; gboolean draw_meeting_icon = FALSE; GSList *categories_pixbufs = NULL, *pixbufs; canvas = GNOME_CANVAS_ITEM (event_item)->canvas; parent = gtk_widget_get_parent (GTK_WIDGET (canvas)); week_view = E_WEEK_VIEW (parent); if (!is_array_index_in_bounds (week_view->events, event_item->priv->event_num)) return; event = &g_array_index (week_view->events, EWeekViewEvent, event_item->priv->event_num); if (!is_comp_data_valid (event)) return; comp = e_cal_component_new (); e_cal_component_set_icalcomponent ( comp, icalcomponent_new_clone (event->comp_data->icalcomp)); if (e_cal_component_has_alarms (comp)) { draw_reminder_icon = TRUE; num_icons++; } if (e_cal_component_has_recurrences (comp) || e_cal_component_is_instance (comp)) { draw_recurrence_icon = TRUE; num_icons++; } if (e_cal_component_has_attachments (comp)) { draw_attach_icon = TRUE; num_icons++; } if (e_cal_component_has_attendees (comp)) { draw_meeting_icon = TRUE; num_icons++; } if (event->different_timezone) { draw_timezone_icon = TRUE; num_icons++; } num_icons += cal_comp_util_get_n_icons (comp, &categories_pixbufs); icon_x_inc = E_WEEK_VIEW_ICON_WIDTH + E_WEEK_VIEW_ICON_X_PAD; if (right_align) icon_x -= icon_x_inc * num_icons; #define draw_pixbuf(pf) \ if (can_draw_in_region (draw_region, icon_x, icon_y, \ E_WEEK_VIEW_ICON_WIDTH, E_WEEK_VIEW_ICON_HEIGHT)) { \ cairo_save (cr); \ gdk_cairo_set_source_pixbuf (cr, pf, icon_x, icon_y); \ cairo_paint (cr); \ cairo_restore (cr); \ } \ \ icon_x += icon_x_inc; if (draw_reminder_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { draw_pixbuf (week_view->reminder_icon); } if (draw_attach_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { draw_pixbuf (week_view->attach_icon); } if (draw_recurrence_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { draw_pixbuf (week_view->recurrence_icon); } if (draw_timezone_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { draw_pixbuf (week_view->timezone_icon); } if (draw_meeting_icon && icon_x + E_WEEK_VIEW_ICON_WIDTH <= x2) { draw_pixbuf (week_view->meeting_icon); } /* draw categories icons */ for (pixbufs = categories_pixbufs; pixbufs; pixbufs = pixbufs->next) { GdkPixbuf *pixbuf = pixbufs->data; draw_pixbuf (pixbuf); } #undef draw_pixbuf g_slist_foreach (categories_pixbufs, (GFunc) g_object_unref, NULL); g_slist_free (categories_pixbufs); g_object_unref (comp); }
static gboolean week_view_event_item_button_press (EWeekViewEventItem *event_item, GdkEvent *bevent) { EWeekView *week_view; ECalendarViewPosition pos; EWeekViewEvent *event; EWeekViewEventSpan *span; GnomeCanvasItem *item; GtkWidget *parent; item = GNOME_CANVAS_ITEM (event_item); parent = gtk_widget_get_parent (GTK_WIDGET (item->canvas)); g_return_val_if_fail (E_IS_WEEK_VIEW (parent), FALSE); week_view = E_WEEK_VIEW (parent); if (!is_array_index_in_bounds (week_view->events, event_item->priv->event_num)) return FALSE; event = &g_array_index ( week_view->events, EWeekViewEvent, event_item->priv->event_num); if (!is_array_index_in_bounds ( week_view->spans, event->spans_index + event_item->priv->span_num)) return FALSE; span = &g_array_index (week_view->spans, EWeekViewEventSpan, event->spans_index + event_item->priv->span_num); pos = week_view_event_item_get_position (event_item, bevent->button.x, bevent->button.y); if (pos == E_CALENDAR_VIEW_POS_NONE) return FALSE; if (bevent->button.button == 1) { week_view->pressed_event_num = event_item->priv->event_num; week_view->pressed_span_num = event_item->priv->span_num; /* Ignore clicks on the event while editing. */ if (E_TEXT (span->text_item)->editing) return FALSE; /* Remember the item clicked and the mouse position, * so we can start a drag if the mouse moves. */ week_view->drag_event_x = bevent->button.x; week_view->drag_event_y = bevent->button.y; /* FIXME: Remember the day offset from the start of the event. */ return TRUE; } else if (bevent->button.button == 3) { if (!gtk_widget_has_focus (GTK_WIDGET (week_view))) { gtk_widget_grab_focus (GTK_WIDGET (week_view)); if (week_view->event_destroyed) { week_view->event_destroyed = FALSE; return FALSE; } } e_week_view_set_selected_time_range_visible ( week_view, event->start, event->end); e_week_view_show_popup_menu ( week_view, (GdkEventButton *) bevent, event_item->priv->event_num); g_signal_stop_emission_by_name ( item->canvas, "button_press_event"); return TRUE; } return FALSE; }
inline pairPosOff* getPairPosOff(GArray* in, int index) { return &g_array_index(in, pairPosOff, index); }
void ManageInterfacesDialog::addRemoteInterfaces(GList* rlist, remote_options *roptions) { GList *if_entry, *lt_entry; if_info_t *if_info; char *if_string = NULL; gchar *descr, *str = NULL, *link_type_name = NULL;; if_capabilities_t *caps; gint linktype_count; bool monitor_mode, found = false; GSList *curr_addr; int ips = 0; guint i; if_addr_t *addr; data_link_info_t *data_link_info; GString *ip_str; link_row *linkr = NULL; interface_t device; guint num_interfaces = global_capture_opts.all_ifaces->len; for (if_entry = g_list_first(rlist); if_entry != NULL; if_entry = g_list_next(if_entry)) { if_info = (if_info_t *)if_entry->data; for (i = 0; i < num_interfaces; i++) { device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); if (device.hidden) continue; if (strcmp(device.name, if_info->name) == 0) { found = TRUE; break; } } if (found) { found = FALSE; continue; } ip_str = g_string_new(""); str = ""; ips = 0; device.name = g_strdup(if_info->name); /* Is this interface hidden and, if so, should we include it anyway? */ descr = capture_dev_user_descr_find(if_info->name); if (descr != NULL) { /* Yes, we have a user-supplied description; use it. */ if_string = g_strdup_printf("%s: %s", descr, if_info->name); g_free(descr); } else { /* No, we don't have a user-supplied description; did we get one from the OS or libpcap? */ if (if_info->vendor_description != NULL) { /* Yes - use it. */ if_string = g_strdup_printf("%s: %s", if_info->vendor_description, if_info->name); } else { /* No. */ if_string = g_strdup(if_info->name); } } /* else descr != NULL */ if (if_info->loopback) { device.display_name = g_strdup_printf("%s (loopback)", if_string); } else { device.display_name = g_strdup(if_string); } #if defined(_WIN32) || defined(HAVE_PCAP_CREATE) if ((device.buffer = capture_dev_user_buffersize_find(if_string)) == -1) { device.buffer = global_capture_opts.default_options.buffer_size; } #endif if ((device.pmode = capture_dev_user_pmode_find(if_string)) == -1) { device.pmode = global_capture_opts.default_options.promisc_mode; } device.has_snaplen = global_capture_opts.default_options.has_snaplen; if ((device.snaplen = capture_dev_user_snaplen_find(if_string)) == -1) { device.snaplen = global_capture_opts.default_options.snaplen; } device.cfilter = g_strdup(global_capture_opts.default_options.cfilter); monitor_mode = prefs_capture_device_monitor_mode(if_string); caps = capture_get_if_capabilities(if_string, monitor_mode, NULL, main_window_update); for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) { address addr_str; if (ips != 0) { g_string_append(ip_str, "\n"); } addr = (if_addr_t *)curr_addr->data; switch (addr->ifat_type) { case IF_AT_IPv4: SET_ADDRESS(&addr_str, AT_IPv4, 4, &addr->addr.ip4_addr); g_string_append(ip_str, ep_address_to_str(&addr_str)); break; case IF_AT_IPv6: SET_ADDRESS(&addr_str, AT_IPv6, 16, addr->addr.ip6_addr); g_string_append(ip_str, ep_address_to_str(&addr_str)); break; default: /* In case we add non-IP addresses */ break; } } /* for curr_addr */ linktype_count = 0; device.links = NULL; if (caps != NULL) { #ifdef HAVE_PCAP_CREATE device.monitor_mode_enabled = monitor_mode; device.monitor_mode_supported = caps->can_set_rfmon; #endif for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) { data_link_info = (data_link_info_t *)lt_entry->data; linkr = (link_row *)g_malloc(sizeof(link_row)); /* * For link-layer types libpcap/WinPcap doesn't know about, the * name will be "DLT n", and the description will be null. * We mark those as unsupported, and don't allow them to be * used. */ if (data_link_info->description != NULL) { str = g_strdup_printf("%s", data_link_info->description); linkr->dlt = data_link_info->dlt; } else { str = g_strdup_printf("%s (not supported)", data_link_info->name); linkr->dlt = -1; } if (linktype_count == 0) { link_type_name = g_strdup(str); device.active_dlt = data_link_info->dlt; } linkr->name = g_strdup(str); g_free(str); device.links = g_list_append(device.links, linkr); linktype_count++; } /* for link_types */ } else { #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = FALSE; device.monitor_mode_supported = FALSE; #endif device.active_dlt = -1; link_type_name = g_strdup("default"); } device.addresses = g_strdup(ip_str->str); device.no_addresses = ips; device.remote_opts.src_type= roptions->src_type; if (device.remote_opts.src_type == CAPTURE_IFREMOTE) { device.local = FALSE; } device.remote_opts.remote_host_opts.remote_host = g_strdup(roptions->remote_host_opts.remote_host); device.remote_opts.remote_host_opts.remote_port = g_strdup(roptions->remote_host_opts.remote_port); device.remote_opts.remote_host_opts.auth_type = roptions->remote_host_opts.auth_type; device.remote_opts.remote_host_opts.auth_username = g_strdup(roptions->remote_host_opts.auth_username); device.remote_opts.remote_host_opts.auth_password = g_strdup(roptions->remote_host_opts.auth_password); device.remote_opts.remote_host_opts.datatx_udp = roptions->remote_host_opts.datatx_udp; device.remote_opts.remote_host_opts.nocap_rpcap = roptions->remote_host_opts.nocap_rpcap; device.remote_opts.remote_host_opts.nocap_local = roptions->remote_host_opts.nocap_local; #ifdef HAVE_PCAP_SETSAMPLING device.remote_opts.sampling_method = roptions->sampling_method; device.remote_opts.sampling_param = roptions->sampling_param; #endif device.selected = TRUE; global_capture_opts.num_selected++; g_array_append_val(global_capture_opts.all_ifaces, device); g_string_free(ip_str, TRUE); } /*for*/ showRemoteInterfaces(); }
static void list_selection_changed_cb (GdauiRawGrid *grid, gpointer user_data) { DsnConfigPrivate *priv; GdaDataModel *model; GArray *selection; gchar *str; const GValue *cvalue; GtkWidget *win = gtk_widget_get_toplevel (GTK_WIDGET (grid)); if (gtk_widget_is_toplevel (win)) { g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (win), "DatasourceDelete")), FALSE); } priv = g_object_get_data (G_OBJECT (user_data), DSN_CONFIG_DATA); selection = gdaui_data_selector_get_selected_rows (GDAUI_DATA_SELECTOR (priv->dsn_list)); if (!selection) { gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), ST_NOPROP); return; } model = gdaui_data_selector_get_model (GDAUI_DATA_SELECTOR (priv->dsn_list)); if (!GDA_IS_DATA_MODEL (model)) { g_array_free (selection, TRUE); gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), ST_NOPROP); return; } cvalue = gda_data_model_get_value_at (model, 0, g_array_index (selection, gint, 0), NULL); g_array_free (selection, TRUE); if (!cvalue) { gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), ST_NOPROP); return; } str = gda_value_stringify ((GValue *) cvalue); g_print ("==> %s\n", str); GdaDsnInfo *dsn_info; dsn_info = gda_config_get_dsn_info (str); g_free (str); if (!dsn_info) { /* something went wrong here... */ gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), ST_NOPROP); return; } gdaui_dsn_editor_set_dsn (priv->dsn_editor, dsn_info); if (gdaui_dsn_editor_need_authentication (priv->dsn_editor)) gtk_widget_show (GTK_WIDGET (priv->view_buttons [GDAUI_DSN_EDITOR_PANE_AUTH])); else gtk_widget_hide (GTK_WIDGET (priv->view_buttons [GDAUI_DSN_EDITOR_PANE_AUTH])); gtk_toggle_button_set_active (priv->view_buttons [GDAUI_DSN_EDITOR_PANE_DEFINITION], TRUE); gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), ST_PROP); if (gtk_widget_is_toplevel (win)) { g_simple_action_set_enabled (G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (win), "DatasourceDelete")), TRUE); } }
static void watch_parent (gint fd) { GIOChannel *channel; GPollFD fds[1]; GArray *pids_to_kill; channel = g_io_channel_unix_new (fd); fds[0].fd = fd; fds[0].events = G_IO_HUP | G_IO_IN; fds[0].revents = 0; pids_to_kill = g_array_new (FALSE, FALSE, sizeof (guint)); do { gint num_events; gchar *command = NULL; guint pid; guint n; GError *error = NULL; num_events = g_poll (fds, 1, -1); if (num_events == 0) continue; if (fds[0].revents == G_IO_HUP) { /* Parent quit, cleanup the mess and exit */ for (n = 0; n < pids_to_kill->len; n++) { pid = g_array_index (pids_to_kill, guint, n); g_printerr ("cleaning up pid %d\n", pid); kill (pid, SIGTERM); } g_array_unref (pids_to_kill); g_io_channel_shutdown (channel, FALSE, &error); g_assert_no_error (error); g_io_channel_unref (channel); exit (0); } /* Read the command from the input */ g_io_channel_read_line (channel, &command, NULL, NULL, &error); g_assert_no_error (error); /* Check for known commands */ if (sscanf (command, ADD_PID_FORMAT, &pid) == 1) { g_array_append_val (pids_to_kill, pid); } else if (sscanf (command, REMOVE_PID_FORMAT, &pid) == 1) { for (n = 0; n < pids_to_kill->len; n++) { if (g_array_index (pids_to_kill, guint, n) == pid) { g_array_remove_index (pids_to_kill, n); pid = 0; break; } } if (pid != 0) { g_warning ("unknown pid %d to remove", pid); } } else { g_warning ("unknown command from parent '%s'", command); } g_free (command); } while (TRUE); }
/* * Fetch the list of local interfaces with capture_interface_list() * and set the list of "all interfaces" in *capture_opts to include * those interfaces. */ void scan_local_interfaces(void) { GList *if_entry, *lt_entry, *if_list; if_info_t *if_info, *temp; char *if_string; gchar *descr; if_capabilities_t *caps=NULL; gint linktype_count; gboolean monitor_mode; GSList *curr_addr; int ips = 0, i, err; guint count = 0, j; if_addr_t *addr, *temp_addr; link_row *link = NULL; data_link_info_t *data_link_info; interface_t device; GString *ip_str; interface_options interface_opts; gboolean found = FALSE; if (global_capture_opts.all_ifaces->len > 0) { for (i = (int)global_capture_opts.all_ifaces->len-1; i >= 0; i--) { device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); if (device.local && device.type != IF_PIPE && device.type != IF_STDIN) { global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); } } } /* Scan through the list and build a list of strings to display. */ if_list = capture_interface_list(&err, NULL); count = 0; for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) { if_info = (if_info_t *)if_entry->data; ip_str = g_string_new(""); ips = 0; if (strstr(if_info->name, "rpcap:")) { continue; } device.name = g_strdup(if_info->name); if (if_info->friendly_name != NULL) { device.friendly_name = g_strdup(if_info->friendly_name); } else { device.friendly_name = NULL; } device.hidden = FALSE; device.locked = FALSE; temp = (if_info_t *)g_malloc0(sizeof(if_info_t)); temp->name = g_strdup(if_info->name); temp->friendly_name = g_strdup(if_info->friendly_name); temp->vendor_description = g_strdup(if_info->vendor_description); temp->loopback = if_info->loopback; /* Is this interface hidden and, if so, should we include it anyway? */ /* Do we have a user-supplied description? */ descr = capture_dev_user_descr_find(if_info->name); if (descr != NULL) { /* Yes, we have a user-supplied description; use it. */ if_string = g_strdup_printf("%s: %s", descr, if_info->name); g_free(descr); } else { /* No, we don't have a user-supplied description; did we get one from the OS or libpcap? */ if (if_info->friendly_name != NULL) { /* We have a friendly name from the OS, use it */ #ifdef _WIN32 /* * On Windows, if we have a friendly name, just show it, * don't show the name, as that's a string made out of * the device GUID, and not at all friendly. */ if_string = g_strdup_printf("%s", if_info->friendly_name); #else /* * On UN*X, if we have a friendly name, show it along * with the interface name; the interface name is short * and somewhat friendly, and many UN*X users are used * to interface names, so we should show it. */ if_string = g_strdup_printf("%s: %s", if_info->friendly_name, if_info->name); #endif } else if (if_info->vendor_description != NULL) { /* We have a device description from libpcap - use it. */ if_string = g_strdup_printf("%s: %s", if_info->vendor_description, if_info->name); } else { /* No. */ if_string = g_strdup(if_info->name); } } device.display_name = if_string; device.selected = FALSE; if (prefs_is_capture_device_hidden(if_info->name)) { device.hidden = TRUE; } device.type = if_info->type; monitor_mode = prefs_capture_device_monitor_mode(if_info->name); caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL); for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) { temp_addr = (if_addr_t *)g_malloc0(sizeof(if_addr_t)); if (ips != 0) { g_string_append(ip_str, "\n"); } addr = (if_addr_t *)curr_addr->data; if (addr) { temp_addr->ifat_type = addr->ifat_type; switch (addr->ifat_type) { case IF_AT_IPv4: temp_addr->addr.ip4_addr = addr->addr.ip4_addr; g_string_append(ip_str, ip_to_str((guint8 *)&addr->addr.ip4_addr)); break; case IF_AT_IPv6: memcpy(temp_addr->addr.ip6_addr, addr->addr.ip6_addr, sizeof(addr->addr)); g_string_append(ip_str, ip6_to_str((struct e_in6_addr *)&addr->addr.ip6_addr)); break; default: /* In case we add non-IP addresses */ break; } } else { g_free(temp_addr); temp_addr = NULL; } if (temp_addr) { temp->addrs = g_slist_append(temp->addrs, temp_addr); } } #ifdef HAVE_PCAP_REMOTE device.local = TRUE; device.remote_opts.src_type = CAPTURE_IFLOCAL; device.remote_opts.remote_host_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host); device.remote_opts.remote_host_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port); device.remote_opts.remote_host_opts.auth_type = global_capture_opts.default_options.auth_type; device.remote_opts.remote_host_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username); device.remote_opts.remote_host_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password); device.remote_opts.remote_host_opts.datatx_udp = global_capture_opts.default_options.datatx_udp; device.remote_opts.remote_host_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap; device.remote_opts.remote_host_opts.nocap_local = global_capture_opts.default_options.nocap_local; #endif #ifdef HAVE_PCAP_SETSAMPLING device.remote_opts.sampling_method = global_capture_opts.default_options.sampling_method; device.remote_opts.sampling_param = global_capture_opts.default_options.sampling_param; #endif linktype_count = 0; device.links = NULL; if (caps != NULL) { #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = monitor_mode; device.monitor_mode_supported = caps->can_set_rfmon; #endif for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) { data_link_info = (data_link_info_t *)lt_entry->data; if (linktype_count == 0) { device.active_dlt = data_link_info->dlt; } link = (link_row *)g_malloc(sizeof(link_row)); if (data_link_info->description != NULL) { link->dlt = data_link_info->dlt; link->name = g_strdup_printf("%s", data_link_info->description); } else { link->dlt = -1; link->name = g_strdup_printf("%s (not supported)", data_link_info->name); } device.links = g_list_append(device.links, link); linktype_count++; } } else { #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = FALSE; device.monitor_mode_supported = FALSE; #endif device.active_dlt = -1; } device.addresses = g_strdup(ip_str->str); device.no_addresses = ips; device.local = TRUE; device.if_info = *temp; device.last_packets = 0; if ((device.pmode = capture_dev_user_pmode_find(if_info->name)) == -1) { device.pmode = global_capture_opts.default_options.promisc_mode; } if ((device.has_snaplen = capture_dev_user_hassnap_find(if_info->name)) == -1) { device.has_snaplen = global_capture_opts.default_options.has_snaplen; } if (capture_dev_user_snaplen_find(if_info->name) == -1) { device.snaplen = global_capture_opts.default_options.snaplen; } else { device.snaplen = (guint)capture_dev_user_snaplen_find(if_info->name); } device.cfilter = g_strdup(global_capture_opts.default_options.cfilter); #if defined(_WIN32) || defined(HAVE_PCAP_CREATE) if ((device.buffer = capture_dev_user_buffersize_find(if_info->name)) == -1) { device.buffer = global_capture_opts.default_options.buffer_size; } #endif if (global_capture_opts.ifaces->len > 0) { for (j = 0; j < global_capture_opts.ifaces->len; j++) { interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j); if (strcmp(interface_opts.name, device.name) == 0) { #if defined(HAVE_PCAP_CREATE) device.buffer = interface_opts.buffer_size; device.monitor_mode_enabled = interface_opts.monitor_mode; #endif device.pmode = interface_opts.promisc_mode; device.has_snaplen = interface_opts.has_snaplen; device.snaplen = interface_opts.snaplen; device.cfilter = g_strdup(interface_opts.cfilter); if (interface_opts.linktype != -1) { device.active_dlt = interface_opts.linktype; } device.selected = TRUE; global_capture_opts.num_selected++; break; } } } if (global_capture_opts.all_ifaces->len <= count) { g_array_append_val(global_capture_opts.all_ifaces, device); count = global_capture_opts.all_ifaces->len; } else { g_array_insert_val(global_capture_opts.all_ifaces, count, device); } if (caps != NULL) { free_if_capabilities(caps); } g_string_free(ip_str, TRUE); count++; } free_interface_list(if_list); /* see whether there are additional interfaces in ifaces */ for (j = 0; j < global_capture_opts.ifaces->len; j++) { interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j); found = FALSE; for (i = 0; i < (int)global_capture_opts.all_ifaces->len; i++) { device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); if (strcmp(device.name, interface_opts.name) == 0) { found = TRUE; break; } } if (!found) { /* new interface, maybe a pipe */ device.name = g_strdup(interface_opts.name); device.display_name = g_strdup_printf("%s: %s", device.name, interface_opts.descr); device.hidden = FALSE; device.selected = TRUE; device.type = IF_PIPE; #if defined(_WIN32) || defined(HAVE_PCAP_CREATE) device.buffer = interface_opts.buffer_size; #endif #if defined(HAVE_PCAP_CREATE) device.monitor_mode_enabled = interface_opts.monitor_mode; device.monitor_mode_supported = FALSE; #endif device.pmode = interface_opts.promisc_mode; device.has_snaplen = interface_opts.has_snaplen; device.snaplen = interface_opts.snaplen; device.cfilter = g_strdup(interface_opts.cfilter); device.active_dlt = interface_opts.linktype; device.addresses = NULL; device.no_addresses = 0; device.last_packets = 0; device.links = NULL; device.local = TRUE; device.locked = FALSE; device.if_info.name = g_strdup(interface_opts.name); device.if_info.friendly_name = NULL; device.if_info.vendor_description = g_strdup(interface_opts.descr); device.if_info.addrs = NULL; device.if_info.loopback = FALSE; g_array_append_val(global_capture_opts.all_ifaces, device); global_capture_opts.num_selected++; } } }
static gboolean process_nduseropt_dnssl (NMIP6Device *device, struct nd_opt_hdr *opt) { size_t opt_len; struct nd_opt_dnssl *dnssl_opt; unsigned char *opt_ptr; time_t now = time (NULL); GArray *new_domains; NMIP6DNSSL domain, *cur_domain; gboolean changed; guint i; opt_len = opt->nd_opt_len; if (opt_len < 2) return FALSE; dnssl_opt = (struct nd_opt_dnssl *) opt; opt_ptr = (unsigned char *)(dnssl_opt + 1); opt_len = (opt_len - 1) * 8; /* prefer bytes for later handling */ new_domains = g_array_new (FALSE, FALSE, sizeof (NMIP6DNSSL)); changed = FALSE; /* Pad the DNS server expiry somewhat to give a bit of slack in cases * where one RA gets lost or something (which can happen on unreliable * links like wifi where certain types of frames are not retransmitted). * Note that 0 has special meaning and is therefore not adjusted. */ domain.expires = ntohl (dnssl_opt->nd_opt_dnssl_lifetime); if (domain.expires > 0) if (domain.expires < 7200) domain.expires = 7200; domain.expires += now; while (opt_len) { const char *domain_str; domain_str = parse_dnssl_domain (opt_ptr, opt_len); if (domain_str == NULL) { nm_log_dbg (LOGD_IP6, "(%s): invalid DNSSL option, parsing aborted", device->iface); break; } /* The DNSSL encoding of domains happen to occupy the same size * as the length of the resulting string, including terminating * null. */ opt_ptr += strlen (domain_str) + 1; opt_len -= strlen (domain_str) + 1; /* Ignore empty domains. They're probably just padding... */ if (domain_str[0] == '\0') continue; /* Update cached domain information if we've seen this domain before */ for (i = 0; i < device->dnssl_domains->len; i++) { cur_domain = &(g_array_index (device->dnssl_domains, NMIP6DNSSL, i)); if (strcmp (domain_str, cur_domain->domain) != 0) continue; cur_domain->expires = domain.expires; if (domain.expires > 0) { nm_log_dbg (LOGD_IP6, "(%s): refreshing RA-provided domain %s (expires in %ld seconds)", device->iface, domain_str, domain.expires - now); break; } nm_log_dbg (LOGD_IP6, "(%s): removing RA-provided domain %s on router request", device->iface, domain_str); g_array_remove_index (device->dnssl_domains, i); changed = TRUE; break; } if (domain.expires == 0) continue; if (i < device->dnssl_domains->len) continue; nm_log_dbg (LOGD_IP6, "(%s): found RA-provided domain %s (expires in %ld seconds)", device->iface, domain_str, domain.expires - now); g_assert (strlen (domain_str) < sizeof (domain.domain)); strcpy (domain.domain, domain_str); g_array_append_val (new_domains, domain); } /* New domains must be added in the order they are listed in the * RA option and before any existing domains. * * Note: This is the place to remove domains if we want to cap the * number of domains. The RFC states that the one to expire * first of the existing domains should be removed. */ if (new_domains->len) { g_array_prepend_vals (device->dnssl_domains, new_domains->data, new_domains->len); changed = TRUE; } g_array_free (new_domains, TRUE); /* Timeouts may have changed even if domains didn't */ set_dnssl_timeout (device); return changed; }
void summary_fill_in(capture_file *cf, summary_tally *st) { frame_data *first_frame, *cur_frame; guint32 framenum; wtapng_section_t* shb_inf; iface_options iface; guint i; wtapng_iface_descriptions_t* idb_info; wtapng_if_descr_t wtapng_if_descr; wtapng_if_stats_t *if_stats; st->packet_count_ts = 0; st->start_time = 0; st->stop_time = 0; st->bytes = 0; st->filtered_count = 0; st->filtered_count_ts = 0; st->filtered_start = 0; st->filtered_stop = 0; st->filtered_bytes = 0; st->marked_count = 0; st->marked_count_ts = 0; st->marked_start = 0; st->marked_stop = 0; st->marked_bytes = 0; st->ignored_count = 0; /* initialize the tally */ if (cf->count != 0) { first_frame = frame_data_sequence_find(cf->frames, 1); st->start_time = nstime_to_sec(&first_frame->abs_ts); st->stop_time = nstime_to_sec(&first_frame->abs_ts); for (framenum = 1; framenum <= cf->count; framenum++) { cur_frame = frame_data_sequence_find(cf->frames, framenum); tally_frame_data(cur_frame, st); } } st->filename = cf->filename; st->file_length = cf->f_datalen; st->file_type = cf->cd_t; st->iscompressed = cf->iscompressed; st->is_tempfile = cf->is_tempfile; st->file_encap_type = cf->lnk_t; st->packet_encap_types = cf->linktypes; st->has_snap = cf->has_snap; st->snap = cf->snap; st->elapsed_time = nstime_to_sec(&cf->elapsed_time); st->packet_count = cf->count; st->drops_known = cf->drops_known; st->drops = cf->drops; st->dfilter = cf->dfilter; /* Get info from SHB */ shb_inf = wtap_file_get_shb_info(cf->wth); if(shb_inf == NULL){ st->opt_comment = NULL; st->shb_hardware = NULL; st->shb_os = NULL; st->shb_user_appl = NULL; }else{ st->opt_comment = shb_inf->opt_comment; st->shb_hardware = shb_inf->shb_hardware; st->shb_os = shb_inf->shb_os; st->shb_user_appl = shb_inf->shb_user_appl; g_free(shb_inf); } st->ifaces = g_array_new(FALSE, FALSE, sizeof(iface_options)); idb_info = wtap_file_get_idb_info(cf->wth); for (i = 0; i < idb_info->interface_data->len; i++) { wtapng_if_descr = g_array_index(idb_info->interface_data, wtapng_if_descr_t, i); iface.cfilter = g_strdup(wtapng_if_descr.if_filter_str); iface.name = g_strdup(wtapng_if_descr.if_name); iface.descr = g_strdup(wtapng_if_descr.if_description); iface.drops_known = FALSE; iface.drops = 0; iface.snap = wtapng_if_descr.snap_len; iface.has_snap = (iface.snap != 65535); iface.encap_type = wtapng_if_descr.wtap_encap; if(wtapng_if_descr.num_stat_entries == 1){ /* dumpcap only writes one ISB, only handle that for now */ if_stats = &g_array_index(wtapng_if_descr.interface_statistics, wtapng_if_stats_t, 0); iface.drops_known = TRUE; iface.drops = if_stats->isb_ifdrop; iface.isb_comment = if_stats->opt_comment; } g_array_append_val(st->ifaces, iface); } g_free(idb_info); }
static gboolean process_nduseropt_rdnss (NMIP6Device *device, struct nd_opt_hdr *opt) { size_t opt_len; struct nd_opt_rdnss *rdnss_opt; time_t now = time (NULL); struct in6_addr *addr; GArray *new_servers; NMIP6RDNSS server, *cur_server; gboolean changed = FALSE; guint i; opt_len = opt->nd_opt_len; if (opt_len < 3 || (opt_len & 1) == 0) return FALSE; rdnss_opt = (struct nd_opt_rdnss *) opt; new_servers = g_array_new (FALSE, FALSE, sizeof (NMIP6RDNSS)); /* Pad the DNS server expiry somewhat to give a bit of slack in cases * where one RA gets lost or something (which can happen on unreliable * links like WiFi where certain types of frames are not retransmitted). * Note that 0 has special meaning and is therefore not adjusted. */ server.expires = ntohl (rdnss_opt->nd_opt_rdnss_lifetime); if (server.expires > 0) if (server.expires < 7200) server.expires = 7200; server.expires += now; for (addr = (struct in6_addr *) (rdnss_opt + 1); opt_len >= 2; addr++, opt_len -= 2) { char buf[INET6_ADDRSTRLEN + 1]; if (!inet_ntop (AF_INET6, addr, buf, sizeof (buf))) { nm_log_warn (LOGD_IP6, "(%s): received invalid RA-provided nameserver", device->iface); continue; } /* Update the cached timeout if we already saw this server */ for (i = 0; i < device->rdnss_servers->len; i++) { cur_server = &(g_array_index (device->rdnss_servers, NMIP6RDNSS, i)); if (!IN6_ARE_ADDR_EQUAL (addr, &cur_server->addr)) continue; cur_server->expires = server.expires; if (server.expires > 0) { nm_log_dbg (LOGD_IP6, "(%s): refreshing RA-provided nameserver %s (expires in %ld seconds)", device->iface, buf, server.expires - now); break; } nm_log_dbg (LOGD_IP6, "(%s): removing RA-provided nameserver %s on router request", device->iface, buf); g_array_remove_index (device->rdnss_servers, i); changed = TRUE; break; } if (server.expires == 0) continue; if (i < device->rdnss_servers->len) continue; nm_log_dbg (LOGD_IP6, "(%s): found RA-provided nameserver %s (expires in %ld seconds)", device->iface, buf, server.expires - now); server.addr = *addr; g_array_append_val (new_servers, server); } /* New servers must be added in the order they are listed in the * RA option and before any existing servers. * * Note: This is the place to remove servers if we want to cap the * number of resolvers. The RFC states that the one to expire * first of the existing servers should be removed. */ if (new_servers->len) { g_array_prepend_vals (device->rdnss_servers, new_servers->data, new_servers->len); changed = TRUE; } g_array_free (new_servers, TRUE); /* Timeouts may have changed even if IPs didn't */ set_rdnss_timeout (device); return changed; }
void gimp_channel_select_vectors (GimpChannel *channel, const gchar *undo_desc, GimpVectors *vectors, GimpChannelOps op, gboolean antialias, gboolean feather, gdouble feather_radius_x, gdouble feather_radius_y, gboolean push_undo) { GimpScanConvert *scan_convert; GList *stroke; gboolean coords_added = FALSE; g_return_if_fail (GIMP_IS_CHANNEL (channel)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (channel))); g_return_if_fail (undo_desc != NULL); g_return_if_fail (GIMP_IS_VECTORS (vectors)); scan_convert = gimp_scan_convert_new (); for (stroke = vectors->strokes; stroke; stroke = stroke->next) { GArray *coords; gboolean closed; coords = gimp_stroke_interpolate (GIMP_STROKE (stroke->data), 1.0, &closed); if (coords && coords->len) { GimpVector2 *points; gint i; points = g_new0 (GimpVector2, coords->len); for (i = 0; i < coords->len; i++) { points[i].x = g_array_index (coords, GimpCoords, i).x; points[i].y = g_array_index (coords, GimpCoords, i).y; } gimp_scan_convert_add_polyline (scan_convert, coords->len, points, TRUE); coords_added = TRUE; g_free (points); } if (coords) g_array_free (coords, TRUE); } if (coords_added) gimp_channel_select_scan_convert (channel, undo_desc, scan_convert, 0, 0, op, antialias, feather, feather_radius_x, feather_radius_y, push_undo); gimp_scan_convert_free (scan_convert); }
bool PinyinLookup::search_bigram(IBranchIterator * iter, int nstep, int npinyin){ lookup_constraint_t* constraint = &g_array_index(m_constraints, lookup_constraint_t, nstep); if ( CONSTRAINT_NOSEARCH == constraint->m_type ) return false; GArray * lookup_content = (GArray *) g_ptr_array_index(m_steps_content, nstep); bool found = false; BigramPhraseArray bigram_phrase_items = g_array_new(FALSE, FALSE, sizeof(BigramPhraseItem)); while ( iter->has_next() ){ lookup_value_t cur_step = iter->next(); //printf("token:%d\t%d\n", cur_step.m_handles[0], cur_step.m_handles[1]); phrase_token_t index_token = cur_step.m_handles[1]; SingleGram * system, * user; m_bigram->load(index_token, system, user); if ( system && user ){ guint32 total_freq; assert(user->get_total_freq(total_freq)); assert(system->set_total_freq(total_freq)); } if ( CONSTRAINT_ONESTEP == constraint->m_type ){ phrase_token_t token = constraint->m_token; if ( system ){ guint32 freq; if( system->get_freq(token, freq) ){ guint32 total_freq; system->get_total_freq(total_freq); gfloat bigram_poss = freq / (gfloat) total_freq; found = bigram_gen_next_step(nstep, &cur_step, token, bigram_poss) || found; } } if ( user ){ guint32 freq; if( user->get_freq(token, freq)){ guint32 total_freq; user->get_total_freq(total_freq); gfloat bigram_poss = freq / (gfloat) total_freq; found = bigram_gen_next_step(nstep, &cur_step, token, bigram_poss) || found; } } } if ( NO_CONSTRAINT == constraint->m_type ){ for ( size_t i = 1; i < m_table_cache->len && i <= MAX_PHRASE_LENGTH;++i ){ lookup_constraint_t * constraint = &g_array_index(m_constraints, lookup_constraint_t, nstep + i - 1); if ( constraint->m_type != NO_CONSTRAINT ) continue; PhraseIndexRanges * ranges = &g_array_index(m_table_cache, PhraseIndexRanges, i); for( size_t m = 0; m < PHRASE_INDEX_LIBRARY_COUNT; ++m){ GArray * array = (*ranges)[m]; if ( !array ) continue; for ( size_t n = 0; n < array->len; ++n){ PhraseIndexRange * range = &g_array_index(array, PhraseIndexRange, n); if (system){ g_array_set_size(bigram_phrase_items, 0); system->search(range, bigram_phrase_items); for( size_t k = 0; k < bigram_phrase_items->len; ++k){ BigramPhraseItem * item = &g_array_index(bigram_phrase_items, BigramPhraseItem, k); found = bigram_gen_next_step(nstep, &cur_step, item->m_token, item->m_freq) || found; } } if (user){ g_array_set_size(bigram_phrase_items, 0); user->search(range, bigram_phrase_items); for( size_t k = 0; k < bigram_phrase_items->len; ++k){ BigramPhraseItem * item = &g_array_index(bigram_phrase_items, BigramPhraseItem, k); found = bigram_gen_next_step(nstep, &cur_step, item->m_token, item->m_freq) || found; } } } } } } if (system) delete system; if (user) delete user; } g_array_free(bigram_phrase_items, TRUE); return found; }
/* * Create clone IDBs for the merge file, based on the input files and mode. */ static wtapng_iface_descriptions_t * generate_merged_idb(merge_in_file_t *in_files, const guint in_file_count, const idb_merge_mode mode) { wtapng_iface_descriptions_t *merged_idb_list = NULL; wtapng_iface_descriptions_t *input_file_idb_list = NULL; wtap_block_t input_file_idb; guint itf_count, merged_index; guint i; /* create new IDB info */ merged_idb_list = g_new(wtapng_iface_descriptions_t,1); merged_idb_list->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); if (mode == IDB_MERGE_MODE_ALL_SAME && all_idbs_are_duplicates(in_files, in_file_count)) { guint num_idbs; merge_debug("merge::generate_merged_idb: mode ALL set and all IDBs are duplicates"); /* they're all the same, so just get the first file's IDBs */ input_file_idb_list = wtap_file_get_idb_info(in_files[0].wth); /* this is really one more than number of IDBs, but that's good for the for-loops */ num_idbs = input_file_idb_list->interface_data->len; /* put them in the merged file */ for (itf_count = 0; itf_count < num_idbs; itf_count++) { input_file_idb = g_array_index(input_file_idb_list->interface_data, wtap_block_t, itf_count); merged_index = add_idb_to_merged_file(merged_idb_list, input_file_idb); add_idb_index_map(&in_files[0], itf_count, merged_index); } /* and set all the other file index maps the same way */ for (i = 1; i < in_file_count; i++) { for (itf_count = 0; itf_count < num_idbs; itf_count++) { add_idb_index_map(&in_files[i], itf_count, itf_count); } } g_free(input_file_idb_list); } else { for (i = 0; i < in_file_count; i++) { input_file_idb_list = wtap_file_get_idb_info(in_files[i].wth); for (itf_count = 0; itf_count < input_file_idb_list->interface_data->len; itf_count++) { input_file_idb = g_array_index(input_file_idb_list->interface_data, wtap_block_t, itf_count); if (mode == IDB_MERGE_MODE_ANY_SAME && find_duplicate_idb(input_file_idb, merged_idb_list, &merged_index)) { merge_debug("merge::generate_merged_idb: mode ANY set and found a duplicate"); /* * It's the same as a previous IDB, so we're going to "merge" * them into one by adding a map from its old IDB index to the new * one. This will be used later to change the phdr interface_id. */ add_idb_index_map(&in_files[i], itf_count, merged_index); } else { merge_debug("merge::generate_merged_idb: mode NONE set or did not find a duplicate"); /* * This IDB does not match a previous (or we want to save all IDBs), * so add the IDB to the merge file, and add a map of the indeces. */ merged_index = add_idb_to_merged_file(merged_idb_list, input_file_idb); add_idb_index_map(&in_files[i], itf_count, merged_index); } } g_free(input_file_idb_list); } } return merged_idb_list; }
/** * Start a capture. * * @return TRUE if the capture starts successfully, FALSE otherwise. */ gboolean capture_start(capture_options *capture_opts, capture_session *cap_session) { gboolean ret; guint i; GString *source = g_string_new(""); cap_session->state = CAPTURE_PREPARING; g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start ..."); #ifdef _WIN32 if (capture_opts->ifaces->len < 2) { #else if (capture_opts->ifaces->len < 4) { #endif for (i = 0; i < capture_opts->ifaces->len; i++) { interface_options interface_opts; interface_opts = g_array_index(capture_opts->ifaces, interface_options, i); if (i > 0) { if (capture_opts->ifaces->len > 2) { g_string_append_printf(source, ","); } g_string_append_printf(source, " "); if (i == capture_opts->ifaces->len - 1) { g_string_append_printf(source, "and "); } } g_string_append_printf(source, "%s", get_iface_description_for_interface(capture_opts, i)); if ((interface_opts.cfilter != NULL) && (strlen(interface_opts.cfilter) > 0)) { g_string_append_printf(source, " (%s)", interface_opts.cfilter); } } } else { g_string_append_printf(source, "%u interfaces", capture_opts->ifaces->len); } cf_set_tempfile_source((capture_file *)cap_session->cf, source->str); g_string_free(source, TRUE); /* try to start the capture child process */ ret = sync_pipe_start(capture_opts, cap_session); if(!ret) { if(capture_opts->save_file != NULL) { g_free(capture_opts->save_file); capture_opts->save_file = NULL; } g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start failed!"); cap_session->state = CAPTURE_STOPPED; } else { /* the capture child might not respond shortly after bringing it up */ /* (for example: it will block if no input arrives from an input capture pipe (e.g. mkfifo)) */ /* to prevent problems, bring the main GUI into "capture mode" right after a successful */ /* spawn/exec of the capture child, without waiting for any response from it */ capture_callback_invoke(capture_cb_capture_prepared, cap_session); if(capture_opts->show_info) capture_info_open(cap_session); } return ret; } void capture_stop(capture_session *cap_session) { g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Stop ..."); capture_callback_invoke(capture_cb_capture_stopping, cap_session); /* stop the capture child gracefully */ sync_pipe_stop(cap_session); }
static GtkCssImage * gtk_css_image_radial_transition (GtkCssImage *start_image, GtkCssImage *end_image, guint property_id, double progress) { GtkCssImageRadial *start, *end, *result; guint i; start = GTK_CSS_IMAGE_RADIAL (start_image); if (end_image == NULL) return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress); if (!GTK_IS_CSS_IMAGE_RADIAL (end_image)) return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress); end = GTK_CSS_IMAGE_RADIAL (end_image); if (start->repeating != end->repeating || start->stops->len != end->stops->len || start->size != end->size || start->circle != end->circle) return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress); result = g_object_new (GTK_TYPE_CSS_IMAGE_RADIAL, NULL); result->repeating = start->repeating; result->circle = start->circle; result->size = start->size; result->position = _gtk_css_value_transition (start->position, end->position, property_id, progress); if (result->position == NULL) goto fail; if (start->sizes[0] && end->sizes[0]) { result->sizes[0] = _gtk_css_value_transition (start->sizes[0], end->sizes[0], property_id, progress); if (result->sizes[0] == NULL) goto fail; } else result->sizes[0] = 0; if (start->sizes[1] && end->sizes[1]) { result->sizes[1] = _gtk_css_value_transition (start->sizes[1], end->sizes[1], property_id, progress); if (result->sizes[1] == NULL) goto fail; } else result->sizes[1] = 0; for (i = 0; i < start->stops->len; i++) { GtkCssImageRadialColorStop stop, *start_stop, *end_stop; start_stop = &g_array_index (start->stops, GtkCssImageRadialColorStop, i); end_stop = &g_array_index (end->stops, GtkCssImageRadialColorStop, i); if ((start_stop->offset != NULL) != (end_stop->offset != NULL)) goto fail; if (start_stop->offset == NULL) { stop.offset = NULL; } else { stop.offset = _gtk_css_value_transition (start_stop->offset, end_stop->offset, property_id, progress); if (stop.offset == NULL) goto fail; } stop.color = _gtk_css_value_transition (start_stop->color, end_stop->color, property_id, progress); if (stop.color == NULL) { if (stop.offset) _gtk_css_value_unref (stop.offset); goto fail; } g_array_append_val (result->stops, stop); } return GTK_CSS_IMAGE (result); fail: g_object_unref (result); return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress); }
/** * fuzzy_match: * @fuzzy: (in): A #Fuzzy. * @needle: (in): The needle to fuzzy search for. * @max_matches: (in): The max number of matches to return. * * Fuzzy searches within @fuzzy for strings that fuzzy match @needle. * Only up to @max_matches will be returned. * * @needle MUST be an ascii string. * * TODO: max_matches is not yet respected. * * Returns: (transfer full) (element-type FuzzyMatch): A newly allocated * #GArray containing #FuzzyMatch elements. This should be freed when * the caller is done with it using g_array_unref(). * It is a programming error to keep the structure around longer than * the @fuzzy instance. */ GArray * fuzzy_match (Fuzzy *fuzzy, const gchar *needle, gsize max_matches) { FuzzyLookup lookup = { 0 }; FuzzyMatch match; FuzzyItem *item; GArray *matches = NULL; GArray *root; gchar *downcase = NULL; gint i; g_return_val_if_fail(fuzzy, NULL); g_return_val_if_fail(!fuzzy->in_bulk_insert, NULL); g_return_val_if_fail(needle, NULL); matches = g_array_new(FALSE, FALSE, sizeof(FuzzyMatch)); if (!*needle) { return matches; } if (!fuzzy->case_sensitive) { downcase = g_ascii_strdown(needle, -1); needle = downcase; } lookup.fuzzy = fuzzy; lookup.n_tables = strlen(needle); lookup.state = g_new0(gint, lookup.n_tables); lookup.tables = g_new0(GArray*, lookup.n_tables); lookup.needle = needle; lookup.max_matches = max_matches; lookup.matches = g_hash_table_new(NULL, NULL); for (i = 0; needle[i]; i++) { lookup.tables[i] = g_ptr_array_index(fuzzy->char_tables, (guint)needle[i]); } root = g_ptr_array_index(fuzzy->char_tables, (guint)needle[0]); if (G_LIKELY(lookup.n_tables > 1)) { for (i = 0; i < root->len; i++) { item = &g_array_index(root, FuzzyItem, i); fuzzy_do_match(&lookup, item, 1, 0); } } else { for (i = 0; i < root->len; i++) { item = &g_array_index(root, FuzzyItem, i); match.key = fuzzy_get_string(fuzzy, item->id); match.value = g_ptr_array_index(fuzzy->id_to_value, item->id); match.score = 0; g_array_append_val(matches, match); } g_free(downcase); return matches; } { GHashTableIter iter; gpointer key; gpointer value; g_hash_table_iter_init(&iter, lookup.matches); while (g_hash_table_iter_next(&iter, &key, &value)) { match.key = fuzzy_get_string(fuzzy, GPOINTER_TO_INT(key)); match.score = 1.0 / (strlen(match.key) + GPOINTER_TO_INT(value)); match.value = g_ptr_array_index(fuzzy->id_to_value, GPOINTER_TO_INT(key)); g_array_append_val(matches, match); } g_array_sort(matches, fuzzy_match_compare); /* * TODO: We could be more clever here when inserting into the array * only if it is a lower score than the end or < max items. */ if (max_matches && (matches->len > max_matches)) { g_array_set_size(matches, max_matches); } } g_free(downcase); g_free(lookup.state); g_free(lookup.tables); g_hash_table_unref(lookup.matches); return matches; }
void so__dlg_preferences_construct_cb (GtkWidget *dialog, GthBrowser *browser, GtkBuilder *dialog_builder) { BrowserData *data; GtkWidget *notebook; GtkWidget *page; GtkListStore *model; GArray *pixbuf_saver_types; int i; GtkTreeSelection *treeselection; GtkTreePath *path; GtkWidget *label; data = g_new0 (BrowserData, 1); data->builder = _gtk_builder_new_from_file ("save-options-preferences.ui", "pixbuf_savers"); notebook = _gtk_builder_get_widget (dialog_builder, "notebook"); page = _gtk_builder_get_widget (data->builder, "preferences_page"); gtk_widget_show (page); model = (GtkListStore *) gtk_builder_get_object (data->builder, "file_type_liststore"); pixbuf_saver_types = gth_main_get_type_set ("pixbuf-saver"); for (i = 0; (pixbuf_saver_types != NULL) && (i < pixbuf_saver_types->len); i++) { GthPixbufSaver *pixbuf_saver; GtkTreeIter iter; GtkWidget *options; pixbuf_saver = g_object_new (g_array_index (pixbuf_saver_types, GType, i), NULL); gtk_list_store_append (model, &iter); gtk_list_store_set (model, &iter, FILE_TYPE_COLUMN_N, i, FILE_TYPE_COLUMN_OBJ, pixbuf_saver, FILE_TYPE_COLUMN_DISPLAY_NAME, gth_pixbuf_saver_get_display_name (pixbuf_saver), -1); options = gth_pixbuf_saver_get_control (pixbuf_saver); gtk_widget_show (options); gtk_notebook_append_page (GTK_NOTEBOOK (_gtk_builder_get_widget (data->builder, "options_notebook")), options, NULL); data->pixbuf_saver = g_list_prepend (data->pixbuf_saver, pixbuf_saver); } treeselection = gtk_tree_view_get_selection (GTK_TREE_VIEW (_gtk_builder_get_widget (data->builder, "file_type_treeview"))); gtk_tree_selection_set_mode (treeselection, GTK_SELECTION_BROWSE); g_signal_connect (treeselection, "changed", G_CALLBACK (treeselection_changed_cb), dialog); label = gtk_label_new (_("Saving")); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label); g_object_set_data_full (G_OBJECT (dialog), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free); path = gtk_tree_path_new_first (); gtk_tree_selection_select_path (treeselection, path); gtk_tree_path_free (path); }
void cell_edited_callback(GtkCellRendererText *cell, const gchar *path_string, gchar *new_text, gpointer data) { GtkTreeModel *model = (GtkTreeModel *)data; GtkTreePath *path = gtk_tree_path_new_from_string(path_string); GtkTreeIter iter; GtkTreeIter iter_name; gchar *col_name; char new_ip[20]; strcpy(new_ip, new_text); gint column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cell), "column")); gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get_iter(model, &iter_name, path); gtk_tree_model_get(model, &iter_name, 0, &col_name, -1); switch (column) { case COLUMN_VALUE: { uint i = 0, index_offset = 0; gchar *old_text; gtk_tree_model_get(model, &iter, column, &old_text, -1); if (0 == strcmp(col_name, pktgen_ethernet_fields[3])) if ((atoi(new_text) > 4096) || (atoi(new_text) < 1)) { GtkWidget *dialog; dialog = gtk_message_dialog_new(GTK_WINDOW(stream_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Invalid VLAN Id! It should be [1-4095]"); gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; } if ((0 == strcmp(col_name, pktgen_ipv4_fields[9])) || (0 == strcmp(col_name, pktgen_ipv4_fields[10])) ) if (!validate_ip_address(new_ip)) { GtkWidget *dialog; dialog = gtk_message_dialog_new(GTK_WINDOW(stream_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "The given IP is not a valid IP address!"); gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; } /* Validate the MAC address */ if ((0 == strcmp(col_name, pktgen_ethernet_fields[0])) || (0 == strcmp(col_name, pktgen_ethernet_fields[1])) ) { if (12 == strlen(new_text)) { gchar *ch; for (i = 0; i < strlen(new_text); i++) { ch = (new_text + i); if ((*ch >= 'a' && *ch <= 'f') || (*ch >= 'A' && *ch <= 'F') || (*ch >= '0' && *ch <= '9')) continue; else { GtkWidget *dialog; dialog = gtk_message_dialog_new( GTK_WINDOW(stream_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Please input only hex values[0-9][a-f], special characters are not allowed!"); gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; } } } else { GtkWidget *dialog; dialog = gtk_message_dialog_new(GTK_WINDOW(stream_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Please input 6 bytes of MAC address in hex pattern [e.g. 012345abcdef]"); gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; } } if ((0 != strcmp(old_text, "<auto>")) && (0 != strcmp(old_text, "IPv4")) && (0 != strcmp(old_text, "UDP")) ) { g_free(old_text); i = gtk_tree_path_get_indices(path)[0]; switch (gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook))) { case 0: index_offset = 0; break; case 1: index_offset = 4; break; case 2: index_offset = 15; break; } g_free(g_array_index(packet_info, protocol, (i + index_offset)).value); g_array_index(packet_info, protocol, (i + index_offset)).value = g_strdup(new_text); gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, g_array_index(packet_info, protocol, (i + index_offset)).value, -1); } else { GtkWidget *dialog; dialog = gtk_message_dialog_new(GTK_WINDOW(stream_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Auto generated values can not be modified!"); gtk_window_set_title(GTK_WINDOW(dialog), "Pktgen"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } } break; } gtk_tree_path_free(path); }