static void xml_print_tree_internal(GNode *node, gpointer data){ NODE_DATA *node_data; node_data = (NODE_DATA *)(node->data); if(node_data->name){ print_indent(node_data->depth); printf("%s", node_data->name); if(node_data->attr != NULL){ GList *list; NODE_ATTR *attr; list = g_list_first(node_data->attr); while(list){ attr = (NODE_ATTR *)(list->data); g_print(" %s=%s", attr->name, attr->value); list = g_list_next(list); } } g_print("\n"); if(G_NODE_IS_LEAF(node)){ print_indent2(node_data->depth); if(node_data->content != NULL){ printf(">%s<\n", node_data->content); } else { printf("NULL\n"); } } else { g_node_children_foreach(node, G_TRAVERSE_ALL, (GNodeForeachFunc)xml_print_tree_internal, (gpointer)NULL); } } else { g_node_children_foreach(node, G_TRAVERSE_ALL, (GNodeForeachFunc)xml_print_tree_internal, (gpointer)NULL); } }
static void handle_vm_section(GNode* root, struct clr_oci_config* config) { if (! (root && root->children)) { return; } if (g_strcmp0(root->data, "path") == 0) { g_autofree gchar* path = clr_oci_resolve_path(root->children->data); if (path) { if (snprintf(config->vm->hypervisor_path, sizeof(config->vm->hypervisor_path), "%s", path) < 0) { g_critical("failed to copy vm hypervisor path"); } } } else if(g_strcmp0(root->data, "image") == 0) { g_autofree gchar* path = clr_oci_resolve_path(root->children->data); if (path) { if (snprintf(config->vm->image_path, sizeof(config->vm->image_path), "%s", path) < 0) { g_critical("failed to copy vm image path"); } } } else if (g_strcmp0(root->data, "kernel") == 0) { g_node_children_foreach(root, G_TRAVERSE_ALL, (GNodeForeachFunc)handle_kernel_section, config); } }
/** * clutter_score_start: * @score: A #ClutterScore * * Starts the score. * * Since: 0.6 */ void clutter_score_start (ClutterScore *score) { ClutterScorePrivate *priv; g_return_if_fail (CLUTTER_IS_SCORE (score)); priv = score->priv; if (priv->is_paused) { g_hash_table_foreach (priv->running_timelines, foreach_running_timeline, GINT_TO_POINTER (ACTION_START)); priv->is_paused = FALSE; } else { g_signal_emit (score, score_signals[STARTED], 0); g_node_children_foreach (priv->root, G_TRAVERSE_ALL, start_children_entries, NULL); } }
static void check_and_store (GNode* node, gpointer data) { TreeElement* temp = (TreeElement*) node -> data; STOCKINFO* stock_data = (STOCKINFO*) temp -> userdata; /* 얕은 복사 */ regex_t_and_node* temp_data = (regex_t_and_node*) malloc (sizeof (regex_t_and_node)); *temp_data = *(regex_t_and_node*) data; int status = regexec (&(temp_data -> state), stock_data -> symbol, 0, NULL, 0); if (status == 0 || g_node_depth (node) == 2) { /* 얕은 복사 */ /* TreeElement* copy_data = (TreeElement*) malloc (sizeof (TreeElement)); *copy_data = *temp; */ GNode* copy_node = new_tree_node (stock_data, IS_OPENED | IS_ACTIVATED, temp_data -> array); g_node_insert (temp_data -> array, -1, copy_node); temp_data -> array = copy_node; if (!G_NODE_IS_LEAF (node)) { g_node_children_foreach (node, G_TRAVERSE_ALL, check_and_store, (gpointer) temp_data); } /* Recursive call */ } free (temp_data); return; }
static void xml_destroy_tree_internal(GNode *node, gpointer data){ NODE_DATA *node_data; #ifdef XML_TRACE LOG(LOG_DEBUG, "IN : xml_destroy_tree_internal()"); #endif node_data = (NODE_DATA *)(node->data); if(G_NODE_IS_LEAF(node)){ if(node_data->name) g_free(node_data->name); if(node_data->content) g_free(node_data->content); if(node_data->attr != NULL){ GList *list; NODE_ATTR *attr; list = g_list_first(node_data->attr); while(list){ attr = (NODE_ATTR *)(list->data); if(attr->name) g_free(attr->name); if(attr->value) g_free(attr->value); g_free(attr); list = g_list_next(list); } } } else { g_node_children_foreach(node, G_TRAVERSE_ALL, (GNodeForeachFunc)xml_destroy_tree_internal, (gpointer)NULL); } #ifdef XML_TRACE LOG(LOG_DEBUG, "OUT : xml_destroy_tree_internal()"); #endif }
static void plist_copy_node(GNode * node, gpointer parent_node_ptr) { plist_t newnode = NULL; plist_data_t data = plist_get_data(node); plist_data_t newdata = plist_new_plist_data(); assert(data); // plist should always have data memcpy(newdata, data, sizeof(struct plist_data_s)); plist_type node_type = plist_get_node_type(node); if (node_type == PLIST_DATA || node_type == PLIST_STRING || node_type == PLIST_KEY) { switch (node_type) { case PLIST_DATA: newdata->buff = (uint8_t *) malloc(data->length); memcpy(newdata->buff, data->buff, data->length); case PLIST_KEY: case PLIST_STRING: newdata->strval = strdup((char *) data->strval); default: break; } } newnode = plist_new_node(newdata); if (*(plist_t*)parent_node_ptr) { g_node_append(*(plist_t*)parent_node_ptr, newnode); } else { *(plist_t*)parent_node_ptr = newnode; } g_node_children_foreach(node, G_TRAVERSE_ALL, plist_copy_node, &newnode); }
void envar_handler(GNode *node) { gchar profile_file[PATH_MAX] = { 0 }; buffer_envar = g_string_new(""); LOG(MOD "Groups Handler running...\n"); g_node_children_foreach(node, G_TRAVERSE_ALL, envar_item, NULL); g_strlcpy(profile_file, PROFILE_PATH, PATH_MAX); if (make_dir(profile_file, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) != 0) { LOG(MOD "Cannot create directory '%s'\n", (char*)profile_file); goto fail; } g_strlcat(profile_file, "/cloud-init.sh", PATH_MAX); if (!write_file(buffer_envar->str, buffer_envar->len, profile_file, O_CREAT|O_APPEND|O_WRONLY, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)) { LOG(MOD "Cannot write environment variables\n"); goto fail; } fail: g_string_free(buffer_envar, true); buffer_envar = NULL; }
static void serialize_plist(GNode * node, gpointer data) { uint64_t *index_val = NULL; struct serialize_s *ser = (struct serialize_s *) data; uint64_t current_index = ser->objects->len; //first check that node is not yet in objects gpointer val = g_hash_table_lookup(ser->ref_table, node); if (val) { //data is already in table return; } //insert new ref index_val = (uint64_t *) malloc(sizeof(uint64_t)); *index_val = current_index; g_hash_table_insert(ser->ref_table, node, index_val); //now append current node to object array g_ptr_array_add(ser->objects, node); //now recurse on children g_node_children_foreach(node, G_TRAVERSE_ALL, serialize_plist, data); return; }
static void i7_node_finalize(GObject *self) { I7_NODE_USE_PRIVATE; cairo_pattern_destroy(priv->label_pattern); cairo_pattern_destroy(priv->node_pattern[NODE_UNPLAYED_UNBLESSED]); cairo_pattern_destroy(priv->node_pattern[NODE_UNPLAYED_BLESSED]); cairo_pattern_destroy(priv->node_pattern[NODE_PLAYED_UNBLESSED]); cairo_pattern_destroy(priv->node_pattern[NODE_PLAYED_BLESSED]); g_free(priv->command); g_free(priv->label); g_free(priv->transcript_text); g_free(priv->expected_text); g_free(priv->transcript_pango_string); g_free(priv->expected_pango_string); g_free(priv->id); goo_canvas_points_unref(I7_NODE(self)->tree_points); g_list_free(priv->transcript_diffs); g_list_free(priv->expected_diffs); /* recurse */ g_node_children_foreach(I7_NODE(self)->gnode, G_TRAVERSE_ALL, (GNodeForeachFunc)unref_node, NULL); /* free the node itself */ g_node_destroy(I7_NODE(self)->gnode); G_OBJECT_CLASS(i7_node_parent_class)->finalize(self); }
static bool vm_handle_section(GNode* root, struct clr_oci_config* config) { gboolean ret = false; struct stat st; if (! root) { g_critical("root node is NULL"); return false; } if (! config ) { g_critical("oci config is NULL"); return false; } if(! config->vm) { config->vm = g_malloc0(sizeof(struct clr_oci_vm_cfg)); } g_node_children_foreach(root, G_TRAVERSE_ALL, (GNodeForeachFunc)handle_vm_section, config); /* Needs: * - hypervisor_path * - image_path * - kernel_path * Optional: * - kernel_params */ if (! config->vm->hypervisor_path[0] || stat (config->vm->hypervisor_path, &st) < 0) { g_critical("VM hypervisor path does not exist"); goto out; } if (! config->vm->image_path[0] || stat (config->vm->image_path, &st) < 0) { g_critical("VM image path does not exist"); goto out; } if (! config->vm->kernel_path[0] || stat (config->vm->kernel_path, &st) < 0) { g_critical("VM kernel path does not exist"); goto out; } ret = true; out: if (! ret) { g_free_if_set (config->vm->kernel_params); g_free (config->vm); config->vm = NULL; } return ret; }
static void envar_item(GNode* node, gpointer data) { if (!node->data || !data) { g_node_children_foreach(node, G_TRAVERSE_ALL, envar_item, node->data ? node->data : data); } else { g_string_append_printf(buffer_envar, "export %s=\"%s\"\n", (char*)data, (char*)node->data ); g_setenv(data, node->data, true); } }
void privacy_msginfo_get_signed_state(MsgInfo *msginfo, gchar **system) { struct SignedState sstate; MimeInfo *mimeinfo = procmime_scan_message(msginfo); if (!mimeinfo) return; sstate.msginfo = msginfo; sstate.system = system; g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_signed_flag, &sstate); }
static void runcmd_item(GNode* node, gpointer command_line) { if (!node->data) { g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, command_line); if (!exec_task(((GString*)command_line)->str)) { LOG(MOD "Execute command failed\n"); } g_string_set_size((GString*)command_line, 0); } else { g_string_append_printf((GString*)command_line, "%s ", (char*)node->data); } }
void open_close_branch (GNode* parent, int flag) { if (!G_NODE_IS_LEAF (parent)) { /* remove open flag */ TreeElement* temp = (TreeElement*) parent -> data; temp -> state_info -= (temp -> state_info & BASIS_OPENED); /* and redefine */ temp -> state_info += flag; g_node_children_foreach (parent, G_TRAVERSE_ALL, activate_node, &flag); } }
static void runcmd_item(GNode* node, gpointer data) { gchar command_line[COMMAND_SIZE] = { 0 }; if (!node->data) { g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, command_line); if (!exec_task(command_line)) { LOG(MOD "Execute command failed\n"); } } else { g_strlcat(data, node->data,COMMAND_SIZE); g_strlcat(data, " ", COMMAND_SIZE); } }
static void groups_item(GNode* node, gpointer data) { gchar command_groupadd[COMMAND_SIZE]; gchar command_usermod[COMMAND_SIZE]; if (!node->data) { /* null placeholder */ g_node_children_foreach(node, G_TRAVERSE_ALL, groups_item, data); } else if (!data) { /* add new group */ LOG(MOD "Adding %s group...\n", (char*)node->data); g_snprintf(command_groupadd, COMMAND_SIZE, GROUPADD_PATH " -f '%s'", (char*)node->data); exec_task(command_groupadd); g_node_children_foreach(node, G_TRAVERSE_ALL, groups_item, node->data); } else { /* add user to new group */ LOG(MOD "Adding %s to %s group...\n", (char*)node->data, (char*)data); g_snprintf(command_usermod, COMMAND_SIZE, USERMOD_PATH " -a -G '%s' '%s'", (char*)data, (char*)node->data); exec_task(command_usermod); } }
static bool annotations_handle_section (GNode* root, struct cc_oci_config* config) { if (! root) { g_critical("root node is NULL"); return false; } if (! config ) { g_critical("oci config is NULL"); return false; } g_node_children_foreach (root, G_TRAVERSE_ALL, (GNodeForeachFunc)handle_annotation, config); return true; }
GNode* search_by_regex (GNode* node, char* pattern, GNode* empty_GNode) { TreeElement* root_data; root_data = (TreeElement*) node -> data; STOCKINFO* userdata = (STOCKINFO*) root_data -> userdata; empty_GNode = new_tree_node (userdata, IS_OPENED | IS_ACTIVATED, NULL); GNode* fulled_GNode = empty_GNode; regex_t_and_node data; regex_t* state = &(data.state); int res = regcomp (state, pattern, REG_EXTENDED); char str [100]; regerror (res, state, str, sizeof (str)); data.array = fulled_GNode; g_node_children_foreach (node, G_TRAVERSE_ALL, check_and_store, (gpointer) &data); regfree (&data.state); return fulled_GNode; }
static void msginfo_set_signed_flag(GNode *node, gpointer data) { struct SignedState *sstate = (struct SignedState *)data; MsgInfo *msginfo = sstate->msginfo; MimeInfo *mimeinfo = node->data; if (privacy_mimeinfo_is_signed(mimeinfo)) { procmsg_msginfo_set_flags(msginfo, 0, MSG_SIGNED); if (sstate->system && !*(sstate->system) && mimeinfo->privacy) *(sstate->system) = g_strdup(mimeinfo->privacy->system->id); } if (privacy_mimeinfo_is_encrypted(mimeinfo)) { procmsg_msginfo_set_flags(msginfo, 0, MSG_ENCRYPTED); if (sstate->system && !*(sstate->system) && mimeinfo->privacy) *(sstate->system) = g_strdup(mimeinfo->privacy->system->id); } else { /* searching inside encrypted parts doesn't really make sense */ g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_signed_flag, sstate); } }
static void on_timeline_completed (ClutterTimeline *timeline, ClutterScoreEntry *entry) { ClutterScorePrivate *priv = entry->score->priv; g_hash_table_remove (priv->running_timelines, GUINT_TO_POINTER (entry->id)); g_signal_handler_disconnect (timeline, entry->complete_id); entry->complete_id = 0; CLUTTER_NOTE (SCHEDULER, "timeline [%p] ('%lu') completed", entry->timeline, entry->id); g_signal_emit (entry->score, score_signals[TIMELINE_COMPLETED], 0, entry->timeline); /* start every child */ if (entry->node->children) { g_node_children_foreach (entry->node, G_TRAVERSE_ALL, start_children_entries, NULL); } /* score has finished - fire 'completed' signal */ if (g_hash_table_size (priv->running_timelines) == 0) { CLUTTER_NOTE (SCHEDULER, "looks like we finished"); g_signal_emit (entry->score, score_signals[COMPLETED], 0); clutter_score_stop (entry->score); if (priv->loop) clutter_score_start (entry->score); } }
static void plist_free_node(GNode * node, gpointer none) { g_node_unlink(node); plist_data_t data = plist_get_data(node); if (data) { switch (data->type) { case PLIST_KEY: case PLIST_STRING: free(data->strval); break; case PLIST_DATA: free(data->buff); break; default: break; } free(data); } node->data = NULL; g_node_children_foreach(node, G_TRAVERSE_ALL, plist_free_node, NULL); }
ProtocolHierarchyDialog::ProtocolHierarchyDialog(QWidget &parent, CaptureFile &cf) : WiresharkDialog(parent, cf), ui(new Ui::ProtocolHierarchyDialog) { ui->setupUi(this); loadGeometry(parent.width() * 4 / 5, parent.height() * 4 / 5); setWindowSubtitle(tr("Protocol Hierarchy Statistics")); ui->hierStatsTreeWidget->setItemDelegateForColumn(pct_packets_col_, &percent_bar_delegate_); ui->hierStatsTreeWidget->setItemDelegateForColumn(pct_bytes_col_, &percent_bar_delegate_); ph_stats_t *ph_stats = ph_stats_new(cap_file_.capFile()); if (ph_stats) { ui->hierStatsTreeWidget->invisibleRootItem()->setData(0, Qt::UserRole, VariantPointer<ph_stats_t>::asQVariant(ph_stats)); g_node_children_foreach(ph_stats->stats_tree, G_TRAVERSE_ALL, addTreeNode, ui->hierStatsTreeWidget->invisibleRootItem()); ph_stats_free(ph_stats); } ui->hierStatsTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->hierStatsTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showProtoHierMenu(QPoint))); ui->hierStatsTreeWidget->setSortingEnabled(true); ui->hierStatsTreeWidget->expandAll(); for (int i = 0; i < ui->hierStatsTreeWidget->columnCount(); i++) { ui->hierStatsTreeWidget->resizeColumnToContents(i); } QMenu *submenu; FilterAction::Action cur_action = FilterAction::ActionApply; submenu = ctx_menu_.addMenu(FilterAction::actionName(cur_action)); foreach (FilterAction::ActionType at, FilterAction::actionTypes()) { FilterAction *fa = new FilterAction(submenu, cur_action, at); submenu->addAction(fa); connect(fa, SIGNAL(triggered()), this, SLOT(filterActionTriggered())); }
static void on_timeline_marker (ClutterTimeline *timeline, const gchar *marker_name, gint frame_num, ClutterScoreEntry *entry) { GNode *parent; CLUTTER_NOTE (SCHEDULER, "timeline [%p] marker ('%s') reached", entry->timeline, entry->marker); parent = find_entry_by_timeline (entry->score, timeline); if (!parent) return; /* start every child */ if (parent->children) { g_node_children_foreach (parent, G_TRAVERSE_ALL, start_children_entries, (gpointer) marker_name); } }
gchar * i7_node_get_xml(I7Node *self) { I7_NODE_USE_PRIVATE; /* Escape the following strings if necessary */ gchar *command = g_markup_escape_text(priv->command, -1); gchar *transcript_text = g_markup_escape_text(priv->transcript_text, -1); gchar *expected_text = g_markup_escape_text(priv->expected_text, -1); gchar *label = g_markup_escape_text(priv->label, -1); GString *string = g_string_new(""); g_string_append_printf(string, " <item nodeId=\"%s\">\n", priv->id); g_string_append_printf(string, " <command xml:space=\"preserve\">%s</command>\n", command); g_string_append_printf(string, " <result xml:space=\"preserve\">%s</result>\n", transcript_text); g_string_append_printf(string, " <commentary xml:space=\"preserve\">%s</commentary>\n", expected_text); g_string_append_printf(string, " <played>%s</played>\n", priv->played? "YES" : "NO"); g_string_append_printf(string, " <changed>%s</changed>\n", priv->changed? "YES" : "NO"); g_string_append_printf(string, " <temporary score=\"%d\">%s</temporary>\n", priv->score, priv->locked? "NO" : "YES"); if(label) g_string_append_printf(string, " <annotation xml:space=\"preserve\">%s</annotation>\n", label); if(self->gnode->children) { g_string_append(string, " <children>\n"); g_node_children_foreach(self->gnode, G_TRAVERSE_ALL, (GNodeForeachFunc)write_child_pointer, string); g_string_append(string, " </children>\n"); } g_string_append(string, " </item>\n"); /* Free strings if necessary */ g_free(command); g_free(transcript_text); g_free(expected_text); g_free(label); return g_string_free(string, FALSE); /* return cstr */ }
void write_files_handler(GNode *node) { LOG(MOD "Write Files Handler running...\n"); g_node_children_foreach(node, G_TRAVERSE_ALL, write_files_item, NULL); }
void service_handler(GNode *node) { LOG(MOD "Service Handler running...\n"); g_node_children_foreach(node, G_TRAVERSE_ALL, service_item, NULL); }
void runcmd_handler(GNode *node) { GString* command_line = g_string_new(""); LOG(MOD "runcmd handler running...\n"); g_node_children_foreach(node, G_TRAVERSE_ALL, runcmd_item, command_line); g_string_free(command_line, true); }
static void users_item(GNode* node, gpointer data) { if (node->data) { /* to avoid bugs with key(gecos, etc) as username */ if (node->children) { for (size_t i = 0; users_options[i].key != NULL; ++i) { if (0 == g_strcmp0(node->data, users_options[i].key)) { if (users_options[i].func) { users_options[i].func(node->children, data, users_options[i].data); } return; } } LOG(MOD "No handler for %s.\n", (char*)node->data); return; } users_add_username(node, data, "%s"); } else { bool b; GString* sudo_directives; GString* ssh_keys; GString* command = g_string_new(USERADD_PATH " "); memset(users_current_username, 0, LOGIN_NAME_MAX); g_node_children_foreach(node, G_TRAVERSE_ALL, users_item, command); if (0 == strlen(users_current_username)) { LOG(MOD "Missing username.\n"); return; } LOG(MOD "Adding %s user...\n", users_current_username); exec_task(command->str); CLOUD_CONFIG_KEY(LOCK_PASSWD, "lock-passwd"); CLOUD_CONFIG_KEY(INACTIVE, "inactive"); CLOUD_CONFIG_KEY(SSH_AUTH_KEYS, "ssh-authorized-keys"); CLOUD_CONFIG_KEY(SUDO, "sudo"); GNode *item = cloud_config_find(node, LOCK_PASSWD); if (item) { cloud_config_bool(item, &b); if (b) { LOG(MOD "Locking %s user.\n", users_current_username); g_string_printf(command, PASSWD_PATH " -l '%s'", users_current_username); exec_task(command->str); } } item = cloud_config_find(node, INACTIVE); if (item) { cloud_config_bool(item, &b); if (b) { LOG(MOD "Deactivating %s user...\n", users_current_username); g_string_printf(command, USERMOD_PATH " --expiredate 1 '%s'", users_current_username); exec_task(command->str); } } g_string_free(command, true); item = cloud_config_find(node, SSH_AUTH_KEYS); if (item) { ssh_keys = g_string_new(""); g_node_traverse(item->parent, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, users_ssh_key_item, ssh_keys); if (!write_ssh_keys(ssh_keys, users_current_username)) { LOG(MOD "Cannot write ssh keys\n"); } g_string_free(ssh_keys, true); } item = cloud_config_find(node, SUDO); if (item) { sudo_directives = g_string_new(""); g_string_printf(sudo_directives, "# Rules for %s user\n", users_current_username); g_node_traverse(item->parent, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, users_sudo_item, sudo_directives); g_string_append(sudo_directives, "\n"); if (!write_sudo_directives(sudo_directives, "users-cloud-init", O_CREAT|O_APPEND|O_WRONLY)) { LOG(MOD "Cannot write sudo directives\n"); } g_string_free(sudo_directives, true); } } }
void users_handler(GNode *node) { LOG(MOD "Users Handler running...\n"); g_node_children_foreach(node, G_TRAVERSE_ALL, users_item, NULL); }
void groups_handler(GNode *node) { LOG(MOD "Groups Handler running...\n"); g_node_children_foreach(node, G_TRAVERSE_ALL, groups_item, NULL); }