Esempio n. 1
0
//void omiterate_fullPacket(t_omiterate *x, long len, long ptr)
void omiterate_fullPacket(t_omiterate *x, t_symbol *msg, int argc, t_atom *argv)
{
	OMAX_UTIL_GET_LEN_AND_PTR;
	t_osc_bndl_it_s *it = osc_bndl_it_s_get(len, ptr);
	while(osc_bndl_it_s_hasNext(it)){
		t_osc_msg_s *m = osc_bndl_it_s_next(it);
		long l = osc_message_s_getSize(m);
		char *p = osc_message_s_getAddress(m);
		omax_util_outletOSC(x->outlet, l, p);
	}
	osc_bndl_it_s_destroy(it);
}
Esempio n. 2
0
void ocoll_fullPacket_impl(t_ocoll *x, long len, char *ptr)
{
	osc_bundle_s_wrap_naked_message(len, ptr);
	if(len == OSC_HEADER_SIZE){
		// empty bundle
		return;
	}
	critical_enter(x->lock);
	if(x->buffer_pos + len > x->buffer_len){
		char *tmp = (char *)osc_mem_resize(x->buffer, x->buffer_pos + len);
		if(!tmp){
			object_error((t_object *)x, "Out of memory...sayonara max...");
			critical_exit(x->lock);
			return;
		}
		x->buffer = tmp;
		memset(x->buffer + x->buffer_pos, '\0', len);
		x->buffer_len = x->buffer_pos + len;
	}
	t_osc_bndl_it_s *it = osc_bndl_it_s_get(len, ptr);
	while(osc_bndl_it_s_hasNext(it)){
		t_osc_msg_s *m = osc_bndl_it_s_next(it);
		t_osc_msg_ar_s *match = osc_bundle_s_lookupAddress(x->buffer_pos, x->buffer, osc_message_s_getAddress(m), 1);
		if(!match){
			long l = osc_message_s_getSize(m) + 4;
			memcpy(x->buffer + x->buffer_pos, osc_message_s_getPtr(m), l);
			x->buffer_pos += l;
		}else{
			// this function can resize its buffer, but we don't have to worry about that
			// since we already resized it above to accommidate the entire bundle
			int i;
			for(i = 0; i < osc_message_array_s_getLen(match); i++){
				t_osc_msg_s *mm = osc_message_array_s_get(match, i);
				osc_bundle_s_replaceMessage(&(x->buffer_len),
                                            &(x->buffer_pos),
                                            &(x->buffer),
                                            mm,
                                            m);
			}
			osc_message_array_s_free(match);
		}
	}
	osc_bndl_it_s_destroy(it);
	critical_exit(x->lock);
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	// create a bundle and add messages to it
	t_osc_bndl_u *bndl_u = osc_bundle_u_alloc();
	t_osc_msg_u *m1 = osc_message_u_alloc();
	osc_message_u_setAddress(m1, "/foo");
	osc_message_u_appendFloat(m1, 3.14);
	osc_bundle_u_addMsg(bndl_u, m1);

	t_osc_msg_u *m2 = osc_message_u_allocWithString("/bar", "whatevs");
	osc_bundle_u_addMsg(bndl_u, m2);

	t_osc_msg_u *m3 = osc_message_u_allocWithAddress("/bloo");
	t_osc_atom_u *a = osc_atom_u_allocWithInt32(12);
	osc_message_u_appendAtom(m3, a);
	osc_bundle_u_addMsg(bndl_u, m3);

	// serialize the bundle
	long len = osc_bundle_u_nserialize(NULL, 0, bndl_u);
	char bndl_s[len];
	osc_bundle_u_nserialize(bndl_s, len, bndl_u);

	// free the original unserialized bundle
	osc_bundle_u_free(bndl_u);
	bndl_u = NULL;

	// deserialize the serialized bundle
	osc_bundle_s_deserialize(len, bndl_s, &bndl_u);
	
	// iterate over messages in a serialized bundle
	t_osc_bndl_it_s *b_it_s = osc_bndl_it_s_get(len, bndl_s);
	while(osc_bndl_it_s_hasNext(b_it_s)){
		t_osc_msg_s *m = osc_bndl_it_s_next(b_it_s);
		printf("%s\n", osc_message_s_getAddress(m));
	}
	osc_bndl_it_s_destroy(b_it_s);

	// turn a serialized bundle into printable text
	long tlen = osc_bundle_s_nformat(NULL, 0, len, bndl_s, 0);
	char text[tlen + 1];
	osc_bundle_s_nformat(text, tlen, len, bndl_s, 0);
	printf("\nBUNDLE:\n");
	printf("%s\n", text);
	printf("\n");

	// turn text into an unserialized bundle
	t_osc_bndl_u *bndl_u_2 = NULL;
	char *text2 = "/jean : [1, 2, 3], /john : 6.66, /jeremy : \"is cool\"";
	osc_parser_parseString(strlen(text2), text2, &bndl_u_2);

	// iterate over messages in an unserialized bundle
	t_osc_bndl_it_u *b_it_u = osc_bndl_it_u_get(bndl_u_2);
	while(osc_bndl_it_u_hasNext(b_it_u)){
		t_osc_msg_u *m = osc_bndl_it_u_next(b_it_u);
		printf("%s has typetags ", osc_message_u_getAddress(m));
		// iterate over atoms in list
		t_osc_msg_it_u *m_it_u = osc_msg_it_u_get(m);
		while(osc_msg_it_u_hasNext(m_it_u)){
			t_osc_atom_u *a = osc_msg_it_u_next(m_it_u);
			printf("%c", osc_atom_u_getTypetag(a));
		}
		osc_msg_it_u_destroy(m_it_u);
		printf("\n");
	}
	osc_bndl_it_u_destroy(b_it_u);
}
Esempio n. 4
0
//void oO_fullPacket(t_oO *x, long len, long ptr)
void oO_fullPacket(t_oO *x, t_symbol *msg, int argc, t_atom *argv)
{
	char bracket[] = {'[', ']', '{', '}'};
	char wild[] = {'*', '?'};
	char alphanum[62];
	for(int i = 0; i < 10; i++){
		alphanum[i] = i + 48;
	}
	for(int i = 0; i < 26; i++){
		alphanum[i + 10] = i + 65;
	}
	for(int i = 0; i < 26; i++){
		alphanum[i + 36] = i + 97;
	}

	OMAX_UTIL_GET_LEN_AND_PTR;
	char copy[len];
	memcpy(copy, ptr, len);
	int n = 0;
	osc_bundle_s_getMsgCount(len, copy, &n);
	long r = floor(((double)random() / 2147483647.) * n);
	t_osc_bndl_it_s *it = osc_bndl_it_s_get(len, copy);
	int i = 0;
	t_osc_msg_s *m = NULL;
	while(i <= r && osc_bndl_it_s_hasNext(it)){
		i++;
		m = osc_bndl_it_s_next(it);
	}
	osc_bndl_it_s_destroy(it);
	if(m){
		char *p = osc_message_s_getAddress(m);
		if(p){
			int n = osc_message_s_getSize(m);
			long r = floor(((double)random() / 2147483647.) * n);
			if(r <= strlen(p)){
				// inside address section---can add a random NULL byte or f**k with wildcard chars
				switch(random() & 0x1){
				case 0:
					object_post((t_object *)x, "replaced '%c' at position %d with NULL\n", p[r], r);
					p[r] = '\0';
					break;
				case 1:
					{
						int isbracket = 0;
						for(int i = 0; i < sizeof(bracket); i++){
							if(bracket[i] == p[r]){
								isbracket = 1;
								break;
							}
						}
						if(isbracket){
							// we have a bracket, replace it with an alphanum char or NULL
							switch(random() & 0x1){
							case 0:
								{
									long rrr = (long)floor(((double)random() / 2147483647.) * sizeof(alphanum));
									object_post((t_object *)x, "replaced '%c' at position %d with '%c'\n", p[r], r, alphanum[rrr]);
									p[r] = alphanum[rrr];
								}
								break;
							case 1:
								object_post((t_object *)x, "replaced '%c' at position %d with NULL\n", p[r], r);
								p[r] = NULL;
								break;
							}
						}else{
							// not a bracket, replace it with one or NULL
							switch(random() & 0x1){
							case 0:
								{
									long rrr = (long)floor(((double)random() / 2147483647.) * sizeof(bracket));
									object_post((t_object *)x, "replaced '%c' at position %d with '%c'\n", p[r], r, bracket[rrr]);
									p[r] = bracket[rrr];
								}
								break;
							case 1:
								object_post((t_object *)x, "replaced '%c' at position %d with NULL\n", p[r], r);
								p[r] = NULL;
								break;
							}
						}
					}
					break;
				}
			}else if(r < (osc_message_s_getData(m) - p)){
				// typetag section---add a NULL or char
				if(p[r] == NULL){
					long rrr = (long)floor(((double)random() / 2147483647.) * sizeof(alphanum));
					object_post((t_object *)x, "replaced NULL at position %d with '%c'\n", r, alphanum[rrr]);
					p[r] = alphanum[rrr];
				}else{
					object_post((t_object *)x, "replaced '%c' at position %d with NULL\n", p[r], r);
					p[r] = NULL;
				}
			}else{
				// not much we can do here unles we know it's a string or something else with NULL padding, 
				// so just try again
				oO_fullPacket(x, msg, argc, argv);
				return;
			}
		}
	}
	omax_util_outletOSC(x->outlet, len, copy);
}