// got_invite(from, to, reason, passwd, reply) // This function should be called when receiving an invitation from user // "from", to enter the room "to". Optional reason and room password can // be provided. void got_invite(const char* from, const char *to, const char* reason, const char* passwd, gboolean reply) { GString *sbuf; char *barejid; GSList *room_elt; sbuf = g_string_new(""); if (reason && reason[0]) { g_string_printf(sbuf, "Received an invitation to <%s>, from <%s>, reason: %s", to, from, reason); } else { g_string_printf(sbuf, "Received an invitation to <%s>, from <%s>", to, from); } barejid = jidtodisp(from); scr_WriteIncomingMessage(barejid, sbuf->str, 0, HBB_PREFIX_INFO, 0); scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str); { // remove any equal older invites GSList *iel = invitations; while (iel) { event_muc_invitation *invitation = iel->data; iel = iel -> next; if (!g_strcmp0(to, invitation->to) && !g_strcmp0(passwd, invitation->passwd)) { // found a previous invitation // We keep the old one, unless the current one is better and allows us // to send a reply. if (!reply || invitation->reply) { g_free(barejid); return; } scr_LogPrint(LPRINT_DEBUG, "Destroying previous invitation event %s.", invitation->evid); evs_del(invitation->evid); } } } { // create event const char *id; char *desc = g_strdup_printf("<%s> invites you to %s", from, to); event_muc_invitation *invitation; invitation = g_new(event_muc_invitation, 1); invitation->to = g_strdup(to); invitation->from = g_strdup(from); invitation->passwd = g_strdup(passwd); invitation->reason = g_strdup(reason); invitation->reply = reply; invitation->evid = NULL; invitations = g_slist_append(invitations, invitation); id = evs_new(desc, NULL, 0, evscallback_invitation, invitation, (GDestroyNotify)destroy_event_muc_invitation); g_free(desc); if (id) { invitation->evid = g_strdup(id); g_string_printf(sbuf, "Please use /event %s accept|reject", id); } else g_string_printf(sbuf, "Unable to create a new event!"); } scr_WriteIncomingMessage(barejid, sbuf->str, 0, HBB_PREFIX_INFO, 0); scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str); g_string_free(sbuf, TRUE); g_free(barejid); // Make sure the MUC room barejid is a room in the roster barejid = jidtodisp(to); room_elt = roster_find(barejid, jidsearch, 0); if (room_elt) buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); g_free(barejid); }
/** * get the content in the form, and set it in a list composed * of each element with their content (list of struct content_element * * \param * * \return a newly allocated list * */ GSList *gsb_form_scheduler_get_content_list ( void ) { GSList *content_list = NULL; GSList *tmp_list; tmp_list = gsb_form_widget_get_list (); while (tmp_list) { struct_element *element; element = tmp_list -> data; if (GTK_WIDGET_VISIBLE (element -> element_widget)) { content_element *element_save; switch (element -> element_number) { /* first, check the entries */ case TRANSACTION_FORM_DATE: case TRANSACTION_FORM_VALUE_DATE: case TRANSACTION_FORM_DEBIT: case TRANSACTION_FORM_CREDIT: case TRANSACTION_FORM_NOTES: case TRANSACTION_FORM_BANK: case TRANSACTION_FORM_VOUCHER: if (!gsb_form_widget_check_empty (element -> element_widget)) { element_save = g_malloc0 (sizeof (content_element)); element_save -> element_number = element -> element_number; element_save -> element_string = my_strdup (gtk_entry_get_text (GTK_ENTRY (element -> element_widget))); content_list = g_slist_append ( content_list, element_save ); } break; case TRANSACTION_FORM_TYPE: element_save = g_malloc0 (sizeof (content_element)); element_save -> element_number = element -> element_number; element_save -> element_int = gsb_payment_method_get_selected_number (element -> element_widget); content_list = g_slist_append ( content_list, element_save ); break; case TRANSACTION_FORM_CONTRA: element_save = g_malloc0 (sizeof (content_element)); element_save -> element_number = element -> element_number; element_save -> element_int = gsb_payment_method_get_selected_number (element -> element_widget); content_list = g_slist_append ( content_list, element_save ); break; case TRANSACTION_FORM_EXERCICE: element_save = g_malloc0 (sizeof (content_element)); element_save -> element_number = element -> element_number; element_save -> element_int = gsb_fyear_get_fyear_from_combobox ( element -> element_widget, NULL ); content_list = g_slist_append ( content_list, element_save ); break; case TRANSACTION_FORM_DEVISE: element_save = g_malloc0 (sizeof (content_element)); element_save -> element_number = element -> element_number; element_save -> element_int = gsb_currency_get_currency_from_combobox (element -> element_widget); content_list = g_slist_append ( content_list, element_save ); break; /* check the combofix */ case TRANSACTION_FORM_PARTY: case TRANSACTION_FORM_CATEGORY: case TRANSACTION_FORM_BUDGET: if (!gsb_form_widget_check_empty (GTK_COMBOFIX (element -> element_widget) -> entry)) { element_save = g_malloc0 (sizeof (content_element)); element_save -> element_number = element -> element_number; element_save -> element_string = my_strdup (gtk_combofix_get_text (GTK_COMBOFIX (element -> element_widget))); content_list = g_slist_append ( content_list, element_save ); } break; } } tmp_list = tmp_list -> next; } return content_list; }
static void get_devices (NAApplication *application) { int i; NMClient *nm_client = nm_client_new (); const GPtrArray *nm_connections = nm_client_get_active_connections (nm_client); for (i = 0; i < nm_connections->len; i++) { NMActiveConnection *active_conn = NM_ACTIVE_CONNECTION (g_ptr_array_index (nm_connections, i)); g_debug ("Active connection: %s", nm_active_connection_get_connection (active_conn)); } const GPtrArray *nm_devices = nm_client_get_devices (nm_client); for (i = 0; i < nm_devices->len; i++) { NMDevice *nm_device = NM_DEVICE (g_ptr_array_index (nm_devices, i)); if (nm_device_get_state (nm_device) == NM_DEVICE_STATE_ACTIVATED) { const char *iface = nm_device_get_iface (nm_device); const char *ip_iface = nm_device_get_ip_iface (nm_device); g_debug ("Active device found: %s with ip iface %s", iface, ip_iface); NMIP4Config *ip4_config = nm_device_get_ip4_config (nm_device); if (ip4_config != NULL) { const GSList *ip4_addresses = nm_ip4_config_get_addresses (ip4_config); const GSList *iter = ip4_addresses; while (iter != NULL) { guint32 address = nm_ip4_address_get_address ((NMIP4Address *)iter->data); struct in_addr addr = { address, }; char *str_addr = g_new (char, INET_ADDRSTRLEN); inet_ntop (AF_INET, &addr, str_addr, INET_ADDRSTRLEN); add_local_address (str_addr); g_debug ("Adding local IP4 address %s", str_addr); iter = iter->next; } } NMIP6Config *ip6_config = nm_device_get_ip6_config (nm_device); if (ip6_config != NULL) { const GSList *ip6_addresses = nm_ip6_config_get_addresses (ip6_config); const GSList *iter = ip6_addresses; while (iter != NULL) { const struct in6_addr *address = nm_ip6_address_get_address ((NMIP6Address *)iter->data); char *str_addr = g_new (char, INET6_ADDRSTRLEN); inet_ntop (AF_INET6, address, str_addr, INET6_ADDRSTRLEN); add_local_address (str_addr); g_debug ("Adding local IP6 address %s", str_addr); iter = iter->next; } } GError *error = NULL; NAPCapHandle *handle = na_pcap_open (iface, &error); if (handle != NULL) { application->priv->iface_handles = g_slist_append (application->priv->iface_handles, handle); } else { g_debug ("Error opening handler for interface %s: %s\n", iface, error->message); g_error_free (error); } } } }
static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen, gpointer user_data) { struct discover_primary *dp = user_data; struct att_data_list *list; unsigned int i, err; uint16_t start, end; if (status) { err = status == ATT_ECODE_ATTR_NOT_FOUND ? 0 : status; goto done; } list = dec_read_by_grp_resp(ipdu, iplen); if (list == NULL) { err = ATT_ECODE_IO; goto done; } for (i = 0, end = 0; i < list->num; i++) { const uint8_t *data = list->data[i]; struct gatt_primary *primary; bt_uuid_t uuid; start = att_get_u16(&data[0]); end = att_get_u16(&data[2]); if (list->len == 6) { bt_uuid_t uuid16 = att_get_uuid16(&data[4]); bt_uuid_to_uuid128(&uuid16, &uuid); } else if (list->len == 20) { uuid = att_get_uuid128(&data[4]); } else { /* Skipping invalid data */ continue; } primary = g_try_new0(struct gatt_primary, 1); if (!primary) { err = ATT_ECODE_INSUFF_RESOURCES; goto done; } primary->range.start = start; primary->range.end = end; bt_uuid_to_string(&uuid, primary->uuid, sizeof(primary->uuid)); dp->primaries = g_slist_append(dp->primaries, primary); } att_data_list_free(list); err = 0; if (end != 0xffff) { size_t buflen; uint8_t *buf = g_attrib_get_buffer(dp->attrib, &buflen); guint16 oplen = encode_discover_primary(end + 1, 0xffff, NULL, buf, buflen); g_attrib_send(dp->attrib, 0, buf[0], buf, oplen, primary_all_cb, dp, NULL); return; } done: dp->cb(dp->primaries, err, dp->user_data); discover_primary_free(dp); }
static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; struct sr_serial_dev_inst *serial; GSList *l, *devices; int len, i; const char *conn, *serialcomm; char *buf, **tokens; drvc = di->context; drvc->instances = NULL; devices = NULL; conn = serialcomm = NULL; for (l = options; l; l = l->next) { src = l->data; switch (src->key) { case SR_CONF_CONN: conn = g_variant_get_string(src->data, NULL); break; case SR_CONF_SERIALCOMM: serialcomm = g_variant_get_string(src->data, NULL); break; } } if (!conn) return NULL; if (!serialcomm) serialcomm = SERIALCOMM; serial = sr_serial_dev_inst_new(conn, serialcomm); if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; serial_flush(serial); if (serial_write_blocking(serial, "*IDN?\r\n", 7, SERIAL_WRITE_TIMEOUT_MS) < 7) { sr_err("Unable to send identification string."); return NULL; } len = 128; buf = g_malloc(len); serial_readline(serial, &buf, &len, 250); if (!len) return NULL; tokens = g_strsplit(buf, ",", 4); if (!strcmp("Agilent Technologies", tokens[0]) && tokens[1] && tokens[2] && tokens[3]) { for (i = 0; supported_agdmm[i].model; i++) { if (strcmp(supported_agdmm[i].modelname, tokens[1])) continue; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup("Agilent"); sdi->model = g_strdup(tokens[1]); sdi->version = g_strdup(tokens[3]); devc = g_malloc0(sizeof(struct dev_context)); devc->profile = &supported_agdmm[i]; devc->cur_mq = -1; sdi->inst_type = SR_INST_SERIAL; sdi->conn = serial; sdi->priv = devc; sdi->driver = di; sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; } } g_strfreev(tokens); g_free(buf); serial_close(serial); if (!devices) sr_serial_dev_inst_free(serial); return devices; }
static PartitionTable * part_table_parse_msdos_extended (int fd, guint64 offset, guint64 size) { int n; PartitionTable *p; guint64 next; //HAL_INFO (("Entering MS-DOS extended parser")); p = NULL; next = offset; while (next != 0) { guint64 readfrom; const guint8 embr[512]; readfrom = next; next = 0; //HAL_INFO (("readfrom = %lld", readfrom)); if (lseek (fd, readfrom, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, &embr, sizeof (embr)) != sizeof (embr)) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } if (memcmp (&embr[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0) { HAL_INFO (("No MSDOS_MAGIC found")); goto out; } //HAL_INFO (("MSDOS_MAGIC found")); if (p == NULL) { p = part_table_new_empty (PART_TYPE_MSDOS_EXTENDED); p->offset = offset; p->size = size; } for (n = 0; n < 2; n++) { PartitionEntry *pe; guint64 pstart; guint64 psize; pstart = 0x200 * ((guint64) get_le32 (&(embr[MSDOS_PARTTABLE_OFFSET + n * 16 + 8]))); psize = 0x200 * ((guint64) get_le32 (&(embr[MSDOS_PARTTABLE_OFFSET + n * 16 + 12]))); if (psize == 0) continue; pe = NULL; if (n == 0) { //HAL_INFO (("part %d (offset %lld, size %lld, type 0x%02x)", // n, readfrom + pstart, psize, ptype)); //HAL_INFO (("pstart = %lld", pstart)); //hexdump (&(embr[MSDOS_PARTTABLE_OFFSET + n * 16]), 16); pe = part_entry_new (NULL, &(embr[MSDOS_PARTTABLE_OFFSET + n * 16]), 16, readfrom + MSDOS_PARTTABLE_OFFSET + n * 16); } else { if (pstart != 0) { //HAL_INFO (("found chain at offset %lld", offset + pstart); next = offset + pstart; } } //HAL_INFO (("pe = %p", pe)); if (pe != NULL) { p->entries = g_slist_append (p->entries, pe); } } } out: //HAL_INFO (("Exiting MS-DOS extended parser")); return p; }
static PartitionTable * part_table_parse_gpt (int fd, guint64 offset, guint64 size) { int n; PartitionTable *p; guint8 buf[16]; guint64 partition_entry_lba; int num_entries; int size_of_entry; HAL_INFO (("Entering EFI GPT parser")); /* by way of getting here, we've already checked for a protective MBR */ p = NULL; /* Check GPT signature */ if (lseek (fd, offset + 512 + 0, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, buf, 8) != 8) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } if (memcmp (buf, GPT_MAGIC, 8) != 0) { HAL_INFO (("No GPT_MAGIC found")); goto out; } HAL_INFO (("GPT magic found")); /* Disk UUID */ if (lseek (fd, offset + 512 + 56, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, buf, 16) != 16) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } //hexdump ((guint8*) buf, 16); if (lseek (fd, offset + 512 + 72, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, buf, 8) != 8) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } partition_entry_lba = get_le64 (buf); if (lseek (fd, offset + 512 + 80, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, buf, 4) != 4) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } num_entries = get_le32 (buf); if (lseek (fd, offset + 512 + 84, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, buf, 4) != 4) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } size_of_entry = get_le32(buf); p = part_table_new_empty (PART_TYPE_GPT); p->offset = offset; p->size = size; HAL_INFO (("partition_entry_lba=%d", partition_entry_lba)); HAL_INFO (("num_entries=%d", num_entries)); HAL_INFO (("size_of_entry=%d", size_of_entry)); for (n = 0; n < num_entries; n++) { PartitionEntry *pe; struct { guint8 partition_type_guid[16]; guint8 partition_guid[16]; guint8 starting_lba[8]; guint8 ending_lba[8]; guint8 attributes[8]; guint8 partition_name[72]; } gpt_part_entry; char *partition_type_guid; if (lseek (fd, offset + partition_entry_lba * 512 + n * size_of_entry, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, &gpt_part_entry, 128) != 128) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } partition_type_guid = get_le_guid (gpt_part_entry.partition_type_guid); if (strcmp (partition_type_guid, GPT_PART_TYPE_GUID_EMPTY) == 0) continue; pe = part_entry_new (NULL, (guint8*) &gpt_part_entry, 128, offset + partition_entry_lba * 512 + n * size_of_entry); p->entries = g_slist_append (p->entries, pe); g_free (partition_type_guid); //hexdump ((guint8 *) &gpt_part_entry, 128); } out: HAL_INFO (("Leaving EFI GPT parser")); return p; }
/* XXX - Would it make more sense to use GStrings here instead of reallocing our buffers? */ static gboolean read_filters_file(FILE *f, gpointer user_data) { #define INIT_BUF_SIZE 128 gchar *name = NULL; gchar *filter_exp = NULL; guint32 name_len = INIT_BUF_SIZE; guint32 filter_exp_len = INIT_BUF_SIZE; guint32 i = 0; gint32 c; guint16 fg_r, fg_g, fg_b, bg_r, bg_g, bg_b; gboolean disabled = FALSE; gboolean skip_end_of_line = FALSE; name = (gchar *)g_malloc(name_len + 1); filter_exp = (gchar *)g_malloc(filter_exp_len + 1); while (1) { if (skip_end_of_line) { do { c = getc(f); } while (c != EOF && c != '\n'); if (c == EOF) break; disabled = FALSE; skip_end_of_line = FALSE; } while ((c = getc(f)) != EOF && isspace(c)) { if (c == '\n') { continue; } } if (c == EOF) break; if (c == '!') { disabled = TRUE; continue; } /* skip # comments and invalid lines */ if (c != '@') { skip_end_of_line = TRUE; continue; } /* we get the @ delimiter. * Format is: * @name@filter expression@[background r,g,b][foreground r,g,b] */ /* retrieve name */ i = 0; while (1) { c = getc(f); if (c == EOF || c == '@') break; if (i >= name_len) { /* buffer isn't long enough; double its length.*/ name_len *= 2; name = (gchar *)g_realloc(name, name_len + 1); } name[i++] = c; } name[i] = '\0'; if (c == EOF) { break; } else if (i == 0) { skip_end_of_line = TRUE; continue; } /* retrieve filter expression */ i = 0; while (1) { c = getc(f); if (c == EOF || c == '@') break; if (i >= filter_exp_len) { /* buffer isn't long enough; double its length.*/ filter_exp_len *= 2; filter_exp = (gchar *)g_realloc(filter_exp, filter_exp_len + 1); } filter_exp[i++] = c; } filter_exp[i] = '\0'; if (c == EOF) { break; } else if (i == 0) { skip_end_of_line = TRUE; continue; } /* retrieve background and foreground colors */ if (fscanf(f,"[%hu,%hu,%hu][%hu,%hu,%hu]", &bg_r, &bg_g, &bg_b, &fg_r, &fg_g, &fg_b) == 6) { /* we got a complete color filter */ color_t bg_color, fg_color; color_filter_t *colorf; dfilter_t *temp_dfilter; if (!dfilter_compile(filter_exp, &temp_dfilter)) { g_warning("Could not compile \"%s\" in colorfilters file.\n%s", name, dfilter_error_msg); prefs.unknown_colorfilters = TRUE; skip_end_of_line = TRUE; continue; } if (!initialize_color(&fg_color, fg_r, fg_g, fg_b)) { /* oops */ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not allocate foreground color " "specified in input file for %s.", name); dfilter_free(temp_dfilter); skip_end_of_line = TRUE; continue; } if (!initialize_color(&bg_color, bg_r, bg_g, bg_b)) { /* oops */ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not allocate background color " "specified in input file for %s.", name); dfilter_free(temp_dfilter); skip_end_of_line = TRUE; continue; } colorf = color_filter_new(name, filter_exp, &bg_color, &fg_color, disabled); if(user_data == &color_filter_list) { GSList **cfl = (GSList **)user_data; /* internal call */ colorf->c_colorfilter = temp_dfilter; *cfl = g_slist_append(*cfl, colorf); } else { /* external call */ /* just editing, don't need the compiled filter */ dfilter_free(temp_dfilter); color_filter_add_cb (colorf, user_data); } } /* if sscanf */ skip_end_of_line = TRUE; } g_free(name); g_free(filter_exp); return TRUE; }
/** * watchdog_discover_resources: * @hnd: void pointer to handler * * Discover the resources in watchdog. * * Return value: 0 for success | Error code **/ static int watchdog_discover_resources(void *hnd) { struct oh_event *e; struct oh_handler_state *tmp = (struct oh_handler_state *)hnd; int puid, timeout = DEFAULT_TIMEOUT; struct wdtitems *wdt; if (!tmp) { dbg("no handler given"); return SA_ERR_HPI_INVALID_PARAMS; } wdt = tmp->data; if (!wdt->initialized) { wdt->initialized = 1; /* * Verify we really have a watchdog available that * interacts with the watchdog char device in the standard way * as described in the kernel watchdog-api.txt * documentation. * * If there are any problems with the standard watchdog * interface, consider the watchdog device undetected * and do not return an error, but just do not bubble * up and RPT and RDR entries. */ wdt->fd = open(wdt->path, O_RDWR); if (-1 == wdt->fd) { dbg("watchdog device is not enabled"); return 0; } /* the clock is ticking... set the default timeout */ /* before it is too late */ if ( -1 == ioctl(wdt->fd, WDIOC_SETTIMEOUT, &timeout)) { dbg("unable to set watchdog timeout"); if (write(wdt->fd, "V", 1) != 1) { dbg("write in watchdog failed"); } close(wdt->fd); return 0; } if ( -1 == ioctl(wdt->fd, WDIOC_GETTIMEOUT, &timeout)) { dbg("unable to read watchdog timeout"); if (write(wdt->fd, "V", 1) != 1) { dbg("write in watchdog failed"); } close(wdt->fd); return 0; } /* writing "V" and closing the wdt disables it */ if (-1 == write(wdt->fd, "V", 1)) { dbg("Unable to write to watchdog - cannot close"); return 0; } close(wdt->fd); /* Set wdt to contain watchdog timer information. * Note: Using watchdog-api.txt, pretimer interrupt * and pretimeout interval functionality is not available. * In addition, event notification of a timeout is * unavailable. */ wdt->data.Log = SAHPI_FALSE; /* don't issue event on timeout */ wdt->data.Running = SAHPI_FALSE; /* not currently running */ wdt->data.TimerUse = SAHPI_WTU_SMS_OS; wdt->data.TimerAction = SAHPI_WA_RESET; wdt->data.PretimerInterrupt = SAHPI_WPI_NONE; wdt->data.PreTimeoutInterval = 0; wdt->data.TimerUseExpFlags = 0; /* not used -- cannot set on timeout */ wdt->data.InitialCount = timeout * 1000; wdt->data.PresentCount = 0; /* * Since event notification on timeout is not available, * the only events we can send back to the OpenHPI * infrastructure are the initial RPT and RDR creation * events to populate the domain RPT table. */ /* * create RPT creation event */ e = (struct oh_event *)malloc(sizeof(*e)); if (!e) { dbg("unable to allocate event"); return SA_ERR_HPI_OUT_OF_SPACE; } memset(e, '\0', sizeof(struct oh_event)); e->hid = tmp->hid; e->event.EventType = SAHPI_ET_RESOURCE; /* Note: .res_event.entry.ResourceInfo currently unassigned */ e->resource.ResourceEntity.Entry[0].EntityType = SAHPI_ENT_SYSTEM_BOARD; e->resource.ResourceEntity.Entry[0].EntityLocation = 0; oh_concat_ep( &(e->resource.ResourceEntity), &g_epbase); puid = oh_uid_from_entity_path(&(e->resource.ResourceEntity)); e->resource.ResourceId = puid; e->event.Source = puid; e->resource.EntryId = puid; e->resource.ResourceCapabilities = WD_CAPS; e->resource.ResourceSeverity = SAHPI_CRITICAL; /* Note e->u.res_event.entry.DomainId as well as e->u.res_event.domainid.ptr not set */ e->resource.ResourceTag.DataType = SAHPI_TL_TYPE_ASCII6; e->resource.ResourceTag.Language = SAHPI_LANG_ENGLISH; e->resource.ResourceTag.DataLength = 12; strcpy((char *)e->resource.ResourceTag.Data, "System-Board"); e->event.Timestamp = SAHPI_TIME_UNSPECIFIED; e->event.Severity = e->resource.ResourceSeverity; e->event.EventDataUnion.ResourceEvent.ResourceEventType = SAHPI_RESE_RESOURCE_ADDED; /* add resource */ if (0 != oh_add_resource(tmp->rptcache, &(e->resource), NULL, 0)) { dbg("unable to add resource to RPT"); return SA_ERR_HPI_ERROR; } /* * create RDR creation event */ /* note: reusing e; okay so long as we don't do a free(e) before */ SaHpiRdrT *tmprdr = (SaHpiRdrT *)malloc(sizeof(SaHpiRdrT)); if (!tmprdr) { dbg("unable to allocate event"); return SA_ERR_HPI_OUT_OF_SPACE; } memset(tmprdr, '\0', sizeof(*tmprdr)); tmprdr->RecordId = 0; /* set to 0 b/c first -- and only -- RDR*/ tmprdr->RdrType = SAHPI_WATCHDOG_RDR; tmprdr->RdrTypeUnion.WatchdogRec.WatchdogNum = SAHPI_DEFAULT_WATCHDOG_NUM; /* set to default b/c only wdt */ tmprdr->RdrTypeUnion.WatchdogRec.Oem = 0; /* n/a */ tmprdr->Entity.Entry[0].EntityType = SAHPI_ENT_SYSTEM_BOARD; tmprdr->Entity.Entry[0].EntityLocation = 0; oh_concat_ep( &(tmprdr->Entity), &g_epbase); tmprdr->IdString.DataType = SAHPI_TL_TYPE_ASCII6; tmprdr->IdString.Language = SAHPI_LANG_ENGLISH; tmprdr->IdString.DataLength = 8; strcpy((char *)tmprdr->IdString.Data, "Watchdog"); /* add RDR */ if (oh_add_rdr(tmp->rptcache, puid, tmprdr, NULL, 0)) { dbg("unable to add RDR to RPT"); return SA_ERR_HPI_ERROR; } /* Add rdr to event */ e->rdrs = g_slist_append(e->rdrs, tmprdr); /* add event to our event queue */ oh_evt_queue_push(tmp->eventq, e); } return 0; }
static void add_screen(xcb_randr_get_screen_info_reply_t *reply) { const gchar *title = "Display"; GtkWidget *item = gtk_menu_item_new_with_label(title); GtkMenuShell *menu = GTK_MENU_SHELL(app_menu); struct screen_info *info = g_malloc(sizeof *info); xcb_randr_rotation_t rotation = normalize_rotation(reply->rotation); xcb_randr_rotation_t rotations = reply->rotations; info->label_menu_item = item; info->rotation_menu_group = NULL; info->rotation = rotation; info->config_timestamp = reply->config_timestamp; info->root = reply->root; info->sizeID = reply->sizeID; info->rate = reply->rate; screens_info = g_slist_append(screens_info, info); gtk_widget_set_sensitive(item, FALSE); gtk_menu_shell_append(menu, item); #define R(rot, title) \ if (rotations & XCB_RANDR_ROTATION_##rot) \ add_screen_rotation(info, XCB_RANDR_ROTATION_##rot, title, \ XCB_RANDR_ROTATION_##rot & rotation) R(ROTATE_0, "Landscape"); R(ROTATE_90, "Portrait"); R(ROTATE_180, "Landscape Flipped"); R(ROTATE_270, "Portrait Flipped"); if (rotations & xcb_rotations_mask && rotations & xcb_reflections_mask) gtk_menu_shell_append(menu, gtk_separator_menu_item_new()); R(REFLECT_X, "Reflected X"); R(REFLECT_Y, "Reflected Y"); #undef R gtk_menu_shell_append(menu, gtk_separator_menu_item_new()); gtk_widget_show_all(app_menu); /* Get screen resources */ xcb_randr_get_screen_resources_current_cookie_t resources_cookie; xcb_randr_get_screen_resources_current_reply_t *resources_reply; xcb_generic_error_t *err = NULL; resources_cookie = xcb_randr_get_screen_resources_current(conn, info->root); resources_reply = xcb_randr_get_screen_resources_current_reply(conn, resources_cookie, &err); if (err) { g_warning("Get Screen Resources returned error %u\n", err->error_code); return; } /* Get screen outputs */ xcb_randr_output_t *outputs; guint i; gchar *output_name; outputs = xcb_randr_get_screen_resources_current_outputs(resources_reply); for (i = 0; i < resources_reply->num_outputs; i++) { xcb_randr_get_output_info_reply_t *output_info_reply; xcb_randr_get_output_info_cookie_t output_info_cookie = xcb_randr_get_output_info_unchecked(conn, outputs[i], resources_reply->config_timestamp); output_info_reply = xcb_randr_get_output_info_reply(conn, output_info_cookie, NULL); /* Show only if connected */ switch (output_info_reply->connection) { case XCB_RANDR_CONNECTION_DISCONNECTED: case XCB_RANDR_CONNECTION_UNKNOWN: continue; case XCB_RANDR_CONNECTION_CONNECTED: break; } output_name = get_output_name(output_info_reply); /* Put output names on the menu */ gtk_menu_item_set_label(GTK_MENU_ITEM(item), output_name); g_free(output_name); /* TODO: concatenate multiple names or pick them intelligently */ } }
static void xml_start_element(void *user_data, const xmlChar *xml_name, const xmlChar **attrs) { const char *name = (const char *) xml_name; xmlctxt *ctxt = (xmlctxt *) user_data; switch (ctxt->state) { case STATE_START: if (strcmp(name, "sparql")) { fprintf(stderr, "results not in valid SPARQL results format (missing sparql)\n"); /* stop parsing */ } else { ctxt->state = STATE_SPARQL_WANT_HEAD; } break; case STATE_SPARQL_WANT_HEAD: if (!strcmp(name, "head")) { if (ctxt->pass == 0) { /* do nothing */ } else { if (!ctxt->tsv) { for (int i=0; i<MAX(ctxt->cols, 1); i++) { if (i == 0) { printf("%s%s%s", ctxt->aa.TL, ctxt->aa.H, ctxt->aa.H); } else { printf("%s%s%s", ctxt->aa.TC, ctxt->aa.H, ctxt->aa.H); } for (int j=0; j<ctxt->widths[i]; j++) { printf("%s", ctxt->aa.H); } } printf("%s\n", ctxt->aa.TR); } } ctxt->state = STATE_HEAD; ctxt->col = 0; } else { fprintf(stderr, "results not in valid SPARQL results format (missing head)\n"); /* stop parsing */ } break; case STATE_HEAD: if (!strcmp(name, "variable")) { ctxt->state = STATE_VARIABLE; while (attrs && *attrs) { const char *key = (const char *) *(attrs++); const char *value = (const char *) *(attrs++); if (ctxt->pass == 0) { if (ctxt->cols < TMP_COLS) { ctxt->tmp_widths[ctxt->cols] = g_utf8_strlen(value, -1) + 1; } ctxt->name_list = g_slist_append(ctxt->name_list, g_strdup(value)); (ctxt->cols)++; } else { if (!strcmp(key, "name")) { if (ctxt->tsv) { printf("%s?%s", ctxt->col>0 ? ctxt->aa.V : "", value); } else { printf("%s ?%*s ", ctxt->aa.V, -ctxt->widths[ctxt->col] + 1, value); } (ctxt->col)++; } } } break; } /* fall through */ case STATE_HEAD_LINK_ONLY: if (!strcmp(name, "link")) { ctxt->state = STATE_LINK; /* handle link */ } else { fprintf(stderr, "results not in valid SPARQL results format (wrong element in head)\n"); /* stop parsing */ } break; case STATE_SPARQL_WANT_RESULTS: if (!strcmp(name, "results")) { if (ctxt->pass == 0) { /* do nothing */ } else { for (int i=0; i<ctxt->cols; i++) { if (i == 0) { printf("%s%s%s", ctxt->aa.CL, ctxt->aa.H, ctxt->aa.H); } else { printf("%s%s%s", ctxt->aa.CC, ctxt->aa.H, ctxt->aa.H); } for (int j=0; j<ctxt->widths[i]; j++) { printf("%s", ctxt->aa.H); } } printf("%s\n", ctxt->aa.CR); } ctxt->state = STATE_RESULTS; } else if (!strcmp(name, "boolean")) { ctxt->state = STATE_BOOLEAN; } else { fprintf(stderr, "results not in valid SPARQL results format (missing results)\n"); /* stop parsing */ } break; case STATE_RESULTS: if (!strcmp(name, "result")) { ctxt->state = STATE_RESULT; ctxt->col = 0; } else { fprintf(stderr, "results not in valid SPARQL results format (missing result)\n"); /* stop parsing */ } break; case STATE_RESULT: if (!strcmp(name, "binding")) { while (attrs && *attrs) { const char *key = (const char *) *(attrs++); const char *value = (const char *) *(attrs++); ctxt->current_col = -1; if (!strcmp(key, "name")) { ctxt->current_col = name_to_col(ctxt, value); } if (ctxt->current_col == -1) { fprintf(stderr, "no column name found in results\n"); ctxt->current_col = 0; } } ctxt->state = STATE_BINDING; } else { fprintf(stderr, "results not in valid SPARQL results format (missing binding)\n"); /* stop parsing */ } break; case STATE_BINDING: if (!strcmp(name, "uri")) { ctxt->state = STATE_URI; } else if (!strcmp(name, "bnode")) { ctxt->state = STATE_BNODE; } else if (!strcmp(name, "literal")) { /* FIXME we don't worry about lang tags and type URIs here yet */ ctxt->state = STATE_LITERAL; } else { fprintf(stderr, "results not in valid SPARQL results format (wrong element in binding)\n"); /* stop parsing */ } break; default: fprintf(stderr, "results not in valid SPARQL results format, unexpected <%s>\n", name); /* stop parsing */ } g_free(ctxt->text); ctxt->text = NULL; }
static void parse_ignore_host(gpointer data, gpointer user_data) { gchar *hostname, *input, *netmask; gboolean ip_addr = FALSE, has_error = FALSE; struct in_addr host; #ifdef ENABLE_IPV6 struct in6_addr host6, mask6; gint i; #endif ProxyHostAddr *elt; input = (gchar *) data; elt = g_new0(ProxyHostAddr, 1); if ((netmask = strchr(input, '/')) != NULL) { hostname = g_strndup(input, netmask - input); ++netmask; } else { hostname = g_ascii_strdown(input, -1); } if (inet_pton(AF_INET, hostname, &host) > 0) { ip_addr = TRUE; elt->type = PROXY_IPv4; elt->addr.s_addr = host.s_addr; if (netmask) { gchar *endptr; gint width = strtol(netmask, &endptr, 10); if (*endptr != '\0' || width < 0 || width > 32) { has_error = TRUE; } elt->mask.s_addr = htonl(~0 << width); elt->addr.s_addr &= elt->mask.s_addr; } else { elt->mask.s_addr = 0xffffffff; } } #ifdef ENABLE_IPV6 else if (have_ipv6() && inet_pton(AF_INET6, hostname, &host6) > 0) { ip_addr = TRUE; elt->type = PROXY_IPv6; for (i = 0; i < 16; ++i) { elt->addr6.s6_addr[i] = host6.s6_addr[i]; } if (netmask) { gchar *endptr; gint width = strtol(netmask, &endptr, 10); if (*endptr != '\0' || width < 0 || width > 128) { has_error = TRUE; } for (i = 0; i < 16; ++i) { elt->mask6.s6_addr[i] = 0; } for (i = 0; i < width / 8; i++) { elt->mask6.s6_addr[i] = 0xff; } elt->mask6.s6_addr[i] = (0xff << (8 - width % 8)) & 0xff; ipv6_network_addr(&elt->addr6, &mask6, &elt->addr6); } else { for (i = 0; i < 16; ++i) { elt->mask6.s6_addr[i] = 0xff; } } } #endif if (ip_addr) { if (!has_error) { gchar *dst = g_new0(gchar, INET_ADDRSTRLEN); gl_ignore_addrs = g_slist_append(gl_ignore_addrs, elt); DEBUG_HTTP(("Host %s/%s does not go through proxy.", hostname, inet_ntop(AF_INET, &elt->mask, dst, INET_ADDRSTRLEN))); g_free(dst); } g_free(hostname); } else { /* It is a hostname. */ gl_ignore_hosts = g_slist_append(gl_ignore_hosts, hostname); DEBUG_HTTP(("Host %s does not go through proxy.", hostname)); g_free(elt); } }
gboolean panel_struts_register_strut (PanelToplevel *toplevel, GdkScreen *screen, int monitor, PanelOrientation orientation, int strut_size, int strut_start, int strut_end) { PanelStrut *strut; gboolean new_strut = FALSE; int monitor_x, monitor_y, monitor_width, monitor_height; if (!(strut = panel_struts_find_strut (toplevel))) { strut = g_new0 (PanelStrut, 1); new_strut = TRUE; } else if (strut->toplevel == toplevel && strut->orientation == orientation && strut->screen == screen && strut->monitor == monitor && strut->strut_size == strut_size && strut->strut_start == strut_start && strut->strut_end == strut_end) return FALSE; strut->toplevel = toplevel; strut->orientation = orientation; strut->screen = screen; strut->monitor = monitor; strut->strut_size = strut_size; strut->strut_start = strut_start; strut->strut_end = strut_end; panel_struts_get_monitor_geometry (screen, monitor, &monitor_x, &monitor_y, &monitor_width, &monitor_height); switch (strut->orientation) { case PANEL_ORIENTATION_TOP: strut->geometry.x = strut->strut_start; strut->geometry.y = monitor_y; strut->geometry.width = strut->strut_end - strut->strut_start + 1; strut->geometry.height = strut->strut_size; break; case PANEL_ORIENTATION_BOTTOM: strut->geometry.x = strut->strut_start; strut->geometry.y = monitor_y + monitor_height - strut->strut_size; strut->geometry.width = strut->strut_end - strut->strut_start + 1; strut->geometry.height = strut->strut_size; break; case PANEL_ORIENTATION_LEFT: strut->geometry.x = monitor_x; strut->geometry.y = strut->strut_start; strut->geometry.width = strut->strut_size; strut->geometry.height = strut->strut_end - strut->strut_start + 1; break; case PANEL_ORIENTATION_RIGHT: strut->geometry.x = monitor_x + monitor_width - strut->strut_size; strut->geometry.y = strut->strut_start; strut->geometry.width = strut->strut_size; strut->geometry.height = strut->strut_end - strut->strut_start + 1; break; } if (new_strut) panel_struts_list = g_slist_append (panel_struts_list, strut); panel_struts_list = g_slist_sort (panel_struts_list, (GCompareFunc) panel_struts_compare); return panel_struts_allocate_struts (toplevel, screen, monitor); }
static gboolean panel_struts_allocate_struts (PanelToplevel *toplevel, GdkScreen *screen, int monitor) { GSList *allocated = NULL; GSList *l; gboolean toplevel_changed = FALSE; for (l = panel_struts_list; l; l = l->next) { PanelStrut *strut = l->data; PanelStrut *overlap; GdkRectangle geometry; int monitor_x, monitor_y; int monitor_width, monitor_height; gboolean moved_down; int skip; if (strut->screen != screen || strut->monitor != monitor) continue; panel_struts_get_monitor_geometry (strut->screen, strut->monitor, &monitor_x, &monitor_y, &monitor_width, &monitor_height); strut->allocated_strut_size = strut->strut_size; strut->allocated_strut_start = strut->strut_start; strut->allocated_strut_end = strut->strut_end; geometry = strut->geometry; moved_down = FALSE; skip = 0; while ((overlap = panel_struts_intersect (allocated, &geometry, skip))) skip = panel_struts_allocation_overlapped ( strut, overlap, &geometry, &moved_down, skip); if (strut->orientation & PANEL_VERTICAL_MASK) { if (geometry.y < monitor_y) { geometry.height = geometry.y + geometry.height - monitor_y; geometry.y = monitor_y; } if (geometry.y + geometry.height > monitor_y + monitor_height) geometry.height = monitor_y + monitor_height - geometry.y; } if (strut->allocated_geometry.x != geometry.x || strut->allocated_geometry.y != geometry.y || strut->allocated_geometry.width != geometry.width || strut->allocated_geometry.height != geometry.height) { strut->allocated_geometry = geometry; if (strut->toplevel == toplevel) toplevel_changed = TRUE; else gtk_widget_queue_resize (GTK_WIDGET (strut->toplevel)); } allocated = g_slist_append (allocated, strut); } g_slist_free (allocated); return toplevel_changed; }
GSList * log_read_dates (const char **buffer_lines, time_t current) { int current_year, offsetyear, i, n, rangemin, rangemax, timestamp_len = 0; GSList *days = NULL; GDate *date = NULL; struct tm *tmptm; char *date_string = NULL; Day *day; gboolean done = FALSE; g_return_val_if_fail (buffer_lines != NULL, NULL); n = g_strv_length ((char **) buffer_lines); tmptm = localtime (¤t); current_year = tmptm->tm_year + 1900; offsetyear = 0; /* find the first line with a date we're able to parse */ for (i = 0; buffer_lines[i]; i++) { if ((date = string_get_date (buffer_lines[i], &date_string, ×tamp_len)) != NULL) break; } if (!date) { /* no valid dates in the array, return NULL */ return NULL; } if (!g_date_valid (date)) { g_date_free (date); g_free (date_string); return NULL; } g_date_set_year (date, current_year); day = g_slice_new0 (Day); days = g_slist_append (days, day); /* $i now contains the line number for the first good date */ day->date = date; day->first_line = i; day->last_line = -1; day->timestamp_len = timestamp_len; /* now scan the logfile to get the last line of the day */ rangemin = i; rangemax = n - 1; while (!done) { /* find out the last line of the day we're currently building */ i = n - 1; while (day->last_line < 0) { if (strstr (buffer_lines[i], date_string)) { /* if we find the same string on the last line of the log, we're done */ if (i == n - 1) { done = TRUE; day->last_line = i; break; } /* we're still in a section of lines with the same date; * - if the next one changes, then we're on the last. * - else we keep searching in the following. */ if (!strstr (buffer_lines[i + 1], date_string)) { day->last_line = i; break; } else { rangemin = i; i = floor (((float) i + (float) rangemax) / 2.); } } else { /* we can't find the same date here; go back to a safer range. */ rangemax = i; i = floor (((float) rangemin + (float) i) / 2.); } } g_free (date_string); date_string = NULL; if (!done) { /* this means we finished the current day but we're not at the end * of the buffer: reset the parameters for the next day. */ GDate *newdate = NULL; for (i = day->last_line + 1; buffer_lines[i]; i++) { if ((newdate = string_get_date (buffer_lines[i], &date_string, ×tamp_len)) != NULL) break; } if (date_string == NULL && i == n - 1) { done = TRUE; } /* this will set the last line of the "old" log to either: * - "n - 1" if we can't find another date * - the line before the new date else. */ day->last_line = i - 1; if (newdate) { /* append a new day to the list */ g_date_set_year (newdate, current_year + offsetyear); if (g_date_compare (newdate, date) < 1) { /* this isn't possible, as we're reading the log forward. * so it means that newdate is the next year. */ g_date_add_years (newdate, 1); offsetyear++; } date = newdate; day = g_slice_new0 (Day); days = g_slist_prepend (days, day); day->date = date; day->first_line = i; day->last_line = -1; day->timestamp_len = timestamp_len; rangemin = i; rangemax = n - 1; } } } if (date_string) { g_free (date_string); } /* sort the days in chronological order */ days = g_slist_sort (days, days_compare); return days; }
static void get_contexts_cb(const struct ofono_error *error, GSList *contexts, void *data) { struct cb_data *cbd = data; wan_get_status_cb cb = cbd->cb; struct ofono_wan_data *od = cbd->user; struct wan_status status; struct ofono_connection_context *context; struct wan_connected_service *wanservice; GSList *iter; memset(&status, 0, sizeof(struct wan_status)); status.state = ofono_connection_manager_get_powered(od->cm); /* FIXME until we have voicecall functionality and can determine wether we have an active call * this is true forever */ status.dataaccess_usable = true; status.wan_status = WAN_STATUS_TYPE_ENABLE; status.disablewan = od->wan_disabled; status.roam_guard = !ofono_connection_manager_get_roaming_allowed(od->cm); status.network_attached = ofono_connection_manager_get_attached(od->cm); enum ofono_connection_bearer bearer = ofono_connection_manager_get_bearer(od->cm); if (bearer == OFONO_CONNECTION_BEARER_UNKNOWN && od->netreg) { enum ofono_network_technology tech = ofono_network_registration_get_technology(od->netreg); status.network_type = convert_ofono_network_technology_to_wan_network_type(tech); } else { status.network_type = convert_ofono_connection_bearer_to_wan_network_type(bearer); } for (iter = contexts; iter != NULL; iter = g_slist_next(iter)) { context = iter->data; ofono_connection_context_register_prop_changed_cb(context, context_prop_changed_cb, od); wanservice = g_new0(struct wan_connected_service, 1); switch (ofono_connection_context_get_type(context)) { case OFONO_CONNECTION_CONTEXT_TYPE_INTERNET: wanservice->services[WAN_SERVICE_TYPE_INTERNET] = true; break; case OFONO_CONNECTION_CONTEXT_TYPE_MMS: wanservice->services[WAN_SERVICE_TYPE_MMS] = true; break; default: break; } wanservice->ipaddress = ofono_connection_context_get_address(context); wanservice->connection_status = ofono_connection_context_get_active(context) ? WAN_CONNECTION_STATUS_ACTIVE : WAN_CONNECTION_STATUS_DISCONNECTED; /* FIXME to what we have to set the following field? */ wanservice->req_status = WAN_REQUEST_STATUS_CONNECT_SUCCEEDED; /* If at least one service is active we report a active connection */ if (wanservice->connection_status == WAN_CONNECTION_STATUS_ACTIVE) status.connection_status = WAN_CONNECTION_STATUS_ACTIVE; status.connected_services = g_slist_append(status.connected_services, wanservice); } cb(NULL, &status, cbd->data); g_slist_free_full(status.connected_services, g_free); g_free(cbd); }
/* * Routine used to register record end routine. The routine should only * be registered when the dissector is used in the record, not in the * proto_register_XXX function. */ void register_file_record_end_routine(packet_info *pinfo, void (*func)(void)) { pinfo->frame_end_routines = g_slist_append(pinfo->frame_end_routines, (gpointer)func); }
/* Add a check_button or radio_button to control a particular option This function makes particular use of the current... variables at the top of this file. */ static void xkb_options_add_option (XklConfigRegistry * config_registry, XklConfigItem * config_item, GtkBuilder * dialog) { GtkWidget *option_check; gchar *utf_option_name = xci_desc_to_utf8 (config_item); /* Copy this out because we'll load it into the widget with set_data */ gchar *full_option_name = g_strdup (matekbd_keyboard_config_merge_items (current1st_level_id, config_item->name)); gboolean initial_state; if (current_multi_select) option_check = gtk_check_button_new_with_label (utf_option_name); else { if (current_radio_group == NULL) { /* The first radio in a group is to be "Default", meaning none of the below options are to be included in the selected list. This is a HIG-compliant alternative to allowing no selection in the group. */ option_check = gtk_radio_button_new_with_label (current_radio_group, _("Default")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (option_check), TRUE); /* Make option name underscore - to enforce its first position in the list */ g_object_set_data_full (G_OBJECT (option_check), "utfOptionName", g_strdup (" "), g_free); option_checks_list = g_slist_append (option_checks_list, option_check); current_radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (option_check)); current_none_radio = option_check; g_signal_connect (option_check, "focus-in-event", G_CALLBACK (option_focused_cb), WID ("options_scroll")); } option_check = gtk_radio_button_new_with_label (current_radio_group, utf_option_name); current_radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (option_check)); g_object_set_data (G_OBJECT (option_check), "NoneRadio", current_none_radio); } initial_state = xkb_options_is_selected (full_option_name); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (option_check), initial_state); g_object_set_data_full (G_OBJECT (option_check), OPTION_ID_PROP, full_option_name, g_free); g_object_set_data_full (G_OBJECT (option_check), "utfOptionName", utf_option_name, g_free); g_signal_connect (option_check, "toggled", G_CALLBACK (option_toggled_cb), NULL); option_checks_list = g_slist_append (option_checks_list, option_check); g_signal_connect (option_check, "focus-in-event", G_CALLBACK (option_focused_cb), WID ("options_scroll")); xkb_options_expander_selcounter_add (initial_state); }
static PartitionTable * part_table_parse_msdos (int fd, guint64 offset, guint64 size, gboolean *found_gpt) { int n; const guint8 mbr[512]; PartitionTable *p; //HAL_INFO (("Entering MS-DOS parser")); *found_gpt = FALSE; p = NULL; if (lseek (fd, offset, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, &mbr, sizeof (mbr)) != sizeof (mbr)) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } if (memcmp (&mbr[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0) { HAL_INFO (("No MSDOS_MAGIC found")); goto out; } //HAL_INFO (("MSDOS_MAGIC found")); /* sanity checks */ for (n = 0; n < 4; n++) { if (mbr[MSDOS_PARTTABLE_OFFSET + n * 16 + 0] != 0 && mbr[MSDOS_PARTTABLE_OFFSET + n * 16 + 0] != 0x80) { HAL_INFO (("partitioning flag for part %d is not 0x00 or 0x80", n)); goto out; } /* protective MBR for GPT => GPT, not MS-DOS */ if (mbr[MSDOS_PARTTABLE_OFFSET + n * 16 + 4] == 0xee) { HAL_INFO (("found partition type 0xee => protective MBR for GPT", n)); *found_gpt = TRUE; goto out; } } p = part_table_new_empty (PART_TYPE_MSDOS); p->offset = offset; p->size = size; /* we _always_ want to create four partitions */ for (n = 0; n < 4; n++) { PartitionEntry *pe; guint64 pstart; guint64 psize; guint8 ptype; PartitionTable *e_part_table; pstart = 0x200 * ((guint64) get_le32 (&(mbr[MSDOS_PARTTABLE_OFFSET + n * 16 + 8]))); psize = 0x200 * ((guint64) get_le32 (&(mbr[MSDOS_PARTTABLE_OFFSET + n * 16 + 12]))); ptype = mbr[MSDOS_PARTTABLE_OFFSET + n * 16 + 4]; //HAL_INFO (("looking at part %d (offset %lld, size %lld, type 0x%02x)", n, pstart, psize, ptype)); pe = NULL; e_part_table = NULL; /* look for embedded partition tables */ switch (ptype) { /* extended partitions */ case 0x05: /* MS-DOS */ case 0x0f: /* Win95 */ case 0x85: /* Linux */ e_part_table = part_table_parse_msdos_extended (fd, pstart, psize); if (e_part_table != NULL) { pe = part_entry_new (e_part_table, &(mbr[MSDOS_PARTTABLE_OFFSET + n * 16]), 16, offset + MSDOS_PARTTABLE_OFFSET + n * 16); } break; case 0xa5: /* FreeBSD */ case 0xa6: /* OpenBSD */ case 0xa9: /* NetBSD */ //e_part_table = part_table_parse_bsd (fd, pstart, psize); //break; default: //HAL_INFO (("new part entry")); pe = part_entry_new (NULL, &(mbr[MSDOS_PARTTABLE_OFFSET + n * 16]), 16, offset + MSDOS_PARTTABLE_OFFSET + n * 16); break; } //HAL_INFO (("pe = %p", pe)); p->entries = g_slist_append (p->entries, pe); } out: //HAL_INFO (("Exiting MS-DOS parser")); return p; }
/* Add a group of options: create title and layout widgets and then add widgets for all the options in the group. */ static void xkb_options_add_group (XklConfigRegistry * config_registry, XklConfigItem * config_item, GtkBuilder * dialog) { GtkWidget *align, *vbox, *option_check; gboolean allow_multiple_selection = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (config_item), XCI_PROP_ALLOW_MULTIPLE_SELECTION)); GSList *expanders_list = g_object_get_data (G_OBJECT (dialog), EXPANDERS_PROP); gchar *utf_group_name = xci_desc_to_utf8 (config_item); gchar *titlemarkup = g_strconcat ("<span>", utf_group_name, "</span>", NULL); current_expander = gtk_expander_new (titlemarkup); gtk_expander_set_use_markup (GTK_EXPANDER (current_expander), TRUE); g_object_set_data_full (G_OBJECT (current_expander), "utfGroupName", utf_group_name, g_free); g_object_set_data_full (G_OBJECT (current_expander), "groupId", g_strdup (config_item->name), g_free); g_free (titlemarkup); align = gtk_alignment_new (0, 0, 1, 1); gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 12, 12, 0); vbox = gtk_vbox_new (TRUE, 6); gtk_container_add (GTK_CONTAINER (align), vbox); gtk_container_add (GTK_CONTAINER (current_expander), align); current_multi_select = (gboolean) allow_multiple_selection; current_radio_group = NULL; current1st_level_id = config_item->name; option_checks_list = NULL; xkl_config_registry_foreach_option (config_registry, config_item->name, (ConfigItemProcessFunc) xkb_options_add_option, dialog); /* sort it */ option_checks_list = g_slist_sort (option_checks_list, (GCompareFunc) xkb_option_checks_compare); while (option_checks_list) { option_check = GTK_WIDGET (option_checks_list->data); gtk_box_pack_start (GTK_BOX (vbox), option_check, TRUE, TRUE, 0); option_checks_list = option_checks_list->next; } /* free it */ g_slist_free (option_checks_list); option_checks_list = NULL; xkb_options_expander_highlight (); expanders_list = g_slist_append (expanders_list, current_expander); g_object_set_data (G_OBJECT (dialog), EXPANDERS_PROP, expanders_list); g_signal_connect (current_expander, "focus-in-event", G_CALLBACK (option_focused_cb), WID ("options_scroll")); }
static PartitionTable * part_table_parse_apple (int fd, guint64 offset, guint64 size) { int n; PartitionTable *p; struct { guint16 signature; guint16 block_size; guint32 block_count; /* more stuff */ } __attribute__ ((packed)) mac_header; struct { guint16 signature; guint16 res1; guint32 map_count; guint32 start_block; guint32 block_count; char name[32]; char type[32]; guint32 data_start; guint32 data_count; guint32 status; guint32 boot_start; guint32 boot_size; guint32 boot_load; guint32 boot_load2; guint32 boot_entry; guint32 boot_entry2; guint32 boot_cksum; char processor[16]; /* identifies ISA of boot */ /* more stuff */ } __attribute__ ((packed)) mac_part; int block_size; int block_count; int map_count; HAL_INFO (("Entering Apple parser")); p = NULL; /* Check Mac start of disk signature */ if (lseek (fd, offset + 0, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, &mac_header, sizeof (mac_header)) != sizeof (mac_header)) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } if (memcmp (&(mac_header.signature), MAC_MAGIC, 2) != 0) { HAL_INFO (("No MAC_MAGIC found")); goto out; } block_size = GUINT16_FROM_BE (mac_header.block_size); block_count = GUINT32_FROM_BE (mac_header.block_count); /* num blocks on whole disk */ HAL_INFO (("Mac MAGIC found, block_size=%d", block_size)); p = part_table_new_empty (PART_TYPE_APPLE); p->offset = offset; p->size = size; /* get number of entries from first entry */ if (lseek (fd, offset + block_size, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, &mac_part, sizeof (mac_part)) != sizeof (mac_part)) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } map_count = GUINT32_FROM_BE (mac_part.map_count); /* num blocks in part map */ HAL_INFO (("map_count = %d", map_count)); for (n = 0; n < map_count; n++) { PartitionEntry *pe; if (memcmp (&(mac_part.signature), MAC_PART_MAGIC, 2) != 0) { HAL_INFO (("No MAC_PART_MAGIC found")); break; } if (lseek (fd, offset + (n + 1) * block_size, SEEK_SET) < 0) { HAL_INFO (("lseek failed (%s)", strerror (errno))); goto out; } if (read (fd, &mac_part, sizeof (mac_part)) != sizeof (mac_part)) { HAL_INFO (("read failed (%s)", strerror (errno))); goto out; } pe = part_entry_new (NULL, (guint8*) &mac_part, sizeof (mac_part), offset + (n + 1) * block_size); p->entries = g_slist_append (p->entries, pe); } out: HAL_INFO (("Leaving Apple parser")); return p; }
/** * Execute syntax and commit checks **/ static gboolean validate_func(GNode *node, gpointer data) { if (node == NULL) { return TRUE; } struct VyattaNode *gp = (struct VyattaNode *) node->data; struct Config *c = &(gp->_config); struct Data *d = &(gp->_data); struct Aux *a = &(gp->_aux); struct Result *result = (struct Result*)data; /* let's mark first last nodes here for use later * do first/last/only sibling check, restrict to nodes with operations * defined */ GNode *n_last_op = NULL; GNode *n_first_op = NULL; GNode *sib = g_node_first_sibling(node); while (sib != NULL) { if (IS_DELETE(((struct VyattaNode*)(sib->data))->_data._operation)) { if (n_first_op == NULL) { n_first_op = sib; } n_last_op = sib; } sib = sib->next; } sib = g_node_first_sibling(node); while (sib != NULL) { if (IS_SET_OR_CREATE(((struct VyattaNode*)(sib->data)) ->_data._operation)) { if (n_first_op == NULL) { n_first_op = sib; } n_last_op = sib; } sib = sib->next; } a->_first = (node == n_first_op); a->_last = (node == n_last_op); /* since this visits all working nodes, let's maintain a set of nodes * to commit */ GSList *coll = (GSList*)result->_data; if (d->_path != NULL) { char buf[MAX_LENGTH_DIR_PATH*sizeof(char)]; if (IS_DELETE(d->_operation)) { sprintf(buf,"- %s",d->_path); if (c->_def.multi) { /* need to handle the embedded multinode as a special * case--should be fixed! */ char *val = (char*)clind_unescape(d->_name); strcat(buf,val); free(val); } char *tmp = (char *) malloc(strlen(buf)+1); strcpy(tmp,buf); coll = g_slist_append(coll,tmp); result->_data = (void*)coll; } else if (IS_SET_OR_CREATE(d->_operation)) { sprintf(buf,"+ %s",d->_path); if (c->_def.multi) { /* need to handle the embedded multinode as a special * case--should be fixed! */ char *val = (char*)clind_unescape(d->_name); strcat(buf,val); free(val); } char *tmp = (char *) malloc(strlen(buf)+1); strcpy(tmp,buf); coll = g_slist_append(coll,tmp); result->_data = (void*)coll; } } //don't run syntax check on this node if it is unchanged. if (IS_NOOP(d->_operation) && c->_def.actions[syntax_act].vtw_list_head && !c->_def.actions[syntax_act].vtw_list_head->vtw_node_aux) { return FALSE; } if (IS_DELETE(d->_operation) && !IS_ACTIVE(d->_operation)) { return FALSE; //will not perform validation checks on deleted nodes } if (!c->_def.actions || !c->_def.actions[result->_action].vtw_list_head){ return FALSE; } /* will not call term multi if it is a noop--shouldn't show up in tree * in the first place, but will require more rework of unionfs code * to fix this. */ if (c->_def.multi && IS_NOOP(d->_operation)) { return FALSE; } //look at parent for multi tag if (d->_value && d->_name) { char *val = d->_name; if (c->_def.tag) { /* need to handle the embedded multinode as a special * case--should be fixed! */ val = (char*)clind_unescape(d->_name); } d_dplog("commit2::process_func(): @ value: %s",(char *) val); set_at_string(val); //embedded multinode value } else { if (g_debug) { dplog("commit2::process_func(): boolean value is: %d", d->_value); if (node->parent && ((struct VyattaNode*)(node->parent->data))->_data._name) { dplog("commit2::process_func(): parent has a name: %s", ((struct VyattaNode*)(node->parent->data))->_data._name); } dplog("commit2::process_func(): @ value: [NULL]"); } } common_set_context(c->_path,d->_path); d_dplog("Executing %s on this node", ActionNames[result->_action]); if (g_coverage) { struct timeval t; gettimeofday(&t,NULL); fprintf(out_stream, "[START] %lu:%lu, %s@%s", (unsigned long) t.tv_sec, (unsigned long) t.tv_usec, ActionNames[result->_action], d->_path); } boolean status = 1; if (g_dump_actions == FALSE) { //set location env setenv(ENV_DATA_PATH,d->_path,1); if (g_old_print_output == TRUE) { status = execute_list(c->_def.actions[result->_action].vtw_list_head, &c->_def, NULL); } else { char *p = process_script_path(d->_path); status = execute_list(c->_def.actions[result->_action].vtw_list_head, &c->_def, p); free(p); } unsetenv(ENV_DATA_PATH); } else { char buf[MAX_LENGTH_DIR_PATH*sizeof(char)]; if (c->_def.actions[syntax_act].vtw_list_head) { if (c->_def.actions[syntax_act].vtw_list_head->vtw_node_aux == 0) { sprintf(buf,"syntax\t:\t%s",d->_path); } else { sprintf(buf,"commit\t:\t%s",d->_path); } } if (c->_def.multi) { /* need to handle the embedded multinode as a special * case--should be fixed! */ char *val = (char*)clind_unescape(d->_name); strcat(buf,val); free(val); } fprintf(out_stream,"%s\n",buf); status = 1; } if (g_coverage) { struct timeval t; gettimeofday(&t,NULL); fprintf(out_stream,"[END] %lu:%lu\n",t.tv_sec,t.tv_usec); } if (!status) { //EXECUTE_LIST RETURNS FALSE ON FAILURE.... syslog(LOG_ERR, "commit error for %s:[%s]", ActionNames[result->_action], d->_path); if (g_display_error_node) { fprintf(out_stream, "%s@_errloc_:[%s]\n", ActionNames[result->_action], d->_path); } result->_err_code = 1; d_dplog("commit2::validate_func(): FAILURE: status: %d", status); // WILL STOP AT THIS POINT if mode is not set for full syntax check return result->_mode ? FALSE: TRUE; } return FALSE; }
static GSList *scan(GSList *options) { struct drv_context *drvc; struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_usb_dev_inst *usb; struct sr_channel *ch; struct sr_config *src; const struct fx2lafw_profile *prof; GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; struct libusb_device_handle *hdl; int devcnt, num_logic_channels, ret, i, j; const char *conn; char manufacturer[64], product[64]; drvc = di->priv; conn = NULL; for (l = options; l; l = l->next) { src = l->data; switch (src->key) { case SR_CONF_CONN: conn = g_variant_get_string(src->data, NULL); break; } } if (conn) conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn); else conn_devices = NULL; /* Find all fx2lafw compatible devices and upload firmware to them. */ devices = NULL; libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { if (conn) { usb = NULL; for (l = conn_devices; l; l = l->next) { usb = l->data; if (usb->bus == libusb_get_bus_number(devlist[i]) && usb->address == libusb_get_device_address(devlist[i])) break; } if (!l) /* This device matched none of the ones that * matched the conn specification. */ continue; } if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) { sr_warn("Failed to get device descriptor: %s.", libusb_error_name(ret)); continue; } if ((ret = libusb_open(devlist[i], &hdl)) < 0) continue; if (des.iManufacturer == 0) { manufacturer[0] = '\0'; } else if ((ret = libusb_get_string_descriptor_ascii(hdl, des.iManufacturer, (unsigned char *) manufacturer, sizeof(manufacturer))) < 0) { sr_warn("Failed to get manufacturer string descriptor: %s.", libusb_error_name(ret)); continue; } if (des.iProduct == 0) { product[0] = '\0'; } else if ((ret = libusb_get_string_descriptor_ascii(hdl, des.iProduct, (unsigned char *) product, sizeof(product))) < 0) { sr_warn("Failed to get product string descriptor: %s.", libusb_error_name(ret)); continue; } libusb_close(hdl); prof = NULL; for (j = 0; supported_fx2[j].vid; j++) { if (des.idVendor == supported_fx2[j].vid && des.idProduct == supported_fx2[j].pid && (!supported_fx2[j].usb_manufacturer || !strcmp(manufacturer, supported_fx2[j].usb_manufacturer)) && (!supported_fx2[j].usb_manufacturer || !strcmp(product, supported_fx2[j].usb_product))) { prof = &supported_fx2[j]; break; } } /* Skip if the device was not found. */ if (!prof) continue; devcnt = g_slist_length(drvc->instances); sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING, prof->vendor, prof->model, prof->model_version); if (!sdi) return NULL; sdi->driver = di; /* Fill in channellist according to this device's profile. */ num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8; for (j = 0; j < num_logic_channels; j++) { if (!(ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, channel_names[j]))) return NULL; sdi->channels = g_slist_append(sdi->channels, ch); } devc = fx2lafw_dev_new(); devc->profile = prof; sdi->priv = devc; drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); if (fx2lafw_check_conf_profile(devlist[i])) { /* Already has the firmware, so fix the new address. */ sr_dbg("Found an fx2lafw device."); sdi->status = SR_ST_INACTIVE; sdi->inst_type = SR_INST_USB; sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL); } else { if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION, prof->firmware) == SR_OK) /* Store when this device's FW was updated. */ devc->fw_updated = g_get_monotonic_time(); else sr_err("Firmware upload failed for " "device %d.", devcnt); sdi->inst_type = SR_INST_USB; sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), 0xff, NULL); } } libusb_free_device_list(devlist, 1); g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free); return devices; }
int main(int argc, char** argv) { int ch; boolean priority_mode = TRUE; boolean test_mode = FALSE; boolean disable_partial_commit = FALSE; boolean full_commit_check = FALSE; boolean break_priority = FALSE; int break_priority_node = -1; boolean disable_hook = FALSE; char *commit_comment = NULL; /* this is needed before calling certain glib functions */ g_type_init(); //grab inputs while ((ch = getopt(argc, argv, "xdpthsecoafb:rlC:")) != -1) { switch (ch) { case 'x': g_old_print_output = TRUE; break; case 'd': g_debug = TRUE; break; case 'h': usage(); exit(0); break; case 'p': priority_mode = FALSE; break; case 't': test_mode = TRUE; break; case 's': g_dump_trans = TRUE; break; case 'e': g_display_error_node = TRUE; break; case 'c': g_coverage = TRUE; break; case 'o': disable_partial_commit = TRUE; break; case 'a': g_dump_actions = TRUE; break; case 'f': full_commit_check = TRUE; break; case 'b': break_priority_node = strtoul(optarg,NULL,10); break_priority = TRUE; break; case 'r': disable_hook = TRUE; break; case 'C': commit_comment = strdup(optarg); break; case 'l': release_config_lock(); break; default: usage(); exit(0); } } //can also be set via environment variable if (getenv("VYATTA_OUTPUT_ERROR_LOCATION") != NULL) { g_print_error_location_all = TRUE; } if (disable_hook == FALSE) { execute_hook(PRE_COMMIT_HOOK_DIR,commit_comment); } initialize_output("Commit"); init_paths(TRUE); d_dplog("commit2: starting up"); if (get_config_lock() != 0) { fprintf(out_stream, "Configuration system temporarily locked " "due to another commit in progress\n"); exit(1); } //get local session data plus configuration data GNode *config_data = common_get_local_session_data(); if (g_node_n_children(config_data) == 0) { common_commit_clean_temp_config(NULL, test_mode); fprintf(out_stream, "No configuration changes to commit\n"); return 0; } GNode *orig_node_tree = g_node_copy(config_data); // Get collection of transactions, i.e. trans nodes that have been activated. GNode *trans_coll = get_transactions(config_data, priority_mode); if (trans_coll == NULL) { printf("commit2: transactions collection is empty, exiting\n"); exit(0); } if (g_debug == TRUE || g_dump_trans == TRUE) { if (g_dump_trans == TRUE) { fprintf(out_stream,"Dumping transactions\n"); syslog(LOG_DEBUG,"Dumping transactions"); } //iterate over config_data and dump... g_node_traverse(trans_coll, G_PRE_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc)dump_func, (gpointer)NULL); if (g_dump_trans == TRUE) { exit(0); } } set_in_commit(TRUE); GNode *trans_child_node = (GNode*)g_node_first_child(trans_coll); if (trans_child_node == NULL) { printf("commit2: No child nodes to process, exiting\n"); exit(0); } //open the changes file and clear FILE *fp_changes = fopen(COMMIT_CHANGES_FILE,"w"); if (fp_changes == NULL) { cond_plog(true, LOG_ERR, "commit2: Cannot access changes file, exiting"); exit(0); } GSList *completed_root_node_coll = NULL; GSList *nodes_visited_coll = NULL; int errors = 0; int i = 0; do { boolean success = FALSE; d_dplog("commit2: Starting new transaction processing pass on root: [%s]", ((trans_child_node && trans_child_node->data && ((struct VyattaNode*)(trans_child_node->data))->_data._name) ? ((struct VyattaNode*)(trans_child_node->data))->_data._name : "")); if (break_priority) { gpointer gp = ((GNode*)trans_child_node)->data; long p = (long) ((struct VyattaNode*)gp)->_config._priority; if (p >= break_priority_node) { g_dump_trans = TRUE; g_node_traverse(trans_child_node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc)dump_func, (gpointer)NULL); g_dump_trans = FALSE; fprintf(out_stream,"Press any key to commit...\n"); // Wait for single character char input = getchar(); input = input; //to fix stupid compilier warning } } //complete() now requires a undisturbed copy of the trans_child_node tree GNode *comp_cp_node = g_node_copy(trans_child_node); if (g_dump_actions == TRUE) { fprintf(out_stream,"\n"); //add an extra line here } //on each priority node now execute actions nodes_visited_coll = NULL; if (validate_configuration(trans_child_node, full_commit_check, &nodes_visited_coll) == TRUE && (success = process_priority_node(trans_child_node)) == TRUE) { //this below copies the node directory from the local to active location //if this is true root skip if (trans_child_node != NULL && trans_child_node->data != NULL && strcmp(((struct VyattaNode*)(trans_child_node->data)) ->_data._path, "/") == 0) { //no op, need better way to define true root } else { if (disable_partial_commit == FALSE && g_dump_actions == FALSE) { completed_root_node_coll = g_slist_append(completed_root_node_coll, comp_cp_node); } } } if (g_dump_actions == TRUE) { success = TRUE; //FORCE SUCCESS ON DISPLAY MODE OF ACTIONS } if (success == FALSE) { errors |= 1; d_dplog("commit2: Failed in processing node"); } else { errors |= 2; } //now update the changes file update_change_file(fp_changes,nodes_visited_coll); fflush(fp_changes); ++i; } while ((trans_child_node = (GNode*) g_node_nth_child((GNode*) trans_coll, (guint) i)) != NULL); if (errors == 2) { /* * Need to add to the following func below to clean up dangling .wh. files */ if (g_dump_actions == FALSE) { common_commit_copy_to_live_config(orig_node_tree, TRUE, test_mode); common_commit_clean_temp_config(orig_node_tree, test_mode); } d_dplog("commit2: successful commit, now cleaning up temp directories"); } else { fprintf(out_stream,"Commit failed\n"); complete(completed_root_node_coll, test_mode); } set_in_commit(FALSE); d_dplog("DONE"); if (fp_changes != NULL) { fclose(fp_changes); } restore_output(); if (disable_hook == FALSE) { if (errors == 2) { setenv(ENV_COMMIT_STATUS,"SUCCESS",1); } else if (errors == 3) { setenv(ENV_COMMIT_STATUS,"PARTIAL",1); } else { setenv(ENV_COMMIT_STATUS,"FAILURE",1); } execute_hook(POST_COMMIT_HOOK_DIR,commit_comment); unsetenv(ENV_COMMIT_STATUS); } //remove tmp changes file as all the work is now done unlink(COMMIT_CHANGES_FILE); exit (errors == 2 ? 0 : 1); }
void fb_post_or_get(FacebookAccount *fba, FacebookMethod method, const gchar *host, const gchar *url, const gchar *postdata, FacebookProxyCallbackFunc callback_func, gpointer user_data, gboolean keepalive) { GString *request; gchar *cookies; FacebookConnection *fbconn; gchar *real_url; gboolean is_proxy = FALSE; const gchar *user_agent; /* TODO: Fix keepalive and use it as much as possible */ keepalive = FALSE; if (host == NULL) host = "www.facebook.com"; if (fba && fba->account && fba->account->proxy_info && (fba->account->proxy_info->type == PURPLE_PROXY_HTTP || (fba->account->proxy_info->type == PURPLE_PROXY_USE_GLOBAL && purple_global_proxy_get_info() && purple_global_proxy_get_info()->type == PURPLE_PROXY_HTTP))) { real_url = g_strdup_printf("http://%s%s", host, url); is_proxy = TRUE; } else { real_url = g_strdup(url); } cookies = fb_cookies_to_string(fba); user_agent = purple_account_get_string(fba->account, "user-agent", "Opera/9.50 (Windows NT 5.1; U; en-GB)"); /* Build the request */ request = g_string_new(NULL); g_string_append_printf(request, "%s %s HTTP/1.0\r\n", (method & FB_METHOD_POST) ? "POST" : "GET", real_url); g_string_append_printf(request, "Host: %s\r\n", host); g_string_append_printf(request, "Connection: %s\r\n", (keepalive ? "Keep-Alive" : "close")); g_string_append_printf(request, "User-Agent: %s\r\n", user_agent); if (method & FB_METHOD_POST) { g_string_append_printf(request, "Content-Type: application/x-www-form-urlencoded\r\n"); g_string_append_printf(request, "Content-length: %zu\r\n", strlen(postdata)); } g_string_append_printf(request, "Accept: */*\r\n"); g_string_append_printf(request, "Cookie: isfbe=false;%s\r\n", cookies); #ifdef HAVE_ZLIB if (zlib_inflate != NULL) g_string_append_printf(request, "Accept-Encoding: gzip\r\n"); #endif purple_debug_misc("facebook", "sending request headers:\n%s\n", request->str); g_string_append_printf(request, "\r\n"); if (method & FB_METHOD_POST) g_string_append_printf(request, "%s", postdata); /* If it needs to go over a SSL connection, we probably shouldn't print * it in the debug log. Without this condition a user's password is * printed in the debug log */ if (method == FB_METHOD_POST) purple_debug_misc("facebook", "sending request data:\n%s\n", postdata); g_free(cookies); g_free(real_url); /* * Do a separate DNS lookup for the given host name and cache it * for next time. * * TODO: It would be better if we did this before we call * purple_proxy_connect(), so we could re-use the result. * Or even better: Use persistent HTTP connections for servers * that we access continually. * * TODO: This cache of the hostname<-->IP address does not respect * the TTL returned by the DNS server. We should expire things * from the cache after some amount of time. */ if (!is_proxy) { /* Don't do this for proxy connections, since proxies do the DNS lookup */ gchar *host_ip; host_ip = g_hash_table_lookup(fba->hostname_ip_cache, host); if (host_ip != NULL) { purple_debug_info("facebook", "swapping original host %s with cached value of %s\n", host, host_ip); host = host_ip; } else if (fba->account && !fba->account->disconnecting) { GSList *host_lookup_list = NULL; PurpleDnsQueryData *query; host_lookup_list = g_slist_prepend( host_lookup_list, g_strdup(host)); host_lookup_list = g_slist_prepend( host_lookup_list, fba); query = purple_dnsquery_a(host, 80, fb_host_lookup_cb, host_lookup_list); fba->dns_queries = g_slist_prepend(fba->dns_queries, query); host_lookup_list = g_slist_append(host_lookup_list, query); } } fbconn = g_new0(FacebookConnection, 1); fbconn->fba = fba; fbconn->method = method; fbconn->hostname = g_strdup(host); fbconn->request = request; fbconn->callback = callback_func; fbconn->user_data = user_data; fbconn->fd = -1; fbconn->connection_keepalive = keepalive; fbconn->request_time = time(NULL); fba->conns = g_slist_prepend(fba->conns, fbconn); fb_attempt_connection(fbconn); }
int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config) { sdp_record_t *record; gboolean tmp, master = TRUE; GError *err = NULL; struct avctp_server *server; if (config) { tmp = g_key_file_get_boolean(config, "General", "Master", &err); if (err) { debug("audio.conf: %s", err->message); g_error_free(err); } else master = tmp; } server = g_new0(struct avctp_server, 1); if (!server) return -ENOMEM; if (!connection) connection = dbus_connection_ref(conn); record = avrcp_tg_record(); if (!record) { error("Unable to allocate new service record"); g_free(server); return -1; } if (add_record_to_server(src, record) < 0) { error("Unable to register AVRCP target service record"); g_free(server); sdp_record_free(record); return -1; } server->tg_record_id = record->handle; record = avrcp_ct_record(); if (!record) { error("Unable to allocate new service record"); g_free(server); return -1; } if (add_record_to_server(src, record) < 0) { error("Unable to register AVRCP controller service record"); sdp_record_free(record); g_free(server); return -1; } server->ct_record_id = record->handle; server->io = avctp_server_socket(src, master); if (!server->io) { remove_record_from_server(server->ct_record_id); remove_record_from_server(server->tg_record_id); g_free(server); return -1; } bacpy(&server->src, src); servers = g_slist_append(servers, server); return 0; }
static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen, gpointer user_data) { struct discover_char *dc = user_data; struct att_data_list *list; unsigned int i, err = ATT_ECODE_ATTR_NOT_FOUND; size_t buflen; uint8_t *buf; guint16 oplen; bt_uuid_t uuid; uint16_t last = 0; if (status) { err = status; goto done; } list = dec_read_by_type_resp(ipdu, iplen); if (list == NULL) { err = ATT_ECODE_IO; goto done; } for (i = 0; i < list->num; i++) { uint8_t *value = list->data[i]; struct gatt_char *chars; bt_uuid_t uuid; last = att_get_u16(value); if (list->len == 7) { bt_uuid_t uuid16 = att_get_uuid16(&value[5]); bt_uuid_to_uuid128(&uuid16, &uuid); } else uuid = att_get_uuid128(&value[5]); chars = g_try_new0(struct gatt_char, 1); if (!chars) { err = ATT_ECODE_INSUFF_RESOURCES; goto done; } if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid)) break; chars->handle = last; chars->properties = value[2]; chars->value_handle = att_get_u16(&value[3]); bt_uuid_to_string(&uuid, chars->uuid, sizeof(chars->uuid)); dc->characteristics = g_slist_append(dc->characteristics, chars); } att_data_list_free(list); if (last != 0 && (last + 1 < dc->end)) { buf = g_attrib_get_buffer(dc->attrib, &buflen); bt_uuid16_create(&uuid, GATT_CHARAC_UUID); oplen = enc_read_by_type_req(last + 1, dc->end, &uuid, buf, buflen); if (oplen == 0) return; g_attrib_send(dc->attrib, 0, buf[0], buf, oplen, char_discovered_cb, dc, NULL); return; } done: err = (dc->characteristics ? 0 : err); dc->cb(dc->characteristics, err, dc->user_data); discover_char_free(dc); }
GSList *quick_search_filter(QuickSearch *qsearch, QSearchCondType type, const gchar *key) { SummaryView *summaryview = qsearch->summaryview; FilterCondType ftype; FilterRule *status_rule = NULL; FilterRule *rule = NULL; FilterCond *cond; FilterInfo fltinfo; GSList *cond_list = NULL; GSList *rule_list = NULL; GSList *flt_mlist = NULL; GSList *cur; gint count = 0, total = 0; gchar status_text[1024]; gboolean dmode; if (!summaryview->all_mlist) return NULL; debug_print("quick_search_filter: filtering summary (type: %d)\n", type); switch (type) { case QS_UNREAD: case QS_MARK: case QS_CLABEL: case QS_MIME: ftype = qsearch_cond_types[type].ftype; cond = filter_cond_new(ftype, 0, 0, NULL, NULL); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_W1DAY: cond = filter_cond_new(FLT_COND_AGE_GREATER, 0, FLT_NOT_MATCH, NULL, "1"); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_LAST5: cond = filter_cond_new(FLT_COND_AGE_GREATER, 0, FLT_NOT_MATCH, NULL, "5"); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_LAST7: cond = filter_cond_new(FLT_COND_AGE_GREATER, 0, FLT_NOT_MATCH, NULL, "7"); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_LAST30: cond = filter_cond_new(FLT_COND_AGE_GREATER, 0, FLT_NOT_MATCH, NULL, "30"); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_IN_ADDRESSBOOK: cond = filter_cond_new(FLT_COND_HEADER, FLT_IN_ADDRESSBOOK, 0, "From", NULL); cond_list = g_slist_append(cond_list, cond); status_rule = filter_rule_new("Status filter rule", FLT_OR, cond_list, NULL); break; case QS_ALL: default: break; } if (key) { gchar **keys; gint i; keys = g_strsplit(key, " ", -1); for (i = 0; keys[i] != NULL; i++) { cond_list = NULL; if (keys[i] == '\0') continue; cond = filter_cond_new(FLT_COND_HEADER, FLT_CONTAIN, 0, "Subject", keys[i]); cond_list = g_slist_append(cond_list, cond); cond = filter_cond_new(FLT_COND_HEADER, FLT_CONTAIN, 0, "From", keys[i]); cond_list = g_slist_append(cond_list, cond); if (FOLDER_ITEM_IS_SENT_FOLDER(summaryview->folder_item)) { cond = filter_cond_new(FLT_COND_TO_OR_CC, FLT_CONTAIN, 0, NULL, keys[i]); cond_list = g_slist_append(cond_list, cond); } if (cond_list) { rule = filter_rule_new("Quick search rule", FLT_OR, cond_list, NULL); rule_list = g_slist_append(rule_list, rule); } } g_strfreev(keys); } memset(&fltinfo, 0, sizeof(FilterInfo)); dmode = get_debug_mode(); set_debug_mode(FALSE); for (cur = summaryview->all_mlist; cur != NULL; cur = cur->next) { MsgInfo *msginfo = (MsgInfo *)cur->data; GSList *hlist = NULL; gboolean matched = TRUE; total++; if (status_rule) { if (type == QS_IN_ADDRESSBOOK) hlist = procheader_get_header_list_from_msginfo (msginfo); if (!filter_match_rule(status_rule, msginfo, hlist, &fltinfo)) { if (hlist) procheader_header_list_destroy(hlist); continue; } } if (rule_list) { GSList *rcur; if (!hlist) hlist = procheader_get_header_list_from_msginfo (msginfo); /* AND keyword match */ for (rcur = rule_list; rcur != NULL; rcur = rcur->next) { rule = (FilterRule *)rcur->data; if (!filter_match_rule(rule, msginfo, hlist, &fltinfo)) { matched = FALSE; break; } } } if (matched) { flt_mlist = g_slist_prepend(flt_mlist, msginfo); count++; } if (hlist) procheader_header_list_destroy(hlist); } flt_mlist = g_slist_reverse(flt_mlist); set_debug_mode(dmode); if (status_rule || rule) { if (count > 0) g_snprintf(status_text, sizeof(status_text), _("%1$d in %2$d matched"), count, total); else g_snprintf(status_text, sizeof(status_text), _("No messages matched")); gtk_label_set_text(GTK_LABEL(qsearch->status_label), status_text); } else gtk_label_set_text(GTK_LABEL(qsearch->status_label), ""); filter_rule_list_free(rule_list); filter_rule_free(status_rule); return flt_mlist; }
static void add_purple_buddy_to_groups(JabberStream *js, const char *jid, const char *alias, GSList *groups) { GSList *buddies, *l; PurpleAccount *account = purple_connection_get_account(js->gc); buddies = purple_find_buddies(js->gc->account, jid); if(!groups) { if(!buddies) groups = g_slist_append(groups, g_strdup(_("Buddies"))); else { /* TODO: What should we do here? Removing the local buddies * is wrong, but so is letting the group state get out of sync with * the server. */ g_slist_free(buddies); return; } } while(buddies) { PurpleBuddy *b = buddies->data; PurpleGroup *g = purple_buddy_get_group(b); buddies = g_slist_delete_link(buddies, buddies); /* XMPP groups are case-sensitive, but libpurple groups are * case-insensitive. We treat a buddy in both "Friends" and "friends" * as only being in one group, but if we push changes about the buddy * to the server, the buddy will be dropped from one of the groups. * Not optimal, but better than the alternative, I think. */ if((l = g_slist_find_custom(groups, purple_group_get_name(g), (GCompareFunc)purple_utf8_strcasecmp))) { /* The buddy is already on the local list. Update info. */ const char *servernick, *balias; /* Previously stored serverside / buddy-supplied alias */ if((servernick = purple_blist_node_get_string((PurpleBlistNode*)b, "servernick"))) serv_got_alias(js->gc, jid, servernick); /* Alias from our roster retrieval */ balias = purple_buddy_get_local_buddy_alias(b); if(alias && !purple_strequal(alias, balias)) purple_serv_got_private_alias(js->gc, jid, alias); g_free(l->data); groups = g_slist_delete_link(groups, l); } else { /* This buddy isn't in the group on the server anymore */ purple_debug_info("jabber", "jabber_roster_parse(): Removing %s " "from group '%s' on the local list\n", purple_buddy_get_name(b), purple_group_get_name(g)); purple_blist_remove_buddy(b); } } if (groups) { char *tmp = roster_groups_join(groups); purple_debug_info("jabber", "jabber_roster_parse(): Adding %s to " "groups: %s\n", jid, tmp); g_free(tmp); } while(groups) { PurpleGroup *g = purple_find_group(groups->data); PurpleBuddy *b = purple_buddy_new(account, jid, alias); if(!g) { g = purple_group_new(groups->data); purple_blist_add_group(g, NULL); } purple_blist_add_buddy(b, NULL, g, NULL); purple_blist_alias_buddy(b, alias); g_free(groups->data); groups = g_slist_delete_link(groups, groups); } g_slist_free(buddies); }
/** * create the scheduled part : that widgets are created at the beginning * and normally never destroyed, they are showed only for * scheduled transactions * Cela ne fonctionne pas : tous les widgets sont détruits par la * fonction gsb_form_create_widgets ( ) * * \param table a GtkTable with the dimension SCHEDULED_HEIGHT*SCHEDULED_WIDTH to be filled * * \return FALSE * */ gboolean gsb_form_scheduler_create ( GtkWidget *table ) { gint row, column; struct_element *element; devel_debug (NULL); if (!table) return FALSE; /* just in case... be sure that not created */ if (scheduled_element_list) gsb_form_scheduler_free_list ( ); /* check the dimensions, * if problem give a warning message but continue the program with changing the values */ g_object_get ( G_OBJECT (table), "n-columns", &column, "n-rows", &row, NULL ); if ( column != SCHEDULED_WIDTH || row != SCHEDULED_HEIGHT ) { warning_debug ( _("gsb_form_scheduler_create is called with a bad table,\n" "the number of rows or columns is not good.\n" "The function will resize the table to the correct values but " "should check that warning.")); gtk_table_resize ( GTK_TABLE (table), SCHEDULED_HEIGHT, SCHEDULED_WIDTH ); } /* ok, now fill the form * we play with height and width, but for now it's fix : 6 columns and 1 line */ for ( row=0 ; row < SCHEDULED_HEIGHT ; row++ ) for ( column=0 ; column < SCHEDULED_WIDTH ; column++ ) { gint element_number; GtkWidget *widget = NULL; const gchar *tooltip_text = NULL; gchar *text_auto [] = { _("Manual"), _("Automatic"), NULL }; gchar *text_frequency [] = { _("Once"), _("Weekly"), _("Monthly"), _("Bimonthly"), _("Quarterly"), _("Yearly"), _("Custom"), NULL }; gchar *text_frequency_user [] = { _("Days"), _("Weeks"), _("Months"), _("Years"), NULL }; element_number = row*SCHEDULED_WIDTH + column; switch ( element_number ) { case SCHEDULED_FORM_ACCOUNT: widget = gsb_account_create_combo_list ( G_CALLBACK ( gsb_form_scheduler_change_account ), NULL, FALSE); gtk_combo_box_set_active ( GTK_COMBO_BOX (widget), 0 ); tooltip_text = _("Choose the account"); break; case SCHEDULED_FORM_AUTO: widget = gsb_combo_box_new_with_index ( text_auto, NULL, NULL ); tooltip_text = _("Automatic/manual scheduled transaction"); break; case SCHEDULED_FORM_FREQUENCY_BUTTON: widget = gsb_combo_box_new_with_index ( text_frequency, G_CALLBACK (gsb_form_scheduler_frequency_button_changed), NULL ); tooltip_text = _("Frequency"); break; case SCHEDULED_FORM_LIMIT_DATE: widget = gsb_calendar_entry_new (FALSE); g_signal_connect ( G_OBJECT (widget), "button-press-event", G_CALLBACK (gsb_form_scheduler_button_press_event), GINT_TO_POINTER (element_number)); g_signal_connect ( G_OBJECT (widget), "focus-in-event", G_CALLBACK (gsb_form_entry_get_focus), GINT_TO_POINTER (element_number)); g_signal_connect_after ( G_OBJECT (widget), "focus-out-event", G_CALLBACK (gsb_form_scheduler_entry_lose_focus), GINT_TO_POINTER (element_number)); tooltip_text = _("Limit date"); break; case SCHEDULED_FORM_FREQUENCY_USER_ENTRY: widget = gtk_entry_new (); g_signal_connect ( G_OBJECT (widget), "focus-in-event", G_CALLBACK (gsb_form_entry_get_focus), GINT_TO_POINTER (element_number)); g_signal_connect_after ( G_OBJECT (widget), "focus-out-event", G_CALLBACK (gsb_form_scheduler_entry_lose_focus), GINT_TO_POINTER (element_number)); tooltip_text = _("Own frequency"); break; case SCHEDULED_FORM_FREQUENCY_USER_BUTTON: widget = gsb_combo_box_new_with_index ( text_frequency_user, NULL, NULL ); tooltip_text = _("Custom frequency"); break; } if (!widget) continue; if (tooltip_text) gtk_widget_set_tooltip_text ( GTK_WIDGET (widget), tooltip_text); /* save the element */ element = g_malloc0 (sizeof (struct_element)); element -> element_number = element_number; element -> element_widget = widget; scheduled_element_list = g_slist_append ( scheduled_element_list, element ); /* set in the form */ gtk_table_attach ( GTK_TABLE (table), widget, column, column+1, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); } gsb_form_scheduler_clean ( ); return FALSE; }