#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <assert.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>

#include <ccn/ccn.h>
#include <ccn/uri.h>
#include <ccn/keystore.h>
#include <ccn/signing.h>
#include <ccn/schedule.h>
#include <ccn/hashtb.h>
#include <ccn/sync.h>
#include <ccn/seqwriter.h>

#include "nlsr.h"
#include "nlsr_sync.h"
#include "nlsr_lsdb.h"
#include "utility.h"
#include "nlsr_km.h"
#include "nlsr_km_util.h"


char *
hex_string(unsigned char *s, size_t l)
{
	const char *hex_digits = "0123456789abcdef";
	char *r;
	int i;
	r = calloc(1, 1 + 2 * l);
	for (i = 0; i < l; i++) {
		r[2*i] = hex_digits[(s[i]>>4) & 0xf];
		r[1+2*i] = hex_digits[s[i] & 0xf];
	}
	return(r);
}

/**
* call back function from sync. Receive notification of updates in sync.
* This function calls process_content_from_sync to handle incoming content
* from sync.
*/

int
sync_cb(struct ccns_name_closure *nc,
		struct ccn_charbuf *lhash,
		struct ccn_charbuf *rhash,
		struct ccn_charbuf *name)
{
	nlsr_lock();
	int res;
	struct ccn_charbuf *content_name; 
	struct ccn_indexbuf *content_comps;
	struct ccn_indexbuf *name_comps;
	
	content_comps = ccn_indexbuf_create();
	res = ccn_name_split(name, content_comps);
	if ( res < 0 )
		return 0;
	
	if (content_comps->n < 2)
		return 0;

	content_name = ccn_charbuf_create();
	ccn_name_init(content_name);
	
	res = ccn_name_append_components( content_name,	name->buf,
			content_comps->buf[0], content_comps->buf[content_comps->n - 1]);

	if ( res < 0)
		return 0;

	// for debugging
	struct ccn_charbuf *temp=ccn_charbuf_create();
	ccn_uri_append(temp, content_name->buf, content_name->length, 0);
	if ( nlsr->debugging )
		printf("Name before chopping: %s \n",ccn_charbuf_as_string(temp));
	ccn_charbuf_destroy(&temp);

	name_comps = ccn_indexbuf_create();
	res=ccn_name_split (content_name, name_comps);
	if (res < 0)
		return 0;		

	if ( nlsr->debugging )
	{
		printf("Number of components in name = %d \n",res);
		printf("Number of components in name as indexbuf->n = %d \n",
				(int)name_comps->n);
	}

	ccn_name_chop(content_name, name_comps, -3);
	if ( nlsr->debugging )
		printf("Number of components in name as indexbuf->n after chopping= %d \n"
				, (int)name_comps->n);	

	//for debugging 
	struct ccn_charbuf *temp1=ccn_charbuf_create();
	ccn_uri_append(temp1, content_name->buf, content_name->length, 0);
	if ( nlsr->debugging )
		printf("Name after chopping: %s \n",ccn_charbuf_as_string(temp1));
	ccn_charbuf_destroy(&temp1);

	//main method that processes contents from the sync
	process_content_from_sync(content_name, name_comps);
	
	ccn_charbuf_destroy(&content_name);
	ccn_indexbuf_destroy(&content_comps);
	ccn_indexbuf_destroy(&name_comps);

	nlsr_unlock();
	return(0);
}


/**
* this function retrieve part of name from interest name and put it in name_part
*/

void
get_name_part(struct name_prefix *name_part,struct ccn_charbuf * interest_ccnb, 
		struct ccn_indexbuf *interest_comps, int offset)
{
	int lsa_position=0;
	
	struct ccn_indexbuf *components=ccn_indexbuf_create();
	struct ccn_charbuf *name=ccn_charbuf_create();
	ccn_name_from_uri(name,nlsr->slice_prefix);
	ccn_name_split (name, components);
	lsa_position=components->n-2;
	ccn_charbuf_destroy(&name);

	struct ccn_charbuf *temp=ccn_charbuf_create();
	ccn_name_init(temp);	
	ccn_name_append_components( temp,	interest_ccnb->buf,
								interest_comps->buf[lsa_position+1], 
								interest_comps->buf[interest_comps->n - 1]);

	struct ccn_charbuf *temp1=ccn_charbuf_create();
	ccn_uri_append(temp1, temp->buf, temp->length, 0);

