mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
lib/util: split out server_id_from_string_ex allow the unique delimiter to be passed in
In future it also allows to specifiy another delemiter than '/' in order to use the resulting buffer as part of a file/directory name. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15693 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
parent
8695231403
commit
20431cc622
@ -115,11 +115,19 @@ size_t server_id_str_buf_unique(struct server_id id, char *buf, size_t buflen)
|
||||
|
||||
struct server_id server_id_from_string(uint32_t local_vnn,
|
||||
const char *pid_string)
|
||||
{
|
||||
return server_id_from_string_ex(local_vnn, '/', pid_string);
|
||||
}
|
||||
|
||||
struct server_id server_id_from_string_ex(uint32_t local_vnn,
|
||||
char unique_delimiter,
|
||||
const char *pid_string)
|
||||
{
|
||||
struct server_id templ = {
|
||||
.vnn = NONCLUSTER_VNN, .pid = UINT64_MAX
|
||||
};
|
||||
struct server_id result;
|
||||
char unique_delimiter_found = '\0';
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@ -130,10 +138,10 @@ struct server_id server_id_from_string(uint32_t local_vnn,
|
||||
*/
|
||||
|
||||
result = templ;
|
||||
ret = sscanf(pid_string, "%"SCNu32":%"SCNu64".%"SCNu32"/%"SCNu64,
|
||||
ret = sscanf(pid_string, "%"SCNu32":%"SCNu64".%"SCNu32"%c%"SCNu64,
|
||||
&result.vnn, &result.pid, &result.task_id,
|
||||
&result.unique_id);
|
||||
if (ret == 4) {
|
||||
&unique_delimiter_found, &result.unique_id);
|
||||
if (ret == 5 && unique_delimiter_found == unique_delimiter) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -145,9 +153,10 @@ struct server_id server_id_from_string(uint32_t local_vnn,
|
||||
}
|
||||
|
||||
result = templ;
|
||||
ret = sscanf(pid_string, "%"SCNu32":%"SCNu64"/%"SCNu64,
|
||||
&result.vnn, &result.pid, &result.unique_id);
|
||||
if (ret == 3) {
|
||||
ret = sscanf(pid_string, "%"SCNu32":%"SCNu64"%c%"SCNu64,
|
||||
&result.vnn, &result.pid,
|
||||
&unique_delimiter_found, &result.unique_id);
|
||||
if (ret == 4 && unique_delimiter_found == unique_delimiter) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -159,9 +168,10 @@ struct server_id server_id_from_string(uint32_t local_vnn,
|
||||
}
|
||||
|
||||
result = templ;
|
||||
ret = sscanf(pid_string, "%"SCNu64".%"SCNu32"/%"SCNu64,
|
||||
&result.pid, &result.task_id, &result.unique_id);
|
||||
if (ret == 3) {
|
||||
ret = sscanf(pid_string, "%"SCNu64".%"SCNu32"%c%"SCNu64,
|
||||
&result.pid, &result.task_id,
|
||||
&unique_delimiter_found, &result.unique_id);
|
||||
if (ret == 4 && unique_delimiter_found == unique_delimiter) {
|
||||
result.vnn = local_vnn;
|
||||
return result;
|
||||
}
|
||||
@ -175,9 +185,9 @@ struct server_id server_id_from_string(uint32_t local_vnn,
|
||||
}
|
||||
|
||||
result = templ;
|
||||
ret = sscanf(pid_string, "%"SCNu64"/%"SCNu64,
|
||||
&result.pid, &result.unique_id);
|
||||
if (ret == 2) {
|
||||
ret = sscanf(pid_string, "%"SCNu64"%c%"SCNu64,
|
||||
&result.pid, &unique_delimiter_found, &result.unique_id);
|
||||
if (ret == 3 && unique_delimiter_found == unique_delimiter) {
|
||||
result.vnn = local_vnn;
|
||||
return result;
|
||||
}
|
||||
|
@ -56,6 +56,9 @@ size_t server_id_str_buf_unique(struct server_id id, char *buf, size_t buflen);
|
||||
|
||||
struct server_id server_id_from_string(uint32_t local_vnn,
|
||||
const char *pid_string);
|
||||
struct server_id server_id_from_string_ex(uint32_t local_vnn,
|
||||
char unique_delimiter,
|
||||
const char *pid_string);
|
||||
|
||||
/**
|
||||
* Set the serverid to the special value that represents a disconnected
|
||||
|
Loading…
Reference in New Issue
Block a user