00001 #include "system.h"
00002
00003 #include <rpmio_internal.h>
00004 #include <rpmmacro.h>
00005 #include <rpmmessages.h>
00006 #include <popt.h>
00007
00008 #include "debug.h"
00009
00010 static int _debug = 0;
00011
00012
00013 #define HTTPSPATH "https://localhost/rawhide/toad/tput.txt"
00014 #define HTTPPATH "http://localhost/rawhide/toad/tput.txt"
00015 #define FTPPATH "ftp://localhost/home/test/tput.txt"
00016 #define DIRPATH "file://localhost/var/ftp/tput.txt"
00017 static char * httpspath = HTTPSPATH;
00018 static char * httppath = HTTPPATH;
00019 static char * ftppath = FTPPATH;
00020 static char * dirpath = DIRPATH;
00021
00022 static size_t readFile(const char * path)
00023 {
00024 char buf[BUFSIZ];
00025 size_t len = 0;
00026 FD_t fd;
00027 int xx;
00028
00029 buf[0] = '\0';
00030 fprintf(stderr, "===== Fread %s\n", path);
00031 fd = Fopen(path, "r.ufdio");
00032 if (fd != NULL) {
00033
00034 len = Fread(buf, 1, sizeof(buf), fd);
00035 xx = Fclose(fd);
00036 }
00037
00038 if (len > 0)
00039 fwrite(buf, 1, strlen(buf), stderr);
00040
00041 return len;
00042 }
00043
00044 static size_t writeFile(const char * path)
00045 {
00046 char buf[BUFSIZ];
00047 size_t len = 0;
00048 FD_t fd;
00049 int xx;
00050
00051 strcpy(buf, "Hello World!\n");
00052 fprintf(stderr, "===== Fwrite %s\n", path);
00053 fd = Fopen(path, "w.ufdio");
00054 if (fd != NULL) {
00055 len = Fwrite(buf, 1, strlen(buf), fd);
00056 xx = Fclose(fd);
00057 if (xx)
00058 fprintf(stderr, "===> Fclose rc %d\n", xx);
00059 }
00060
00061 if (len > 0)
00062 fwrite(buf, 1, strlen(buf), stderr);
00063
00064 return len;
00065 }
00066
00067 static int unlinkFile(const char * path)
00068 {
00069 fprintf(stderr, "===== Unlink %s\n", path);
00070 return Unlink(path);
00071 }
00072
00073 static void doFile(const char * path)
00074 {
00075 int xx;
00076
00077 fprintf(stderr, "===== %s\n", path);
00078 #if 0
00079 xx = unlink("/home/toad/tput.txt");
00080 xx = unlink("/var/ftp/tput.txt");
00081 xx = unlink("/var/www/html/tput.txt");
00082 #endif
00083
00084 #if 0
00085 xx = unlinkFile(path);
00086 #endif
00087 xx = writeFile(path);
00088 #if 0
00089 xx = readFile(path);
00090 xx = Unlink(path);
00091
00092 xx = unlink("/home/toad/tput.txt");
00093 xx = unlink("/var/ftp/tput.txt");
00094 xx = unlink("/var/www/html/tput.txt");
00095 #endif
00096 }
00097
00098 static struct poptOption optionsTable[] = {
00099 { "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL },
00100 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00101 N_("debug protocol data stream"), NULL},
00102 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00103 N_("debug rpmio I/O"), NULL},
00104 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00105 N_("debug URL cache handling"), NULL},
00106 { "verbose", 'v', 0, 0, 'v', NULL, NULL },
00107 POPT_AUTOHELP
00108 POPT_TABLEEND
00109 };
00110
00111 int
00112 main(int argc, const char *argv[])
00113 {
00114 poptContext optCon = poptGetContext(argv[0], argc, argv, optionsTable, 0);
00115 int rc;
00116
00117 while ((rc = poptGetNextOpt(optCon)) > 0) {
00118 switch (rc) {
00119 case 'v':
00120 rpmIncreaseVerbosity();
00121 break;
00122 default:
00123 break;
00124 }
00125 }
00126
00127 if (_debug) {
00128 rpmIncreaseVerbosity();
00129 rpmIncreaseVerbosity();
00130 }
00131
00132 _av_debug = -1;
00133 _ftp_debug = -1;
00134 _dav_debug = -1;
00135 #if 0
00136 doFile(dirpath);
00137 doFile(ftppath);
00138 #endif
00139 doFile(httppath);
00140 #if 0
00141 doFile(httpspath);
00142 #endif
00143
00144 urlFreeCache();
00145
00146 return 0;
00147 }