void
button_new_config_callback(GtkWidget *widget, gpointer data) {
    Distribution_Tab *tab = data;

    Distribution_Dialog *dist_dialog = g_slice_alloc0(sizeof (Distribution_Dialog));
    dist_dialog->tmp_prefs = g_slice_alloc0(sizeof (XKB_Preferences));
    GtkWidget *dialog = build_dialog_layout_variant_management(NULL, dist_dialog);

    gint result = gtk_dialog_run(GTK_DIALOG(dialog));

    Layout *layout;
    Variant *variant;
    if ((result == GTK_RESPONSE_ACCEPT) &&
            (dist_dialog->active_layout != NULL && dist_dialog->active_variant != NULL)) {

        layout = xkb_rules_get_layout(rules, NULL, dist_dialog->active_layout);
        variant = xkb_rules_layout_get_variant(layout, NULL, dist_dialog->active_variant);

        xkb_preferences_layout_variant_append(user_prefs, layout->id, variant->id);
        list_store_update(tab->store);
    } else {
    }

    /* TODO: Memory clean must be performed */

    xkb_preferences_set_to_env(user_prefs);

    gtk_widget_destroy(dialog);
}
Ejemplo n.º 2
0
static BotCTransPath * 
_path_new(int nlinks)
{
    BotCTransPath * path = g_slice_new(BotCTransPath);
    path->nlinks = nlinks;
    path->links = g_slice_alloc0(nlinks*sizeof(BotCTransLink*));
    path->invert = g_slice_alloc0(nlinks*sizeof(int));
    return path;
}
Ejemplo n.º 3
0
void
salut_set_gesture_to_track (Salut *self,
                            GestId id,
                            void (*callback) (gpointer),
                            gpointer callback_data)
{
  if (self->gest_id == id)
    empty_gesture_list (self->gesture_list, self->gesture_list_length);
  else
    {
      free_gesture_list (self->gesture_list, self->gesture_list_length);
      self->gesture_list = NULL;
      self->gesture_list_length = 0;
    }
  self->gesture_index = 0;

  switch (id)
    {
    case NONE:
    case TOTAL_GESTURES:
    case HAND_METAL:
    case HAND_EAST_COAST:
    case HAND_INDIAN:
      break;

    case BOW:
      self->gesture_list_length = 3;
      self->gesture_list =
        g_slice_alloc0 (self->gesture_list_length * sizeof (SkeltrackJoint));
      break;

    case HAND_WAVE:
      self->gesture_list_length = 6;
      self->gesture_list =
        g_slice_alloc0 (self->gesture_list_length * sizeof (SkeltrackJoint));
      break;

    case CURTSY:
      self->gesture_list_length = 2;
      self->gesture_list =
        g_slice_alloc0 (self->gesture_list_length * sizeof (SkeltrackJoint));
      break;

    case KISS:
      self->gesture_list_length = 3;
      self->gesture_list =
        g_slice_alloc0 (self->gesture_list_length * sizeof (SkeltrackJoint));
      break;
    }

  self->gest_id = id;
  self->callback = callback;
  self->callback_data = callback_data;
}
Ejemplo n.º 4
0
static struct rspamd_lua_cryptobox_hash *
rspamd_lua_hash_create (const gchar *type)
{
	struct rspamd_lua_cryptobox_hash *h;

	h = g_slice_alloc0 (sizeof (*h));

	if (type) {
		if (g_ascii_strcasecmp (type, "md5") == 0) {
			h->is_ssl = TRUE;
			h->c = EVP_MD_CTX_create ();
			EVP_DigestInit (h->c, EVP_md5 ());

			goto ret;
		}
		else if (g_ascii_strcasecmp (type, "sha1") == 0 ||
					g_ascii_strcasecmp (type, "sha") == 0) {
			h->is_ssl = TRUE;
			h->c = EVP_MD_CTX_create ();
			EVP_DigestInit (h->c, EVP_sha1 ());

			goto ret;
		}
		else if (g_ascii_strcasecmp (type, "sha256") == 0) {
			h->is_ssl = TRUE;
			h->c = EVP_MD_CTX_create ();
			EVP_DigestInit (h->c, EVP_sha256 ());

			goto ret;
		}
		else if (g_ascii_strcasecmp (type, "sha512") == 0) {
			h->is_ssl = TRUE;
			h->c = EVP_MD_CTX_create ();
			EVP_DigestInit (h->c, EVP_sha512 ());

			goto ret;
		}
		else if (g_ascii_strcasecmp (type, "sha384") == 0) {
			h->is_ssl = TRUE;
			h->c = EVP_MD_CTX_create ();
			EVP_DigestInit (h->c, EVP_sha384 ());

			goto ret;
		}
	}

	h->h = g_slice_alloc0 (sizeof (*h->h));
	rspamd_cryptobox_hash_init (h->h, NULL, 0);

ret:
	return h;
}
Ejemplo n.º 5
0
gpointer
rspamd_redis_init (struct rspamd_stat_ctx *ctx,
		struct rspamd_config *cfg, struct rspamd_statfile *st)
{
	struct redis_stat_ctx *backend;
	struct rspamd_statfile_config *stf = st->stcf;
	struct rspamd_redis_stat_elt *st_elt;
	const ucl_object_t *obj;
	gboolean ret = FALSE;

