Example #1
0
RAW *forge_raw(const char *raw, json_item *jlist)
{
	RAW *new_raw;
	char unixtime[16];
	struct jsontring *string;
	
	json_item *jstruct = NULL;
		
	sprintf(unixtime, "%li", time(NULL));
	
	jstruct = json_new_object();
	
	json_set_property_strN(jstruct, "time", 4, unixtime, strlen(unixtime));
	json_set_property_strN(jstruct, "raw", 3, raw, strlen(raw));
	json_set_property_objN(jstruct, "data", 4, jlist);

	string = json_to_string(jstruct, NULL, 1);

	new_raw = xmalloc(sizeof(*new_raw));
    	new_raw->len = string->len;
	new_raw->next = NULL;
	new_raw->priority = RAW_PRI_LO;
	new_raw->refcount = 0;

	new_raw->data = string->jstring;

	free(string);

	return new_raw;
}
Example #2
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 *jcopy = json_copy(eTmp->val);
				
				set_json(eTmp->key, NULL, &jprop);
				
				json_attach(jprop, jcopy, JSON_OBJECT);*/
			} else {
				json_set_property_strZ(jprop, eTmp->key, eTmp->val);
			}
		}
		
		eTmp = eTmp->next;
	}
	json_set_property_objN(jstr, "properties", 10, jprop);
	
	//}
	
	return jstr;
}
Example #3
0
unsigned int cmd_connect(callbackp *callbacki)
{
	USERS *nuser;
	RAW *newraw;
	json_item *jstr = NULL;

	nuser = adduser(NULL, NULL, NULL, callbacki->call_user, callbacki->g_ape);
	
	callbacki->call_user = nuser;

	jstr = json_new_object();
	json_set_property_objN(jstr, "user", 4, get_json_object_user(callbacki->call_user));	
	
	newraw = forge_raw("IDENT", jstr);
	newraw->priority = RAW_PRI_HI;
	post_raw_sub(newraw, callbacki->call_subuser, callbacki->g_ape);	

	jstr = json_new_object();	
	json_set_property_strN(jstr, "sessid", 6, nuser->sessid, 32);
	
	newraw = forge_raw(RAW_LOGIN, jstr);
	newraw->priority = RAW_PRI_HI;
	
	post_raw(newraw, nuser, callbacki->g_ape);	
	
	return (RETURN_NOTHING);
}
Example #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;
}
Example #5
0
json_item *get_json_object_proxy(ape_proxy *proxy)
{
	json_item *jstr = json_new_object();
	json_item *jprop = json_new_object();
	extend *eTmp = proxy->properties;

	json_set_property_strN(jstr, "pubid", 5, proxy->pipe->pubid, 32);
	json_set_property_strN(jstr, "casttype", 8, "proxy", 5);
	
	json_set_property_strZ(jprop, "host", proxy->sock.host->host);
	json_set_property_strZ(jprop, "ip", proxy->sock.host->ip);
	json_set_property_intZ(jprop, "port", proxy->sock.port);

	while (eTmp != NULL) {
		json_set_property_strZ(jprop, eTmp->key, eTmp->val);
		eTmp = eTmp->next;
	}
	
	json_set_property_objN(jstr, "properties", 10, jprop);

	return jstr;
}
Example #6
0
void proxy_process_eol(ape_socket *co, acetables *g_ape)
{
	char *b64;
	ape_proxy *proxy = co->attach;
	char *data = co->buffer_in.data;

	RAW *newraw;
	json_item *jlist = json_new_object();
	
	data[co->buffer_in.length] = '\0';
	b64 = base64_encode(data, strlen(data));
	
	json_set_property_strZ(jlist, "data", b64);
	json_set_property_strN(jlist, "event", 5, "READ", 4);
	json_set_property_objN(jlist, "pipe", 4, get_json_object_proxy(proxy));
	
	newraw = forge_raw("PROXY_EVENT", jlist);
	
	proxy_post_raw(newraw, proxy, g_ape);
	
	free(b64);	
}
Example #7
0
json_item *json_set_element_strN(json_item *obj, const char *value, int valuelen)
{
	return json_set_property_strN(obj, NULL, 0, value, valuelen);
}
Example #8
0
void json_set_property_strZ(json_item *obj, const char *key, const char *value)
{
	int len = (key != NULL ? strlen(key) : 0);
	
	json_set_property_strN(obj, key, len, value, strlen(value));
}