static void gspeechd_client_read_speak_data_cb (GInputStream *stream, GAsyncResult *res, gpointer user_data) { GSpeechdClient *client = user_data; gchar *s, *response; gsize len; SsipStatus status; gboolean ret; GError *error = NULL; s = g_data_input_stream_read_line_finish (G_DATA_INPUT_STREAM(stream), res, &len, &error); g_printf ("--->%s\n",s); #define END_SPEAK_DATA_STR ".\xD" #define END_SPEAK_DATA_RESPONSE "225-1\r\n" if (g_strcmp0 (s, END_SPEAK_DATA_STR) != 0) { g_data_input_stream_read_line_async(client->input, G_PRIORITY_DEFAULT, client->cancellable, (GAsyncReadyCallback)gspeechd_client_read_speak_data_cb, gspeechd_client_ref (client)); return; } ret = g_data_output_stream_put_string (client->output, END_SPEAK_DATA_RESPONSE, client->cancellable, NULL); g_printf ("%d %s\n", ret, END_SPEAK_DATA_RESPONSE); status = OK_MESSAGE_QUEUED; response = ssip_response (status); ret = g_data_output_stream_put_string (client->output, response, client->cancellable, NULL); g_printf ("%d %s\n", ret, response); /* parse commands again */ g_data_input_stream_read_line_async(client->input, G_PRIORITY_DEFAULT, client->cancellable, (GAsyncReadyCallback)gspeechd_client_read_line_cb, gspeechd_client_ref (client)); }
void ControllerLIRC::line_read( GObject * stream , GAsyncResult * result ) { GError * error = 0; char * line = g_data_input_stream_read_line_finish( G_DATA_INPUT_STREAM( stream ) , result , NULL , & error ); if ( error ) { tplog( "READ ERROR : %s" , error->message ); g_clear_error( & error ); g_object_unref( connection ); connection = 0; return; } if ( line ) { // Split it into 4 pieces gchar * * parts = g_strsplit( line , " " , 4 ); if ( g_strv_length( parts ) >= 3 ) { KeyMap::const_iterator it = key_map.find( parts[ 2 ] ); if ( it != key_map.end() ) { if ( g_timer_elapsed( timer , NULL ) >= repeat ) { tp_controller_key_down( controller , it->second , 0 , TP_CONTROLLER_MODIFIER_NONE ); tp_controller_key_up( controller , it->second , 0 , TP_CONTROLLER_MODIFIER_NONE ); g_timer_start( timer ); } } } g_strfreev(parts); g_free( line ); } g_data_input_stream_read_line_async( G_DATA_INPUT_STREAM( stream ) , 0 , NULL , line_read , this ); }
static void _j4status_io_stream_read_callback(GObject *stream, GAsyncResult *res, gpointer user_data) { J4statusIOStream *self = user_data; GError *error = NULL; gchar *line; line = g_data_input_stream_read_line_finish(self->in, res, NULL, &error); if ( line == NULL ) { if ( error != NULL ) { g_warning("Input error: %s", error->message); g_clear_error(&error); } _j4status_io_stream_reconnect_maybe(self); return; } j4status_core_action(self->io->core, line); g_free(line); g_data_input_stream_read_line_async(self->in, G_PRIORITY_DEFAULT, NULL, _j4status_io_stream_read_callback, self); }
static void stdin_read_complete(GObject *src, GAsyncResult *res, gpointer data) { char *s, *ep; GError *err = NULL; gsize len; s = g_data_input_stream_read_line_finish(G_DATA_INPUT_STREAM(src), res, &len, &err); if (!s) { if (err) { FATAL_ERROR("Reading from stdin: %s\n", err->message); g_error_free(err); return; } switch (state) { case STATE_WAITING_FOR_BUS_N_DEV: FATAL_ERROR("EOF while waiting for bus and device num\n"); break; case STATE_WAITING_FOR_POL_KIT: ERROR("Cancelled while waiting for authorization\n"); break; case STATE_WAITING_FOR_STDIN_EOF: cleanup(); break; } return; } switch (state) { case STATE_WAITING_FOR_BUS_N_DEV: busnum = strtol(s, &ep, 10); if (!isspace(*ep)) { FATAL_ERROR("Invalid busnum / devnum: %s\n", s); break; } devnum = strtol(ep, &ep, 10); if (*ep != '\0') { FATAL_ERROR("Invalid busnum / devnum: %s\n", s); break; } /* * The set_facl() call is a no-op for root, so no need to ask PolKit * and then if ok call set_facl(), when called by a root process. */ if (getuid() != 0) { polkit_cancellable = g_cancellable_new(); polkit_authority_check_authorization( authority, subject, "org.spice-space.lowlevelusbaccess", NULL, POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, polkit_cancellable, (GAsyncReadyCallback)check_authorization_cb, NULL); state = STATE_WAITING_FOR_POL_KIT; } else { fprintf(stdout, "SUCCESS\n"); fflush(stdout); state = STATE_WAITING_FOR_STDIN_EOF; } g_data_input_stream_read_line_async(stdin_stream, G_PRIORITY_DEFAULT, NULL, stdin_read_complete, NULL); break; default: FATAL_ERROR("Unexpected extra input in state %u: %s\n", state, s); } g_free(s); }
static void gspeechd_client_read_line_cb (GInputStream *stream, GAsyncResult *res, gpointer user_data) { GSpeechdClient *client = user_data; gchar *s, *response; gsize len; gboolean ret; GError *error = NULL; SsipCommand *cmd; SsipStatus status; /* read lines and removes newline */ s = g_data_input_stream_read_line_finish (G_DATA_INPUT_STREAM(stream), res, &len, &error); if (error != NULL ) { g_printf ("-->%s\n", error->message); g_error_free (error); return; } if (s == NULL) { /* client has closed a connection */ g_printf ("-->connection closed\n"); return; } g_printf ("-->%s\n", s); /* parse SSIP command */ cmd = ssip_command_new (s); /* TODO remove history */ client->history = g_list_append (client->history, s); /* process command */ switch (ssip_cmd_get (cmd)) { case SSIP_CMD_SET: switch (ssip_set_param_get (cmd)) { case SSIP_SET_PARAM_CLIENT_NAME: /* TODO free previous name before */ client->name = g_strdup (ssip_set_param_value_get (cmd)); /* TODO emit event to the server */ status = OK_CLIENT_NAME_SET; break; case SSIP_SET_PARAM_PRIORITY: status = OK_PRIORITY_SET; break; default: break; } break; case SSIP_CMD_SPEAK: status = OK_RECEIVE_DATA; response = ssip_response (status); ret = g_data_output_stream_put_string (client->output, response, client->cancellable, NULL); g_printf ("%d %s\n", ret, response); g_data_input_stream_read_line_async(client->input, G_PRIORITY_DEFAULT, client->cancellable, (GAsyncReadyCallback)gspeechd_client_read_speak_data_cb, gspeechd_client_ref (client)); return; case SSIP_CMD_HELP: default: break; } response = ssip_response (status); ret = g_data_output_stream_put_string (client->output, response, client->cancellable, NULL); g_printf ("%d %s\n", ret, response); /* when QUIT received, send an event connection_closed */ g_data_input_stream_read_line_async(client->input, G_PRIORITY_DEFAULT, client->cancellable, (GAsyncReadyCallback)gspeechd_client_read_line_cb, gspeechd_client_ref (client)); }
static void identd_read_ready (GDataInputStream *in_stream, GAsyncResult *res, ident_info *info) { GSocketAddress *sok_addr; GOutputStream *out_stream; guint64 local, remote; gchar *read_buf, buf[512], *p; if ((read_buf = g_data_input_stream_read_line_finish (in_stream, res, NULL, NULL))) { local = g_ascii_strtoull (read_buf, NULL, 0); p = strchr (read_buf, ','); if (!p) { g_free (read_buf); goto cleanup; } remote = g_ascii_strtoull (p + 1, NULL, 0); g_free (read_buf); g_snprintf (buf, sizeof (buf), "%"G_GUINT16_FORMAT", %"G_GUINT16_FORMAT" : ", (guint16)MIN(local, G_MAXUINT16), (guint16)MIN(remote, G_MAXUINT16)); if (!local || !remote || local > G_MAXUINT16 || remote > G_MAXUINT16) { g_strlcat (buf, "ERROR : INVALID-PORT\r\n", sizeof (buf)); g_debug ("Identd: Received invalid port"); } else { info->username = g_hash_table_lookup (responses, GINT_TO_POINTER (local)); if (!info->username) { g_strlcat (buf, "ERROR : NO-USER\r\n", sizeof (buf)); g_debug ("Identd: Received invalid local port"); } else { const gsize len = strlen (buf); g_hash_table_steal (responses, GINT_TO_POINTER (local)); g_snprintf (buf + len, sizeof (buf) - len, "USERID : UNIX : %s\r\n", info->username); if ((sok_addr = g_socket_connection_get_remote_address (info->conn, NULL))) { GInetAddress *inet_addr; gchar *addr; inet_addr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (sok_addr)); addr = g_inet_address_to_string (inet_addr); hexchat_printf (ph, _("*\tServicing ident request from %s as %s"), addr, info->username); g_object_unref (sok_addr); g_object_unref (inet_addr); g_free (addr); } } } out_stream = g_io_stream_get_output_stream (G_IO_STREAM (info->conn)); g_output_stream_write_async (out_stream, buf, strlen (buf), G_PRIORITY_DEFAULT, NULL, (GAsyncReadyCallback)identd_write_ready, info); } return; cleanup: ident_info_free (info); }