static ObjectChange* bus_move_handle(Bus *bus, Handle *handle, Point *to, ConnectionPoint *cp, HandleMoveReason reason, ModifierKeys modifiers) { Connection *conn = &bus->connection; Point *endpoints; real *parallel=NULL; real *perp=NULL; Point vhat, vhatperp; Point u; real vlen, vlen2; real len_scale; int i; const int num_handles = bus->num_handles; /* const to help scan-build */ /* code copied to Misc/tree.c */ parallel = (real *)g_alloca (num_handles * sizeof(real)); perp = (real *)g_alloca (num_handles * sizeof(real)); if (handle->id == HANDLE_BUS) { handle->pos = *to; } else { endpoints = &conn->endpoints[0]; vhat = endpoints[1]; point_sub(&vhat, &endpoints[0]); if ((fabs(vhat.x) == 0.0) && (fabs(vhat.y)==0.0)) { vhat.x += 0.01; } vlen = sqrt(point_dot(&vhat, &vhat)); point_scale(&vhat, 1.0/vlen); vhatperp.x = -vhat.y; vhatperp.y = vhat.x; for (i=0;i<num_handles;i++) { u = bus->handles[i]->pos; point_sub(&u, &endpoints[0]); parallel[i] = point_dot(&vhat, &u); perp[i] = point_dot(&vhatperp, &u); } connection_move_handle(&bus->connection, handle->id, to, cp, reason, modifiers); vhat = endpoints[1]; point_sub(&vhat, &endpoints[0]); if ((fabs(vhat.x) == 0.0) && (fabs(vhat.y)==0.0)) { vhat.x += 0.01; } vlen2 = sqrt(point_dot(&vhat, &vhat)); len_scale = vlen2 / vlen; point_normalize(&vhat); vhatperp.x = -vhat.y; vhatperp.y = vhat.x; for (i=0;i<num_handles;i++) { if (bus->handles[i]->connected_to == NULL) { u = vhat; point_scale(&u, parallel[i]*len_scale); point_add(&u, &endpoints[0]); bus->parallel_points[i] = u; u = vhatperp; point_scale(&u, perp[i]); point_add(&u, &bus->parallel_points[i]); bus->handles[i]->pos = u; } } } bus_update_data(bus); return NULL; }
/* In addition to writing the stack matrix into the give @matrix * argument this function *may* sometimes also return a pointer * to a matrix too so if we are querying the inverse matrix we * should query from the return matrix so that the result can * be cached within the stack. */ CoglMatrix * cogl_matrix_entry_get (CoglMatrixEntry *entry, CoglMatrix *matrix) { int depth; CoglMatrixEntry *current; CoglMatrixEntry **children; int i; for (depth = 0, current = entry; current; current = current->parent, depth++) { switch (current->op) { case COGL_MATRIX_OP_LOAD_IDENTITY: cogl_matrix_init_identity (matrix); goto initialized; case COGL_MATRIX_OP_LOAD: { CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)current; *matrix = *load->matrix; goto initialized; } case COGL_MATRIX_OP_SAVE: { CoglMatrixEntrySave *save = (CoglMatrixEntrySave *)current; if (!save->cache_valid) { CoglMagazine *matrices_magazine = cogl_matrix_stack_matrices_magazine; save->cache = _cogl_magazine_chunk_alloc (matrices_magazine); cogl_matrix_entry_get (current->parent, save->cache); save->cache_valid = TRUE; } *matrix = *save->cache; goto initialized; } default: continue; } } initialized: if (depth == 0) { switch (entry->op) { case COGL_MATRIX_OP_LOAD_IDENTITY: case COGL_MATRIX_OP_TRANSLATE: case COGL_MATRIX_OP_ROTATE: case COGL_MATRIX_OP_ROTATE_QUATERNION: case COGL_MATRIX_OP_ROTATE_EULER: case COGL_MATRIX_OP_SCALE: case COGL_MATRIX_OP_MULTIPLY: return NULL; case COGL_MATRIX_OP_LOAD: { CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)entry; return load->matrix; } case COGL_MATRIX_OP_SAVE: { CoglMatrixEntrySave *save = (CoglMatrixEntrySave *)entry; return save->cache; } } g_warn_if_reached (); return NULL; } #ifdef COGL_ENABLE_DEBUG if (!current) { g_warning ("Inconsistent matrix stack"); return NULL; } entry->composite_gets++; #endif children = g_alloca (sizeof (CoglMatrixEntry) * depth); /* We need walk the list of entries from the init/load/save entry * back towards the leaf node but the nodes don't link to their * children so we need to re-walk them here to add to a separate * array. */ for (i = depth - 1, current = entry; i >= 0 && current; i--, current = current->parent) { children[i] = current; } #ifdef COGL_ENABLE_DEBUG if (COGL_DEBUG_ENABLED (COGL_DEBUG_PERFORMANCE) && entry->composite_gets >= 2) { COGL_NOTE (PERFORMANCE, "Re-composing a matrix stack entry multiple times"); } #endif for (i = 0; i < depth; i++) { switch (children[i]->op) { case COGL_MATRIX_OP_TRANSLATE: { CoglMatrixEntryTranslate *translate = (CoglMatrixEntryTranslate *)children[i]; cogl_matrix_translate (matrix, translate->x, translate->y, translate->z); continue; } case COGL_MATRIX_OP_ROTATE: { CoglMatrixEntryRotate *rotate= (CoglMatrixEntryRotate *)children[i]; cogl_matrix_rotate (matrix, rotate->angle, rotate->x, rotate->y, rotate->z); continue; } case COGL_MATRIX_OP_ROTATE_EULER: { CoglMatrixEntryRotateEuler *rotate = (CoglMatrixEntryRotateEuler *)children[i]; CoglEuler euler; cogl_euler_init (&euler, rotate->heading, rotate->pitch, rotate->roll); cogl_matrix_rotate_euler (matrix, &euler); continue; } case COGL_MATRIX_OP_ROTATE_QUATERNION: { CoglMatrixEntryRotateQuaternion *rotate = (CoglMatrixEntryRotateQuaternion *)children[i]; CoglQuaternion quaternion; cogl_quaternion_init_from_array (&quaternion, rotate->values); cogl_matrix_rotate_quaternion (matrix, &quaternion); continue; } case COGL_MATRIX_OP_SCALE: { CoglMatrixEntryScale *scale = (CoglMatrixEntryScale *)children[i]; cogl_matrix_scale (matrix, scale->x, scale->y, scale->z); continue; } case COGL_MATRIX_OP_MULTIPLY: { CoglMatrixEntryMultiply *multiply = (CoglMatrixEntryMultiply *)children[i]; cogl_matrix_multiply (matrix, matrix, multiply->matrix); continue; } case COGL_MATRIX_OP_LOAD_IDENTITY: case COGL_MATRIX_OP_LOAD: case COGL_MATRIX_OP_SAVE: g_warn_if_reached (); continue; } } return NULL; }
/* searhces for match inside value, if match is mixed case, hten use case-sensitive, else insensitive */ gboolean camel_search_header_match (const gchar *value, const gchar *match, camel_search_match_t how, camel_search_t type, const gchar *default_charset) { const gchar *name, *addr; const guchar *ptr; gint truth = FALSE, i; CamelInternetAddress *cia; gchar *v, *vdom, *mdom; gunichar c; ptr = (const guchar *)value; while ((c = camel_utf8_getc (&ptr)) && g_unichar_isspace (c)) value = (const gchar *)ptr; switch (type) { case CAMEL_SEARCH_TYPE_ENCODED: v = camel_header_decode_string (value, default_charset); /* FIXME: Find header charset */ truth = header_match (v, match, how); g_free (v); break; case CAMEL_SEARCH_TYPE_MLIST: /* Special mailing list old-version domain hack If one of the mailing list names doesn't have an @ in it, its old-style, so only match against the pre-domain part, which should be common */ vdom = strchr (value, '@'); mdom = strchr (match, '@'); if (mdom == NULL && vdom != NULL) { v = g_alloca (vdom-value+1); memcpy (v, value, vdom-value); v[vdom-value] = 0; value = (gchar *)v; } else if (mdom != NULL && vdom == NULL) { v = g_alloca (mdom-match+1); memcpy (v, match, mdom-match); v[mdom-match] = 0; match = (gchar *)v; } /* Falls through */ case CAMEL_SEARCH_TYPE_ASIS: truth = header_match (value, match, how); break; case CAMEL_SEARCH_TYPE_ADDRESS_ENCODED: case CAMEL_SEARCH_TYPE_ADDRESS: /* possible simple case to save some work if we can */ if (header_match (value, match, how)) return TRUE; /* Now we decode any addresses, and try asis matches on name and address parts */ cia = camel_internet_address_new (); if (type == CAMEL_SEARCH_TYPE_ADDRESS_ENCODED) camel_address_decode ((CamelAddress *)cia, value); else camel_address_unformat ((CamelAddress *)cia, value); for (i=0; !truth && camel_internet_address_get (cia, i, &name, &addr);i++) truth = (name && header_match (name, match, how)) || (addr && header_match (addr, match, how)); g_object_unref (cia); break; } return truth; }
void _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx, const char *version_string, GLuint shader_gl_handle, GLenum shader_gl_type, GLsizei count_in, const char **strings_in, const GLint *lengths_in) { const char *vertex_boilerplate; const char *fragment_boilerplate; const char **strings = g_alloca (sizeof (char *) * (count_in + 4)); GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 4)); int count = 0; char *tex_coord_declarations = NULL; vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE; fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE; if (version_string) { strings[count] = version_string; lengths[count++] = -1; } if (ctx->driver == COGL_DRIVER_GLES2 && cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D)) { static const char texture_3d_extension[] = "#extension GL_OES_texture_3D : enable\n"; strings[count] = texture_3d_extension; lengths[count++] = sizeof (texture_3d_extension) - 1; } if (shader_gl_type == GL_VERTEX_SHADER) { strings[count] = vertex_boilerplate; lengths[count++] = strlen (vertex_boilerplate); } else if (shader_gl_type == GL_FRAGMENT_SHADER) { strings[count] = fragment_boilerplate; lengths[count++] = strlen (fragment_boilerplate); } memcpy (strings + count, strings_in, sizeof (char *) * count_in); if (lengths_in) memcpy (lengths + count, lengths_in, sizeof (GLint) * count_in); else { int i; for (i = 0; i < count_in; i++) lengths[count + i] = -1; /* null terminated */ } count += count_in; if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_SHOW_SOURCE))) { GString *buf = g_string_new (NULL); int i; g_string_append_printf (buf, "%s shader:\n", shader_gl_type == GL_VERTEX_SHADER ? "vertex" : "fragment"); for (i = 0; i < count; i++) if (lengths[i] != -1) g_string_append_len (buf, strings[i], lengths[i]); else g_string_append (buf, strings[i]); g_message ("%s", buf->str); g_string_free (buf, TRUE); } GE( ctx, glShaderSource (shader_gl_handle, count, (const char **) strings, lengths) ); g_free (tex_coord_declarations); }
static CORBA_Object od_server_activate_factory (MateComponent_ServerInfo *si, ODActivationInfo *actinfo, const MateComponent_ActivationEnvironment *environment, MateComponent_ActivationClient client, CORBA_Environment *ev) { MateComponent_ActivationResult *res; MateComponent_StringList selorder; MateComponent_ActivationFlags flags; CORBA_Object retval = CORBA_OBJECT_NIL; CORBA_Object factory = CORBA_OBJECT_NIL; char *requirements; char *iid; memset (&selorder, 0, sizeof (MateComponent_StringList)); requirements = g_alloca (strlen (si->location_info) + sizeof ("iid == ''")); sprintf (requirements, "iid == '%s'", si->location_info); flags = ((actinfo->flags | MateComponent_ACTIVATION_FLAG_NO_LOCAL) & (~MateComponent_ACTIVATION_FLAG_PRIVATE)); iid = g_strdup (si->iid); res = MateComponent_ActivationContext_activateMatchingFull ( actinfo->ac, requirements, &selorder, environment, flags, client, actinfo->ctx, ev); si = NULL; /* si can have been freed - due to re-enterancy */ if (ev->_major != CORBA_NO_EXCEPTION) goto out; switch (res->res._d) { case MateComponent_ACTIVATION_RESULT_NONE: CORBA_free (res); goto out; break; case MateComponent_ACTIVATION_RESULT_OBJECT: factory = res->res._u.res_object; break; default: g_assert_not_reached (); break; } /* Here comes the too clever by 1/2 bit: * we drop the (recursive) 'server_lock' - so we * can get other threads re-entering / doing activations * here. cf. od_server_activate_exe. */ { ServerLockState state; state = server_lock_drop (); retval = MateComponent_GenericFactory_createObject (factory, iid, ev); if (ev->_major != CORBA_NO_EXCEPTION) retval = CORBA_OBJECT_NIL; server_lock_resume (state); } CORBA_free (res); out: g_free (iid); return retval; }
static gchar * log_matcher_pcre_re_replace(LogMatcher *s, LogMessage *msg, gint value_handle, const gchar *value, gssize value_len, LogTemplate *replacement, gssize *new_length) { LogMatcherPcreRe *self = (LogMatcherPcreRe *) s; GString *new_value = NULL; gint *matches; gsize matches_size; gint num_matches; gint rc; gint start_offset, last_offset; gint options; gboolean last_match_was_empty; if (pcre_fullinfo(self->pattern, self->extra, PCRE_INFO_CAPTURECOUNT, &num_matches) < 0) g_assert_not_reached(); if (num_matches > RE_MAX_MATCHES) num_matches = RE_MAX_MATCHES; matches_size = 3 * (num_matches + 1); matches = g_alloca(matches_size * sizeof(gint)); /* we need zero initialized offsets for the last match as the * algorithm tries uses that as the base position */ matches[0] = matches[1] = matches[2] = 0; if (value_len == -1) value_len = strlen(value); last_offset = start_offset = 0; last_match_was_empty = FALSE; do { /* loop over the string, replacing one occurence at a time. */ /* NOTE: zero length matches need special care, as we could spin * forever otherwise (since the current position wouldn't be * advanced). * * A zero-length match can be as simple as "a*" which will be * returned unless PCRE_NOTEMPTY is specified. * * By supporting zero-length matches, we basically make it * possible to insert replacement between each incoming * character. * * For example: * pattern: a* * replacement: # * input: message * result: #m#e#s#s#a#g#e# * * This mimics Perl behaviour. */ if (last_match_was_empty) { /* Otherwise, arrange to run another match at the same point * to see if a non-empty match can be found. */ options = PCRE_NOTEMPTY | PCRE_ANCHORED; } else { options = 0; } rc = pcre_exec(self->pattern, self->extra, value, value_len, start_offset, (self->match_options | options), matches, matches_size); if (rc < 0 && rc != PCRE_ERROR_NOMATCH) { msg_error("Error while matching regexp", evt_tag_int("error_code", rc), NULL); break; } else if (rc < 0) { if ((options & PCRE_NOTEMPTY) == 0) { /* we didn't match, even when we permitted to match the * empty string. Nothing to find here, bail out */ break; } /* we didn't match, quite possibly because the empty match * was not permitted. Skip one character in order to avoid * infinite loop over the same zero-length match. */ start_offset = start_offset + 1; /* FIXME: handle complex sequences like utf8 and newline characters */ last_match_was_empty = FALSE; continue; } else { /* if the output array was too small, truncate the number of captures to RE_MAX_MATCHES */ if (rc == 0) rc = matches_size / 3; log_matcher_pcre_re_feed_backrefs(s, msg, value_handle, matches, rc, value); log_matcher_pcre_re_feed_named_substrings(s, msg, matches, value); if (!new_value) new_value = g_string_sized_new(value_len); /* append non-matching portion */ g_string_append_len(new_value, &value[last_offset], matches[0] - last_offset); /* replacement */ log_template_append_format(replacement, msg, NULL, LTZ_LOCAL, 0, NULL, new_value); last_match_was_empty = (matches[0] == matches[1]); start_offset = last_offset = matches[1]; } } while (self->super.flags & LMF_GLOBAL && start_offset < value_len); if (new_value) { /* append the last literal */ g_string_append_len(new_value, &value[last_offset], value_len - last_offset); if (new_length) *new_length = new_value->len; return g_string_free(new_value, FALSE); } return NULL; }
static const gchar * gdk_win32_display_get_name (GdkDisplay *display) { HDESK hdesk = GetThreadDesktop (GetCurrentThreadId ()); char dummy; char *desktop_name; HWINSTA hwinsta = GetProcessWindowStation (); char *window_station_name; DWORD n; DWORD session_id; char *display_name; static const char *display_name_cache = NULL; typedef BOOL (WINAPI *PFN_ProcessIdToSessionId) (DWORD, DWORD *); PFN_ProcessIdToSessionId processIdToSessionId; g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); if (display_name_cache != NULL) return display_name_cache; n = 0; GetUserObjectInformation (hdesk, UOI_NAME, &dummy, 0, &n); if (n == 0) desktop_name = "Default"; else { n++; desktop_name = g_alloca (n + 1); memset (desktop_name, 0, n + 1); if (!GetUserObjectInformation (hdesk, UOI_NAME, desktop_name, n, &n)) desktop_name = "Default"; } n = 0; GetUserObjectInformation (hwinsta, UOI_NAME, &dummy, 0, &n); if (n == 0) window_station_name = "WinSta0"; else { n++; window_station_name = g_alloca (n + 1); memset (window_station_name, 0, n + 1); if (!GetUserObjectInformation (hwinsta, UOI_NAME, window_station_name, n, &n)) window_station_name = "WinSta0"; } processIdToSessionId = (PFN_ProcessIdToSessionId) GetProcAddress (GetModuleHandle ("kernel32.dll"), "ProcessIdToSessionId"); if (!processIdToSessionId || !processIdToSessionId (GetCurrentProcessId (), &session_id)) session_id = 0; display_name = g_strdup_printf ("%ld\\%s\\%s", session_id, window_station_name, desktop_name); GDK_NOTE (MISC, g_print ("gdk_win32_display_get_name: %s\n", display_name)); display_name_cache = display_name; return display_name_cache; }
static char* menu_realpath(const char* name, char* resolved) { char* rpath = NULL; char* dest = NULL; char* extra_buf = NULL; const char* start; const char* end; const char* rpath_limit; long int path_max; int num_links = 0; if (name == NULL) { /* As per Single Unix Specification V2 we must return an error if * either parameter is a null pointer. We extend this to allow * the RESOLVED parameter to be NULL in case the we are expected to * allocate the room for the return value. */ errno = EINVAL; return NULL; } if (name[0] == '\0') { /* As per Single Unix Specification V2 we must return an error if * the name argument points to an empty string. */ errno = ENOENT; return NULL; } #ifdef PATH_MAX path_max = PATH_MAX; #else path_max = pathconf(name, _PC_PATH_MAX); if (path_max <= 0) { path_max = 1024; } #endif rpath = resolved ? g_alloca(path_max) : g_malloc(path_max); rpath_limit = rpath + path_max; if (name[0] != G_DIR_SEPARATOR) { if (!getcwd(rpath, path_max)) { rpath[0] = '\0'; goto error; } dest = strchr(rpath, '\0'); } else { rpath[0] = G_DIR_SEPARATOR; dest = rpath + 1; } for (start = end = name; *start; start = end) { struct stat st; int n; /* Skip sequence of multiple path-separators. */ while (*start == G_DIR_SEPARATOR) { ++start; } /* Find end of path component. */ for (end = start; *end && *end != G_DIR_SEPARATOR; ++end) { /* Nothing. */; } if (end - start == 0) { break; } else if (end - start == 1 && start[0] == '.') { /* nothing */; } else if (end - start == 2 && start[0] == '.' && start[1] == '.') { /* Back up to previous component, ignore if at root already. */ if (dest > rpath + 1) { while ((--dest)[-1] != G_DIR_SEPARATOR) { /* Nothing. */; } } } else { size_t new_size; if (dest[-1] != G_DIR_SEPARATOR) { *dest++ = G_DIR_SEPARATOR; } if (dest + (end - start) >= rpath_limit) { char* new_rpath; ptrdiff_t dest_offset = dest - rpath; if (resolved) { #ifdef ENAMETOOLONG errno = ENAMETOOLONG; #else /* Uh... just pick something */ errno = EINVAL; #endif if (dest > rpath + 1) { dest--; } *dest = '\0'; goto error; } new_size = rpath_limit - rpath; if (end - start + 1 > path_max) { new_size += end - start + 1; } else { new_size += path_max; } new_rpath = (char*) realloc(rpath, new_size); if (new_rpath == NULL) { goto error; } rpath = new_rpath; rpath_limit = rpath + new_size; dest = rpath + dest_offset; } memcpy(dest, start, end - start); dest = dest + (end - start); *dest = '\0'; if (stat(rpath, &st) < 0) { goto error; } if (S_ISLNK(st.st_mode)) { char* buf = alloca(path_max); size_t len; if (++num_links > MAXSYMLINKS) { errno = ELOOP; goto error; } n = readlink(rpath, buf, path_max); if (n < 0) { goto error; } buf[n] = '\0'; if (!extra_buf) { extra_buf = g_alloca(path_max); } len = strlen(end); if ((long int) (n + len) >= path_max) { #ifdef ENAMETOOLONG errno = ENAMETOOLONG; #else /* Uh... just pick something */ errno = EINVAL; #endif goto error; } /* Careful here, end may be a pointer into extra_buf... */ g_memmove(&extra_buf[n], end, len + 1); name = end = memcpy(extra_buf, buf, n); if (buf[0] == G_DIR_SEPARATOR) { dest = rpath + 1; /* It's an absolute symlink */ } else { /* Back up to previous component, ignore if at root already: */ if (dest > rpath + 1) { while ((--dest)[-1] != G_DIR_SEPARATOR) { /* Nothing. */; } } } } } } if (dest > rpath + 1 && dest[-1] == G_DIR_SEPARATOR) { --dest; } *dest = '\0'; return resolved ? memcpy(resolved, rpath, dest - rpath + 1) : rpath; error: if (resolved) { strcpy(resolved, rpath); } else { g_free(rpath); } return NULL; }
glibtop_map_entry * glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid) { int fd, i, nmaps, pr_err, heap; #if GLIBTOP_SOLARIS_RELEASE >= 50600 prxmap_t *maps; struct ps_prochandle *Pr = NULL; #else prmap_t *maps; #endif /* A few defines, to make it shorter down there */ #ifdef HAVE_PROCFS_H # define OFFSET pr_offset #else # define OFFSET pr_off #endif glibtop_map_entry *entry; struct stat inode; char buffer[BUFSIZ]; memset (buf, 0, sizeof (glibtop_proc_map)); #ifdef HAVE_PROCFS_H sprintf(buffer, "/proc/%d/xmap", (int)pid); #else sprintf(buffer, "/proc/%d", (int)pid); #endif if((fd = s_open(buffer, O_RDONLY)) < 0) { if (errno != EPERM && errno != EACCES) glibtop_warn_io_r(server, "open (%s)", buffer); return NULL; } #ifdef HAVE_PROCFS_H if(fstat(fd, &inode) < 0) { if(errno != EOVERFLOW) glibtop_warn_io_r(server, "fstat (%s)", buffer); /* else call daemon for 64-bit support */ s_close(fd); return NULL; } maps = g_alloca(inode.st_size); nmaps = inode.st_size / sizeof(prxmap_t); if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size) { glibtop_warn_io_r(server, "pread (%s)", buffer); s_close(fd); return NULL; } #else if(ioctl(fd, PIOCNMAP, &nmaps) < 0) { glibtop_warn_io_r(server, "ioctl(%s, PIOCNMAP)", buffer); s_close(fd); return NULL; } maps = g_alloca((nmaps + 1) * sizeof(prmap_t)); if(ioctl(fd, PIOCMAP, maps) < 0) { glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer); s_close(fd); return NULL; } #endif buf->number = nmaps; buf->size = sizeof(glibtop_map_entry); buf->total = nmaps * sizeof(glibtop_map_entry); entry = g_malloc0(buf->total); #if GLIBTOP_SOLARIS_RELEASE >= 50600 if(server->machine->objname && server->machine->pgrab && server->machine->pfree) Pr = (server->machine->pgrab)(pid, 1, &pr_err); #endif for(heap = 0,i = 0; i < nmaps; ++i) { int len; entry[i].start = maps[i].pr_vaddr; entry[i].end = maps[i].pr_vaddr + maps[i].pr_size; #if GLIBTOP_SOLARIS_RELEASE >= 50600 if(maps[i].pr_dev != PRNODEV) { entry[i].device = maps[i].pr_dev; entry[i].inode = maps[i].pr_ino; entry[i].flags |= _glibtop_sysdeps_map_device; } #endif entry[i].offset = maps[i].OFFSET; if(maps[i].pr_mflags & MA_READ) entry[i].perm |= GLIBTOP_MAP_PERM_READ; if(maps[i].pr_mflags & MA_WRITE){ entry[i].perm |= GLIBTOP_MAP_PERM_WRITE; entry[i].size = maps[i].pr_size; } if(maps[i].pr_mflags & MA_EXEC) entry[i].perm |= GLIBTOP_MAP_PERM_EXECUTE; if(maps[i].pr_mflags & MA_SHARED) entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; else entry[i].perm |= GLIBTOP_MAP_PERM_PRIVATE; entry[i].flags = _glibtop_sysdeps_map_entry; #if GLIBTOP_SOLARIS_RELEASE >= 50600 if(maps[i].pr_mflags & MA_ANON) { if(!heap) { ++heap; strcpy(entry[i].filename, "[ heap ]"); } else if(i == nmaps - 1) strcpy(entry[i].filename, "[ stack ]"); else strcpy(entry[i].filename, "[ anon ]"); entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); } else if(Pr) { server->machine->objname(Pr, maps[i].pr_vaddr, buffer, BUFSIZ); if((len = resolvepath(buffer, entry[i].filename, GLIBTOP_MAP_FILENAME_LEN)) > 0) { entry[i].filename[len] = 0; entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); } } #endif } #if GLIBTOP_SOLARIS_RELEASE >= 50600 if(Pr) server->machine->pfree(Pr); #endif buf->flags = _glibtop_sysdeps_proc_map; s_close(fd); return entry; }
int main (int argc, gchar **argv) { GOptionContext *context; GError *error = NULL; struct event_base *ev_base; GString *b32_key; pid_t *sfd; rspamd_inet_addr_t *addr; struct event term_ev, int_ev; struct in_addr ina = {INADDR_ANY}; rspamd_init_libs (); context = g_option_context_new ( "rspamd-http-server - test server for benchmarks"); g_option_context_set_summary (context, "Summary:\n Rspamd test HTTP server " RVERSION "\n Release id: " RID); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { rspamd_fprintf (stderr, "option parsing failed: %s\n", error->message); g_error_free (error); exit (1); } maps = g_hash_table_new (g_int_hash, g_int_equal); if (key == NULL) { server_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX, openssl_mode ? RSPAMD_CRYPTOBOX_MODE_NIST : RSPAMD_CRYPTOBOX_MODE_25519); b32_key = rspamd_keypair_print (server_key, RSPAMD_KEYPAIR_PUBKEY | RSPAMD_KEYPAIR_BASE32); rspamd_printf ("key: %v\n", b32_key); } else { /* TODO: add key loading */ } if (cache_size > 0) { c = rspamd_keypair_cache_new (cache_size); } sfd = g_alloca (sizeof (*sfd) * nworkers); addr = rspamd_inet_address_new (AF_INET, &ina); rspamd_inet_address_set_port (addr, port); rspamd_http_start_servers (sfd, addr); /* Just wait for workers */ ev_base = event_init (); event_set (&term_ev, SIGTERM, EV_SIGNAL, rspamd_http_server_term, sfd); event_base_set (ev_base, &term_ev); event_add (&term_ev, NULL); event_set (&int_ev, SIGINT, EV_SIGNAL, rspamd_http_server_term, sfd); event_base_set (ev_base, &int_ev); event_add (&int_ev, NULL); event_base_loop (ev_base, 0); return 0; }
void cogl_polygon (const CoglTextureVertex *vertices, unsigned int n_vertices, CoglBool use_color) { CoglPipeline *pipeline; ValidateState validate_state; int n_layers; int n_attributes; CoglAttribute **attributes; int i; unsigned int stride; size_t stride_bytes; CoglAttributeBuffer *attribute_buffer; float *v; _COGL_GET_CONTEXT (ctx, NO_RETVAL); pipeline = cogl_get_source (); validate_state.original_pipeline = pipeline; validate_state.pipeline = pipeline; cogl_pipeline_foreach_layer (pipeline, _cogl_polygon_validate_layer_cb, &validate_state); pipeline = validate_state.pipeline; n_layers = cogl_pipeline_get_n_layers (pipeline); n_attributes = 1 + n_layers + (use_color ? 1 : 0); attributes = g_alloca (sizeof (CoglAttribute *) * n_attributes); /* Our data is arranged like: * [X, Y, Z, TX0, TY0, TX1, TY1..., R, G, B, A,...] */ stride = 3 + (2 * n_layers) + (use_color ? 1 : 0); stride_bytes = stride * sizeof (float); /* Make sure there is enough space in the global vertex array. This * is used so we can render the polygon with a single call to OpenGL * but still support any number of vertices */ g_array_set_size (ctx->polygon_vertices, n_vertices * stride); attribute_buffer = cogl_attribute_buffer_new (ctx, n_vertices * stride_bytes, NULL); attributes[0] = cogl_attribute_new (attribute_buffer, "cogl_position_in", stride_bytes, 0, 3, COGL_ATTRIBUTE_TYPE_FLOAT); for (i = 0; i < n_layers; i++) { static const char *names[] = { "cogl_tex_coord0_in", "cogl_tex_coord1_in", "cogl_tex_coord2_in", "cogl_tex_coord3_in", "cogl_tex_coord4_in", "cogl_tex_coord5_in", "cogl_tex_coord6_in", "cogl_tex_coord7_in" }; char *allocated_name = NULL; const char *name; if (i < 8) name = names[i]; else name = allocated_name = g_strdup_printf ("cogl_tex_coord%d_in", i); attributes[i + 1] = cogl_attribute_new (attribute_buffer, name, stride_bytes, /* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */ 12 + 8 * i, 2, COGL_ATTRIBUTE_TYPE_FLOAT); g_free (allocated_name); } if (use_color) { attributes[n_attributes - 1] = cogl_attribute_new (attribute_buffer, "cogl_color_in", stride_bytes, /* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */ 12 + 8 * n_layers, 4, COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE); } /* Convert the vertices into an array of float vertex attributes */ v = (float *)ctx->polygon_vertices->data; for (i = 0; i < n_vertices; i++) { AppendTexCoordsState append_tex_coords_state; uint8_t *c; /* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */ v[0] = vertices[i].x; v[1] = vertices[i].y; v[2] = vertices[i].z; append_tex_coords_state.vertices_in = vertices; append_tex_coords_state.vertex = i; append_tex_coords_state.layer = 0; append_tex_coords_state.vertices_out = v; cogl_pipeline_foreach_layer (pipeline, append_tex_coord_attributes_cb, &append_tex_coords_state); if (use_color) { /* NB: [X,Y,Z,TX,TY...,R,G,B,A,...] */ c = (uint8_t *) (v + 3 + 2 * n_layers); c[0] = cogl_color_get_red_byte (&vertices[i].color); c[1] = cogl_color_get_green_byte (&vertices[i].color); c[2] = cogl_color_get_blue_byte (&vertices[i].color); c[3] = cogl_color_get_alpha_byte (&vertices[i].color); } v += stride; } v = (float *)ctx->polygon_vertices->data; cogl_buffer_set_data (COGL_BUFFER (attribute_buffer), 0, v, ctx->polygon_vertices->len * sizeof (float)); /* XXX: although this may seem redundant, we need to do this since * cogl_polygon() can be used with legacy state and its the source stack * which track whether legacy state is enabled. * * (We only have a CoglDrawFlag to disable legacy state not one * to enable it) */ cogl_push_source (pipeline); _cogl_framebuffer_draw_attributes (cogl_get_draw_framebuffer (), pipeline, COGL_VERTICES_MODE_TRIANGLE_FAN, 0, n_vertices, attributes, n_attributes, 0 /* no draw flags */); cogl_pop_source (); if (pipeline != validate_state.original_pipeline) cogl_object_unref (pipeline); cogl_object_unref (attribute_buffer); for (i = 0; i < n_attributes; i++) cogl_object_unref (attributes[i]); }
/** * g_hmac_new: * @digest_type: the desired type of digest * @key: (array length=key_len): the key for the HMAC * @key_len: the length of the keys * * Creates a new #GHmac, using the digest algorithm @digest_type. * If the @digest_type is not known, %NULL is returned. * A #GHmac can be used to compute the HMAC of a key and an * arbitrary binary blob, using different hashing algorithms. * * A #GHmac works by feeding a binary blob through g_hmac_update() * until the data is complete; the digest can then be extracted * using g_hmac_get_string(), which will return the checksum as a * hexadecimal string; or g_hmac_get_digest(), which will return a * array of raw bytes. Once either g_hmac_get_string() or * g_hmac_get_digest() have been called on a #GHmac, the HMAC * will be closed and it won't be possible to call g_hmac_update() * on it anymore. * * Return value: the newly created #GHmac, or %NULL. * Use g_hmac_unref() to free the memory allocated by it. * * Since: 2.30 */ GHmac * g_hmac_new (GChecksumType digest_type, const guchar *key, gsize key_len) { GChecksum *checksum; GHmac *hmac; guchar *buffer; guchar *pad; gsize i, len; gsize block_size; checksum = g_checksum_new (digest_type); g_return_val_if_fail (checksum != NULL, NULL); switch (digest_type) { case G_CHECKSUM_MD5: case G_CHECKSUM_SHA1: block_size = 64; /* RFC 2104 */ break; case G_CHECKSUM_SHA256: block_size = 64; /* RFC draft-kelly-ipsec-ciph-sha2-01 */ break; default: g_return_val_if_reached (NULL); } hmac = g_slice_new0 (GHmac); hmac->ref_count = 1; hmac->digest_type = digest_type; hmac->digesti = checksum; hmac->digesto = g_checksum_new (digest_type); buffer = g_alloca (block_size); pad = g_alloca (block_size); memset (buffer, 0, block_size); /* If the key is too long, hash it */ if (key_len > block_size) { len = block_size; g_checksum_update (hmac->digesti, key, key_len); g_checksum_get_digest (hmac->digesti, buffer, &len); g_checksum_reset (hmac->digesti); } /* Otherwise pad it with zeros */ else { memcpy (buffer, key, key_len); } /* First pad */ for (i = 0; i < block_size; i++) pad[i] = 0x36 ^ buffer[i]; /* ipad value */ g_checksum_update (hmac->digesti, pad, block_size); /* Second pad */ for (i = 0; i < block_size; i++) pad[i] = 0x5c ^ buffer[i]; /* opad value */ g_checksum_update (hmac->digesto, pad, block_size); return hmac; }
void rspamd_http_test_func (void) { struct event_base *ev_base = event_init (); rspamd_mempool_t *pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL); struct rspamd_cryptobox_keypair *serv_key, *client_key; struct rspamd_cryptobox_pubkey *peer_key; struct rspamd_keypair_cache *c; rspamd_mempool_mutex_t *mtx; rspamd_inet_addr_t *addr; gdouble ts1, ts2; gchar filepath[PATH_MAX], *buf; gchar *env; gint fd; guint i, j; pid_t *sfd; GString *b32_key; double diff, total_diff = 0.0, *latency, mean, std; /* Read environment */ if ((env = getenv ("RSPAMD_HTTP_CONNS")) != NULL) { pconns = strtoul (env, NULL, 10); } else { return; } if ((env = getenv ("RSPAMD_HTTP_TESTS")) != NULL) { ntests = strtoul (env, NULL, 10); } if ((env = getenv ("RSPAMD_HTTP_SIZE")) != NULL) { file_size = strtoul (env, NULL, 10); } if ((env = getenv ("RSPAMD_HTTP_SERVERS")) != NULL) { nservers = strtoul (env, NULL, 10); } rspamd_cryptobox_init (); rspamd_snprintf (filepath, sizeof (filepath), "/tmp/http-test-XXXXXX"); g_assert ((fd = mkstemp (filepath)) != -1); sfd = g_alloca (sizeof (*sfd) * nservers); latency = g_malloc0 (pconns * ntests * sizeof (gdouble)); buf = g_malloc (file_size); memset (buf, 0, file_size); g_assert (write (fd, buf, file_size) == file_size); g_free (buf); mtx = rspamd_mempool_get_mutex (pool); rspamd_parse_inet_address (&addr, "127.0.0.1", 0); rspamd_inet_address_set_port (addr, 43898); serv_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX, RSPAMD_CRYPTOBOX_MODE_25519); client_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX, RSPAMD_CRYPTOBOX_MODE_25519); c = rspamd_keypair_cache_new (16); rspamd_http_start_servers (sfd, addr, serv_key, NULL); usleep (100000); /* Do client stuff */ gperf_profiler_init (NULL, "plain-http-client"); for (i = 0; i < ntests; i ++) { for (j = 0; j < pconns; j ++) { rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, addr, NULL, NULL, c, ev_base, &latency[i * pconns + j]); } ts1 = rspamd_get_ticks (); event_base_loop (ev_base, 0); ts2 = rspamd_get_ticks (); diff = (ts2 - ts1) * 1000.0; total_diff += diff; } gperf_profiler_stop (); msg_info ("Made %d connections of size %d in %.6f ms, %.6f cps", ntests * pconns, file_size, total_diff, ntests * pconns / total_diff * 1000.); mean = rspamd_http_calculate_mean (latency, &std); msg_info ("Latency: %.6f ms mean, %.6f dev", mean, std); rspamd_http_stop_servers (sfd); rspamd_http_start_servers (sfd, addr, serv_key, c); //rspamd_mempool_lock_mutex (mtx); usleep (100000); b32_key = rspamd_keypair_print (serv_key, RSPAMD_KEYPAIR_PUBKEY|RSPAMD_KEYPAIR_BASE32); g_assert (b32_key != NULL); peer_key = rspamd_pubkey_from_base32 (b32_key->str, b32_key->len, RSPAMD_KEYPAIR_KEX, RSPAMD_CRYPTOBOX_MODE_25519); g_assert (peer_key != NULL); total_diff = 0.0; gperf_profiler_init (NULL, "cached-http-client"); for (i = 0; i < ntests; i ++) { for (j = 0; j < pconns; j ++) { rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, addr, client_key, peer_key, c, ev_base, &latency[i * pconns + j]); } ts1 = rspamd_get_ticks (); event_base_loop (ev_base, 0); ts2 = rspamd_get_ticks (); diff = (ts2 - ts1) * 1000.0; total_diff += diff; } gperf_profiler_stop (); msg_info ("Made %d encrypted connections of size %d in %.6f ms, %.6f cps", ntests * pconns, file_size, total_diff, ntests * pconns / total_diff * 1000.); mean = rspamd_http_calculate_mean (latency, &std); msg_info ("Latency: %.6f ms mean, %.6f dev", mean, std); /* Restart server */ rspamd_http_stop_servers (sfd); /* No keypairs cache */ rspamd_http_start_servers (sfd, addr, serv_key, NULL); usleep (100000); total_diff = 0.0; gperf_profiler_init (NULL, "fair-http-client"); for (i = 0; i < ntests; i ++) { for (j = 0; j < pconns; j ++) { rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, addr, client_key, peer_key, c, ev_base, &latency[i * pconns + j]); } ts1 = rspamd_get_ticks (); event_base_loop (ev_base, 0); ts2 = rspamd_get_ticks (); diff = (ts2 - ts1) * 1000.0; total_diff += diff; } gperf_profiler_stop (); msg_info ("Made %d uncached encrypted connections of size %d in %.6f ms, %.6f cps", ntests * pconns, file_size, total_diff, ntests * pconns / total_diff * 1000.); mean = rspamd_http_calculate_mean (latency, &std); msg_info ("Latency: %.6f ms mean, %.6f dev", mean, std); /* AES mode */ serv_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX, RSPAMD_CRYPTOBOX_MODE_NIST); client_key = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX, RSPAMD_CRYPTOBOX_MODE_NIST); c = rspamd_keypair_cache_new (16); /* Restart server */ rspamd_http_stop_servers (sfd); /* No keypairs cache */ rspamd_http_start_servers (sfd, addr, serv_key, c); //rspamd_mempool_lock_mutex (mtx); usleep (100000); b32_key = rspamd_keypair_print (serv_key, RSPAMD_KEYPAIR_PUBKEY | RSPAMD_KEYPAIR_BASE32); g_assert (b32_key != NULL); peer_key = rspamd_pubkey_from_base32 (b32_key->str, b32_key->len, RSPAMD_KEYPAIR_KEX, RSPAMD_CRYPTOBOX_MODE_NIST); g_assert (peer_key != NULL); total_diff = 0.0; gperf_profiler_init (NULL, "cached-http-client-aes"); for (i = 0; i < ntests; i++) { for (j = 0; j < pconns; j++) { rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, addr, client_key, peer_key, NULL, ev_base, &latency[i * pconns + j]); } ts1 = rspamd_get_ticks (); event_base_loop (ev_base, 0); ts2 = rspamd_get_ticks (); diff = (ts2 - ts1) * 1000.0; total_diff += diff; } gperf_profiler_stop (); msg_info ( "Made %d aes encrypted connections of size %d in %.6f ms, %.6f cps", ntests * pconns, file_size, total_diff, ntests * pconns / total_diff * 1000.); mean = rspamd_http_calculate_mean (latency, &std); msg_info ("Latency: %.6f ms mean, %.6f dev", mean, std); /* Restart server */ rspamd_http_stop_servers (sfd); /* No keypairs cache */ rspamd_http_start_servers (sfd, addr, serv_key, NULL); //rspamd_mempool_lock_mutex (mtx); usleep (100000); total_diff = 0.0; gperf_profiler_init (NULL, "fair-http-client-aes"); for (i = 0; i < ntests; i++) { for (j = 0; j < pconns; j++) { rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, addr, client_key, peer_key, c, ev_base, &latency[i * pconns + j]); } ts1 = rspamd_get_ticks (); event_base_loop (ev_base, 0); ts2 = rspamd_get_ticks (); diff = (ts2 - ts1) * 1000.0; total_diff += diff; } gperf_profiler_stop (); msg_info ( "Made %d uncached aes encrypted connections of size %d in %.6f ms, %.6f cps", ntests * pconns, file_size, total_diff, ntests * pconns / total_diff * 1000.); mean = rspamd_http_calculate_mean (latency, &std); msg_info ("Latency: %.6f ms mean, %.6f dev", mean, std); close (fd); unlink (filepath); rspamd_http_stop_servers (sfd); }
static CoglBool _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline, unsigned long pipelines_difference) { CoglPipelineShaderState *shader_state; _COGL_GET_CONTEXT (ctx, FALSE); shader_state = get_shader_state (pipeline); if (shader_state->source) { const char *source_strings[2]; GLint lengths[2]; GLint compile_status; GLuint shader; CoglPipelineSnippetData snippet_data; CoglPipelineSnippetList *vertex_snippets; COGL_STATIC_COUNTER (vertend_glsl_compile_counter, "glsl vertex compile counter", "Increments each time a new GLSL " "vertex shader is compiled", 0 /* no application private data */); COGL_COUNTER_INC (_cogl_uprof_context, vertend_glsl_compile_counter); g_string_append (shader_state->header, "void\n" "cogl_real_vertex_transform ()\n" "{\n" " cogl_position_out = " "cogl_modelview_projection_matrix * " "cogl_position_in;\n" "}\n"); g_string_append (shader_state->source, " cogl_vertex_transform ();\n" " cogl_color_out = cogl_color_in;\n" "}\n"); vertex_snippets = get_vertex_snippets (pipeline); /* Add hooks for the vertex transform part */ memset (&snippet_data, 0, sizeof (snippet_data)); snippet_data.snippets = vertex_snippets; snippet_data.hook = COGL_SNIPPET_HOOK_VERTEX_TRANSFORM; snippet_data.chain_function = "cogl_real_vertex_transform"; snippet_data.final_name = "cogl_vertex_transform"; snippet_data.function_prefix = "cogl_vertex_transform"; snippet_data.source_buf = shader_state->header; _cogl_pipeline_snippet_generate_code (&snippet_data); /* Add all of the hooks for vertex processing */ memset (&snippet_data, 0, sizeof (snippet_data)); snippet_data.snippets = vertex_snippets; snippet_data.hook = COGL_SNIPPET_HOOK_VERTEX; snippet_data.chain_function = "cogl_generated_source"; snippet_data.final_name = "cogl_vertex_hook"; snippet_data.function_prefix = "cogl_vertex_hook"; snippet_data.source_buf = shader_state->source; _cogl_pipeline_snippet_generate_code (&snippet_data); g_string_append (shader_state->source, "void\n" "main ()\n" "{\n" " cogl_vertex_hook ();\n"); /* If there are any snippets then we can't rely on the projection matrix to flip the rendering for offscreen buffers so we'll need to flip it using an extra statement and a uniform */ if (_cogl_pipeline_has_vertex_snippets (pipeline)) { g_string_append (shader_state->header, "uniform vec4 _cogl_flip_vector;\n"); g_string_append (shader_state->source, " cogl_position_out *= _cogl_flip_vector;\n"); } g_string_append (shader_state->source, "}\n"); GE_RET( shader, ctx, glCreateShader (GL_VERTEX_SHADER) ); lengths[0] = shader_state->header->len; source_strings[0] = shader_state->header->str; lengths[1] = shader_state->source->len; source_strings[1] = shader_state->source->str; _cogl_glsl_shader_set_source_with_boilerplate (ctx, NULL, shader, GL_VERTEX_SHADER, 2, /* count */ source_strings, lengths); GE( ctx, glCompileShader (shader) ); GE( ctx, glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) ); if (!compile_status) { GLint len = 0; char *shader_log; GE( ctx, glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &len) ); shader_log = g_alloca (len); GE( ctx, glGetShaderInfoLog (shader, len, &len, shader_log) ); g_warning ("Shader compilation failed:\n%s", shader_log); } shader_state->header = NULL; shader_state->source = NULL; shader_state->gl_shader = shader; } if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_BUILTIN_POINT_SIZE_UNIFORM) && (pipelines_difference & COGL_PIPELINE_STATE_POINT_SIZE)) { CoglPipeline *authority = _cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_POINT_SIZE); GE( ctx, glPointSize (authority->big_state->point_size) ); } return TRUE; }
static CamelAuthenticationResult pop3_store_authenticate_sync (CamelService *service, const gchar *mechanism, GCancellable *cancellable, GError **error) { CamelPOP3Store *store = CAMEL_POP3_STORE (service); CamelNetworkSettings *network_settings; CamelAuthenticationResult result; CamelSettings *settings; CamelPOP3Command *pcu = NULL; CamelPOP3Command *pcp = NULL; CamelPOP3Engine *pop3_engine; const gchar *password; gchar *host; gchar *user; gint status; password = camel_service_get_password (service); settings = camel_service_ref_settings (service); network_settings = CAMEL_NETWORK_SETTINGS (settings); host = camel_network_settings_dup_host (network_settings); user = camel_network_settings_dup_user (network_settings); g_object_unref (settings); pop3_engine = camel_pop3_store_ref_engine (store); if (!pop3_engine) { g_set_error_literal ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_UNAVAILABLE, _("You must be working online to complete this operation")); result = CAMEL_AUTHENTICATION_ERROR; goto exit; } if (mechanism == NULL) { if (password == NULL) { g_set_error_literal ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE, _("Authentication password not available")); result = CAMEL_AUTHENTICATION_ERROR; goto exit; } /* pop engine will take care of pipelining ability */ pcu = camel_pop3_engine_command_new ( pop3_engine, 0, NULL, NULL, cancellable, error, "USER %s\r\n", user); pcp = camel_pop3_engine_command_new ( pop3_engine, 0, NULL, NULL, cancellable, error, "PASS %s\r\n", password); } else if (strcmp (mechanism, "+APOP") == 0 && pop3_engine->apop) { gchar *secret, *md5asc, *d; if (password == NULL) { g_set_error_literal ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE, _("Authentication password not available")); result = CAMEL_AUTHENTICATION_ERROR; goto exit; } d = pop3_engine->apop; while (*d != '\0') { if (!isascii ((gint) * d)) { /* Translators: Do not translate APOP. */ g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_URL_INVALID, _("Unable to connect to POP server %s: " "Invalid APOP ID received. Impersonation " "attack suspected. Please contact your admin."), host); result = CAMEL_AUTHENTICATION_ERROR; goto exit; } d++; } secret = g_alloca ( strlen (pop3_engine->apop) + strlen (password) + 1); sprintf (secret, "%s%s", pop3_engine->apop, password); md5asc = g_compute_checksum_for_string ( G_CHECKSUM_MD5, secret, -1); pcp = camel_pop3_engine_command_new ( pop3_engine, 0, NULL, NULL, cancellable, error, "APOP %s %s\r\n", user, md5asc); g_free (md5asc); } else { GList *link; link = pop3_engine->auth; while (link != NULL) { CamelServiceAuthType *auth = link->data; if (g_strcmp0 (auth->authproto, mechanism) == 0) { result = try_sasl ( store, mechanism, cancellable, error); goto exit; } link = g_list_next (link); } g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE, _("No support for %s authentication"), mechanism); result = CAMEL_AUTHENTICATION_ERROR; goto exit; } while ((status = camel_pop3_engine_iterate (pop3_engine, pcp, cancellable, error)) > 0) ; if (status == -1) { g_prefix_error ( error, _("Unable to connect to POP server %s.\n" "Error sending password: "******": " separator. */ _("Unable to connect to POP server %s.\n" "Error sending username%s"), host, (tmp != NULL) ? tmp : ""); g_free (tmp); result = CAMEL_AUTHENTICATION_ERROR; } else if (pcp->state != CAMEL_POP3_COMMAND_OK) { result = CAMEL_AUTHENTICATION_REJECTED; } else { result = CAMEL_AUTHENTICATION_ACCEPTED; } camel_pop3_engine_command_free (pop3_engine, pcp); if (pcu != NULL) camel_pop3_engine_command_free (pop3_engine, pcu); exit: g_free (host); g_free (user); g_clear_object (&pop3_engine); return result; }
CORBA_Object CORBA_ORB_string_to_object (CORBA_ORB orb, const CORBA_char *string, CORBA_Environment *ev) { CORBA_Object retval = CORBA_OBJECT_NIL; CORBA_unsigned_long len; GIOPRecvBuffer *buf; #if defined ENABLE_HTTP gchar *ior = NULL; #endif guchar *tmpbuf; int i; if (strncmp (string, "IOR:", strlen("IOR:")) && strncmp (string, "corbaloc:", strlen ("corbaloc:")) && strncmp (string, "iiop:", strlen ("iiop:")) && strncmp (string, "iiops:", strlen ("iiops:")) && strncmp (string, "ssliop:", strlen ("ssliop:")) && strncmp (string, "uiop:", strlen ("uiop:"))) { #if defined ENABLE_HTTP if (orbit_use_http_iors && strstr (string, "://")) { /* FIXME: this code is a security hazard */ ior = orb_http_resolve (string); if (!ior) { /* FIXME, set error minor code * (vendor's error code) to tell user * initial location of error, ie my * local ORB, proxy's ORB, server's * ORB, etc. */ CORBA_exception_set_system ( ev, ex_CORBA_BAD_PARAM, CORBA_COMPLETED_NO); return CORBA_OBJECT_NIL; } string = ior; } else #endif { CORBA_exception_set_system ( ev, ex_CORBA_BAD_PARAM, CORBA_COMPLETED_NO); return CORBA_OBJECT_NIL; } } if (!strncmp (string, "IOR:", strlen ("IOR:"))) { string += 4; len = strlen (string); while (len > 0 && !g_ascii_isxdigit (string [len - 1])) len--; if (len % 2) { #if defined ENABLE_HTTP g_free (ior); #endif return CORBA_OBJECT_NIL; } tmpbuf = g_alloca (len / 2); for (i = 0; i < len; i += 2) tmpbuf [i/2] = (g_ascii_xdigit_value (string [i]) << 4) | g_ascii_xdigit_value (string [i + 1]); buf = giop_recv_buffer_use_encaps (tmpbuf, len / 2); if (ORBit_demarshal_object (&retval, buf, orb)) { CORBA_exception_set_system ( ev, ex_CORBA_MARSHAL, CORBA_COMPLETED_NO); retval = CORBA_OBJECT_NIL; } giop_recv_buffer_unuse (buf); #if defined ENABLE_HTTP g_free (ior); #endif return retval; } else { return ORBit_object_by_corbaloc (orb, string, ev); } }
static void groupwise_store_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex) { CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (service); CamelStore *store = CAMEL_STORE (service); const char *property_value; CamelGroupwiseStorePrivate *priv = groupwise_store->priv; char *path = NULL; d(printf ("\nin groupwise store constrcut\n")); CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex); if (camel_exception_is_set (ex)) return; if (!(url->host || url->user)) { camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_INVALID, _("Host or user not available in url")); } /*XXX: The number 3 assigned to the list_loaded variable denotes * the number of times the get_folder_info is called during startup. * We are just trying to minimize the call. * This is a dirty hack. But it *WORKS* */ groupwise_store->list_loaded = 3; /*storage path*/ priv->storage_path = camel_session_get_storage_path (session, service, ex); if (!priv->storage_path) return; /*store summary*/ path = g_alloca (strlen (priv->storage_path) + 32); sprintf (path, "%s/.summary", priv->storage_path); groupwise_store->summary = camel_groupwise_store_summary_new (); camel_store_summary_set_filename ((CamelStoreSummary *)groupwise_store->summary, path); camel_store_summary_touch ((CamelStoreSummary *)groupwise_store->summary); camel_store_summary_load ((CamelStoreSummary *) groupwise_store->summary); /*host and user*/ priv->server_name = g_strdup (url->host); priv->user = g_strdup (url->user); /*base url*/ priv->base_url = camel_url_to_string (service->url, (CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS | CAMEL_URL_HIDE_AUTH) ); /*soap port*/ property_value = camel_url_get_param (url, "soap_port"); if (property_value == NULL) priv->port = g_strdup ("7191"); else if(strlen(property_value) == 0) priv->port = g_strdup ("7191"); else priv->port = g_strdup (property_value); /*filter*/ if (camel_url_get_param (url, "filter")) store->flags |= CAMEL_STORE_FILTER_INBOX; /*Hash Table*/ priv->id_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->name_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->parent_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /*ssl*/ priv->use_ssl = g_strdup (camel_url_get_param (url, "use_ssl")); store->flags &= ~CAMEL_STORE_VJUNK; store->flags &= ~CAMEL_STORE_VTRASH; }
int main (int argc, char *argv[]) { guint seed32, *seedp = NULL; gboolean ccounters = FALSE, use_memchunks = FALSE; guint n_threads = 1; const gchar *mode = "slab allocator + magazine cache", *emode = " "; if (argc > 1) n_threads = g_ascii_strtoull (argv[1], NULL, 10); if (argc > 2) { guint i, l = strlen (argv[2]); for (i = 0; i < l; i++) switch (argv[2][i]) { case 'G': /* GLib mode */ g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, FALSE); g_slice_set_config (G_SLICE_CONFIG_BYPASS_MAGAZINES, FALSE); mode = "slab allocator + magazine cache"; break; case 'S': /* slab mode */ g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, FALSE); g_slice_set_config (G_SLICE_CONFIG_BYPASS_MAGAZINES, TRUE); mode = "slab allocator"; break; case 'M': /* malloc mode */ g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE); mode = "system malloc"; break; case 'O': /* old memchunks */ use_memchunks = TRUE; mode = "old memchunks"; break; case 'f': /* eager freeing */ g_slice_set_config (G_SLICE_CONFIG_WORKING_SET_MSECS, 0); clean_memchunks = TRUE; emode = " with eager freeing"; break; case 'c': /* print contention counters */ ccounters = TRUE; break; case '~': want_corruption = TRUE; /* force occasional corruption */ break; default: usage(); return 1; } } if (argc > 3) prime_size = g_ascii_strtoull (argv[3], NULL, 10); if (argc > 4) { seed32 = g_ascii_strtoull (argv[4], NULL, 10); seedp = &seed32; } g_thread_init (NULL); if (argc <= 1) usage(); { gchar strseed[64] = "<random>"; GThread **threads; guint i; if (seedp) g_snprintf (strseed, 64, "%u", *seedp); g_print ("Starting %d threads allocating random blocks <= %u bytes with seed=%s using %s%s\n", n_threads, prime_size, strseed, mode, emode); threads = g_alloca (sizeof(GThread*) * n_threads); if (!use_memchunks) for (i = 0; i < n_threads; i++) threads[i] = g_thread_create (test_sliced_mem_thread, seedp, TRUE, NULL); else { for (i = 0; i < n_threads; i++) threads[i] = g_thread_create (test_memchunk_thread, seedp, TRUE, NULL); } for (i = 0; i < n_threads; i++) g_thread_join (threads[i]); if (ccounters) { guint n, n_chunks = g_slice_get_config (G_SLICE_CONFIG_CHUNK_SIZES); g_print (" ChunkSize | MagazineSize | Contention\n"); for (i = 0; i < n_chunks; i++) { gint64 *vals = g_slice_get_config_state (G_SLICE_CONFIG_CONTENTION_COUNTER, i, &n); g_print (" %9" G_GINT64_FORMAT " | %9" G_GINT64_FORMAT " | %9" G_GINT64_FORMAT "\n", vals[0], vals[2], vals[1]); g_free (vals); } } else g_print ("Done.\n"); return 0; } }
static gboolean _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline, unsigned long pipelines_difference) { CoglPipelineShaderState *shader_state; _COGL_GET_CONTEXT (ctx, FALSE); shader_state = get_shader_state (pipeline); if (shader_state->source) { const char *source_strings[2]; GLint lengths[2]; GLint compile_status; GLuint shader; int n_layers; COGL_STATIC_COUNTER (vertend_glsl_compile_counter, "glsl vertex compile counter", "Increments each time a new GLSL " "vertex shader is compiled", 0 /* no application private data */); COGL_COUNTER_INC (_cogl_uprof_context, vertend_glsl_compile_counter); g_string_append (shader_state->source, " cogl_position_out = " "cogl_modelview_projection_matrix * " "cogl_position_in;\n" " cogl_color_out = cogl_color_in;\n" "}\n"); GE_RET( shader, ctx, glCreateShader (GL_VERTEX_SHADER) ); lengths[0] = shader_state->header->len; source_strings[0] = shader_state->header->str; lengths[1] = shader_state->source->len; source_strings[1] = shader_state->source->str; n_layers = cogl_pipeline_get_n_layers (pipeline); _cogl_shader_set_source_with_boilerplate (shader, GL_VERTEX_SHADER, n_layers, 2, /* count */ source_strings, lengths); GE( ctx, glCompileShader (shader) ); GE( ctx, glGetShaderiv (shader, GL_COMPILE_STATUS, &compile_status) ); if (!compile_status) { GLint len = 0; char *shader_log; GE( ctx, glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &len) ); shader_log = g_alloca (len); GE( ctx, glGetShaderInfoLog (shader, len, &len, shader_log) ); g_warning ("Shader compilation failed:\n%s", shader_log); } shader_state->header = NULL; shader_state->source = NULL; shader_state->gl_shader = shader; } return TRUE; }
static gpointer test_memchunk_thread (gpointer data) { GMemChunk **memchunks; guint i, j; guint8 **ps; guint *ss; guint32 rand_accu = 2147483563; /* initialize random numbers */ if (data) rand_accu = *(guint32*) data; else { GTimeVal rand_tv; g_get_current_time (&rand_tv); rand_accu = rand_tv.tv_usec + (rand_tv.tv_sec << 16); } /* prepare for memchunk creation */ memchunks = g_alloca (sizeof (memchunks[0]) * prime_size); memset (memchunks, 0, sizeof (memchunks[0]) * prime_size); ps = g_new (guint8*, number_of_blocks); ss = g_new (guint, number_of_blocks); /* create number_of_blocks random sizes */ for (i = 0; i < number_of_blocks; i++) ss[i] = quick_rand32() % prime_size; /* allocate number_of_blocks blocks */ for (i = 0; i < number_of_blocks; i++) ps[i] = memchunk_alloc (&memchunks[ss[i]], ss[i]); for (j = 0; j < number_of_repetitions; j++) { /* free number_of_blocks/2 blocks */ for (i = 0; i < number_of_blocks; i += 2) memchunk_free (memchunks[ss[i]], ps[i]); /* allocate number_of_blocks/2 blocks with new sizes */ for (i = 0; i < number_of_blocks; i += 2) { ss[i] = quick_rand32() % prime_size; ps[i] = memchunk_alloc (&memchunks[ss[i]], ss[i]); } } /* free number_of_blocks blocks */ for (i = 0; i < number_of_blocks; i++) memchunk_free (memchunks[ss[i]], ps[i]); /* alloc and free many equally sized chunks in a row */ for (i = 0; i < number_of_repetitions; i++) { guint sz = quick_rand32() % prime_size; guint k = number_of_blocks / 100; for (j = 0; j < k; j++) ps[j] = memchunk_alloc (&memchunks[sz], sz); for (j = 0; j < k; j++) memchunk_free (memchunks[sz], ps[j]); } /* cleanout memchunks */ for (i = 0; i < prime_size; i++) if (memchunks[i]) old_mem_chunk_destroy (memchunks[i]); g_free (ps); g_free (ss); return NULL; }
static gboolean groupwise_store_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, GError **error) { CamelServiceClass *service_class; CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (service); CamelStore *store = CAMEL_STORE (service); const gchar *property_value; CamelGroupwiseStorePrivate *priv = groupwise_store->priv; gchar *path = NULL; d(printf ("\nin groupwise store constrcut\n")); /* Chain up to parent's construct() method. */ service_class = CAMEL_SERVICE_CLASS (camel_groupwise_store_parent_class); if (!service_class->construct (service, session, provider, url, error)) return FALSE; if (!(url->host || url->user)) { g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID, _("Host or user not available in url")); } /*storage path*/ priv->storage_path = camel_session_get_storage_path (session, service, error); if (!priv->storage_path) return FALSE; /*store summary*/ path = g_alloca (strlen (priv->storage_path) + 32); sprintf (path, "%s/.summary", priv->storage_path); groupwise_store->summary = camel_groupwise_store_summary_new (); camel_store_summary_set_filename ((CamelStoreSummary *)groupwise_store->summary, path); camel_store_summary_touch ((CamelStoreSummary *)groupwise_store->summary); camel_store_summary_load ((CamelStoreSummary *) groupwise_store->summary); /*host and user*/ priv->server_name = g_strdup (url->host); priv->user = g_strdup (url->user); /*base url*/ priv->base_url = camel_url_to_string (service->url, (CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS | CAMEL_URL_HIDE_AUTH) ); /*soap port*/ property_value = camel_url_get_param (url, "soap_port"); if (property_value == NULL) priv->port = g_strdup ("7191"); else if (strlen (property_value) == 0) priv->port = g_strdup ("7191"); else priv->port = g_strdup (property_value); /*filter*/ if (camel_url_get_param (url, "filter")) store->flags |= CAMEL_STORE_FILTER_INBOX; /*Hash Table*/ priv->id_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->name_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); priv->parent_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /*ssl*/ priv->use_ssl = g_strdup (camel_url_get_param (url, "use_ssl")); store->flags &= ~CAMEL_STORE_VJUNK; store->flags &= ~CAMEL_STORE_VTRASH; return TRUE; }
static gboolean dx_dinput_event_dispatch (GSource *source, GSourceFunc callback, gpointer user_data) { ControllerDXDInput * const input = ((DXDInputSource *) source)->controller; GimpController *controller = &input->parent_instance; const DIDATAFORMAT * const format = input->format; const DIOBJECTDATAFORMAT *rgodf = format->rgodf; guchar *data; gint i; GimpControllerEvent cevent = { 0, }; data = g_alloca (format->dwDataSize); if (FAILED (IDirectInputDevice8_GetDeviceState (input->didevice8, format->dwDataSize, data))) { return TRUE; } g_object_ref (controller); for (i = 0; i < input->num_buttons; i++) { if (input->prevdata[rgodf->dwOfs] != data[rgodf->dwOfs]) { if (data[rgodf->dwOfs] & 0x80) { /* Click event, compatibility with Linux Input */ cevent.any.type = GIMP_CONTROLLER_EVENT_TRIGGER; cevent.any.source = controller; cevent.any.event_id = i*NUM_EVENTS_PER_BUTTON; gimp_controller_event (controller, &cevent); /* Press event */ cevent.any.event_id = i*NUM_EVENTS_PER_BUTTON + 1; gimp_controller_event (controller, &cevent); } else { /* Release event */ cevent.any.type = GIMP_CONTROLLER_EVENT_TRIGGER; cevent.any.source = controller; cevent.any.event_id = i*NUM_EVENTS_PER_BUTTON + 2; gimp_controller_event (controller, &cevent); } } rgodf++; } for (i = 0; i < input->num_axes; i++) { LONG *prev = (LONG *)(input->prevdata+rgodf->dwOfs); LONG *curr = (LONG *)(data+rgodf->dwOfs); if (ABS (*prev - *curr) > 1) { cevent.any.type = GIMP_CONTROLLER_EVENT_VALUE; cevent.any.source = controller; cevent.any.event_id = input->num_button_events + i*NUM_EVENTS_PER_AXIS; g_value_init (&cevent.value.value, G_TYPE_DOUBLE); if (*curr - *prev < 0) { g_value_set_double (&cevent.value.value, *prev - *curr); } else { cevent.any.event_id++; g_value_set_double (&cevent.value.value, *curr - *prev); } gimp_controller_event (controller, &cevent); g_value_unset (&cevent.value.value); } else *curr = *prev; rgodf++; } for (i = 0; i < input->num_sliders; i++) { LONG *prev = (LONG *)(input->prevdata+rgodf->dwOfs); LONG *curr = (LONG *)(data+rgodf->dwOfs); if (ABS (*prev - *curr) > 1) { cevent.any.type = GIMP_CONTROLLER_EVENT_VALUE; cevent.any.source = controller; cevent.any.event_id = input->num_button_events + input->num_axis_events + i*NUM_EVENTS_PER_SLIDER; g_value_init (&cevent.value.value, G_TYPE_DOUBLE); if (*curr - *prev < 0) { g_value_set_double (&cevent.value.value, *prev - *curr); } else { cevent.any.event_id++; g_value_set_double (&cevent.value.value, *curr - *prev); } gimp_controller_event (controller, &cevent); g_value_unset (&cevent.value.value); } else *curr = *prev; rgodf++; } for (i = 0; i < input->num_povs; i++) { LONG prev = *((LONG *)(input->prevdata+rgodf->dwOfs)); LONG curr = *((LONG *)(data+rgodf->dwOfs)); double prevx, prevy; double currx, curry; if (prev != curr) { if (prev == -1) { prevx = 0.; prevy = 0.; } else { prevx = sin (prev/36000.*2.*G_PI); prevy = cos (prev/36000.*2.*G_PI); } if (curr == -1) { currx = 0.; curry = 0.; } else { currx = sin (curr/36000.*2.*G_PI); curry = cos (curr/36000.*2.*G_PI); } cevent.any.type = GIMP_CONTROLLER_EVENT_VALUE; cevent.any.source = controller; cevent.any.event_id = input->num_button_events + input->num_axis_events + input->num_slider_events + i*NUM_EVENTS_PER_POV; g_value_init (&cevent.value.value, G_TYPE_DOUBLE); g_value_set_double (&cevent.value.value, currx - prevx); gimp_controller_event (controller, &cevent); cevent.any.event_id++; g_value_set_double (&cevent.value.value, curry - prevy); gimp_controller_event (controller, &cevent); g_value_unset (&cevent.value.value); if (curr == -1) { cevent.any.type = GIMP_CONTROLLER_EVENT_TRIGGER; cevent.any.event_id++; gimp_controller_event (controller, &cevent); } } rgodf++; } g_assert (rgodf == format->rgodf + format->dwNumObjs); memmove (input->prevdata, data, format->dwDataSize); g_object_unref (controller); return TRUE; }
/* Copied largely from goad.c, goad_server_activate_exe() */ static CORBA_Object od_server_activate_exe (MateComponent_ServerInfo *si, ODActivationInfo *actinfo, CORBA_Object od_obj, const MateComponent_ActivationEnvironment *environment, CORBA_Environment *ev) { char **args; char *extra_arg, *ctmp, *ctmp2; int fd_arg; int i; char *iorstr, *iid; CORBA_Object retval; /* Munge the args */ args = g_alloca (36 * sizeof (char *)); #ifndef G_OS_WIN32 /* Split location_info into executable pathname and command-line * arguments. */ for (i = 0, ctmp = ctmp2 = si->location_info; i < 32; i++) { while (*ctmp2 && !g_ascii_isspace ((guchar) *ctmp2)) ctmp2++; if (!*ctmp2) break; args[i] = g_alloca (ctmp2 - ctmp + 1); strncpy (args[i], ctmp, ctmp2 - ctmp); args[i][ctmp2 - ctmp] = '\0'; ctmp = ctmp2; while (*ctmp2 && g_ascii_isspace ((guchar) *ctmp2)) ctmp2++; if (!*ctmp2) break; ctmp = ctmp2; } if (!g_ascii_isspace ((guchar) *ctmp) && i < 32) args[i++] = ctmp; if (i > 1) g_warning ("Passing command-line arguments in .server files is deprecated: \"%s\"", si->location_info); #else /* We don't support command-line arguments in the location on * Win32, as the executable pathname might well contain spaces * itself (C:\Program Files\Evolution 2.6.2\libexec\...). * location_info is just the executable's pathname. */ args[0] = g_alloca (strlen (si->location_info) + 1); strcpy (args[0], si->location_info); i = 1; #endif extra_arg = g_alloca (strlen (si->iid) + sizeof ("--oaf-activate-iid=")); args[i++] = extra_arg; sprintf (extra_arg, "--oaf-activate-iid=%s", si->iid); fd_arg = i; extra_arg = g_alloca (sizeof ("--oaf-ior-fd=") + 10); args[i++] = "--oaf-ior-fd=%d"; iorstr = CORBA_ORB_object_to_string ( matecomponent_activation_orb_get (), od_obj, ev); if (ev->_major != CORBA_NO_EXCEPTION) iorstr = NULL; if(actinfo->flags & MateComponent_ACTIVATION_FLAG_PRIVATE) { extra_arg = g_alloca (sizeof ("--oaf-private")); args[i++] = extra_arg; g_snprintf (extra_arg, sizeof ("--oaf-private"), "--oaf-private"); } args[i] = NULL; iid = g_strdup (si->iid); /* Here comes the too clever by 1/2 bit: * we drop the (recursive) 'server_lock' - so we * can get other threads re-entering / doing activations * here. cf. od_server_activate_factory */ { ServerLockState state; state = server_lock_drop (); /* * We set the process group of activated servers to our process group; * this allows people to destroy all OAF servers along with oafd * if necessary */ retval = matecomponent_activation_server_by_forking ( (const char **) args, TRUE, fd_arg, environment, iorstr, iid, FALSE, matecomponent_object_directory_re_check_fn, actinfo, ev); server_lock_resume (state); } g_free (iid); CORBA_free (iorstr); return retval; }
/** * gimp_scan_convert_render_full: * @sc: a #GimpScanConvert context * @buffer: the #GeglBuffer to render to * @off_x: horizontal offset into the @buffer * @off_y: vertical offset into the @buffer * @replace: if true the original content of the @buffer gets estroyed * @antialias: if true the rendering happens antialiased * @value: value to use for covered pixels * * This function renders the area described by the path to the * @buffer, taking the offset @off_x and @off_y in the buffer into * account. The rendering can happen antialiased and be rendered on * top of existing content or replacing it completely. The @value * specifies the opacity value to be used for the objects in the @sc. * * You cannot add additional polygons after this command. */ void gimp_scan_convert_render_full (GimpScanConvert *sc, GeglBuffer *buffer, gint off_x, gint off_y, gboolean replace, gboolean antialias, gdouble value) { const Babl *format; GeglBufferIterator *iter; GeglRectangle *roi; cairo_t *cr; cairo_surface_t *surface; cairo_path_t path; gint bpp; gint x, y; gint width, height; g_return_if_fail (sc != NULL); g_return_if_fail (GEGL_IS_BUFFER (buffer)); x = 0; y = 0; width = gegl_buffer_get_width (buffer); height = gegl_buffer_get_height (buffer); if (sc->clip && ! gimp_rectangle_intersect (x, y, width, height, sc->clip_x, sc->clip_y, sc->clip_w, sc->clip_h, &x, &y, &width, &height)) return; path.status = CAIRO_STATUS_SUCCESS; path.data = (cairo_path_data_t *) sc->path_data->data; path.num_data = sc->path_data->len; format = babl_format ("Y u8"); bpp = babl_format_get_bytes_per_pixel (format); iter = gegl_buffer_iterator_new (buffer, NULL, 0, format, GEGL_BUFFER_READWRITE, GEGL_ABYSS_NONE); roi = &iter->roi[0]; while (gegl_buffer_iterator_next (iter)) { guchar *data = iter->data[0]; guchar *tmp_buf = NULL; const gint stride = cairo_format_stride_for_width (CAIRO_FORMAT_A8, roi->width); /* cairo rowstrides are always multiples of 4, whereas * maskPR.rowstride can be anything, so to be able to create an * image surface, we maybe have to create our own temporary * buffer */ if (roi->width * bpp != stride) { tmp_buf = g_alloca (stride * roi->height); if (! replace) { const guchar *src = data; guchar *dest = tmp_buf; gint i; for (i = 0; i < roi->height; i++) { memcpy (dest, src, roi->width * bpp); src += roi->width * bpp; dest += stride; } } } surface = cairo_image_surface_create_for_data (tmp_buf ? tmp_buf : data, CAIRO_FORMAT_A8, roi->width, roi->height, stride); cairo_surface_set_device_offset (surface, -off_x - roi->x, -off_y - roi->y); cr = cairo_create (surface); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); if (replace) { cairo_set_source_rgba (cr, 0, 0, 0, 0); cairo_paint (cr); } cairo_set_source_rgba (cr, 0, 0, 0, value); cairo_append_path (cr, &path); cairo_set_antialias (cr, antialias ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE); cairo_set_miter_limit (cr, sc->miter); if (sc->do_stroke) { cairo_set_line_cap (cr, sc->cap == GIMP_CAP_BUTT ? CAIRO_LINE_CAP_BUTT : sc->cap == GIMP_CAP_ROUND ? CAIRO_LINE_CAP_ROUND : CAIRO_LINE_CAP_SQUARE); cairo_set_line_join (cr, sc->join == GIMP_JOIN_MITER ? CAIRO_LINE_JOIN_MITER : sc->join == GIMP_JOIN_ROUND ? CAIRO_LINE_JOIN_ROUND : CAIRO_LINE_JOIN_BEVEL); cairo_set_line_width (cr, sc->width); if (sc->dash_info) cairo_set_dash (cr, (double *) sc->dash_info->data, sc->dash_info->len, sc->dash_offset); cairo_scale (cr, 1.0, sc->ratio_xy); cairo_stroke (cr); } else { cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_fill (cr); } cairo_destroy (cr); cairo_surface_destroy (surface); if (tmp_buf) { const guchar *src = tmp_buf; guchar *dest = data; gint i; for (i = 0; i < roi->height; i++) { memcpy (dest, src, roi->width * bpp); src += stride; dest += roi->width * bpp; } } } }
void cogl_debug_matrix_entry_print (CoglMatrixEntry *entry) { int depth; CoglMatrixEntry *e; CoglMatrixEntry **children; int i; for (depth = 0, e = entry; e; e = e->parent) depth++; children = g_alloca (sizeof (CoglMatrixEntry) * depth); for (i = depth - 1, e = entry; i >= 0 && e; i--, e = e->parent) { children[i] = e; } g_print ("MatrixEntry %p =\n", entry); for (i = 0; i < depth; i++) { entry = children[i]; switch (entry->op) { case COGL_MATRIX_OP_LOAD_IDENTITY: g_print (" LOAD IDENTITY\n"); continue; case COGL_MATRIX_OP_TRANSLATE: { CoglMatrixEntryTranslate *translate = (CoglMatrixEntryTranslate *)entry; g_print (" TRANSLATE X=%f Y=%f Z=%f\n", translate->x, translate->y, translate->z); continue; } case COGL_MATRIX_OP_ROTATE: { CoglMatrixEntryRotate *rotate = (CoglMatrixEntryRotate *)entry; g_print (" ROTATE ANGLE=%f X=%f Y=%f Z=%f\n", rotate->angle, rotate->x, rotate->y, rotate->z); continue; } case COGL_MATRIX_OP_ROTATE_QUATERNION: { CoglMatrixEntryRotateQuaternion *rotate = (CoglMatrixEntryRotateQuaternion *)entry; g_print (" ROTATE QUATERNION w=%f x=%f y=%f z=%f\n", rotate->values[0], rotate->values[1], rotate->values[2], rotate->values[3]); continue; } case COGL_MATRIX_OP_ROTATE_EULER: { CoglMatrixEntryRotateEuler *rotate = (CoglMatrixEntryRotateEuler *)entry; g_print (" ROTATE EULER heading=%f pitch=%f roll=%f\n", rotate->heading, rotate->pitch, rotate->roll); continue; } case COGL_MATRIX_OP_SCALE: { CoglMatrixEntryScale *scale = (CoglMatrixEntryScale *)entry; g_print (" SCALE X=%f Y=%f Z=%f\n", scale->x, scale->y, scale->z); continue; } case COGL_MATRIX_OP_MULTIPLY: { CoglMatrixEntryMultiply *mult = (CoglMatrixEntryMultiply *)entry; g_print (" MULT:\n"); _cogl_matrix_prefix_print (" ", mult->matrix); continue; } case COGL_MATRIX_OP_LOAD: { CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)entry; g_print (" LOAD:\n"); _cogl_matrix_prefix_print (" ", load->matrix); continue; } case COGL_MATRIX_OP_SAVE: g_print (" SAVE\n"); } } }
static void log_proto_buffered_server_apply_state(LogProtoBufferedServer *self, PersistEntryHandle handle, const gchar *persist_name) { struct stat st; gint64 ofs = 0; LogProtoBufferedServerState *state; gint fd; fd = self->super.transport->fd; self->persist_handle = handle; if (fstat(fd, &st) < 0) return; state = log_proto_buffered_server_get_state(self); if (!self->buffer) { self->buffer = g_malloc(state->buffer_size); } state->pending_buffer_end = 0; if (state->file_inode && state->file_inode == st.st_ino && state->file_size <= st.st_size && state->raw_stream_pos <= st.st_size) { ofs = state->raw_stream_pos; lseek(fd, ofs, SEEK_SET); } else { if (state->file_inode) { /* the stored state does not match the current file */ msg_notice("The current log file has a mismatching size/inode information, restarting from the beginning", evt_tag_str("state", persist_name), evt_tag_int("stored_inode", state->file_inode), evt_tag_int("cur_file_inode", st.st_ino), evt_tag_int("stored_size", state->file_size), evt_tag_int("cur_file_size", st.st_size), evt_tag_int("raw_stream_pos", state->raw_stream_pos), NULL); } goto error; } if (state->raw_buffer_size) { gssize rc; guchar *raw_buffer; if (!self->super.options->encoding) { /* no conversion, we read directly into our buffer */ if (state->raw_buffer_size > state->buffer_size) { msg_notice("Invalid LogProtoBufferedServerState.raw_buffer_size, larger than buffer_size and no encoding is set, restarting from the beginning", evt_tag_str("state", persist_name), evt_tag_int("raw_buffer_size", state->raw_buffer_size), evt_tag_int("buffer_size", state->buffer_size), evt_tag_int("init_buffer_size", self->super.options->init_buffer_size), NULL); goto error; } raw_buffer = self->buffer; } else { if (state->raw_buffer_size > self->super.options->max_buffer_size) { msg_notice("Invalid LogProtoBufferedServerState.raw_buffer_size, larger than max_buffer_size, restarting from the beginning", evt_tag_str("state", persist_name), evt_tag_int("raw_buffer_size", state->raw_buffer_size), evt_tag_int("init_buffer_size", self->super.options->init_buffer_size), evt_tag_int("max_buffer_size", self->super.options->max_buffer_size), NULL); goto error; } raw_buffer = g_alloca(state->raw_buffer_size); } rc = log_transport_read(self->super.transport, raw_buffer, state->raw_buffer_size, NULL); if (rc != state->raw_buffer_size) { msg_notice("Error re-reading buffer contents of the file to be continued, restarting from the beginning", evt_tag_str("state", persist_name), NULL); goto error; } state->pending_buffer_end = 0; if (self->super.options->encoding) { if (!log_proto_buffered_server_convert_from_raw(self, raw_buffer, rc)) { msg_notice("Error re-converting buffer contents of the file to be continued, restarting from the beginning", evt_tag_str("state", persist_name), NULL); goto error; } } else { state->pending_buffer_end += rc; } if (state->buffer_pos > state->pending_buffer_end) { msg_notice("Converted buffer contents is smaller than the current buffer position, starting from the beginning of the buffer, some lines may be duplicated", evt_tag_str("state", persist_name), NULL); state->buffer_pos = state->pending_buffer_pos = 0; } } else { /* although we do have buffer position information, but the * complete contents of the buffer is already processed, instead * of reading and then dropping it, position the file after the * indicated block */ state->raw_stream_pos += state->raw_buffer_size; ofs = state->raw_stream_pos; state->raw_buffer_size = 0; state->buffer_pos = state->pending_buffer_end = 0; lseek(fd, state->raw_stream_pos, SEEK_SET); } goto exit; error: ofs = 0; state->buffer_pos = 0; state->pending_buffer_end = 0; state->__deprecated_buffer_cached_eol = 0; state->raw_stream_pos = 0; state->raw_buffer_size = 0; state->raw_buffer_leftover_size = 0; lseek(fd, 0, SEEK_SET); exit: state->file_inode = st.st_ino; state->file_size = st.st_size; state->raw_stream_pos = ofs; state->pending_buffer_pos = state->buffer_pos; state->pending_raw_stream_pos = state->raw_stream_pos; state->pending_raw_buffer_size = state->raw_buffer_size; state->__deprecated_buffer_cached_eol = 0; state = NULL; log_proto_buffered_server_put_state(self); }
void e_mail_formatter_format_header (EMailFormatter *formatter, GString *buffer, const gchar *header_name, const gchar *header_value, guint32 flags, const gchar *charset) { gchar *canon_name, *buf, *value = NULL; const gchar *label, *txt; gboolean addrspec = FALSE; gchar *str_field = NULL; gint i; g_return_if_fail (E_IS_MAIL_FORMATTER (formatter)); g_return_if_fail (buffer != NULL); g_return_if_fail (header_name != NULL); g_return_if_fail (header_value != NULL); canon_name = g_alloca (strlen (header_name) + 1); strcpy (canon_name, header_name); e_mail_formatter_canon_header_name (canon_name); for (i = 0; addrspec_hdrs[i]; i++) { if (g_str_equal (canon_name, addrspec_hdrs[i])) { addrspec = TRUE; break; } } label = _(canon_name); if (addrspec) { struct _camel_header_address *addrs; GString *html; gchar *img; gchar *charset; charset = e_mail_formatter_dup_charset (formatter); if (charset == NULL) charset = e_mail_formatter_dup_default_charset (formatter); buf = camel_header_unfold (header_value); addrs = camel_header_address_decode (buf, charset); if (addrs == NULL) { g_free (charset); g_free (buf); return; } g_free (charset); g_free (buf); html = g_string_new (""); img = e_mail_formatter_format_address ( formatter, html, addrs, label, (flags & E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS), !(flags & E_MAIL_FORMATTER_HEADER_FLAG_NOELIPSIZE)); if (img != NULL) { str_field = g_strdup_printf ("%s: %s", label, img); label = str_field; flags |= E_MAIL_FORMATTER_HEADER_FLAG_NODEC; g_free (img); } camel_header_address_list_clear (&addrs); txt = value = html->str; g_string_free (html, FALSE); flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML; flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Subject")) { buf = camel_header_unfold (header_value); txt = value = camel_header_decode_string (buf, charset); g_free (buf); flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "X-Evolution-Mailer")) { /* pseudo-header */ label = _("Mailer"); txt = value = camel_header_format_ctext (header_value, charset); flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Date") || g_str_equal (canon_name, "Resent-Date")) { CamelMimeFilterToHTMLFlags text_format_flags; gint msg_offset, local_tz; time_t msg_date; struct tm local; gchar *html; gboolean hide_real_date; hide_real_date = !e_mail_formatter_get_show_real_date (formatter); txt = header_value; while (*txt == ' ' || *txt == '\t') txt++; text_format_flags = e_mail_formatter_get_text_format_flags (formatter); html = camel_text_to_html (txt, text_format_flags, 0); msg_date = camel_header_decode_date (txt, &msg_offset); e_localtime_with_offset (msg_date, &local, &local_tz); /* Convert message offset to minutes (e.g. -0400 --> -240) */ msg_offset = ((msg_offset / 100) * 60) + (msg_offset % 100); /* Turn into offset from localtime, not UTC */ msg_offset -= local_tz / 60; /* value will be freed at the end */ if (!hide_real_date && !msg_offset) { /* No timezone difference; just * show the real Date: header. */ txt = value = html; } else { gchar *date_str; date_str = e_datetime_format_format ( "mail", "header", DTFormatKindDateTime, msg_date); if (hide_real_date) { /* Show only the local-formatted date, losing * all timezone information like Outlook does. * Should we attempt to show it somehow? */ txt = value = date_str; } else { txt = value = g_strdup_printf ( "%s (<I>%s</I>)", html, date_str); g_free (date_str); } g_free (html); } flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML; flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Newsgroups")) { struct _camel_header_newsgroup *ng, *scan; GString *html; buf = camel_header_unfold (header_value); if (!(ng = camel_header_newsgroups_decode (buf))) { g_free (buf); return; } g_free (buf); html = g_string_new (""); scan = ng; while (scan) { if (flags & E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS) g_string_append_printf ( html, "%s", scan->newsgroup); else g_string_append_printf ( html, "<a href=\"news:%s\">%s</a>", scan->newsgroup, scan->newsgroup); scan = scan->next; if (scan) g_string_append_printf (html, ", "); } camel_header_newsgroups_free (ng); txt = html->str; g_string_free (html, FALSE); flags |= E_MAIL_FORMATTER_HEADER_FLAG_HTML; flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD; } else if (g_str_equal (canon_name, "Received") || g_str_has_prefix (canon_name, "X-")) { /* don't unfold Received nor extension headers */ txt = value = camel_header_decode_string (header_value, charset); } else { /* don't unfold Received nor extension headers */ buf = camel_header_unfold (header_value); txt = value = camel_header_decode_string (buf, charset); g_free (buf); } e_mail_formatter_format_text_header ( formatter, buffer, label, txt, flags); g_free (value); g_free (str_field); }
static GIOStatus log_proto_buffered_server_fetch_into_buffer(LogProtoBufferedServer *self) { guchar *raw_buffer = NULL; gint avail; gint rc; LogProtoBufferedServerState *state = log_proto_buffered_server_get_state(self); GIOStatus result = G_IO_STATUS_NORMAL; if (G_UNLIKELY(!self->buffer)) log_proto_buffered_server_allocate_buffer(self, state); if (self->convert == (GIConv) -1) { /* no conversion, we read directly into our buffer */ raw_buffer = self->buffer + state->pending_buffer_end; avail = state->buffer_size - state->pending_buffer_end; } else { /* if conversion is needed, we first read into an on-stack * buffer, and then convert it into our internal buffer */ raw_buffer = g_alloca(self->super.options->init_buffer_size + state->raw_buffer_leftover_size); memcpy(raw_buffer, state->raw_buffer_leftover, state->raw_buffer_leftover_size); avail = self->super.options->init_buffer_size; } if (avail == 0) goto exit; rc = log_proto_buffered_server_read_data(self, raw_buffer + state->raw_buffer_leftover_size, avail); if (rc < 0) { if (errno == EAGAIN) { /* ok we don't have any more data to read, return to main poll loop */ result = G_IO_STATUS_AGAIN; } else { /* an error occurred while reading */ msg_error("I/O error occurred while reading", evt_tag_int(EVT_TAG_FD, self->super.transport->fd), evt_tag_errno(EVT_TAG_OSERROR, errno), NULL); result = G_IO_STATUS_ERROR; } } else if (rc == 0) { /* EOF read */ msg_verbose("EOF occurred while reading", evt_tag_int(EVT_TAG_FD, self->super.transport->fd), NULL); if (state->raw_buffer_leftover_size > 0) { msg_error("EOF read on a channel with leftovers from previous character conversion, dropping input", NULL); state->pending_buffer_pos = state->pending_buffer_end = 0; } result = G_IO_STATUS_EOF; } else { state->pending_raw_buffer_size += rc; rc += state->raw_buffer_leftover_size; state->raw_buffer_leftover_size = 0; if (self->convert == (GIConv) -1) { state->pending_buffer_end += rc; } else if (!log_proto_buffered_server_convert_from_raw(self, raw_buffer, rc)) { result = G_IO_STATUS_ERROR; } } exit: log_proto_buffered_server_put_state(self); return result; }
char * camel_nntp_store_summary_path_to_full (CamelNNTPStoreSummary *s, const char *path, char dir_sep) { char *full, *f; guint32 c, v = 0; const char *p; int state=0; char *subpath, *last = NULL; CamelStoreInfo *si; /* check to see if we have a subpath of path already defined */ subpath = g_alloca (strlen (path) + 1); strcpy (subpath, path); do { si = camel_store_summary_path ((CamelStoreSummary *) s, subpath); if (si == NULL) { last = strrchr (subpath, '/'); if (last) *last = 0; } } while (si == NULL && last); /* path is already present, use the raw version we have */ if (si && strlen (subpath) == strlen (path)) { f = g_strdup (camel_nntp_store_info_full_name (s, si)); camel_store_summary_info_free ((CamelStoreSummary *) s, si); return f; } f = full = g_alloca (strlen (path)*2+1); if (si) p = path + strlen (subpath); else p = path; while ((c = camel_utf8_getc ((const unsigned char **) &p))) { switch (state) { case 0: if (c == '%') { state = 1; } else { if (c == '/') c = dir_sep; camel_utf8_putc((unsigned char **) &f, c); } break; case 1: state = 2; v = hexnib (c) << 4; break; case 2: state = 0; v |= hexnib (c); camel_utf8_putc ((unsigned char **) &f, v); break; } } camel_utf8_putc ((unsigned char **) &f, c); /* merge old path part if required */ f = camel_utf8_utf7 (full); if (si) { full = g_strdup_printf ("%s%s", camel_nntp_store_info_full_name (s, si), f); g_free (f); camel_store_summary_info_free ((CamelStoreSummary *) s, si); f = full; } return f; }
gboolean pdb_lang_save_single (PdbLang *lang, PdbFile *file, GError **error) { int n_langs = g_hash_table_size (lang->hash_table); PdbLangSaveData *save_data = g_alloca (sizeof (PdbLangSaveData) * n_langs); int table_pos, end_pos; int i; if (!pdb_file_write_32 (file, n_langs, error)) return FALSE; table_pos = file->pos; /* Seek past the offset table which we'll fill in later */ if (!pdb_file_seek (file, n_langs * 8, SEEK_CUR, error)) return FALSE; for (i = 0; i < n_langs; i++) save_data[i].entry = &g_array_index (lang->languages, PdbLangEntry, i); qsort (save_data, n_langs, sizeof (PdbLangSaveData), pdb_lang_sort_save_data); for (i = 0; i < n_langs; i++) { guint8 *compressed_data; int compressed_len; int write_status; save_data[i].offset = file->pos; if (!pdb_file_write (file, save_data[i].entry->name, strlen (save_data[i].entry->name) + 1, error)) return FALSE; pdb_trie_compress (save_data[i].entry->trie, &compressed_data, &compressed_len); write_status = pdb_file_write (file, compressed_data, compressed_len, error); g_free (compressed_data); if (!write_status) return FALSE; } end_pos = file->pos; if (!pdb_file_seek (file, table_pos, SEEK_SET, error)) return FALSE; for (i = 0; i < n_langs; i++) { PdbLangEntry *entry = save_data[i].entry; int code_len = strlen (entry->code); char code[4]; if (code_len > 3) code_len = 3; memcpy (code, entry->code, code_len); memset (code + code_len, 0, sizeof (code) - code_len); if (!pdb_file_write (file, code, sizeof (code), error) || !pdb_file_write_32 (file, save_data[i].offset, error)) return FALSE; } return pdb_file_seek (file, end_pos, SEEK_SET, error); }