	name_part->name=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1,
																sizeof(char));
	memcpy(name_part->name,ccn_charbuf_as_string(temp1),
										strlen(ccn_charbuf_as_string(temp1)));
	name_part->name[strlen(ccn_charbuf_as_string(temp1))]='\0';
	name_part->length=strlen(ccn_charbuf_as_string(temp1))+1;

	ccn_charbuf_destroy(&temp1);
	ccn_charbuf_destroy(&temp);
	ccn_indexbuf_destroy(&components);

	if ( nlsr->debugging )
		printf("Name Part: %s \n",name_part->name);
	
}


/**
* Get content value by content name and put the content value in content_data
*/


int 
get_content_by_content_name(char *content_name, unsigned char **content_data,
							char *orig_router)
{
	
	int ret=-1;
	struct ccn_charbuf *name = NULL;
	struct ccn_charbuf *templ = NULL;
	struct ccn_charbuf *resultbuf = NULL;
	struct ccn_parsed_ContentObject pcobuf = { 0 };
	int res;
	int allow_stale = 1;
	int content_only = 1;
	int scope = -1;
	const unsigned char *ptr;//,*ptr_in; 
	size_t length;//,length_in;
	int resolve_version = CCN_V_HIGHEST;
	int timeout_ms = 3000;
	const unsigned lifetime_default = CCN_INTEREST_LIFETIME_SEC << 12;
	unsigned lifetime_l12 = lifetime_default;
	int get_flags = 0;

	name = ccn_charbuf_create();
	res = ccn_name_from_uri(name,content_name);
	if (res < 0) {
		fprintf(stderr, "Bad ccn URI: %s\n", content_name);
		ccn_charbuf_destroy(&name);
		return ret;
	}

	if (allow_stale || lifetime_l12 != lifetime_default || scope != -1) {
		templ = ccn_charbuf_create();
		ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
		ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
		ccn_charbuf_append_closer(templ); /* </Name> */
		if (allow_stale) {
			ccn_charbuf_append_tt(templ, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
			ccnb_append_number(templ,
					CCN_AOK_DEFAULT | CCN_AOK_STALE);
			ccn_charbuf_append_closer(templ); /* </AnswerOriginKind> */
		}
		if (scope != -1) {
			ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
		}
		if (lifetime_l12 != lifetime_default) {
			/*
			 * Choose the interest lifetime so there are at least 3
			 * expressions (in the unsatisfied case).
			 */
			unsigned char buf[3] = { 0 };
			int i;
			for (i = sizeof(buf) - 1; i >= 0; i--, lifetime_l12 >>= 8)
				buf[i] = lifetime_l12 & 0xff;
			ccnb_append_tagged_blob(templ, CCN_DTAG_InterestLifetime, buf, 
					sizeof(buf));
		}
		ccn_charbuf_append_closer(templ); /* </Interest> */
	}
	resultbuf = ccn_charbuf_create();
	if (resolve_version != 0) {
		res = ccn_resolve_version(nlsr->ccn, name, resolve_version, 500);
		if (res >= 0) {
			ccn_uri_append(resultbuf, name->buf, name->length, 1);
			resultbuf->length = 0;
		}
	}
	res = ccn_get(nlsr->ccn, name, templ, timeout_ms, resultbuf, &pcobuf, NULL, 
			get_flags);
	if (res >= 0) {
		ptr = resultbuf->buf;
		length = resultbuf->length;
		if (content_only){
			ccn_content_get_value(ptr, length, &pcobuf, &ptr, &length);
			struct ccn_parsed_ContentObject pcobuf1 = { 0 };
			int chk_cont=ccn_parse_ContentObject(ptr,length,&pcobuf1,NULL);
			if ( nlsr->debugging )	
				printf("Content Parsing result: %d\n",chk_cont); 
			if ( contain_key_name(ptr, &pcobuf1) == 1){
						
				int res_verify=verify_key(ptr,&pcobuf1,1);

				if ( res_verify != 0 ){
					if ( nlsr->debugging )
						printf("Error in verfiying keys !! :( \n");
				}
				else{
					if ( nlsr->debugging )
						printf("Key verification is successful :)\n");
					//ptr_in=ptr;
					//length_in=length;
					//ccn_content_get_value(ptr_in, length_in, &pcobuf1, 
					//										&ptr_in, &length_in);
					*content_data = (unsigned char *) calloc(length, 
																sizeof(char *));
					memcpy (*content_data, ptr, length);
					ret=0;
				}
			}
		}
	}

	ccn_charbuf_destroy(&resultbuf);
	ccn_charbuf_destroy(&templ);
	ccn_charbuf_destroy(&name);

	return ret;   
}

/**
* Handle incoming lsa content, Calls functions to install lsa into lsdb
*/

void 
process_incoming_sync_content_lsa( unsigned char *content_data)
{


	if ( nlsr->debugging )
		printf("process_incoming_sync_content_lsa called \n");	

	char *sep="|";
	char *rem;
	char *orig_router;
	char *orl;
	int orig_router_length;
	char *lst;
	int ls_type;
	char *lsid;
	long int ls_id;
	char *isvld;
	int isValid;
	char *num_link;
	int no_link;
	char *np;
	char *np_length;
	int name_length;
	char *data;
	char *orig_time;


	if ( nlsr->debugging )
		printf("LSA Data \n");

	if( strlen((char *)content_data ) > 0 )
	{

		orig_router=strtok_r((char *)content_data,sep,&rem);
		orl=strtok_r(NULL,sep,&rem);
		orig_router_length=atoi(orl);

		if ( nlsr->debugging )
		{
			printf("	Orig Router Name  : %s\n",orig_router);
			printf("	Orig Router Length: %d\n",orig_router_length);
		}

		lst=strtok_r(NULL,sep,&rem);		
		ls_type=atoi(lst);

		if ( nlsr->debugging )
			printf("	LS Type  : %d\n",ls_type);

		if ( ls_type == LS_TYPE_NAME )
		{
			lsid=strtok_r(NULL,sep,&rem);
			ls_id=atoi(lsid);
			orig_time=strtok_r(NULL,sep,&rem);
			isvld=strtok_r(NULL,sep,&rem);
			isValid=atoi(isvld);
			np=strtok_r(NULL,sep,&rem);
			np_length=strtok_r(NULL,sep,&rem);
			name_length=atoi(np_length);
			if ( nlsr->debugging )
			{
				printf("	LS ID  : %ld\n",ls_id);
				printf("	isValid  : %d\n",isValid);
				printf("	Name Prefix : %s\n",np);
				printf("	Orig Time   : %s\n",orig_time);
				printf("	Name Prefix length: %d\n",name_length);
			}

			build_and_install_others_name_lsa(orig_router,ls_type,ls_id,
														orig_time,isValid,np);

			print_name_lsdb();

		}
		else if ( ls_type == LS_TYPE_ADJ )
		{
			orig_time=strtok_r(NULL,sep,&rem);
			num_link=strtok_r(NULL,sep,&rem);
			no_link=atoi(num_link);
			data=rem;

			if ( nlsr->debugging )
			{
				printf("	Orig Time   : %s\n",orig_time);
				printf("	No Link  : %d\n",no_link);
				printf("	Data  : %s\n",data);
			}
			build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,
																no_link,data);
		}
		else if ( ls_type == LS_TYPE_COR )
		{
			orig_time=strtok_r(NULL,sep,&rem);
			char *cor_r=strtok_r(NULL,sep,&rem);
			char *cor_theta=strtok_r(NULL,sep,&rem);

			double r, theta;
			r=strtod(cor_r,NULL);
			theta=strtod(cor_theta,NULL);

			if ( nlsr->debugging )
			{
				printf("	Orig Time   : %s\n",orig_time);
				printf("	Cor R	    : %f\n",r);
				printf("	Cor Theta   : %f\n",theta);
			}
			build_and_install_others_cor_lsa(orig_router,ls_type,orig_time, 
													(double)r, (double)theta);	
		}

	}
}

