// The main funtion int main (int argc, char * argv []) { signal(SIGPIPE, sigproc); int snaplen = -1; int port = 0; int limit = 0; int max_conn= 7; bool daemon = false; init_packet_handler(); // set up tables std::string webroot="",pcaproot=""; std::string query=""; while (1) { int option_index; struct option long_options [] = { {"select", 1, 0, 's'}, {"limit", 1, 0, 'l'}, {"maxconn", 1, 0, 'm'}, {"webroot", 1, 0, 'w'}, {"pcaproot",1, 0, 'r'}, {"port", 1, 0, 'p'}, {"deamon", 0, 0, 'd'}, {"csv", 0, 0, 'c'}, {"json", 0, 0, 'j'}, {"table", 0, 0, 't'}, {"xml", 0, 0, 'x'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {NULL, 0, 0, 0} }; int c = getopt_long (argc, argv, "w:r:s:l:p:hHdvcxtjm:", long_options, &option_index); if (c == -1) break; switch (c) { case 'v': fprintf (stdout, "%s\n", PACKAGE_STRING ); exit (0); break; case 's': query = optarg; break; case 'c': g_app->set_output(PacketQ::csv); break; case 't': g_app->set_output(PacketQ::csv_format); break; case 'x': g_app->set_output(PacketQ::xml); break; case 'j': g_app->set_output(PacketQ::json); break; case 'd': daemon = true; break; case 'w': webroot = optarg; break; case 'r': pcaproot = optarg; break; case 'm': max_conn = atoi(optarg)+1; if (max_conn<2) max_conn = 2; break; case 'l': limit = atoi(optarg); break; case 'p': port = atoi(optarg); break; default: fprintf (stderr, "Unknown option: %c\n", c); usage (argv [0],false); return 1; case 'h': usage (argv [0],true); return 1; } } g_app->set_limit(limit); if (port>0) { start_server( port, daemon, webroot, pcaproot, max_conn ); } if (optind >= argc) { fprintf (stderr, "Missing input uri\n"); usage (argv [0],false); return 1; } try { // pass 1 make sure we read out sample Query q; q.ask( query.c_str(), true ); g_app->m_query.set_sample( q.get_sample() ); } catch(Error &e) { printf( "Error: %s\n", e.m_err.c_str() ); fflush( stdout ); exit(1); } catch(...) { } while (optind < argc) { read_file( argv[optind] ); optind++; } try { // pass 2 now all tables are in place and the query can be properly analyzed g_app->m_query.ask( query.c_str() ); } catch(Error &e) { printf( "Error: %s\n", e.m_err.c_str() ); fflush( stdout ); exit(1); } catch(...) { printf( "Error: an unknown error has occured !\n" ); fflush( stdout ); } g_app->m_query.execute(); Table *result = g_app->m_query.get_result(); switch( g_app->get_output() ) { case( PacketQ::csv_format ): { if (result) result->csv(true); } break; case( PacketQ::csv ): { if (result) result->csv(); } break; case( PacketQ::xml ): { if (result) result->xml(); } break; case( PacketQ::json ): { printf("[\n"); if (result) result->json(); printf("]\n"); } break; } delete g_app; return 0; }