Esempio n. 1
0
void
oio_str_randomize(guint8 *buf, gsize buflen)
{
	union {
		guint32 r32;
		guint8 r8[4];
	} raw;

	if (NULL == buf || 0 == buflen)
		return;

	// Fill 4 by 4
	gsize mod32 = buflen % 4;
	gsize max32 = buflen / 4;
	for (register gsize i32=0; i32 < max32 ; ++i32) {
		raw.r32 = g_random_int();
		((guint32*)buf)[i32] = raw.r32;
	}

	// Finish with the potentially remaining unset bytes
	raw.r32 = g_random_int();
	switch (mod32) {
		case 3:
			buf[ (max32*4) + 2 ] = raw.r8[2];
		case 2:
			buf[ (max32*4) + 1 ] = raw.r8[1];
		case 1:
			buf[ (max32*4) + 0 ] = raw.r8[0];
	}
}
Esempio n. 2
0
static void
gst_rtp_mux_ready_to_paused (GstRTPMux * rtp_mux)
{

  GST_OBJECT_LOCK (rtp_mux);

  g_clear_object (&rtp_mux->last_pad);
  rtp_mux->send_stream_start = TRUE;

  if (rtp_mux->ssrc == -1)
    rtp_mux->current_ssrc = g_random_int ();
  else
    rtp_mux->current_ssrc = rtp_mux->ssrc;

  if (rtp_mux->seqnum_offset == -1)
    rtp_mux->seqnum_base = g_random_int_range (0, G_MAXUINT16);
  else
    rtp_mux->seqnum_base = rtp_mux->seqnum_offset;
  rtp_mux->seqnum = rtp_mux->seqnum_base;

  if (rtp_mux->ts_offset == -1)
    rtp_mux->ts_base = g_random_int ();
  else
    rtp_mux->ts_base = rtp_mux->ts_offset;

  rtp_mux->last_stop = GST_CLOCK_TIME_NONE;

  GST_DEBUG_OBJECT (rtp_mux, "set timestamp-offset to %u", rtp_mux->ts_base);

  GST_OBJECT_UNLOCK (rtp_mux);
}
Esempio n. 3
0
RTP_session *
rtp_session_new(RTSP_Client *client, RTSP_session *rtsp_s, RTP_transport *transport,
	GstRTSPUrl *uri, Track *tr)
{
    RTP_session *rtp_s = g_new0(RTP_session, 1);

	rtp_s->ref_count = 1;
	rtp_s->playing = FALSE;
    rtp_s->uri = gst_rtsp_url_get_request_uri(uri);

    memcpy(&rtp_s->transport, transport, sizeof(RTP_transport));
    memset(transport, 0, sizeof(RTP_transport));
    rtp_s->start_rtptime = g_random_int();
    rtp_s->start_seq = g_random_int_range(0, G_MAXUINT16);
    rtp_s->seq_no = rtp_s->start_seq - 1;

    rtp_s->track = tr;
    if (tr->properties.media_type == MP_video)
    	rtp_s->consumer = bq_consumer_new(tr->producer);

    rtp_s->ssrc = g_random_int();
    rtp_s->client = client;

#ifdef HAVE_METADATA
	rtp_s->metadata = rtsp_s->resource->metadata;
#endif

    rtsp_s->rtp_sessions = g_slist_append(rtsp_s->rtp_sessions, rtp_s);
    rtp_s->rtsp = rtsp_s;
    rtsp_session_ref(rtsp_s);

    return rtp_s;
}
static void
_round_lock(sqlx_cache_t *cache)
{
	hashstr_t *hn0 = NULL, *hn1 = NULL;
	HASHSTR_ALLOCA(hn0, name0);
	HASHSTR_ALLOCA(hn1, name1);

	gint id0;
	GError *err = sqlx_cache_open_and_lock_base(cache, hn0, &id0);
	g_assert_no_error (err);

	for (int i=0; i<5 ;i++) {
		gint id = g_random_int();
		err = sqlx_cache_open_and_lock_base(cache, hn0, &id);
		g_assert_no_error (err);
		g_assert_cmpint(id0, ==, id);
	}
	for (int i=0; i<6 ;i++) {
		err = sqlx_cache_unlock_and_close_base(cache, id0, FALSE);
		g_assert_no_error (err);
	}
	err = sqlx_cache_unlock_and_close_base(cache, id0, FALSE);
	g_assert_error (err, GQ(), CODE_INTERNAL_ERROR);
	g_clear_error (&err);

	for (int i=0; i<5 ;i++) {
		gint id = g_random_int ();
		err = sqlx_cache_open_and_lock_base(cache, hn1, &id);
		g_assert_no_error (err);
		err = sqlx_cache_unlock_and_close_base(cache, id, FALSE);
		g_assert_no_error (err);
	}
}
Esempio n. 5
0
/**
 * soup_websocket_client_prepare_handshake:
 * @msg: a #SoupMessage
 * @origin: (allow-none): the "Origin" header to set
 * @protocols: (allow-none) (array zero-terminated=1): list of
 *   protocols to offer
 *
 * Adds the necessary headers to @msg to request a WebSocket
 * handshake. The message body and non-WebSocket-related headers are
 * not modified.
 *
 * This is a low-level function; if you use
 * soup_session_websocket_connect_async() to create a WebSocket
 * connection, it will call this for you.
 *
 * Since: 2.50
 */
