]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/util: add server_id_from_string()
authorStefan Metzmacher <metze@samba.org>
Fri, 17 Aug 2012 10:47:57 +0000 (12:47 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 17 Aug 2012 18:07:07 +0000 (20:07 +0200)
metze

lib/util/samba_util.h
lib/util/server_id.c

index 26a5c6872b2eba912e74cb26969fae755857bbab..e69aa7c40ce7df4abe0f9a2f8330ac5dd0d79cee 100644 (file)
@@ -901,5 +901,7 @@ const char *shlib_ext(void);
 struct server_id;
 bool server_id_equal(const struct server_id *p1, const struct server_id *p2);
 char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id);
+struct server_id server_id_from_string(uint32_t local_vnn,
+                                      const char *pid_string);
 
 #endif /* _SAMBA_UTIL_H_ */
index 7370ad93356c694d3c4da0494e40f43b195f62d6..d41fb0b2877da5bb2b7e1367c434abb7d66e9182 100644 (file)
@@ -60,3 +60,39 @@ char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id)
                                       (unsigned)id->task_id);
        }
 }
+
+struct server_id server_id_from_string(uint32_t local_vnn,
+                                      const char *pid_string)
+{
+       struct server_id result;
+       unsigned long long pid;
+       unsigned int vnn, task_id = 0;
+
+       ZERO_STRUCT(result);
+
+       /*
+        * We accept various forms with 1, 2 or 3 component forms
+        * because the server_id_str() can print different forms, and
+        * we want backwards compatibility for scripts that may call
+        * smbclient.
+        */
+       if (sscanf(pid_string, "%u:%llu.%u", &vnn, &pid, &task_id) == 3) {
+               result.vnn = vnn;
+               result.pid = pid;
+               result.task_id = task_id;
+       } else if (sscanf(pid_string, "%u:%llu", &vnn, &pid) == 2) {
+               result.vnn = vnn;
+               result.pid = pid;
+       } else if (sscanf(pid_string, "%llu.%u", &pid, &task_id) == 2) {
+               result.vnn = local_vnn;
+               result.pid = pid;
+               result.task_id = task_id;
+       } else if (sscanf(pid_string, "%llu", &pid) == 1) {
+               result.vnn = local_vnn;
+               result.pid = pid;
+       } else {
+               result.vnn = NONCLUSTER_VNN;
+               result.pid = UINT64_MAX;
+       }
+       return result;
+}