/**
* Check LSA whether its new. If new retrieve the LSA content and call 
* process_incoming_sync_content_lsa with content_data
*/

void
process_content_from_sync (struct ccn_charbuf *content_name, 
								struct ccn_indexbuf *components)
{
	if (nlsr->debugging)
		printf("process_content_from_sync called \n");
	size_t comp_size;
	char *lst;
	char *lsid;
	const unsigned char *second_last_comp;
	const unsigned char *third_last_comp;
	const unsigned char *origtime;
	char *sep=".";
	char *rem;
	char *second_comp_type;

	int ls_type;
	long int ls_id=0;

	unsigned char *content_data = NULL;

	char *time_stamp=get_current_timestamp_micro_v2();

	struct ccn_charbuf *uri = ccn_charbuf_create();
	ccn_uri_append(uri, content_name->buf, content_name->length, 0);	

	struct name_prefix *orig_router=(struct name_prefix *)
								calloc( 1, sizeof(struct name_prefix));

	ccn_name_comp_get( content_name->buf, components, 
					  components->n-1-2, &second_last_comp, &comp_size);
	
	if (nlsr->debugging)
		printf("2nd Last Component: %s \n", second_last_comp);

	second_comp_type=strtok_r((char *)second_last_comp, sep, &rem);
	if (second_comp_type == NULL || rem == NULL)
	{
		printf ("Error: unable to tokenize the string: %s, calling exit()\n",
													(char *)second_last_comp); 
		exit(0);
	}