void
soup_websocket_client_prepare_handshake (SoupMessage  *msg,
					 const char   *origin,
					 char        **protocols)
{
	guint32 raw[4];
	char *key;

	soup_message_headers_replace (msg->request_headers, "Upgrade", "websocket");
	soup_message_headers_append (msg->request_headers, "Connection", "Upgrade");

	raw[0] = g_random_int ();
	raw[1] = g_random_int ();
	raw[2] = g_random_int ();
	raw[3] = g_random_int ();
	key = g_base64_encode ((const guchar *)raw, sizeof (raw));
	soup_message_headers_replace (msg->request_headers, "Sec-WebSocket-Key", key);
	g_free (key);

	soup_message_headers_replace (msg->request_headers, "Sec-WebSocket-Version", "13");

	if (origin)
		soup_message_headers_replace (msg->request_headers, "Origin", origin);

	if (protocols) {
		char *protocols_str;

		protocols_str = g_strjoinv (", ", protocols);
		soup_message_headers_replace (msg->request_headers,
					      "Sec-WebSocket-Protocol", protocols_str);
		g_free (protocols_str);
	}
}
Esempio n. 6
0
sc_element* get_random_element(sc_type type)
{
    sc_addr id;

    id.seg = g_random_int() % sc_storage_get_segments_count();
    id.offset = g_random_int() % SEGMENT_SIZE;
    return sc_storage_get_element(id, SC_FALSE);
}
Esempio n. 7
0
sc_addr get_random_addr(sc_type type)
{
    sc_addr addr;

    addr.seg = g_random_int() % sc_storage_get_segments_count();
    addr.offset = 0;
    addr.offset = g_random_int() % SEGMENT_SIZE;

    return addr;
}
Esempio n. 8
0
void
wmem_init_hashing(void)
{
    x = g_random_int();
    if G_UNLIKELY(x == 0)
        x = 1;

    preseed  = g_random_int();
    postseed = g_random_int();
}
Esempio n. 9
0
PurpleBOSHConnection*
jabber_bosh_connection_init(JabberStream *js, const char *url)
{
	PurpleBOSHConnection *conn;
	char *host, *path, *user, *passwd;
	int port;

	if (!purple_url_parse(url, &host, &port, &path, &user, &passwd)) {
		purple_debug_info("jabber", "Unable to parse given URL.\n");
		return NULL;
	}

	conn = g_new0(PurpleBOSHConnection, 1);
	conn->host = host;
	conn->port = port;
	conn->path = g_strdup_printf("/%s", path);
	g_free(path);
	conn->pipelining = TRUE;

	if (purple_ip_address_is_valid(host))
		js->serverFQDN = g_strdup(js->user->domain);
	else
		js->serverFQDN = g_strdup(host);

	if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) {
		purple_debug_info("jabber", "Ignoring unexpected username and password "
		                            "in BOSH URL.\n");
	}

	g_free(user);
	g_free(passwd);

	conn->js = js;

	/*
	 * Random 64-bit integer masked off by 2^52 - 1.
	 *
	 * This should produce a random integer in the range [0, 2^52). It's
	 * unlikely we'll send enough packets in one session to overflow the rid.
	 */
	conn->rid = ((guint64)g_random_int() << 32) | g_random_int();
	conn->rid &= 0xFFFFFFFFFFFFFLL;

	conn->pending = purple_circ_buffer_new(0 /* default grow size */);

	conn->state = BOSH_CONN_OFFLINE;
	if (purple_strcasestr(url, "https://") != NULL)
		conn->ssl = TRUE;
	else
		conn->ssl = FALSE;

	conn->connections[0] = jabber_bosh_http_connection_init(conn);

	return conn;
}
Esempio n. 10
0
static GstStateChangeReturn
gst_rtp_base_payload_change_state (GstElement * element,
    GstStateChange transition)
{
  GstRTPBasePayload *rtpbasepayload;
  GstRTPBasePayloadPrivate *priv;
  GstStateChangeReturn ret;

  rtpbasepayload = GST_RTP_BASE_PAYLOAD (element);
  priv = rtpbasepayload->priv;

  switch (transition) {
    case GST_STATE_CHANGE_NULL_TO_READY:
      break;
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      gst_segment_init (&rtpbasepayload->segment, GST_FORMAT_UNDEFINED);

      if (priv->seqnum_offset_random)
        rtpbasepayload->seqnum_base = g_random_int_range (0, G_MAXUINT16);
      else
        rtpbasepayload->seqnum_base = rtpbasepayload->seqnum_offset;
      priv->next_seqnum = rtpbasepayload->seqnum_base;
      rtpbasepayload->seqnum = rtpbasepayload->seqnum_base;

      if (priv->ssrc_random)
        rtpbasepayload->current_ssrc = g_random_int ();
      else
        rtpbasepayload->current_ssrc = rtpbasepayload->ssrc;

      if (priv->ts_offset_random)
        rtpbasepayload->ts_base = g_random_int ();
      else
        rtpbasepayload->ts_base = rtpbasepayload->ts_offset;
      rtpbasepayload->timestamp = rtpbasepayload->ts_base;
      g_atomic_int_set (&rtpbasepayload->priv->notified_first_timestamp, 1);
      priv->base_offset = GST_BUFFER_OFFSET_NONE;
      break;
    default:
      break;
  }

  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);

  switch (transition) {
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
      g_atomic_int_set (&rtpbasepayload->priv->notified_first_timestamp, 1);
      break;
    case GST_STATE_CHANGE_READY_TO_NULL:
      break;
    default:
      break;
  }
  return ret;
}
Esempio n. 11
0
static void
request_handshake_rfc6455 (WebSocketClient *self,
                           WebSocketConnection *conn,
                           const gchar *host,
                           const gchar *path)
{
  gchar *key;
  gchar *protocols;
  GString *handshake;
  const gchar *origin;
  guint32 raw[4];
  gsize len;

  raw[0] = g_random_int ();
  raw[1] = g_random_int ();
  raw[2] = g_random_int ();
  raw[3] = g_random_int ();
  G_STATIC_ASSERT (sizeof (raw) == 16);
  key = g_base64_encode ((const guchar *)raw, sizeof (raw));

  /* Save this for verify_handshake_rfc6455() */
  g_free (self->accept_key);
  self->accept_key = _web_socket_complete_accept_key_rfc6455 (key);

  handshake = g_string_new ("");
  g_string_printf (handshake, "GET %s HTTP/1.1\r\n"
                              "Host: %s\r\n"
                              "Upgrade: websocket\r\n"
                              "Connection: Upgrade\r\n"
                              "Sec-WebSocket-Key: %s\r\n"
                              "Sec-WebSocket-Version: 13\r\n",
                              path, host, key);

  /* RFC 6454 talks about 'null' */
  origin = web_socket_connection_get_origin (conn);
  g_string_append_printf (handshake, "Origin: %s\r\n", origin ? origin : "null");

  if (self->possible_protocols)
    {
      protocols = g_strjoinv (", ", self->possible_protocols);
      g_string_append_printf (handshake, "Sec-WebSocket-Protocol: %s\r\n", protocols);
      g_free (protocols);
    }

  include_custom_headers (self, handshake);
  g_string_append (handshake, "\r\n");

  g_free (key);

  len = handshake->len;
  _web_socket_connection_queue (conn, WEB_SOCKET_QUEUE_URGENT,
                                g_string_free (handshake, FALSE), len, 0);
  g_debug ("queued rfc6455 handshake request");
}
Esempio n. 12
0
gboolean xr_client_open(xr_client_conn* conn, const char* uri, GError** err)
{
  GError* local_err = NULL;

  g_return_val_if_fail(conn != NULL, FALSE);
  g_return_val_if_fail(uri != NULL, FALSE);
  g_return_val_if_fail(!conn->is_open, FALSE);
  g_return_val_if_fail(err == NULL || *err == NULL, FALSE);

  xr_trace(XR_DEBUG_CLIENT_TRACE, "(conn=%p, uri=%s)", conn, uri);

  // parse URI format: http://host:8080/RES
  g_free(conn->host);
  g_free(conn->resource);
  conn->host = NULL;
  conn->resource = NULL;
  if (!_parse_uri(uri, &conn->secure, &conn->host, &conn->resource))
  {
    g_set_error(err, XR_CLIENT_ERROR, XR_CLIENT_ERROR_FAILED, "invalid URI format: %s", uri);
    return FALSE;
  }

  // enable/disable TLS
  if (conn->secure)
  {
    g_socket_client_set_tls(conn->client, TRUE);
    g_socket_client_set_tls_validation_flags(conn->client, G_TLS_CERTIFICATE_VALIDATE_ALL & ~G_TLS_CERTIFICATE_UNKNOWN_CA & ~G_TLS_CERTIFICATE_BAD_IDENTITY);
  }
  else
  {
    g_socket_client_set_tls(conn->client, FALSE);
  }

  conn->conn = g_socket_client_connect_to_host(conn->client, conn->host, 80, NULL, &local_err);
  if (local_err)
  {
    g_propagate_prefixed_error(err, local_err, "Connection failed: ");
    return FALSE;
  }

  xr_set_nodelay(g_socket_connection_get_socket(conn->conn));

  conn->http = xr_http_new(G_IO_STREAM(conn->conn));
  g_free(conn->session_id);
  conn->session_id = g_strdup_printf("%08x%08x%08x%08x", g_random_int(), g_random_int(), g_random_int(), g_random_int());
  conn->is_open = 1;

  xr_client_set_http_header(conn, "X-SESSION-ID", conn->session_id);

  return TRUE;
}
Esempio n. 13
0
/**
 * gsm_util_generate_startup_id:
 *
 * Generates a new SM client ID.
 *
 * Return value: an SM client ID.
 **/
