static void test_charset_conversion (const char *datadir, const char *base, const char *from, const char *to) { const char *what = "GMimeFilterCharset"; GByteArray *actual, *expected; GMimeStream *stream; GMimeFilter *filter; char *path, *name; testsuite_check ("%s (%s %s -> %s)", what, base, from, to); actual = g_byte_array_new (); stream = g_mime_stream_mem_new_with_byte_array (actual); g_mime_stream_mem_set_owner ((GMimeStreamMem *) stream, FALSE); filter = g_mime_filter_charset_new (from, to); name = g_strdup_printf ("%s.%s.txt", base, from); path = g_build_filename (datadir, name, NULL); pump_data_through_filter (filter, path, stream, TRUE, TRUE); g_mime_filter_reset (filter); g_object_unref (stream); g_object_unref (filter); g_free (path); g_free (name); name = g_strdup_printf ("%s.%s.txt", base, to); path = g_build_filename (datadir, name, NULL); expected = read_all_bytes (path, TRUE); g_free (path); g_free (name); if (actual->len != expected->len) { testsuite_check_failed ("%s failed: stream lengths do not match: expected=%u; actual=%u", what, expected->len, actual->len); goto error; } if (memcmp (actual->data, expected->data, actual->len) != 0) { testsuite_check_failed ("%s failed: stream contents do not match", what); goto error; } testsuite_check_passed (); error: g_byte_array_free (expected, TRUE); g_byte_array_free (actual, TRUE); }
static void* register_thread (MonoThreadInfo *info, gpointer baseptr) { size_t stsize = 0; guint8 *staddr = NULL; int small_id = mono_thread_info_register_small_id (); gboolean result; mono_thread_info_set_tid (info, mono_native_thread_id_get ()); info->small_id = small_id; mono_os_sem_init (&info->resume_semaphore, 0); /*set TLS early so SMR works */ mono_native_tls_set_value (thread_info_key, info); THREADS_DEBUG ("registering info %p tid %p small id %x\n", info, mono_thread_info_get_tid (info), info->small_id); if (threads_callbacks.thread_register) { if (threads_callbacks.thread_register (info, baseptr) == NULL) { // g_warning ("thread registation failed\n"); mono_native_tls_set_value (thread_info_key, NULL); g_free (info); return NULL; } } mono_thread_info_get_stack_bounds (&staddr, &stsize); g_assert (staddr); g_assert (stsize); info->stack_start_limit = staddr; info->stack_end = staddr + stsize; info->stackdata = g_byte_array_new (); mono_threads_suspend_register (info); /* Transition it before taking any locks or publishing itself to reduce the chance of others witnessing a detached thread. We can reasonably expect that until this thread gets published, no other thread will try to manipulate it. */ mono_threads_transition_attach (info); mono_thread_info_suspend_lock (); /*If this fail it means a given thread has been registered twice, which doesn't make sense. */ result = mono_thread_info_insert (info); g_assert (result); mono_thread_info_suspend_unlock (); return info; }
char * Downloader::GetResponseText (const char *partname, gint64 *size) { LOG_DOWNLOADER ("Downloader::GetResponseText (%s, %p)\n", partname, size); TextStream *stream; char buffer[4096]; GByteArray *buf; struct stat st; ssize_t nread; char *data; char *path; if (!(path = GetDownloadedFilename (partname))) return NULL; if (g_stat (path, &st) == -1) { g_free (path); return NULL; } if (st.st_size > 0) { stream = new TextStream (); if (!stream->OpenFile (path, true)) { delete stream; g_free (path); return NULL; } g_free (path); buf = g_byte_array_new (); while ((nread = stream->Read (buffer, sizeof (buffer))) > 0) g_byte_array_append (buf, (const guint8 *) buffer, nread); *size = buf->len; g_byte_array_append (buf, (const guint8 *) "", 1); data = (char *) buf->data; g_byte_array_free (buf, false); delete stream; } else { data = g_strdup (""); *size = 0; } return data; }
/* Data */ MObject * mbus_data_new( const guint8 * str, guint len, gboolean decode ) { M_OBJECT_ALLOC( MData, MDATA ); if ( str ) { if ( decode ) { GByteArray * tmp = g_byte_array_sized_new( len ); me->array = g_byte_array_new(); g_byte_array_append( tmp, str, len ); base64decode( tmp, me->array ); g_byte_array_free( tmp, TRUE ); } else { me->array = g_byte_array_sized_new( len ); g_byte_array_append( me->array, str, len ); } } else me->array = g_byte_array_new(); return obj; }
static void cockpit_auth_init (CockpitAuth *self) { gint fd; self->key = g_byte_array_new (); g_byte_array_set_size (self->key, 128); fd = g_open ("/dev/urandom", O_RDONLY, 0); if (fd < 0 || read (fd, self->key->data, 128) != 128) g_error ("couldn't read random key, startup aborted"); close (fd); self->authenticated = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, cockpit_authenticated_free); }
static GByteArray* sqlx_encode_ASN1(struct asn_TYPE_descriptor_s *descr, void *s, GError **err) { asn_enc_rval_t rv; GByteArray *encoded = g_byte_array_new(); rv = der_encode(descr, s, metautils_asn1c_write_gba, encoded); if (0 >= rv.encoded) { g_byte_array_free(encoded, TRUE); GSETERROR(err, "TableSequence encoding error : %s", rv.failed_type->name); return NULL; } return encoded; }
GByteArray * g_byte_array_new_take (guint8 *data, gsize len) { GByteArray *array; array = g_byte_array_new (); g_assert (array->data == NULL); g_assert (array->len == 0); array->data = data; array->len = len; return array; }
/** * @brief Write a GString to the RTSP socket of the client * * @param client The client to write the data to * @param string The data to send out as string * * @note after calling this function, the @p string object should no * longer be referenced by the code path. */ void rtsp_write_string(RTSP_Client *client, GString *string) { /* Copy the GString into a GByteArray; we can avoid copying the data since both are transparent structures with a g_malloc'd data pointer. */ GByteArray *outpkt = g_byte_array_new(); outpkt->data = (guint8*)string->str; outpkt->len = string->len; /* make sure you don't free the actual data pointer! */ g_string_free(string, false); client->write_data(client, outpkt); }
static void ipc_commit(Input *input){ g_assert(input->buffer->len > 0 && input->buffer->data[input->buffer->len-1] == 0); window_present(main_window_get_window(), TRUE); if(input->buffer->len > MAX_BUFFER_SIZE){ g_byte_array_free(input->buffer, TRUE); input->buffer=g_byte_array_new(); }else{ g_byte_array_set_size(input->buffer, 0); } /* Call any methods or ect that you need to handle the input. * 'input->buffer' should be handled just like any element of argv. */ }
/** * e2k_entryid_generate_local: * @exchange_dn: the Exchange 5.5-style DN of the local user * * Constructs an ENTRYID value that can be used as a MAPI * recipient (eg, for a message forwarding server-side rule), * corresponding to the local user identified by @exchange_dn. * * Return value: the recipient ENTRYID **/ GByteArray * e2k_entryid_generate_local (const char *exchange_dn) { GByteArray *entryid; entryid = g_byte_array_new (); e2k_rule_append_uint32 (entryid, 0); g_byte_array_append (entryid, MAPI_LOCAL_UID, sizeof (MAPI_LOCAL_UID)); e2k_rule_append_uint16 (entryid, 1); e2k_rule_append_uint16 (entryid, 0); e2k_rule_append_string (entryid, exchange_dn); return entryid; }
static int generate_response(void *user_data) { struct pbap_session *pbap = user_data; GSList *sorted; GSList *l; uint16_t max = pbap->params->maxlistcount; DBG(""); if (max == 0) { /* Ignore all other parameter and return PhoneBookSize */ uint16_t size = htons(g_slist_length(pbap->cache.entries)); pbap->obj->aparams = g_byte_array_new(); pbap->obj->aparams = append_aparam_header(pbap->obj->aparams, PHONEBOOKSIZE_TAG, &size); return 0; } /* * Don't free the sorted list content: this list contains * only the reference for the "real" cache entry. */ sorted = sort_entries(pbap->cache.entries, pbap->params->order, pbap->params->searchattrib, (const char *) pbap->params->searchval); /* Computing offset considering first entry of the phonebook */ l = g_slist_nth(sorted, pbap->params->liststartoffset); pbap->obj->buffer = g_string_new(VCARD_LISTING_BEGIN); for (; l && max; l = l->next, max--) { const struct cache_entry *entry = l->data; char *escaped_name = g_markup_escape_text(entry->name, -1); g_string_append_printf(pbap->obj->buffer, VCARD_LISTING_ELEMENT, entry->handle, escaped_name); g_free(escaped_name); } pbap->obj->buffer = g_string_append(pbap->obj->buffer, VCARD_LISTING_END); g_slist_free(sorted); return 0; }
static gboolean set_ical_from_mime_part (CamelMimePart * part, ScalixObject * object) { CamelDataWrapper *content; CamelStream *stream; GByteArray *data; icalcomponent *icomp = NULL; icalcomponent *subcomp = NULL; ScalixAppointmentPrivate *priv; priv = SCALIX_APPOINTMENT_GET_PRIVATE (SCALIX_APPOINTMENT (object)); content = camel_medium_get_content_object (CAMEL_MEDIUM (part)); data = g_byte_array_new (); stream = camel_stream_mem_new_with_byte_array (data); camel_data_wrapper_decode_to_stream (content, stream); if (data == NULL || data->data == NULL) { g_print ("Found corrupt ical data\n"); return FALSE; } icomp = icalparser_parse_string ((const char *) data->data); if (icalcomponent_isa (icomp) != ICAL_VCALENDAR_COMPONENT) { icalcomponent_free (icomp); return FALSE; } /* Grab the timezone if any */ subcomp = icalcomponent_get_first_component (icomp, ICAL_VTIMEZONE_COMPONENT); if (subcomp != NULL) { icaltimezone *zone; zone = icaltimezone_new (); icaltimezone_set_component (zone, subcomp); priv->timezone = zone; } /* Grab the main VEVENT */ subcomp = icalcomponent_get_first_component (icomp, ICAL_VEVENT_COMPONENT); e_cal_component_set_icalcomponent (E_CAL_COMPONENT (object), subcomp); return TRUE; }
GError * metautils_message_extract_body_gba(MESSAGE msg, GByteArray **result) { EXTRA_ASSERT(result != NULL); gsize bsize = 0; *result = NULL; void *b = metautils_message_get_BODY(msg, &bsize); if (!b) return NEWERROR(CODE_BAD_REQUEST, "No body"); *result = g_byte_array_new(); if (bsize > 0) g_byte_array_append(*result, b, bsize); return NULL; }
WSLUA_METAMETHOD ByteArray__concat(lua_State* L) { /* Concatenate two ByteArrays */ #define WSLUA_ARG_ByteArray__cat_FIRST 1 /* First array */ #define WSLUA_ARG_ByteArray__cat_SECOND 2 /* Second array */ ByteArray ba1 = checkByteArray(L,WSLUA_ARG_ByteArray__cat_FIRST); ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray__cat_SECOND); ByteArray ba; ba = g_byte_array_new(); g_byte_array_append(ba,ba1->data,ba1->len); g_byte_array_append(ba,ba2->data,ba2->len); pushByteArray(L,ba); WSLUA_RETURN(1); /* The new composite ByteArray. */ }
FbMqttMessage * fb_mqtt_message_new(FbMqttMessageType type, FbMqttMessageFlags flags) { FbMqttMessage *msg; FbMqttMessagePrivate *priv; msg = g_object_new(FB_TYPE_MQTT_MESSAGE, NULL); priv = msg->priv; priv->type = type; priv->flags = flags; priv->bytes = g_byte_array_new(); priv->local = TRUE; return msg; }
GByteArray* metautils_encode_lines(gchar **strv) { GByteArray *gba = g_byte_array_new(); if (strv) { gchar **p; for (p=strv; *p ;++p) { g_byte_array_append(gba, (guint8*)*p, strlen(*p)); g_byte_array_append(gba, (guint8*)"\n", 1); } } g_byte_array_append(gba, (guint8*)"", 1); g_byte_array_set_size(gba, gba->len - 1); return gba; }
/*! \brief Sends a packet to start the datalog streaming from the ECU */ G_MODULE_EXPORT void start_streaming(void) { OutputData *output = NULL; GByteArray *payload = NULL; guint8 byte = 1;/* Start streaming */ ENTER(); output = initialize_outputdata_f(); payload = g_byte_array_new(); g_byte_array_append(payload,&byte,1); DATA_SET(output->data,"payload_id",GINT_TO_POINTER(REQUEST_SET_ASYNC_DATALOG_TYPE)); DATA_SET(output->data,"payload_data_array",payload); io_cmd_f("basic_payload_pkt",output); EXIT(); return; }
static void cockpit_request_start (CockpitWebServer *self, GIOStream *io, gboolean first) { GSocketConnection *connection; CockpitRequest *request; gboolean input = TRUE; GSocket *socket; request = g_new0 (CockpitRequest, 1); request->web_server = self; request->io = g_object_ref (io); request->buffer = g_byte_array_new (); /* Right before a successive request, EOF is not unexpected */ request->eof_okay = !first; request->timeout = g_timeout_source_new_seconds (cockpit_webserver_request_timeout); g_source_set_callback (request->timeout, on_request_timeout, request, NULL); g_source_attach (request->timeout, self->main_context); if (first) { connection = G_SOCKET_CONNECTION (io); socket = g_socket_connection_get_socket (connection); g_socket_set_blocking (socket, FALSE); if (self->certificate) { request->source = g_socket_create_source (g_socket_connection_get_socket (connection), G_IO_IN, NULL); g_source_set_callback (request->source, (GSourceFunc)on_socket_input, request, NULL); g_source_attach (request->source, self->main_context); /* Wait on reading input */ input = FALSE; } } /* Owns the request */ g_hash_table_add (self->requests, request); if (input) start_request_input (request); }
static void test_enriched (const char *datadir, const char *input, const char *output) { const char *what = "GMimeFilterEnriched"; GByteArray *actual, *expected; GMimeStream *stream; GMimeFilter *filter; char *path; testsuite_check ("%s (%s)", what, input); actual = g_byte_array_new (); stream = g_mime_stream_mem_new_with_byte_array (actual); g_mime_stream_mem_set_owner ((GMimeStreamMem *) stream, FALSE); filter = g_mime_filter_enriched_new (0); path = g_build_filename (datadir, input, NULL); pump_data_through_filter (filter, path, stream, TRUE, TRUE); g_mime_filter_reset (filter); g_object_unref (stream); g_object_unref (filter); g_free (path); path = g_build_filename (datadir, output, NULL); expected = read_all_bytes (path, TRUE); g_free (path); if (actual->len != expected->len) { testsuite_check_failed ("%s failed: stream lengths do not match: expected=%u; actual=%u", what, expected->len, actual->len); printf ("enriched: -->%.*s<--\n", (int) actual->len, (char *) actual->data); goto error; } if (memcmp (actual->data, expected->data, actual->len) != 0) { testsuite_check_failed ("%s failed: stream contents do not match", what); goto error; } testsuite_check_passed (); error: g_byte_array_free (expected, TRUE); g_byte_array_free (actual, TRUE); }
/** * g_byte_array_new_take: * @data: (array length=len): byte data for the array * @len: length of @data * * Create byte array containing the data. The data will be owned by the array * and will be freed with g_free(), i.e. it could be allocated using g_strdup(). * * Since: 2.32 * * Returns: (transfer full): a new #GByteArray */ GByteArray * g_byte_array_new_take (guint8 *data, gsize len) { GByteArray *array; GRealArray *real; array = g_byte_array_new (); real = (GRealArray *)array; g_assert (real->data == NULL); g_assert (real->len == 0); real->data = data; real->len = len; return array; }
static gpointer gdk_pixbuf__gdip_image_begin_load (GdkPixbufModuleSizeFunc size_func, GdkPixbufModulePreparedFunc prepared_func, GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) { GdipContext *context = g_new0 (GdipContext, 1); context->size_func = size_func; context->prepared_func = prepared_func; context->updated_func = updated_func; context->user_data = user_data; context->buffer = g_byte_array_new (); return context; }
static GByteArray* create_assertion_key (const gchar *purpose, const gchar *peer) { GByteArray *key; g_return_val_if_fail (purpose, NULL); key = g_byte_array_new (); g_byte_array_append (key, (void*)purpose, strlen (purpose)); if (peer != NULL) { g_byte_array_append (key, (void*)"\0", 1); g_byte_array_append (key, (void*)peer, strlen (peer)); } return key; }
GpStatus GdipPathIterNextMarkerPath (GpPathIterator *iterator, int *resultCount, GpPath *path) { int index = 0; BYTE type; GpPointF point; if (!iterator || !resultCount) return InvalidParameter; /* There are no paths or markers or we are done with all the markers */ if (!path || !iterator->path || (iterator->path->count == 0) || (iterator->markerPosition == iterator->path->count)) { *resultCount = 0; return Ok; } /* Clear the existing values from path */ if (path->count > 0) { g_array_free (path->points, TRUE); g_byte_array_free (path->types, TRUE); path->points = g_array_new (FALSE, FALSE, sizeof (GpPointF)); path->types = g_byte_array_new (); path->count = 0; } for (index = iterator->markerPosition; index < iterator->path->count; index++) { type = g_array_index (iterator->path->types, BYTE, index); point = g_array_index (iterator->path->points, GpPointF, index); g_array_append_val (path->points, point); g_byte_array_append (path->types, &type, 1); path->count++; /* Copy the marker and stop copying the points when we reach a marker type */ if (type & PathPointTypePathMarker) { index++; break; } } *resultCount = index - iterator->markerPosition; iterator->markerPosition = index; return Ok; }
packet_constructor_t packet_create(enum packet_id type) { packet_constructor_t pc; pc.type = type; pc.data = g_byte_array_new(); pc.offsets = g_array_new(false, false, sizeof(unsigned)); pc.offset = 1; /* add the type byte */ { uint8_t typebyte = type; g_byte_array_append(pc.data, &typebyte, 1); } return pc; }
/** * e2k_search_key_generate: * @addrtype: the type of @address (usually "SMTP" or "EX") * @address: the address data * * Constructs a PR_SEARCH_KEY value for @address * * Return value: the search key **/ GByteArray * e2k_search_key_generate (const char *addrtype, const char *address) { GByteArray *search_key; guint8 *p; search_key = g_byte_array_new (); g_byte_array_append (search_key, addrtype, strlen (addrtype)); g_byte_array_append (search_key, ":", 1); g_byte_array_append (search_key, address, strlen (address)); g_byte_array_append (search_key, "", 1); for (p = search_key->data; *p; p++) *p = g_ascii_toupper (*p); return search_key; }
/** * e2k_entryid_generate_contact: * @contact_entryid: the #PR_ENTRYID of an item in the user's Contacts * folder. * @nth_address: which of the contact's email addresses to use. * * Constructs an ENTRYID value that can be used as a MAPI recipient * (eg, for a message forwarding server-side rule), corresponding to * the Contacts folder entry identified by @contact_entryid. * * Return value: the recipient ENTRYID **/ GByteArray * e2k_entryid_generate_contact (GByteArray *contact_entryid, int nth_address) { GByteArray *entryid; entryid = g_byte_array_new (); e2k_rule_append_uint32 (entryid, 0); g_byte_array_append (entryid, MAPI_CONTACT_UID, sizeof (MAPI_CONTACT_UID)); e2k_rule_append_uint32 (entryid, 3); e2k_rule_append_uint32 (entryid, 4); e2k_rule_append_uint32 (entryid, nth_address); e2k_rule_append_uint32 (entryid, contact_entryid->len); g_byte_array_append (entryid, contact_entryid->data, contact_entryid->len); return entryid; }
static void test_read_and_write_external (void) { ThriftMemoryBuffer *tbuffer = NULL; gchar *b; GError *error = NULL; GByteArray *buf = g_byte_array_new (); g_assert (buf != NULL); tbuffer = g_object_new (THRIFT_TYPE_MEMORY_BUFFER, "buf", buf, NULL); g_assert (thrift_memory_buffer_write (THRIFT_TRANSPORT (tbuffer), (gpointer) TEST_DATA, 10, &error) == TRUE); g_assert (error == NULL); g_assert (memcmp (buf->data, TEST_DATA, 10) == 0); g_object_unref (tbuffer); }
GHashTable* gridd_stats_remote (addr_info_t *ai, gint ms, GError **err, const gchar *pattern) { GHashTable *ht=NULL; struct code_handler_s codes [] = { { CODE_FINAL_OK, REPSEQ_FINAL, NULL, field_extractor }, { CODE_PARTIAL_CONTENT, 0, NULL, field_extractor }, { 0, 0, NULL, NULL }, }; struct reply_sequence_data_s data = { &ht , 0 , codes }; /*create the result hash table*/ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (!ht) { GSETERROR(err, "cannot create a hashtable"); return NULL; } /*create and fill the request*/ GByteArray *gba_pattern = g_byte_array_append(g_byte_array_new(), (guint8*)pattern, strlen(pattern)); MESSAGE request = metautils_message_create_named("REQ_STATS"); metautils_message_add_fields_gba (request, MSGKEY_PATTERN, gba_pattern, NULL); g_byte_array_free(gba_pattern, TRUE); if (!request) { GSETERROR(err, "Cannot create a message"); goto errorLabel; } /*run the reply sequence*/ if (!metaXClient_reply_sequence_run_from_addrinfo(err, request, ai, ms, &data)) { GSETERROR(err, "Cannot execute the request and parse the answers"); goto errorLabel; } metautils_message_destroy (request); return ht; errorLabel: if (ht) g_hash_table_destroy (ht); metautils_message_destroy (request); return NULL; }
Util::Buffer::Buffer( MemoryUse memory_use , gpointer _data , guint _length ) : bytes( 0 ) { switch( memory_use ) { case Util::Buffer::MEMORY_USE_TAKE: bytes = g_byte_array_new(); g_free( bytes->data ); bytes->data = ( guint8 * ) _data; bytes->len = _length; break; case Util::Buffer::MEMORY_USE_COPY: bytes = g_byte_array_sized_new( _length ); g_byte_array_append( bytes , ( const guint8 * ) _data , _length ); break; } }
HTMLTableCell * html_engine_new_cell (HTMLEngine *e, HTMLTable *table) { HTMLObject *cell; HTMLObject *text; HTMLObject *flow; cell = html_table_cell_new (1, 1, table->padding); flow = html_clueflow_new (HTML_CLUEFLOW_STYLE_NORMAL, g_byte_array_new (), HTML_LIST_TYPE_UNORDERED, 0, HTML_CLEAR_NONE); text = html_engine_new_text_empty (e); html_clue_append (HTML_CLUE (flow), text); html_clue_append (HTML_CLUE (cell), flow); return HTML_TABLE_CELL (cell); }