	backend = g_slice_alloc0 (sizeof (*backend));

	/* First search in backend configuration */
	obj = ucl_object_lookup (st->classifier->cfg->opts, "backend");
	if (obj != NULL && ucl_object_type (obj) == UCL_OBJECT) {
		ret = rspamd_redis_try_ucl (backend, obj, cfg, stf->symbol);
	}

	/* Now try statfiles config */
	if (!ret) {
		ret = rspamd_redis_try_ucl (backend, stf->opts, cfg, stf->symbol);
	}

	/* Now try classifier config */
	if (!ret) {
		ret = rspamd_redis_try_ucl (backend, st->classifier->cfg->opts, cfg,
				stf->symbol);
	}

	if (!ret) {
		msg_err_config ("cannot init redis backend for %s", stf->symbol);
		g_slice_free1 (sizeof (*backend), backend);
		return NULL;
	}

	stf->clcf->flags |= RSPAMD_FLAG_CLASSIFIER_INCREMENTING_BACKEND;
	backend->stcf = stf;

	st_elt = g_slice_alloc0 (sizeof (*st_elt));
	st_elt->ev_base = ctx->ev_base;
	st_elt->ctx = backend;
	backend->stat_elt = rspamd_stat_ctx_register_async (
			rspamd_redis_async_stat_cb,
			rspamd_redis_async_stat_fin,
			st_elt,
			REDIS_STAT_TIMEOUT);
	st_elt->async = backend->stat_elt;

	return (gpointer)backend;
}
Ejemplo n.º 6
0
struct rspamd_re_runtime *
rspamd_re_cache_runtime_new (struct rspamd_re_cache *cache)
{
	struct rspamd_re_runtime *rt;
	g_assert (cache != NULL);

	rt = g_slice_alloc0 (sizeof (*rt));
	rt->cache = cache;
	REF_RETAIN (cache);
	rt->checked = g_slice_alloc0 (NBYTES (cache->nre));
	rt->results = g_slice_alloc0 (cache->nre);

	return rt;
}
Ejemplo n.º 7
0
rspamd_regexp_t *
rspamd_re_cache_add (struct rspamd_re_cache *cache, rspamd_regexp_t *re,
		enum rspamd_re_type type, gpointer type_data, gsize datalen)
{
	guint64 class_id;
	struct rspamd_re_class *re_class;
	rspamd_regexp_t *nre;
	struct rspamd_re_cache_elt *elt;

	g_assert (cache != NULL);
	g_assert (re != NULL);

	class_id = rspamd_re_cache_class_id (type, type_data, datalen);
	re_class = g_hash_table_lookup (cache->re_classes, &class_id);

