From: Todd L. <jt...@us...> - 2002-06-22 00:19:30
|
Update of /cvsroot/replaypc/replaypc In directory usw-pr-cvs1:/tmp/cvs-serv20080 Modified Files: httpfsclient.h httpfsclient.c Makefile Added Files: timecheck.c Log Message: add timecheck program make httpfs error messages disable-able -- need a real logging facility --- NEW FILE: timecheck.c --- #include <stdio.h> #include "httpfsclient.h" #ifdef WIN32 #include "gnu_getopt\getopt.h" #endif #ifdef __unix__ #include <unistd.h> #endif #define NUM_CHECKS 60 static void usage(const char * err) { if (err) fprintf(stderr, "*** ERROR: %s\n\n", err); fprintf(stderr, "Usage: timecheck [-a address] [-o offset]\n" "\n" "Address defaults to $RTV4K_ADDRESS\n" "Starting offset defaults to $TIMEOFF if set, otherwise 0\n" "\n"); exit(err ? 1 : 0); } static int check_connectivity(char * address, int encrypt) { char * result; if (encrypt) { replaytv_version.major = 4; replaytv_version.minor = 3; replaytv_version.patch = 0; replaytv_version.build = 230; } else { replaytv_version.major = 4; replaytv_version.minor = 1; replaytv_version.patch = 1; replaytv_version.build = 190; } if (hfs_do_simple(&result, address, "ls", "name", encrypt ? "/Video" : "/", NULL) != 0) return -1; free(result); return 0; } static int check_offset(char * address, int offset) { char envbuf[64]; sprintf(envbuf, "TIMEOFF=%d", offset); putenv(envbuf); return check_connectivity(address, 1); } static int find_in_range(char * address, int start_offset, int * p_offset) { int i; int offset; offset = start_offset; for (i = 0; i < NUM_CHECKS; i++) { offset = start_offset + i*60; if (check_offset(address, offset) == 0) break; offset = start_offset - i*60; if (check_offset(address, offset) == 0) break; } if (i == NUM_CHECKS) return -1; *p_offset = offset; return 0; } static int find_range_top(char * address, int start_offset, int * p_offset) { int i; int offset; offset = start_offset; for (i = 64; i > 0; i /= 2) if (check_offset(address, offset + i) == 0) offset += i; *p_offset = offset; return 0; } int main(int argc, char ** argv) { char * address; char * timeoff; int offset; int ch; address = getenv("RTV4K_ADDRESS"); timeoff = getenv("TIMEOFF"); while ((ch = getopt(argc, argv, "a:o:")) != EOF) { switch(ch) { case 'a': address = optarg; break; case 'o': timeoff = optarg; break; default: usage("Invalid argument"); } } if (optind != argc) usage("Unneeded argument"); if (address == NULL) usage("Need replay's address"); if (timeoff == NULL) offset = 0; else offset = atoi(timeoff); if (check_connectivity(address, 0)) { fprintf(stderr, "Error communicating with %s unrelated to time.\n", address); return -1; } hfs_output_errors = 0; if (find_in_range(address, offset, &offset)) { fprintf(stderr, "Couldn't find a working offset.\n"); return -2; } if (find_range_top(address, offset, &offset)) { fprintf(stderr, "Couldn't find the top of the range(?!)\n"); return -3; } printf("TIMEOFF=%d\n", offset-40); return 0; } Index: httpfsclient.h =================================================================== RCS file: /cvsroot/replaypc/replaypc/httpfsclient.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** httpfsclient.h 30 Mar 2002 00:26:30 -0000 1.5 --- httpfsclient.h 22 Jun 2002 00:19:27 -0000 1.6 *************** *** 53,56 **** --- 53,58 ---- #define URLSIZE 512 + extern int hfs_output_errors; + extern unsigned long hfs_do_simple(char ** presult, const char * address, const char * command, Index: httpfsclient.c =================================================================== RCS file: /cvsroot/replaypc/replaypc/httpfsclient.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** httpfsclient.c 16 Jun 2002 07:51:42 -0000 1.10 --- httpfsclient.c 22 Jun 2002 00:19:27 -0000 1.11 *************** *** 23,26 **** --- 23,28 ---- #include <string.h> + int hfs_output_errors = 1; + #define ARGBUFSIZE 2048 static int make_httpfs_url(char * dst, size_t size, *************** *** 37,41 **** l = strlen(address) + strlen(command) + strlen("http:///httpfs-?"); if (l >= size) { ! fprintf(stderr, "Error: make_httpfs_url: address + command too long for buffer\n"); return -1; } --- 39,44 ---- l = strlen(address) + strlen(command) + strlen("http:///httpfs-?"); if (l >= size) { ! if (hfs_output_errors) ! fprintf(stderr, "Error: make_httpfs_url: address + command too long for buffer\n"); return -1; } *************** *** 55,59 **** argl += strlen(tag)+1+strlen(value); if (argl >= sizeof(argbuf)) { ! fprintf(stderr, "Error: make_httpfs_url: with arg %s, argbuf too small\n", tag); return -1; } --- 58,63 ---- argl += strlen(tag)+1+strlen(value); if (argl >= sizeof(argbuf)) { ! if (hfs_output_errors) ! fprintf(stderr, "Error: make_httpfs_url: with arg %s, argbuf too small\n", tag); return -1; } *************** *** 71,75 **** if (l + strlen("__Q_=") + 2*argl + 32 >= size) { ! fprintf(stderr, "Error: make_httpfs_url: encrypted args too large for buffer\n"); return -1; } --- 75,80 ---- if (l + strlen("__Q_=") + 2*argl + 32 >= size) { ! if (hfs_output_errors) ! fprintf(stderr, "Error: make_httpfs_url: encrypted args too large for buffer\n"); return -1; } *************** *** 82,86 **** } else { if (l + argl >= size) { ! fprintf(stderr, "Error: make_httpfs_url: args too large for buffer\n"); return -1; } --- 87,92 ---- } else { if (l + argl >= size) { ! if (hfs_output_errors) ! fprintf(stderr, "Error: make_httpfs_url: args too large for buffer\n"); return -1; } *************** *** 112,116 **** hc = hc_start_request(url); if (!hc) { ! perror("Error: make_request(): hc_start_request()"); goto exit; } --- 118,123 ---- hc = hc_start_request(url); if (!hc) { ! if (hfs_output_errors) ! perror("Error: make_request(): hc_start_request()"); goto exit; } *************** *** 124,128 **** http_status = hc_get_status(hc); if (http_status/100 != 2) { ! fprintf(stderr, "Error: http status %d\n", http_status); goto exit; } --- 131,136 ---- http_status = hc_get_status(hc); if (http_status/100 != 2) { ! if (hfs_output_errors) ! fprintf(stderr, "Error: http status %d\n", http_status); goto exit; } *************** *** 166,170 **** return 0; } else { ! fprintf(stderr, "Error: end of httpfs status line not found\n"); return -1; } --- 174,179 ---- return 0; } else { ! if (hfs_output_errors) ! fprintf(stderr, "Error: end of httpfs status line not found\n"); return -1; } *************** *** 262,266 **** hc = hc_start_request(buf); if (!hc) { ! perror("Error: hfs_do_simple(): hc_start_request()"); return -1; } --- 271,276 ---- hc = hc_start_request(buf); if (!hc) { ! if (hfs_output_errors) ! perror("Error: hfs_do_simple(): hc_start_request()"); return -1; } *************** *** 275,279 **** http_status = hc_get_status(hc); if (http_status/100 != 2) { ! fprintf(stderr, "Error: http status %d\n", http_status); hc_free(hc); return http_status; --- 285,290 ---- http_status = hc_get_status(hc); if (http_status/100 != 2) { ! if (hfs_output_errors) ! fprintf(stderr, "Error: http status %d\n", http_status); hc_free(hc); return http_status; *************** *** 294,298 **** return 0; } else { ! fprintf(stderr, "Error: end of httpfs status line not found\n"); return -1; } --- 305,310 ---- return 0; } else { ! if (hfs_output_errors) ! fprintf(stderr, "Error: end of httpfs status line not found\n"); return -1; } Index: Makefile =================================================================== RCS file: /cvsroot/replaypc/replaypc/Makefile,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Makefile 19 Jun 2002 18:02:33 -0000 1.16 --- Makefile 22 Jun 2002 00:19:27 -0000 1.17 *************** *** 39,43 **** # on a Unix system ! VER=0.4.0 CPPFLAGS=$(BIGFILE) $(LARGEFILE_SUPPORT) $(PLATFORM_SUPPORT) --- 39,43 ---- # on a Unix system ! VER=0.5.0pre CPPFLAGS=$(BIGFILE) $(LARGEFILE_SUPPORT) $(PLATFORM_SUPPORT) *************** *** 46,51 **** LDLIBS=-lreplaypc $(MD5LIB) ! PROGRAMS=ReplayPC httpfs mark-commercial rddns dump-guide rtvguide ! EXTRA_PROGRAMS=find-GOPs build-ndx ndx-dump un-protect crypt-test dump-cg2 dump-headend dump-zipcode2 dump-filedarray dump-replaychannels dump-addressbook dump-channelset dump-programset dump-replayshows version-test SCRIPTS=rns DOCS=Authors COPYING Readme.txt --- 46,51 ---- LDLIBS=-lreplaypc $(MD5LIB) ! PROGRAMS=ReplayPC httpfs mark-commercial rddns dump-guide rtvguide timecheck ! EXTRA_PROGRAMS=find-GOPs build-ndx ndx-dump un-protect crypt-test dump-cg2 dump-headend dump-zipcode2 dump-filedarray dump-replaychannels dump-addressbook dump-channelset dump-programset dump-replayshows version-test SCRIPTS=rns DOCS=Authors COPYING Readme.txt |