summaryrefslogtreecommitdiff
path: root/src/osfp_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/osfp_common.c')
-rw-r--r--src/osfp_common.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/osfp_common.c b/src/osfp_common.c
index 315fd88..6f6f596 100644
--- a/src/osfp_common.c
+++ b/src/osfp_common.c
@@ -1,3 +1,9 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/fcntl.h>
+
#include "osfp_common.h"
#include "osfp.h"
@@ -41,6 +47,70 @@ enum osfp_os_class_id osfp_os_class_name_to_id(char *name)
return OSFP_OS_CLASS_MAX;
}
+struct osfp_result *osfp_result_build(struct osfp_os_class_score *os_class_score, const char *matched)
+{
+ int i;
+ unsigned int tmp_score;
+ unsigned int likely_score;
+ enum osfp_os_class_id likely_os_class;
+ struct osfp_result *result;
+
+ result = calloc(1, sizeof(struct osfp_result));
+ if (result == NULL) {
+ goto exit;
+ }
+
+ likely_score = 0;
+ likely_os_class = OSFP_OS_CLASS_OTHERS;
+
+ // likely os score
+ for (i = 0; i < OSFP_OS_CLASS_MAX; i++) {
+ tmp_score = os_class_score->scores[i];
+
+ if (likely_score < tmp_score) {
+ likely_score = tmp_score;
+ likely_os_class = i;
+ }
+ result->details[i].score = tmp_score;
+ }
+
+ // prefiltered
+ if (likely_score == OSFP_PERCENTILE) {
+ goto end;
+ }
+
+ // too low to tell os class
+ if (likely_score < OSFP_LOWEST_SCORE_LIMIT) {
+ likely_os_class = OSFP_OS_CLASS_OTHERS;
+ goto end;
+ }
+
+ // when the tied likely scores appear between win/apple-like/unix-like, we throw unknown
+ for (i = 0; i < OSFP_OS_CLASS_MAX; i++) {
+ if (likely_os_class == i) {
+ continue;
+ }
+ if (likely_score != os_class_score->scores[i]) {
+ continue;
+ }
+ if (likely_os_class == OSFP_OS_CLASS_LINUX && i == OSFP_OS_CLASS_ANDROID) {
+ continue;
+ }
+ if (likely_os_class == OSFP_OS_CLASS_MAC_OS && i == OSFP_OS_CLASS_IOS) {
+ continue;
+ }
+ likely_os_class = OSFP_OS_CLASS_UNKNOWN;
+ break;
+ }
+
+end:
+ result->likely_os_class = likely_os_class;
+ result->matched = matched;
+ return result;
+exit:
+ return NULL;
+}
+
void osfp_profile_counter_print(struct osfp_profile_counter *profile, const char *name)
{
printf("profile %s: avg: %lu max: %lu min: %lu curr: %lu total: %lu count: %lu\n",