int main(int argc, char* argv[]) { //ARGH: putting it after g_dbus_node_info_new_for_xml works on Fedora but crashes the XO... gtk_init(&argc, &argv); GError *error = NULL; GOptionContext *context; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); //g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } if(bundle_id == NULL || activity_id == NULL) { g_print ("bundle-id and activity-id are required options\n"); exit (1); } ///////////////////////////////////////////////// introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (introspection_data != NULL); gchar service_name[256]; sprintf(service_name, "org.laptop.Activity%s", activity_id); /*guint owner_id =*/ g_bus_own_name( G_BUS_TYPE_SESSION, service_name, G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); ///////////////////////////////////////////////// /* GDBusProxy *journal = g_dbus_proxy_new_for_bus_sync( G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.laptop.sugar.DataStore", "/org/laptop/sugar/DataStore", "org.laptop.sugar.DataStore", NULL, NULL); GVariant *params = g_variant_new("(a{sv}as)", NULL, NULL); //fprintf(stderr, "journal proxy params is %s\n", params == NULL ? "null" : "notnull"); GVariant *result = g_dbus_proxy_call_sync( journal, "find", params, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); //fprintf(stderr, "journal proxy result is %s\n", result == NULL ? "null" : "notnull"); if(error != NULL) {fprintf(stderr, "error: %d, %d, %s\n", error->domain, error->code, error->message);} if(result != NULL) { //fprintf(stderr, "result type: %s\n", g_variant_get_type_string(result)); GVariant *results = NULL; guint32 count = -1; g_variant_get(result, "(@aa{sv}u)", &results, &count); fprintf(stderr, "results is %s, count is %d\n", results == NULL ? "null" : "notnull", count); //fprintf(stderr, "results type: %s\n", g_variant_get_type_string(results)); GVariant *dictionary = NULL; GVariantIter results_iter; g_variant_iter_init(&results_iter, results); while (g_variant_iter_loop(&results_iter, "@a{sv}", &dictionary)) { GVariantIter dictionary_iter; g_variant_iter_init(&dictionary_iter, dictionary); const char *key = NULL; GVariant *value = NULL; while (g_variant_iter_loop(&dictionary_iter, "{s@v}", &key, &value)) { GVariant *unboxed = g_variant_get_variant(value); if(strcmp(g_variant_get_type_string(unboxed), "ay") != 0) { fprintf(stderr, "%s=%s\n", key, g_variant_print(unboxed, TRUE)); } else if(g_variant_n_children(unboxed) < 256) { // skip preview //ARGH: for some 'clever' reason most of the strings are byte arrays... fprintf(stderr, "%s=", key); guchar c; GVariantIter char_iter; g_variant_iter_init(&char_iter, unboxed); while (g_variant_iter_loop(&char_iter, "y", &c)) { fprintf(stderr, "%c", c); } fprintf(stderr, "\n"); } } } } */ ///////////////////////////////////////////////// WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); /* guint n = -1, i; guint *alma = g_signal_list_ids(G_TYPE_FROM_INSTANCE(webView), &n); for(i=0; i<n; ++i) { GSignalQuery q; g_signal_query(alma[i], &q); printf("alma: %d, %s\n", q.signal_id, q.signal_name); } */ GtkScrolledWindow *scrolledWindow = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); gtk_scrolled_window_add_with_viewport(scrolledWindow, GTK_WIDGET(webView)); GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_decorated(GTK_WINDOW(main_window), FALSE); gtk_window_maximize(GTK_WINDOW(main_window)); //ARGH: do not use fullscreen as it disables the frame //gtk_window_fullscreen(GTK_WINDOW(main_window)); gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(scrolledWindow)); g_signal_connect_after(main_window, "realize", G_CALLBACK(afterMainWindowRealized), NULL); g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL); #ifdef USE_WEBKIT2 g_signal_connect(webView, "close", G_CALLBACK(closeWebViewCb), main_window); #else g_signal_connect(webView, "close-web-view", G_CALLBACK(closeWebViewCb), main_window); /* //g_signal_connect(webView, "resource-request-starting", G_CALLBACK(resourceRequestStarting), main_window); SoupSession *session = webkit_get_default_session(); fprintf(stderr, "session is %s\n", session == NULL ? "null" : "notnull"); g_signal_connect(session, "request-started", G_CALLBACK(requestStartedCb), main_window); */ #endif SoupServer *server = soup_server_new(SOUP_SERVER_PORT, 0, NULL); // use some random port //ARGH: it crashes // SoupAddress *address = soup_address_new("localhost", 0); // if(address != NULL) { // SoupServer *server = soup_server_new(SOUP_SERVER_INTERFACE, address, NULL); // use some random port // } guint port = soup_server_get_port(server); SoupSocket *listener = soup_server_get_listener(server); SoupAddress *addr = soup_socket_get_local_address(listener); fprintf(stderr, "server host %s port %d\n", soup_address_get_name(addr), port); soup_server_add_handler(server, "/activity", serverHandleStatic, NULL, NULL); soup_server_add_handler(server, "/web", serverHandleStatic, NULL, NULL); soup_server_add_handler(server, "/journal", serverHandleJournal, NULL, NULL); // g_signal_connect(server, "request-started", G_CALLBACK(serverRequestStartedCb), NULL); soup_server_run_async(server); /* gchar *current_dir = g_get_current_dir(); gchar index_uri[256]; //ARGH: a file uri always has to be absolute sprintf(index_uri, "file://%s/index.html", current_dir); webkit_web_view_load_uri(webView, index_uri); */ //webkit_web_view_load_uri(webView, "http://nell-colors.github.cscott.net"); //webkit_web_view_load_uri(webView, "http://index.hu"); gchar buffer[256]; sprintf(buffer, "http://localhost:%d/web/index.html", port); webkit_web_view_load_uri(webView, buffer); gtk_widget_grab_focus(GTK_WIDGET(webView)); gtk_widget_show_all(main_window); gtk_main(); return 0; }
gboolean rcd_rpc_remote_server_start (void) { SoupServerAuthContext auth_ctx = { 0 }; int port = rcd_prefs_get_remote_server_port (); const char *bind_ip; /* Server's already running... */ if (soup_server != NULL) return TRUE; rc_debug (RC_DEBUG_LEVEL_MESSAGE, "Starting remote server"); bind_ip = rcd_prefs_get_bind_ipaddress (); if (bind_ip) { SoupAddress *bind_address; bind_address = soup_address_new (bind_ip, port); if (!bind_address) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Unable to bind remote server to '%s'", bind_ip); return FALSE; } if (soup_address_resolve_sync (bind_address) != SOUP_STATUS_OK) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Unable to bind remote server to '%s': Unable to " "resolve address", bind_ip); return FALSE; } soup_server = soup_server_new (SOUP_SERVER_INTERFACE, bind_address, SOUP_SERVER_PORT, port, SOUP_SERVER_SSL_CERT_FILE, SHAREDIR"/rcd.pem", SOUP_SERVER_SSL_KEY_FILE, SHAREDIR"/rcd.pem", NULL); g_object_unref (bind_address); } else { soup_server = soup_server_new (SOUP_SERVER_PORT, port, SOUP_SERVER_SSL_CERT_FILE, SHAREDIR"/rcd.pem", SOUP_SERVER_SSL_KEY_FILE, SHAREDIR"/rcd.pem", NULL); } if (!soup_server) { rc_debug (RC_DEBUG_LEVEL_ERROR, "Could not start RPC server on port %d", port); rc_debug (RC_DEBUG_LEVEL_ERROR, "(This may mean that another rcd process is already running, or that"); rc_debug (RC_DEBUG_LEVEL_ERROR, "you are not running as root and do not have the correct privileges"); rc_debug (RC_DEBUG_LEVEL_ERROR, "on this port.)"); return FALSE; } g_object_set (G_OBJECT (soup_server_get_listener (soup_server)), SOUP_SOCKET_FLAG_CLOEXEC, TRUE, NULL); auth_ctx.types = SOUP_AUTH_TYPE_DIGEST; auth_ctx.callback = soup_auth_callback; auth_ctx.digest_info.realm = "RCD"; auth_ctx.digest_info.allow_algorithms = SOUP_ALGORITHM_MD5; auth_ctx.digest_info.force_integrity = FALSE; soup_server_add_handler (soup_server, "/RPC2", &auth_ctx, soup_rpc_callback, NULL, NULL); soup_server_add_handler (soup_server, NULL, NULL, soup_default_callback, NULL, NULL); soup_server_run_async (soup_server); g_object_unref (soup_server); notify_port_change (port); return TRUE; }