3 * Copyright (C) 2007, Rus V. Brushkoff, All rights reserved.
10 Fl_Preferences prefs(Fl_Preferences::USER, "Harbour", "Sfinx");
12 bool faraon_app::process_requests()
14 if (sfinx.read_packet()) {
15 log("faraon:process", "Error reading sfinx request");
19 while ((el = sfinx.rx_elements.next())) {
21 case SFINX_NOTES_MODULE_UNSORT_REPLY:
22 case SFINX_NOTES_MODULE_UNLINK_REPLY:
23 case SFINX_FILES_MODULE_SORTED_UNLINK_REPLY:
24 case SFINX_FILES_MODULE_UNSORT_REPLY:
26 case SFINX_NOTES_MODULE_EDIT_REPLY:
27 ui()->notes_module_reply((sfinx_string_t *)el);
29 case SFINX_NOTES_MODULE_EDIT_REQUEST:
30 ui()->notes_module_edit((sfinx_note_t *)el);
32 case SFINX_ELEMENT_SEARCH_RESULT:
33 ui()->search_browser((sfinx_pair_vector_t *)el);
35 case SFINX_FILES_MODULE_EDIT_REQUEST:
36 ui()->files_module_edit((sfinx_file_t *)el);
39 ui()->alert((sfinx_string_t *)el);
41 case SFINX_NOTES_MODULE_ADD_REPLY:
42 ui()->notes_module_reply((sfinx_string_t *)el);
44 case SFINX_FILES_MODULE_EDIT_REPLY:
45 case SFINX_FILES_MODULE_CLASSIFY_REPLY:
46 ui()->files_module_edit_reply((sfinx_string_t *)el);
48 case SFINX_ELEMENT_PROGRESS:
49 ui()->progress((sfinx_progress_t *)el);
51 // case SFINX_FILES_MODULE_SORTED_TREE:
52 case SFINX_FILES_MODULE_UNSORTED_TREE:
53 ui()->fill_unsorted_files_tree((sfinx_files_vector_t *)el);
55 case SFINX_FILES_MODULE_CONF:
56 files_module_conf.copy(el);
57 ui()->fill_preferences();
59 case SFINX_EDIT_SLICE:
60 ui()->edit_slice((sfinx_slice_t *)el);
62 case SFINX_OBJECTS_TREE:
63 slices.copy((sfinx_slice_vector_t *)el);
64 slices_need_update = false;
65 ui()->fill_objects_tree();
68 log("sfinx:process", "Unknown element id - %s", sfinx_cmd2str(el->tid()));
76 void faraon_app::main()
78 sfinx.send(SFINX_FILES_MODULE_CONF_REQUEST, (u8_t) 0);
79 // after connecting get all objects info
82 if (sfinx.pending()) {
83 if (process_requests()) {
84 log("faraon:main", "Bad sfinx message");
93 int main(int argc, char **argv)
95 setlocale(LC_ALL, "");
97 sprintf(version, "v%0d.%0d.%0d", SFINX_VERSION_MAJOR, SFINX_VERSION_MINOR, SFINX_VERSION_PLEVEL);
98 app = new faraon_app(argc, argv, "faraon", version, "Harbour <Harbour@Sfinx.Od.UA>", "GPL");
99 app->start_ui(); // start ui
100 app->read_preferences();
103 if (!app->connected()) {
109 catch (SockException *s) {
110 app->ui()->log(SFINX_LOG_FATAL, "Socket exception to %s",
111 app->server_name.c_str());
112 app->sfinx.disconnect();
116 app->ui()->log(SFINX_LOG_FATAL, "Error connecting to %s: (%d) \'%s\'",
117 app->server_name.c_str(), s->getErrorNumber(), s->getErrorString());
121 app->ui()->log(SFINX_LOG_WARN, "Unknown exeption while talking to %s",
122 app->server_name.c_str());
123 app->sfinx.disconnect();
130 bool faraon_app::connect()
132 if (!server_name.size()) {
133 ui()->log(SFINX_LOG_FATAL, "Sfinx server name is not set !");
136 ui()->log(SFINX_LOG_NOTICE, "Connecting to Sfinx server at %s", server_name.c_str());
137 // ask username/pass or select auth_type
138 if (!sfinx.connect(server_name)) {
139 char b[1024], b1[128];
140 sprintf(b, "Connected to server v%d.%d.%d, %lld crypt facilities [ ",
141 sfinx.daemon_version->get(0), sfinx.daemon_version->get(1),
142 sfinx.daemon_version->get(2), sfinx.packet_crypt_types->len());
143 for (u32_t i = 0; i < sfinx.packet_crypt_types->len(); i++) {
144 sprintf(b1, "%s%s", i ? ", " : "",
145 sfinx_cmd2str(sfinx.packet_crypt_types->get(i)));
148 sprintf(b1, " ], %lld auth level [ ", sfinx.min_auth_levels->len());
150 for (u32_t i = 0; i < sfinx.min_auth_levels->len(); i++) {
151 sprintf(b1, "%s%s", i ? ", " : "", sfinx_cmd2str(sfinx.min_auth_levels->get(i)));
155 ui()->log(SFINX_LOG_NOTICE, b);
156 strcpy(b, "md5 server challenge [ ");
157 for (u32_t i = 0; i < sfinx.md5_challenge->len(); i++) {
158 sprintf(b1, "%02x", sfinx.md5_challenge->get(i));
162 ui()->log(SFINX_LOG_NOTICE, b);
168 void faraon_app::read_preferences()
171 Fl_Preferences conn_prefs(prefs, "Connection" );
172 conn_prefs.get("Sfinx Server Name", buf, "localhost", 100);
175 sfinx.send(SFINX_FILES_MODULE_CONF_REQUEST, (u8_t) 0);
178 void faraon_app::write_preferences()
180 Fl_Preferences conn_prefs(prefs, "Connection" );
181 conn_prefs.set("Sfinx Server Name", server_name.c_str());
184 sfinx.send(files_module_conf);