	if ( strcmp( second_comp_type, "lsId" ) == 0 )
	{	
		lsid=rem;
		ls_id=atoi(rem);
		ccn_name_comp_get(content_name->buf, components,components->n-2-2,
												&third_last_comp, &comp_size);
		lst=strtok_r((char *)third_last_comp,sep,&rem);
		lst=rem;
		ls_type=atoi(lst);
		ccn_name_comp_get(content_name->buf, components,components->n-2,
														&origtime, &comp_size);
		ccn_name_chop(content_name,components,-3);
		get_name_part(orig_router,content_name,components,0);

		if ( nlsr->debugging )
			printf("Orig Router: %s Ls Type: %d Ls id: %ld Orig Time: %s\n",
									orig_router->name,ls_type,ls_id,origtime);

		int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
		if ( nlsr->debugging )
			printf("LSA Life time: %d\n",lsa_life_time);

		if ( strcmp(orig_router->name,nlsr->router_name) != 0 
				&& (lsa_life_time < nlsr->router_dead_interval) )
		{
			int is_new_name_lsa=check_is_new_name_lsa(orig_router->name,
									(char *)lst,(char *)lsid,(char *)origtime);
			if ( is_new_name_lsa == 1 )
			{
				if ( nlsr->debugging )
					printf("New NAME LSA.....\n");	
				int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
												&content_data,orig_router->name);
				if ( chk_con == 0 ){
					if ( nlsr->debugging )
						printf("Content Data: %s \n",content_data);
					process_incoming_sync_content_lsa(content_data);
				}
				else{
					if ( nlsr->debugging )
						printf("Verification failed. No content given back\n");
				}
			}
			else 
			{
				if ( nlsr->debugging )
					printf("Name LSA / Newer Name LSA already xists in LSDB\n");
				int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri)
											, &content_data,orig_router->name);

