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);
188 string time2str(sfinx_timestamp_t &t)
191 int year, month, day, hour, min, sec;
192 t.GetDate(year, month, day);
193 t.GetTime(hour, min, sec);
194 sprintf(buf, "%02d/%02d/%04d %02d:%02d:%02d\n", day, month, year, hour, min, sec);
198 void faraon_app::prepare_search_info(sfinx_t *el, string &inf)
204 case SFINX_ELEMENT_SLICE:
205 s = (sfinx_slice_t *)el;
206 inf = "\nType: Slice\n";
207 inf.append("Name: " + s->name_ + "\n");
208 inf.append("Description: " + s->description_ + "\n");
209 inf.append("Create Entry Time: " + time2str(s->ctime));
210 inf.append("Edit Entry Time: " + time2str(s->etime));
213 case SFINX_ELEMENT_NOTE:
214 n = (sfinx_note_t *)el;
215 inf = "\nType: Note\n";
216 inf.append("Name: " + n->name + "\n");
217 inf.append("URL: " + n->url + "\n");
218 inf.append("Text: " + n->text + "\n");
219 inf.append("Create Entry Time: " + time2str(n->ctime));
220 inf.append("Edit Entry Time: " + time2str(n->etime));
223 case SFINX_ELEMENT_FILE:
224 f = (sfinx_file_t *)el;
225 inf = "\nType: File\n";
226 inf.append("Name: " + f->name + "\n");
227 inf.append("Slice Hierarchy: " + app->slice_hierarchy(f->mtag.slice_id) + "\n");
228 if (f->tags.size()) {
229 inf.append("Additional Tags : ");
230 for (u32_t i = 0; i < f->tags.size(); i++) {
233 inf.append(f->tags[i].name + " [ " + f->tags[i].description + " ]");
237 inf.append("Title: " + f->title + "\n");
238 inf.append("Authority: " + f->authority + "\n");
239 inf.append("Description: " + f->description + "\n");
240 inf.append("Comments: " + f->comments + "\n");
242 sprintf(buf, "%llu bytes\n", f->fsize);
243 inf.append("Size: ");
246 inf.append("Csum: " + f->csum + "\n");
247 sprintf(buf, "%llu bytes\n", f->compressed_fsize);
248 inf.append("Compressed Size: ");
250 if (f->compressed_csum.size())
251 inf.append("Compressed Csum: " + f->compressed_csum + "\n");
252 inf.append("Create Entry Time: " + time2str(f->ctime));
253 inf.append("Edit Entry Time: " + time2str(f->etime));
257 debug("Can't fill element info !");