static GBytes * build_environment (GHashTable *os_release) { /* * We don't include entirety of os-release into the * environment for the login.html page. There could * be unexpected things in here. * * However since we are displaying branding based on * the OS name variant flavor and version, including * the corresponding information is not a leak. */ static const gchar *release_fields[] = { "NAME", "ID", "PRETTY_NAME", "VARIANT", "VARIANT_ID", "CPE_NAME", }; static const gchar *prefix = "\n <script>\nvar environment = "; static const gchar *suffix = ";\n </script>"; GByteArray *buffer; GBytes *bytes; JsonObject *object; const gchar *value; gchar *hostname; JsonObject *osr; gint i; object = json_object_new (); add_page_to_environment (object); hostname = g_malloc0 (HOST_NAME_MAX + 1); gethostname (hostname, HOST_NAME_MAX); hostname[HOST_NAME_MAX] = '\0'; json_object_set_string_member (object, "hostname", hostname); g_free (hostname); if (os_release) { osr = json_object_new (); for (i = 0; i < G_N_ELEMENTS (release_fields); i++) { value = g_hash_table_lookup (os_release, release_fields[i]); if (value) json_object_set_string_member (osr, release_fields[i], value); } json_object_set_object_member (object, "os-release", osr); } add_oauth_to_environment (object); bytes = cockpit_json_write_bytes (object); json_object_unref (object); buffer = g_bytes_unref_to_array (bytes); g_byte_array_prepend (buffer, (const guint8 *)prefix, strlen (prefix)); g_byte_array_append (buffer, (const guint8 *)suffix, strlen (suffix)); return g_byte_array_free_to_bytes (buffer); }
WSLUA_METHOD ByteArray_prepend(lua_State* L) { /* Prepend a ByteArray to this ByteArray */ #define WSLUA_ARG_ByteArray_prepend_PREPENDED 2 /* Array to be prepended */ ByteArray ba = checkByteArray(L,1); ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray_prepend_PREPENDED); g_byte_array_prepend(ba,ba2->data,ba2->len); return 0; }
WSLUA_METHOD ByteArray_prepend(lua_State* L) { /* Prepend a ByteArray to this ByteArray */ #define WSLUA_ARG_ByteArray_prepend_PREPENDED 2 /* Array to be prepended */ ByteArray ba = checkByteArray(L,1); ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray_prepend_PREPENDED); if (! (ba && ba2) ) WSLUA_ERROR(ByteArray_prepend,"Both arguments must be ByteArrays"); g_byte_array_prepend(ba,ba2->data,ba2->len); return 0; }
void mbus_data_as_string( MObject * mdata, GString * buf ) { GByteArray * tmp = g_byte_array_new(); M_OBJECT_ASSERT( mdata, MDATA ); base64encode( M_DATA( mdata )->array, tmp ); g_byte_array_prepend( tmp, ( guchar * ) "<", 1 ); g_byte_array_append( tmp, ( guchar * ) ">", 1 ); g_string_append_len( buf, ( gchar * ) tmp->data, tmp->len ); g_byte_array_free( tmp, TRUE ); }
const GByteArray * fb_mqtt_message_bytes(FbMqttMessage *msg) { FbMqttMessagePrivate *priv; guint i; guint8 byte; guint8 sbuf[4]; guint32 size; g_return_val_if_fail(FB_IS_MQTT_MESSAGE(msg), NULL); priv = msg->priv; i = 0; size = priv->bytes->len - priv->offset; do { if (G_UNLIKELY(i >= G_N_ELEMENTS(sbuf))) { return NULL; } byte = size % 128; size /= 128; if (size > 0) { byte |= 128; } sbuf[i++] = byte; } while (size > 0); fb_mqtt_message_reset(msg); g_byte_array_prepend(priv->bytes, sbuf, i); byte = ((priv->type & 0x0F) << 4) | (priv->flags & 0x0F); g_byte_array_prepend(priv->bytes, &byte, sizeof byte); priv->pos = (i + 1) * (sizeof byte); return priv->bytes; }
static gboolean gst_dshowaudiosrc_push_buffer (byte * buffer, long size, byte * src_object, UINT64 start, UINT64 stop) { GstDshowAudioSrc *src = GST_DSHOWAUDIOSRC (src_object); if (!buffer || size == 0 || !src) { return FALSE; } g_mutex_lock (src->gbarray_lock); g_byte_array_prepend (src->gbarray, (guint8 *) buffer, size); g_mutex_unlock (src->gbarray_lock); return TRUE; }
static gboolean gst_dshowaudiosrc_push_buffer (guint8 * buffer, guint size, gpointer src_object, GstClockTime duration) { GstDshowAudioSrc *src = GST_DSHOWAUDIOSRC (src_object); if (!buffer || size == 0 || !src) { return FALSE; } g_mutex_lock (src->gbarray_lock); g_byte_array_prepend (src->gbarray, buffer, size); g_mutex_unlock (src->gbarray_lock); return TRUE; }
static GBytes * build_environment (GHashTable *os_release) { static const gchar *prefix = "\n <script>\nvar environment = "; static const gchar *suffix = ";\n </script>"; GByteArray *buffer; GHashTableIter iter; GBytes *bytes; JsonObject *object; const gchar *title; gchar *hostname; gpointer key, value; JsonObject *osr; object = json_object_new (); title = cockpit_conf_string ("WebService", "LoginTitle"); if (title) json_object_set_string_member (object, "title", title); hostname = g_malloc0 (HOST_NAME_MAX + 1); gethostname (hostname, HOST_NAME_MAX); hostname[HOST_NAME_MAX] = '\0'; json_object_set_string_member (object, "hostname", hostname); g_free (hostname); if (os_release) { osr = json_object_new (); g_hash_table_iter_init (&iter, os_release); while (g_hash_table_iter_next (&iter, &key, &value)) json_object_set_string_member (osr, key, value); json_object_set_object_member (object, "os-release", osr); } add_oauth_to_environment (object); bytes = cockpit_json_write_bytes (object); json_object_unref (object); buffer = g_bytes_unref_to_array (bytes); g_byte_array_prepend (buffer, (const guint8 *)prefix, strlen (prefix)); g_byte_array_append (buffer, (const guint8 *)suffix, strlen (suffix)); return g_byte_array_free_to_bytes (buffer); }
static gboolean rtp_interleaved_send_pkt(RTSP_Client *rtsp, GByteArray *buffer, int channel) { const uint16_t ne_n = htons((uint16_t)buffer->len); const uint8_t interleaved_preamble[4] = { '$', channel, 0, 0 }; /* This might not be the best choice here, to be honest… a * scatter-gather approach might work best, but for now, let's * stick with this… */ g_byte_array_prepend(buffer, interleaved_preamble, 4); memcpy(&buffer->data[2], &ne_n, sizeof(uint16_t)); /* pass the bucket down; it might be direct RTSP or HTTP-tunnelled */ rtsp->write_data(rtsp, buffer); /* no stats accounting because the write_data function will take care of it */ return TRUE; }
static gboolean hon_send_packet(PurpleConnection* gc,guint16 packet_id,const gchar* paramstring , ...){ gboolean res; guint32 intparam; guint8 byteparam; const gchar* stringparam; guint16 short_len; va_list marker; hon_account* hon = gc->proto_data; GByteArray* buffer = g_byte_array_new(); buffer = g_byte_array_append(buffer,(const guint8*)&packet_id,2); va_start( marker, paramstring ); while (paramstring != 0x00 && *paramstring != 0x00) { switch (*paramstring){ case 'i': intparam = va_arg( marker, int); buffer = g_byte_array_append(buffer,(const guint8*)&intparam,4); break; case 's': stringparam = va_arg( marker, const gchar*); buffer = g_byte_array_append(buffer,(const guint8*)stringparam,strlen(stringparam)+1); break; case 'b': byteparam = va_arg( marker, int); buffer = g_byte_array_append(buffer,&byteparam,1); break; } paramstring++; } va_end(marker); short_len = buffer->len; buffer = g_byte_array_prepend(buffer,&short_len,2); res = buffer->len == do_write(hon->fd,buffer->data,buffer->len); g_byte_array_free(buffer,TRUE); return res; }
int main (int argc, char *argv[]) { GByteArray *gbarray; gint i; int user_data = 1; #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); #endif /*SYMBIAN*/ gbarray = g_byte_array_new (); g_byte_array_prepend(gbarray,(guint8 *)"c",1); g_byte_array_prepend(gbarray,(guint8 *)"b",1); g_byte_array_prepend(gbarray,(guint8 *)"a",1); g_assert(gbarray->data[0] == 'a'); g_assert(gbarray->data[1] == 'b'); g_assert(gbarray->data[2] == 'c'); g_byte_array_remove_index(gbarray,1); g_assert(gbarray->data[0] == 'a'); g_assert(gbarray->data[1] == 'c'); g_byte_array_append(gbarray,(guint8 *)"b",1); g_byte_array_remove_index_fast(gbarray,1); g_assert(gbarray->data[1] == 'b'); g_byte_array_append(gbarray,(guint8 *)"c",1); g_byte_array_append(gbarray,(guint8 *)"d",1); g_byte_array_append(gbarray,(guint8 *)"e",1); g_byte_array_remove_range(gbarray,0,3); g_assert(gbarray->data[0] == 'd'); g_assert(gbarray->data[1] == 'e'); g_byte_array_set_size(gbarray,10); g_assert(gbarray->len == 10); g_byte_array_free(gbarray,TRUE); gbarray = g_byte_array_sized_new (10); g_assert(gbarray->len == 0); g_byte_array_append(gbarray,(guint8 *)"c",1); g_byte_array_append(gbarray,(guint8 *)"b",1); g_byte_array_append(gbarray,(guint8 *)"a",1); g_byte_array_sort(gbarray,ascending); g_assert(gbarray->data[0] == 'a'); g_assert(gbarray->data[1] == 'b'); g_assert(gbarray->data[2] == 'c'); g_byte_array_sort_with_data(gbarray,sort_func,&user_data); g_assert(gbarray->data[0] == 'c'); g_assert(gbarray->data[1] == 'b'); g_assert(gbarray->data[2] == 'a'); g_byte_array_free(gbarray,TRUE); #if SYMBIAN testResultXml("byte_array_test"); #endif /* EMULATOR */ return 0; }