NLSR Api server finished
diff --git a/nlsr_npl.c b/nlsr_npl.c
index c384133..a2e2271 100644
--- a/nlsr_npl.c
+++ b/nlsr_npl.c
@@ -25,7 +25,8 @@
void
add_name_to_npl(struct name_prefix *np)
{
- struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
+ struct name_prefix_list_entry *npe=(struct name_prefix_list_entry *)malloc(sizeof(struct name_prefix_list_entry));
+ //struct name_prefix *hnp=(struct name_prefix *)malloc(sizeof(struct name_prefix )); //free
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -36,17 +37,81 @@
if(res == HT_NEW_ENTRY)
{
-
- hnp = e->data;
- hnp->length=np->length;
- hnp->name=(char *)malloc(np->length); //free
- memcpy(hnp->name,np->name,np->length);
+ npe=e->data;
+ npe->np=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
+ npe->np->length=np->length;
+ npe->np->name=(char *)malloc(np->length);
+ memcpy(npe->np->name,np->name,np->length);
+ npe->name_lsa_id=0;
+ //hnp = e->data;
+ //hnp->length=np->length;
+ //hnp->name=(char *)malloc(np->length); //free
+ //memcpy(hnp->name,np->name,np->length);
}
hashtb_end(e);
}
+int
+does_name_exist_in_npl(struct name_prefix *np)
+{
+ int ret=0;
+
+ //struct name_prefix_entry *npe;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ 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 = ⅇ
+ 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)
@@ -56,7 +121,8 @@
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 *np;
+ struct name_prefix_list_entry *npe;
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -66,16 +132,43 @@
for(i=0;i<npl_element;i++)
{
- np=e->data;
+ npe=e->data;
if ( nlsr->debugging )
- printf("Name Prefix: %s and Length: %d \n",np->name,np->length);
+ 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",np->name,np->length);
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"Name Prefix: %s and Length: %d \n",npe->np->name,npe->np->length);
hashtb_next(e);
}
hashtb_end(e);
- printf("\n");
+ 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 = ⅇ
+ 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);
}