Lines 42-53
OS_Name::OS_Name(void) {
Link Here
|
42 |
******************* |
42 |
******************* |
43 |
* returns FAIL is the OS already exist. os_id otherwise. |
43 |
* returns FAIL is the OS already exist. os_id otherwise. |
44 |
*/ |
44 |
*/ |
45 |
|
45 |
|
46 |
|
46 |
|
47 |
int OS_Name::add_os(string &os_name) { |
47 |
int OS_Name::add_os(string &os_name) { |
48 |
|
48 |
|
49 |
if (find_os(os_name) != FAIL) return FAIL; /* exist */ |
49 |
if (find_os(os_name) != FAIL) return FAIL; /* exist */ |
50 |
|
50 |
|
51 |
osid_name.insert(pair<int, string>(id_count, os_name)); |
51 |
osid_name.insert(pair<int, string>(id_count, os_name)); |
52 |
return (id_count++); |
52 |
return (id_count++); |
53 |
} |
53 |
} |
Lines 58-64
int OS_Name::add_os(string &os_name) {
Link Here
|
58 |
******************* |
58 |
******************* |
59 |
* returns FAIL is the OS does not exist. os_id otherwise. |
59 |
* returns FAIL is the OS does not exist. os_id otherwise. |
60 |
*/ |
60 |
*/ |
61 |
|
61 |
|
62 |
|
62 |
|
63 |
int OS_Name::find_os(string &os_name) { |
63 |
int OS_Name::find_os(string &os_name) { |
64 |
map <int, string>::iterator osid_i; |
64 |
map <int, string>::iterator osid_i; |
Lines 76-82
int OS_Name::find_os(string &os_name) {
Link Here
|
76 |
******************* |
76 |
******************* |
77 |
* for debugging _ONLY_ |
77 |
* for debugging _ONLY_ |
78 |
*/ |
78 |
*/ |
79 |
|
79 |
|
80 |
|
80 |
|
81 |
void OS_Name::list_oses(void) { |
81 |
void OS_Name::list_oses(void) { |
82 |
map <int, string>::iterator osid_i; |
82 |
map <int, string>::iterator osid_i; |
Lines 94-111
void OS_Name::list_oses(void) {
Link Here
|
94 |
******************* |
94 |
******************* |
95 |
* for debugging _ONLY_ |
95 |
* for debugging _ONLY_ |
96 |
*/ |
96 |
*/ |
97 |
|
|
|
98 |
|
97 |
|
99 |
|
98 |
|
100 |
const string OS_Name::osid2str(int id) { |
99 |
|
|
|
100 |
const string & OS_Name::osid2str(int id) { |
101 |
map <int, string>::iterator osid_i = osid_name.find(id); |
101 |
map <int, string>::iterator osid_i = osid_name.find(id); |
102 |
if (osid_i != osid_name.end()) return ((*osid_i).second); |
102 |
if (osid_i != osid_name.end()) return ((*osid_i).second); |
103 |
return ("BUG, PLEASE REPORT! :-)"); |
103 |
return ("BUG, PLEASE REPORT! :-)"); |
104 |
} |
104 |
} |
105 |
|
105 |
|
106 |
/* |
106 |
/* |
107 |
* OS_Vector stuff: |
107 |
* OS_Vector stuff: |
108 |
*/ |
108 |
*/ |
109 |
OS_Vector::OS_Vector(int new_os_id) { |
109 |
OS_Vector::OS_Vector(int new_os_id) { |
110 |
os_id = new_os_id; |
110 |
os_id = new_os_id; |
111 |
total = 0; |
111 |
total = 0; |
Lines 148-165
int OS_Matrix::find_os_id(int os_id) {
Link Here
|
148 |
if (os_id == osid_vec[i].get_os_id()) return i; |
148 |
if (os_id == osid_vec[i].get_os_id()) return i; |
149 |
return -1; |
149 |
return -1; |
150 |
} |
150 |
} |
151 |
|
151 |
|
152 |
void OS_Matrix::add_result(int test_id, int os_id, int score, int times) { |
152 |
void OS_Matrix::add_result(int test_id, int os_id, int score, int times) { |
153 |
int i; |
153 |
int i; |
154 |
|
154 |
|
155 |
xprobe_debug(XPROBE_DEBUG_OSMATRIX, "test_id: %i os_id: %i score: %i\n", test_id, os_id, score); |
155 |
xprobe_debug(XPROBE_DEBUG_OSMATRIX, "test_id: %i os_id: %i score: %i\n", test_id, os_id, score); |
156 |
|
156 |
|
157 |
if (find_os_id(os_id) == -1) /* if doesn't exist. we insert it |
157 |
if (find_os_id(os_id) == -1) /* if doesn't exist. we insert it |
158 |
* first */ |
158 |
* first */ |
159 |
osid_vec.push_back(OS_Vector(os_id)); |
159 |
osid_vec.push_back(OS_Vector(os_id)); |
160 |
|
160 |
|
161 |
i = find_os_id(os_id); |
161 |
i = find_os_id(os_id); |
162 |
while (times-- > 0) { |
162 |
while (times-- > 0) { |
163 |
osid_vec[i].add_result(test_id, score); |
163 |
osid_vec[i].add_result(test_id, score); |
164 |
} |
164 |
} |
165 |
} |
165 |
} |
Lines 173-179
int OS_Matrix::get_score(int os_id) {
Link Here
|
173 |
|
173 |
|
174 |
int OS_Matrix::get_max_score(int os_id) { |
174 |
int OS_Matrix::get_max_score(int os_id) { |
175 |
int i = find_os_id(os_id); |
175 |
int i = find_os_id(os_id); |
176 |
|
176 |
|
177 |
//return (xp_loaded_mods * XPROBE_MATCH_YES); |
177 |
//return (xp_loaded_mods * XPROBE_MATCH_YES); |
178 |
return (osid_vec[i].get_number_of_keywords() * XPROBE_MATCH_YES); |
178 |
return (osid_vec[i].get_number_of_keywords() * XPROBE_MATCH_YES); |
179 |
|
179 |
|
Lines 181-192
int OS_Matrix::get_max_score(int os_id) {
Link Here
|
181 |
|
181 |
|
182 |
int OS_Matrix::get_prcnt_score(int os_id) { |
182 |
int OS_Matrix::get_prcnt_score(int os_id) { |
183 |
|
183 |
|
184 |
if (get_score(os_id) < 0) return 0; |
184 |
if (get_score(os_id) < 0) return 0; |
185 |
return get_score(os_id) * 100/get_max_score(os_id); |
185 |
return get_score(os_id) * 100/get_max_score(os_id); |
186 |
|
186 |
|
187 |
} |
187 |
} |
188 |
|
188 |
|
189 |
int OS_Matrix::get_top(int num) { |
189 |
int OS_Matrix::get_top(int num) { |
190 |
|
190 |
|
191 |
sort(osid_vec.begin(), osid_vec.end(), os_vector_compare); |
191 |
sort(osid_vec.begin(), osid_vec.end(), os_vector_compare); |
192 |
|
192 |
|
Lines 194-198
int OS_Matrix::get_top(int num) {
Link Here
|
194 |
return osid_vec[num].get_os_id(); |
194 |
return osid_vec[num].get_os_id(); |
195 |
|
195 |
|
196 |
return 0; /* out of range */ |
196 |
return 0; /* out of range */ |
197 |
} |
197 |
} |
198 |
|
|
|