	if (re_class == NULL) {
		re_class = g_slice_alloc0 (sizeof (*re_class));
		re_class->id = class_id;
		re_class->type_len = datalen;
		re_class->type = type;
		re_class->re = g_hash_table_new_full (rspamd_regexp_hash,
				rspamd_regexp_equal, NULL, (GDestroyNotify)rspamd_regexp_unref);

		if (datalen > 0) {
			re_class->type_data = g_slice_alloc (datalen);
			memcpy (re_class->type_data, type_data, datalen);
		}

		g_hash_table_insert (cache->re_classes, &re_class->id, re_class);
	}

	if ((nre = g_hash_table_lookup (re_class->re, rspamd_regexp_get_id (re)))
			== NULL) {
		/*
		 * We set re id based on the global position in the cache
		 */
		elt = g_slice_alloc0 (sizeof (*elt));
		/* One ref for re_class */
		nre = rspamd_regexp_ref (re);
		rspamd_regexp_set_cache_id (re, cache->nre++);
		/* One ref for cache */
		elt->re = rspamd_regexp_ref (re);
		g_ptr_array_add (cache->re, elt);
		rspamd_regexp_set_class (re, re_class);
		g_hash_table_insert (re_class->re, rspamd_regexp_get_id (nre), nre);
	}

	return nre;
}
Ejemplo n.º 8
0
struct MessageNewViewData *
message_new_view_show(struct Window *win, GHashTable * options)
{
	struct MessageNewViewData *data =
		g_slice_alloc0(sizeof(struct MessageNewViewData));
	data->win = win;
	data->mode = MODE_CONTENT;
	data->content = NULL;
	data->recipients = g_ptr_array_new();
	data->messages_sent = 0;

	if (options != NULL) {
		char *recipient = g_hash_table_lookup(options, "recipient");
		if (recipient != NULL) {
			char *name = g_hash_table_lookup(options, "name");
			if (!name || !*name)
				name = "Number";
			GHashTable *properties =
				g_hash_table_new_full(g_str_hash, g_str_equal,
						      free, free);
			g_hash_table_insert(properties, strdup("name"),
					    strdup(name));
			g_hash_table_insert(properties, strdup("number"),
					    strdup(recipient));
			g_ptr_array_add(data->recipients, properties);
		}
	}


	window_frame_show(win, data, frame_content_show, frame_content_hide);
	window_show(win);

	return data;
}
Ejemplo n.º 9
0
void *
_pygi_boxed_alloc (GIBaseInfo *info, gsize *size_out)
{
    gsize size;

    /* FIXME: Remove when bgo#622711 is fixed */
    if (g_registered_type_info_get_g_type (info) == G_TYPE_VALUE) {
        size = sizeof (GValue);
    } else {
        switch (g_base_info_get_type (info)) {
            case GI_INFO_TYPE_UNION:
                size = g_union_info_get_size ( (GIUnionInfo *) info);
                break;
            case GI_INFO_TYPE_BOXED:
            case GI_INFO_TYPE_STRUCT:
                size = g_struct_info_get_size ( (GIStructInfo *) info);
                break;
            default:
                PyErr_Format (PyExc_TypeError,
                              "info should be Boxed or Union, not '%d'",
                              g_base_info_get_type (info));
                return NULL;
        }
    }

    if( size_out != NULL)
        *size_out = size;

    return g_slice_alloc0 (size);
}
Ejemplo n.º 10
0
static gchar *
lua_map_read (rspamd_mempool_t *pool, gchar *chunk, gint len,
	struct map_cb_data *data)
{
	struct lua_map_callback_data *cbdata, *old;

	if (data->cur_data == NULL) {
		cbdata = g_slice_alloc0 (sizeof (*cbdata));
		old = (struct lua_map_callback_data *)data->prev_data;
		cbdata->L = old->L;
		cbdata->ref = old->ref;
		data->cur_data = cbdata;
	}
	else {
		cbdata = (struct lua_map_callback_data *)data->cur_data;
	}

