#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
#include <assert.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif


#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 "nlsr.h"
#include "nlsr_npl.h"
#include "utility.h"



void 
add_name_to_npl(struct name_prefix *np)
{
	struct name_prefix_list_entry *npe;
	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee; 	
    	int res;

   	hashtb_start(nlsr->npl, e);
    	res = hashtb_seek(e, np->name, np->length, 0);

	if(res == HT_NEW_ENTRY)
	{   
		npe=e->data;
		npe->np=(struct name_prefix *)calloc(1,sizeof(struct name_prefix ));
		npe->np->length=np->length;
		npe->np->name=(char *)calloc(np->length,sizeof(char));
		memcpy(npe->np->name,np->name,np->length);
		npe->name_lsa_id=0;
	}
    	
	hashtb_end(e);

}

int  
does_name_exist_in_npl(struct name_prefix *np)
{
	int ret=0;
	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee; 	
    	int res;

   	hashtb_start(nlsr->npl, e);
    	res = hashtb_seek(e, np->name, np->length, 0);

	if(res == HT_NEW_ENTRY)
	{   
		hashtb_delete(e);
		ret=0;
	}
	else
	{
		ret=1;
    	}
	hashtb_end(e);

	return ret;

}


long int  
get_lsa_id_from_npl(struct name_prefix *np)
{
	int ret=0;

	struct name_prefix_list_entry *npe;

	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee; 	
    	int res;

   	hashtb_start(nlsr->npl, e);
    	res = hashtb_seek(e, np->name, np->length, 0);

	if(res == HT_NEW_ENTRY)
	{   
		hashtb_delete(e);
		ret=0;
	}
	else
	{
		npe=e->data;
		ret=npe->name_lsa_id;
    	}
	hashtb_end(e);

	return ret;

}

void
print_name_prefix_from_npl(void)
{
	if ( nlsr->debugging )
		printf("print_name_prefix_from_npl called \n");	
	if ( nlsr->detailed_logging )
		writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_name_prefix_from_npl called\n");
	int i, npl_element;
	//struct name_prefix *np;
	struct name_prefix_list_entry *npe;

	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee;
    	
    	hashtb_start(nlsr->npl, e);
	npl_element=hashtb_n(nlsr->npl);

	for(i=0;i<npl_element;i++)
	{
		npe=e->data;
		if ( nlsr->debugging )
			printf("Name Prefix: %s and Length: %d and LSA Id: %ld\n",npe->np->name,npe->np->length,npe->name_lsa_id);
		if ( nlsr->detailed_logging )
			writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name Prefix: %s and Length: %d \n",npe->np->name,npe->np->length);	
		hashtb_next(e);		
	}

	hashtb_end(e);

	if ( nlsr->debugging )
		printf("\n");
	if ( nlsr->detailed_logging )
		writeLogg(__FILE__,__FUNCTION__,__LINE__,"\n");
}

void 
update_nlsa_id_for_name_in_npl(struct name_prefix *np, long int nlsa_id)
{
	struct name_prefix_list_entry *npe;
	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee; 	
    	int res;

   	hashtb_start(nlsr->npl, e);
    	res = hashtb_seek(e, np->name, np->length, 0);

	if(res == HT_OLD_ENTRY)
	{   
		npe=e->data;
		npe->name_lsa_id=nlsa_id;
	}
	else
	{
		hashtb_delete(e);	
	}
    	
	hashtb_end(e);
}

void
destroy_npl_entry_component(struct name_prefix_list_entry *npe)
{
	if (npe->np->name)
		free(npe->np->name);
	if(npe->np)
		free(npe->np);
}

void
destroy_npl(void)
{
	int i, npl_element;
	struct name_prefix_list_entry *npe;

	struct hashtb_enumerator ee;
    	struct hashtb_enumerator *e = &ee;
    	
    	hashtb_start(nlsr->npl, e);
	npl_element=hashtb_n(nlsr->npl);

	for(i=0;i<npl_element;i++)
	{
		npe=e->data;
		destroy_npl_entry_component(npe);
		hashtb_next(e);		
	}

	hashtb_end(e);

	if ( nlsr->npl)
		hashtb_destroy(&nlsr->npl);
}
