gboolean qq_msgfont_equal(QQMsgFont *a, QQMsgFont *b) { if(a == b){ return TRUE; } if(a == NULL || b == NULL){ return FALSE; } if(!g_string_equal(a -> name, b -> name)){ return FALSE; } if(!g_string_equal(a -> color, b -> color)){ return FALSE; } if(a -> size != b -> size){ return FALSE; } if(a -> style.a != b -> style.a){ return FALSE; } if(a -> style.b != b -> style.b){ return FALSE; } if(a -> style.c != b -> style.c){ return FALSE; } return TRUE; }
GtkBuilder * windowbuilder_get_builder (const gchararray window_name) { GString *window_string = g_string_new (window_name); guint ssize; if (!builders) { error (0, 0, _("Cannot destroy builder: no builders instantiated")); return NULL; } ssize = g_slist_length (builders); for (int pos = 0; pos < ssize; pos++) { windowbuilder_builder *temp_builder = (windowbuilder_builder*) g_slist_nth_data (builders, pos); if (g_string_equal (window_string, temp_builder->window_name)) { return temp_builder->builder; } } return NULL; }
int windowbuilder_destroy_builder (const gchararray window_name) { GString *window_string = g_string_new (window_name); guint ssize = g_slist_length (builders); if (!builders) { error (0, 0, _("Cannot destroy builder: no builders instantiated")); return -1; } for (int pos = 0; pos < ssize; pos++) { windowbuilder_builder *temp_builder = (windowbuilder_builder*) g_slist_nth_data (builders, pos); if (g_string_equal (window_string, temp_builder->window_name)) { GtkBuilder *builder = temp_builder->builder; GtkWidget *toplevel = GTK_WIDGET (gtk_builder_get_object (builder, "toplevel")); builders = g_slist_remove (builders, temp_builder); g_object_unref (builder); gtk_widget_destroy (toplevel); break; } } return TRUE; }
static liAction* lua_handler_create(liServer *srv, liWorker *wrk, liPlugin* p, liValue *val, gpointer userdata) { liValue *v_filename = NULL, *v_options = NULL, *v_args = NULL; lua_config *conf; guint ttl = 0; UNUSED(wrk); UNUSED(userdata); if (LI_VALUE_STRING == li_value_type(val)) { v_filename = val; } else if (LI_VALUE_LIST == li_value_type(val)) { switch (li_value_list_len(val)) { case 3: v_args = li_value_list_at(val, 2); /* fall through */ case 2: v_options = li_value_list_at(val, 1); /* fall through */ case 1: v_filename = li_value_list_at(val, 0); /* fall through */ case 0: break; default: ERROR(srv, "%s", "lua.handler expects at most 3 arguments"); return NULL; } } if (LI_VALUE_STRING != li_value_type(v_filename)) { ERROR(srv, "%s", "lua.handler expects at least a filename, or a filename and some options"); return NULL; } if (NULL != v_options) { if (NULL == (v_options = li_value_to_key_value_list(v_options))) { ERROR(srv, "%s", "lua.handler expects options in a hash/key-value list"); return NULL; } LI_VALUE_FOREACH(entry, v_options) liValue *entryKey = li_value_list_at(entry, 0); liValue *entryValue = li_value_list_at(entry, 1); GString *entryKeyStr; if (LI_VALUE_STRING != li_value_type(entryKey)) { ERROR(srv, "%s", "lua.handler doesn't take default keys"); return NULL; } entryKeyStr = entryKey->data.string; /* keys are either NONE or STRING */ if (g_string_equal(entryKeyStr, &lon_ttl)) { if (LI_VALUE_NUMBER != li_value_type(entryValue) || entryValue->data.number <= 0) { ERROR(srv, "lua.handler option '%s' expects positive integer as parameter", entryKeyStr->str); return NULL; } ttl = entryValue->data.number; } else { ERROR(srv, "unknown option for lua.handler '%s'", entryKeyStr->str); return NULL; } LI_VALUE_END_FOREACH() } conf = lua_config_new(srv, p, li_value_extract_string(v_filename), ttl, li_value_extract(v_args)); return li_action_new_function(lua_handle, NULL, lua_config_free, conf); }
static gboolean vendor_matches(const gchar vendor[MAX_VENDOR_ID_LENGTH], const gchar * vendor_id) { gboolean result; GString * a, * b; /* vendor is not necessarily NUL-terminated. */ a = g_string_new_len((const gchar *) vendor, MAX_VENDOR_ID_LENGTH); b = g_string_new_len((const gchar *) vendor_id, MAX_VENDOR_ID_LENGTH); result = g_string_equal(a, b); g_string_free(a, TRUE); g_string_free(b, TRUE); return result; }
gboolean S52_string_equal(const GString *v, const GString *v2) { #ifdef S52_USE_GLIB2 // on android glid2 can't handle NULL string if (NULL==v || NULL==v2) { PRINTF("S52_string_equal():WARNING: string NULL\n"); return FALSE; } return g_string_equal(v, v2); #else if (v->len == v2->len) { if (0 == memcmp(v->str, v2->str, v->len)) return TRUE; } return FALSE; #endif }
//------------------------------------------------------------------------------ GList *find_sensor_with_name (const gchar *name) { GList *l = sensors ; GString *gname = g_string_new(name) ; while (l != NULL) { if (g_string_equal(gname, ((T_Sensor*)(l->data))->name )) { g_string_free(gname,FALSE) ; return l ; } ; l = g_list_next(l) ; } ; //printf ("find_sensor_with_name : not found\n") ; g_string_free(gname,FALSE) ; //return l ; // l = NULL return NULL ; } ;
/** * compare two GStrings for case-insensitive equality using UTF8 */ gboolean g_string_equal_ci(const GString *a, const GString *b) { char *a_ci, *b_ci; gsize a_ci_len, b_ci_len; gboolean is_equal = FALSE; if (g_string_equal(a, b)) return TRUE; a_ci = g_utf8_casefold(S(a)); a_ci_len = strlen(a_ci); b_ci = g_utf8_casefold(S(b)); b_ci_len = strlen(b_ci); is_equal = strleq(a_ci, a_ci_len, b_ci, b_ci_len); g_free(a_ci); g_free(b_ci); return is_equal; }
liThrottlePool *li_throttle_pool_new(liServer *srv, liThrottlePoolType type, gpointer param, guint rate) { liThrottlePool *pool; guint i; g_mutex_lock(srv->action_mutex); if (type == LI_THROTTLE_POOL_NAME) { /* named pool */ GString *name = param; /* check if we already have a pool with that name */ for (i = 0; i < srv->throttle_pools->len; i++) { pool = g_array_index(srv->throttle_pools, liThrottlePool*, i); if (g_string_equal(pool->data.name, name)) { g_atomic_int_inc(&pool->refcount); g_mutex_unlock(srv->action_mutex); g_string_free(name, TRUE); return pool; } } } else {
static memcached_ctx* mc_ctx_parse(liServer *srv, liPlugin *p, liValue *config) { memcached_ctx *ctx; memcached_config *mconf = p->data; GString def_server = li_const_gstring(CONST_STR_LEN("127.0.0.1:11211")); if (config && config->type != LI_VALUE_HASH) { ERROR(srv, "%s", "memcache expects an optional hash of options"); return NULL; } ctx = g_slice_new0(memcached_ctx); ctx->srv = srv; ctx->refcount = 1; ctx->p = p; ctx->addr = li_sockaddr_from_string(&def_server, 11211); ctx->pattern = li_pattern_new(srv, "%{req.path}"); ctx->flags = 0; ctx->ttl = 30; ctx->maxsize = 64*1024; /* 64 kB */ ctx->headers = FALSE; if (config) { GHashTable *ht = config->data.hash; GHashTableIter it; gpointer pkey, pvalue; g_hash_table_iter_init(&it, ht); while (g_hash_table_iter_next(&it, &pkey, &pvalue)) { GString *key = pkey; liValue *value = pvalue; if (g_string_equal(key, &mon_server)) { if (value->type != LI_VALUE_STRING) { ERROR(srv, "memcache option '%s' expects string as parameter", mon_server.str); goto option_failed; } li_sockaddr_clear(&ctx->addr); ctx->addr = li_sockaddr_from_string(value->data.string, 11211); if (NULL == ctx->addr.addr) { ERROR(srv, "invalid socket address: '%s'", value->data.string->str); goto option_failed; } } else if (g_string_equal(key, &mon_key)) { if (value->type != LI_VALUE_STRING) { ERROR(srv, "memcache option '%s' expects string as parameter", mon_key.str); goto option_failed; } li_pattern_free(ctx->pattern); ctx->pattern = li_pattern_new(srv, value->data.string->str); if (NULL == ctx->pattern) { ERROR(srv, "memcache: couldn't parse pattern for key '%s'", value->data.string->str); goto option_failed; } } else if (g_string_equal(key, &mon_flags)) { if (value->type != LI_VALUE_NUMBER || value->data.number <= 0) { ERROR(srv, "memcache option '%s' expects positive integer as parameter", mon_flags.str); goto option_failed; } ctx->flags = value->data.number; } else if (g_string_equal(key, &mon_ttl)) { if (value->type != LI_VALUE_NUMBER || value->data.number < 0) { ERROR(srv, "memcache option '%s' expects non-negative integer as parameter", mon_ttl.str); goto option_failed; } ctx->ttl = value->data.number; } else if (g_string_equal(key, &mon_maxsize)) { if (value->type != LI_VALUE_NUMBER || value->data.number <= 0) { ERROR(srv, "memcache option '%s' expects positive integer as parameter", mon_maxsize.str); goto option_failed; } ctx->maxsize = value->data.number; } else if (g_string_equal(key, &mon_headers)) { if (value->type != LI_VALUE_BOOLEAN) { ERROR(srv, "memcache option '%s' expects boolean as parameter", mon_headers.str); goto option_failed; } ctx->headers = value->data.boolean; if (ctx->headers) { ERROR(srv, "%s", "memcache: lookup/storing headers not supported yet"); goto option_failed; } } else { ERROR(srv, "unknown option for memcache '%s'", key->str); goto option_failed; } } } if (LI_SERVER_INIT != g_atomic_int_get(&srv->state)) { ctx->worker_client_ctx = g_slice_alloc0(sizeof(liMemcachedCon*) * srv->worker_count); } else { ctx->mconf_link.data = ctx; g_queue_push_tail_link(&mconf->prepare_ctx, &ctx->mconf_link); } return ctx; option_failed: mc_ctx_release(NULL, ctx); return NULL; }
/** * compare function for GString */ gboolean g_hash_table_string_equal(gconstpointer _a, gconstpointer _b) { return g_string_equal(_a, _b); }
static liAction* auth_generic_create(liServer *srv, liWorker *wrk, liPlugin* p, liValue *val, const char *actname, AuthBasicBackend basic_action, gboolean has_realm) { AuthFile *afd; liValue *method = NULL, *realm = NULL, *file = NULL; gint ttl = 10; GHashTableIter it; gpointer pkey, pvalue; if (!val || val->type != LI_VALUE_HASH) { ERROR(srv, "%s expects a hashtable with at least 3 elements: method, realm and file", actname); return NULL; } g_hash_table_iter_init(&it, val->data.hash); while (g_hash_table_iter_next(&it, &pkey, &pvalue)) { GString *key = pkey; liValue *value = pvalue; if (g_string_equal(key, &aon_method)) { if (value->type != LI_VALUE_STRING) { ERROR(srv, "auth option '%s' expects string as parameter", aon_method.str); return NULL; } method = value; } else if (g_string_equal(key, &aon_realm)) { if (value->type != LI_VALUE_STRING) { ERROR(srv, "auth option '%s' expects string as parameter", aon_realm.str); return NULL; } realm = value; } else if (g_string_equal(key, &aon_file)) { if (value->type != LI_VALUE_STRING) { ERROR(srv, "auth option '%s' expects string as parameter", aon_file.str); return NULL; } file = value; } else if (g_string_equal(key, &aon_ttl)) { if (value->type != LI_VALUE_NUMBER || value->data.number < 0) { ERROR(srv, "auth option '%s' expects non-negative number as parameter", aon_ttl.str); return NULL; } ttl = value->data.number; } } if (NULL == method || NULL == realm || NULL == file) { ERROR(srv, "%s expects a hashtable with 3 elements: method, realm and file", actname); return NULL; } if (!g_str_equal(method->data.string->str, "basic") && !g_str_equal(method->data.string->str, "digest")) { ERROR(srv, "%s: unknown method: %s", actname, method->data.string->str); return NULL; } if (g_str_equal(method->data.string->str, "digest")) { ERROR(srv, "%s: digest authentication not implemented yet", actname); return NULL; } /* load users from file */ afd = auth_file_new(wrk, file->data.string, has_realm, ttl); if (!afd) return FALSE; if (g_str_equal(method->data.string->str, "basic")) { AuthBasicData *bdata; bdata = g_slice_new(AuthBasicData); bdata->p = p; bdata->realm = li_value_extract_string(realm); bdata->backend = basic_action; bdata->data = afd; return li_action_new_function(auth_basic, NULL, auth_basic_free, bdata); } else { auth_file_free(afd); return NULL; /* li_action_new_function(NULL, NULL, auth_backend_plain_free, ad); */ } }
static liAction* auth_generic_create(liServer *srv, liWorker *wrk, liPlugin* p, liValue *val, const char *actname, AuthBasicBackend basic_action, gboolean has_realm) { AuthFile *afd; GString *method = NULL, *file = NULL; liValue *realm = NULL; gboolean have_ttl_parameter = FALSE; gint ttl = 10; val = li_value_get_single_argument(val); if (NULL == (val = li_value_to_key_value_list(val))) { ERROR(srv, "%s expects a hashtable/key-value list with at least 3 elements: method, realm and file", actname); return NULL; } LI_VALUE_FOREACH(entry, val) liValue *entryKey = li_value_list_at(entry, 0); liValue *entryValue = li_value_list_at(entry, 1); GString *entryKeyStr; if (LI_VALUE_NONE == li_value_type(entryKey)) { ERROR(srv, "%s doesn't take default keys", actname); return NULL; } entryKeyStr = entryKey->data.string; /* keys are either NONE or STRING */ if (g_string_equal(entryKeyStr, &aon_method)) { if (LI_VALUE_STRING != li_value_type(entryValue)) { ERROR(srv, "auth option '%s' expects string as parameter", entryKeyStr->str); return NULL; } if (NULL != method) { ERROR(srv, "duplicate auth option '%s'", entryKeyStr->str); return NULL; } method = entryValue->data.string; } else if (g_string_equal(entryKeyStr, &aon_realm)) { if (LI_VALUE_STRING != li_value_type(entryValue)) { ERROR(srv, "auth option '%s' expects string as parameter", entryKeyStr->str); return NULL; } if (NULL != realm) { ERROR(srv, "duplicate auth option '%s'", entryKeyStr->str); return NULL; } realm = entryValue; } else if (g_string_equal(entryKeyStr, &aon_file)) { if (LI_VALUE_STRING != li_value_type(entryValue)) { ERROR(srv, "auth option '%s' expects string as parameter", entryKeyStr->str); return NULL; } if (NULL != file) { ERROR(srv, "duplicate auth option '%s'", entryKeyStr->str); return NULL; } file = entryValue->data.string; } else if (g_string_equal(entryKeyStr, &aon_ttl)) { if (LI_VALUE_NUMBER != li_value_type(entryValue) || entryValue->data.number < 0) { ERROR(srv, "auth option '%s' expects non-negative number as parameter", entryKeyStr->str); return NULL; } if (have_ttl_parameter) { ERROR(srv, "duplicate auth option '%s'", entryKeyStr->str); return NULL; } have_ttl_parameter = TRUE; ttl = entryValue->data.number; } else { ERROR(srv, "unknown auth option '%s'", entryKeyStr->str); return NULL; } LI_VALUE_END_FOREACH() if (NULL == method || NULL == realm || NULL == file) { ERROR(srv, "%s expects a hashtable/key-value list with 3 elements: method, realm and file", actname); return NULL; } if (!g_str_equal(method->str, "basic") && !g_str_equal(method->str, "digest")) { ERROR(srv, "%s: unknown method: %s", actname, method->str); return NULL; } if (g_str_equal(method->str, "digest")) { ERROR(srv, "%s: digest authentication not implemented yet", actname); return NULL; } /* load users from file */ afd = auth_file_new(wrk, file, has_realm, ttl); if (!afd) return FALSE; if (g_str_equal(method->str, "basic")) { AuthBasicData *bdata; bdata = g_slice_new(AuthBasicData); bdata->p = p; bdata->realm = li_value_extract_string(realm); bdata->backend = basic_action; bdata->data = afd; return li_action_new_function(auth_basic, NULL, auth_basic_free, bdata); } else { auth_file_free(afd); return NULL; /* li_action_new_function(NULL, NULL, auth_backend_plain_free, ad); */ } }
int main (int argc, char **argv) { gtk_init (&argc, &argv); // The reality is that warnings shouldn't happen in decent code. g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); SSVCommandLine *cl = ssv_command_line_new (&argc, &argv); // If we are using the default cache directory, and it doesn't // exist, we create it. GString *default_cache_dir = g_string_new (getenv ("HOME")); // IMPROVEME: this must be manually synced with the notion of the // default in ssv_command_line.c. g_string_append (default_cache_dir, "/.ssv_cache"); if ( g_string_equal (cl->cache_dir, default_cache_dir) ) { GError *err = NULL; if ( ! my_is_writable_directory (cl->cache_dir->str, &err) ) { g_assert (err->code == MY_G_UTILITIES_ERROR_G_STAT_FAILED); int return_code = mkdir (cl->cache_dir->str, S_IRWXU); g_assert (return_code == 0); } } // Open the interface to the pyramid_cache. PyramidCache *pyramid_cache = pyramid_cache_new (cl->cache_dir->str, cl->max_cache_size); // List of all the ViewerImage instances being viewed. GPtrArray *images = g_ptr_array_new (); // The big picture coordinate system is defined (internally at // least) to have upper left corner (0, 0) and positive y axis // pointing down, with the upper-left-most image being examined // having its upper left corner at (0, 0) (big picture coordinates). // Since some image offsets specified on the command line may be // negative, we need to find the smallest offsets (assuming that any // offset arguments have been supplied). The first image argument // is understood implicitly to have command line offset arguments of // (0, 0) (so these are the largest minimums possible). ssize_t min_x_offset = 0, min_y_offset = 0; guint ii; for ( ii = 0 ; ii < cl->x_offsets->len ; ii++ ) { gint cxo = g_array_index (cl->x_offsets, gint, ii); // Current x offset. gint cyo = g_array_index (cl->y_offsets, gint, ii); // Current y offset. if ( cxo < min_x_offset ) { min_x_offset = cxo; } if ( cyo < min_y_offset ) { min_y_offset = cyo; } } // Create ViewerImage instances for all the image base name // arguments. for ( ii = 0 ; ii < cl->images->len ; ii++ ) { GString *cin = g_ptr_array_index (cl->images, ii); // If first image (which establishes coordinates system) or if // offset arguments haven't been used, we don't have any offsets to look // up for this image, so use the minimum offsets by themselves. ViewerImage *ci; if ( ii == 0 || cl->x_offsets->len == 0 ) { ci = viewer_image_new (cin->str, cl->pixmaps, cl->sigmas, -min_x_offset, -min_y_offset, pyramid_cache); } else { // Current x offset. gint cxo = g_array_index (cl->x_offsets, gint, ii - 1); // Current y offset. gint cyo = g_array_index (cl->y_offsets, gint, ii - 1); ci = viewer_image_new (cin->str, cl->pixmaps, cl->sigmas, cxo - min_x_offset, cyo - min_y_offset, pyramid_cache); } g_ptr_array_add (images, ci); } // We can now compute the initial dimensions of the big picture // coordinate system domain. These results will be used to // initialize the big picture understanding in the ViewerWindow // instances. Note that if the user is later allowed to change an // image's offsets, the size of the big picture domain may change, // and all windows will need to be notified of this somehow, and // react appropriately... This is an interwindow event, and would // be a pain to implement. The best way is probably for all windows // to hold references to all the images, since they will need to do // something like that anyway to get flicke working. ssize_t min_x = SSIZE_MAX, max_x = -(SSIZE_MAX - 1); g_assert (max_x < 0); // Roll over check, since SSIZE_MIN not defined. ssize_t min_y = SSIZE_MAX, max_y = -(SSIZE_MAX - 1); g_assert (max_y < 0); // Roll over check, since SSIZE_MIN not defined. for ( ii = 0 ; ii < images->len ; ii++ ) { ViewerImage *ci = g_ptr_array_index (images, ii); // Lower right corner x and y indicies (last addressable pixel in // for example x direction is lr_x - 1). ssize_t lr_x = ci->x_offset + ci->size_x; ssize_t lr_y = ci->y_offset + ci->size_y; if ( ci->x_offset < min_x ) min_x = ci->x_offset; if ( lr_x > max_x ) max_x = lr_x; if ( ci->y_offset < min_y ) min_y = ci->y_offset; if ( lr_y > max_y ) max_y = lr_y; } // We normalize the big picture coordinate system so its upper left // corner is (0, 0) (with the positive y axis pointing down). size_t bp_max_x = max_x - min_x, bp_max_y = max_y - min_y; // List of all the windows currently in existence. GPtrArray *windows = g_ptr_array_new (); // We start off with one window of the first image. ViewerImage *i1 = g_ptr_array_index (images, 0); ViewerWindow *w1 = viewer_window_new (i1, images, bp_max_x - 1, bp_max_y - 1, 0, 0, bp_max_x - 1, bp_max_y - 1, cl->analysis_program, cl->async_analysis, cl->analysis_tile_size); g_ptr_array_add (windows, w1); g_signal_connect (G_OBJECT (w1->w), "delete_event", G_CALLBACK (on_window_delete_event), windows); gtk_main (); viewer_image_unref (i1); // Note that the ViewerWindow instances in this array have already // been unrefed by the delete_event callback. my_g_ptr_array_really_free (windows, NULL); my_g_ptr_array_really_free (images, (FreeFunc) viewer_image_unref); exit (EXIT_SUCCESS); }
int main (int argc, char *argv[]) { GStringChunk *string_chunk; gchar *tmp_string = NULL, *tmp_string_2; gint i; GString *string1, *string2; string_chunk = g_string_chunk_new (1024); for (i = 0; i < 100000; i ++) { tmp_string = g_string_chunk_insert (string_chunk, "hi pete"); if (strcmp ("hi pete", tmp_string) != 0) g_error ("string chunks are broken.\n"); } tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 != tmp_string && strcmp(tmp_string_2, tmp_string) == 0); tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string); g_assert (tmp_string_2 == tmp_string); g_string_chunk_free (string_chunk); string1 = g_string_new ("hi pete!"); string2 = g_string_new (""); g_assert (string1 != NULL); g_assert (string2 != NULL); g_assert (strlen (string1->str) == string1->len); g_assert (strlen (string2->str) == string2->len); g_assert (string2->len == 0); g_assert (strcmp ("hi pete!", string1->str) == 0); g_assert (strcmp ("", string2->str) == 0); for (i = 0; i < 10000; i++) g_string_append_c (string1, 'a'+(i%26)); g_assert((strlen("hi pete!") + 10000) == string1->len); g_assert((strlen("hi pete!") + 10000) == strlen(string1->str)); #ifndef G_OS_WIN32 /* MSVC and mingw32 use the same run-time C library, which doesn't like the %10000.10000f format... */ g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #else g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f", "this pete guy sure is a wuss, like he's the number ", 1, " wuss. everyone agrees.\n", string1->str, 10, 666, 15, 15, 666.666666666, 666.666666666); #endif g_string_free (string1, TRUE); g_string_free (string2, TRUE); /* append */ string1 = g_string_new ("firsthalf"); g_string_append (string1, "lasthalf"); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* append_len */ string1 = g_string_new ("firsthalf"); g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf")); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* prepend */ string1 = g_string_new ("lasthalf"); g_string_prepend (string1, "firsthalf"); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* prepend_len */ string1 = g_string_new ("lasthalf"); g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf")); g_assert (strcmp (string1->str, "firsthalflasthalf") == 0); g_string_free (string1, TRUE); /* insert */ string1 = g_string_new ("firstlast"); g_string_insert (string1, 5, "middle"); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert with pos == end of the string */ string1 = g_string_new ("firstmiddle"); g_string_insert (string1, strlen ("firstmiddle"), "last"); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert_len */ string1 = g_string_new ("firstlast"); g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle")); g_assert (strcmp (string1->str, "firstmiddlelast") == 0); g_string_free (string1, TRUE); /* insert_len with magic -1 pos for append */ string1 = g_string_new ("first"); g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last")); g_assert (strcmp (string1->str, "firstlast") == 0); g_string_free (string1, TRUE); /* insert_len with magic -1 len for strlen-the-string */ string1 = g_string_new ("first"); g_string_insert_len (string1, 5, "last", -1); g_assert (strcmp (string1->str, "firstlast") == 0); g_string_free (string1, TRUE); /* g_string_equal */ string1 = g_string_new ("test"); string2 = g_string_new ("te"); g_assert (! g_string_equal(string1, string2)); g_string_append (string2, "st"); g_assert (g_string_equal(string1, string2)); g_string_free (string1, TRUE); g_string_free (string2, TRUE); /* Check handling of embedded ASCII 0 (NUL) characters in GString. */ string1 = g_string_new ("fiddle"); string2 = g_string_new ("fiddle"); g_assert (g_string_equal(string1, string2)); g_string_append_c(string1, '\0'); g_assert (! g_string_equal(string1, string2)); g_string_append_c(string2, '\0'); g_assert (g_string_equal(string1, string2)); g_string_append_c(string1, 'x'); g_string_append_c(string2, 'y'); g_assert (! g_string_equal(string1, string2)); g_assert (string1->len == 8); g_string_append(string1, "yzzy"); g_assert (string1->len == 12); g_assert ( memcmp(string1->str, "fiddle\0xyzzy", 13) == 0); g_string_insert(string1, 1, "QED"); g_assert ( memcmp(string1->str, "fQEDiddle\0xyzzy", 16) == 0); g_string_free (string1, TRUE); g_string_free (string2, TRUE); return 0; }
static void fastcgi_env_create(liVRequest *vr, liEnvironmentDup *envdup, GByteArray* buf) { liConInfo *coninfo = vr->coninfo; GString *tmp = vr->wrk->tmp_str; fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_SOFTWARE"), GSTR_LEN(CORE_OPTIONPTR(LI_CORE_OPTION_SERVER_TAG).string)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_NAME"), GSTR_LEN(vr->request.uri.host)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("GATEWAY_INTERFACE"), CONST_STR_LEN("CGI/1.1")); { guint port = 0; switch (coninfo->local_addr.addr->plain.sa_family) { case AF_INET: port = coninfo->local_addr.addr->ipv4.sin_port; break; #ifdef HAVE_IPV6 case AF_INET6: port = coninfo->local_addr.addr->ipv6.sin6_port; break; #endif } if (port) { g_string_printf(tmp, "%u", htons(port)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_PORT"), GSTR_LEN(tmp)); } } fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_ADDR"), GSTR_LEN(coninfo->local_addr_str)); { guint port = 0; switch (coninfo->remote_addr.addr->plain.sa_family) { case AF_INET: port = coninfo->remote_addr.addr->ipv4.sin_port; break; #ifdef HAVE_IPV6 case AF_INET6: port = coninfo->remote_addr.addr->ipv6.sin6_port; break; #endif } if (port) { g_string_printf(tmp, "%u", htons(port)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("REMOTE_PORT"), GSTR_LEN(tmp)); } } fastcgi_env_add(buf, envdup, CONST_STR_LEN("REMOTE_ADDR"), GSTR_LEN(coninfo->remote_addr_str)); if (vr->request.content_length > 0) { g_string_printf(tmp, "%" L_GOFFSET_MODIFIER "i", vr->request.content_length); fastcgi_env_add(buf, envdup, CONST_STR_LEN("CONTENT_LENGTH"), GSTR_LEN(tmp)); } fastcgi_env_add(buf, envdup, CONST_STR_LEN("SCRIPT_NAME"), GSTR_LEN(vr->request.uri.path)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("PATH_INFO"), GSTR_LEN(vr->physical.pathinfo)); if (vr->physical.pathinfo->len) { g_string_truncate(tmp, 0); g_string_append_len(tmp, GSTR_LEN(vr->physical.doc_root)); /* TODO: perhaps an option for alternative doc-root? */ g_string_append_len(tmp, GSTR_LEN(vr->physical.pathinfo)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("PATH_TRANSLATED"), GSTR_LEN(tmp)); } fastcgi_env_add(buf, envdup, CONST_STR_LEN("SCRIPT_FILENAME"), GSTR_LEN(vr->physical.path)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("DOCUMENT_ROOT"), GSTR_LEN(vr->physical.doc_root)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("REQUEST_URI"), GSTR_LEN(vr->request.uri.raw_orig_path)); if (!g_string_equal(vr->request.uri.raw_orig_path, vr->request.uri.raw_path)) { fastcgi_env_add(buf, envdup, CONST_STR_LEN("REDIRECT_URI"), GSTR_LEN(vr->request.uri.raw_path)); } fastcgi_env_add(buf, envdup, CONST_STR_LEN("QUERY_STRING"), GSTR_LEN(vr->request.uri.query)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("REQUEST_METHOD"), GSTR_LEN(vr->request.http_method_str)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("REDIRECT_STATUS"), CONST_STR_LEN("200")); /* if php is compiled with --force-redirect */ switch (vr->request.http_version) { case LI_HTTP_VERSION_1_1: fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_PROTOCOL"), CONST_STR_LEN("HTTP/1.1")); break; case LI_HTTP_VERSION_1_0: default: fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_PROTOCOL"), CONST_STR_LEN("HTTP/1.0")); break; } if (coninfo->is_ssl) { fastcgi_env_add(buf, envdup, CONST_STR_LEN("HTTPS"), CONST_STR_LEN("on")); } }
/** * mix_videoconfigparamsenc_: * @first: first object to compare * @second: seond object to compare * @returns: boolean indicates if instance are equal. * * Copy instance data from @src to @target. */ gboolean mix_videoconfigparamsenc_equal(MixParams * first, MixParams * second) { gboolean ret = FALSE; MixVideoConfigParamsEnc *this_first, *this_second; if (MIX_IS_VIDEOCONFIGPARAMSENC(first) && MIX_IS_VIDEOCONFIGPARAMSENC(second)) { // Deep compare // Cast the base object to this child object this_first = MIX_VIDEOCONFIGPARAMSENC(first); this_second = MIX_VIDEOCONFIGPARAMSENC(second); /* check the equalitiy of the primitive type properties */ if (this_first->bitrate != this_second->bitrate) { goto not_equal; } if (this_first->frame_rate_num != this_second->frame_rate_num) { goto not_equal; } if (this_first->frame_rate_denom != this_second->frame_rate_denom) { goto not_equal; } if (this_first->initial_qp != this_second->initial_qp) { goto not_equal; } if (this_first->min_qp != this_second->min_qp) { goto not_equal; } if (this_first->intra_period != this_second->intra_period) { goto not_equal; } if (this_first->picture_width != this_second->picture_width && this_first->picture_height != this_second->picture_height) { goto not_equal; } if (this_first->encode_format != this_second->encode_format) { goto not_equal; } if (this_first->mixbuffer_pool_size != this_second->mixbuffer_pool_size) { goto not_equal; } if (this_first->share_buf_mode != this_second->share_buf_mode) { goto not_equal; } if (this_first->ci_frame_id != this_second->ci_frame_id) { goto not_equal; } if (this_first->ci_frame_num != this_second->ci_frame_num) { goto not_equal; } if (this_first->draw != this_second->draw) { goto not_equal; } if (this_first->need_display!= this_second->need_display) { goto not_equal; } if (this_first->rate_control != this_second->rate_control) { goto not_equal; } if (this_first->raw_format != this_second->raw_format) { goto not_equal; } if (this_first->profile != this_second->profile) { goto not_equal; } /* check the equalitiy of the none-primitive type properties */ /* compare mime_type */ if (this_first->mime_type && this_second->mime_type) { if (g_string_equal(this_first->mime_type, this_second->mime_type) != TRUE) { goto not_equal; } } else if (!(!this_first->mime_type && !this_second->mime_type)) { goto not_equal; } ret = TRUE; not_equal: if (ret != TRUE) { return ret; } /* chaining up. */ MixParamsClass *klass = MIX_PARAMS_CLASS(parent_class); if (klass->equal) ret = parent_class->equal(first, second); else ret = TRUE; } return ret; }
gboolean g_hash_table_string_equal(gconstpointer _a, gconstpointer _b) { return g_string_equal((const GString*) _a, (const GString*) _b); }