svn commit: samba r10344 - in branches/tmp/samba4-winsrepl/source:
include nbt_server/wins
metze at samba.org
metze at samba.org
Tue Sep 20 09:35:55 GMT 2005
Author: metze
Date: 2005-09-20 09:35:54 +0000 (Tue, 20 Sep 2005)
New Revision: 10344
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=10344
Log:
create winsdb_record() and winsdb_message() as public functions
so that they can be used in the wrepl_server/
metze
Modified:
branches/tmp/samba4-winsrepl/source/include/structs.h
branches/tmp/samba4-winsrepl/source/nbt_server/wins/winsdb.c
Changeset:
Modified: branches/tmp/samba4-winsrepl/source/include/structs.h
===================================================================
--- branches/tmp/samba4-winsrepl/source/include/structs.h 2005-09-20 09:03:20 UTC (rev 10343)
+++ branches/tmp/samba4-winsrepl/source/include/structs.h 2005-09-20 09:35:54 UTC (rev 10344)
@@ -265,6 +265,8 @@
struct wreplsrv_in_connection;
struct wreplsrv_in_call;
+struct winsdb_record;
+
struct wrepl_packet;
struct wrepl_associate;
struct wrepl_pull_table;
Modified: branches/tmp/samba4-winsrepl/source/nbt_server/wins/winsdb.c
===================================================================
--- branches/tmp/samba4-winsrepl/source/nbt_server/wins/winsdb.c 2005-09-20 09:03:20 UTC (rev 10343)
+++ branches/tmp/samba4-winsrepl/source/nbt_server/wins/winsdb.c 2005-09-20 09:35:54 UTC (rev 10344)
@@ -298,9 +298,7 @@
struct ldb_message **res = NULL;
int ret;
struct winsdb_record *rec;
- struct ldb_message_element *el;
TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
- int i;
/* find the record in the WINS database */
ret = ldb_search(winssrv->wins_db, winsdb_dn(tmp_ctx, name), LDB_SCOPE_BASE,
@@ -310,23 +308,50 @@
}
if (ret != 1) goto failed;
- rec = talloc(tmp_ctx, struct winsdb_record);
+ rec = winsdb_record(res[0], tmp_ctx);
if (rec == NULL) goto failed;
+ rec->name = name;
+ /* see if it has already expired */
+ if (rec->state == WINS_REC_ACTIVE &&
+ rec->expire_time <= time(NULL)) {
+ DEBUG(5,("WINS: expiring name %s (expired at %s)\n",
+ nbt_name_string(tmp_ctx, rec->name), timestring(tmp_ctx, rec->expire_time)));
+ rec->state = WINS_REC_RELEASED;
+ }
+
+ talloc_steal(mem_ctx, rec);
+ talloc_free(tmp_ctx);
+ return rec;
+
+failed:
+ talloc_free(tmp_ctx);
+ return NULL;
+}
+
+struct winsdb_record *winsdb_record(struct ldb_message *msg, TALLOC_CTX *mem_ctx)
+{
+ struct winsdb_record *rec;
+ struct ldb_message_element *el;
+ uint32_t i;
+
+ rec = talloc(mem_ctx, struct winsdb_record);
+ if (rec == NULL) goto failed;
+
/* parse it into a more convenient winsdb_record structure */
- rec->name = name;
- rec->state = ldb_msg_find_int(res[0], "active", WINS_REC_RELEASED);
- rec->nb_flags = ldb_msg_find_int(res[0], "nbFlags", 0);
- rec->wins_owner = ldb_msg_find_string(res[0], "winsOwner", NULL);
- rec->expire_time = ldap_string_to_time(ldb_msg_find_string(res[0], "expires", NULL));
- rec->registered_by = ldb_msg_find_string(res[0], "registeredBy", NULL);
- rec->version = ldb_msg_find_uint64(res[0], "version", 0);
+ rec->name = NULL;
+ rec->state = ldb_msg_find_int(msg, "active", WINS_REC_RELEASED);
+ rec->nb_flags = ldb_msg_find_int(msg, "nbFlags", 0);
+ rec->wins_owner = ldb_msg_find_string(msg, "winsOwner", NULL);
+ rec->expire_time = ldap_string_to_time(ldb_msg_find_string(msg, "expires", NULL));
+ rec->registered_by = ldb_msg_find_string(msg, "registeredBy", NULL);
+ rec->version = ldb_msg_find_uint64(msg, "version", 0);
talloc_steal(rec, rec->wins_owner);
talloc_steal(rec, rec->registered_by);
if (!rec->wins_owner) rec->wins_owner = WINSDB_OWNER_LOCAL;
- el = ldb_msg_find_element(res[0], "address");
+ el = ldb_msg_find_element(msg, "address");
if (el == NULL) goto failed;
rec->addresses = talloc_array(rec, struct winsdb_addr *, el->num_values+1);
@@ -338,32 +363,19 @@
}
rec->addresses[i] = NULL;
- /* see if it has already expired */
- if (rec->state == WINS_REC_ACTIVE &&
- rec->expire_time <= time(NULL)) {
- DEBUG(5,("WINS: expiring name %s (expired at %s)\n",
- nbt_name_string(tmp_ctx, rec->name), timestring(tmp_ctx, rec->expire_time)));
- rec->state = WINS_REC_RELEASED;
- }
-
- talloc_steal(mem_ctx, rec);
- talloc_free(tmp_ctx);
return rec;
-
failed:
- talloc_free(tmp_ctx);
+ talloc_free(rec);
return NULL;
}
-
/*
form a ldb_message from a winsdb_record
*/
-static struct ldb_message *winsdb_message(struct wins_server *winssrv,
- struct winsdb_record *rec, TALLOC_CTX *mem_ctx)
+struct ldb_message *winsdb_message(struct ldb_context *ldb,
+ struct winsdb_record *rec, TALLOC_CTX *mem_ctx)
{
int i, ret=0;
- struct ldb_context *ldb = winssrv->wins_db;
struct ldb_message *msg = ldb_msg_new(mem_ctx);
if (msg == NULL) goto failed;
@@ -401,7 +413,7 @@
rec->version = winsdb_allocate_version(winssrv);
if (rec->version == 0) goto failed;
- msg = winsdb_message(winssrv, rec, tmp_ctx);
+ msg = winsdb_message(winssrv->wins_db, rec, tmp_ctx);
if (msg == NULL) goto failed;
ret = ldb_add(ldb, msg);
if (ret != 0) goto failed;
@@ -430,7 +442,7 @@
if (rec->version == 0) goto failed;
rec->wins_owner = WINSDB_OWNER_LOCAL;
- msg = winsdb_message(winssrv, rec, tmp_ctx);
+ msg = winsdb_message(winssrv->wins_db, rec, tmp_ctx);
if (msg == NULL) goto failed;
for (i=0;i<msg->num_elements;i++) {
More information about the samba-cvs
mailing list