char *
gsm_util_generate_startup_id (void)
{
        static int     sequence = -1;
        static guint   rand1 = 0;
        static guint   rand2 = 0;
        static pid_t   pid = 0;
        struct timeval tv;

        /* The XSMP spec defines the ID as:
         *
         * Version: "1"
         * Address type and address:
         *   "1" + an IPv4 address as 8 hex digits
         *   "2" + a DECNET address as 12 hex digits
         *   "6" + an IPv6 address as 32 hex digits
         * Time stamp: milliseconds since UNIX epoch as 13 decimal digits
         * Process-ID type and process-ID:
         *   "1" + POSIX PID as 10 decimal digits
         * Sequence number as 4 decimal digits
         *
         * XSMP client IDs are supposed to be globally unique: if
         * SmsGenerateClientID() is unable to determine a network
         * address for the machine, it gives up and returns %NULL.
         * MATE and KDE have traditionally used a fourth address
         * format in this case:
         *   "0" + 16 random hex digits
         *
         * We don't even bother trying SmsGenerateClientID(), since the
         * user's IP address is probably "192.168.1.*" anyway, so a random
         * number is actually more likely to be globally unique.
         */

        if (!rand1) {
                rand1 = g_random_int ();
                rand2 = g_random_int ();
                pid = getpid ();
        }

        sequence = (sequence + 1) % 10000;
        gettimeofday (&tv, NULL);
        return g_strdup_printf ("10%.04x%.04x%.10lu%.3u%.10lu%.4d",
                                rand1,
                                rand2,
                                (unsigned long) tv.tv_sec,
                                (unsigned) tv.tv_usec,
                                (unsigned long) pid,
                                sequence);
}
Esempio n. 14
0
/* This is called every time a new packet list object instance is created in
 * packet_list_new.  Initialize the list structure's fields here. */
