Ejemplo n.º 1
0
void t16_soft_dup_dict_in_dict(){
	INIT_LOCAL();

	onion_dict *orig=onion_dict_new();

	char tmp[9];
	int i;
	for (i=0;i<256;i++){
		sprintf(tmp,"%08X",rand());
		onion_dict_add(orig, tmp, tmp, OD_DUP_ALL);
	}
	onion_dict_add(orig, "0", "no frees", 0);

	onion_dict *subdict=onion_dict_new();
	onion_dict_add(subdict,"subdict","test",0);
	onion_dict_add(orig, "subdict", subdict, OD_DICT|OD_FREE_VALUE);

	onion_dict *dest=onion_dict_dup(orig);

	FAIL_IF_NOT(orig==dest);

	/// Check they have exactly the same keys.
	onion_dict_preorder(orig, cmpdict, dest);
	onion_dict_preorder(dest, cmpdict, orig);

	onion_dict_free(orig);
	onion_dict_free(dest);

	END_LOCAL();
}
Ejemplo n.º 2
0
		/**
		 * @short Assigns the reference to the ditionary, from a C onion_dict.
		 */
		Dict &operator=(const onion_dict *o){
// 			ONION_DEBUG0("%p = %p (~%p)", this, o, ptr);
			onion_dict *ptr2=ptr;
			ptr=onion_dict_dup((onion_dict*)(o));
			onion_dict_free(ptr2);
			return *this;
		}
Ejemplo n.º 3
0
		/**
		 * @short Assings the reference to the dictionary.
		 */
		Dict &operator=(const Dict &o){
// 			ONION_DEBUG0("= %p:%p (~%p:%p)", &o, o.ptr, this, ptr);
			onion_dict *ptr2=ptr;
			ptr=onion_dict_dup((onion_dict*)(o.ptr));
			onion_dict_free(ptr2);
// 			ONION_DEBUG0("Done");
			return *this;
		}
Ejemplo n.º 4
0
onion_connection_status Onion::render_to_response(::Onion::template_f fn, const ::Onion::Dict& context, ::Onion::Response &res) {
    ONION_DEBUG("Context: %s", context.toJSON().c_str());

    onion_dict *d=onion_dict_dup( context.c_handler() );

    fn(d, res.c_handler());

    return OCS_PROCESSED;
}
Ejemplo n.º 5
0
static onion_dict *onion_sessions_mem_get(onion_sessions *sessions, const char *session_id){
	ONION_DEBUG0("Accessing session '%s'",session_id);
	onion_dict *sess=onion_dict_get_dict(sessions->data, session_id);
	if (!sess){
		ONION_DEBUG0("Unknown session '%s'.", session_id);
		return NULL;
	}
	return onion_dict_dup(sess);
}
Ejemplo n.º 6
0
static void onion_sessions_mem_save(onion_sessions *sessions, const char *session_id, onion_dict *data){
	if (data==NULL){
		data=onion_dict_get_dict(sessions->data, session_id);
		if (data){
			onion_dict_remove(sessions->data, session_id);
		}
		return;
	}
	onion_dict_add(sessions->data, session_id, onion_dict_dup(data), OD_DUP_KEY|OD_FREE_VALUE|OD_DICT|OD_REPLACE);
}
Ejemplo n.º 7
0
void t05_context(){
	INIT_LOCAL();
	Onion::Dict dict(defaultContext());
	ONION_DEBUG("Render");
	
	// This is important as otemplate templates need ownership as they 
	// will free the pointer. These way we use the internal refcount to avoid double free.
	onion_dict_dup(dict.c_handler()); 
	
	index_html_template(dict.c_handler());
	END_LOCAL();
}
Ejemplo n.º 8
0
void t09_thread_war(){
	INIT_LOCAL();
	
	pthread_t thread[NWAR];
	int i;
	onion_dict *d=onion_dict_new();
	for (i=0;i<NWAR;i++){
		onion_dict *dup=onion_dict_dup(d);
		pthread_create(&thread[i], NULL, (void*)&t09_thread_war_thread, dup);
	}
	
	onion_dict_free(d);

	for (i=0;i<NWAR;i++){
		pthread_join(thread[i], NULL);
	}
	
	END_LOCAL();
}
Ejemplo n.º 9
0
void t08_threaded_lock(){
	INIT_LOCAL();
	
	onion_dict *d=onion_dict_new();
	
	pthread_t thread[N_READERS];
	int i;
	for (i=0;i<N_READERS;i++){
		onion_dict *d2=onion_dict_dup(d);
		pthread_create(&thread[i], NULL, (void*)t08_thread_read, d2);
	}
	//sleep(1);
	t08_thread_write(d);
	
	for (i=0;i<N_READERS;i++){
		char *v;
		pthread_join(thread[i],(void**) &v);
		FAIL_IF_NOT_EQUAL(v, (char *)v);
	}
	
	END_LOCAL();
}
Ejemplo n.º 10
0
		/**
		 * @short Creates a new reference to the dict.
		 * 
		 * WARNING: As Stated it is a reference, not a copy. For that see Onion::Dict::hard_dup.
		 */
		Dict(const Dict &d) : ptr(d.ptr){
			onion_dict_dup(ptr);
// 			ONION_DEBUG0("Dict %p:%p", this, ptr);
		}
Ejemplo n.º 11
0
    /**
		 * @short Creates a Onion::Dict from a c onion_dict.
		 * 
		 * WARNING Losts constness. I found no way to keep it.
		 */
		Dict(const onion_dict *_ptr, bool owner=false) : ptr((onion_dict*)_ptr){
// 			ONION_DEBUG0("Dict %p:%p", this, ptr);
			if (!owner)
				onion_dict_dup(ptr);
		}
Ejemplo n.º 12
0
onion_connection_status extended_html_template(Onion::Dict &d, Onion::Request &req, Onion::Response &res){
	extended_html_template(onion_dict_dup(d.c_handler()),req.c_handler(), res.c_handler());
}