	if (cbdata->data == NULL) {
		cbdata->data = g_string_new_len (chunk, len);
	}
	else {
		g_string_append_len (cbdata->data, chunk, len);
	}

	return NULL;
}
Ejemplo n.º 11
0
// ---------------------------------------------------------------------------
// UgPlugin : UgPlugin is a base structure for downloading.
//
UgPlugin*	ug_plugin_new	(const UgPluginInterface* iface, UgDataset* dataset)
{
	UgPlugin*			plugin;
	UgPluginInitFunc	init;

//	plugin = g_malloc0 (iface->instance_size);
	plugin = g_slice_alloc0 (iface->instance_size);

	// initialize base data
	plugin->iface = iface;
	g_mutex_init (&plugin->lock);
//	plugin->state = UG_STATE_NULL;
	plugin->ref_count = 1;

	init = iface->init;
	if (init) {
		// If plugin initial failed, free resource and return NULL.
		if (init (plugin, dataset) == FALSE) {
			g_mutex_clear (&plugin->lock);
//			g_free (plugin);
			g_slice_free1 (iface->instance_size, plugin);
			return NULL;
		}
	}

	return plugin;
}
Ejemplo n.º 12
0
void
rspamd_stat_init (struct rspamd_config *cfg)
{
	guint i;

	if (stat_ctx == NULL) {
		stat_ctx = g_slice_alloc0 (sizeof (*stat_ctx));
	}

	stat_ctx->backends = stat_backends;
	stat_ctx->backends_count = G_N_ELEMENTS (stat_backends);
	stat_ctx->classifiers = stat_classifiers;
	stat_ctx->classifiers_count = G_N_ELEMENTS (stat_classifiers);
	stat_ctx->tokenizers = stat_tokenizers;
	stat_ctx->tokenizers_count = G_N_ELEMENTS (stat_tokenizers);
	stat_ctx->caches = stat_caches;
	stat_ctx->caches_count = G_N_ELEMENTS (stat_caches);

	/* Init backends */
	for (i = 0; i < stat_ctx->backends_count; i ++) {
		stat_ctx->backends[i].ctx = stat_ctx->backends[i].init (stat_ctx, cfg);
		msg_debug ("added backend %s", stat_ctx->backends[i].name);
	}

	/* Init caches */
	for (i = 0; i < stat_ctx->caches_count; i ++) {
		stat_ctx->caches[i].ctx = stat_ctx->caches[i].init (stat_ctx, cfg);
		msg_debug ("added cache %s", stat_ctx->caches[i].name);
	}
}
Ejemplo n.º 13
0
static void digital_clock_init(DigitalClock * dclock)
{

    DigitalClockPriv *priv;
    GtkWidget *w = GTK_WIDGET(dclock);

    dclock->priv = DIGITAL_CLOCK_GET_PRIV(dclock);
    priv = dclock->priv;
    priv->x = priv->y = 0;
    priv->width = priv->height = -1;
    priv->fsiz = 0;
    priv->mode12 = TRUE;

    priv->time_val=g_slice_alloc0(LENTIMESTR);

//  g_signal_connect (G_OBJECT (dclock), "draw", G_CALLBACK (_draw), dclock);
    dclock->priv->timeoutid =
	g_timeout_add(TimeOutVal, (GSourceFunc) flushtime_cb, dclock);

    GtkStyleContext *stylecontext = gtk_widget_get_style_context(w);
    gtk_style_context_add_class(stylecontext, GTK_STYLE_CLASS_BUTTON);
    gtk_style_context_add_class(stylecontext, "suggested-action");

    gtk_widget_set_hexpand(w,TRUE);
    gtk_widget_set_vexpand(w,TRUE);

}
Ejemplo n.º 14
0
static void
tidy_grid_real_add (ClutterContainer *container,
                    ClutterActor     *actor)
{
  TidyGridPrivate *priv;
  TidyGridActorData *data;

  g_return_if_fail (TIDY_IS_GRID (container));

  priv = TIDY_GRID (container)->priv;

  g_object_ref (actor);

  clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));

  data = g_slice_alloc0 (sizeof (TidyGridActorData));

  priv->list = g_list_append (priv->list, actor);
  g_hash_table_insert (priv->hash_table, actor, data);

  g_signal_emit_by_name (container, "actor-added", actor);

  clutter_actor_queue_relayout (CLUTTER_ACTOR (container));

  g_object_unref (actor);
}
Ejemplo n.º 15
0
static GstPad *
fs_funnel_request_new_pad (GstElement * element, GstPadTemplate * templ,
  const gchar * name)
{
  GstPad *sinkpad;
  FsFunnelPadPrivate *priv = g_slice_alloc0 (sizeof(FsFunnelPadPrivate));

  GST_DEBUG_OBJECT (element, "requesting pad");

  sinkpad = gst_pad_new_from_template (templ, name);

  gst_pad_set_chain_function (sinkpad, GST_DEBUG_FUNCPTR (fs_funnel_chain));
  gst_pad_set_event_function (sinkpad, GST_DEBUG_FUNCPTR (fs_funnel_event));
  gst_pad_set_getcaps_function (sinkpad, GST_DEBUG_FUNCPTR (fs_funnel_getcaps));
  gst_pad_set_bufferalloc_function (sinkpad,
      GST_DEBUG_FUNCPTR (fs_funnel_buffer_alloc));

  gst_segment_init (&priv->segment, GST_FORMAT_UNDEFINED);
  gst_pad_set_element_private (sinkpad, priv);

  gst_pad_set_active (sinkpad, TRUE);

  gst_element_add_pad (element, sinkpad);

  return sinkpad;
}
Ejemplo n.º 16
0
static gboolean gst_imx_pxp_alloc_phys_mem(GstImxPhysMemAllocator *allocator, GstImxPhysMemory *memory, gssize size)
{
	/* allocate cacheable physically contiguous memory block */

	int ret;
	struct pxp_mem_desc *mem_desc = g_slice_alloc0(sizeof(struct pxp_mem_desc));

	mem_desc->size = size;
	mem_desc->mtype = MEMORY_TYPE_CACHED;

	ret = ioctl(gst_imx_pxp_get_fd(), PXP_IOC_GET_PHYMEM, mem_desc);

	if (ret != 0)
	{
		GST_ERROR_OBJECT(allocator, "could not allocate %u bytes of physical memory: %s", size, strerror(errno));
		g_slice_free1(size, mem_desc);
		return FALSE;
	}
	else
	{
		memory->phys_addr = (gst_imx_phys_addr_t)(mem_desc->phys_addr);
		memory->internal = mem_desc;

		GST_INFO_OBJECT(allocator, "allocated %u bytes of physical memory, paddr %" GST_IMX_PHYS_ADDR_FORMAT, size, memory->phys_addr);

		return TRUE;
	}
}
Ejemplo n.º 17
0
static struct httpc* _httpc_new()
{
	gint err;
	gchar sid[33];
	GString *buff = qev_buffer_get();
	struct httpc *hc = g_slice_alloc0(sizeof(*hc));

