Преглед изворни кода

usrloc(k)API function get_udomain()

- get usrloc domain only if it exists, don't create a new one
Daniel-Constantin Mierla пре 15 година
родитељ
комит
c7e65c0f19
4 измењених фајлова са 34 додато и 0 уклоњено
  1. 23 0
      modules_k/usrloc/dlist.c
  2. 9 0
      modules_k/usrloc/dlist.h
  3. 1 0
      modules_k/usrloc/usrloc.c
  4. 1 0
      modules_k/usrloc/usrloc.h

+ 23 - 0
modules_k/usrloc/dlist.c

@@ -447,6 +447,29 @@ static inline int new_dlist(str* _n, dlist_t** _d)
 	return 0;
 }
 
+/*!
+ * \brief Registers a new domain with usrloc
+ *
+ * Find and return a usrloc domain (location table)
+ * \param _n domain name
+ * \param _d usrloc domain
+ * \return 0 on success, -1 on failure
+ */
+int get_udomain(const char* _n, udomain_t** _d)
+{
+	dlist_t* d;
+	str s;
+
+	s.s = (char*)_n;
+	s.len = strlen(_n);
+
+	if (find_dlist(&s, &d) == 0) {
+		*_d = d->d;
+		return 0;
+	}
+	*_d = NULL;
+	return -1;
+}
 
 /*!
  * \brief Registers a new domain with usrloc

+ 9 - 0
modules_k/usrloc/dlist.h

@@ -66,6 +66,15 @@ extern dlist_t* root;
 typedef int (*register_udomain_t)(const char* _n, udomain_t** _d);
 int register_udomain(const char* _n, udomain_t** _d);
 
+/*!
+ * \brief Find and return usrloc domain
+ *
+ * \param _n domain name
+ * \param _d usrloc domain (location table)
+ * \return 0 on success, -1 on failure
+ */
+typedef int (*get_udomain_t)(const char* _n, udomain_t** _d);
+int get_udomain(const char* _n, udomain_t** _d);
 
 /*!
  * \brief Free all allocated memory for domains

+ 1 - 0
modules_k/usrloc/usrloc.c

@@ -61,6 +61,7 @@ int bind_usrloc(usrloc_api_t* api)
 	}
 
 	api->register_udomain   = register_udomain;
+	api->get_udomain        = get_udomain;
 	api->get_all_ucontacts  = get_all_ucontacts;
 	api->insert_urecord     = insert_urecord;
 	api->delete_urecord     = delete_urecord;

+ 1 - 0
modules_k/usrloc/usrloc.h

@@ -43,6 +43,7 @@ typedef struct usrloc_api {
 	unsigned int  nat_flag;   /*! nat_flag module parameter */
 
 	register_udomain_t   register_udomain;
+	get_udomain_t        get_udomain;
 	get_all_ucontacts_t  get_all_ucontacts;
 
 	insert_urecord_t     insert_urecord;