Browse code

add support for UNLINK command

git-svn: trunk@2342

Tomasz Kojm authored on 2006/10/08 00:15:06
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sat Oct  7 17:13:40 CEST 2006 (tk)
2
+----------------------------------
3
+  * shared/cdiff.c: add support for UNLINK command
4
+
1 5
 Sat Oct  7 12:47:32 CEST 2006 (tk)
2 6
 ----------------------------------
3 7
   * libclamav: make the experimental anti-phishing code more thread safe,
... ...
@@ -63,6 +63,7 @@ static int cdiff_cmd_del(const char *cmdstr, struct cdiff_ctx *ctx);
63 63
 static int cdiff_cmd_xchg(const char *cmdstr, struct cdiff_ctx *ctx);
64 64
 static int cdiff_cmd_close(const char *cmdstr, struct cdiff_ctx *ctx);
65 65
 static int cdiff_cmd_move(const char *cmdstr, struct cdiff_ctx *ctx);
66
+static int cdiff_cmd_unlink(const char *cmdstr, struct cdiff_ctx *ctx);
66 67
 
67 68
 static struct cdiff_cmd commands[] = {
68 69
     /* OPEN db_name */
... ...
@@ -83,6 +84,9 @@ static struct cdiff_cmd commands[] = {
83 83
     /* MOVE src_db dst_db start_line first_16b end_line first_16b */
84 84
     { "MOVE", 6, &cdiff_cmd_move },
85 85
 
86
+    /* UNLINK db_name */
87
+    { "UNLINK", 1, &cdiff_cmd_unlink },
88
+
86 89
     { NULL, 0, NULL }
87 90
 };
88 91
 
... ...
@@ -671,6 +675,40 @@ static int cdiff_cmd_move(const char *cmdstr, struct cdiff_ctx *ctx)
671 671
     return 0;
672 672
 }
673 673
 
674
+static int cdiff_cmd_unlink(const char *cmdstr, struct cdiff_ctx *ctx)
675
+{
676
+	char *db;
677
+	unsigned int i;
678
+
679
+
680
+    if(ctx->open_db) {
681
+	logg("!cdiff_cmd_unlink: Database %s is still open\n", ctx->open_db);
682
+	return -1;
683
+    }
684
+
685
+    if(!(db = cdiff_token(cmdstr, 1, 1))) {
686
+	logg("!cdiff_cmd_unlink: Can't get first argument\n");
687
+	return -1;
688
+    }
689
+
690
+    for(i = 0; i < strlen(db); i++) {
691
+	if((db[i] != '.' && !isalnum(db[i])) || strchr("/\\", db[i])) {
692
+	    logg("!cdiff_cmd_unlink: Forbidden characters found in database name\n");
693
+	    free(db);
694
+	    return -1;
695
+	}
696
+    }
697
+
698
+    if(unlink(db) == -1) {
699
+	logg("!cdiff_cmd_unlink: Can't unlink %s\n", db);
700
+	free(db);
701
+	return -1;
702
+    }
703
+
704
+    free(db);
705
+    return 0;
706
+}
707
+
674 708
 int cdiff_apply(int fd)
675 709
 {
676 710
 	struct cdiff_ctx ctx;