	_uuid(sid);

	hc->polling = test_socket();
	hc->waiting = test_socket();
	hc->aq = g_async_queue_new();
	hc->sid = g_strdup(sid);
	hc->th_run = TRUE;
	g_mutex_init(&hc->lock);

	hc->th = g_thread_new("httpc", _httpc_thread, hc);

	g_string_printf(buff, INIT_HEADERS, hc->sid);
	err = send(hc->polling, buff->str, buff->len, 0);
	ck_assert_int_eq(err, buff->len);

	qev_buffer_put(buff);

	_next(hc, "/qio/callback/1:0={\"code\":200,\"data\":\"localhost\"}");

	return hc;
}
Ejemplo n.º 18
0
void
uprof_context_add_counter (UProfContext *context, UProfCounter *counter)
{
  /* We check if we have actually seen this counter before; it might be that
   * it belongs to a dynamic shared object that has been reloaded */
  UProfCounterState *state =
    uprof_context_get_counter_result (context, counter->name);

  /* If we have seen this counter before see if it is being added from a
   * new location and track that location if so.
   */
  if (G_UNLIKELY (state))
    {
      _uprof_object_state_add_location (UPROF_OBJECT_STATE (state),
                                        counter->filename,
                                        counter->line,
                                        counter->function);
    }
  else
    {
      state = g_slice_alloc0 (sizeof (UProfCounterState));
      _uprof_object_state_init (UPROF_OBJECT_STATE (state),
                                context,
                                counter->name,
                                counter->description);
      _uprof_object_state_add_location (UPROF_OBJECT_STATE (state),
                                        counter->filename,
                                        counter->line,
                                        counter->function);
      state->disabled = context->disabled;
      context->counters = g_list_prepend (context->counters, state);
    }
  counter->state = state;
  _uprof_context_dirty_resolved_state (context);
}
Ejemplo n.º 19
0
/* agent must be locked */
static struct ice_candidate_pair *__pair_candidate(struct interface_address *addr, struct ice_agent *ag,
		struct ice_candidate *cand, struct packet_stream *ps)
{
	struct ice_candidate_pair *pair;