				if ( chk_con == 0 ){
					if ( nlsr->debugging )
						printf("Content Data: %s \n",content_data);
					process_incoming_sync_content_lsa(content_data);
				}
				else{
					if ( nlsr->debugging )
						printf("Verification failed. No content given back\n");
				}
			}
		}
		else 
		{
			if ( nlsr->debugging )
				printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
		}
	}
	else
	{
		ls_type=atoi(rem);
		lst=rem;
		if(ls_type == LS_TYPE_ADJ)
		{
			ccn_name_comp_get(content_name->buf, components,components->n-2, 
														&origtime, &comp_size);
			ccn_name_chop(content_name,components,-2);
			get_name_part(orig_router,content_name,components,0);

			if ( nlsr->debugging )
				printf("Orig Router: %s Ls Type: %d Orig Time: %s\n",
											orig_router->name,ls_type,origtime);

			int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
			if ( nlsr->debugging )
				printf("LSA Life time: %d\n",lsa_life_time);

			if ( strcmp(orig_router->name,nlsr->router_name) != 0 
				&& (lsa_life_time < nlsr->router_dead_interval) )
			{
				int is_new_adj_lsa = check_is_new_adj_lsa( orig_router->name, 
													(char *)lst, (char *)origtime);
				if ( is_new_adj_lsa == 1 )
				{
					if ( nlsr->debugging )
						printf("New Adj LSA.....\n");	
					int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
												&content_data,orig_router->name);

					if ( chk_con == 0 ){
						if ( nlsr->debugging )
							printf("Content Data: %s \n",content_data);
						process_incoming_sync_content_lsa(content_data);
					}
					else{
						if ( nlsr->debugging )
							printf("Verification failed. No content given back\n");
					}		
				}
				else
				{
					if ( nlsr->debugging )
						printf("Adj LSA / Newer Adj LSA already exists in LSDB\n");
					int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
												&content_data,orig_router->name);
					if ( chk_con == 0 ){
						if ( nlsr->debugging )
							printf("Content Data: %s \n",content_data);
						process_incoming_sync_content_lsa(content_data);
					}
					else{
						if ( nlsr->debugging )
							printf("Verification failed. No content given back\n");
					}
				}
			}
			else 
			{
				if ( nlsr->debugging )
					printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
			}
		}
		else if(ls_type == LS_TYPE_COR)
		{
			ccn_name_comp_get(content_name->buf, components, components->n-2, 
														&origtime, &comp_size);
			ccn_name_chop(content_name,components,-2);
			get_name_part(orig_router,content_name,components,0);

			if ( nlsr->debugging )
				printf("Orig Router: %s Ls Type: %d Orig Time: %s\n", 
											orig_router->name,ls_type,origtime);

			int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
			if ( nlsr->debugging )
				printf("LSA Life time: %d\n",lsa_life_time);

			if ( strcmp(orig_router->name,nlsr->router_name) != 0 
				&& (lsa_life_time < nlsr->router_dead_interval) )	
			{
				int is_new_cor_lsa=check_is_new_cor_lsa( orig_router->name, 
												(char *)lst,(char *) origtime);
				if ( is_new_cor_lsa == 1 )
				{
					if ( nlsr->debugging )
						printf("New Cor LSA.....\n");	
					int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
																&content_data,
															orig_router->name);

					if ( chk_con == 0 ){
						if ( nlsr->debugging )
							printf("Content Data: %s \n",content_data);
						process_incoming_sync_content_lsa(content_data);
					}
					else{
						if ( nlsr->debugging )
							printf("Verification failed. No content given back\n");
					}		
				}
				else
				{
					if ( nlsr->debugging )
						printf("Cor LSA / Newer Cor LSA already exists in LSDB\n");
					int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
												&content_data,orig_router->name);
					if ( chk_con == 0 ){
						if ( nlsr->debugging )
							printf("Content Data: %s \n",content_data);
						process_incoming_sync_content_lsa(content_data);
					}
					else{
						if ( nlsr->debugging )
							printf("Verification failed. No content given back\n");
					}
				}
			}
			else 
			{	
				if ( nlsr->debugging )
					printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
			}

		}
	}

	if(content_data)
		free(content_data);

	if (orig_router->name)
		free(orig_router->name);
	if (orig_router)
		free(orig_router);
	ccn_charbuf_destroy(&uri);
	//01/31/2013	
	free(time_stamp);
}

/**
* This function performs same functionality as ccnsyncwatch
*/


int
sync_monitor(char *topo_prefix, char *slice_prefix)
{

	struct ccn_charbuf *prefix = ccn_charbuf_create();
	struct ccn_charbuf *topo = ccn_charbuf_create(); 
	
	nlsr->closure=(struct ccns_name_closure *) 
						calloc(1,sizeof(struct ccns_name_closure)); // leak

	nlsr->slice = ccns_slice_create();

	ccn_charbuf_reset(prefix);
	ccn_name_from_uri(prefix, slice_prefix);

	ccn_charbuf_reset(topo);
	ccn_name_from_uri(topo, topo_prefix);

	ccns_slice_set_topo_prefix(nlsr->slice, topo, prefix);
	nlsr->closure->callback = &sync_cb;
	nlsr->ccns = ccns_open(nlsr->ccn, nlsr->slice, nlsr->closure, NULL, NULL);

	ccn_charbuf_destroy(&prefix);
	ccn_charbuf_destroy(&topo);
	return 0;
}

struct ccn_charbuf *
make_template(int scope)
{
	struct ccn_charbuf *templ = NULL;
	templ = ccn_charbuf_create();
	ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
	ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
	ccn_charbuf_append_closer(templ); /* </Name> */
	if (0 <= scope && scope <= 2)
		ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
	ccn_charbuf_append_closer(templ); /* </Interest> */
	return(templ);
}

/**
* Write signed data to repo
*/


