[ekg2-commit] ekg2: drafts.c (HEAD) jogger.c (HEAD) [peres]
CVS commit
cvs w toxygen.net
Nie, 6 Maj 2007, 12:09:35 CEST
Module name: ekg2
Changes by: peres 2007-05-06 12:09:33
Modified files:
drafts.c jogger.c
Log message:
Entry file hashing.
Index: drafts.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/jogger/drafts.c,v
diff -d -u -r1.5 -r1.6
--- drafts.c 6 May 2007 09:31:26 -0000 1.5
+++ drafts.c 6 May 2007 10:09:33 -0000 1.6
@@ -101,12 +101,14 @@
* @param fn - filename to open.
* @param fd - pointer to store fd.
* @param fs - pointer to store filesize.
+ * @param hash - pointer to store filehash or NULL, if not needed.
*
* @return Pointer to file contents or NULL on failure.
*
* @sa jogger_closefile - close such opened file.
*/
-static char *jogger_openfile(const char *fn, int *fd, int *fs) {
+static char *jogger_openfile(const char *fn, int *fd, int *fs, char **hash) {
+ static char jogger_hash[sizeof(int)*2+3];
char *out;
if ((*fd = open(fn, O_RDONLY|O_NONBLOCK)) == -1) { /* we use O_NONBLOCK to get rid of FIFO problems */
@@ -138,6 +140,17 @@
return NULL;
}
+ /* I don't want to write my own hashing function, so using EKG2 one
+ * it will fail to hash data after any \0 in file, if there're any
+ * but we also aren't prepared to handle them */
+ if (hash) {
+ char sizecont[8];
+
+ snprintf(sizecont, 8, "0x%%0%dx", sizeof(int)*2);
+ snprintf(jogger_hash, sizeof(int)*2+3, sizecont, ekg_hash(out));
+ *hash = jogger_hash;
+ }
+
return out;
}
@@ -159,10 +172,10 @@
COMMAND(jogger_prepare) {
int fd, fs;
- char *entry, *s;
+ char *entry, *s, *hash;
int seen = 0;
- if (!(entry = jogger_openfile(params[0], &fd, &fs)))
+ if (!(entry = jogger_openfile(params[0], &fd, &fs, &hash)))
return -1;
s = entry;
@@ -266,22 +279,30 @@
jogger_closefile(fd, entry, fs);
session_set(session, "entry_file", params[0]);
+ session_set(session, "entry_hash", hash);
printq("jogger_prepared", params[0]);
return 0;
}
COMMAND(jogger_publish) {
const char *fn = (params[0] ? params[0] : session_get(session, "entry_file"));
+ const char *oldhash = (!xstrcmp(session_get(session, "entry_file"), fn) ? session_get(session, "entry_hash") : NULL);
int fd, fs;
- char *entry;
+ char *entry, *hash;
if (!fn) {
printq("jogger_notprepared");
return -1;
}
- if (!(entry = jogger_openfile(fn, &fd, &fs)))
+ if (!(entry = jogger_openfile(fn, &fd, &fs, (oldhash ? &hash : NULL))))
return -1;
+ if (oldhash && xstrcmp(oldhash, hash)) {
+ print("jogger_hashdiffers");
+ jogger_closefile(fd, entry, fs);
+ session_set(session, "entry_hash", hash);
+ return -1;
+ }
command_exec("jogger:", session, entry, 0);
Index: jogger.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/jogger/jogger.c,v
diff -d -u -r1.17 -r1.18
--- jogger.c 6 May 2007 09:31:26 -0000 1.17
+++ jogger.c 6 May 2007 10:09:33 -0000 1.18
@@ -233,6 +233,8 @@
format_add("jogger_nonfile", _("%! Given path doesn't appear to be regular file!"), 1);
format_add("jogger_cantread", _("%! Unable to read entry file!"), 1);
format_add("jogger_emptyfile", _("%! File is empty!"), 1);
+ format_add("jogger_hashdiffers", _("%! %|File contents (checksum) differs from the time it was prepared. If you changed anything in the entry file, please run %Tprepare%n again. If you want to force submission, please use %Tpublish%n again."), 1);
+
format_add("jogger_warning", _("%> During QA check of the entry, following warnings have been issued:"), 1);
format_add("jogger_warning_brokenheader", _("%> %|* Header with broken syntax found at: %c%1%n"), 1);
format_add("jogger_warning_wrong_key", _("%> %|* Header contains unknown/wrong key at: %c%1%n"), 1);
@@ -251,6 +253,7 @@
static plugins_params_t jogger_plugin_vars[] = {
PLUGIN_VAR_ADD("entry_file", 0, VAR_STR, NULL, 0, NULL),
+ PLUGIN_VAR_ADD("entry_hash", 0, VAR_STR, NULL, 0, NULL),
PLUGIN_VAR_ADD("log_formats", SESSION_VAR_LOG_FORMATS, VAR_STR, "simple", 0, NULL),
PLUGIN_VAR_ADD("newentry_open_query", 0, VAR_BOOL, "0", 0, NULL),
PLUGIN_VAR_ADD("own_commentformat", 0, VAR_STR, NULL, 0, NULL),
Więcej informacji o liście dyskusyjnej ekg2-commit