	if (addr->family != family_from_address(&cand->endpoint.ip46))
		return NULL;

	pair = g_slice_alloc0(sizeof(*pair));

	pair->agent = ag;
	pair->remote_candidate = cand;
	pair->local_address = addr;
	pair->packet_stream = ps;
	if (cand->component_id != 1)
		PAIR_SET(pair, FROZEN);
	__do_ice_pair_priority(pair);
	__new_stun_transaction(pair);

	g_queue_push_tail(&ag->candidate_pairs, pair);
	g_hash_table_insert(ag->pair_hash, pair, pair);
	g_tree_insert(ag->all_pairs, pair, pair);

	ilog(LOG_DEBUG, "Created candidate pair "PAIR_FORMAT" between %s and %s, type %s", PAIR_FMT(pair),
			smart_ntop_buf(&addr->addr), smart_ntop_ep_buf(&cand->endpoint),
			ice_candidate_type_str(cand->type));

	return pair;
}
Ejemplo n.º 20
0
/* agent must be locked */
static struct ice_candidate_pair *__pair_candidate(struct stream_fd *sfd, struct ice_agent *ag,
		struct ice_candidate *cand)
{
	struct ice_candidate_pair *pair;

	if (sfd->socket.family != cand->endpoint.address.family)
		return NULL;

	pair = g_slice_alloc0(sizeof(*pair));

	pair->agent = ag;
	pair->remote_candidate = cand;
	pair->local_intf = sfd->local_intf;
	pair->sfd = sfd;
	if (cand->component_id != 1)
		PAIR_SET(pair, FROZEN);
	__do_ice_pair_priority(pair);
	__new_stun_transaction(pair);

	g_queue_push_tail(&ag->candidate_pairs, pair);
	g_hash_table_insert(ag->pair_hash, pair, pair);
	g_tree_insert(ag->all_pairs, pair, pair);

	ilog(LOG_DEBUG, "Created candidate pair "PAIR_FORMAT" between %s and %s, type %s", PAIR_FMT(pair),
			sockaddr_print_buf(&sfd->socket.local.address),
			endpoint_print_buf(&cand->endpoint),
			ice_candidate_type_str(cand->type));