static void
packet_list_init(PacketList *packet_list)
{
	gint i, j;

	/* To check whether an iter belongs to our model. */
	packet_list->stamp = g_random_int();

	packet_list->n_cols = cfile.cinfo.num_cols;
	packet_list->physical_rows = g_ptr_array_new();
	packet_list->visible_rows = g_ptr_array_new();

	packet_list->columnized = FALSE;
	packet_list->sort_id = 0; /* defaults to first column for now */
	packet_list->sort_order = GTK_SORT_ASCENDING;

	packet_list->col_to_text = g_new(int, packet_list->n_cols);
	for (i = 0, j = 0; i < packet_list->n_cols; i++) {
		if (!col_based_on_frame_data(&cfile.cinfo, i)) {
			packet_list->col_to_text[i] = j;
			j++;
		} else
			packet_list->col_to_text[i] = -1;
	}
	packet_list->n_text_cols = j;

#ifdef PACKET_LIST_STATISTICS
	packet_list->const_strings = 0;
#endif
}
Esempio n. 15
0
static void test_qga_sync(gconstpointer fix)
{
    const TestFixture *fixture = fix;
    guint32 v, r = g_random_int();
    QDict *ret;

    /*
     * TODO guest-sync is inherently limited: we cannot distinguish
     * failure caused by reacting to garbage on the wire prior to this
     * command, from failure of this actual command. Clients are
     * supposed to be able to send a raw '\xff' byte to at least
     * re-synchronize the server's parser prior to this command, but
     * we are not in a position to test that here because (at least
     * for now) it causes the server to issue an error message about
     * invalid JSON. Testing of '\xff' handling is done in
     * guest-sync-delimited instead.
     */
    ret = qmp_fd(fixture->fd,
                 "{'execute': 'guest-sync', 'arguments': {'id': %u } }",
                 r);

    g_assert_nonnull(ret);
    qmp_assert_no_error(ret);

    v = qdict_get_int(ret, "return");
    g_assert_cmpint(r, ==, v);

    qobject_unref(ret);
}
Esempio n. 16
0
/* This is called every time a new packet list object instance is created in
 * packet_list_new.  Initialize the list structure's fields here. */
