Beispiel #1
0
static void print_obj(struct db_obj_ent *obj)
{
	uint32_t n_str = GUINT32_FROM_LE(obj->n_str);
	int i;
	void *p;
	uint16_t *slenp;
	char *dbstr;

	if (GUINT32_FROM_LE(obj->flags) & DB_OBJ_INLINE) {
		printf("%s\t%s\t%s\t[%u]\t%u\n",
			obj->bucket,
			obj->owner,
			obj->md5,
			(unsigned) GUINT64_FROM_LE(obj->size),
			n_str);
	} else {
		printf("%s\t%s\t%s\t%llX",
			obj->bucket,
			obj->owner,
			obj->md5,
			(long long) GUINT64_FROM_LE(obj->d.a.oid));
		for (i = 0; i < MAXWAY; i++) {
			if (i == 0) {
				printf("\t");
			} else {
				printf(",");
			}
			printf("%d", GUINT32_FROM_LE(obj->d.a.nidv[i]));
		}
		printf(" %u\n", n_str);
	}

	p = obj;
	p += sizeof(*obj);
	slenp = p;

	p += n_str * sizeof(uint16_t);

	for (i = 0; i < n_str; i++) {
		char pfx[16];

		dbstr = p;
		p += GUINT16_FROM_LE(*slenp);
		slenp++;

		if (i == 0)
			strcpy(pfx, "key: ");
		else
			sprintf(pfx, "str%d: ", i);

		printf("%s%s\n", pfx, dbstr);
	}

	printf("====\n");
}
Beispiel #2
0
guint64
msn_read64le(const char *buf)
{
    guint64 val;
    memcpy(&val, buf, sizeof(val));
    return GUINT64_FROM_LE(val);
}
Beispiel #3
0
double mdb_get_double(unsigned char *buf, int offset)
{
	union {guint64 g; double d;} d;
	memcpy(&d, &buf[offset], 8);
	d.g = GUINT64_FROM_LE(d.g);
	return d.d;
}
Beispiel #4
0
static guint64
get_longlong (gchar **p)
{
	guint64 v = * (guint64 *) *p;
	*p += 8;
	return GUINT64_FROM_LE (v);
}
Beispiel #5
0
Datei: tth.c Projekt: Tilka/ncdc
void tiger_final(tiger_ctx_t *ctx, char result[24]) {
  unsigned index = (unsigned)ctx->length & 63;
  guint64 *msg64 = (guint64 *)ctx->message;

  /* pad message and run for last block */

  /* append the byte 0x01 to the message */
  ctx->message[index++] = 0x01;

  /* if no room left in the message to store 64-bit message length */
  if(index > 56) {
    /* then fill the rest with zeros and process it */
    while(index < 64)
      ctx->message[index++] = 0;
    tiger_process_block(ctx->hash, msg64);
    index = 0;
  }
  while(index < 56)
    ctx->message[index++] = 0;
  msg64[7] = GUINT64_FROM_LE(ctx->length << 3);
  tiger_process_block(ctx->hash, msg64);

  /* save result hash */
  guint64 *res = (guint64 *)result;
  res[0] = GINT64_TO_LE(ctx->hash[0]);
  res[1] = GINT64_TO_LE(ctx->hash[1]);
  res[2] = GINT64_TO_LE(ctx->hash[2]);
}
Beispiel #6
0
double mdb_get_double(void *buf, int offset)
{
	union {guint64 g; double d;} d;
	memcpy(&d, buf + offset, 8);
	d.g = GUINT64_FROM_LE(d.g);
	return d.d;
}
Beispiel #7
0
/**
 * Reads an unsigned 64-bit Little Endian value from the stream into native endian format.
 *
 * @param value Pointer to the variable to read the value into.
 * @param stream A #VFSFile object representing the stream.
 * @return TRUE if read was succesful, FALSE if there was an error.
 */
EXPORT bool_t vfs_fget_le64(uint64_t *value, VFSFile *stream)
{
    uint64_t tmp;
    if (vfs_fread(&tmp, sizeof(tmp), 1, stream) != 1)
        return FALSE;
    *value = GUINT64_FROM_LE(tmp);
    return TRUE;
}
Beispiel #8
0
/**
 * g_bytes_vector_read_uint64:
 * @vector: (in): A #GBytesVector.
 * @value: (out): A location for a #guint64.
 *
 * Reads a #guint64 from the vector of buffers in @vector. If successful
 * then @value is set and %TRUE is returned.
 *
 * Returns: %TRUE if successful; otherwise %FALSE.
 */
