git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
daemon: Split out checksum type to program name mapping into function.
[libguestfs.git]
/
daemon
/
checksum.c
diff --git
a/daemon/checksum.c
b/daemon/checksum.c
index
13719fd
..
4ee6231
100644
(file)
--- a/
daemon/checksum.c
+++ b/
daemon/checksum.c
@@
-27,32
+27,40
@@
#include "daemon.h"
#include "actions.h"
#include "daemon.h"
#include "actions.h"
-static char *
-
checksum (const char *csumtype, const char *path
)
+static c
onst c
har *
+
program_of_csum (const char *csumtype
)
{
{
- const char *program;
- char *out, *err;
- int r;
- int len;
-
if (STRCASEEQ (csumtype, "crc"))
if (STRCASEEQ (csumtype, "crc"))
-
program =
"cksum";
+
return
"cksum";
else if (STRCASEEQ (csumtype, "md5"))
else if (STRCASEEQ (csumtype, "md5"))
-
program =
"md5sum";
+
return
"md5sum";
else if (STRCASEEQ (csumtype, "sha1"))
else if (STRCASEEQ (csumtype, "sha1"))
-
program =
"sha1sum";
+
return
"sha1sum";
else if (STRCASEEQ (csumtype, "sha224"))
else if (STRCASEEQ (csumtype, "sha224"))
-
program =
"sha224sum";
+
return
"sha224sum";
else if (STRCASEEQ (csumtype, "sha256"))
else if (STRCASEEQ (csumtype, "sha256"))
-
program =
"sha256sum";
+
return
"sha256sum";
else if (STRCASEEQ (csumtype, "sha384"))
else if (STRCASEEQ (csumtype, "sha384"))
-
program =
"sha384sum";
+
return
"sha384sum";
else if (STRCASEEQ (csumtype, "sha512"))
else if (STRCASEEQ (csumtype, "sha512"))
-
program =
"sha512sum";
+
return
"sha512sum";
else {
reply_with_error ("unknown checksum type, expecting crc|md5|sha1|sha224|sha256|sha384|sha512");
return NULL;
}
else {
reply_with_error ("unknown checksum type, expecting crc|md5|sha1|sha224|sha256|sha384|sha512");
return NULL;
}
+}
+
+static char *
+checksum (const char *csumtype, const char *path)
+{
+ const char *program;
+ char *out, *err;
+ int r;
+ int len;
+
+ program = program_of_csum (csumtype);
+ if (program == NULL)
+ return NULL;
r = command (&out, &err, program, path, NULL);
if (r == -1) {
r = command (&out, &err, program, path, NULL);
if (r == -1) {