6 Fl_Preferences prefs(Fl_Preferences::USER, "Harbour", "Sfinx");
8 bool faraon_app::process_requests()
10 if (sfinx.read_packet()) {
11 log("faraon:process", "Error reading sfinx request");
15 while ((el = sfinx.rx_elements.next())) {
17 case SFINX_ELEMENT_SEARCH_RESULT:
18 ui()->search_browser((sfinx_pair_vector_t *)el);
20 case SFINX_FILES_MODULE_EDIT_FILE_REQUEST:
21 ui()->files_module_edit((sfinx_file_t *)el);
24 ui()->alert((sfinx_string_t *)el);
26 case SFINX_FILES_MODULE_EDIT_REPLY:
27 ui()->files_module_edit_reply((sfinx_string_t *)el);
29 case SFINX_FILES_MODULE_CLASSIFY_REPLY:
30 ui()->files_module_classify_reply((sfinx_string_t *)el);
32 case SFINX_ELEMENT_PROGRESS:
33 ui()->progress((sfinx_progress_t *)el);
35 case SFINX_FILES_MODULE_SORTED_TREE:
36 case SFINX_FILES_MODULE_UNSORTED_TREE:
37 ui()->fill_files_module_tree((sfinx_files_vector_t *)el);
39 case SFINX_FILES_MODULE_CONF:
40 // set files module conf
41 files_module_conf.copy(el);
42 ui()->fill_preferences();
44 case SFINX_EDIT_SLICE:
45 ui()->edit_slice((sfinx_slice_t *)el);
47 case SFINX_SLICES_MODULE_TREE:
48 ui()->fill_slices_tree((sfinx_slice_vector_t *)el);
49 slices.copy((sfinx_slice_vector_t *)el);
51 case SFINX_SLICES_MODULE_TREE_EXCEPT:
52 ui()->fill_select_slice_tree((sfinx_slice_vector_t *)el);
55 log("sfinx:process", "Unknown element id - 0x%x", el->id());
63 void faraon_app::main()
65 // after connecting get some info :
66 sfinx.send(SFINX_SLICES_MODULE_TREE_REQUEST, (u8_t)0); // prepare for slice_name() calls
68 if (sfinx.pending()) {
69 if (process_requests()) {
70 log("faraon:main", "Bad sfinx message");
79 int main(int argc, char **argv)
81 setlocale(LC_ALL, "");
83 sprintf(version, "v%0d.%0d.%0d", SFINX_VERSION_MAJOR, SFINX_VERSION_MINOR, SFINX_VERSION_PLEVEL);
84 app = new faraon_app(argc, argv, "faraon", version, "Harbour <Harbour@Sfinx.Od.UA>", "GPL");
85 app->start_ui(); // start ui
86 app->read_preferences();
89 if (!app->connected()) {
95 catch (SockException *s) {
96 app->ui()->log(SFINX_LOG_FATAL, "Socket exception to %s",
97 app->server_name.c_str());
101 app->ui()->log(SFINX_LOG_FATAL, "Error connecting to %s: (%d) \'%s\'",
102 app->server_name.c_str(), s->getErrorNumber(), s->getErrorString());
106 app->ui()->log(SFINX_LOG_WARN, "Disconnected from %s",
107 app->server_name.c_str());
114 bool faraon_app::connect()
116 if (!server_name.size()) {
117 ui()->log(SFINX_LOG_FATAL, "Sfinx server name is not set !");
120 ui()->log(SFINX_LOG_NOTICE, "Connecting to Sfinx server at %s", server_name.c_str());
121 // ask username/pass or select auth_type
122 if (!sfinx.connect(server_name)) {
123 char b[1024], b1[128];
124 sprintf(b, "Connected to server v%d.%d.%d, %d crypt facilities [", sfinx.daemon_version->get(0), sfinx.daemon_version->get(1),
125 sfinx.daemon_version->get(2), sfinx.packet_crypt_types->size());
126 for (u32_t i = 0; i < sfinx.packet_crypt_types->size(); i++) {
127 sprintf(b1, " 0x%x ", sfinx.packet_crypt_types->get(i));
130 sprintf(b1, "], %d auth level [", sfinx.min_auth_levels->size());
132 for (u32_t i = 0; i < sfinx.min_auth_levels->size(); i++) {
133 sprintf(b1, " 0x%x ", sfinx.min_auth_levels->get(i));
137 ui()->log(SFINX_LOG_NOTICE, b);
138 strcpy(b, "md5 server challenge [ ");
139 for (u32_t i = 0; i < sfinx.md5_challenge->size(); i++) {
140 sprintf(b1, "%02x", sfinx.md5_challenge->get(i));
144 ui()->log(SFINX_LOG_NOTICE, b);
150 void faraon_app::read_preferences()
153 Fl_Preferences conn_prefs(prefs, "Connection" );
154 conn_prefs.get("Sfinx Server Name", buf, "localhost", 100);
157 sfinx.send(SFINX_FILES_MODULE_CONF_REQUEST, (u8_t) 0);
160 void faraon_app::write_preferences()
162 Fl_Preferences conn_prefs(prefs, "Connection" );
163 conn_prefs.set("Sfinx Server Name", server_name.c_str());
166 sfinx.send(files_module_conf);