gboolean
g_bytes_vector_read_uint64 (GBytesVector *vector,
                            guint64      *value)
{
   gboolean ret;

   if ((ret = g_bytes_vector_read(vector, (guint8 *)value, sizeof *value))) {
      *value = GUINT64_FROM_LE(*value);
   }

   return ret;
}
Beispiel #9
0
void
msn_message_parse_slp_body(MsnMessage *msg, const char *body, size_t len)
{
	MsnSlpHeader header;
	const char *tmp;
	int body_len;

	tmp = body;

	if (len < sizeof(header)) {
		g_return_if_reached();
	}

	/* Import the header. */
	memcpy(&header, tmp, sizeof(header));
	tmp += sizeof(header);

	msg->msnslp_header.session_id = GUINT32_FROM_LE(header.session_id);
	msg->msnslp_header.id         = GUINT32_FROM_LE(header.id);
	msg->msnslp_header.offset     = GUINT64_FROM_LE(header.offset);
	msg->msnslp_header.total_size = GUINT64_FROM_LE(header.total_size);
	msg->msnslp_header.length     = GUINT32_FROM_LE(header.length);
	msg->msnslp_header.flags      = GUINT32_FROM_LE(header.flags);
	msg->msnslp_header.ack_id     = GUINT32_FROM_LE(header.ack_id);
	msg->msnslp_header.ack_sub_id = GUINT32_FROM_LE(header.ack_sub_id);
	msg->msnslp_header.ack_size   = GUINT64_FROM_LE(header.ack_size);

	/* Import the body. */
	body_len = len - (tmp - body);
	/* msg->body_len = msg->msnslp_header.length; */

	if (body_len > 0) {
		msg->body_len = len - (tmp - body);
		msg->body = g_malloc0(msg->body_len + 1);
		memcpy(msg->body, tmp, msg->body_len);
		tmp += body_len;
	}
}
Beispiel #10
0
static BlueSkyCleanerItem *bluesky_cleaner_deserialize(BlueSkyRCStr *raw)
{
    const char *data = raw->data;
    size_t len = raw->len;
    const char *data1, *data2, *data3;
    size_t len1, len2, len3;

    g_assert(len > 4);
    if (len < sizeof(struct cloudlog_header)
        || memcmp(data, CLOUDLOG_MAGIC, 4) != 0)
    {
        g_warning("Deserializing garbage cloud log item from cleaner!");
        return NULL;
    };

    struct cloudlog_header *header = (struct cloudlog_header *)data;
    len1 = GUINT32_FROM_LE(header->size1);
    len2 = GUINT32_FROM_LE(header->size2);
    len3 = GUINT32_FROM_LE(header->size3);
    data1 = data + sizeof(struct cloudlog_header);
    data2 = data1 + len1;
    data3 = data2 + len2;
    g_assert(data3 + len3 - data <= len);

    BlueSkyCleanerItem *item = g_new0(BlueSkyCleanerItem, 1);
    item->type = header->type - '0';
    item->inum = GUINT64_FROM_LE(header->inum);
    memcpy(&item->id, &header->id, sizeof(BlueSkyCloudID));

    int link_count = len2 / sizeof(BlueSkyCloudID);
    g_print("Outgoing links: %d\n", link_count);
    item->links = g_array_new(FALSE, TRUE, sizeof(BlueSkyCleanerLink));
    for (int i = 0; i < link_count; i++) {
        BlueSkyCleanerLink link;

        g_assert(len2 >= sizeof(link.id));
        memcpy(&link.id, data2, sizeof(link.id));
        data2 += sizeof(link.id); len2 -= sizeof(link.id);

        g_assert(len3 >= sizeof(link.location));
        memcpy(&link.location, data3, sizeof(link.location));
        data3 += sizeof(link.location); len3 -= sizeof(link.location);

        g_array_append_val(item->links, link);
    }

    return item;
}
Beispiel #11
0
Datei: tth.c Projekt: Tilka/ncdc
static void tiger_process_block(guint64 state[3], guint64 *block) {
  /* Optimized for GCC IA32.
     The order of declarations is important for compiler. */
  guint64 a, b, c;
  guint64 x0, x1, x2, x3, x4, x5, x6, x7;
#ifndef CPU_X64
  guint64 tmp;
  char i;
#endif

  x0=GUINT64_FROM_LE(block[0]); x1=GUINT64_FROM_LE(block[1]);
  x2=GUINT64_FROM_LE(block[2]); x3=GUINT64_FROM_LE(block[3]);
  x4=GUINT64_FROM_LE(block[4]); x5=GUINT64_FROM_LE(block[5]);
  x6=GUINT64_FROM_LE(block[6]); x7=GUINT64_FROM_LE(block[7]);

  a = state[0];
  b = state[1];
  c = state[2];

  /* passes and key shedules */
#ifndef CPU_X64
  for(i=0; i<3; i++) {
    if(i != 0)
      key_schedule;
    pass(a, b, c, (i==0 ? 5 : i==1 ? 7 : 9));
    tmp=a;
    a=c;
    c=b;
    b=tmp;
  }
#else
  pass(a, b, c, 5);
  key_schedule;
  pass(c, a, b, 7);
  key_schedule;
  pass(b, c, a, 9);
#endif

  /* feedforward operation */
  state[0] = a ^ state[0];
  state[1] = b - state[1];
  state[2] = c + state[2];
}
Beispiel #12
0
static gboolean
read_word (EvaDebugLog *log,
           guint64     *out)
{
  if (log->is_64bit)
    {
      guint64 val;
      if (fread (&val, 8, 1, log->fp) != 1)
        return FALSE;
      *out = log->little_endian ? GUINT64_FROM_LE (val) : GUINT64_FROM_BE (val);
    }
  else
    {
      guint32 val;
      if (fread (&val, 4, 1, log->fp) != 1)
        return FALSE;
      *out = log->little_endian ? GUINT32_FROM_LE (val) : GUINT32_FROM_BE (val);
    }
  return TRUE;
}
Beispiel #13
0
static void do_bucket_list(void)
{
	int rc;
	DBC *cur = NULL;
	DBT key, val;
	unsigned long count = 0;
	struct db_bucket_ent *ent;

	memset(&key, 0, sizeof(key));
	memset(&val, 0, sizeof(val));
	val.flags = DB_DBT_MALLOC;

	rc = tdb.buckets->cursor(tdb.buckets, NULL, &cur, 0);
	if (rc) {
		tdb.buckets->err(tdb.buckets, rc, "cursor create");
		exit(1);
	}

	printf("name\towner\ttime_created\n");

	while (1) {
		rc = cur->get(cur, &key, &val, DB_NEXT);
		if (rc)
			break;

		ent = val.data;

		printf("%s\t%s\t%llu\n",
		       ent->name,
		       ent->owner,
		       (unsigned long long) GUINT64_FROM_LE(ent->time_create));

		count++;

		free(ent);
	}

	fprintf(stderr, "%lu records\n", count);

	cur->close(cur);
}
Beispiel #14
0
static void do_obj_cnt(void)
{
	DBC *cur = NULL;
	DBT key, val;
	uint64_t cntbuf;	/* LE */
	uint64_t objcount;	/* Host order */
	int rc;

	rc = tdb.oids->cursor(tdb.oids, NULL, &cur, 0);
	if (rc) {
		tdb.oids->err(tdb.oids, rc, "cursor create");
		exit(1);
	}

	memset(&key, 0, sizeof(key));
	memset(&val, 0, sizeof(val));
	val.flags = DB_DBT_USERMEM;
	val.data = &cntbuf;
	val.ulen = sizeof(uint64_t);

	/* read existing counter, if any */
	rc = cur->get(cur, &key, &val, DB_NEXT);
	if (rc == DB_NOTFOUND) {
		printf("-\n");
	} else if (rc) {
		printf("\n");
		fprintf(stderr, "objid get error %d\n", rc);
		exit(1);
	} else {
		if (val.size != sizeof(uint64_t)) {
			printf("\n");
			fprintf(stderr, "objid_init got size %d\n", val.size);
			exit(1);
		}

		objcount = GUINT64_FROM_LE(*(uint64_t *)val.data);
		printf("%llu\n", (unsigned long long) objcount);
	}

	cur->close(cur);
}
Beispiel #15
0
/**
 * qmi_utils_read_guint64_from_buffer:
 * @buffer: a buffer with raw binary data.
 * @buffer_size: size of @buffer.
 * @endian: endianness of firmware value; swapped to host byte order if necessary
 * @out: return location for the read variable.
 *
 * Reads an unsigned 64-bit integer from the buffer. The number in the buffer is
 * expected to be given in the byte order specified by @endian, and this method
 * takes care of converting the read value to the proper host endianness.
 *
 * The user needs to make sure that at least 8 bytes are available
 * in the buffer.
 *
 * Also note that both @buffer and @buffer_size get updated after the 8 bytes
 * read.
 */
