Exemplo n.º 1
0
json_item *get_json_object_channel(CHANNEL *chan)
{
	json_item *jstr = json_new_object();
	json_set_property_strN(jstr, "casttype", 8, "multi", 5);
	json_set_property_strN(jstr, "pubid", 5, chan->pipe->pubid, 32);

	json_item *jprop = json_new_object();
	json_set_property_strZ(jprop, "name", chan->name);

	extend *eTmp = chan->properties;
	
	while (eTmp != NULL) {
		if (eTmp->visibility == EXTEND_ISPUBLIC) {
			if (eTmp->type == EXTEND_JSON) {
				json_item *jcopy = json_item_copy(eTmp->val, NULL);
				
				json_set_property_objZ(jprop, eTmp->key, jcopy);
			} else {
				json_set_property_strZ(jprop, eTmp->key, eTmp->val);
			}
		}
		
		eTmp = eTmp->next;
	}
	json_set_property_objN(jstr, "properties", 10, jprop);
	
	//}
	
	return jstr;
}
Exemplo n.º 2
0
json_item *json_item_copy(json_item *cx, json_item *father)
{
	json_item *new_item = NULL, *return_item = NULL;
	json_item *temp_item = NULL;

	while (cx != NULL) {	
		new_item = init_json_item();
		new_item->father = father;
		
		if (return_item == NULL) {
			return_item = new_item;
		}

		new_item->type = cx->type;
		new_item->jchild.type = cx->jchild.type;
		
		if (temp_item != NULL) {
			temp_item->next = new_item;
		}
		
		if (cx->key.val != NULL) {
			new_item->key.len = cx->key.len;
			new_item->key.val = xmalloc(sizeof(char) * (cx->key.len + 1));
			memcpy(new_item->key.val, cx->key.val, cx->key.len + 1);
		}
		
		if (cx->jval.vu.str.value != NULL) {
			new_item->jval.vu.str.length = cx->jval.vu.str.length;
			new_item->jval.vu.str.value = xmalloc(sizeof(char) * (cx->jval.vu.str.length + 1));
			memcpy(new_item->jval.vu.str.value, cx->jval.vu.str.value, cx->jval.vu.str.length + 1);
		} else if (cx->jval.vu.integer_value) {
			new_item->jval.vu.integer_value = cx->jval.vu.integer_value;
		} else if (cx->jval.vu.float_value) {
			new_item->jval.vu.float_value = cx->jval.vu.float_value;
		}
		if (cx->jchild.child != NULL) {
			new_item->jchild.child = json_item_copy(cx->jchild.child, new_item);
		}
		if (new_item->father != NULL) {
			new_item->father->jchild.head = new_item;
		}
		temp_item = new_item;
		
		cx = cx->next;
	}
	
	return return_item;
}
Exemplo n.º 3
0
int post_to_pipe(json_item *jlist, const char *rawname, const char *pipe, subuser *from, acetables *g_ape)
{
	USERS *sender = from->user;
	transpipe *recver = get_pipe_strict(pipe, sender, g_ape);
	json_item *jlist_copy = NULL;
	RAW *newraw;
	
	if (sender != NULL) {
		if (recver == NULL) {
			send_error(sender, "UNKNOWN_PIPE", "109", g_ape);
			return 0;
		}
		json_set_property_objN(jlist, "from", 4, get_json_object_user(sender));

	}
	
	if (sender != NULL && sender->nsub > 1) {
		jlist_copy = json_item_copy(jlist, NULL);
	
		json_set_property_objN(jlist_copy, "pipe", 4, get_json_object_pipe(recver));
		newraw = forge_raw(rawname, jlist_copy);
		post_raw_restricted(newraw, sender, from, g_ape);
	}	
	switch(recver->type) {
		case USER_PIPE:
			json_set_property_objN(jlist, "pipe", 4, get_json_object_user(sender));
			newraw = forge_raw(rawname, jlist);
			post_raw(newraw, recver->pipe, g_ape);
			break;
		case CHANNEL_PIPE:
			if (((CHANNEL*)recver->pipe)->head != NULL && ((CHANNEL*)recver->pipe)->head->next != NULL) {
				json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(recver->pipe));
				newraw = forge_raw(rawname, jlist);
				post_raw_channel_restricted(newraw, recver->pipe, sender, g_ape);
			}
			break;
		case CUSTOM_PIPE:
			json_set_property_objN(jlist, "pipe", 4, get_json_object_user(sender));
			post_json_custom(jlist, sender, recver, g_ape);
			break;
		default:
			break;
	}
		
	return 1;
}
Exemplo n.º 4
0
json_item *get_json_object_user(USERS *user)
{
	json_item *jstr = NULL;
	
	if (user != NULL) {
		jstr = json_new_object();
		json_set_property_strN(jstr, "casttype", 8, "uni", 3);
		json_set_property_strN(jstr, "pubid", 5, user->pipe->pubid, 32);
		
		if (user->properties != NULL) {
			int has_prop = 0;
			
			json_item *jprop = NULL;
						
			extend *eTmp = user->properties;
			
			while (eTmp != NULL) {
				if (eTmp->visibility == EXTEND_ISPUBLIC) {
					if (!has_prop) {
						has_prop = 1;
						jprop = json_new_object();
					}
					if (eTmp->type == EXTEND_JSON) {
						json_item *jcopy = json_item_copy(eTmp->val, NULL);
						
						json_set_property_objZ(jprop, eTmp->key, jcopy);
					} else {
						json_set_property_strZ(jprop, eTmp->key, eTmp->val);

					}			
				}
				eTmp = eTmp->next;
			}
			if (has_prop) {
				json_set_property_objN(jstr, "properties", 10, jprop);
			}
		}

	} else {
		json_set_property_strZ(jstr, "pubid", SERVER_NAME);
	}
	return jstr;
}
Exemplo n.º 5
0
unsigned int checkcmd(clientget *cget, transport_t transport, subuser **iuser, acetables *g_ape)
{	
	struct _cmd_process pc = {cget->hlines, NULL, NULL, cget->client, cget->host, cget->ip_get, transport};
	
	json_item *ijson, *ojson;
	
	unsigned int ret;

	ijson = ojson = init_json_parser(cget->get);
	if (ijson == NULL || ijson->jchild.child == NULL) {
		RAW *newraw;
		json_item *jlist = json_new_object();

		json_set_property_strZ(jlist, "code", "005");
		json_set_property_strZ(jlist, "value", "BAD_JSON");

		newraw = forge_raw(RAW_ERR, jlist);
		
		send_raw_inline(cget->client, transport, newraw, g_ape);
	} else {
		for (ijson = ijson->jchild.child; ijson != NULL; ijson = ijson->next) {
			
			if (pc.guser != NULL && pc.guser->istmp) { /* if "CONNECT" was delayed, push other cmd to the queue and stop execution */
				pc.guser->cmdqueue = json_item_copy(ijson, NULL);
				break;
			}		
			if ((ret = process_cmd(ijson, &pc, iuser, g_ape)) != -1) {
				free_json_item(ojson);
				return ret;
			}
			if (*iuser != NULL) {
				pc.sub = *iuser;
			}					
		}
		free_json_item(ojson);

		return (CONNECT_KEEPALIVE);
	}
	
	return (CONNECT_SHUTDOWN);
}