コード例 #1
0
ファイル: o.listenumerate.c プロジェクト: equilet/CNMAT-odot
void olistenumerate_doFullPacket(t_olistenumerate *x,
                           long len,
                           char *ptr)
{
    if (!x->address) {
        return;
    }
    
    critical_enter(x->lock);
    char* address_name = x->address->s_name;
    critical_exit(x->lock);
    
    t_osc_msg_ar_s *matches = osc_bundle_s_lookupAddress(len, ptr, address_name, 1);
    
    char delegate[len];
    long dlen = len;
    memcpy(delegate, ptr, len);
    
    if (matches) {
        // right outlet:
        osc_bundle_s_removeMessage(address_name, &dlen, delegate, 1);
        int message_count = 0;
        osc_bundle_s_getMsgCount(dlen, delegate, &message_count);
        if (message_count > 0) {
            omax_util_outletOSC(x->outlets[0], dlen, delegate);
            OSC_MEM_INVALIDATE(delegate);
        }
        
        // left outlet:
        for (int i = 0; i < osc_array_getLen(matches); ++i)
        {
            t_osc_message_s* message_match = (t_osc_message_s*)osc_array_get(matches, i);
            t_osc_message_u* unserialized_msg = osc_message_s_deserialize(message_match);
            
            int array_length = osc_message_u_getArgCount(unserialized_msg);
            if (array_length > 0)
            {
                for (int j = 0; j < array_length; ++j)
                {
			t_osc_atom_u* iter_atom = osc_message_u_getArg(unserialized_msg, j);
                    t_osc_atom_u* atom_copy = osc_atom_u_copy(iter_atom);
                    if (atom_copy)
                    {
                        t_osc_bundle_u* unserialized_result = NULL;
                        //char type = osc_atom_u_getTypetag(atom_copy);
                        unserialized_result = osc_bundle_u_alloc();
                        t_osc_message_u* value = osc_message_u_allocWithAddress("/value");
                        osc_message_u_appendAtom(value, atom_copy);
                        osc_bundle_u_addMsg(unserialized_result, value);
                        
                        t_osc_message_u* address = osc_message_u_allocWithString("/address", address_name);
                        t_osc_message_u* index = osc_message_u_allocWithAddress("/index");
                        osc_message_u_appendInt32(index, j);
                        t_osc_message_u* length = osc_message_u_allocWithAddress("/length");
                        osc_message_u_appendInt32(length, array_length);
                        osc_bundle_u_addMsg(unserialized_result, address);
                        osc_bundle_u_addMsg(unserialized_result, index);
                        osc_bundle_u_addMsg(unserialized_result, length);
                        t_osc_bndl_s *bs = osc_bundle_u_serialize(unserialized_result);
                        osc_bundle_u_free(unserialized_result); // frees value, count, length and atom_copy
                        unserialized_result = NULL;
                        atom_copy = NULL;
                        
                        if (bs)
                        {
				omax_util_outletOSC(x->outlets[1], osc_bundle_s_getLen(bs), osc_bundle_s_getPtr(bs));
				osc_bundle_s_deepFree(bs);
                            bs = NULL;
                        }
                    }
                }
                
                if (unserialized_msg) {
                    osc_message_u_free(unserialized_msg);
                    unserialized_msg = NULL;
                }
                
            } else {
                olistenumerate_noMatchesOrData(x);
            }
        }
    } else { // no matches
        // right outlet:
        omax_util_outletOSC(x->outlets[0], dlen, delegate);
    }
    
    if (matches) {
        osc_array_free(matches);
    }
}
コード例 #2
0
ファイル: o.O.c プロジェクト: CNMAT/CNMAT-odot
//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);
}