remove empty directories from new melted project
[melted] / src / miracle / miracle_connection.c
index 6bf496c..7f287e3 100644 (file)
@@ -129,12 +129,14 @@ static int connection_send( int fd, valerie_response response )
                }
 
                if ( ( code == 201 || code == 500 ) && strcmp( valerie_response_get_line( response, items - 1 ), "" ) )
-                       write( fd, "\r\n", 2 );
+                       if ( write( fd, "\r\n", 2 ) != 2 )
+                               miracle_log( LOG_ERR, "write(\"\\r\\n\") failed!" );
        }
        else
        {
-               char *message = "500 Empty Response\r\n\r\n";
-               write( fd, message, strlen( message ) );
+               const char *message = "500 Empty Response\r\n\r\n";
+               if ( write( fd, message, strlen( message ) ) != strlen( message ))
+                       miracle_log( LOG_ERR, "write(%s) failed!", message );
        }
 
        return error;
@@ -201,6 +203,7 @@ void *parser_thread( void *arg )
 {
        struct hostent *he;
        connection_t *connection = arg;
+       mlt_properties owner = connection->owner;
        char address[ 512 ];
        char command[ 1024 ];
        int fd = connection->fd;
@@ -223,6 +226,8 @@ void *parser_thread( void *arg )
 
                while( !error && connection_read( fd, command, 1024 ) )
                {
+                       response = NULL;
+
                        if ( !strncmp( command, "PUSH ", 5 ) )
                        {
                                char temp[ 20 ];
@@ -244,8 +249,19 @@ void *parser_thread( void *arg )
                                }
                                buffer[ bytes ] = '\0';
                                if ( bytes > 0 && total == bytes )
-                                       service = ( mlt_service )mlt_factory_producer( "westley-xml", buffer );
-                               response = valerie_parser_push( parser, command, service );
+                               {
+                                       if ( mlt_properties_get( owner, "push-parser-off" ) == 0 )
+                                       {
+                                               service = ( mlt_service )mlt_factory_producer( NULL, "westley-xml", buffer );
+                                               mlt_events_fire( owner, "push-received", &response, command, service, NULL );
+                                               if ( response == NULL )
+                                                       response = valerie_parser_push( parser, command, service );
+                                       }
+                                       else
+                                       {
+                                               response = valerie_parser_received( parser, command, buffer );
+                                       }
+                               }
                                error = connection_send( fd, response );
                                valerie_response_close( response );
                                mlt_service_close( service );
@@ -253,7 +269,9 @@ void *parser_thread( void *arg )
                        }
                        else if ( strncmp( command, "STATUS", 6 ) )
                        {
-                               response = valerie_parser_execute( parser, command );
+                               mlt_events_fire( owner, "command-received", &response, command, NULL );
+                               if ( response == NULL )
+                                       response = valerie_parser_execute( parser, command );
                                miracle_log( LOG_INFO, "%s \"%s\" %d", address, command, valerie_response_get_error_code( response ) );
                                error = connection_send( fd, response );
                                valerie_response_close( response );