static int sim_init() { int i; dbg("************************************\n"); dbg("****** Blade Center Simulator ******\n"); dbg("************************************\n"); sim_hash = g_hash_table_new(g_str_hash, g_str_equal); if (sim_hash == NULL) { dbg("Cannot allocate simulation hash table\n"); return -1; } for (i=0; sim_resource_array[i].oid != NULL; i++) { char *key; char *key_exists; SnmpMibInfoT *mibinfo; key = g_strdup(sim_resource_array[i].oid); if (!key) { dbg("Cannot allocate memory for key for oid=%s\n", sim_resource_array[i].oid); sim_close(); return -1; } mibinfo = g_malloc0(sizeof(SnmpMibInfoT)); if (!mibinfo) { dbg("Cannot allocate memory for hash value for oid=%s", sim_resource_array[i].oid); sim_close(); return -1; } key_exists = g_hash_table_lookup(sim_hash, key); if (!key_exists) { mibinfo->type = sim_resource_array[i].mib.type; switch (mibinfo->type) { case ASN_INTEGER: mibinfo->value.integer = sim_resource_array[i].mib.value.integer; break; case ASN_OCTET_STR: strcpy(mibinfo->value.string, sim_resource_array[i].mib.value.string); break; default: dbg("Unknown SNMP type=%d for oid=%s\n", mibinfo->type, key); return -1; } g_hash_table_insert(sim_hash, key, mibinfo); } else { dbg("WARNING: Oid %s is defined twice\n", sim_resource_array[i].oid); } } return 0; }
static gboolean collect_coverage_for (MonoProfiler *prof, MonoMethod *method) { int i; char *classname; char *fqn; MonoMethodHeader *header; gboolean has_positive, found; guint32 iflags, flags, code_size; MonoClass *klass; MonoImage *image; flags = mono_method_get_flags (method, &iflags); if ((iflags & 0x1000 /*METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL*/) || (flags & 0x2000 /*METHOD_ATTRIBUTE_PINVOKE_IMPL*/)) return FALSE; //if (method->wrapper_type != MONO_WRAPPER_NONE) // return FALSE; klass = mono_method_get_class (method); image = mono_class_get_image (klass); /* Hacky way of determining the executing assembly */ if (! prof->outfile_name && (strcmp (mono_method_get_name (method), "Main") == 0)) { prof->outfile_name = g_strdup_printf ("%s.cov", mono_image_get_filename (image)); } /* Check filters */ if (prof->filters) { /* Check already filtered classes first */ if (g_hash_table_lookup (prof->filtered_classes, klass)) return FALSE; classname = mono_type_get_name (mono_class_get_type (klass)); fqn = g_strdup_printf ("[%s]%s", mono_image_get_name (image), classname); // Check positive filters first has_positive = FALSE; found = FALSE; for (i = 0; i < prof->filters->len; ++i) { char *filter = g_ptr_array_index (prof->filters_as_str, i); if (filter [0] == '+') { filter = &filter [1]; if (strstr (fqn, filter) != NULL) found = TRUE; has_positive = TRUE; } } if (has_positive && !found) return FALSE; for (i = 0; i < prof->filters->len; ++i) { // Is substring search suffices ??? // GPatternSpec *spec = g_ptr_array_index (filters, i); // if (g_pattern_match_string (spec, classname)) { char *filter = g_ptr_array_index (prof->filters_as_str, i); if (filter [0] == '+') continue; // Skip '-' filter = &filter [1]; if (strstr (fqn, filter) != NULL) { g_hash_table_insert (prof->filtered_classes, klass, klass); return FALSE; } } g_free (fqn); g_free (classname); } header = mono_method_get_header (method); mono_method_header_get_code (header, &code_size, NULL); if (code_size > 20000) { exit (1); g_warning ("Unable to instrument method %s:%s since it is too complex.", mono_class_get_name (klass), mono_method_get_name (method)); return FALSE; } g_hash_table_insert (prof->methods, method, method); g_hash_table_insert (prof->classes, klass, klass); g_hash_table_insert (prof->assemblies, mono_image_get_assembly (image), mono_image_get_assembly (image)); return TRUE; }
int load_linkip(char *filepath) { FILE *fp; //打开配置文件指针 int a[4]; //临时存储点分IP的4个段 int flag; //标识IP是否合法 char s[1024]; //存储从配置文件中读取的一行数据 uint32_t i; //for循环计数 char c,c1; //连续从文件的一行中读取的两个字符,用以标识变量、IP、注释行无用行 char *eq = NULL;//字符串中表示"="的指针 int len = 0; //读取的字符串长度,如果是一个变量,其标识符的长度要大于0 int idc; //临时存储idc 编号 int link; //临时存储link编号 int master; //临时存储master编号 link_ip_t *tmpip = NULL;//指向待探测ip fp = fopen(filepath,"rt"); if (fp == NULL) ERROR_RETURN(("can not open config file:link_ip.congfig"), -1); while (!feof(fp)) { c = fgetc(fp); if ((int)c == -1) { //EOF==-1 break; } if (c != '$') { while (c != '\n' && !feof(fp)) { c = fgetc(fp); } continue; } if ((c1 = fgetc(fp)) != ':') { while (c != '\n' && !feof(fp)) { c = fgetc(fp); } continue; } if ('$' == c && ':' ==c1) { //memset(s,0,1024); len = 0; fgets(s,1024,fp); if ((eq = strchr(s,'=')) == NULL) continue; len = eq - s; if ( len <= 0 ) continue; if (bcmp(s,"link_ip",len) == 0) { flag = 0; idc = link = master = a[0] = a[1] = a[2] = a[3] = -1; sscanf(eq + 1,"%d,%d,%d.%d.%d.%d,%d",&idc,&link,&a[0],&a[1],&a[2],&a[3],&master); if(idc <= 0 || link <= 0) continue; for (i = 0;i <= 3;i++) { if ( a[i] > 255 || a[i] < 0 ) { ERROR_LOG("[warning]:illegal link ip in file\"%s\"[%s],ignored",filepath,s); flag = 1; //IP有问题!则跳出并置位错误标记为真 break; } }//for if (!flag) { if ((tmpip = (link_ip_t*)malloc(sizeof(link_ip_t))) == NULL) ERROR_RETURN(("Load_Link_Config:read ip.malloc failed!"), -1); tmpip->ip = a[0]*256*256*256 + a[1]*256*256 + a[2]*256 + a[3]; tmpip->idc_observer = idc; tmpip->idc_master = master; tmpip->link_no = link; snprintf((char*)tmpip->hashkey, sizeof(tmpip->hashkey), "%d%d", tmpip->idc_observer, tmpip->ip); tmpip->next = NULL; if (link_ip_set == NULL) link_ip_set = tmpip; else { tmpip->next = link_ip_set; link_ip_set = tmpip; } if (g_hash_table_lookup(link_hash_ip, tmpip->hashkey ) == NULL) g_hash_table_insert(link_hash_ip, tmpip->hashkey, tmpip); }//if legal ip }//if linkip }//if $: }//while fclose(fp); return 0; }
kpfs_ret kpfs_node_parse_dir(kpfs_node * parent_node, const char *path) { char *response = NULL; json_object *jobj; json_object *tmp_jobj; kpfs_node *node = NULL; int len = 0; char *parent_path = NULL; kpfs_ret ret = KPFS_RET_FAIL; if (NULL == parent_node) return KPFS_RET_FAIL; response = (char *)kpfs_api_metadata(path); KPFS_LOG("response %s:\n", response); jobj = json_tokener_parse(response); if (NULL == jobj || is_error(jobj)) { KPFS_FILE_LOG("%s:%d, json_tokener_parse return error.\n", __FUNCTION__, __LINE__); KPFS_SAFE_FREE(response); return KPFS_RET_FAIL; } json_object_object_foreach(jobj, key, val) { if (!strcmp(key, KPFS_ID_MSG)) { if (json_type_string == json_object_get_type(val)) { if (0 == strcmp(KPFS_MSG_STR_REUSED_NONCE, json_object_get_string(val))) { KPFS_FILE_LOG("%s:%d, receive reused nonce.\n", __FUNCTION__, __LINE__); goto error_out; } } } else if (!strcmp(key, KPFS_ID_PATH)) { } else if (!strcmp(key, KPFS_ID_ROOT)) { if (json_type_string == json_object_get_type(val)) { } } else if (!strcmp(key, KPFS_ID_HASH)) { } else if (!strcmp(key, KPFS_ID_FILES)) { if (json_type_array == json_object_get_type(val)) { int j = 0, array_len = 0; array_len = json_object_array_length(val); for (j = 0; j < array_len; j++) { tmp_jobj = json_object_array_get_idx(val, j); if (tmp_jobj && !is_error(tmp_jobj)) { node = calloc(sizeof(kpfs_node), 1); if (NULL == node) { KPFS_FILE_LOG("%s:%d, fail to calloc node.\n", __FUNCTION__, __LINE__); goto error_out; } errno = pthread_mutex_init(&(node->mutex), NULL); if (errno) { KPFS_FILE_LOG("%s:%d, pthread_mutex_init fail.\n", __FUNCTION__, __LINE__); goto error_out; } node->sub_nodes = g_hash_table_new(g_str_hash, g_str_equal); len = strlen(path) + 1; parent_path = calloc(len, 1); snprintf(parent_path, len, "%s", path); KPFS_FILE_LOG("\n", __FUNCTION__, __LINE__); json_object_object_foreach(tmp_jobj, key2, val2) { if (!strcmp(key2, KPFS_ID_IS_DELETED)) { if (json_type_boolean == json_object_get_type(val2)) { node->is_deleted = json_object_get_boolean(val2) == TRUE ? 1 : 0; KPFS_FILE_LOG("%s:%d, is_deleted: %d.\n", __FUNCTION__, __LINE__, node->is_deleted); } } else if (!strcmp(key2, KPFS_ID_NAME)) { if (json_type_string == json_object_get_type(val2)) { node->name = strdup(json_object_get_string(val2)); KPFS_FILE_LOG("%s:%d, name: %s.\n", __FUNCTION__, __LINE__, node->name); } } else if (!strcmp(key2, KPFS_ID_REV)) { if (json_type_string == json_object_get_type(val2)) { node->revision = strdup(json_object_get_string(val2)); KPFS_FILE_LOG("%s:%d, revision: %s.\n", __FUNCTION__, __LINE__, json_object_get_string(val2)); } } else if (!strcmp(key2, KPFS_ID_CREATE_TIME)) { if (json_type_string == json_object_get_type(val2)) { char str[128] = { 0 }; snprintf(str, sizeof(str), "%s", json_object_get_string(val2)); node->st.st_ctime = kpfs_node_str2time(str); KPFS_FILE_LOG("%s:%d, ctime: %d.\n", __FUNCTION__, __LINE__, node->st.st_ctime); } } else if (!strcmp(key2, KPFS_ID_MODIFY_TIME)) { if (json_type_string == json_object_get_type(val2)) { char str[128] = { 0 }; snprintf(str, sizeof(str), "%s", json_object_get_string(val2)); node->st.st_mtime = kpfs_node_str2time(str); KPFS_FILE_LOG("%s:%d, mtime: %d.\n", __FUNCTION__, __LINE__, node->st.st_mtime); } } else if (!strcmp(key2, KPFS_ID_SIZE)) { if (json_type_int == json_object_get_type(val2)) { node->st.st_size = json_object_get_int(val2); KPFS_FILE_LOG("%s:%d, size: %d.\n", __FUNCTION__, __LINE__, node->st.st_size); } } else if (!strcmp(key2, KPFS_ID_TYPE)) { if (json_type_string == json_object_get_type(val2)) { if (0 == strcasecmp(KPFS_NODE_TYPE_STR_FILE, json_object_get_string(val2))) { node->type = KPFS_NODE_TYPE_FILE; } else { node->type = KPFS_NODE_TYPE_FOLDER; } KPFS_FILE_LOG("%s:%d, type: %d.\n", __FUNCTION__, __LINE__, node->type); } } else if (!strcmp(key2, KPFS_ID_FILE_ID)) { if (json_type_string == json_object_get_type(val2)) { node->id = strdup(json_object_get_string(val2)); KPFS_FILE_LOG("%s:%d, id: %s.\n", __FUNCTION__, __LINE__, node->id); } } } if (node->name) { if (1 == strlen(parent_path) && parent_path[0] == '/') { len = strlen(parent_path) + strlen(node->name) + 1; node->fullpath = calloc(len, 1); snprintf(node->fullpath, len, "%s%s", parent_path, node->name); } else { len = strlen(parent_path) + strlen("/") + strlen(node->name) + 1; node->fullpath = calloc(len, 1); snprintf(node->fullpath, len, "%s/%s", parent_path, node->name); } KPFS_FILE_LOG("%s:%d, fullpath: %s.\n", __FUNCTION__, __LINE__, node->fullpath); if (KPFS_NODE_TYPE_FOLDER == node->type) { kpfs_node_parse_dir(node, node->fullpath); node->st.st_mode = S_IFDIR | 0755; node->st.st_nlink = 2; if (0 == node->st.st_size) node->st.st_size = getpagesize(); } else { node->st.st_mode = S_IFREG | 0666; node->st.st_nlink = 1; } KPFS_NODE_LOCK(parent_node); g_hash_table_insert(parent_node->sub_nodes, node->fullpath, node); KPFS_NODE_UNLOCK(parent_node); } } } } }
static void lvm_update_vgs (GObject *source_obj, GAsyncResult *result, gpointer user_data) { UDisksLVM2State *state; UDisksDaemon *daemon = UDISKS_DAEMON (source_obj); GDBusObjectManagerServer *manager; GTask *task = G_TASK (result); GError *error = NULL; VGsPVsData *data = g_task_propagate_pointer (task, &error); BDLVMVGdata **vgs = NULL; BDLVMPVdata **pvs = NULL; GHashTableIter vg_name_iter; gpointer key, value; const gchar *vg_name; if (!data) { if (error) udisks_warning ("LVM2 plugin: %s", error->message); else /* this should never happen */ udisks_warning ("LVM2 plugin: failure but no error when getting VGs!"); return; } vgs = data->vgs; pvs = data->pvs; /* free the data container (but not 'vgs' and 'pvs') */ g_free (data); manager = udisks_daemon_get_object_manager (daemon); state = get_module_state (daemon); /* Remove obsolete groups */ g_hash_table_iter_init (&vg_name_iter, udisks_lvm2_state_get_name_to_volume_group (state)); while (g_hash_table_iter_next (&vg_name_iter, &key, &value)) { UDisksLinuxVolumeGroupObject *group; gboolean found = FALSE; vg_name = key; group = value; for (BDLVMVGdata **vgs_p=vgs; !found && (*vgs_p); vgs_p++) found = g_strcmp0 ((*vgs_p)->name, vg_name) == 0; if (!found) { udisks_linux_volume_group_object_destroy (group); g_dbus_object_manager_server_unexport (manager, g_dbus_object_get_object_path (G_DBUS_OBJECT (group))); g_hash_table_iter_remove (&vg_name_iter); } } /* Add new groups and update existing groups */ for (BDLVMVGdata **vgs_p=vgs; *vgs_p; vgs_p++) { UDisksLinuxVolumeGroupObject *group; GSList *vg_pvs = NULL; vg_name = (*vgs_p)->name; group = g_hash_table_lookup (udisks_lvm2_state_get_name_to_volume_group (state), vg_name); if (group == NULL) { group = udisks_linux_volume_group_object_new (daemon, vg_name); g_hash_table_insert (udisks_lvm2_state_get_name_to_volume_group (state), g_strdup (vg_name), group); } for (BDLVMPVdata **pvs_p=pvs; *pvs_p; pvs_p++) if (g_strcmp0 ((*pvs_p)->vg_name, vg_name) == 0) vg_pvs = g_slist_prepend (vg_pvs, *pvs_p); udisks_linux_volume_group_object_update (group, *vgs_p, vg_pvs); } /* this is safe to do -- all BDLVMPVdata objects are still existing because the function that frees them is scheduled in main loop by the udisks_linux_volume_group_object_update() call above */ for (BDLVMPVdata **pvs_p=pvs; *pvs_p; pvs_p++) if ((*pvs_p)->vg_name == NULL) bd_lvm_pvdata_free (*pvs_p); /* only free the containers, the contents were passed further */ g_free (vgs); g_free (pvs); }
/** * ccss_cairo_style_draw_rectangle_with_gap: * @self: a ccss_style_t. * @cr: the target to draw onto. * @x: the starting x coordinate. * @y: the starting y coordinate. * @width: width of the outline to draw. * @height: height of the outline to draw. * @gap_side: side in which to leave the gap. * @gap_start: starting position of the gap. * @gap_width: width of the gap. * * Draw a rectangle with gap using this style instance. **/ void ccss_cairo_style_draw_rectangle_with_gap (ccss_style_t const *self, cairo_t *cr, double x, double y, double width, double height, ccss_cairo_gap_side_t gap_side, double gap_start, double gap_width) { ccss_border_stroke_t bottom, left, right, top; ccss_border_join_t const *bl; ccss_border_join_t const *br; ccss_border_join_t const *tl; ccss_border_join_t const *tr; ccss_background_attachment_t const *bg_attachment; ccss_color_t const *bg_color; ccss_background_image_t const *bg_image; ccss_background_position_t const *bg_position; ccss_background_repeat_t const *bg_repeat; ccss_background_size_t const *bg_size; ccss_border_join_t bottom_left = { .base.state = CCSS_PROPERTY_STATE_SET, .radius = 0 }; ccss_border_join_t bottom_right = { .base.state = CCSS_PROPERTY_STATE_SET, .radius = 0 }; ccss_border_join_t top_left = { .base.state = CCSS_PROPERTY_STATE_SET, .radius = 0 }; ccss_border_join_t top_right = { .base.state = CCSS_PROPERTY_STATE_SET, .radius = 0 }; double l, t, w, h; ccss_cairo_appearance_t *appearance = NULL; if (ccss_style_get_property (self, "ccss-appearance", (ccss_property_t const **) &appearance) && appearance->base.state == CCSS_PROPERTY_STATE_SET && appearance->draw_function) { static GQuark gap_side_id = 0; static GQuark gap_start_id = 0; static GQuark gap_width_id = 0; gap_side_t gap_side_property; gap_start_t gap_start_property; gap_width_t gap_width_property; bool ret; if (gap_side_id == 0) gap_side_id = g_quark_from_static_string ("ccss-gap-side"); ccss_property_init (&gap_side_property.base, peek_property_class ("ccss-gap-side")); gap_side_property.side = gap_side; gap_side_property.base.state = CCSS_PROPERTY_STATE_SET; g_hash_table_insert (self->properties, (gpointer) gap_side_id, &gap_side_property); if (gap_start_id == 0) gap_start_id = g_quark_from_static_string ("ccss-gap-start"); ccss_property_init (&gap_start_property.base, peek_property_class ("ccss-gap-start")); gap_start_property.start = gap_start; gap_start_property.base.state = CCSS_PROPERTY_STATE_SET; g_hash_table_insert (self->properties, (gpointer) gap_start_id, &gap_start_property); if (gap_width_id == 0) gap_width_id = g_quark_from_static_string ("ccss-gap-width"); ccss_property_init (&gap_width_property.base, peek_property_class ("ccss-gap-width")); gap_width_property.width = gap_width; gap_width_property.base.state = CCSS_PROPERTY_STATE_SET; g_hash_table_insert (self->properties, (gpointer) gap_width_id, &gap_width_property); ret = appearance->draw_function (self, cr, x, y, width, height); g_hash_table_remove (self->properties, (gpointer) gap_side_id); g_hash_table_remove (self->properties, (gpointer) gap_start_id); g_hash_table_remove (self->properties, (gpointer) gap_width_id); if (ret) return; } gather_outline (self, &bottom, &left, &right, &top, &bl, &br, &tl, &tr); gather_background (self, &bg_attachment, &bg_color, &bg_image, &bg_position, &bg_repeat, &bg_size); /* The rounding radii will have to be adjusted for certain gap * positions, so we work on a copied set of them. */ if (bl) bottom_left = *bl; if (br) bottom_right = *br; if (tl) top_left = *tl; if (tr) top_right = *tr; switch (gap_side) { case CCSS_CAIRO_GAP_SIDE_LEFT: if (bottom_left.radius > height - gap_start - gap_width) bottom_left.radius = height - gap_start - gap_width; if (top_left.radius > gap_start) top_left.radius = gap_start; break; case CCSS_CAIRO_GAP_SIDE_TOP: if (top_left.radius > gap_start) top_left.radius = gap_start; if (top_right.radius > width - gap_start - gap_width) top_right.radius = width - gap_start - gap_width; break; case CCSS_CAIRO_GAP_SIDE_RIGHT: if (top_right.radius > gap_start) top_right.radius = gap_start; if (bottom_right.radius > height - gap_start - gap_width) bottom_right.radius = height - gap_start - gap_width; break; case CCSS_CAIRO_GAP_SIDE_BOTTOM: if (bottom_left.radius > gap_start) bottom_left.radius = gap_start; if (bottom_right.radius > width - gap_start - gap_width) bottom_right.radius = width - gap_start - gap_width; break; default: g_assert_not_reached (); return; /* prevent error building without assertions */ } if (top_left.radius < 0) top_left.radius = 0; if (top_right.radius < 0) top_right.radius = 0; if (bottom_right.radius < 0) bottom_right.radius = 0; if (bottom_left.radius < 0) bottom_left.radius = 0; ccss_cairo_border_clamp_radii (x, y, width, height, &top_left.radius, &top_right.radius, &bottom_right.radius, &bottom_left.radius); ccss_cairo_border_path (&left, &top_left, &top, &top_right, &right, &bottom_right, &bottom, &bottom_left, cr, x, y, width, height); /* FIXME: background size is calculated against allocation * when using `fixed'. */ if (bg_attachment && CCSS_BACKGROUND_FIXED == bg_attachment->attachment) { l = self->viewport_x; t = self->viewport_y; w = self->viewport_width; h = self->viewport_height; } else { l = x; t = y; w = width; h = height; } ccss_cairo_background_fill (bg_attachment, bg_color, bg_image, bg_position, bg_repeat, bg_size, cr, l, t, w, h); cairo_new_path (cr); /* Drawing functions start at bottom-left corder and * proceed clock-wise. */ switch (gap_side) { case CCSS_CAIRO_GAP_SIDE_LEFT: /* Draw gap only if it's not over the whole border. */ if (gap_start > y || gap_width < height) { /* Rounding reaches until start of gap? * With Gtk+ the portion following the gap might not be visible. */ if (bottom_left.radius < height - gap_start - gap_width && gap_start + gap_width < height) { ccss_cairo_border_draw ( &left, NULL, NULL, NULL, NULL, NULL, NULL, &bottom_left, CCSS_BORDER_VISIBILITY_HIDE_BOTTOM_LEFT | CCSS_BORDER_ROUNDING_UNRESTRICTED, cr, x, y + gap_start + gap_width - 1, 0, height - gap_start - gap_width + 1); } /* Rounding reaches until start of gap? */ if (top_left.radius < gap_start) { ccss_cairo_border_draw ( &left, &top_left, NULL, NULL, NULL, NULL, NULL, NULL, CCSS_BORDER_VISIBILITY_HIDE_LEFT_TOP | CCSS_BORDER_ROUNDING_UNRESTRICTED, cr, x, y, 0, gap_start + 1); } } ccss_cairo_border_draw (&left, &top_left, &top, &top_right, &right, &bottom_right, &bottom, &bottom_left, CCSS_BORDER_VISIBILITY_HIDE_LEFT, cr, x, y, width, height); break; case CCSS_CAIRO_GAP_SIDE_TOP: /* Draw gap only if it's not over the whole border. */ if (gap_start > x || gap_width < width) { /* Rounding reaches until start of gap? */ if (top_left.radius < gap_start) { ccss_cairo_border_draw ( NULL, &top_left, &top, NULL, NULL, NULL, NULL, NULL, CCSS_BORDER_VISIBILITY_HIDE_LEFT_TOP | CCSS_BORDER_ROUNDING_UNRESTRICTED, cr, x, y, gap_start + 1, 0); } /* Rounding reaches until start of gap? * With Gtk+ the portion following the gap might not be visible. */ if (top_right.radius < width - gap_start - gap_width && gap_start + gap_width < width) { ccss_cairo_border_draw ( NULL, NULL, &top, &top_right, NULL, NULL, NULL, NULL, CCSS_BORDER_VISIBILITY_HIDE_TOP_RIGHT | CCSS_BORDER_ROUNDING_UNRESTRICTED, cr, x + gap_start + gap_width - 1, y, width - gap_start - gap_width + 1, 0); } } ccss_cairo_border_draw (&left, &top_left, &top, &top_right, &right, &bottom_right, &bottom, &bottom_left, CCSS_BORDER_VISIBILITY_HIDE_TOP, cr, x, y, width, height); break; case CCSS_CAIRO_GAP_SIDE_RIGHT: /* Draw gap only if it's not over the whole border. */ if (gap_start > y || gap_width < height) { /* Rounding reaches until start of gap? */ if (top_right.radius < gap_start) { ccss_cairo_border_draw ( NULL, NULL, NULL, &top_right, &right, NULL, NULL, NULL, CCSS_BORDER_VISIBILITY_HIDE_TOP_RIGHT | CCSS_BORDER_ROUNDING_UNRESTRICTED, cr, x + width, y, 0, gap_start + 1); } /* Rounding reaches until start of gap? * With Gtk+ the portion following the gap might not be visible. */ if (bottom_right.radius < height - gap_start - gap_width && gap_start + gap_width < height) { ccss_cairo_border_draw ( NULL, NULL, NULL, NULL, &right, &bottom_right, NULL, NULL, CCSS_BORDER_VISIBILITY_HIDE_RIGHT_BOTTOM | CCSS_BORDER_ROUNDING_UNRESTRICTED, cr, x + width, y + gap_start + gap_width - 1, 0, height - gap_start - gap_width + 1); } } ccss_cairo_border_draw (&left, &top_left, &top, &top_right, &right, &bottom_right, &bottom, &bottom_left, CCSS_BORDER_VISIBILITY_HIDE_RIGHT, cr, x, y, width, height); break; case CCSS_CAIRO_GAP_SIDE_BOTTOM: /* Draw gap only if it's not over the whole border. */ if (gap_start > x || gap_width < width) { /* Rounding reaches until start of gap? && * With Gtk+ the portion following the gap might not be visible. */ if (bottom_right.radius < width - gap_start - gap_width && gap_start + gap_width < width) { ccss_cairo_border_draw ( NULL, NULL, NULL, NULL, NULL, &bottom_right, &bottom, NULL, CCSS_BORDER_VISIBILITY_HIDE_RIGHT_BOTTOM | CCSS_BORDER_ROUNDING_UNRESTRICTED, cr, x + gap_start + gap_width - 1, y + height, width - gap_start - gap_width + 1, 0); } /* Rounding reaches until start of gap? */ if (bottom_left.radius < gap_start) { ccss_cairo_border_draw ( NULL, NULL, NULL, NULL, NULL, NULL, &bottom, &bottom_left, CCSS_BORDER_VISIBILITY_HIDE_BOTTOM_LEFT | CCSS_BORDER_ROUNDING_UNRESTRICTED, cr, x, y + height, gap_start + 1, 0); } } ccss_cairo_border_draw (&left, &top_left, &top, &top_right, &right, &bottom_right, &bottom, &bottom_left, CCSS_BORDER_VISIBILITY_HIDE_BOTTOM, cr, x, y, width, height); break; default: g_assert_not_reached (); return; /* prevent error building without assertions */ } } /** * ccss_cairo_style_get_double: * @self: a #ccss_style_t. * @property_name: name of the property. * @value: location to store the converted property. * * Query a numeric property with fallbacks, e.g. `border-color' if `border-left-color' is not given. * * Returns: %TRUE if the property was found and could be converted. **/ bool ccss_cairo_style_get_double (ccss_style_t const *self, char const *property_name, double *value) { ccss_property_t const *property; g_return_val_if_fail (self && property_name && value, false); property = lookup_property_r (self, property_name); if (NULL == property) return false; /* Have conversion function? */ g_return_val_if_fail (property->vtable, false); if (NULL == property->vtable->convert) { return false; } return property->vtable->convert (property, CCSS_PROPERTY_TYPE_DOUBLE, value); } /** * ccss_cairo_style_get_string: * @self: a #ccss_style_t. * @property_name: name of the property. * @value: location to store the converted property. * * Query a string property with fallbacks, e.g. `border-color' if `border-left-color' is not given. * * Returns: %TRUE if the property was found and could be converted. **/ bool ccss_cairo_style_get_string (ccss_style_t const *self, char const *property_name, char **value) { ccss_property_t const *property; g_return_val_if_fail (self && property_name && value, false); property = lookup_property_r (self, property_name); if (NULL == property) return false; /* Have conversion function? */ g_return_val_if_fail (property->vtable, false); if (NULL == property->vtable->convert) { return false; } return property->vtable->convert (property, CCSS_PROPERTY_TYPE_STRING, value); } /** * ccss_cairo_style_get_property: * @self: a #ccss_style_t. * @property_name: name of the property. * @property: location to store the property. * * Query a custom property with fallbacks, e.g. `border-color' if `border-left-color' is not given. * * Returns: %TRUE if the property was found. **/ bool ccss_cairo_style_get_property (ccss_style_t const *self, char const *property_name, ccss_property_t const **property) { g_return_val_if_fail (self && property_name && property, false); *property = lookup_property_r (self, property_name); return (bool) *property; } static void gap_destroy_nop (ccss_property_t *property) { /* Gap properties are stack-allocated. */ } static bool gap_side_convert (gap_side_t const *property, ccss_property_type_t target, void *value) { g_return_val_if_fail (property && value, false); if (CCSS_PROPERTY_TYPE_DOUBLE == target) return false; switch (property->side) { case CCSS_CAIRO_GAP_SIDE_LEFT: * (char const **) value = g_strdup ("left"); break; case CCSS_CAIRO_GAP_SIDE_RIGHT: * (char const **) value = g_strdup ("right"); break; case CCSS_CAIRO_GAP_SIDE_TOP: * (char const **) value = g_strdup ("top"); break; case CCSS_CAIRO_GAP_SIDE_BOTTOM: * (char const **) value = g_strdup ("bottom"); break; } return true; }
/* Populate list of available themes */ static void _xfdashboard_settings_populate_themes_list(XfdashboardSettings *self, GtkWidget *inWidget) { GHashTable *themes; GArray *themesPaths; GDir *directory; GtkListStore *model; GtkTreeIter iter; guint i; g_return_if_fail(XFDASHBOARD_IS_SETTINGS(self)); g_return_if_fail(GTK_IS_TREE_VIEW(inWidget)); /* Create hash-table to keep track of duplicates (e.g. user overrides standard themes) */ themes=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); /* Get model of widget to fill */ model=gtk_list_store_new(COLUMN_THEME_LAST, G_TYPE_STRING, /* COLUMN_THEME_NAME */ G_TYPE_STRING, /* COLUMN_THEME_FILE */ G_TYPE_STRING, /* COLUMN_THEME_DISPLAY_NAME */ G_TYPE_STRING, /* COLUMN_THEME_AUTHORS */ G_TYPE_STRING, /* COLUMN_THEME_VERSION */ G_TYPE_STRING, /* COLUMN_THEME_DESCRIPTION */ G_TYPE_STRING /* COLUMN_THEME_SCREENSHOTS */ ); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), COLUMN_THEME_DISPLAY_NAME, (GtkTreeIterCompareFunc)_xfdashboard_settings_sort_themes_list_model, NULL, NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), COLUMN_THEME_DISPLAY_NAME, GTK_SORT_ASCENDING); /* Get paths to iterate through to find themes */ themesPaths=g_array_new(TRUE, TRUE, sizeof(gchar*)); if(themesPaths) { gchar *themePath; const gchar *homeDirectory; /* First add user's data dir */ themePath=g_build_filename(g_get_user_data_dir(), "themes", NULL); g_array_append_val(themesPaths, themePath); g_debug("Adding to theme search path: %s", themePath); /* Then add user's home directory */ homeDirectory=g_get_home_dir(); if(homeDirectory) { themePath=g_build_filename(homeDirectory, ".themes", NULL); g_array_append_val(themesPaths, themePath); g_debug("Adding to theme search path: %s", themePath); } /* At last add system-wide path */ themePath=g_build_filename(PACKAGE_DATADIR, "themes", NULL); g_array_append_val(themesPaths, themePath); g_debug("Adding to theme search path: %s", themePath); } /* Iterate through all themes at all theme paths */ for(i=0; i<themesPaths->len; ++i) { const gchar *themePath; const gchar *themeName; /* Get theme path to iterate through */ themePath=g_array_index(themesPaths, const gchar*, i); /* Open handle to directory to iterate through * but skip NULL paths or directory objects */ directory=g_dir_open(themePath, 0, NULL); if(G_UNLIKELY(directory==NULL)) continue; /* Iterate through directory and find available themes */ while((themeName=g_dir_read_name(directory))) { gchar *themeIndexFile; GKeyFile *themeKeyFile; GError *error; gchar *themeDisplayName; gchar *themeComment; gchar **themeAuthors; gchar *realThemeAuthor; gchar *themeVersion; gchar **themeScreenshots; gchar *realThemeScreenshot; error=NULL; themeDisplayName=NULL; themeComment=NULL; themeAuthors=NULL; themeVersion=NULL; themeScreenshots=NULL; realThemeAuthor=NULL; realThemeScreenshot=NULL; /* Check if theme description file exists and add it if there is no theme * with same name. */ themeIndexFile=g_build_filename(themePath, themeName, XFDASHBOARD_THEME_SUBPATH, XFDASHBOARD_THEME_FILE, NULL); if(!g_file_test(themeIndexFile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { g_debug("Invalid theme '%s': Missing theme index file at %s", themeName, themeIndexFile); /* Release allocated resources */ if(themeIndexFile) g_free(themeIndexFile); /* Continue with next entry */ continue; } if(g_hash_table_lookup(themes, themeName)) { g_debug("Invalid theme '%s': Duplicate theme at %s", themeName, themeIndexFile); /* Release allocated resources */ if(themeIndexFile) g_free(themeIndexFile); /* Continue with next entry */ continue; } /* Get theme file to retrieve data of it */ themeKeyFile=g_key_file_new(); if(!g_key_file_load_from_file(themeKeyFile, themeIndexFile, G_KEY_FILE_NONE, &error)) { g_warning("Invalid theme '%s' at %s: %s", themeName, themeIndexFile, error ? error->message : _("Unknown error")); /* Release allocated resources */ if(error) g_error_free(error); if(themeKeyFile) g_key_file_free(themeKeyFile); if(themeIndexFile) g_free(themeIndexFile); /* Continue with next entry */ continue; } /* Check if theme is valid by checking if all essential * keys are defined: Name, Comment, Style and Layout */ if(!g_key_file_has_key(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Name", &error)) { g_warning("Invalid theme '%s' at %s: %s", themeName, themeIndexFile, error ? error->message : _("Unknown error")); /* Release allocated resources */ if(error) g_error_free(error); if(themeKeyFile) g_key_file_free(themeKeyFile); if(themeIndexFile) g_free(themeIndexFile); /* Continue with next entry */ continue; } if(!g_key_file_has_key(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Comment", &error)) { g_warning("Invalid theme '%s' at %s: %s", themeName, themeIndexFile, error ? error->message : _("Unknown error")); /* Release allocated resources */ if(error) g_error_free(error); if(themeKeyFile) g_key_file_free(themeKeyFile); if(themeIndexFile) g_free(themeIndexFile); /* Continue with next entry */ continue; } if(!g_key_file_has_key(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Style", &error)) { g_warning("Invalid theme '%s' at %s: %s", themeName, themeIndexFile, error ? error->message : _("Unknown error")); /* Release allocated resources */ if(error) g_error_free(error); if(themeKeyFile) g_key_file_free(themeKeyFile); if(themeIndexFile) g_free(themeIndexFile); /* Continue with next entry */ continue; } if(!g_key_file_has_key(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Layout", &error)) { g_warning("Invalid theme '%s' at %s: %s", themeName, themeIndexFile, error ? error->message : _("Unknown error")); /* Release allocated resources */ if(error) g_error_free(error); if(themeKeyFile) g_key_file_free(themeKeyFile); if(themeIndexFile) g_free(themeIndexFile); /* Continue with next entry */ continue; } /* Theme is valid so get theme data which includes * optional field: Author, Version and Screenshot */ themeDisplayName=g_key_file_get_locale_string(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Name", NULL, NULL); themeComment=g_key_file_get_locale_string(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Comment", NULL, NULL); themeAuthors=g_key_file_get_string_list(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Author", NULL, NULL); if(themeAuthors) { /* Replace list of string with authors with one string * containing all authors seperated by new-line. */ realThemeAuthor=g_strjoinv("\n", themeAuthors); } themeVersion=g_key_file_get_string(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Version", NULL); themeScreenshots=g_key_file_get_string_list(themeKeyFile, XFDASHBOARD_THEME_GROUP, "Screenshot", NULL, NULL); if(themeScreenshots) { /* Replace list of string with filenames to screenshots * with one string containing the first screenshot's filename. */ realThemeScreenshot=g_strdup(themeScreenshots[0]); } /* Add to widget's list */ gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, COLUMN_THEME_NAME, themeName, COLUMN_THEME_FILE, themeIndexFile, COLUMN_THEME_DISPLAY_NAME, themeDisplayName, COLUMN_THEME_AUTHORS, realThemeAuthor, COLUMN_THEME_VERSION, themeVersion, COLUMN_THEME_DESCRIPTION, themeComment, COLUMN_THEME_SCREENSHOTS, realThemeScreenshot, -1); /* Remember theme to avoid duplicates (and allow overrides by user */ g_hash_table_insert(themes, g_strdup(themeName), GINT_TO_POINTER(1)); g_debug("Added theme '%s' from %s", themeName, themeIndexFile); /* Release allocated resources */ if(realThemeAuthor) g_free(realThemeAuthor); if(realThemeScreenshot) g_free(realThemeScreenshot); if(themeDisplayName) g_free(themeDisplayName); if(themeComment) g_free(themeComment); if(themeAuthors) g_strfreev(themeAuthors); if(themeVersion) g_free(themeVersion); if(themeScreenshots) g_strfreev(themeScreenshots); if(themeKeyFile) g_key_file_free(themeKeyFile); if(themeIndexFile) g_free(themeIndexFile); } /* Close handle to directory */ g_dir_close(directory); } /* Set new list store at widget */ gtk_tree_view_set_model(GTK_TREE_VIEW(inWidget), GTK_TREE_MODEL(model)); g_object_unref(model); /* Release allocated resources */ if(themesPaths) { for(i=0; i<themesPaths->len; ++i) { gchar *themePath; themePath=g_array_index(themesPaths, gchar*, i); g_free(themePath); } g_array_free(themesPaths, TRUE); } if(themes) g_hash_table_destroy(themes); }
/** * Update contact to LDAP * * \param server AddressBook resource * \param contact GHashTable with object to update */ void ldapsvr_update_contact(LdapServer *server, GHashTable *contact) { LDAP *ld = NULL; LDAPMod *mods[MODSIZE]; LDAPMod modarr[4]; gint cnt = 0; gchar *param, *dn; Rdn *NoRemove = NULL; char *cn[] = {NULL, NULL}; char *givenName[] = {NULL, NULL}; char **mail = NULL; char *sn[] = {NULL, NULL}; GList *mailList; int mod_op; cm_return_if_fail(server != NULL || contact != NULL); ld = ldapsvr_connect(server->control); if (ld == NULL) { clean_up(ld, server, contact); return; } dn = g_hash_table_lookup(contact, "dn"); if (dn == NULL) { clean_up(ld, server, contact); return; } NoRemove = ldapsvr_modify_dn(contact, dn); if (NoRemove) { /* We are trying to change RDN */ gchar *newRdn = g_strdup_printf("%s=%s", NoRemove->attribute, NoRemove->value); #ifdef OPEN_LDAP_API_AT_LEAST_3000 int rc = ldap_rename_s(ld, dn, newRdn, NULL, 1, NULL, NULL); #else /* This is deprecated as of OpenLDAP-2.3.0 */ int rc = ldap_modrdn2_s(ld, dn, newRdn, 1); #endif if(rc != LDAP_SUCCESS) { if (rc == LDAP_ALREADY_EXISTS) { /* We are messing with a contact with more than one listed email * address and the email we are changing is not the one used for dn */ /* It needs to be able to handle renaming errors to an already defined * dn. For now we just refuse the update. It will be caught later on as * a LDAPRC_NAMING_VIOLATION error. */ } else { g_printerr("Current dn: %s\n", dn); g_printerr("new dn: %s\n", newRdn); g_printerr("LDAP Error(ldap_modrdn2_s) failed[0x%x]: %s\n", rc, ldaputil_get_error(ld)); g_free(newRdn); clean_up(ld, server, contact); return; } } else { ItemPerson *person = g_hash_table_lookup(contact, "person"); g_free(newRdn); dn = g_strdup(NoRemove->new_dn); g_hash_table_replace(contact, "dn", dn); if (person) { g_free(person->externalID); person->externalID = dn; } } } else { server->retVal = LDAPRC_NODN; clean_up(ld, server, contact); return; } param = g_hash_table_lookup(contact , "cn"); mod_op = ldapsvr_deside_operation(ld, server, dn, "displayName", param); if (mod_op >= 0 && (strcmp(param, NoRemove->value) != 0 && strcmp("cn", NoRemove->attribute) != 0)) { if (mod_op == LDAP_MOD_DELETE) { /* Setting param to NULL instructs OpenLDAP to remove any * value stored for this attribute and remove the attribute * completely. Should multiple instances of an attribute be * allowed in the future param is required to have the value * store for the attribute which is going to be deleted */ param = NULL; } if (mod_op == LDAP_MOD_REPLACE && strcmp(param, "") == 0) { /* Having an empty string is considered a syntax error in * ldap. E.g attributes with empty strings are not allowed * in which case we treate this as a request for deleting * the attribute. */ mod_op = LDAP_MOD_DELETE; param = NULL; } if (mod_op == LDAP_MOD_ADD && strcmp(param, "") == 0) { /* Adding an empty string is considered a syntax error in * ldap. E.g attributes with empty strings are not allowed * in which case we silently refuse to add this entry */ } else { SETMOD(mods[cnt], modarr[cnt], mod_op, "displayName", cn, param); cnt++; g_hash_table_insert(contact, "displayName", param); } } param = g_hash_table_lookup(contact , "givenName"); mod_op = ldapsvr_deside_operation(ld, server, dn, "givenName", param); if (mod_op >= 0 && (strcmp(param, NoRemove->value) != 0 && strcmp("givenName", NoRemove->attribute) != 0)) { if (mod_op == LDAP_MOD_DELETE) { /* Setting param to NULL instructs OpenLDAP to remove any * value stored for this attribute and remove the attribute * completely. Should multiple instances of an attribute be * allowed in the future param is required to have the value * store for the attribute which is going to be deleted */ param = NULL; } if (mod_op == LDAP_MOD_REPLACE && strcmp(param, "") == 0) { /* Having an empty string is considered a syntax error in * ldap. E.g attributes with empty strings are not allowed * in which case we treate this as a request for deleting * the attribute. */ mod_op = LDAP_MOD_DELETE; param = NULL; } if (mod_op == LDAP_MOD_ADD && strcmp(param, "") == 0) { /* Adding an empty string is considered a syntax error in * ldap. E.g attributes with empty strings are not allowed * in which case we silently refuse to add this entry */ } else { SETMOD(mods[cnt], modarr[cnt], mod_op, "givenName", givenName, param); cnt++; } } mailList = g_hash_table_lookup(contact , "mail"); if (mailList) { debug_print("# of mail: %d\n", g_list_length(mailList)); if (!(strcmp("mail", NoRemove->attribute) == 0 && g_list_length(mailList) == 1)) { char **tmp; tmp = g_malloc(sizeof(*tmp) * (g_list_length(mailList)+1)); mail = tmp; while (mailList) { EmailKeyValue *item = mailList->data; *tmp++ = g_strdup((gchar *) item->mail); mailList = g_list_next(mailList); } *tmp = NULL; /* * At least one email address is required * in which case it will always be a replace */ SETMODS(mods[cnt], modarr[cnt], LDAP_MOD_REPLACE, "mail", mail); cnt++; } } else { /* * an error condition since at least one email adress * is required. Should never occur though. */ } param = g_hash_table_lookup(contact , "sn"); mod_op = ldapsvr_deside_operation(ld, server, dn, "sn", param); if (mod_op >= 0 && (strcmp(param, NoRemove->value) != 0 && strcmp("sn", NoRemove->attribute) != 0)) { if (mod_op == LDAP_MOD_DELETE) { /* Setting param to NULL instructs OpenLDAP to remove any * value stored for this attribute and remove the attribute * completely. Should multiple instances of an attribute be * allowed in the future param is required to have the value * store for the attribute which is going to be deleted */ param = NULL; } if (mod_op == LDAP_MOD_REPLACE && strcmp(param, "") == 0) { /* Having an empty string is considered a syntax error in * ldap. E.g attributes with empty strings are not allowed * in which case we treate this as a request for deleting * the attribute. */ mod_op = LDAP_MOD_DELETE; param = NULL; } if (mod_op == LDAP_MOD_ADD && strcmp(param, "") == 0) { /* Adding an empty string is considered a syntax error in * ldap. E.g attributes with empty strings are not allowed * in which case we silently refuse to add this entry */ } else { SETMOD(mods[cnt], modarr[cnt], mod_op, "sn", sn, param); cnt++; } } debug_print("newDN: %s\n", dn); if (NoRemove) rdn_free(NoRemove); server->retVal = LDAPRC_SUCCESS; if (cnt > 0) { int rc; mods[cnt] = NULL; rc = ldap_modify_ext_s(ld, dn, mods, NULL, NULL); if (rc) { g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n", dn, rc, ldaputil_get_error(ld)); server->retVal = LDAPRC_NAMING_VIOLATION; } if (mail) g_free(mail); } ldapsvr_handle_other_attributes(ld, server, dn, contact); /* If we do not make changes persistent at this point then changes * will be lost if the user makes new search on the same server since * changes are only present in Claws' internal cache. This issue has to * be solved in addressbook.c since this involves access to structures * which are only accessible in addressbook.c */ clean_up(ld, server, contact); }
/** * Retrieve person object for update. * \param person ItemPerson to update. * \param array GHashTable with user input. * \return false if update is not needed, or true if update is needed. */ gboolean ldapsvr_retrieve_item_person(ItemPerson *person, GHashTable *array) { GList *node, *attr; cm_return_val_if_fail(person != NULL, FALSE); switch (person->status) { case NONE: return FALSE; case ADD_ENTRY: g_hash_table_insert(array, "status", "new"); break; case UPDATE_ENTRY: g_hash_table_insert(array, "status", "update"); break; case DELETE_ENTRY: g_hash_table_insert(array, "status", "delete"); break; default: g_critical(_("ldapsvr_retrieve_item_person->Unknown status: %d"), person->status); } g_hash_table_insert(array, "uid", ADDRITEM_ID(person)); g_hash_table_insert(array, "cn", ADDRITEM_NAME(person)); g_hash_table_insert(array, "givenName", person->firstName); g_hash_table_insert(array, "sn", person->lastName); g_hash_table_insert(array, "nickName", person->nickName); g_hash_table_insert(array, "dn", person->externalID); g_hash_table_insert(array, "person", person); node = person->listEMail; attr = NULL; while (node) { EmailKeyValue *newEmail = ldapsvr_retrieve_item_email(node->data); if (newEmail) attr = g_list_append(attr, newEmail); node = g_list_next(node); } g_hash_table_insert(array, "mail", attr); node = person->listAttrib; attr = NULL; while (node) { AttrKeyValue *newAttr = ldapsvr_retrieve_attribute(node->data); if (newAttr) attr = g_list_append(attr, newAttr); node = g_list_next(node); } g_hash_table_insert(array, "attribute", attr); return TRUE; }
static void add_config_file (GoaDaemon *daemon, const gchar *path, GHashTable *group_name_to_key_file_data, GList **key_files_to_free) { GKeyFile *key_file; GError *error; key_file = g_key_file_new (); error = NULL; if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error)) { if (!(error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT)) { g_warning ("Error loading %s: %s (%s, %d)", path, error->message, g_quark_to_string (error->domain), error->code); } g_error_free (error); g_key_file_free (key_file); } else { gchar **groups; const char *guid; gsize num_groups; guint n; guid = g_dbus_connection_get_guid (daemon->connection); groups = g_key_file_get_groups (key_file, &num_groups); for (n = 0; n < num_groups; n++) { if (g_str_has_prefix (groups[n], "Account ")) { gboolean is_temporary; char *session_id; is_temporary = g_key_file_get_boolean (key_file, groups[n], "IsTemporary", NULL); if (is_temporary) { session_id = g_key_file_get_string (key_file, groups[n], "SessionId", NULL); /* discard temporary accounts from older sessions */ if (session_id != NULL && g_strcmp0 (session_id, guid) != 0) { g_debug ("ignoring account \"%s\" in file %s because it's stale", groups[n], path); g_free (groups[n]); g_free (session_id); continue; } g_free (session_id); } else { g_key_file_remove_key (key_file, groups[n], "SessionId", NULL); } g_hash_table_insert (group_name_to_key_file_data, groups[n], /* steals string */ key_file_data_new (key_file, path)); } else { g_warning ("Unexpected group \"%s\" in file %s", groups[n], path); g_free (groups[n]); } } g_free (groups); *key_files_to_free = g_list_prepend (*key_files_to_free, key_file); } }
void hashTable_finalize(int* numThreads, int* numRegions, LikwidResults** results) { int threadId = 0; uint32_t numberOfThreads = 0; uint32_t numberOfRegions = 0; GHashTable* regionLookup; regionLookup = g_hash_table_new(g_str_hash, g_str_equal); /* determine number of active threads */ for (int i=0; i<MAX_NUM_THREADS; i++) { if (threadList[i] != NULL) { numberOfThreads++; uint32_t threadNumberOfRegions = g_hash_table_size(threadList[i]->hashTable); /* Determine maximum number of regions */ if (numberOfRegions < threadNumberOfRegions) { numberOfRegions = threadNumberOfRegions; } } } /* allocate data structures */ (*results) = (LikwidResults*) malloc(numberOfRegions * sizeof(LikwidResults)); for ( uint32_t i=0; i < numberOfRegions; i++ ) { (*results)[i].time = (double*) malloc(numberOfThreads * sizeof(double)); (*results)[i].count = (uint32_t*) malloc(numberOfThreads * sizeof(uint32_t)); (*results)[i].counters = (double**) malloc(numberOfThreads * sizeof(double*)); for ( uint32_t j=0; j < numberOfThreads; j++ ) { (*results)[i].time[j] = 0.0; (*results)[i].count[j] = 0; (*results)[i].counters[j] = (double*) malloc(NUM_PMC * sizeof(double)); for ( uint32_t k=0; k < NUM_PMC; k++ ) { (*results)[i].counters[j][k] = 0.0; } } } uint32_t regionIds[numberOfRegions]; uint32_t currentRegion = 0; for (int core=0; core<MAX_NUM_THREADS; core++) { ThreadList* resPtr = threadList[core]; if (resPtr != NULL) { LikwidThreadResults* threadResult = NULL; GHashTableIter iter; gpointer key, value; g_hash_table_iter_init (&iter, resPtr->hashTable); /* iterate over all regions in thread */ while (g_hash_table_iter_next (&iter, &key, &value)) { threadResult = (LikwidThreadResults*) value; uint32_t* regionId = (uint32_t*) g_hash_table_lookup(regionLookup, key); /* is region not yet registered */ if ( regionId == NULL ) { (*results)[currentRegion].tag = bstrcpy (threadResult->label); regionIds[currentRegion] = currentRegion; regionId = regionIds + currentRegion; g_hash_table_insert(regionLookup, g_strdup(key), (regionIds+currentRegion)); currentRegion++; } (*results)[*regionId].count[threadId] = threadResult->count; (*results)[*regionId].time[threadId] = threadResult->time; for ( int j=0; j < NUM_PMC; j++ ) { (*results)[*regionId].counters[threadId][j] = threadResult->PMcounters[j]; } } threadId++; } } (*numThreads) = numberOfThreads; (*numRegions) = numberOfRegions; }
static void scan_net_interfaces_24(void) { FILE *proc_net; NetInfo ni; gchar buffer[256]; gchar *devid, *detailed; gdouble recv_bytes; gdouble recv_errors; gdouble recv_packets; gdouble trans_bytes; gdouble trans_errors; gdouble trans_packets; if (!g_file_test("/proc/net/dev", G_FILE_TEST_EXISTS)) { if (network_interfaces) { g_free(network_interfaces); network_interfaces = g_strdup("[Network Interfaces]\n" "None found=\n"); } return; } if (network_interfaces) { g_free(network_interfaces); } if (network_icons) { g_free(network_icons); } network_interfaces = g_strdup("[Network Interfaces]\n"); network_icons = g_strdup(""); proc_net = fopen("/proc/net/dev", "r"); if (!proc_net) return; while (fgets(buffer, 256, proc_net)) { if (strchr(buffer, ':')) { gint trash; gchar ifacename[16]; gchar *buf = buffer; gchar *iface_type, *iface_icon; gint i; buf = g_strstrip(buf); memset(ifacename, 0, 16); for (i = 0; buffer[i] != ':' && i < 16; i++) { ifacename[i] = buffer[i]; } buf = strchr(buf, ':') + 1; /* iface: bytes packets errs drop fifo frame compressed multicast */ sscanf(buf, "%lf %lf %lf %d %d %d %d %d %lf %lf %lf", &recv_bytes, &recv_packets, &recv_errors, &trash, &trash, &trash, &trash, &trash, &trans_bytes, &trans_packets, &trans_errors); gdouble recv_mb = recv_bytes / 1048576.0; gdouble trans_mb = trans_bytes / 1048576.0; get_net_info(ifacename, &ni); devid = g_strdup_printf("NET%s", ifacename); network_interfaces = h_strdup_cprintf ("$%s$%s=%s|%.2lfMiB|%.2lfMiB\n", network_interfaces, devid, ifacename, ni.ip[0] ? ni.ip : "", trans_mb, recv_mb); net_get_iface_type(ifacename, &iface_type, &iface_icon, &ni); network_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", network_icons, devid, ifacename, iface_icon); detailed = g_strdup_printf("[Network Adapter Properties]\n" "Interface Type=%s\n" "Hardware Address (MAC)=%02x:%02x:%02x:%02x:%02x:%02x\n" "MTU=%d\n" "[Transfer Details]\n" "Bytes Received=%.0lf (%.2fMiB)\n" "Bytes Sent=%.0lf (%.2fMiB)\n", iface_type, ni.mac[0], ni.mac[1], ni.mac[2], ni.mac[3], ni.mac[4], ni.mac[5], ni.mtu, recv_bytes, recv_mb, trans_bytes, trans_mb); #ifdef HAS_LINUX_WE if (ni.is_wireless) { gchar *txpower; if (ni.wi_has_txpower) { gint mw, dbm; if (ni.wi_txpower.flags & IW_TXPOW_MWATT) { mw = ni.wi_txpower.value; dbm = (int) ceil(10.0 * log10((double) ni.wi_txpower.value)); } else { dbm = ni.wi_txpower.value; mw = (int) floor(pow(10.0, ((double) dbm / 10.0))); } txpower = g_strdup_printf("%ddBm (%dmW)", dbm, mw); } else { txpower = g_strdup("Unknown"); } detailed = h_strdup_cprintf("\n[Wireless Properties]\n" "Network Name (SSID)=%s\n" "Bit Rate=%dMb/s\n" "Transmission Power=%s\n" "Mode=%s\n" "Status=%d\n" "Link Quality=%d\n" "Signal / Noise=%d / %d\n", detailed, ni.wi_essid, ni.wi_rate / 1000000, txpower, wi_operation_modes[ni.wi_mode], ni.wi_status, ni.wi_quality_level, ni.wi_signal_level, ni.wi_noise_level); g_free(txpower); } #endif if (ni.ip[0] || ni.mask[0] || ni.broadcast[0]) { detailed = h_strdup_cprintf("\n[Internet Protocol (IPv4)]\n" "IP Address=%s\n" "Mask=%s\n" "Broadcast Address=%s\n", detailed, ni.ip[0] ? ni.ip : "Not set", ni.mask[0] ? ni.mask : "Not set", ni.broadcast[0] ? ni. broadcast : "Not set"); } g_hash_table_insert(moreinfo, devid, detailed); } } fclose(proc_net); }
static DeskmenuObject *check_file_cache (Deskmenu *deskmenu, gchar *filename) { DeskmenuObject *dm_object; gchar *user_default = g_build_path (G_DIR_SEPARATOR_S, g_get_user_config_dir (), "compiz", "boxmenu", "menu.xml", NULL); //TODO: add a size column to cache for possible autorefresh g_print("Checking cache...\n"); if (strlen(filename) == 0) filename = g_build_path (G_DIR_SEPARATOR_S, g_get_user_config_dir (), "compiz", "boxmenu", "menu.xml", NULL); if (strcmp(filename, user_default) == 0) { g_print("Looking up default menu...\n"); /* set default filename to be [configdir]/compiz/boxmenu/menu.xml */ gboolean success = FALSE; if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { g_print("Getting default system menu...\n"); const gchar* const *cursor = g_get_system_config_dirs (); gchar *path = NULL; while (*cursor) { g_free (path); path = g_strdup (*cursor); filename = g_build_path (G_DIR_SEPARATOR_S, path, "compiz", "boxmenu", "menu.xml", NULL); if (g_file_test(filename, G_FILE_TEST_EXISTS)) { if (g_hash_table_lookup(deskmenu->file_cache, filename) == NULL) { g_hash_table_insert (deskmenu->file_cache, g_strdup(filename), deskmenu_parse_file(filename)); g_print("Prepared default system menu!\n"); } else { g_print("Retrieving default system menu!\n"); } g_free (path); success = TRUE; break; } cursor++; } } else { if (g_hash_table_lookup(deskmenu->file_cache, user_default) == NULL) { if (g_file_test(filename, G_FILE_TEST_EXISTS)) { g_print("Preparing default menu!\n"); g_hash_table_insert (deskmenu->file_cache, g_strdup(filename), deskmenu_parse_file(filename)); success = TRUE; } } else { g_print("Retrieving cached default user menu...\n"); success = TRUE; } } if (!success) { g_printerr ("Couldn't find a menu file...\n"); exit (1); } } else { if (g_hash_table_lookup(deskmenu->file_cache, filename) == NULL) { if (g_file_test(filename, G_FILE_TEST_EXISTS)) { g_print("Preparing new non-default menu...\n"); g_hash_table_insert (deskmenu->file_cache, g_strdup(filename), deskmenu_parse_file(filename)); } else { if (g_hash_table_lookup(deskmenu->file_cache, user_default) != NULL) { g_print("Couldn't find specified file, loading default...\n"); filename = user_default; } else { g_printerr ("Couldn't find a menu file...\n"); exit (1); } } } } dm_object = g_hash_table_lookup (deskmenu->file_cache, filename); g_printf("Done loading %s!\n", filename); return dm_object; }
static void set_up_element_hash (void) { element_hash = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_insert (element_hash, "menu", GINT_TO_POINTER (DESKMENU_ELEMENT_MENU)); g_hash_table_insert (element_hash, "separator", GINT_TO_POINTER (DESKMENU_ELEMENT_SEPARATOR)); g_hash_table_insert (element_hash, "item", GINT_TO_POINTER (DESKMENU_ELEMENT_ITEM)); g_hash_table_insert (element_hash, "name", GINT_TO_POINTER (DESKMENU_ELEMENT_NAME)); g_hash_table_insert (element_hash, "icon", GINT_TO_POINTER (DESKMENU_ELEMENT_ICON)); g_hash_table_insert (element_hash, "vpicon", GINT_TO_POINTER (DESKMENU_ELEMENT_VPICON)); g_hash_table_insert (element_hash, "command", GINT_TO_POINTER (DESKMENU_ELEMENT_COMMAND)); g_hash_table_insert (element_hash, "thisvp", GINT_TO_POINTER (DESKMENU_ELEMENT_THISVP)); g_hash_table_insert (element_hash, "minionly", GINT_TO_POINTER (DESKMENU_ELEMENT_MINIONLY)); g_hash_table_insert (element_hash, "wrap", GINT_TO_POINTER (DESKMENU_ELEMENT_WRAP)); g_hash_table_insert (element_hash, "sort", GINT_TO_POINTER (DESKMENU_ELEMENT_SORT)); g_hash_table_insert (element_hash, "quantity", GINT_TO_POINTER (DESKMENU_ELEMENT_QUANTITY)); g_hash_table_insert (element_hash, "age", GINT_TO_POINTER (DESKMENU_ELEMENT_AGE)); }
static GstFlowReturn gst_mxf_mux_create_metadata (GstMXFMux * mux) { GstFlowReturn ret = GST_FLOW_OK; GList *l; GArray *tmp; GST_DEBUG_OBJECT (mux, "Creating MXF metadata"); GST_OBJECT_LOCK (mux); for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) { GstMXFMuxPad *pad = l->data; GstCaps *caps; GstBuffer *buffer; if (!pad || !pad->descriptor) { GST_OBJECT_UNLOCK (mux); return GST_FLOW_ERROR; } caps = gst_pad_get_current_caps (GST_PAD_CAST (pad)); if (!caps) { GST_OBJECT_UNLOCK (mux); return GST_FLOW_ERROR; } buffer = gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad)); if (pad->writer->update_descriptor) pad->writer->update_descriptor (pad->descriptor, caps, pad->mapping_data, buffer); if (buffer) gst_buffer_unref (buffer); gst_caps_unref (caps); } /* Preface */ mux->preface = (MXFMetadataPreface *) g_object_new (MXF_TYPE_METADATA_PREFACE, NULL); mxf_uuid_init (&MXF_METADATA_BASE (mux->preface)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (mux->preface)->instance_uid, mux->preface); mux->metadata_list = g_list_prepend (mux->metadata_list, mux->preface); mxf_timestamp_set_now (&mux->preface->last_modified_date); mux->preface->version = 258; mux->preface->object_model_version = 1; mxf_op_set_generalized (&mux->preface->operational_pattern, MXF_OP_1a, TRUE, TRUE, FALSE); tmp = g_array_new (FALSE, FALSE, sizeof (MXFUL)); for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) { GstMXFMuxPad *pad = l->data; guint i; gboolean found = FALSE; if (!pad || !pad->descriptor || mxf_ul_is_zero (&pad->descriptor->essence_container)) { GST_OBJECT_UNLOCK (mux); return GST_FLOW_ERROR; } for (i = 0; i < tmp->len; i++) { if (mxf_ul_is_equal (&pad->descriptor->essence_container, &g_array_index (tmp, MXFUL, i))) { found = TRUE; break; } } if (found) continue; g_array_append_val (tmp, pad->descriptor->essence_container); } mux->preface->n_essence_containers = tmp->len; mux->preface->essence_containers = (MXFUL *) g_array_free (tmp, FALSE); /* This will later be used as UID for the material package */ mxf_uuid_init (&mux->preface->primary_package_uid, mux->metadata); /* Identifications */ { MXFMetadataIdentification *identification; static const guint8 gst_uid[] = { 0xe5, 0xde, 0xcd, 0x04, 0x24, 0x90, 0x69, 0x18, 0x8a, 0xc9, 0xb5, 0xd7, 0x02, 0x58, 0x46, 0x78 }; guint major, minor, micro, nano; mux->preface->n_identifications = 1; mux->preface->identifications = g_new0 (MXFMetadataIdentification *, 1); identification = mux->preface->identifications[0] = (MXFMetadataIdentification *) g_object_new (MXF_TYPE_METADATA_IDENTIFICATION, NULL); mxf_uuid_init (&MXF_METADATA_BASE (identification)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (identification)->instance_uid, identification); mux->metadata_list = g_list_prepend (mux->metadata_list, identification); mxf_uuid_init (&identification->this_generation_uid, NULL); identification->company_name = g_strdup ("GStreamer"); identification->product_name = g_strdup ("GStreamer Multimedia Framework"); gst_version (&major, &minor, µ, &nano); identification->product_version.major = major; identification->product_version.minor = minor; identification->product_version.patch = micro; identification->product_version.build = nano; identification->product_version.release = (nano == 0) ? 1 : (nano == 1) ? 2 : 4; identification->version_string = g_strdup_printf ("%u.%u.%u.%u", major, minor, micro, nano); memcpy (&identification->product_uid, &gst_uid, 16); memcpy (&identification->modification_date, &mux->preface->last_modified_date, sizeof (MXFTimestamp)); memcpy (&identification->toolkit_version, &identification->product_version, sizeof (MXFProductVersion)); #ifdef HAVE_SYS_UTSNAME_H { struct utsname sys_details; if (uname (&sys_details) == 0) { identification->platform = g_strdup_printf ("%s %s %s", sys_details.sysname, sys_details.release, sys_details.machine); } } #endif #if defined(G_OS_WIN32) if (identification->platform == NULL) identification->platform = g_strdup ("Microsoft Windows"); #elif defined(G_OS_BEOS) if (identification->platform == NULL) identification->platform = g_strdup ("BEOS"); #elif defined(G_OS_UNIX) if (identification->platform == NULL) identification->platform = g_strdup ("Unix"); #endif } /* Content storage */ { MXFMetadataContentStorage *cstorage; guint i; cstorage = mux->preface->content_storage = (MXFMetadataContentStorage *) g_object_new (MXF_TYPE_METADATA_CONTENT_STORAGE, NULL); mxf_uuid_init (&MXF_METADATA_BASE (cstorage)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (cstorage)->instance_uid, cstorage); mux->metadata_list = g_list_prepend (mux->metadata_list, cstorage); cstorage->n_packages = 2; cstorage->packages = g_new0 (MXFMetadataGenericPackage *, 2); /* Source package */ { MXFMetadataSourcePackage *p; cstorage->packages[1] = (MXFMetadataGenericPackage *) g_object_new (MXF_TYPE_METADATA_SOURCE_PACKAGE, NULL); mxf_uuid_init (&MXF_METADATA_BASE (cstorage->packages[1])->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (cstorage->packages[1])->instance_uid, cstorage->packages[1]); mux->metadata_list = g_list_prepend (mux->metadata_list, cstorage->packages[1]); p = (MXFMetadataSourcePackage *) cstorage->packages[1]; mxf_umid_init (&p->parent.package_uid); p->parent.name = g_strdup ("Source package"); memcpy (&p->parent.package_creation_date, &mux->preface->last_modified_date, sizeof (MXFTimestamp)); memcpy (&p->parent.package_modified_date, &mux->preface->last_modified_date, sizeof (MXFTimestamp)); p->parent.n_tracks = GST_ELEMENT_CAST (mux)->numsinkpads; p->parent.tracks = g_new0 (MXFMetadataTrack *, p->parent.n_tracks); if (p->parent.n_tracks > 1) { MXFMetadataMultipleDescriptor *d; p->descriptor = (MXFMetadataGenericDescriptor *) g_object_new (MXF_TYPE_METADATA_MULTIPLE_DESCRIPTOR, NULL); d = (MXFMetadataMultipleDescriptor *) p->descriptor; d->n_sub_descriptors = p->parent.n_tracks; d->sub_descriptors = g_new0 (MXFMetadataGenericDescriptor *, p->parent.n_tracks); mxf_uuid_init (&MXF_METADATA_BASE (d)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (d)->instance_uid, d); mux->metadata_list = g_list_prepend (mux->metadata_list, d); } /* Tracks */ { guint n = 0; /* Essence tracks */ for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) { GstMXFMuxPad *pad = l->data; MXFMetadataTimelineTrack *track; MXFMetadataSequence *sequence; MXFMetadataSourceClip *clip; GstCaps *caps; GstBuffer *buffer; p->parent.tracks[n] = (MXFMetadataTrack *) g_object_new (MXF_TYPE_METADATA_TIMELINE_TRACK, NULL); track = (MXFMetadataTimelineTrack *) p->parent.tracks[n]; mxf_uuid_init (&MXF_METADATA_BASE (track)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (track)->instance_uid, track); mux->metadata_list = g_list_prepend (mux->metadata_list, track); caps = gst_pad_get_current_caps (GST_PAD_CAST (pad)); buffer = gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad)); track->parent.track_id = n + 1; track->parent.track_number = pad->writer->get_track_number_template (pad->descriptor, caps, pad->mapping_data); pad->writer->get_edit_rate (pad->descriptor, caps, pad->mapping_data, buffer, p, track, &track->edit_rate); if (buffer) gst_buffer_unref (buffer); gst_caps_unref (caps); sequence = track->parent.sequence = (MXFMetadataSequence *) g_object_new (MXF_TYPE_METADATA_SEQUENCE, NULL); mxf_uuid_init (&MXF_METADATA_BASE (sequence)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (sequence)->instance_uid, sequence); mux->metadata_list = g_list_prepend (mux->metadata_list, sequence); memcpy (&sequence->data_definition, &pad->writer->data_definition, 16); sequence->n_structural_components = 1; sequence->structural_components = g_new0 (MXFMetadataStructuralComponent *, 1); clip = (MXFMetadataSourceClip *) g_object_new (MXF_TYPE_METADATA_SOURCE_CLIP, NULL); sequence->structural_components[0] = (MXFMetadataStructuralComponent *) clip; mxf_uuid_init (&MXF_METADATA_BASE (clip)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (clip)->instance_uid, clip); mux->metadata_list = g_list_prepend (mux->metadata_list, clip); memcpy (&clip->parent.data_definition, &sequence->data_definition, 16); clip->start_position = 0; pad->source_package = p; pad->source_track = track; pad->descriptor->linked_track_id = n + 1; if (p->parent.n_tracks == 1) { p->descriptor = (MXFMetadataGenericDescriptor *) pad->descriptor; } else { MXF_METADATA_MULTIPLE_DESCRIPTOR (p-> descriptor)->sub_descriptors[n] = (MXFMetadataGenericDescriptor *) pad->descriptor; } n++; } } } /* Material package */ { MXFMetadataMaterialPackage *p; MXFFraction min_edit_rate = { 0, 0 }; gdouble min_edit_rate_d = G_MAXDOUBLE; cstorage->packages[0] = (MXFMetadataGenericPackage *) g_object_new (MXF_TYPE_METADATA_MATERIAL_PACKAGE, NULL); memcpy (&MXF_METADATA_BASE (cstorage->packages[0])->instance_uid, &mux->preface->primary_package_uid, 16); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (cstorage->packages[0])->instance_uid, cstorage->packages[0]); mux->metadata_list = g_list_prepend (mux->metadata_list, cstorage->packages[0]); p = (MXFMetadataMaterialPackage *) cstorage->packages[0]; mxf_umid_init (&p->package_uid); p->name = g_strdup ("Material package"); memcpy (&p->package_creation_date, &mux->preface->last_modified_date, sizeof (MXFTimestamp)); memcpy (&p->package_modified_date, &mux->preface->last_modified_date, sizeof (MXFTimestamp)); p->n_tracks = GST_ELEMENT_CAST (mux)->numsinkpads + 1; p->tracks = g_new0 (MXFMetadataTrack *, p->n_tracks); /* Tracks */ { guint n; n = 1; /* Essence tracks */ for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) { GstMXFMuxPad *pad = l->data; GstCaps *caps; GstBuffer *buffer; MXFMetadataSourcePackage *source_package; MXFMetadataTimelineTrack *track, *source_track; MXFMetadataSequence *sequence; MXFMetadataSourceClip *clip; source_package = MXF_METADATA_SOURCE_PACKAGE (cstorage->packages[1]); source_track = MXF_METADATA_TIMELINE_TRACK (source_package->parent.tracks[n - 1]); p->tracks[n] = (MXFMetadataTrack *) g_object_new (MXF_TYPE_METADATA_TIMELINE_TRACK, NULL); track = (MXFMetadataTimelineTrack *) p->tracks[n]; mxf_uuid_init (&MXF_METADATA_BASE (track)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (track)->instance_uid, track); mux->metadata_list = g_list_prepend (mux->metadata_list, track); track->parent.track_id = n + 1; track->parent.track_number = 0; caps = gst_pad_get_current_caps (GST_PAD_CAST (pad)); buffer = gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad)); pad->writer->get_edit_rate (pad->descriptor, caps, pad->mapping_data, buffer, source_package, source_track, &track->edit_rate); if (buffer) gst_buffer_unref (buffer); gst_caps_unref (caps); if (track->edit_rate.n != source_track->edit_rate.n || track->edit_rate.d != source_track->edit_rate.d) { memcpy (&source_track->edit_rate, &track->edit_rate, sizeof (MXFFraction)); } if (track->edit_rate.d <= 0 || track->edit_rate.n <= 0) { GST_ERROR_OBJECT (mux, "Invalid edit rate"); GST_OBJECT_UNLOCK (mux); return GST_FLOW_ERROR; } if (min_edit_rate_d > ((gdouble) track->edit_rate.n) / ((gdouble) track->edit_rate.d)) { min_edit_rate_d = ((gdouble) track->edit_rate.n) / ((gdouble) track->edit_rate.d); memcpy (&min_edit_rate, &track->edit_rate, sizeof (MXFFraction)); } sequence = track->parent.sequence = (MXFMetadataSequence *) g_object_new (MXF_TYPE_METADATA_SEQUENCE, NULL); mxf_uuid_init (&MXF_METADATA_BASE (sequence)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (sequence)->instance_uid, sequence); mux->metadata_list = g_list_prepend (mux->metadata_list, sequence); memcpy (&sequence->data_definition, &pad->writer->data_definition, 16); sequence->n_structural_components = 1; sequence->structural_components = g_new0 (MXFMetadataStructuralComponent *, 1); clip = (MXFMetadataSourceClip *) g_object_new (MXF_TYPE_METADATA_SOURCE_CLIP, NULL); sequence->structural_components[0] = (MXFMetadataStructuralComponent *) clip; mxf_uuid_init (&MXF_METADATA_BASE (clip)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (clip)->instance_uid, clip); mux->metadata_list = g_list_prepend (mux->metadata_list, clip); memcpy (&clip->parent.data_definition, &sequence->data_definition, 16); clip->start_position = 0; memcpy (&clip->source_package_id, &cstorage->packages[1]->package_uid, 32); clip->source_track_id = n; n++; } n = 0; /* Timecode track */ { MXFMetadataTimelineTrack *track; MXFMetadataSequence *sequence; MXFMetadataTimecodeComponent *component; p->tracks[n] = (MXFMetadataTrack *) g_object_new (MXF_TYPE_METADATA_TIMELINE_TRACK, NULL); track = (MXFMetadataTimelineTrack *) p->tracks[n]; mxf_uuid_init (&MXF_METADATA_BASE (track)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (track)->instance_uid, track); mux->metadata_list = g_list_prepend (mux->metadata_list, track); track->parent.track_id = n + 1; track->parent.track_number = 0; track->parent.track_name = g_strdup ("Timecode track"); /* FIXME: Is this correct? */ memcpy (&track->edit_rate, &min_edit_rate, sizeof (MXFFraction)); sequence = track->parent.sequence = (MXFMetadataSequence *) g_object_new (MXF_TYPE_METADATA_SEQUENCE, NULL); mxf_uuid_init (&MXF_METADATA_BASE (sequence)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (sequence)->instance_uid, sequence); mux->metadata_list = g_list_prepend (mux->metadata_list, sequence); memcpy (&sequence->data_definition, mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_TIMECODE_12M_INACTIVE), 16); sequence->n_structural_components = 1; sequence->structural_components = g_new0 (MXFMetadataStructuralComponent *, 1); component = (MXFMetadataTimecodeComponent *) g_object_new (MXF_TYPE_METADATA_TIMECODE_COMPONENT, NULL); sequence->structural_components[0] = (MXFMetadataStructuralComponent *) component; mxf_uuid_init (&MXF_METADATA_BASE (component)->instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (component)->instance_uid, component); mux->metadata_list = g_list_prepend (mux->metadata_list, component); memcpy (&component->parent.data_definition, &sequence->data_definition, 16); component->start_timecode = 0; if (track->edit_rate.d == 0) component->rounded_timecode_base = 1; else component->rounded_timecode_base = (((gdouble) track->edit_rate.n) / ((gdouble) track->edit_rate.d) + 0.5); /* TODO: drop frame */ } memcpy (&mux->min_edit_rate, &min_edit_rate, sizeof (MXFFraction)); } } for (i = 0; i < cstorage->packages[1]->n_tracks; i++) { MXFMetadataTrack *track = cstorage->packages[1]->tracks[i]; guint j; guint32 templ; guint8 n_type, n; if ((track->track_number & 0x00ff00ff) != 0) continue; templ = track->track_number; n_type = 0; for (j = 0; j < cstorage->packages[1]->n_tracks; j++) { MXFMetadataTrack *tmp = cstorage->packages[1]->tracks[j]; if (tmp->track_number == templ) { n_type++; } } n = 0; for (j = 0; j < cstorage->packages[1]->n_tracks; j++) { MXFMetadataTrack *tmp = cstorage->packages[1]->tracks[j]; if (tmp->track_number == templ) { n++; tmp->track_number |= (n_type << 16) | (n); } } } cstorage->n_essence_container_data = 1; cstorage->essence_container_data = g_new0 (MXFMetadataEssenceContainerData *, 1); cstorage->essence_container_data[0] = (MXFMetadataEssenceContainerData *) g_object_new (MXF_TYPE_METADATA_ESSENCE_CONTAINER_DATA, NULL); mxf_uuid_init (&MXF_METADATA_BASE (cstorage->essence_container_data[0])-> instance_uid, mux->metadata); g_hash_table_insert (mux->metadata, &MXF_METADATA_BASE (cstorage->essence_container_data[0])->instance_uid, cstorage->essence_container_data[0]); mux->metadata_list = g_list_prepend (mux->metadata_list, cstorage->essence_container_data[0]); cstorage->essence_container_data[0]->linked_package = MXF_METADATA_SOURCE_PACKAGE (cstorage->packages[1]); cstorage->essence_container_data[0]->index_sid = 0; cstorage->essence_container_data[0]->body_sid = 1; }
/** * Add new contact to LDAP * * \param server AddressBook resource * \param contact GHashTable with object to add */ void ldapsvr_add_contact(LdapServer *server, GHashTable *contact) { gchar *email = NULL, *param = NULL; LDAP *ld = NULL; LDAPMod *mods[MODSIZE]; LDAPMod modarr[7]; gint cnt = 0; char *cn[] = {NULL, NULL}; char *displayName[] = {NULL, NULL}; char *givenName[] = {NULL, NULL}; char **mail = NULL; char *sn[] = {NULL, NULL}; char *org[] = {NULL, NULL}; char *obj[] = {/*"top",*/ "person", "organizationalPerson", "inetOrgPerson", NULL}; int rc=0; GList *node; AttrKeyValue *ou, *commonName; ItemPerson *person; gchar *base_dn; GList *mailList; cm_return_if_fail(server != NULL || contact != NULL); node = g_hash_table_lookup(contact , "mail"); if (node) { EmailKeyValue *newEmail = node->data; email = g_strdup(newEmail->mail); } if (email == NULL) { server->retVal = LDAPRC_NODN; clean_up(ld, server, contact); return; } base_dn = g_strdup_printf("mail=%s,%s", email, server->control->baseDN?server->control->baseDN:"null"); g_free(email); person = ldapsvr_get_contact(server, g_hash_table_lookup(contact , "uid")); person->externalID = g_strdup(base_dn); debug_print("dn: %s\n", base_dn); ld = ldapsvr_connect(server->control); if (ld == NULL) { clean_up(ld, server, contact); debug_print("no ldap found\n"); return; } SETMODS(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "objectClass", obj); cnt++; ou = get_ou(base_dn); if (ou != NULL) { SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, g_strdup(ou->key), org, g_strdup(ou->value)); cnt++; attrkeyvalue_free(ou); } commonName = get_cn(base_dn); if (commonName == NULL) { param = g_hash_table_lookup(contact , "cn"); if (param) { SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "cn", cn, param); } else { clean_up(ld, server, contact); debug_print("no CN found\n"); return; } } else { SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, g_strdup(commonName->key), cn, g_strdup(commonName->value)); cnt++; param = g_hash_table_lookup(contact , "cn"); SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "displayName", displayName, param); g_hash_table_insert(contact, "displayName", param); attrkeyvalue_free(commonName); } cnt++; param = g_hash_table_lookup(contact , "givenName"); if (param) { SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "givenName", givenName, param); cnt++; } mailList = g_hash_table_lookup(contact , "mail"); if (mailList) { char **tmp; tmp = g_malloc(sizeof(*tmp) * (g_list_length(mailList)+1)); mail = tmp; while (mailList) { EmailKeyValue *item = mailList->data; *tmp++ = g_strdup((gchar *) item->mail); mailList = g_list_next(mailList); } *tmp = NULL; SETMODS(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "mail", mail); cnt++; } param = g_hash_table_lookup(contact, "sn"); if (param == NULL) param = g_strdup(N_("Some SN")); SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "sn", sn, param); cnt++; mods[cnt] = NULL; if (debug_get_mode()) { ldapsvr_print_ldapmod(mods); } server->retVal = LDAPRC_SUCCESS; rc = ldap_add_ext_s(ld, base_dn, mods, NULL, NULL); if (rc) { switch (rc) { case LDAP_ALREADY_EXISTS: server->retVal = LDAPRC_ALREADY_EXIST; break; default: g_printerr("ldap_modify for dn=%s\" failed[0x%x]: %s\n", base_dn, rc, ldaputil_get_error(ld)); if (rc == 0x8) server->retVal = LDAPRC_STRONG_AUTH; else server->retVal = LDAPRC_NAMING_VIOLATION; } } ldapsvr_handle_other_attributes(ld, server, base_dn, contact); g_free(base_dn); clean_up(ld, server, contact); }
static void panel_place_menu_item_append_gtk_bookmarks (GtkWidget *menu, guint max_items_or_submenu) { typedef struct { char *full_uri; char *label; } PanelBookmark; GtkWidget *add_menu; char *filename; GIOChannel *io_channel; GHashTable *table; int i; GSList *lines = NULL; GSList *add_bookmarks, *l; PanelBookmark *bookmark; filename = g_build_filename (g_get_home_dir (), BOOKMARKS_FILENAME, NULL); io_channel = g_io_channel_new_file (filename, "r", NULL); g_free (filename); if (!io_channel) return; /* We use a hard limit to avoid having users shooting their * own feet, and to avoid crashing the system if a misbehaving * application creates a big bookmarks file. */ for (i = 0; i < MAX_BOOKMARK_ITEMS; i++) { char *contents; gsize length; gsize terminator_pos; GIOStatus status; status = g_io_channel_read_line (io_channel, &contents, &length, &terminator_pos, NULL); if (status != G_IO_STATUS_NORMAL) break; if (length == 0) break; /* Clear the line terminator (\n), if any */ if (terminator_pos > 0) contents[terminator_pos] = '\0'; lines = g_slist_prepend (lines, contents); } g_io_channel_shutdown (io_channel, FALSE, NULL); g_io_channel_unref (io_channel); if (!lines) return; lines = g_slist_reverse (lines); table = g_hash_table_new (g_str_hash, g_str_equal); add_bookmarks = NULL; for (l = lines; l; l = l->next) { char *line = (char*) l->data; if (line[0] && !g_hash_table_lookup (table, line)) { GFile *file; char *space; char *label; gboolean keep; g_hash_table_insert (table, line, line); space = strchr (line, ' '); if (space) { *space = '\0'; label = g_strdup (space + 1); } else { label = NULL; } keep = FALSE; if (g_str_has_prefix (line, "x-caja-search:")) keep = TRUE; if (!keep) { file = g_file_new_for_uri (line); keep = !g_file_is_native (file) || g_file_query_exists (file, NULL); g_object_unref (file); } if (!keep) { if (label) g_free (label); continue; } bookmark = g_malloc (sizeof (PanelBookmark)); bookmark->full_uri = g_strdup (line); bookmark->label = label; add_bookmarks = g_slist_prepend (add_bookmarks, bookmark); } } g_hash_table_destroy (table); g_slist_foreach (lines, (GFunc) g_free, NULL); g_slist_free (lines); add_bookmarks = g_slist_reverse (add_bookmarks); if (g_slist_length (add_bookmarks) <= max_items_or_submenu) { add_menu = menu; } else { GtkWidget *item; item = gtk_image_menu_item_new (); setup_menuitem_with_icon (item, panel_menu_icon_get_size (), NULL, PANEL_ICON_BOOKMARKS, _("Bookmarks")); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); add_menu = create_empty_menu (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), add_menu); } for (l = add_bookmarks; l; l = l->next) { char *display_name; char *tooltip; char *label; char *icon; GFile *file; GIcon *gicon; bookmark = l->data; file = g_file_new_for_uri (bookmark->full_uri); display_name = g_file_get_parse_name (file); g_object_unref (file); /* Translators: %s is a URI */ tooltip = g_strdup_printf (_("Open '%s'"), display_name); g_free (display_name); label = NULL; if (bookmark->label) { label = g_strdup (g_strstrip (bookmark->label)); if (!label [0]) { g_free (label); label = NULL; } } if (!label) { label = panel_util_get_label_for_uri (bookmark->full_uri); if (!label) { g_free (tooltip); g_free (bookmark->full_uri); if (bookmark->label) g_free (bookmark->label); g_free (bookmark); continue; } } icon = panel_util_get_icon_for_uri (bookmark->full_uri); /*FIXME: we should probably get a GIcon if possible, so that we * have customized icons for cd-rom, eg */ if (!icon) icon = g_strdup (PANEL_ICON_FOLDER); gicon = g_themed_icon_new_with_default_fallbacks (icon); //FIXME: drag and drop will be broken for x-caja-search uris panel_menu_items_append_place_item (icon, gicon, label, tooltip, add_menu, G_CALLBACK (activate_uri), bookmark->full_uri); g_free (icon); g_object_unref (gicon); g_free (tooltip); g_free (label); g_free (bookmark->full_uri); if (bookmark->label) g_free (bookmark->label); g_free (bookmark); } g_slist_free (add_bookmarks); }
static void xslt_yelp_document (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltStylePreCompPtr comp) { YelpTransform *transform; YelpTransformPrivate *priv; xmlChar *page_id = NULL; gchar *temp; xmlChar *page_buf; gint buf_size; xsltStylesheetPtr style = NULL; const char *old_outfile; xmlDocPtr new_doc = NULL; xmlDocPtr old_doc; xmlNodePtr old_insert; debug_print (DB_FUNCTION, "entering\n"); if (ctxt->state == XSLT_STATE_STOPPED) return; if (!ctxt || !node || !inst || !comp) return; transform = YELP_TRANSFORM (ctxt->_private); priv = GET_PRIV (transform); page_id = xsltEvalAttrValueTemplate (ctxt, inst, (const xmlChar *) "href", NULL); if (page_id == NULL || *page_id == '\0') { if (page_id) xmlFree (page_id); else xsltTransformError (ctxt, NULL, inst, _("No href attribute found on " "yelp:document\n")); /* FIXME: put a real error here */ goto done; } debug_print (DB_ARG, " page_id = \"%s\"\n", page_id); old_outfile = ctxt->outputFile; old_doc = ctxt->output; old_insert = ctxt->insert; ctxt->outputFile = (const char *) page_id; style = xsltNewStylesheet (); if (style == NULL) { xsltTransformError (ctxt, NULL, inst, _("Out of memory")); goto done; } style->omitXmlDeclaration = TRUE; new_doc = xmlNewDoc (BAD_CAST "1.0"); new_doc->charset = XML_CHAR_ENCODING_UTF8; new_doc->dict = ctxt->dict; xmlDictReference (new_doc->dict); ctxt->output = new_doc; ctxt->insert = (xmlNodePtr) new_doc; xsltApplyOneTemplate (ctxt, node, inst->children, NULL, NULL); xsltSaveResultToString (&page_buf, &buf_size, new_doc, style); ctxt->outputFile = old_outfile; ctxt->output = old_doc; ctxt->insert = old_insert; g_mutex_lock (&priv->mutex); temp = g_strdup ((gchar *) page_id); xmlFree (page_id); g_async_queue_push (priv->queue, g_strdup ((gchar *) temp)); g_hash_table_insert (priv->chunks, temp, page_buf); g_object_ref (transform); g_idle_add ((GSourceFunc) transform_chunk, transform); g_mutex_unlock (&priv->mutex); done: if (new_doc) xmlFreeDoc (new_doc); if (style) xsltFreeStylesheet (style); }
static gboolean category_filter_model_update (GtkTreeStore * store) { int i, n; int low = 0; int all = 0; int high = 0; int public = 0; int normal = 0; int private = 0; int store_pos; GtkTreeIter top; GtkTreeIter iter; GtkTreeModel * model = GTK_TREE_MODEL (store); GPtrArray * hosts = g_ptr_array_new (); GStringChunk * strings = g_string_chunk_new (4096); GHashTable * hosts_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); GObject * o = G_OBJECT (store); GtkTreeModel * tmodel = GTK_TREE_MODEL (g_object_get_qdata (o, TORRENT_MODEL_KEY)); g_object_steal_qdata (o, DIRTY_KEY); /* Walk through all the torrents, tallying how many matches there are * for the various categories. Also make a sorted list of all tracker * hosts s.t. we can merge it with the existing list */ if (gtk_tree_model_iter_nth_child (tmodel, &iter, NULL, 0)) do { tr_torrent * tor; const tr_info * inf; int keyCount; char ** keys; gtk_tree_model_get (tmodel, &iter, MC_TORRENT, &tor, -1); inf = tr_torrentInfo (tor); keyCount = 0; keys = g_new (char*, inf->trackerCount); for (i=0, n=inf->trackerCount; i<n; ++i) { int k; int * count; char buf[1024]; char * key; gtr_get_host_from_url (buf, sizeof (buf), inf->trackers[i].announce); key = g_string_chunk_insert_const (strings, buf); count = g_hash_table_lookup (hosts_hash, key); if (count == NULL) { count = tr_new0 (int, 1); g_hash_table_insert (hosts_hash, key, count); g_ptr_array_add (hosts, key); } for (k=0; k<keyCount; ++k) if (!strcmp (keys[k], key)) break; if (k==keyCount) keys[keyCount++] = key; } for (i=0; i<keyCount; ++i) { int * incrementme = g_hash_table_lookup (hosts_hash, keys[i]); ++*incrementme; } g_free (keys); ++all; if (inf->isPrivate) ++private; else ++public;
static gboolean add_locale (const char *language_name, gboolean utf8_only) { GdmLocale *locale; GdmLocale *old_locale; char *name; gboolean is_utf8 = FALSE; g_return_val_if_fail (language_name != NULL, FALSE); g_return_val_if_fail (*language_name != '\0', FALSE); language_name_get_codeset_details (language_name, NULL, &is_utf8); if (is_utf8) { name = g_strdup (language_name); } else if (utf8_only) { name = g_strdup_printf ("%s.utf8", language_name); language_name_get_codeset_details (name, NULL, &is_utf8); if (!is_utf8) { g_free (name); return FALSE; } } else { name = g_strdup (language_name); } if (!language_name_is_valid (name)) { g_debug ("Ignoring '%s' as a locale, since it's invalid", name); g_free (name); return FALSE; } locale = g_new0 (GdmLocale, 1); gdm_parse_language_name (name, &locale->language_code, &locale->territory_code, &locale->codeset, &locale->modifier); g_free (name); name = NULL; #ifdef WITH_INCOMPLETE_LOCALES if (utf8_only) { if (locale->territory_code == NULL || locale->modifier) { g_debug ("Ignoring '%s' as a locale, since it lacks territory code or modifier", name); gdm_locale_free (locale); return FALSE; } } #endif locale->id = construct_language_name (locale->language_code, locale->territory_code, NULL, locale->modifier); locale->name = construct_language_name (locale->language_code, locale->territory_code, locale->codeset, locale->modifier); #ifndef WITH_INCOMPLETE_LOCALES if (!gdm_language_has_translations (locale->name) && !gdm_language_has_translations (locale->id) && !gdm_language_has_translations (locale->language_code) && utf8_only) { g_debug ("Ignoring '%s' as a locale, since it lacks translations", locale->name); gdm_locale_free (locale); return FALSE; } #endif if (!utf8_only) { g_free (locale->id); locale->id = g_strdup (locale->name); } old_locale = g_hash_table_lookup (gdm_available_locales_map, locale->id); if (old_locale != NULL) { if (strlen (old_locale->name) > strlen (locale->name)) { gdm_locale_free (locale); return FALSE; } } g_hash_table_insert (gdm_available_locales_map, g_strdup (locale->id), locale); return TRUE; }
gboolean thrift_test_handler_test_insanity (TTestThriftTestIf *iface, GHashTable **_return, const TTestInsanity *argument, GError **error) { TTestXtruct *xtruct_in; gchar *string_thing = NULL; gint byte_thing; gint i32_thing; gint64 i64_thing; GPtrArray *xtructs; TTestInsanity *looney; GHashTable *user_map; GHashTable *first_map; GHashTable *second_map; GHashTableIter hash_table_iter; GHashTableIter inner_hash_table_iter; GHashTableIter user_map_iter; gpointer key; gpointer value; TTestUserId *user_id; guint i; THRIFT_UNUSED_VAR (iface); THRIFT_UNUSED_VAR (error); printf ("testInsanity()\n"); first_map = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); second_map = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); g_hash_table_insert (first_map, GINT_TO_POINTER (T_TEST_NUMBERZ_TWO), argument); g_hash_table_insert (first_map, GINT_TO_POINTER (T_TEST_NUMBERZ_THREE), argument); /* Increment argument's ref count since first_map now holds two references to it and would otherwise attempt to deallocate it twice during destruction. We do this instead of creating a copy of argument in order to mimic the C++ implementation (and since, frankly, the world needs less argument, not more). */ g_object_ref (argument); looney = g_object_new (T_TEST_TYPE_INSANITY, NULL); g_hash_table_insert (second_map, GINT_TO_POINTER (T_TEST_NUMBERZ_SIX), looney); user_id = g_malloc (sizeof *user_id); *user_id = 1; g_hash_table_insert (*_return, user_id, first_map); user_id = g_malloc (sizeof *user_id); *user_id = 2; g_hash_table_insert (*_return, user_id, second_map); printf ("return"); printf (" = {"); g_hash_table_iter_init (&hash_table_iter, *_return); while (g_hash_table_iter_next (&hash_table_iter, &key, &value)) { printf ("%" PRId64 " => {", *(TTestUserId *)key); g_hash_table_iter_init (&inner_hash_table_iter, (GHashTable *)value); while (g_hash_table_iter_next (&inner_hash_table_iter, &key, &value)) { printf ("%d => {", (TTestNumberz)key); g_object_get ((TTestInsanity *)value, "userMap", &user_map, "xtructs", &xtructs, NULL); printf ("{"); g_hash_table_iter_init (&user_map_iter, user_map); while (g_hash_table_iter_next (&user_map_iter, &key, &value)) { printf ("%d => %" PRId64 ", ", (TTestNumberz)key, *(TTestUserId *)value); } printf ("}, "); g_hash_table_unref (user_map); printf ("{"); for (i = 0; i < xtructs->len; ++i) { xtruct_in = g_ptr_array_index (xtructs, i); g_object_get (xtruct_in, "string_thing", &string_thing, "byte_thing", &byte_thing, "i32_thing", &i32_thing, "i64_thing", &i64_thing, NULL); printf ("{\"%s\", %d, %d, %" PRId64 "}, ", string_thing, byte_thing, i32_thing, i64_thing); } printf ("}"); g_ptr_array_unref (xtructs); printf ("}, "); } printf ("}, "); } printf ("}\n"); return TRUE; }
static LINE_CACHE_REC * view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line) { INDENT_FUNC indent_func; LINE_CACHE_REC *rec; LINE_CACHE_SUB_REC *sub; GSList *lines; unsigned char cmd; const unsigned char *ptr, *next_ptr, *last_space_ptr; int xpos, pos, indent_pos, last_space, last_color, color, linecount; int char_len; unichar chr; g_return_val_if_fail(line->text != NULL, NULL); color = ATTR_RESETFG | ATTR_RESETBG; xpos = 0; indent_pos = view->default_indent; last_space = last_color = 0; last_space_ptr = NULL; sub = NULL; indent_func = view->default_indent_func; linecount = 1; lines = NULL; for (ptr = line->text;;) { if (*ptr == '\0') { /* command */ ptr++; cmd = *ptr; ptr++; if (cmd == LINE_CMD_EOL || cmd == LINE_CMD_FORMAT) break; if (cmd == LINE_CMD_CONTINUE) { unsigned char *tmp; memcpy(&tmp, ptr, sizeof(char *)); ptr = tmp; continue; } if (cmd == LINE_CMD_INDENT) { /* set indentation position here - don't do it if we're too close to right border */ if (xpos < view->width-5) indent_pos = xpos; } else if (cmd == LINE_CMD_INDENT_FUNC) { memcpy(&indent_func, ptr, sizeof(INDENT_FUNC)); ptr += sizeof(INDENT_FUNC); if (indent_func == NULL) indent_func = view->default_indent_func; } else update_cmd_color(cmd, &color); continue; } if (!view->utf8) { /* MH */ if (term_type != TERM_TYPE_BIG5 || ptr[1] == '\0' || !is_big5(ptr[0], ptr[1])) char_len = 1; else char_len = 2; next_ptr = ptr+char_len; } else { char_len = 1; while (ptr[char_len] != '\0' && char_len < 6) char_len++; next_ptr = ptr; if (get_utf8_char(&next_ptr, char_len, &chr) < 0) char_len = 1; else char_len = utf8_width(chr); next_ptr++; } if (xpos + char_len > view->width && sub != NULL && (last_space <= indent_pos || last_space <= 10) && view->longword_noindent) { /* long word, remove the indentation from this line */ xpos -= sub->indent; sub->indent = 0; } if (xpos + char_len > view->width) { xpos = indent_func == NULL ? indent_pos : indent_func(view, line, -1); sub = g_new0(LINE_CACHE_SUB_REC, 1); if (last_space > indent_pos && last_space > 10) { /* go back to last space */ color = last_color; ptr = last_space_ptr; while (*ptr == ' ') ptr++; } else if (view->longword_noindent) { /* long word, no indentation in next line */ xpos = 0; sub->continues = TRUE; } sub->start = ptr; sub->indent = xpos; sub->indent_func = indent_func; sub->color = color; lines = g_slist_append(lines, sub); linecount++; last_space = 0; continue; } if (!view->utf8 && char_len > 1) { last_space = xpos; last_space_ptr = next_ptr; last_color = color; } else if (*ptr == ' ') { last_space = xpos; last_space_ptr = ptr; last_color = color; } xpos += char_len; ptr = next_ptr; } rec = g_malloc(sizeof(LINE_CACHE_REC)-sizeof(LINE_CACHE_SUB_REC) + sizeof(LINE_CACHE_SUB_REC) * (linecount-1)); rec->last_access = time(NULL); rec->count = linecount; if (rec->count > 1) { for (pos = 0; lines != NULL; pos++) { void *data = lines->data; memcpy(&rec->lines[pos], data, sizeof(LINE_CACHE_SUB_REC)); lines = g_slist_remove(lines, data); g_free(data); } } g_hash_table_insert(view->cache->line_cache, line, rec); return rec; }
/* creates a stat_tree node * name: the name of the stats_tree node * parent_name: the name of the ALREADY REGISTERED parent * with_hash: whether or not it should keep a hash with its children names * as_named_node: whether or not it has to be registered in the root namespace */ static stat_node* new_stat_node(stats_tree *st, const gchar *name, int parent_id, gboolean with_hash, gboolean as_parent_node) { stat_node *node = (stat_node *)g_malloc (sizeof(stat_node)); stat_node *last_chld = NULL; node->counter = 0; node->total = 0; node->minvalue = G_MAXINT; node->maxvalue = G_MININT; node->st_flags = parent_id?0:ST_FLG_ROOTCHILD; node->bh = (burst_bucket*)g_malloc0(sizeof(burst_bucket)); node->bt = node->bh; node->bcount = 0; node->max_burst = 0; node->burst_time = -1.0; node->name = g_strdup(name); node->children = NULL; node->next = NULL; node->st = (stats_tree*) st; node->hash = with_hash ? g_hash_table_new(g_str_hash,g_str_equal) : NULL; node->parent = NULL; node->rng = NULL; if (as_parent_node) { g_hash_table_insert(st->names, node->name, node); g_ptr_array_add(st->parents,node); node->id = st->parents->len - 1; } else { node->id = -1; } if (parent_id >= 0 && parent_id < (int) st->parents->len ) { node->parent = (stat_node *)g_ptr_array_index(st->parents,parent_id); } else { /* ??? should we set the parent to be root ??? */ g_assert_not_reached(); } if (node->parent->children) { /* insert as last child */ for (last_chld = node->parent->children; last_chld->next; last_chld = last_chld->next ) ; last_chld->next = node; } else { /* insert as first child */ node->parent->children = node; } if(node->parent->hash) { g_hash_table_insert(node->parent->hash,node->name,node); } if (st->cfg->setup_node_pr) { st->cfg->setup_node_pr(node); } else { node->pr = NULL; } return node; }
static gboolean checkout_one_file_at (OstreeRepo *repo, OstreeRepoCheckoutOptions *options, GFile *source, GFileInfo *source_info, int destination_dfd, const char *destination_name, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *checksum; gboolean is_symlink; gboolean can_cache; gboolean need_copy = TRUE; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; g_autoptr(GInputStream) input = NULL; g_autoptr(GVariant) xattrs = NULL; gboolean is_whiteout; is_symlink = g_file_info_get_file_type (source_info) == G_FILE_TYPE_SYMBOLIC_LINK; checksum = ostree_repo_file_get_checksum ((OstreeRepoFile*)source); is_whiteout = !is_symlink && options->process_whiteouts && g_str_has_prefix (destination_name, WHITEOUT_PREFIX); /* First, see if it's a Docker whiteout, * https://github.com/docker/docker/blob/1a714e76a2cb9008cd19609059e9988ff1660b78/pkg/archive/whiteouts.go */ if (is_whiteout) { const char *name = destination_name + (sizeof (WHITEOUT_PREFIX) - 1); if (!name[0]) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid empty whiteout '%s'", name); goto out; } g_assert (name[0] != '/'); /* Sanity */ if (!glnx_shutil_rm_rf_at (destination_dfd, name, cancellable, error)) goto out; need_copy = FALSE; } else if (!is_symlink) { gboolean did_hardlink = FALSE; /* Try to do a hardlink first, if it's a regular file. This also * traverses all parent repos. */ OstreeRepo *current_repo = repo; while (current_repo) { gboolean is_bare = ((current_repo->mode == OSTREE_REPO_MODE_BARE && options->mode == OSTREE_REPO_CHECKOUT_MODE_NONE) || (current_repo->mode == OSTREE_REPO_MODE_BARE_USER && options->mode == OSTREE_REPO_CHECKOUT_MODE_USER)); gboolean current_can_cache = (options->enable_uncompressed_cache && current_repo->enable_uncompressed_cache); gboolean is_archive_z2_with_cache = (current_repo->mode == OSTREE_REPO_MODE_ARCHIVE_Z2 && options->mode == OSTREE_REPO_CHECKOUT_MODE_USER && current_can_cache); /* But only under these conditions */ if (is_bare || is_archive_z2_with_cache) { /* Override repo mode; for archive-z2 we're looking in the cache, which is in "bare" form */ _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, OSTREE_REPO_MODE_BARE); if (!checkout_file_hardlink (current_repo, options, loose_path_buf, destination_dfd, destination_name, TRUE, &did_hardlink, cancellable, error)) goto out; if (did_hardlink && options->devino_to_csum_cache) { struct stat stbuf; OstreeDevIno *key; if (TEMP_FAILURE_RETRY (fstatat (destination_dfd, destination_name, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0) { glnx_set_error_from_errno (error); goto out; } key = g_new (OstreeDevIno, 1); key->dev = stbuf.st_dev; key->ino = stbuf.st_ino; memcpy (key->checksum, checksum, 65); g_hash_table_add ((GHashTable*)options->devino_to_csum_cache, key); } if (did_hardlink) break; } current_repo = current_repo->parent_repo; } need_copy = !did_hardlink; } can_cache = (options->enable_uncompressed_cache && repo->enable_uncompressed_cache); /* Ok, if we're archive-z2 and we didn't find an object, uncompress * it now, stick it in the cache, and then hardlink to that. */ if (can_cache && !is_whiteout && !is_symlink && need_copy && repo->mode == OSTREE_REPO_MODE_ARCHIVE_Z2 && options->mode == OSTREE_REPO_CHECKOUT_MODE_USER) { gboolean did_hardlink; if (!ostree_repo_load_file (repo, checksum, &input, NULL, NULL, cancellable, error)) goto out; /* Overwrite any parent repo from earlier */ _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, OSTREE_REPO_MODE_BARE); if (!checkout_object_for_uncompressed_cache (repo, loose_path_buf, source_info, input, cancellable, error)) { g_prefix_error (error, "Unpacking loose object %s: ", checksum); goto out; } g_clear_object (&input); /* Store the 2-byte objdir prefix (e.g. e3) in a set. The basic * idea here is that if we had to unpack an object, it's very * likely we're replacing some other object, so we may need a GC. * * This model ensures that we do work roughly proportional to * the size of the changes. For example, we don't scan any * directories if we didn't modify anything, meaning you can * checkout the same tree multiple times very quickly. * * This is also scale independent; we don't hardcode e.g. looking * at 1000 objects. * * The downside is that if we're unlucky, we may not free * an object for quite some time. */ g_mutex_lock (&repo->cache_lock); { gpointer key = GUINT_TO_POINTER ((g_ascii_xdigit_value (checksum[0]) << 4) + g_ascii_xdigit_value (checksum[1])); if (repo->updated_uncompressed_dirs == NULL) repo->updated_uncompressed_dirs = g_hash_table_new (NULL, NULL); g_hash_table_insert (repo->updated_uncompressed_dirs, key, key); } g_mutex_unlock (&repo->cache_lock); if (!checkout_file_hardlink (repo, options, loose_path_buf, destination_dfd, destination_name, FALSE, &did_hardlink, cancellable, error)) { g_prefix_error (error, "Using new cached uncompressed hardlink of %s to %s: ", checksum, destination_name); goto out; } need_copy = !did_hardlink; } /* Fall back to copy if we couldn't hardlink */ if (need_copy) { if (!ostree_repo_load_file (repo, checksum, &input, NULL, &xattrs, cancellable, error)) goto out; if (options->overwrite_mode == OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES) { if (!checkout_file_unioning_from_input_at (repo, options, source_info, xattrs, input, destination_dfd, destination_name, cancellable, error)) { g_prefix_error (error, "Union checkout of %s to %s: ", checksum, destination_name); goto out; } } else { if (!checkout_file_from_input_at (repo, options, source_info, xattrs, input, destination_dfd, destination_name, cancellable, error)) { g_prefix_error (error, "Checkout of %s to %s: ", checksum, destination_name); goto out; } } if (input) { if (!g_input_stream_close (input, cancellable, error)) goto out; } } ret = TRUE; out: return ret; }
/* Open the configuration file and fill in the key_sequences hash table * with key/character-list pairs taken from the [keys] group of the file. */ static void load_config (GtkImContextMultipress *self) { GKeyFile *key_file; GError *error = NULL; gchar **keys; gsize n_keys = 0; gsize i; key_file = g_key_file_new (); if (!g_key_file_load_from_file (key_file, CONFIGURATION_FILENAME, G_KEY_FILE_NONE, &error)) { g_warning ("Error while trying to open the %s configuration file: %s", CONFIGURATION_FILENAME, error->message); g_error_free (error); g_key_file_free (key_file); return; } keys = g_key_file_get_keys (key_file, "keys", &n_keys, &error); if (error != NULL) { g_warning ("Error while trying to read the %s configuration file: %s", CONFIGURATION_FILENAME, error->message); g_error_free (error); g_key_file_free (key_file); return; } for (i = 0; i < n_keys; ++i) { KeySequence *seq; guint keyval; keyval = gdk_keyval_from_name (keys[i]); if (keyval == GDK_KEY_VoidSymbol) { g_warning ("Error while trying to read the %s configuration file: " "invalid key name \"%s\"", CONFIGURATION_FILENAME, keys[i]); continue; } seq = g_slice_new (KeySequence); seq->characters = g_key_file_get_string_list (key_file, "keys", keys[i], &seq->n_characters, &error); if (error != NULL) { g_warning ("Error while trying to read the %s configuration file: %s", CONFIGURATION_FILENAME, error->message); g_error_free (error); error = NULL; g_slice_free (KeySequence, seq); continue; } /* Ownership of the KeySequence is taken over by the hash table */ g_hash_table_insert (self->key_sequences, GUINT_TO_POINTER (keyval), seq); } g_strfreev (keys); g_key_file_free (key_file); }
static void prv_server_available_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { dls_upnp_t *upnp = user_data; const char *udn; dls_device_t *device; const gchar *ip_address; dls_device_context_t *context; const dleyna_task_queue_key_t *queue_id; unsigned int i; prv_device_new_ct_t *priv_t; udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy); if (!udn) goto on_error; ip_address = gupnp_context_get_host_ip( gupnp_control_point_get_context(cp)); DLEYNA_LOG_DEBUG("UDN %s", udn); DLEYNA_LOG_DEBUG("IP Address %s", ip_address); device = g_hash_table_lookup(upnp->server_udn_map, udn); if (!device) { priv_t = g_hash_table_lookup(upnp->server_uc_map, udn); if (priv_t) device = priv_t->device; } if (!device) { DLEYNA_LOG_DEBUG("Device not found. Adding"); DLEYNA_LOG_DEBUG_NL(); priv_t = g_new0(prv_device_new_ct_t, 1); queue_id = dleyna_task_processor_add_queue( dls_server_get_task_processor(), dleyna_service_task_create_source(), DLS_SERVER_SINK, DLEYNA_TASK_QUEUE_FLAG_AUTO_REMOVE, dleyna_service_task_process_cb, dleyna_service_task_cancel_cb, dleyna_service_task_delete_cb); dleyna_task_queue_set_finally(queue_id, prv_device_chain_end); dleyna_task_queue_set_user_data(queue_id, priv_t); device = dls_device_new(upnp->connection, proxy, ip_address, upnp->interface_info, upnp->property_map, upnp->counter, queue_id); upnp->counter++; priv_t->upnp = upnp; priv_t->udn = g_strdup(udn); priv_t->queue_id = queue_id; priv_t->device = device; g_hash_table_insert(upnp->server_uc_map, g_strdup(udn), priv_t); } else { DLEYNA_LOG_DEBUG("Device Found"); for (i = 0; i < device->contexts->len; ++i) { context = g_ptr_array_index(device->contexts, i); if (!strcmp(context->ip_address, ip_address)) break; } if (i == device->contexts->len) { DLEYNA_LOG_DEBUG("Adding Context"); (void) dls_device_append_new_context(device, ip_address, proxy); } DLEYNA_LOG_DEBUG_NL(); } on_error: return; }
static int load_mmap() { char full_path[DIR_PATH_LEN] = {0}; int i = 0; cdn_speed_ip_mmap = (my_mmap_t*)malloc( max_project_number * sizeof(my_mmap_t) ); cdn_speed_area_mmap = (my_mmap_t*)malloc( max_project_number * sizeof(my_mmap_t) ); url_page_mmap = (my_mmap_t*)malloc(max_page_per_proj * max_project_number * sizeof(my_mmap_t)); snprintf(full_path, sizeof(full_path), "%s/%s", idc_mmap_file_dirpath,"idc_test_ip_mmap"); idc_test_ip_mmap.type = MMAP_TYPE_IDC_IP; if (create_mmap(full_path, idc_mmap_size_ip, &idc_test_ip_mmap) != 0) return -1; if(idc_test_ip_mmap.mmap_head->records_num != 0)//mmap中有数据,则根据mmap更新hash表 set_hash_for_ip_mmap(idc_hash_ip, &idc_test_ip_mmap, idc_test_ip_mmap.type); idc_test_area_mmap.type = MMAP_TYPE_IDC_AREA; snprintf(full_path, sizeof(full_path), "%s/%s", idc_mmap_file_dirpath,"idc_test_area_mmap"); if (create_mmap(full_path, idc_mmap_size_area, &idc_test_area_mmap) != 0) return -1; //重启时重设records idc_test_area_mmap.records_num = idc_test_area_mmap.mmap_head->records_num = 0; for(i = 1; i <= max_project_number; i++) { snprintf(full_path, sizeof(full_path), "%s/%s%03d", cdn_mmap_file_dirpath,"cdn_speed_ip_mmap",i); cdn_speed_ip_mmap[ i-1 ].type = MMAP_TYPE_CDN_IP; if (create_mmap(full_path, cdn_mmap_size_ip, &cdn_speed_ip_mmap[ i-1 ]) != 0) return -1; if(cdn_speed_ip_mmap[ i-1 ].mmap_head->records_num != 0) set_hash_for_ip_mmap(cdn_hash_ip[i-1], &cdn_speed_ip_mmap[ i-1 ], cdn_speed_ip_mmap[ i-1 ].type); cdn_speed_area_mmap[ i-1 ].type = MMAP_TYPE_CDN_AREA; snprintf(full_path, sizeof(full_path), "%s/%s%03d", cdn_mmap_file_dirpath,"cdn_speed_area_mmap",i); if (create_mmap(full_path, cdn_mmap_size_area, &cdn_speed_area_mmap[ i-1 ]) != 0) return -1; cdn_speed_area_mmap[ i-1 ].records_num = cdn_speed_area_mmap[ i-1 ].mmap_head->records_num = 0; } //url_page's mmap int j, pos; url_page_status = (url_page_used_t*)malloc(sizeof(url_page_used_t) * max_project_number); if(url_page_status == NULL) ERROR_RETURN(("URL PAGE STATUS CREATE FAILED!") ,-1); for(i = 0; i < max_project_number; i++) { url_page_status[i].used_count = 0; for (j = 0; j < max_page_per_proj; j++) url_page_status[i].status[j] = 0; } for(i = 1; i <= max_project_number; i++) { for(j = 1; j <= max_page_per_proj; j++) { snprintf(full_path, sizeof(full_path), "%s/%s%03d_%03d", url_mmap_file_dirpath,"url_page_mmap", i, j); pos = (i-1) * max_page_per_proj + (j-1); url_page_mmap[pos].type = MMAP_TYPE_URL; if (create_mmap(full_path, url_mmap_size_page, &url_page_mmap[pos]) == -1) return -1; //加入hash表 url_page_index[i] if(url_page_mmap[pos].key > 0 && url_page_mmap[pos].value > 0 && url_page_mmap[pos].value < max_page_per_proj) { g_hash_table_insert(url_page_index[i-1], &(url_page_mmap[pos].key), &(url_page_mmap[pos].value)); url_page_status[i-1].used_count ++; url_page_status[i-1].status[url_page_mmap[pos].value] = 1; } url_page_mmap[pos].records_num = url_page_mmap[pos].mmap_head->records_num = 0; } } return 0; }
static void picture_scaled (GObject *source_object, GAsyncResult *res, gpointer user_data) { BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data); CcBackgroundItem *item; GError *error = NULL; GdkPixbuf *pixbuf; const char *source_url; GtkTreeIter iter; GtkListStore *store; store = bg_source_get_liststore (BG_SOURCE (bg_source)); item = g_object_get_data (source_object, "item"); pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (pixbuf == NULL) { g_warning ("Failed to load image: %s", error->message); g_error_free (error); g_object_unref (item); return; } /* insert the item into the liststore */ gtk_list_store_insert_with_values (store, &iter, 0, 0, pixbuf, 1, item, -1); source_url = cc_background_item_get_source_url (item); if (source_url != NULL) { g_hash_table_insert (bg_source->priv->known_items, bg_pictures_source_get_unique_filename (source_url), GINT_TO_POINTER (TRUE)); } else { char *cache_path; GFile *file, *parent, *dir; cache_path = bg_pictures_source_get_cache_path (); dir = g_file_new_for_path (cache_path); g_free (cache_path); file = g_file_new_for_uri (cc_background_item_get_uri (item)); parent = g_file_get_parent (file); if (g_file_equal (parent, dir)) { char *basename; basename = g_file_get_basename (file); g_hash_table_insert (bg_source->priv->known_items, basename, GINT_TO_POINTER (TRUE)); } g_object_unref (file); g_object_unref (parent); } g_object_unref (pixbuf); }
static void gam_dnotify_directory_handler_internal(const char *path, pollHandlerMode mode) { DNotifyData *data; int fd; switch (mode) { case GAMIN_ACTIVATE: GAM_DEBUG(DEBUG_INFO, "Adding %s to dnotify\n", path); break; case GAMIN_DEACTIVATE: GAM_DEBUG(DEBUG_INFO, "Removing %s from dnotify\n", path); break; case GAMIN_FLOWCONTROLSTART: GAM_DEBUG(DEBUG_INFO, "Start flow control for %s\n", path); break; case GAMIN_FLOWCONTROLSTOP: GAM_DEBUG(DEBUG_INFO, "Stop flow control for %s\n", path); break; default: gam_error(DEBUG_INFO, "Unknown DNotify operation %d for %s\n", mode, path); return; } G_LOCK(dnotify); if (mode == GAMIN_ACTIVATE) { if ((data = g_hash_table_lookup(path_hash, path)) != NULL) { data->refcount++; GAM_DEBUG(DEBUG_INFO, " found incremented refcount: %d\n", data->refcount); G_UNLOCK(dnotify); #ifdef GAMIN_DEBUG_API gam_debug_report(GAMDnotifyChange, path, data->refcount); #endif return; } fd = open(path, O_RDONLY); if (fd < 0) { G_UNLOCK(dnotify); return; } data = gam_dnotify_data_new(path, fd); g_hash_table_insert(fd_hash, GINT_TO_POINTER(data->fd), data); g_hash_table_insert(path_hash, data->path, data); fcntl(fd, F_SETSIG, SIGRTMIN); fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_DELETE | DN_RENAME | DN_ATTRIB | DN_MULTISHOT); GAM_DEBUG(DEBUG_INFO, "activated DNotify for %s\n", path); #ifdef GAMIN_DEBUG_API gam_debug_report(GAMDnotifyCreate, path, 0); #endif } else if (mode == GAMIN_DEACTIVATE) { data = g_hash_table_lookup(path_hash, path); if (!data) { GAM_DEBUG(DEBUG_INFO, " not found !!!\n"); G_UNLOCK(dnotify); return; } data->refcount--; if (data->refcount == 0) { close(data->fd); GAM_DEBUG(DEBUG_INFO, "deactivated DNotify for %s\n", data->path); g_hash_table_remove(path_hash, data->path); g_hash_table_remove(fd_hash, GINT_TO_POINTER(data->fd)); gam_dnotify_data_free(data); #ifdef GAMIN_DEBUG_API gam_debug_report(GAMDnotifyDelete, path, 0); #endif } else { GAM_DEBUG(DEBUG_INFO, " found decremented refcount: %d\n", data->refcount); #ifdef GAMIN_DEBUG_API gam_debug_report(GAMDnotifyChange, data->path, data->refcount); #endif } } else if ((mode == GAMIN_FLOWCONTROLSTART) || (mode == GAMIN_FLOWCONTROLSTOP)) { data = g_hash_table_lookup(path_hash, path); if (!data) { GAM_DEBUG(DEBUG_INFO, " not found !!!\n"); G_UNLOCK(dnotify); return; } if (data != NULL) { if (mode == GAMIN_FLOWCONTROLSTART) { if (data->fd >= 0) { close(data->fd); g_hash_table_remove(fd_hash, GINT_TO_POINTER(data->fd)); data->fd = -1; GAM_DEBUG(DEBUG_INFO, "deactivated DNotify for %s\n", data->path); #ifdef GAMIN_DEBUG_API gam_debug_report(GAMDnotifyFlowOn, data->path, 0); #endif } data->busy++; } else { if (data->busy > 0) { data->busy--; if (data->busy == 0) { fd = open(data->path, O_RDONLY); if (fd < 0) { G_UNLOCK(dnotify); GAM_DEBUG(DEBUG_INFO, "Failed to reactivate DNotify for %s\n", data->path); return; } data->fd = fd; g_hash_table_insert(fd_hash, GINT_TO_POINTER(data->fd), data); fcntl(fd, F_SETSIG, SIGRTMIN); fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_DELETE | DN_RENAME | DN_ATTRIB | DN_MULTISHOT); GAM_DEBUG(DEBUG_INFO, "Reactivated DNotify for %s\n", data->path); #ifdef GAMIN_DEBUG_API gam_debug_report(GAMDnotifyFlowOff, path, 0); #endif } } } } } else { GAM_DEBUG(DEBUG_INFO, "Unimplemented operation\n"); } G_UNLOCK(dnotify); }
int update_member(unsigned int id, uint64_t born, uint64_t seq, int32_t votes, uint32_t procs, const char *uname, const char *state, const char *version) { int changed = 0; crm_node_t *node = NULL; node = g_hash_table_lookup(membership_list, GUINT_TO_POINTER(id)); if (node == NULL) { ais_malloc0(node, sizeof(crm_node_t)); ais_info("Creating entry for node %u born on " U64T "", id, seq); node->id = id; node->addr = NULL; node->state = ais_strdup("unknown"); g_hash_table_insert(membership_list, GUINT_TO_POINTER(id), node); node = g_hash_table_lookup(membership_list, GUINT_TO_POINTER(id)); } AIS_ASSERT(node != NULL); if (seq != 0) { node->last_seen = seq; } if (born != 0 && node->born != born) { changed = TRUE; node->born = born; ais_info("%p Node %u (%s) born on: " U64T, node, id, uname, born); } if (version != NULL) { ais_free(node->version); node->version = ais_strdup(version); } if (uname != NULL) { if (node->uname == NULL || ais_str_eq(node->uname, uname) == FALSE) { ais_info("%p Node %u now known as %s (was: %s)", node, id, uname, node->uname); ais_free(node->uname); node->uname = ais_strdup(uname); changed = TRUE; } } if (procs != 0 && procs != node->processes) { ais_info("Node %s now has process list: %.32x (%u)", node->uname, procs, procs); node->processes = procs; changed = TRUE; } if (votes >= 0 && votes != node->votes) { ais_info("Node %s now has %d quorum votes (was %d)", node->uname, votes, node->votes); node->votes = votes; changed = TRUE; } if (state != NULL) { if (node->state == NULL || ais_str_eq(node->state, state) == FALSE) { ais_free(node->state); node->state = ais_strdup(state); ais_info("Node %u/%s is now: %s", id, node->uname ? node->uname : "unknown", state); changed = TRUE; } } return changed; }