MESSAGE message_unmarshall(const guint8 *buf, gsize len, GError ** error) { if (!buf || len < 4) { GSETERROR(error, "Invalid parameter"); return NULL; } guint32 l0 = *((guint32*)buf); l0 = g_ntohl(l0); if (l0 > len-4) { GSETERROR(error, "l4v: uncomplete"); return NULL; } MESSAGE m = NULL; asn_codec_ctx_t codec_ctx; codec_ctx.max_stack_size = ASN1C_MAX_STACK; size_t s = l0; asn_dec_rval_t rc = ber_decode(&codec_ctx, &asn_DEF_Message, (void**)&m, buf+4, s); if (rc.code == RC_OK) return m; if (rc.code == RC_WMORE) GSETERROR(error, "%s (%"G_GSIZE_FORMAT" bytes consumed)", "uncomplete content", rc.consumed); else GSETERROR(error, "%s (%"G_GSIZE_FORMAT" bytes consumed)", "invalid content", rc.consumed); metautils_message_destroy (m); return NULL; }
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; }
GByteArray* message_marshall_gba_and_clean(MESSAGE m) { GByteArray *result; EXTRA_ASSERT(m != NULL); result = message_marshall_gba(m, NULL); metautils_message_destroy(m); return result; }
static GError * _client_manage_reply_data(struct gridd_client_s *c) { GError *err = NULL; MESSAGE r = message_unmarshall(c->reply->data, c->reply->len, &err); if (!r) g_prefix_error(&err, "Decoding: "); else err = _client_manage_reply(c, r); metautils_message_destroy(r); return err; }