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 CommandOption *faraon_opt_list = 0;
95 CommandOptionArg server_opt("sfinx", "s", "\tSfinx Server", false,
98 int main(int argc, char **argv)
100 setlocale(LC_ALL, "");
102 sprintf(version, "v%0d.%0d.%0d", SFINX_VERSION_MAJOR, SFINX_VERSION_MINOR, SFINX_VERSION_PLEVEL);
103 app = new faraon_app(argc, argv, "faraon", version,
104 "Rus V. Brushkoff <Rus@Sfinx.Od.UA>", "GPL", faraon_opt_list);
105 app->start_ui(); // start ui
106 app->read_preferences();
109 if (!app->connected()) {
115 catch (SockException *s) {
116 app->ui()->log(SFINX_LOG_FATAL, "Socket exception to %s",
117 app->server_name.c_str());
118 app->sfinx.disconnect();
122 app->ui()->log(SFINX_LOG_FATAL, "Error connecting to %s: (%d) \'%s\'",
123 app->server_name.c_str(), s->getErrorNumber(), s->getErrorString());
127 app->ui()->log(SFINX_LOG_WARN, "Unknown exeption while talking to %s",
128 app->server_name.c_str());
129 app->sfinx.disconnect();
136 bool faraon_app::connect()
138 if (!server_name.size()) {
139 ui()->log(SFINX_LOG_FATAL, "Sfinx server name is not set !");
142 ui()->log(SFINX_LOG_NOTICE, "Connecting to Sfinx server at %s", server_name.c_str());
143 // ask username/pass or select auth_type
144 if (!sfinx.connect(server_name)) {
145 char b[1024], b1[128];
146 sprintf(b, "Connected to server v%d.%d.%d, %lld crypt facilities [ ",
147 sfinx.daemon_version->get(0), sfinx.daemon_version->get(1),
148 sfinx.daemon_version->get(2), sfinx.packet_crypt_types->len());
149 for (u32_t i = 0; i < sfinx.packet_crypt_types->len(); i++) {
150 sprintf(b1, "%s%s", i ? ", " : "",
151 sfinx_cmd2str(sfinx.packet_crypt_types->get(i)));
154 sprintf(b1, " ], %lld auth level [ ", sfinx.min_auth_levels->len());
156 for (u32_t i = 0; i < sfinx.min_auth_levels->len(); i++) {
157 sprintf(b1, "%s%s", i ? ", " : "", sfinx_cmd2str(sfinx.min_auth_levels->get(i)));
161 ui()->log(SFINX_LOG_NOTICE, b);
162 strcpy(b, "md5 server challenge [ ");
163 for (u32_t i = 0; i < sfinx.md5_challenge->len(); i++) {
164 sprintf(b1, "%02x", sfinx.md5_challenge->get(i));
168 ui()->log(SFINX_LOG_NOTICE, b);
174 void faraon_app::read_preferences()
177 Fl_Preferences conn_prefs(prefs, "Connection" );
178 if (server_opt.numValue)
179 server_name = server_opt.values[0];
181 conn_prefs.get("Sfinx Server Name", buf, "localhost", 100);
185 sfinx.send(SFINX_FILES_MODULE_CONF_REQUEST, (u8_t) 0);
188 void faraon_app::write_preferences()
190 Fl_Preferences conn_prefs(prefs, "Connection" );
191 conn_prefs.set("Sfinx Server Name", server_name.c_str());
194 sfinx.send(files_module_conf);
198 string time2str(sfinx_timestamp_t &t)
201 int year, month, day, hour, min, sec;
202 t.GetDate(year, month, day);
203 t.GetTime(hour, min, sec);
204 sprintf(buf, "%02d/%02d/%04d %02d:%02d:%02d\n", day, month, year, hour, min, sec);
208 void faraon_app::prepare_search_info(sfinx_t *el, string &inf)
214 files_module_conf.get(FILES_MODULE_SORTED_TREE_PATH, dir);
216 case SFINX_ELEMENT_SLICE:
217 s = (sfinx_slice_t *)el;
218 inf = "\nType: Slice\n";
219 inf.append("Name: " + s->name_ + "\n");
220 inf.append("Description: " + s->description_ + "\n");
221 inf.append("Create Entry Time: " + time2str(s->ctime));
222 inf.append("Edit Entry Time: " + time2str(s->etime));
225 case SFINX_ELEMENT_NOTE:
226 n = (sfinx_note_t *)el;
227 inf = "\nType: Note\n";
228 inf.append("Name: " + n->name + "\n");
229 inf.append("URL: " + n->url + "\n");
230 inf.append("Text: " + n->text + "\n");
231 inf.append("Create Entry Time: " + time2str(n->ctime));
232 inf.append("Edit Entry Time: " + time2str(n->etime));
235 case SFINX_ELEMENT_FILE:
236 f = (sfinx_file_t *)el;
237 inf = "\nType: File\n";
238 inf.append("Title: " + f->title + "\n");
239 inf.append("URL: " + dir + slice_hierarchy_path(f->mtag.slice_id) + "/" + f->name + "\n");
240 inf.append("Slice Hierarchy: " + app->slice_hierarchy(f->mtag.slice_id) + "\n");
241 if (f->tags.size()) {
242 inf.append("Additional Tags : ");
243 for (u32_t i = 0; i < f->tags.size(); i++) {
246 inf.append(f->tags[i].name + " [ " + f->tags[i].description + " ]");
250 inf.append("Authority: " + f->authority + "\n");
251 inf.append("Description: " + f->description + "\n");
252 inf.append("Comments: " + f->comments + "\n");
254 sprintf(buf, "%llu bytes\n", f->fsize);
255 inf.append("Size: ");
258 inf.append("Csum: " + f->csum + "\n");
259 if (f->compressed_csum.size()) {
260 inf.append("Compressed Size: ");
261 sprintf(buf, "%llu bytes\n", f->compressed_fsize);
263 inf.append("Compressed Csum: " + f->compressed_csum + "\n");
265 inf.append("Create Entry Time: " + time2str(f->ctime));
266 inf.append("Edit Entry Time: " + time2str(f->etime));
270 debug("Can't fill element info !");