void
qmi_utils_read_guint64_from_buffer (const guint8 **buffer,
                                    guint16       *buffer_size,
                                    QmiEndian      endian,
                                    guint64       *out)
{
    g_assert (out != NULL);
    g_assert (buffer != NULL);
    g_assert (buffer_size != NULL);
    g_assert (*buffer_size >= 8);

    memcpy (out, &((*buffer)[0]), 8);
    if (endian == QMI_ENDIAN_BIG)
        *out = GUINT64_FROM_BE (*out);
    else
        *out = GUINT64_FROM_LE (*out);

    print_read_bytes_trace ("guint64", &(*buffer)[0], out, 8);

    *buffer = &((*buffer)[8]);
    *buffer_size = (*buffer_size) - 8;
}
Beispiel #16
0
static void *read_tiff_tag_8(FILE *f,
			     int64_t count, int64_t offset,
			     uint16_t endian) {
  uint64_t *result = g_try_new(uint64_t, count);
  if (result == NULL) {
    goto FAIL;
  }

  if (!read_tiff_tag(f, count * sizeof *result, result, offset, NULL)) {
    goto FAIL;
  }

  // swap?
  for (int64_t i = 0; i < count; i++) {
    if (endian == TIFF_BIGENDIAN) {
      result[i] = GUINT64_FROM_BE(result[i]);
    } else {
      result[i] = GUINT64_FROM_LE(result[i]);
    }
  }

  /*
  g_debug("  count %" PRId64, count);
  for (int i = 0; i < count; i++) {
    if (i > 50) {
      g_debug("    ...");
      break;
    }
    g_debug("   %" PRIu64, result[i]);
  }
  g_debug(" ");
  */

  return result;

 FAIL:
  g_free(result);
  return NULL;
}
Beispiel #17
0
/**
 * qmi_utils_read_sized_guint_from_buffer:
 * @buffer: a buffer with raw binary data.
 * @buffer_size: size of @buffer.
 * @n_bytes: number of bytes to read.
 * @endian: endianness of firmware value; swapped to host byte order if necessary
 * @out: return location for the read variable.
 *
 * Reads a @n_bytes-sized unsigned integer from the buffer. The number in the
 * buffer is expected to be given in the byte order specified by @endian, and
 * this method takes care of converting the read value to the proper host
 * endianness.
 *
 * The user needs to make sure that at least @n_bytes bytes are available
 * in the buffer.
 *
 * Also note that both @buffer and @buffer_size get updated after the @n_bytes
 * bytes read.
 */