static void
packet_list_init(PacketList *packet_list)
{
	guint i;

	for(i = 0; i < (guint)cfile.cinfo.num_cols; i++) {
		/* We get the packetlist record for all columns */
		packet_list->column_types[i] = G_TYPE_STRING;
	}

	/* To check whether an iter belongs to our model. */
	packet_list->stamp = g_random_int();

	/* Note: We need one extra column to store the entire PacketListRecord */
	packet_list->column_types[i] = G_TYPE_POINTER;
	packet_list->n_columns = (guint)cfile.cinfo.num_cols+1;
	packet_list->physical_rows = g_ptr_array_new();
	packet_list->visible_rows = g_ptr_array_new();

	packet_list->columnized = FALSE;
	packet_list->sort_id = 0; /* defaults to first column for now */
	packet_list->sort_order = GTK_SORT_ASCENDING;

#ifdef NEW_PACKET_LIST_STATISTICS
	packet_list->const_strings = 0;
#endif
}
Esempio n. 17
0
/**
 * @brief Resume (or start) an RTP session
 *
 * @param session_gen The session to resume or start
 * @param range_gen Pointer tp @ref RTSP_Range to start with
 *
 * @todo This function should probably take care of starting eventual
 *       libev events when the scheduler is replaced.
 *
 * This function is used by the PLAY method of RTSP to start or resume
 * a session; since a newly-created session starts as paused, this is
 * the only method available.
 *
 * The use of a pointer to double rather than a double itself is to
 * make it possible to pass this function straight to foreach
 * functions from glib.
 *
 * @internal This function should only be called from g_slist_foreach.
 */