int
write_data_to_repo(char *data, char *name_prefix)
{

	nlsr_lock();
	if ( nlsr->debugging )
	{
		printf("write_data_to_repo called\n");
		printf("Content Name: %s \n",name_prefix);
		printf("Content Data: %s \n",data);
	}

	struct ccn *temp_ccn;
	temp_ccn=ccn_create();
	int ccn_fd=ccn_connect(temp_ccn, NULL);
	if(ccn_fd == -1)
	{
		fprintf(stderr,"Could not connect to ccnd for Data Writing\n");
		writeLogg(__FILE__,__FUNCTION__,__LINE__, 
						"Could not connect to ccnd for Data Writing\n");
		return -1;
	}

	struct ccn_charbuf *name = NULL;
	struct ccn_seqwriter *w = NULL;
	int blocksize = 4096;
	int freshness = -1;
	int scope = 1;
	int res;
	size_t blockread;
	struct ccn_charbuf *templ;

	name = ccn_charbuf_create();
	res = ccn_name_from_uri(name, name_prefix);
	if (res < 0) {
		fprintf(stderr, "bad CCN URI: %s\n",name_prefix);
		return -1;
	}

	w = ccn_seqw_create(temp_ccn, name);
	if (w == NULL) {
		fprintf(stderr, "ccn_seqw_create failed\n");
		return -1;
	}
	ccn_seqw_set_block_limits(w, blocksize, blocksize);
	if (freshness > -1)
		ccn_seqw_set_freshness(w, freshness);

	struct ccn_charbuf *name_v = ccn_charbuf_create();
	ccn_seqw_get_name(w, name_v);
	ccn_name_from_uri(name_v, "%C1.R.sw");
	ccn_name_append_nonce(name_v);
	templ = make_template(scope);
	res = ccn_get(temp_ccn, name_v, templ, 60000, NULL, NULL, NULL, 0);
	ccn_charbuf_destroy(&templ);
	ccn_charbuf_destroy(&name_v);
	if (res < 0) {
		fprintf(stderr, "No response from repository\n");
		return -1;
	}

	struct ccn_charbuf *resultbuf=ccn_charbuf_create();

	sign_content_with_user_defined_keystore(name,
										resultbuf,
										data,
										strlen(data),
										nlsr->keystore_path,
										nlsr->keystore_passphrase,
										nlsr->root_key_prefix,
										nlsr->site_name,
										nlsr->router_name);	


	blockread=resultbuf->length;

	if (blockread > 0) {
		res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length);	
		while (res == -1) {
			ccn_run(temp_ccn,1);
			res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length);	
		}
	}

	ccn_seqw_close(w);
	ccn_run(temp_ccn, 1);
	ccn_charbuf_destroy(&name);
	ccn_destroy(&temp_ccn);
	ccn_charbuf_destroy(&resultbuf);

	nlsr_unlock();
	return 0;
}

/**
*	Create slice for sync/repo
*/


int
create_sync_slice(char *topo_prefix, char *slice_prefix)
{
	int res;
	struct ccn *handle; 
	struct ccns_slice *slice;
	struct ccn_charbuf *prefix = ccn_charbuf_create();
	struct ccn_charbuf *topo = ccn_charbuf_create();
	struct ccn_charbuf *clause = ccn_charbuf_create();
	struct ccn_charbuf *slice_name = ccn_charbuf_create();
	struct ccn_charbuf *slice_uri = ccn_charbuf_create();

	if (prefix == NULL || topo == NULL || clause == NULL ||
			slice_name == NULL || slice_uri == NULL) {
		fprintf(stderr, "Unable to allocate required memory.\n");
		return -1;
	}

	handle = ccn_create();
	res = ccn_connect(handle, NULL);
	if (0 > res) {
		fprintf(stderr, "Unable to connect to ccnd.\n");
		return -1;
	}    

	slice = ccns_slice_create();

	ccn_charbuf_reset(topo);
	ccn_name_from_uri(topo, topo_prefix);
	ccn_charbuf_reset(prefix);
	ccn_name_from_uri(prefix,slice_prefix );
	ccns_slice_set_topo_prefix(slice, topo, prefix);


	res = ccns_write_slice(handle, slice, slice_name);

	//01/31/2013
	ccns_slice_destroy(&slice);
	ccn_destroy(&handle);
	ccn_charbuf_destroy(&prefix);
	ccn_charbuf_destroy(&topo);
	ccn_charbuf_destroy(&clause);
	ccn_charbuf_destroy(&slice_name);
	ccn_charbuf_destroy(&slice_uri);

	return 0;
}