	return pair;
}
PP_Resource
ppb_flash_menu_create(PP_Instance instance_id, const struct PP_Flash_Menu *menu_data)
{
    struct pp_instance_s *pp_i = tables_get_pp_instance(instance_id);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return 0;
    }

    PP_Resource flash_menu = pp_resource_allocate(PP_RESOURCE_FLASH_MENU, pp_i);
    if (pp_resource_get_type(flash_menu) != PP_RESOURCE_FLASH_MENU) {
        trace_error("%s, resource allocation failure\n", __func__);
        return 0;
    }

    struct flash_menu_create_param_s *p = g_slice_alloc0(sizeof(*p));

    p->flash_menu = flash_menu;
    p->menu_data =  menu_data;
    p->m_loop =     ppb_message_loop_get_current();
    p->depth =      ppb_message_loop_get_depth(p->m_loop) + 1;

    ppb_message_loop_post_work_with_result(p->m_loop, PP_MakeCCB(flash_menu_create_comt, p), 0,
                                           PP_OK, p->depth, __func__);
    ppb_message_loop_run_nested(p->m_loop);

    g_slice_free1(sizeof(*p), p);
    return flash_menu;
}
Ejemplo n.º 22
0
static int streams_parse_func(char **a, void **ret, void *p) {
	struct stream_params *sp;
	u_int32_t ip;
	int *i;

	i = p;
	sp = g_slice_alloc0(sizeof(*sp));

	SP_SET(sp, SEND);
	SP_SET(sp, RECV);
	sp->protocol = &transport_protocols[PROTO_RTP_AVP];

	ip = inet_addr(a[0]);
	if (ip == -1)
		goto fail;

	in4_to_6(&sp->rtp_endpoint.ip46, ip);
	sp->rtp_endpoint.port = atoi(a[1]);
	sp->index = ++(*i);
	sp->consecutive_ports = 1;

	sp->rtcp_endpoint = sp->rtp_endpoint;
	sp->rtcp_endpoint.port++;

	if (!sp->rtp_endpoint.port && strcmp(a[1], "0"))
		goto fail;

	*ret = sp;
	return 0;

fail:
	ilog(LOG_WARNING, "Failed to parse a media stream: %s:%s", a[0], a[1]);
	g_slice_free1(sizeof(*sp), sp);
	return -1;
}
Ejemplo n.º 23
0
gpointer
g_mem_chunk_alloc0 (GMemChunk *mem_chunk)
{
    g_return_val_if_fail (mem_chunk != NULL, NULL);

    return g_slice_alloc0 (mem_chunk->alloc_size);
}
Ejemplo n.º 24
0
void *moloch_size_alloc(int size, int zero)
{
    size += 8;
    void *mem = (zero?g_slice_alloc0(size):g_slice_alloc(size));
    memcpy(mem, &size, 4);
    return mem + 8;
}
Ejemplo n.º 25
0
struct sdp_chopper *sdp_chopper_new(str *input) {
	struct sdp_chopper *c = g_slice_alloc0(sizeof(*c));
	c->input = input;
	c->chunk = g_string_chunk_new(512);
	c->iov = g_array_new(0, 0, sizeof(struct iovec));
	return c;
}
Ejemplo n.º 26
0
sprite_ol_t* add_sprite_ol(home_t* p_home, home_proto_t* p_proto)
{
	sprite_ol_t* p = g_slice_alloc0(sizeof(sprite_ol_t));	
	update_sprite_head_info(p_proto, p);
	g_hash_table_insert(p_home->sprites, &p->id, p);
	add_online_user(p_home, p_proto->onlineid);
	return p;	
}
Ejemplo n.º 27
0
/**
 * ncm_matrix_new0:
 * @nrows: number of rows
 * @ncols: number of columns
 *
 * This function allocates memory for a new #NcmMatrix of doubles
 * with @nrows rows and @ncols columns and sets all elements to zero.
 *
 * Returns: (transfer full): A new #NcmMatrix.
 */
