static void inf_adopted_session_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) { InfAdoptedSession* session; InfAdoptedSessionPrivate* priv; session = INF_ADOPTED_SESSION(object); priv = INF_ADOPTED_SESSION_PRIVATE(session); switch(prop_id) { case PROP_IO: g_assert(priv->io == NULL); /* construct only */ priv->io = INF_IO(g_value_dup_object(value)); break; case PROP_MAX_TOTAL_LOG_SIZE: priv->max_total_log_size = g_value_get_uint(value); break; case PROP_ALGORITHM: /* read only */ default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
/** * infinoted_signal_unregister: * @sig: A #InfinotedSignal. * * Unregisters signal handlers registered with infinoted_signal_register(). */ void infinoted_signal_unregister(InfinotedSignal* sig) { #ifdef G_OS_WIN32 SetConsoleCtrlHandler(infinoted_signal_console_handler, FALSE); #endif #ifdef LIBINFINITY_HAVE_LIBDAEMON if(sig->run) { inf_io_remove_watch(INF_IO(sig->run->io), sig->watch); sig->watch = NULL; daemon_signal_done(); } #else signal(SIGINT, sig->previous_sigint_handler); signal(SIGTERM, sig->previous_sigterm_handler); #ifndef G_OS_WIN32 signal(SIGQUIT, sig->previous_sigquit_handler); signal(SIGHUP, sig->previous_sighup_handler); #endif /* !G_OS_WIN32 */ _infinoted_signal_server = NULL; #endif /* !LIBINFINITY_HAVE_LIBDAEMON */ g_slice_free(InfinotedSignal, sig); }
static void infinoted_signal_sig_func(InfNativeSocket* fd, InfIoEvent event, gpointer user_data) { InfinotedSignal* sig; int occured; GError* error; sig = (InfinotedSignal*)user_data; if(event & INF_IO_ERROR) { inf_io_remove_watch(INF_IO(sig->run->io), sig->watch); daemon_signal_done(); sig->run = NULL; sig->signal_fd = 0; sig->watch = NULL; infinoted_log_error( sig->run->startup->log, _("Error on signal handler connection; signal " "handlers have been removed from now on") ); } else if(event & INF_IO_INCOMING) { occured = daemon_signal_next(); if(occured == SIGINT || occured == SIGTERM || occured == SIGQUIT) { printf("\n"); inf_standalone_io_loop_quit(sig->run->io); } else if(occured == SIGHUP) { error = NULL; if(!infinoted_config_reload(sig->run, &error)) { infinoted_log_error( sig->run->startup->log, _("Configuration reload failed: %s"), error->message ); g_error_free(error); } else { infinoted_log_info( sig->run->startup->log, _("Configuration reloaded") ); } } } }
/** * infinoted_signal_register: * @run: A #InfinotedRun. * * Registers signal handlers for SIGINT and SIGTERM that terminate the given * infinote server. When you don't need the signal handlers anymore, you * must unregister them again using infinoted_signal_unregister(). * * Returns: A #InfinotedSignal to unregister the signal handlers again later. */ InfinotedSignal* infinoted_signal_register(InfinotedRun* run) { InfinotedSignal* sig; sig = g_slice_new(InfinotedSignal); #ifdef LIBINFINITY_HAVE_LIBDAEMON sig->run = run; /* TODO: Should we report when this fails? Should ideally happen before * actually forking then - are signal connections kept in fork()'s child? */ if(daemon_signal_init(SIGINT, SIGTERM, SIGQUIT, SIGHUP, 0) == 0) { sig->signal_fd = daemon_signal_fd(); sig->watch = inf_io_add_watch( INF_IO(run->io), &sig->signal_fd, INF_IO_INCOMING | INF_IO_ERROR, infinoted_signal_sig_func, sig, NULL ); } #else sig->previous_sigint_handler = signal(SIGINT, &infinoted_signal_sigint_handler); sig->previous_sigterm_handler = signal(SIGTERM, &infinoted_signal_sigterm_handler); sig->previous_sigquit_handler = #ifndef G_OS_WIN32 signal(SIGQUIT, &infinoted_signal_sigquit_handler); sig->previous_sighup_handler = signal(SIGHUP, &infinoted_signal_sighup_handler); #endif /* !G_OS_WIN32 */ _infinoted_signal_server = run; #endif /* !LIBINFINITY_HAVE_LIBDAEMON */ #ifdef G_OS_WIN32 SetConsoleCtrlHandler(infinoted_signal_console_handler, TRUE); #endif return sig; }
int main(int argc, char* argv[]) { InfTestMassJoin massjoin; GError* error; int i; gchar* name; error = NULL; if(!inf_init(&error)) { fprintf(stderr, "%s\n", error->message); return -1; } massjoin.io = INF_IO(inf_standalone_io_new()); massjoin.joiners = NULL; for(i = 0; i < 128; ++i) { name = g_strdup_printf("MassJoin%03d", i); inf_test_mass_join_connect( &massjoin, "127.0.0.1", inf_protocol_get_default_port(), "Test", name ); g_free(name); //g_usleep(100000); } inf_standalone_io_loop(INF_STANDALONE_IO(massjoin.io)); return 0; }
static void inf_test_chat_userjoin_finished_cb(InfcRequest* request, InfUser* user, gpointer user_data) { InfTestChat* test; test = (InfTestChat*)user_data; printf("User join complete. Start chatting!\n"); #ifndef G_OS_WIN32 inf_io_add_watch( INF_IO(test->io), &test->input_fd, INF_IO_INCOMING | INF_IO_ERROR, inf_test_chat_input_cb, test, NULL ); #endif test->self = user; }
static void inf_test_browser_notify_status_cb(GObject* object, GParamSpec* pspec, gpointer user_data) { InfTestBrowser* test; InfBrowserStatus status; test = (InfTestBrowser*)user_data; g_object_get(G_OBJECT(test->browser), "status", &status, NULL); if(status == INF_BROWSER_OPEN) { printf("Connection established\n"); #ifndef G_OS_WIN32 inf_io_add_watch( INF_IO(test->io), &test->input_fd, INF_IO_INCOMING | INF_IO_ERROR, inf_test_browser_input_cb, test, NULL ); #endif /* Explore root node */ inf_browser_get_root(test->browser, &test->cwd); inf_browser_explore(test->browser, &test->cwd, NULL, NULL); } if(status == INF_BROWSER_CLOSED) { if(inf_standalone_io_loop_running(test->io)) inf_standalone_io_loop_quit(test->io); } }
int main(int argc, char* argv[]) { InfStandaloneIo* io; InfNameResolver* resolver; InfTcpConnection* connection; GError* error; error = NULL; if(inf_init(&error) == FALSE) { fprintf(stderr, "%s", error->message); g_error_free(error); return 1; } io = inf_standalone_io_new(); resolver = inf_name_resolver_new(INF_IO(io), "0x539.de", "5223", "_jabber._tcp"); g_signal_connect( G_OBJECT(resolver), "resolved", G_CALLBACK(resolved_cb), io ); connection = inf_tcp_connection_new_resolve(INF_IO(io), resolver); g_object_unref(resolver); g_signal_connect( G_OBJECT(connection), "received", G_CALLBACK(received_cb), io ); g_signal_connect( G_OBJECT(connection), "sent", G_CALLBACK(sent_cb), io ); g_signal_connect( G_OBJECT(connection), "error", G_CALLBACK(error_cb), io ); g_signal_connect( G_OBJECT(connection), "notify::status", G_CALLBACK(notify_status_cb), io ); if(inf_tcp_connection_open(connection, &error) == FALSE) { fprintf(stderr, "Could not open connection: %s\n", error->message); g_error_free(error); } else { inf_standalone_io_loop(io); } g_object_unref(G_OBJECT(io)); g_object_unref(G_OBJECT(connection)); return 0; }
static gboolean inf_test_certificate_validate_run(const InfTestCertificateValidateDesc* desc, GError** error) { InfIo* io; InfdXmppServer* server; InfXmppManager* xmpp_manager; InfCertificateVerify* verify; InfXmppConnection* client; gchar* pinned_file; InfXmlConnectionStatus status; InfTestCertificateValidateCheckCertificateData check_certificate_data; gboolean result; GError* conn_error; GHashTable* pinned; gnutls_x509_crt_t pinned_cert; InfCertificateChain* current_cert; gboolean cert_equal; /* Setup server */ io = INF_IO(inf_standalone_io_new()); server = inf_test_certificate_setup_server( io, desc->key_file, desc->cert_file, error ); if(server == NULL) { g_object_unref(io); return FALSE; } /* Create client */ pinned_file = inf_test_validate_setup_pin( desc->hostname, desc->pinned_certificate, error ); if(pinned_file == NULL) { g_object_unref(server); g_object_unref(io); return FALSE; } xmpp_manager = inf_xmpp_manager_new(); verify = inf_certificate_verify_new(xmpp_manager, pinned_file); check_certificate_data.did_query = FALSE; check_certificate_data.accept_query = desc->accept_query; g_signal_connect( G_OBJECT(verify), "check-certificate", G_CALLBACK(inf_test_certificate_validate_check_certificate), &check_certificate_data ); client = inf_test_certificate_validate_setup_client( io, desc->ca_file, desc->hostname, error ); if(client == NULL) { g_unlink(pinned_file); g_free(pinned_file); g_object_unref(io); g_object_unref(xmpp_manager); g_object_unref(verify); g_object_unref(server); return FALSE; } inf_xmpp_manager_add_connection(xmpp_manager, client); /* Okay, now watch for status changes on the client or whether a dialog * appears. */ g_signal_connect( G_OBJECT(client), "notify::status", G_CALLBACK(inf_test_validate_certificate_notify_status_cb), io ); conn_error = NULL; g_signal_connect( G_OBJECT(client), "error", G_CALLBACK(inf_test_validate_certificate_error_cb), &conn_error ); inf_standalone_io_loop(INF_STANDALONE_IO(io)); g_object_unref(io); /* Evaluate result */ result = TRUE; g_object_get(G_OBJECT(client), "status", &status, NULL); if(status == INF_XML_CONNECTION_OPEN) { g_assert(conn_error == NULL); if(check_certificate_data.did_query == TRUE && desc->expectation != INF_TEST_CERTIFICATE_VALIDATE_EXPECT_QUERY_ACCEPT) { g_set_error( error, inf_test_certificate_validate_error(), 3, "Certificate queried and accepted but not expected to" ); result = FALSE; } else if(check_certificate_data.did_query == FALSE && desc->expectation != INF_TEST_CERTIFICATE_VALIDATE_EXPECT_ACCEPT) { g_set_error( error, inf_test_certificate_validate_error(), 0, "Certificate accepted but not expected to" ); result = FALSE; } } else { g_assert(check_certificate_data.did_query || conn_error != NULL); /* TODO: The certificate verification result is not preserved at * the moment. We could change this in * inf_xmpp_connection_certificate_verify_cancel such that the existing * error is used if any, or otherwise our own is created. */ if(conn_error != NULL && conn_error->domain != inf_xmpp_connection_error_quark() && conn_error->code != INF_XMPP_CONNECTION_ERROR_CERTIFICATE_NOT_TRUSTED) { g_propagate_error(error, conn_error); conn_error = NULL; result = FALSE; } else if(check_certificate_data.did_query == TRUE && desc->expectation != INF_TEST_CERTIFICATE_VALIDATE_EXPECT_QUERY_REJECT) { g_set_error( error, inf_test_certificate_validate_error(), 2, "Certificate queried and rejected but not expected to" ); result = FALSE; } else if(check_certificate_data.did_query == FALSE && desc->expectation != INF_TEST_CERTIFICATE_VALIDATE_EXPECT_REJECT) { g_set_error( error, inf_test_certificate_validate_error(), 1, "Certificate rejected but not expected to" ); result = FALSE; } if(conn_error != NULL) { g_error_free(conn_error); conn_error = NULL; } } /* If we got the expected result, check whether the host was correctly * pinned or not. */ if(result == TRUE) { pinned = inf_cert_util_read_certificate_map(pinned_file, error); if(pinned == NULL) { result = FALSE; } else { pinned_cert = g_hash_table_lookup(pinned, desc->hostname); cert_equal = FALSE; if(pinned_cert != NULL) { g_object_get( G_OBJECT(client), "remote-certificate", ¤t_cert, NULL ); cert_equal = inf_cert_util_compare_fingerprint( pinned_cert, inf_certificate_chain_get_own_certificate(current_cert), &conn_error ); inf_certificate_chain_unref(current_cert); } if(conn_error != NULL) { g_propagate_error(error, conn_error); conn_error = NULL; } else if(cert_equal == TRUE && desc->expect_pinned == FALSE) { g_set_error( error, inf_test_certificate_validate_error(), 4, "Certificate was pinned but not expected to" ); result = FALSE; } else if(pinned_cert == NULL && desc->expect_pinned == TRUE) { g_set_error( error, inf_test_certificate_validate_error(), 5, "Certificate was not pinned but expected to" ); result = FALSE; } g_hash_table_destroy(pinned); } } g_unlink(pinned_file); g_free(pinned_file); g_object_unref(xmpp_manager); g_object_unref(verify); g_object_unref(server); g_object_unref(client); return result; }
static void init_infinity (GeditCollaborationWindowHelper *helper) { InfGtkIo *io; InfCommunicationManager *communication_manager; InfXmppManager *xmpp_manager; InfCertificateCredentials *certificate_credentials; InfGtkBrowserModel *model_sort; io = inf_gtk_io_new (); communication_manager = inf_communication_manager_new (); xmpp_manager = inf_xmpp_manager_new (); certificate_credentials = inf_certificate_credentials_new (); helper->priv->io = INF_IO (io); helper->priv->certificate_credentials = certificate_credentials; helper->priv->browser_store = inf_gtk_browser_store_new (INF_IO (io), communication_manager); model_sort = INF_GTK_BROWSER_MODEL ( inf_gtk_browser_model_sort_new ( INF_GTK_BROWSER_MODEL (helper->priv->browser_store) ) ); gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (model_sort), compare_func, NULL, NULL); helper->priv->browser_view = inf_gtk_browser_view_new_with_model (model_sort); gtk_widget_show (helper->priv->browser_view); g_signal_connect_after (helper->priv->browser_store, "set-browser", G_CALLBACK (on_set_browser), helper); g_signal_connect (helper->priv->browser_view, "selection-changed", G_CALLBACK (on_selection_changed), helper); g_signal_connect (helper->priv->browser_view, "populate-popup", G_CALLBACK (on_populate_popup), helper); g_signal_connect (helper->priv->browser_view, "activate", G_CALLBACK (on_browser_activate), helper); #ifdef LIBINFINITY_HAVE_AVAHI init_infinity_discovery (helper, xmpp_manager); #endif init_bookmarks (helper); g_object_unref (communication_manager); g_object_unref (xmpp_manager); }
static void inf_tcp_connection_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) { InfTcpConnection* connection; InfTcpConnectionPrivate* priv; #ifndef G_OS_WIN32 const gchar* device_string; unsigned int new_index; #endif GError* error; connection = INF_TCP_CONNECTION(object); priv = INF_TCP_CONNECTION_PRIVATE(connection); switch(prop_id) { case PROP_IO: g_assert(priv->status == INF_TCP_CONNECTION_CLOSED); if(priv->io != NULL) g_object_unref(G_OBJECT(priv->io)); priv->io = INF_IO(g_value_dup_object(value)); break; case PROP_RESOLVER: g_assert(priv->status == INF_TCP_CONNECTION_CLOSED); inf_tcp_connection_set_resolver( connection, INF_NAME_RESOLVER(g_value_get_object(value)) ); break; case PROP_KEEPALIVE: error = NULL; inf_tcp_connection_set_keepalive( connection, (InfKeepalive*)g_value_get_boxed(value), &error ); if(error != NULL) { g_warning("Failed to set keepalive settings: %s\n", error->message); g_error_free(error); } break; case PROP_REMOTE_ADDRESS: g_assert(priv->status == INF_TCP_CONNECTION_CLOSED); if(priv->remote_address != NULL) inf_ip_address_free(priv->remote_address); priv->remote_address = (InfIpAddress*)g_value_dup_boxed(value); break; case PROP_REMOTE_PORT: g_assert(priv->status == INF_TCP_CONNECTION_CLOSED); priv->remote_port = g_value_get_uint(value); break; case PROP_DEVICE_INDEX: g_assert(priv->status == INF_TCP_CONNECTION_CLOSED); /* TODO: Verify that such a device exists */ priv->device_index = g_value_get_uint(value); g_object_notify(G_OBJECT(object), "device-name"); break; case PROP_DEVICE_NAME: #ifdef G_OS_WIN32 /* TODO: We can probably implement this using GetInterfaceInfo() */ g_warning("The device-name property is not implemented on Win32"); #else g_assert(priv->status == INF_TCP_CONNECTION_CLOSED); device_string = g_value_get_string(value); if(device_string == NULL) priv->device_index = 0; new_index = if_nametoindex(device_string); if(new_index == 0) { g_warning(_("Interface `%s' does not exist"), device_string); } else { priv->device_index = new_index; g_object_notify(G_OBJECT(object), "device-index"); } #endif break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
int main(int argc, char* argv[]) { InfTestBrowser test; InfIpAddress* address; InfCommunicationManager* manager; InfTcpConnection* tcp_conn; GError* error; gnutls_global_init(); g_type_init(); test.io = inf_standalone_io_new(); #ifndef G_OS_WIN32 test.input_fd = STDIN_FILENO; #endif address = inf_ip_address_new_loopback4(); error = NULL; tcp_conn = inf_tcp_connection_new_and_open(INF_IO(test.io), address, inf_protocol_get_default_port(), &error); inf_ip_address_free(address); if(tcp_conn == NULL) { fprintf(stderr, "Could not open TCP connection: %s\n", error->message); g_error_free(error); } else { test.conn = inf_xmpp_connection_new( tcp_conn, INF_XMPP_CONNECTION_CLIENT, NULL, "localhost", INF_XMPP_CONNECTION_SECURITY_BOTH_PREFER_TLS, NULL, NULL, NULL ); g_object_unref(G_OBJECT(tcp_conn)); manager = inf_communication_manager_new(); test.browser = INF_BROWSER( infc_browser_new( INF_IO(test.io), manager, INF_XML_CONNECTION(test.conn) ) ); g_signal_connect_after( G_OBJECT(test.browser), "notify::status", G_CALLBACK(inf_test_browser_notify_status_cb), &test ); g_signal_connect( G_OBJECT(test.browser), "error", G_CALLBACK(inf_test_browser_error_cb), &test ); inf_standalone_io_loop(test.io); g_object_unref(G_OBJECT(manager)); g_object_unref(G_OBJECT(test.browser)); /* TODO: Wait until the XMPP connection is in status closed */ g_object_unref(G_OBJECT(test.conn)); } g_object_unref(G_OBJECT(test.io)); return 0; }
static gboolean perform_test(guint max_total_log_size, InfTextChunk* initial, GSList* users, GSList* requests, GError** error) { InfTextBuffer* buffer; InfCommunicationManager* manager; InfIo* io; InfTextSession* session; InfAdoptedAlgorithm* algorithm; InfUserTable* user_table; InfTextUser* user; gchar* user_name; GSList* item; xmlNodePtr request; gboolean result; GError* local_error; guint verify_user_id; InfAdoptedUser* verify_user; guint verify_log_size; gint verify_can_undo; gint verify_can_redo; InfAdoptedRequestLog* log; guint log_size; buffer = INF_TEXT_BUFFER(inf_text_default_buffer_new("UTF-8")); inf_text_buffer_insert_chunk(buffer, 0, initial, NULL); manager = inf_communication_manager_new(); io = INF_IO(inf_standalone_io_new()); user_table = inf_user_table_new(); local_error = NULL; for(item = users; item != NULL; item = g_slist_next(item)) { user_name = g_strdup_printf("User_%u", GPOINTER_TO_UINT(item->data)); user = INF_TEXT_USER( g_object_new( INF_TEXT_TYPE_USER, "id", GPOINTER_TO_UINT(item->data), "name", user_name, "status", INF_USER_ACTIVE, "flags", 0, NULL ) ); g_free(user_name); inf_user_table_add_user(user_table, INF_USER(user)); g_object_unref(user); } session = INF_TEXT_SESSION( g_object_new( INF_TEXT_TYPE_SESSION, "communication-manager", manager, "buffer", buffer, "io", io, "user_table", user_table, "max-total-log-size", max_total_log_size, NULL ) ); algorithm = inf_adopted_session_get_algorithm(INF_ADOPTED_SESSION(session)); g_object_unref(io); g_object_unref(manager); g_object_unref(user_table); g_object_unref(buffer); for(item = requests; item != NULL; item = item->next) { request = (xmlNodePtr)item->data; if(strcmp((const char*)request->name, "request") == 0) { /* Request */ result = inf_communication_object_received( INF_COMMUNICATION_OBJECT(session), NULL, request, &local_error ); if(local_error != NULL) goto fail; } else { /* TODO: Make an extra function out of this: */ /* Verify */ result = inf_xml_util_get_attribute_uint_required( request, "user", &verify_user_id, &local_error ); if(result == FALSE) goto fail; verify_user = INF_ADOPTED_USER( inf_user_table_lookup_user_by_id(user_table, verify_user_id) ); if(verify_user == NULL) { g_set_error( error, inf_test_text_cleanup_error_quark(), INF_TEST_TEXT_CLEANUP_USER_UNAVAILABLE, "User ID '%u' not available", verify_user_id ); goto fail; } result = inf_xml_util_get_attribute_uint( request, "log-size", &verify_log_size, &local_error ); if(local_error) goto fail; if(result) { log = inf_adopted_user_get_request_log(INF_ADOPTED_USER(verify_user)); log_size = inf_adopted_request_log_get_end(log) - inf_adopted_request_log_get_begin(log); if(verify_log_size != log_size) { g_set_error( error, inf_test_text_cleanup_error_quark(), INF_TEST_TEXT_CLEANUP_VERIFY_FAILED, "Log size does not match; got %u, but expected %u", log_size, verify_log_size ); goto fail; } } result = inf_xml_util_get_attribute_int( request, "can-undo", &verify_can_undo, &local_error ); if(local_error) goto fail; if(result) { result = inf_adopted_algorithm_can_undo(algorithm, verify_user); if(result != verify_can_undo) { g_set_error( error, inf_test_text_cleanup_error_quark(), INF_TEST_TEXT_CLEANUP_VERIFY_FAILED, "can-undo does not match; got %d, but expected %d", (guint)result, verify_can_undo ); goto fail; } } result = inf_xml_util_get_attribute_int( request, "can-redo", &verify_can_redo, &local_error ); if(local_error) goto fail; if(result) { result = inf_adopted_algorithm_can_redo(algorithm, verify_user); if(result != verify_can_redo) { g_set_error( error, inf_test_text_cleanup_error_quark(), INF_TEST_TEXT_CLEANUP_VERIFY_FAILED, "can-redo does not match; got %d, but expected %d", (guint)result, verify_can_redo ); goto fail; } } } } g_object_unref(session); return TRUE; fail: g_object_unref(session); if(local_error) g_propagate_error(error, local_error); return FALSE; }
static gboolean test_fixline(const gchar* initial_buffer_content, const gchar* initial_base_content, guint n_lines, InfTestTextFixlineOperation operation, InfTestTextFixlineTarget target, guint pos, gchar* text, const gchar* final_buffer_content, const gchar* final_base_content) { InfStandaloneIo* io; InfTextBuffer* base; InfTextBuffer* buffer; /* Create the initial state */ io = inf_standalone_io_new(); base = INF_TEXT_BUFFER(inf_text_default_buffer_new("UTF-8")); inf_text_buffer_insert_text( base, 0, initial_buffer_content, strlen(initial_buffer_content), strlen(initial_buffer_content), 0 ); buffer = INF_TEXT_BUFFER( inf_text_fixline_buffer_new(INF_IO(io), base, n_lines) ); /* Check the initial state */ if(!check_buffer(base, initial_base_content, "Initial base")) { g_object_unref(io); g_object_unref(base); g_object_unref(buffer); return FALSE; } if(!check_buffer(buffer, initial_buffer_content, "Initial buf")) { g_object_unref(io); g_object_unref(base); g_object_unref(buffer); return FALSE; } /* Apply the operation */ switch(operation) { case OP_NONE: break; case OP_INS: if(target == TG_BASE) { inf_text_buffer_insert_text( base, pos, text, strlen(text), strlen(text), 0 ); } else if(target == TG_BUF) { inf_text_buffer_insert_text( buffer, pos, text, strlen(text), strlen(text), 0 ); } break; case OP_DEL: if(target == TG_BASE) inf_text_buffer_erase_text(base, pos, GPOINTER_TO_UINT(text), 0); else if(target == TG_BUF) inf_text_buffer_erase_text(buffer, pos, GPOINTER_TO_UINT(text), 0); break; default: g_assert_not_reached(); break; } /* Run any delayed action */ inf_standalone_io_iteration_timeout(io, 0); /* Check the final state */ if(!check_buffer(base, final_base_content, "Final base")) { g_object_unref(io); g_object_unref(base); g_object_unref(buffer); return FALSE; } if(!check_buffer(buffer, final_buffer_content, "Final buf")) { g_object_unref(io); g_object_unref(base); g_object_unref(buffer); return FALSE; } g_object_unref(io); g_object_unref(base); g_object_unref(buffer); return TRUE; }
xmlNodePtr request; gboolean result; InfTextChunk* test_chunk; gchar* first; gchar* second; gsize first_bytes; gsize second_bytes; GTimer* timer; buffer = INF_TEXT_BUFFER(inf_text_default_buffer_new("UTF-8")); inf_text_buffer_insert_chunk(buffer, 0, initial, NULL); manager = inf_communication_manager_new(); io = INF_IO(inf_standalone_io_new()); user_table = inf_user_table_new(); for(item = users; item != NULL; item = g_slist_next(item)) { user_name = g_strdup_printf("User_%u", GPOINTER_TO_UINT(item->data)); user = INF_TEXT_USER( g_object_new( INF_TEXT_TYPE_USER, "id", GPOINTER_TO_UINT(item->data), "name", user_name, "status", INF_USER_ACTIVE, "flags", 0, NULL )
int main(int argc, char* argv[]) { InfGtkIo* io; InfConnectionManager* connection_manager; #ifdef LIBINFINITY_HAVE_AVAHI InfXmppManager* xmpp_manager; InfDiscoveryAvahi* avahi; #endif InfGtkBrowserStore* store; GtkWidget* view; GtkWidget* scroll; GtkWidget* window; gtk_init(&argc, &argv); gnutls_global_init(); io = inf_gtk_io_new(); #ifdef LIBINFINITY_HAVE_AVAHI xmpp_manager = inf_xmpp_manager_new(); avahi = inf_discovery_avahi_new(INF_IO(io), xmpp_manager, NULL, NULL, NULL); g_object_unref(G_OBJECT(xmpp_manager)); #endif connection_manager = inf_connection_manager_new(); store = inf_gtk_browser_store_new(INF_IO(io), connection_manager, NULL); g_object_unref(G_OBJECT(connection_manager)); g_object_unref(G_OBJECT(io)); g_signal_connect( G_OBJECT(store), "set-browser", G_CALLBACK(on_set_browser), NULL ); #ifdef LIBINFINITY_HAVE_AVAHI inf_gtk_browser_store_add_discovery(store, INF_DISCOVERY(avahi)); g_object_unref(G_OBJECT(avahi)); #endif view = inf_gtk_browser_view_new_with_model(INF_GTK_BROWSER_MODEL(store)); g_object_unref(G_OBJECT(store)); gtk_widget_show(view); g_signal_connect( G_OBJECT(view), "activate", G_CALLBACK(on_activate), NULL ); scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN ); gtk_container_add(GTK_CONTAINER(scroll), view); gtk_widget_show(scroll); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window),"Infinote Browser"); gtk_window_set_default_size(GTK_WINDOW(window), 400, 400); gtk_window_set_icon_name(GTK_WINDOW(window), "infinote"); gtk_container_set_border_width(GTK_CONTAINER(window), 6); gtk_container_add(GTK_CONTAINER(window), scroll); gtk_widget_show(window); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(on_destroy), NULL); gtk_main(); return 0; }