static void rtp_session_resume(gpointer session_gen, gpointer range_gen) {
    RTP_session *session = (RTP_session*)session_gen;
    RTSP_Range *range = (RTSP_Range*)range_gen;

    fnc_log(FNC_LOG_VERBOSE, "Resuming session %p\n", session);

    session->range = range;
    session->start_seq = 1 + session->seq_no;
    session->start_rtptime = g_random_int();
    session->send_time = 0.0;
    session->last_packet_send_time = time(NULL);

    /* Create the new thread pool for the read requests */
    session->fill_pool = g_thread_pool_new(rtp_session_fill_cb, session,
                                           1, true, NULL);

    /* Prefetch frames */
    rtp_session_fill(session);

    ev_periodic_set(&session->transport.rtp_writer,
                    range->playback_time - 0.05,
                    0, NULL);
    ev_periodic_start(session->srv->loop, &session->transport.rtp_writer);
    ev_io_start(session->srv->loop, &session->transport.rtcp_reader);
}
Esempio n. 18
0
static gboolean
add_random_xattrs (int fd, GError **error)
{
  const guint nattrs = MIN (2, g_random_int () % 16);

  for (guint i = 0; i < nattrs; i++)
    {
      guint32 randxattrname_v = g_random_int ();
      g_autofree char *randxattrname = g_strdup_printf ("user.test%u", randxattrname_v);

      if (!set_random_xattr_value (fd, randxattrname, error))
        return FALSE;
    }

  return TRUE;
}
Esempio n. 19
0
static gboolean
_prepare (RestProxyCall *call, GError **error)
{
  OAuthProxy *proxy = NULL;
  OAuthProxyPrivate *priv;
  char *s;
  GHashTable *oauth_params;

  g_object_get (call, "proxy", &proxy, NULL);
  priv = PROXY_GET_PRIVATE (proxy);

  /* We have to make this hash free the strings and thus duplicate when we put
   * them in since when we call call steal_oauth_params that has to duplicate
   * the param names since it removes them from the main hash
   */
  oauth_params = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);

  /* First, steal any OAuth properties in the regular params */
  steal_oauth_params (call, oauth_params);

  g_hash_table_insert (oauth_params, g_strdup ("oauth_version"), g_strdup ("1.0"));

  s = g_strdup_printf ("%"G_GINT64_FORMAT , (gint64) time (NULL));
  g_hash_table_insert (oauth_params, g_strdup ("oauth_timestamp"), s);

  s = g_strdup_printf ("%u", g_random_int ());
  g_hash_table_insert (oauth_params, g_strdup ("oauth_nonce"), s);

  g_hash_table_insert (oauth_params, g_strdup ("oauth_consumer_key"),
                       g_strdup (priv->consumer_key));

  if (priv->token)
    g_hash_table_insert (oauth_params, g_strdup ("oauth_token"), g_strdup (priv->token));

  switch (priv->method) {
  case PLAINTEXT:
    g_hash_table_insert (oauth_params, g_strdup ("oauth_signature_method"), g_strdup ("PLAINTEXT"));
    s = sign_plaintext (priv);
    break;
  case HMAC_SHA1:
    g_hash_table_insert (oauth_params, g_strdup ("oauth_signature_method"), g_strdup ("HMAC-SHA1"));
    s = sign_hmac (proxy, call, oauth_params);
    break;
  }
  g_hash_table_insert (oauth_params, g_strdup ("oauth_signature"), s);

  s = make_authorized_header (oauth_params);
  if (priv->oauth_echo) {
    rest_proxy_call_add_header (call, "X-Verify-Credentials-Authorization", s);
    rest_proxy_call_add_param (call, "X-Auth-Service-Provider", priv->service_url);
  } else {
    rest_proxy_call_add_header (call, "Authorization", s);
  }
  g_free (s);
  g_hash_table_destroy (oauth_params);

  g_object_unref (proxy);

  return TRUE;
}
Esempio n. 20
0
static void
trace_view_store_init (TraceViewStore *trace_view_store)
{
	trace_view_store->n_columns	= TRACE_VIEW_STORE_N_COLUMNS;

	trace_view_store->column_types[0] = G_TYPE_UINT;	/* INDEX */
	trace_view_store->column_types[1] = G_TYPE_UINT;	/* CPU	*/
	trace_view_store->column_types[2] = G_TYPE_STRING;	/* TS	*/
	trace_view_store->column_types[3] = G_TYPE_STRING;	/* COMM */
	trace_view_store->column_types[4] = G_TYPE_UINT;	/* PID */
	trace_view_store->column_types[5] = G_TYPE_STRING;	/* LAT */
	trace_view_store->column_types[6] = G_TYPE_STRING;	/* EVENT */
	trace_view_store->column_types[7] = G_TYPE_STRING;	/* INFO */

	g_assert (TRACE_VIEW_STORE_N_COLUMNS == 8);

	trace_view_store->num_rows = 0;
	trace_view_store->rows	= NULL;

	trace_view_store->spin = NULL;
	trace_view_store->page = 1;
	trace_view_store->pages = 1;
	trace_view_store->rows_per_page = TRACE_VIEW_DEFAULT_MAX_ROWS;
	trace_view_store->num_rows = 0;
	trace_view_store->start_row = 0;
	trace_view_store->visible_rows = 0;
	trace_view_store->actual_rows = 0;

	/* Set all columns visible */
	trace_view_store->visible_column_mask = (1 << TRACE_VIEW_STORE_N_COLUMNS) - 1;

	trace_view_store->stamp = g_random_int();	/* Random int to check whether an iter belongs to our model */

}
Esempio n. 21
0
static bool
vorbis_encoder_tag(struct encoder *_encoder, const struct tag *tag,
		   G_GNUC_UNUSED GError **error)
{
	struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder;
	vorbis_comment comment;

	/* write the vorbis_comment object */

	vorbis_comment_init(&comment);
	copy_tag_to_vorbis_comment(&comment, tag);

	/* reset ogg_stream_state and begin a new stream */

	ogg_stream_reset_serialno(&encoder->os, g_random_int());

	/* send that vorbis_comment to the ogg_stream_state */

	vorbis_encoder_headerout(encoder, &comment);
	vorbis_comment_clear(&comment);

	/* the next vorbis_encoder_read() call should flush the
	   ogg_stream_state */

	encoder->flush = true;

	return true;
}
Esempio n. 22
0
static void
gnc_tree_model_owner_init (GncTreeModelOwner *model)
{
    GncTreeModelOwnerPrivate *priv;
    gboolean red;

    ENTER("model %p", model);
    while (model->stamp == 0)
    {
        model->stamp = g_random_int ();
    }

    red = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);

    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
    priv->book       = NULL;
    priv->owner_list = NULL;
    priv->owner_type = GNC_OWNER_NONE;
    priv->negative_color = red ? "red" : NULL;

    gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
                          gnc_tree_model_owner_update_color,
                          model);

    LEAVE(" ");
}
Esempio n. 23
0
static void
testcase (void)
{
  GThread *threads[THREADS];
  int i;

  g_thread_init (NULL);

#ifdef TEST_EMULATED_FUTEX
  _g_futex_thread_init ();
  #define SUFFIX "-emufutex"

  /* ensure that we are using the emulated futex by checking
   * (at compile-time) for the existance of 'g_futex_mutex'
   */
  g_assert (g_futex_mutex != NULL);
#else
  #define SUFFIX ""
#endif

  for (i = 0; i < LOCKS; i++)
    bits[i] = g_random_int () % 32;

  for (i = 0; i < THREADS; i++)
    threads[i] = g_thread_create (thread_func, NULL, TRUE, NULL);

  for (i = 0; i < THREADS; i++)
    g_thread_join (threads[i]);

  for (i = 0; i < LOCKS; i++)
    {
      g_assert (owners[i] == NULL);
      g_assert (locks[i] == 0);
    }
}
Esempio n. 24
0
static void test_qga_sync_delimited(gconstpointer fix)
{
    const TestFixture *fixture = fix;
    guint32 v, r = g_random_int();
    unsigned char c;
    QDict *ret;
    gchar *cmd;

    cmd = g_strdup_printf("%c{'execute': 'guest-sync-delimited',"
                          " 'arguments': {'id': %u } }", 0xff, r);
    qmp_fd_send(fixture->fd, cmd);
    g_free(cmd);

    v = read(fixture->fd, &c, 1);
    g_assert_cmpint(v, ==, 1);
    g_assert_cmpint(c, ==, 0xff);

    ret = qmp_fd_receive(fixture->fd);
    g_assert_nonnull(ret);
    qmp_assert_no_error(ret);

    v = qdict_get_int(ret, "return");
    g_assert_cmpint(r, ==, v);

    QDECREF(ret);
}
Esempio n. 25
0
static gchar *generate_password(void)
{
	SMD5 *md5;
	time_t t;
	gchar date_str[15];
	const gchar *hostname;
	guint32 salt;
	gchar *b64;

	time(&t);
	strftime(date_str, sizeof(date_str), "%Y%m%d%H%M%S", localtime(&t));

	hostname = get_domain_name();

	salt = g_random_int();

	md5 = s_gnet_md5_new_incremental();
	s_gnet_md5_update(md5, (guchar *)date_str, strlen(date_str));
	s_gnet_md5_update(md5, (const guchar *)hostname, strlen(hostname));
	s_gnet_md5_update(md5, (guchar *)&salt, sizeof(salt));
	s_gnet_md5_final(md5);

	b64 = g_malloc(S_GNET_MD5_HASH_LENGTH * 2);
	base64_encode(b64, (guchar *)s_gnet_md5_get_digest(md5), S_GNET_MD5_HASH_LENGTH);
	debug_print("generate_password: b64(%s %s %u) = %s\n", date_str, hostname, salt, b64);
	b64[12] = '\0';
	debug_print("generate_password: password = %s\n", b64);

	s_gnet_md5_delete(md5);

	return b64;
}
Esempio n. 26
0
int
main ()
{
  int i;

  #ifdef SYMBIAN
  g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
  g_set_print_handler(mrtPrintHandler);
  #endif /*SYMBIAN*/
	  

  for (i = 0; i < SIZE; i++)
    array[i] = g_random_int ();

  g_qsort_with_data (array, SIZE, sizeof (guint32), sort, NULL);

  for (i = 0; i < SIZE - 1; i++)
    g_assert (array[i] <= array[i+1]);

  /* 0 elemenents is a valid case */
  g_qsort_with_data (array, 0, sizeof (guint32), sort, NULL);

#ifdef SYMBIAN
  testResultXml("qsort-test");
#endif /* EMULATOR */
  return 0;
}
Esempio n. 27
0
static void finish_set_timezone(GDBusMethodInvocation *invocation, struct method_call_data *data) {
	gchar link[PATH_MAX], tmp[PATH_MAX];

	if (snprintf(link, sizeof link, "%s%s%s", LOCALTIME_TO_ZONEINFO_PATH, ZONEINFO_PATH,
		     data->set_timezone.timezone) >= sizeof link)
		goto error;

	if (snprintf(tmp, sizeof tmp, "%s.%06u", LOCALTIME_PATH, g_random_int()) >= sizeof tmp)
		goto error;

	if (symlink(link, tmp))
		goto error;

	set_default_file_context(tmp, link);

	if (rename(tmp, LOCALTIME_PATH)) {
		unlink(tmp);
		goto error;
	}

	emit_property_change(g_dbus_method_invocation_get_connection(invocation),
			     "Timezone", g_variant_new_string(data->set_timezone.timezone));
	return_success(invocation);

	update_kernel_utc_offset();

	/* RTC in local needs to be set for the new timezone */
	if (is_rtc_local())
		start_hwclock_call(FALSE, FALSE, FALSE, NULL, NULL, NULL);

	return;
error:
	return_error(invocation, G_DBUS_ERROR_FAILED, "Failed to update %s", LOCALTIME_PATH);
}
int janus_set_pid(void){
	for(guint32 i = 0; i < JANUS_PID_SIZE; i++)
		if(PID[i]) return 0;

	guint32 rand = g_random_int();
	return snprintf(PID, JANUS_PID_SIZE, "%u", rand);
}
Esempio n. 29
0
/* Make a temporary file name. The format parameter is something like "%s.jpg" 
 * and will be expanded to something like "/tmp/vips-12-34587.jpg".
 *
 * You need to free the result. 
 */
char *
vips__temp_name( const char *format )
{
	static int serial = 0;

	char file[FILENAME_MAX];
	char file2[FILENAME_MAX];
	char *name;

	vips_snprintf( file, FILENAME_MAX, "vips-%d-%u", 
		serial++, g_random_int() );
	vips_snprintf( file2, FILENAME_MAX, format, file );
	name = g_build_filename( vips__temp_dir(), file2, NULL );

	/* We could use something like g_mkstemp() to guarantee uniqueness
	 * across processes, but the extra FS calls can be difficult for 
	 * selinux.
	 *
	 * g_random_int() should be safe enough -- it's seeded from time(), so
	 * it ought not to collide often -- and on linux at least we never 
	 * actually use these filenames in the filesystem anyway.
	 */

	return( name );
}
/* Ids are generated as follows:
 * 
 * the upper 6 bytes are the time in seconds and microseconds
 * 
 * the lower 2 bytes are a random number
 * 
 * */
static long long int gen_id(const GTimeVal *tv)
{
  long long int now = (tv->tv_sec * 1000000 + tv->tv_usec) << 16;
  long long int rnd = ((long long int)g_random_int()) & 0xFFFF;
    
  return now | rnd;
}