formats/msgpack.c
void
msg_info_reply(msgpack_packer* pk, const char *s, size_t sz) {

	const char *p = s;
	unsigned int count = 0;

	/* TODO: handle new format */

	/* count number of lines */
	while(p < s + sz) {
		p = strchr(p, '\r');
		if(!p) break;

		p++;
		count++;
	}

	/* create msgpack object */
	msgpack_pack_map(pk, count);

	p = s;
	while(p < s + sz) {
		char *key, *val, *nl, *colon;
		size_t key_sz, val_sz;

		/* find key */
		colon = strchr(p, ':');
		if(!colon) {
			break;
		}
		key_sz = colon - p;
		key = calloc(key_sz + 1, 1);
		memcpy(key, p, key_sz);
		p = colon + 1;

		/* find value */
		nl = strchr(p, '\r');
		if(!nl) {
			free(key);
			break;
		}
		val_sz = nl - p;
		val = calloc(val_sz + 1, 1);
		memcpy(val, p, val_sz);
		p = nl + 1;
		if(*p == '\n') p++;

		/* add to object */
		msgpack_pack_raw(pk, key_sz);
		msgpack_pack_raw_body(pk, key, key_sz);
		msgpack_pack_raw(pk, val_sz);
		msgpack_pack_raw_body(pk, val, val_sz);

		free(key);
		free(val);
	}
}
/**
 * Parse info message and return object.
 */
Parse info message and return object.
Parse info message and return object .
void
msg_info_reply(msgpack_packer* pk, const char *s, size_t sz) {
	const char *p = s;
	unsigned int count = 0;
	while(p < s + sz) {
		p = strchr(p, '\r');
		if(!p) break;
		p++;
		count++;
	}
	msgpack_pack_map(pk, count);
	p = s;
	while(p < s + sz) {
		char *key, *val, *nl, *colon;
		size_t key_sz, val_sz;
		colon = strchr(p, ':');
		if(!colon) {
			break;
		}
		key_sz = colon - p;
		key = calloc(key_sz + 1, 1);
		memcpy(key, p, key_sz);
		p = colon + 1;
		nl = strchr(p, '\r');
		if(!nl) {
			free(key);
			break;
		}
		val_sz = nl - p;
		val = calloc(val_sz + 1, 1);
		memcpy(val, p, val_sz);
		p = nl + 1;
		if(*p == '\n') p++;
		msgpack_pack_raw(pk, key_sz);
		msgpack_pack_raw_body(pk, key, key_sz);
		msgpack_pack_raw(pk, val_sz);
		msgpack_pack_raw_body(pk, val, val_sz);
		free(key);
		free(val);
	}
}
void msg_info_reply ( msgpack_packer * pk , const char * s , size_t sz ) { const char * p = s ; unsigned int count = 0 ; while ( p < s + sz ) { p = strchr ( p , ' \r ' ) ; if ( ! p ) break ; p ++ ; count ++ ; } msgpack_pack_map ( pk , count ) ; p = s ; while ( p < s + sz ) { char * key , * val , * nl , * colon ; size_t key_sz , val_sz ; colon = strchr ( p , ' ' ) ; if ( ! colon ) { break ; } key_sz = colon - p ; key = calloc ( key_sz + 1 , 1 ) ; memcpy ( key , p , key_sz ) ; p = colon + 1 ; nl = strchr ( p , ' \r ' ) ; if ( ! nl ) { free ( key ) ; break ; } val_sz = nl - p ; val = calloc ( val_sz + 1 , 1 ) ; memcpy ( val , p , val_sz ) ; p = nl + 1 ; if ( * p == ' \n ' ) p ++ ; msgpack_pack_raw ( pk , key_sz ) ; msgpack_pack_raw_body ( pk , key , key_sz ) ; msgpack_pack_raw ( pk , val_sz ) ; msgpack_pack_raw_body ( pk , val , val_sz ) ; free ( key ) ; free ( val ) ; } }
Parse info message and return object.
Parse info message and return object .
/* TODO: handle new format */ /* count number of lines */ /* create msgpack object */ /* find key */ /* find value */ /* add to object */