|
1 /*************************************************************************** |
|
2 genericscanner.cpp - description |
|
3 ------------------- |
|
4 begin : Sa Feb 12 2005 |
|
5 copyright : (C) 2005 by Christian Hilgers |
|
6 email : christian@hilgers.ag |
|
7 ***************************************************************************/ |
|
8 |
|
9 /*************************************************************************** |
|
10 * * |
|
11 * This program is free software; you can redistribute it and/or modify * |
|
12 * it under the terms of the GNU General Public License as published by * |
|
13 * the Free Software Foundation; either version 2 of the License, or * |
|
14 * (at your option) any later version. * |
|
15 * * |
|
16 ***************************************************************************/ |
|
17 |
|
18 #include "genericscanner.h" |
|
19 |
|
20 |
|
21 bool GenericScanner::StartScanning( int fromhandler, int tohandler, const char *TempFileName ) |
|
22 { |
|
23 string ScannerAnswer; |
|
24 ScannerAnswer.reserve(100); |
|
25 |
|
26 char buf[100]; |
|
27 int ret; |
|
28 |
|
29 for(;;) |
|
30 { |
|
31 #ifndef NOMAND |
|
32 int fd = open(TempFileName, O_RDONLY); |
|
33 |
|
34 if ( fd < 0 ) |
|
35 { |
|
36 LogFile::ErrorMessage("Could not open tempfile: %s %s\n", TempFileName, strerror(errno)); |
|
37 break; |
|
38 } |
|
39 else |
|
40 { |
|
41 //Wait until file is ready for scanning |
|
42 char Ready[2]; |
|
43 while (read(fd, Ready, 1) < 0 && errno == EINTR); |
|
44 while (close(fd) < 0 && errno == EINTR); |
|
45 } |
|
46 #else |
|
47 //Wait for scanning command |
|
48 while ((ret = read(fromhandler, buf, 1)) < 0) |
|
49 { |
|
50 if (errno == EINTR) continue; |
|
51 break; |
|
52 } |
|
53 if (ret <= 0 || buf[0] != 's') break; |
|
54 #endif |
|
55 |
|
56 //Start scanner and get return code |
|
57 ScannerAnswer = Scan( TempFileName ); |
|
58 |
|
59 memset(&buf, 0, sizeof(buf)); |
|
60 ScannerAnswer.copy(buf, 99); |
|
61 |
|
62 //Send answer to ScannerHandler |
|
63 while ((ret = write(tohandler, buf, 100)) < 0) |
|
64 { |
|
65 if (errno == EINTR) continue; |
|
66 break; |
|
67 } |
|
68 if (ret <= 0) break; //Pipe was closed - or some bad error |
|
69 |
|
70 //Wait for ScannerHandler to finish before we loop again - important |
|
71 while ((ret = read(fromhandler, buf, 1)) < 0) |
|
72 { |
|
73 if (errno == EINTR) continue; |
|
74 break; |
|
75 } |
|
76 if (ret <= 0) break; //Pipe was closed - or some bad error |
|
77 |
|
78 //Continue scanning? |
|
79 if (buf[0] == 'q') break; |
|
80 } |
|
81 |
|
82 //End Scanning loop |
|
83 return false; |
|
84 } |
|
85 |
|
86 |
|
87 bool GenericScanner::InitDatabase() |
|
88 { |
|
89 LogFile::ErrorMessage("Program Error: InitDatabase()\n"); |
|
90 return false; |
|
91 } |
|
92 int GenericScanner::ReloadDatabase() |
|
93 { |
|
94 LogFile::ErrorMessage("Program Error: ReloadDatabase()\n"); |
|
95 return -1; |
|
96 } |
|
97 void GenericScanner::FreeDatabase() |
|
98 { |
|
99 LogFile::ErrorMessage("Program Error: FreeDatabase()\n"); |
|
100 } |
|
101 string GenericScanner::Scan( const char *TempFileName ) |
|
102 { |
|
103 LogFile::ErrorMessage("Program Error: Scan()\n"); |
|
104 return ""; |
|
105 } |
|
106 |
|
107 //Scanner might not have this function, so this is allowed |
|
108 void GenericScanner::CloseSocket() |
|
109 { |
|
110 } |
|
111 |
|
112 //Constructor |
|
113 GenericScanner::GenericScanner() |
|
114 { |
|
115 } |
|
116 |
|
117 //Destructor |
|
118 GenericScanner::~GenericScanner() |
|
119 { |
|
120 } |