void
qmi_utils_read_sized_guint_from_buffer (const guint8 **buffer,
                                        guint16       *buffer_size,
                                        guint          n_bytes,
                                        QmiEndian      endian,
                                        guint64       *out)
{
    g_assert (out != NULL);
    g_assert (buffer != NULL);
    g_assert (buffer_size != NULL);
    g_assert (*buffer_size >= n_bytes);

    *out = 0;
    memcpy (out, *buffer, n_bytes);
    if (endian == QMI_ENDIAN_BIG)
        *out = GUINT64_FROM_BE (*out);
    else
        *out = GUINT64_FROM_LE (*out);

    *buffer = &((*buffer)[n_bytes]);
    *buffer_size = (*buffer_size) - n_bytes;
}
Beispiel #18
0
static inline gint
rspamd_archive_rar_read_vint (const guchar *start, gsize remain, guint64 *res)
{
	/*
	 * From http://www.rarlab.com/technote.htm:
	 * Variable length integer. Can include one or more bytes, where
	 * lower 7 bits of every byte contain integer data and highest bit
	 * in every byte is the continuation flag.
	 * If highest bit is 0, this is the last byte in sequence.
	 * So first byte contains 7 least significant bits of integer and
	 * continuation flag. Second byte, if present, contains next 7 bits and so on.
	 */
	guint64 t = 0;
	guint shift = 0;
	const guchar *p = start;

	while (remain > 0 && shift <= 57) {
		if (*p & 0x80) {
			t |= ((guint64)(*p & 0x7f)) << shift;
		}
		else {
			t |= ((guint64)(*p & 0x7f)) << shift;
			p ++;
			break;
		}

		shift += 7;
		p++;
		remain --;
	}

	if (remain == 0 || shift > 64) {
		return -1;
	}

	*res = GUINT64_FROM_LE (t);

	return p - start;
}
Beispiel #19
0
void
msn_message_parse_payload(MsnMessage *msg,
						  const char *payload, size_t payload_len)
{
	char *tmp_base, *tmp;
	const char *content_type;
	char *end;
	char **elems, **cur, **tokens;

	g_return_if_fail(payload != NULL);

	tmp_base = tmp = g_malloc0(payload_len + 1);
	memcpy(tmp_base, payload, payload_len);

	/* Parse the attributes. */
	end = strstr(tmp, "\r\n\r\n");
	/* TODO? some clients use \r delimiters instead of \r\n, the official client
	 * doesn't send such messages, but does handle receiving them. We'll just
	 * avoid crashing for now */
	if (end == NULL) {
		g_free(tmp_base);
		g_return_if_reached();
	}
	*end = '\0';

	elems = g_strsplit(tmp, "\r\n", 0);

	for (cur = elems; *cur != NULL; cur++)
	{
		const char *key, *value;

		tokens = g_strsplit(*cur, ": ", 2);

		key = tokens[0];
		value = tokens[1];

		if (!strcmp(key, "MIME-Version"))
		{
			g_strfreev(tokens);
			continue;
		}

		if (!strcmp(key, "Content-Type"))
		{
			char *charset, *c;

			if ((c = strchr(value, ';')) != NULL)
			{
				if ((charset = strchr(c, '=')) != NULL)
				{
					charset++;
					msn_message_set_charset(msg, charset);
				}

				*c = '\0';
			}

			msn_message_set_content_type(msg, value);
		}
		else
		{
			msn_message_set_attr(msg, key, value);
		}

		g_strfreev(tokens);
	}

	g_strfreev(elems);

	/* Proceed to the end of the "\r\n\r\n" */
	tmp = end + 4;

	/* Now we *should* be at the body. */
	content_type = msn_message_get_content_type(msg);

	if (content_type != NULL &&
		!strcmp(content_type, "application/x-msnmsgrp2p"))
	{
		MsnSlpHeader header;
		MsnSlpFooter footer;
		int body_len;

		if (payload_len - (tmp - tmp_base) < sizeof(header)) {
			g_free(tmp_base);
			g_return_if_reached();
		}

		msg->msnslp_message = TRUE;

		/* Import the header. */
		memcpy(&header, tmp, sizeof(header));
		tmp += sizeof(header);

		msg->msnslp_header.session_id = GUINT32_FROM_LE(header.session_id);
		msg->msnslp_header.id         = GUINT32_FROM_LE(header.id);
		msg->msnslp_header.offset     = GUINT64_FROM_LE(header.offset);
		msg->msnslp_header.total_size = GUINT64_FROM_LE(header.total_size);
		msg->msnslp_header.length     = GUINT32_FROM_LE(header.length);
		msg->msnslp_header.flags      = GUINT32_FROM_LE(header.flags);
		msg->msnslp_header.ack_id     = GUINT32_FROM_LE(header.ack_id);
		msg->msnslp_header.ack_sub_id = GUINT32_FROM_LE(header.ack_sub_id);
		msg->msnslp_header.ack_size   = GUINT64_FROM_LE(header.ack_size);

		body_len = payload_len - (tmp - tmp_base) - sizeof(footer);

		/* Import the body. */
		if (body_len > 0) {
			msg->body_len = body_len;
			msg->body = g_malloc0(msg->body_len + 1);
			memcpy(msg->body, tmp, msg->body_len);
			tmp += body_len;
		}

		/* Import the footer. */
		if (body_len >= 0) {
			memcpy(&footer, tmp, sizeof(footer));
			tmp += sizeof(footer);
			msg->msnslp_footer.value = GUINT32_FROM_BE(footer.value);
		}
	}
	else
	{
		if (payload_len - (tmp - tmp_base) > 0) {
			msg->body_len = payload_len - (tmp - tmp_base);
			msg->body = g_malloc0(msg->body_len + 1);
			memcpy(msg->body, tmp, msg->body_len);
		}
	}

	g_free(tmp_base);
}
Beispiel #20
0
/* reads the next packet */
static gboolean observer_read(wtap *wth, int *err, gchar **err_info,
    gint64 *data_offset)
{
	int offset;
	packet_entry_header packet_header;

	/*
	 * Skip records other than data records.
	 */
	for (;;) {
		*data_offset = wth->data_offset;

		/* process the packet header, including TLVs */
		offset = read_packet_header(wth->fh, &packet_header, err,
		    err_info);
		if (offset <= 0)
			return FALSE;	/* EOF or error */

		wth->data_offset += offset;

		if (packet_header.packet_type == PACKET_TYPE_DATA_PACKET)
			break;

		/* skip to next packet */
		packet_header.offset_to_next_packet =
		    GUINT16_FROM_LE(packet_header.offset_to_next_packet);
		if (!skip_to_next_packet(wth, offset,
		    packet_header.offset_to_next_packet, err, err_info))
			return FALSE;	/* EOF or error */
	}

	/* set-up the packet header */
	packet_header.network_size =
	    GUINT16_FROM_LE(packet_header.network_size);
	/* neglect frame markers for wiretap */
	if (packet_header.network_size < 4) {
		*err = WTAP_ERR_BAD_RECORD;
		*err_info = g_strdup_printf("Observer: bad record: Packet length %u < 4",
		    packet_header.network_size);
		return FALSE;
	}
	packet_header.network_size -= 4;
	packet_header.captured_size =
	    GUINT16_FROM_LE(packet_header.captured_size);
	wth->phdr.pkt_encap = observer_encap[packet_header.network_type];
	wth->phdr.len    = packet_header.network_size;
	wth->phdr.caplen = MIN(packet_header.captured_size, wth->phdr.len);
	packet_header.nano_seconds_since_2000 =
	    GUINT64_FROM_LE(packet_header.nano_seconds_since_2000);
	wth->phdr.ts.secs =
	    (time_t) (packet_header.nano_seconds_since_2000/1000000000 + seconds1970to2000);
	wth->phdr.ts.nsecs = (int) (packet_header.nano_seconds_since_2000%1000000000);

	/* set-up the packet buffer */
	buffer_assure_space(wth->frame_buffer, packet_header.captured_size);

	/* read data */
	if (!read_packet_data(wth->fh, packet_header.offset_to_frame, offset,
	    buffer_start_ptr(wth->frame_buffer), packet_header.captured_size,
	    err, err_info))
		return FALSE;
	wth->data_offset += packet_header.captured_size;
	offset += packet_header.captured_size;

	/* update the pseudo header */
	switch (wth->file_encap) {

	case WTAP_ENCAP_ETHERNET:
		/* There is no FCS in the frame */
		wth->pseudo_header.eth.fcs_len = 0;
		break;
	}

	return TRUE;
}
Beispiel #21
0
static bool bucket_list_keys(struct client *cli, const char *user,
			     const char *bucket)
{
	GHashTable *param;
	enum errcode err = InternalError;
	char *prefix, *marker, *maxkeys_str, *delim, *s;
	int maxkeys = 100, i, rc;
	GList *content, *tmpl;
	size_t pfx_len;
	struct bucket_list_info bli;
	bool rcb;
	DB_ENV *dbenv = tdbrep.tdb.env;
	DB_TXN *txn = NULL;
	DB *objs = tdbrep.tdb.objs;
	DBC *cur = NULL;
	DBT pkey, pval;
	struct db_obj_key *obj_key;
	size_t alloc_len;
	bool seen_prefix = false;
	int get_flags;

	/* verify READ access */
	if (!user || !has_access(user, bucket, NULL, "READ")) {
		err = AccessDenied;
		goto err_out;
	}

	/* parse URI query string */
	param = hreq_query(&cli->req);
	if (!param)
		goto err_out;

	/* read useful params from query string */
	prefix = g_hash_table_lookup(param, "prefix");
	pfx_len = prefix ? strlen(prefix) : 0;

	marker = g_hash_table_lookup(param, "marker");
	delim = g_hash_table_lookup(param, "delimiter");
	maxkeys_str = g_hash_table_lookup(param, "max-keys");
	if (maxkeys_str) {
		i = atoi(maxkeys_str);
		if (i > 0 && i < maxkeys)
			maxkeys = i;
	}

	/* open transaction */
	rc = dbenv->txn_begin(dbenv, NULL, &txn, 0);
	if (rc) {
		dbenv->err(dbenv, rc, "DB_ENV->txn_begin");
		goto err_out;
	}

	/* search for (bucket, *) in object database, to see if
	 * any objects associated with this bucket exist
	 */
	rc = objs->cursor(objs, txn, &cur, 0);
	if (rc) {
		objs->err(objs, rc, "objs->cursor");
		goto err_out;
	}

	alloc_len = sizeof(*obj_key) +
		    (marker ? strlen(marker) : pfx_len) + 1;
	obj_key = alloca(alloc_len);

	memset(obj_key, 0, alloc_len);
	strncpy(obj_key->bucket, bucket, sizeof(obj_key->bucket));
	strcpy(obj_key->key, marker ? marker : prefix ? prefix : "");

	memset(&pkey, 0, sizeof(pkey));
	pkey.data = obj_key;
	pkey.size = alloc_len;

	memset(&bli, 0, sizeof(bli));
	bli.prefix = prefix;
	bli.pfx_len = pfx_len;
	bli.delim = delim;
	bli.common_pfx = g_hash_table_new_full(g_str_hash, g_str_equal,
					       free, NULL);
	bli.maxkeys = maxkeys;

	/* iterate through each returned data row */
	get_flags = DB_SET_RANGE;
	while (1) {
		struct obj_vitals v;
		struct db_obj_key *tmpkey;
		struct db_obj_ent *obj;

		memset(&pval, 0, sizeof(pval));
		pval.flags = DB_DBT_MALLOC;

		rc = cur->get(cur, &pkey, &pval, get_flags);
		if (rc) {
			if (rc != DB_NOTFOUND)
				objs->err(objs, rc, "bucket_list_keys iter");
			break;
		}

		get_flags = DB_NEXT;

		tmpkey = pkey.data;
		obj = pval.data;

		if (strcmp(tmpkey->bucket, bucket)) {
			free(obj);
			break;
		}
		if (prefix) {
			if (strncmp(tmpkey->key, prefix, pfx_len) != 0) {
				free(obj);
				if (!seen_prefix)
					/* continue searching for
					 * a record that begins with this
					 * prefix
					 */
					continue;
				else
					/* no more records with our prefix */
					break;
			}

			seen_prefix = true;
		}

		memset(&v, 0, sizeof(v));
		strcpy(v.md5, obj->md5);
		strncpy(v.owner, obj->owner, sizeof(v.owner)-1);
		if (!(GUINT32_FROM_LE(obj->flags) & DB_OBJ_INLINE))
			memcpy(&v.addr, &obj->d.a, sizeof(v.addr));
		v.mtime = GUINT64_FROM_LE(obj->mtime);
		v.size = GUINT64_FROM_LE(obj->size);
		free(obj);

		if (bucket_list_iter(tmpkey->key, &v, &bli))
			break;
	}

	/* close cursor, transaction */
	rc = cur->close(cur);
	if (rc) {
		objs->err(objs, rc, "objs->cursor close");
		goto err_out_rb;
	}

	rc = txn->commit(txn, 0);
	if (rc) {
		dbenv->err(dbenv, rc, "DB_ENV->txn_commit");
		goto err_out_param;
	}

	s = g_markup_printf_escaped(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
"<ListBucketResult xmlns=\"http://indy.yyz.us/doc/2006-03-01/\">\r\n"
"  <Name>%s</Name>\r\n"
"  <MaxKeys>%d</MaxKeys>\r\n"
"  <IsTruncated>%s</IsTruncated>\r\n",

		 bucket,
		 maxkeys,
		 bli.trunc ? "true" : "false");

	content = g_list_append(NULL, s);

	if (prefix) {
		s = g_markup_printf_escaped("  <Prefix>%s</Prefix>\n", prefix);
		content = g_list_append(content, s);
	}
	if (marker) {
		s = g_markup_printf_escaped("  <Marker>%s</Marker>\n", marker);
		content = g_list_append(content, s);
	}

	tmpl = bli.res;
	while (tmpl) {
		char timestr[64];
		struct obj_vitals *vp;

		vp = tmpl->data;
		tmpl = tmpl->next;

		/*
		 * FIXME Use the vp->addr to verify that key still exists.
		 * And if it doesn't, then what? (addr.nid can be 0 for inline)
		 */

		s = g_markup_printf_escaped(
                         "  <Contents>\r\n"
                         "    <Key>%s</Key>\r\n"
                         "    <LastModified>%s</LastModified>\r\n"
                         "    <ETag>%s</ETag>\r\n"
                         "    <Size>%llu</Size>\r\n"
                         "    <StorageClass>STANDARD</StorageClass>\r\n"
                         "    <Owner>\r\n"
                         "      <ID>%s</ID>\r\n"
                         "      <DisplayName>%s</DisplayName>\r\n"
                         "    </Owner>\r\n"
                         "  </Contents>\r\n",

			 vp->key,
			 hutil_time2str(timestr, sizeof(timestr), vp->mtime / 1000000),
			 vp->md5,
			 (unsigned long long) vp->size,
			 vp->owner,
			 vp->owner);

		content = g_list_append(content, s);

		free(vp->key);
		free(vp);
	}

	g_list_free(bli.res);

	content = bucket_list_pfx(content, bli.common_pfx, bli.delim);

	s = strdup("</ListBucketResult>\r\n");
	content = g_list_append(content, s);

	free(bli.last_comp);
	g_hash_table_destroy(bli.common_pfx);
	g_hash_table_destroy(param);

	rcb = cli_resp_xml(cli, 200, content);

	g_list_free(content);

	return rcb;

err_out_rb:
	rc = txn->abort(txn);
	if (rc)
		dbenv->err(dbenv, rc, "DB_ENV->txn_abort");
err_out_param:
	g_hash_table_destroy(param);
err_out:
	return cli_err(cli, err);
}
Beispiel #22
0
bool service_list(struct client *cli, const char *user)
{
	GList *files = NULL, *content = NULL;
	char *s;
	enum errcode err = InternalError;
	int rc;
	bool rcb;
	DB_TXN *txn = NULL;
	DBC *cur = NULL;
	DB_ENV *dbenv = tdbrep.tdb.env;
	DB *bidx = tdbrep.tdb.buckets_idx;
	DBT skey, pkey, pval;

	if (asprintf(&s,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
"<ListAllMyBucketsResult xmlns=\"http://indy.yyz.us/doc/2006-03-01/\">\r\n"
"  <Owner>\r\n"
"    <ID>%s</ID>\r\n"
"    <DisplayName>%s</DisplayName>\r\n"
"  </Owner>\r\n"
"  <Buckets>\r\n",

		     user,
		     user) < 0)
		goto err_out;

	content = g_list_append(content, s);

	/* open transaction, search cursor */
	rc = dbenv->txn_begin(dbenv, NULL, &txn, 0);
	if (rc) {
		dbenv->err(dbenv, rc, "DB_ENV->txn_begin");
		goto err_out_content;
	}

	rc = bidx->cursor(bidx, txn, &cur, 0);
	if (rc) {
		bidx->err(bidx, rc, "bidx->cursor");
		goto err_out_content;
	}

	memset(&skey, 0, sizeof(skey));
	memset(&pkey, 0, sizeof(pkey));
	memset(&pval, 0, sizeof(pval));

	skey.data = (char *) user;
	skey.size = strlen(user) + 1;

	/* FIXME: Use of DB_NEXT rather than DB_SET to begin search
	 * means we iterate through entire db, rather than
	 * starting at the first matching key.
	 */

	/* loop through matching buckets, if any */
	while (1) {
		char timestr[64];
		struct db_bucket_ent *ent;

		rc = cur->pget(cur, &skey, &pkey, &pval, DB_NEXT);
		if (rc)
			break;

		ent = pval.data;

		s = g_markup_printf_escaped(
                        "    <Bucket>\r\n"
                        "      <Name>%s</Name>\r\n"
                        "      <CreationDate>%s</CreationDate>\r\n"
                        "    </Bucket>\r\n",

			     ent->name,
			     hutil_time2str(timestr, sizeof(timestr),
			     	      GUINT64_FROM_LE(ent->time_create)));
		if (!s)
			goto err_out_content;

		content = g_list_append(content, s);
	}

	if (rc != DB_NOTFOUND)
		bidx->err(bidx, rc, "service_list iter");

	/* close cursor, transaction */
	rc = cur->close(cur);
	if (rc)
		bidx->err(bidx, rc, "bidx->cursor close");

	rc = txn->commit(txn, 0);
	if (rc)
		dbenv->err(dbenv, rc, "DB_ENV->txn_commit");

	if (asprintf(&s,
"  </Buckets>\r\n"
"</ListAllMyBucketsResult>\r\n") < 0)
		goto err_out_content;

	content = g_list_append(content, s);

	rcb = cli_resp_xml(cli, 200, content);

	strlist_free(files);
	g_list_free(content);

	return rcb;

err_out_content:
	strlist_free(content);
err_out:
	strlist_free(files);
	return cli_err(cli, err);
}
Beispiel #23
0
guint64
msn_read64le(const char *buf)
{
	return GUINT64_FROM_LE(*(guint64 *)buf);
}
Beispiel #24
0
char *
arv_uvcp_packet_to_string (const ArvUvcpPacket *packet)
{
	GString *string;
	char *c_string;
	int packet_size;
	guint32 value;

	g_return_val_if_fail (packet != NULL, NULL);

	string = g_string_new ("");

	g_string_append_printf (string, "packet_type  = %s\n",
				arv_uvcp_packet_type_to_string (GUINT16_FROM_LE (packet->header.packet_type)));
	g_string_append_printf (string, "command      = %s\n",
				arv_uvcp_command_to_string (GUINT16_FROM_LE (packet->header.command)));
	g_string_append_printf (string, "size         = %d\n", GUINT16_FROM_LE (packet->header.size));
	g_string_append_printf (string, "id           = %d\n", GUINT16_FROM_LE (packet->header.id));

	switch (GUINT16_FROM_LE (packet->header.command)) {
		case ARV_UVCP_COMMAND_READ_MEMORY_CMD:
			{
				ArvUvcpReadMemoryCmd *cmd_packet = (void *) packet;

				value = GUINT64_FROM_LE (cmd_packet->infos.address);
				g_string_append_printf (string, "address      = %10u (0x%08x)\n",
							value, value);
				value = GUINT16_FROM_LE (cmd_packet->infos.size);
				g_string_append_printf (string, "size         = %10u (0x%08x)\n",
							value, value);
				break;
			}
		case ARV_UVCP_COMMAND_READ_MEMORY_ACK:
			{
				break;
			}
		case ARV_UVCP_COMMAND_WRITE_MEMORY_CMD:
			{
				ArvUvcpWriteMemoryCmd *cmd_packet = (void *) packet;

				value = GUINT64_FROM_LE (cmd_packet->infos.address);
				g_string_append_printf (string, "address      = %10u (0x%08x)\n",
							value, value);
			}
		case ARV_UVCP_COMMAND_WRITE_MEMORY_ACK:
			{
				ArvUvcpWriteMemoryAck *cmd_packet = (void *) packet;

				value = GUINT64_FROM_LE (cmd_packet->infos.bytes_written);
				g_string_append_printf (string, "written      = %10u (0x%08x)\n",
							value, value);
			}
	}

	packet_size = sizeof (ArvUvcpHeader) + GUINT16_FROM_LE (packet->header.size);

	arv_g_string_append_hex_dump (string, packet, packet_size);

	c_string = string->str;

	g_string_free (string, FALSE);

	return c_string;
}
Beispiel #25
0
static guint64
get_le64 (const void *buf)
{
	return GUINT64_FROM_LE ( * ((guint64 *) buf) );
}
Beispiel #26
0
uint64_t ru64(char **ptr)
{
	*ptr += 8;
	return GUINT64_FROM_LE(*(uint64_t *)(*ptr - 8));
}