NcmMatrix *
ncm_matrix_new0 (const guint nrows, const guint ncols)
{
  gdouble *d = g_slice_alloc0 (sizeof(gdouble) * nrows * ncols);
  NcmMatrix *cm = ncm_matrix_new_full (d, nrows, ncols, ncols, NULL, NULL);
  cm->type = NCM_MATRIX_SLICE;
  return cm;
}
Ejemplo n.º 28
0
struct event_base *
rspamd_prepare_worker (struct rspamd_worker *worker, const char *name,
	void (*accept_handler)(int, short, void *), gboolean load_lua)
{
	struct event_base *ev_base;
	struct event *accept_events;
	GList *cur;
	struct rspamd_worker_listen_socket *ls;

#ifdef WITH_PROFILER
	extern void _start (void), etext (void);
	monstartup ((u_long) & _start, (u_long) & etext);
#endif

	gperf_profiler_init (worker->srv->cfg, name);

	worker->srv->pid = getpid ();
	worker->signal_events = g_hash_table_new_full (g_direct_hash, g_direct_equal,
			NULL, g_free);

	ev_base = event_init ();

	rspamd_worker_init_signals (worker, ev_base);
	rspamd_control_worker_add_default_handler (worker, ev_base);
#ifdef WITH_HIREDIS
	rspamd_redis_pool_config (worker->srv->cfg->redis_pool,
			worker->srv->cfg, ev_base);
#endif

	/* Accept all sockets */
	if (accept_handler) {
		cur = worker->cf->listen_socks;

		while (cur) {
			ls = cur->data;

			if (ls->fd != -1) {
				accept_events = g_slice_alloc0 (sizeof (struct event) * 2);
				event_set (&accept_events[0], ls->fd, EV_READ | EV_PERSIST,
						accept_handler, worker);
				event_base_set (ev_base, &accept_events[0]);
				event_add (&accept_events[0], NULL);
				worker->accept_events = g_list_prepend (worker->accept_events,
						accept_events);
			}

			cur = g_list_next (cur);
		}
	}

	if (load_lua) {
		struct rspamd_config *cfg = worker->srv->cfg;

		rspamd_lua_run_postloads (cfg->lua_state, cfg, ev_base, worker);
	}

	return ev_base;
}
Ejemplo n.º 29
0
static void _add_app(
	const gchar *name,
	const gchar *path)
{
	guint i;
	gboolean ok;
	qio_app_cb cb;
	GString *full_path = qev_buffer_get();
	guint *magic_num = NULL;
	struct app *app = g_slice_alloc0(sizeof(*app));

	app->name = g_strdup(name);

	if (strspn(path, PATH_STARTERS) == 0) {
		g_string_printf(full_path, "%s/%s", PATH_LIB_DIR, path);
	} else {
		g_string_assign(full_path, path);
	}

	app->mod = g_module_open(full_path->str, G_MODULE_BIND_LOCAL);
	ASSERT(app->mod != NULL,
			"Could not open app %s: %s", name, g_module_error());

	/*
	 * For config: unloading modules causes segfaults on exit because the
	 * modules can be closed an removed from memory. Keep them in memory at
	 * all times: not like they can be removed at runtime anyway.
	 */
	g_module_make_resident(app->mod);

	for (i = 0; i < _apps->len; i++) {
		struct app *oapp = g_ptr_array_index(_apps, i);
		ASSERT(app->mod != oapp->mod,
				"Duplicate app detected %s (%s).",
				name, full_path->str);
	}

	ok = g_module_symbol(app->mod, "__qio_is_app", (void*)&magic_num) &&
			*magic_num == QIO_MAGIC_NUM;
	ASSERT(ok, "Loaded module is not a QuickIO app: %s (%s)",
				name, full_path->str)

	#define X(fn) \
		ASSERT(g_module_symbol(app->mod, "__qio_app_" G_STRINGIFY(fn), (void*)&cb), \
				"App missing default QuickIO function %s: %s (%s)", \
				"__qio_app_" G_STRINGIFY(fn), name, full_path->str); \
			app->fn = cb;

		CALLBACKS
	#undef X

	ASSERT(app->init(),
			"Could not initialize app (%s): init() failed",
			name);

	g_ptr_array_add(_apps, app);
	qev_buffer_put(full_path);
}
Ejemplo n.º 30
0
void event_queue_enqueue(event_queue *queue, guint time, void (*func)(guint, void *), void *data)
{
  event_queue_entry *entry = g_slice_alloc0(sizeof(event_queue_entry));
  entry->time = time;
  entry->func = func;
  entry->data = data;
  g_sequence_insert_sorted(queue->queue, entry, (gint (*)(gconstpointer,
          gconstpointer, gpointer)) event_queue_entry_compare, NULL);
}