Exemplo n.º 1
0
static gboolean
thrift_dispatch_processor_real_dispatch_call (ThriftDispatchProcessor *self,
                                              ThriftProtocol *in,
                                              ThriftProtocol *out,
                                              gchar *fname,
                                              gint32 seqid,
                                              GError **error)
{
  ThriftTransport *transport;
  ThriftApplicationException *xception;
  gchar *message;
  gint32 result;
  gboolean dispatch_result = FALSE;

  THRIFT_UNUSED_VAR (self);

  /* By default, return an application exception to the client indicating the
     method name is not recognized. */

  if ((thrift_protocol_skip (in, T_STRUCT, error) < 0) ||
      (thrift_protocol_read_message_end (in, error) < 0))
    return FALSE;

  g_object_get (in, "transport", &transport, NULL);
  result = thrift_transport_read_end (transport, error);
  g_object_unref (transport);
  if (result < 0)
    return FALSE;

  if (thrift_protocol_write_message_begin (out,
                                           fname,
                                           T_EXCEPTION,
                                           seqid,
                                           error) < 0)
    return FALSE;
  message = g_strconcat ("Invalid method name: '", fname, "'", NULL);
  xception =
    g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION,
                  "type",    THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN_METHOD,
                  "message", message,
                  NULL);
  g_free (message);
  result = thrift_struct_write (THRIFT_STRUCT (xception),
                                out,
                                error);
  g_object_unref (xception);
  if ((result < 0) ||
      (thrift_protocol_write_message_end (out, error) < 0))
    return FALSE;

  g_object_get (out, "transport", &transport, NULL);
  dispatch_result =
    ((thrift_transport_write_end (transport, error) >= 0) &&
     (thrift_transport_flush (transport, error) >= 0));
  g_object_unref (transport);

  return dispatch_result;
}
gboolean bucket_store_mapping_client_recv_get_mapping (BucketStoreMappingIf * iface, GHashTable ** _return, BucketStoreMappingException ** e, GError ** error)
{

    gint32 rseqid;
    gchar * fname;
    ThriftMessageType mtype;
    ThriftProtocol * protocol = BUCKET_STORE_MAPPING_CLIENT (iface)->input_protocol;

    if (thrift_protocol_read_message_begin (protocol, &fname, &mtype, &rseqid, error) < 0)
    {
        if (fname) g_free (fname);
        return FALSE;
    }

    if (mtype == T_EXCEPTION) {
        if (fname) g_free (fname);
        ThriftApplicationException *xception = g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION, NULL);
        thrift_struct_read (THRIFT_STRUCT (xception), protocol, NULL);
        thrift_protocol_read_message_end (protocol, NULL);
        thrift_transport_read_end (protocol->transport, NULL);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, xception->type, "application error: %s", xception->message);
        g_object_unref (xception);
        return FALSE;
    } else if (mtype != T_REPLY) {
        if (fname) g_free (fname);
        thrift_protocol_skip (protocol, T_STRUCT, NULL);
        thrift_protocol_read_message_end (protocol, NULL);
        thrift_transport_read_end (protocol->transport, NULL);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_MESSAGE_TYPE, "invalid message type %d, expected T_REPLY", mtype);
        return FALSE;
    } else if (strncmp (fname, "getMapping", 10) != 0) {
        thrift_protocol_skip (protocol, T_STRUCT, NULL);
        thrift_protocol_read_message_end (protocol, error);
        thrift_transport_read_end (protocol->transport, error);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_WRONG_METHOD_NAME, "wrong method name %s, expected getMapping", fname);
        if (fname) g_free (fname);
        return FALSE;
    }
    if (fname) g_free (fname);

    {
        gint32 ret;
        gint32 xfer = 0;
        gchar *name = NULL;
        ThriftType ftype;
        gint16 fid;
        guint32 len = 0;
        gpointer data = NULL;


        /* satisfy -Wall in case these aren't used */
        THRIFT_UNUSED_VAR (len);
        THRIFT_UNUSED_VAR (data);

        /* read the struct begin marker */
        if ((ret = thrift_protocol_read_struct_begin (protocol, &name, error)) < 0)
        {
            if (name) g_free (name);
            return 0;
        }
        xfer += ret;
        if (name) g_free (name);
        name = NULL;

        /* read the struct fields */
        while (1)
        {
            /* read the beginning of a field */
            if ((ret = thrift_protocol_read_field_begin (protocol, &name, &ftype, &fid, error)) < 0)
            {
                if (name) g_free (name);
                return 0;
            }
            xfer += ret;
            if (name) g_free (name);
            name = NULL;

            /* break if we get a STOP field */
            if (ftype == T_STOP)
            {
                break;
            }

            switch (fid)
            {
            case 0:
                if (ftype == T_MAP)
                {
                    {
                        guint32 size;
                        ThriftType key_type;
                        ThriftType value_type;

                        /* read the map begin marker */
                        if ((ret = thrift_protocol_read_map_begin (protocol, &key_type, &value_type, &size, error)) < 0)
                            return 0;
                        xfer += ret;

                        /* iterate through each of the map's fields */
                        guint32 i;
                        for (i = 0; i < size; i++)
                        {
                            gint32* key0 = g_new (gint32, 1);
                            HostPort * val1 = NULL;
                            if ((ret = thrift_protocol_read_i32 (protocol, &*key0, error)) < 0)
                                return 0;
                            xfer += ret;
                            if ( val1 != NULL)
                            {
                                g_object_unref (val1);
                            }
                            val1 = g_object_new (TYPE_HOST_PORT, NULL);
                            if ((ret = thrift_struct_read (THRIFT_STRUCT (val1), protocol, error)) < 0)
                            {
                                g_object_unref (val1);
                                return 0;
                            }
                            xfer += ret;
                            g_hash_table_insert ((GHashTable *)*_return, (gpointer) key0, (gpointer) val1);
                        }

                        /* read the map end marker */
                        if ((ret = thrift_protocol_read_map_end (protocol, error)) < 0)
                            return 0;
                        xfer += ret;
                    }
                } else {
                    if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
                        return 0;
                    xfer += ret;
                }
                break;
            case 1:
                if (ftype == T_STRUCT)
                {
                    /* This struct is an exception */
                    if ( *e != NULL)
                    {
                        g_object_unref (*e);
                    }
                    *e = g_object_new (TYPE_BUCKET_STORE_MAPPING_EXCEPTION, NULL);
                    if ((ret = thrift_struct_read (THRIFT_STRUCT (*e), protocol, error)) < 0)
                    {
                        g_object_unref (*e);
                        return 0;
                    }
                    xfer += ret;
                } else {
                    if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
                        return 0;
                    xfer += ret;
                }
                break;
            default:
                if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
                    return 0;
                xfer += ret;
                break;
            }
            if ((ret = thrift_protocol_read_field_end (protocol, error)) < 0)
                return 0;
            xfer += ret;
        }

        if ((ret = thrift_protocol_read_struct_end (protocol, error)) < 0)
            return 0;
        xfer += ret;

    }

    if (thrift_protocol_read_message_end (protocol, error) < 0)
        return FALSE;

    if (!thrift_transport_read_end (protocol->transport, error))
        return FALSE;

    if (*e != NULL)
    {
        g_set_error (error, BUCKET_STORE_MAPPING_EXCEPTION_ERROR, BUCKET_STORE_MAPPING_EXCEPTION_ERROR_CODE, "BucketStoreMappingException");
        return FALSE;
    }
    return TRUE;
}
Exemplo n.º 3
0
static void
thrift_server_primitives (const int port)
{
  ThriftServerTransport *transport = NULL;
  ThriftTransport *client = NULL;
  ThriftBinaryProtocol *tbp = NULL;
  ThriftProtocol *protocol = NULL;
  gboolean value_boolean = FALSE;
  gint8 value_byte = 0;
  gint16 value_16 = 0;
  gint32 value_32 = 0;
  gint64 value_64 = 0;
  gdouble value_double = 0;
  gchar *string = NULL;
  gpointer binary = NULL;
  guint32 len = 0;
  void *comparator = (void *) TEST_STRING;

  ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
                                              "port", port, NULL);
  transport = THRIFT_SERVER_TRANSPORT (tsocket);
  thrift_server_transport_listen (transport, NULL);
  client = thrift_server_transport_accept (transport, NULL);
  assert (client != NULL);

  tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
                      client, NULL);
  protocol = THRIFT_PROTOCOL (tbp);

  assert (thrift_binary_protocol_read_bool (protocol,
                                            &value_boolean, NULL) > 0);
  assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) > 0);
  assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) > 0);
  assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) > 0);
  assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) > 0);
  assert (thrift_binary_protocol_read_double (protocol,
                                              &value_double, NULL) > 0);
  assert (thrift_binary_protocol_read_string (protocol, &string, NULL) > 0);
  assert (thrift_binary_protocol_read_binary (protocol, &binary,
                                              &len, NULL) > 0);

  assert (value_boolean == TEST_BOOL);
  assert (value_byte = TEST_BYTE);
  assert (value_16 = TEST_I16);
  assert (value_32 = TEST_I32);
  assert (value_64 = TEST_I64);
  assert (value_double = TEST_DOUBLE);
  assert (strcmp (TEST_STRING, string) == 0);
  assert (memcmp (comparator, binary, len) == 0);

  g_free (string);
  g_free (binary);

  thrift_binary_protocol_read_binary (protocol, &binary, &len, NULL);
  g_free (binary);

  transport_read_count = 0;
  transport_read_error_at = 0;
  assert (thrift_binary_protocol_read_binary (protocol, &binary,
                                              &len, NULL) == -1);
  transport_read_error_at = -1;

  transport_read_count = 0;
  transport_read_error_at = 1;
  assert (thrift_binary_protocol_read_binary (protocol, &binary,
                                              &len, NULL) == -1);
  transport_read_error_at = -1;

  transport_read_error = 1;
  assert (thrift_binary_protocol_read_bool (protocol,
                                            &value_boolean, NULL) == -1);
  assert (thrift_binary_protocol_read_byte (protocol,
                                            &value_byte, NULL) == -1);
  assert (thrift_binary_protocol_read_i16 (protocol,
                                           &value_16, NULL) == -1);
  assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) == -1);
  assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) == -1);
  assert (thrift_binary_protocol_read_double (protocol,
                                              &value_double, NULL) == -1);
  transport_read_error = 0;

  /* test partial write failure */
  thrift_protocol_read_i32 (protocol, &value_32, NULL);

  thrift_transport_read_end (client, NULL);
  thrift_transport_close (client, NULL);

  g_object_unref (tbp);
  g_object_unref (client);
  g_object_unref (tsocket);
}
Exemplo n.º 4
0
/* test reading from the transport after the peer has unexpectedly
   closed the connection */
static void
test_read_after_peer_close(void)
{
  int status;
  pid_t pid;
  int port = 51199;
  GError *err = NULL;

  pid = fork ();
  g_assert (pid >= 0);

  if (pid == 0)
    {
      ThriftServerTransport *server_transport = NULL;
      ThriftTransport *client_transport = NULL;

      /* child listens */
      server_transport = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
				       "port", port,
				       NULL);
      g_assert (server_transport != NULL);

      thrift_server_transport_listen (server_transport, &err);
      g_assert (err == NULL);

      /* wrap the client transport in a ThriftFramedTransport */
      client_transport = g_object_new
	  (THRIFT_TYPE_FRAMED_TRANSPORT,
	   "transport",  thrift_server_transport_accept (server_transport, &err),
	   "r_buf_size", 0,
	   NULL);
      g_assert (err == NULL);
      g_assert (client_transport != NULL);

      /* close the connection immediately after the client connects */
      thrift_transport_close (client_transport, NULL);

      g_object_unref (client_transport);
      g_object_unref (server_transport);

      exit (0);
    } else {
	ThriftSocket *tsocket = NULL;
	ThriftTransport *transport = NULL;
	guchar buf[10]; /* a buffer */

	/* parent connects, wait a bit for the socket to be created */
	sleep (1);

	tsocket = g_object_new (THRIFT_TYPE_SOCKET,
				"hostname", "localhost",
				"port",     port,
				NULL);
	transport = g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT,
				  "transport",  THRIFT_TRANSPORT (tsocket),
				  "w_buf_size", 0,
				  NULL);

	g_assert (thrift_transport_open (transport, NULL) == TRUE);
	g_assert (thrift_transport_is_open (transport));

	/* attempting to read from the transport after the peer has closed
       the connection fails gracefully without generating a critical
       warning or segmentation fault */
	thrift_transport_read (transport, buf, 10, &err);
	g_assert (err != NULL);

	g_error_free (err);
	err = NULL;

	thrift_transport_read_end (transport, &err);
	g_assert (err == NULL);

	thrift_transport_close (transport, &err);
	g_assert (err == NULL);

	g_object_unref (transport);
	g_object_unref (tsocket);

	g_assert (wait (&status) == pid);
	g_assert (status == 0);
    }
}
Exemplo n.º 5
0
static gboolean
t_test_second_service_processor_process_secondtest_string (TTestSecondServiceProcessor *self,
        gint32 sequence_id,
        ThriftProtocol *input_protocol,
        ThriftProtocol *output_protocol,
        GError **error)
{
    gboolean result = TRUE;
    ThriftTransport * transport;
    TTestSecondServiceSecondtestStringArgs * args =
        g_object_new (T_TEST_TYPE_SECOND_SERVICE_SECONDTEST_STRING_ARGS, NULL);

    g_object_get (input_protocol, "transport", &transport, NULL);

    if ((thrift_struct_read (THRIFT_STRUCT (args), input_protocol, error) != -1) &&
            (thrift_protocol_read_message_end (input_protocol, error) != -1) &&
            (thrift_transport_read_end (transport, error) != FALSE))
    {
        gchar * thing;
        gchar * return_value;
        TTestSecondServiceSecondtestStringResult * result_struct;

        g_object_get (args,
                      "thing", &thing,
                      NULL);

        g_object_unref (transport);
        g_object_get (output_protocol, "transport", &transport, NULL);

        result_struct = g_object_new (T_TEST_TYPE_SECOND_SERVICE_SECONDTEST_STRING_RESULT, NULL);
        g_object_get (result_struct, "success", &return_value, NULL);

        if (t_test_second_service_handler_secondtest_string (T_TEST_SECOND_SERVICE_IF (self->handler),
                &return_value,
                thing,
                error) == TRUE)
        {
            g_object_set (result_struct, "success", return_value, NULL);
            if (return_value != NULL)
                g_free (return_value);

            result =
                ((thrift_protocol_write_message_begin (output_protocol,
                        "secondtestString",
                        T_REPLY,
                        sequence_id,
                        error) != -1) &&
                 (thrift_struct_write (THRIFT_STRUCT (result_struct),
                                       output_protocol,
                                       error) != -1));
        }
        else
        {
            if (*error == NULL)
                g_warning ("SecondService.secondtestString implementation returned FALSE "
                           "but did not set an error");

            ThriftApplicationException *xception =
                g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION,
                              "type",    *error != NULL ? (*error)->code :
                              THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN,
                              "message", *error != NULL ? (*error)->message : NULL,
                              NULL);
            g_clear_error (error);

            result =
                ((thrift_protocol_write_message_begin (output_protocol,
                        "secondtestString",
                        T_EXCEPTION,
                        sequence_id,
                        error) != -1) &&
                 (thrift_struct_write (THRIFT_STRUCT (xception),
                                       output_protocol,
                                       error) != -1));

            g_object_unref (xception);
        }

        if (thing != NULL)
            g_free (thing);
        g_object_unref (result_struct);

        if (result == TRUE)
            result =
                ((thrift_protocol_write_message_end (output_protocol, error) != -1) &&
                 (thrift_transport_write_end (transport, error) != FALSE) &&
                 (thrift_transport_flush (transport, error) != FALSE));
    }
    else
        result = FALSE;

    g_object_unref (transport);
    g_object_unref (args);

    return result;
}
Exemplo n.º 6
0
gboolean t_test_second_service_client_recv_secondtest_string (TTestSecondServiceIf * iface, gchar ** _return, GError ** error)
{

    gint32 rseqid;
    gchar * fname = NULL;
    ThriftMessageType mtype;
    ThriftProtocol * protocol = T_TEST_SECOND_SERVICE_CLIENT (iface)->input_protocol;

    if (thrift_protocol_read_message_begin (protocol, &fname, &mtype, &rseqid, error) < 0)
    {
        if (fname) g_free (fname);
        return FALSE;
    }

    if (mtype == T_EXCEPTION) {
        if (fname) g_free (fname);
        ThriftApplicationException *xception = g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION, NULL);
        thrift_struct_read (THRIFT_STRUCT (xception), protocol, NULL);
        thrift_protocol_read_message_end (protocol, NULL);
        thrift_transport_read_end (protocol->transport, NULL);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, xception->type, "application error: %s", xception->message);
        g_object_unref (xception);
        return FALSE;
    } else if (mtype != T_REPLY) {
        if (fname) g_free (fname);
        thrift_protocol_skip (protocol, T_STRUCT, NULL);
        thrift_protocol_read_message_end (protocol, NULL);
        thrift_transport_read_end (protocol->transport, NULL);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_MESSAGE_TYPE, "invalid message type %d, expected T_REPLY", mtype);
        return FALSE;
    } else if (strncmp (fname, "secondtestString", 16) != 0) {
        thrift_protocol_skip (protocol, T_STRUCT, NULL);
        thrift_protocol_read_message_end (protocol, error);
        thrift_transport_read_end (protocol->transport, error);
        g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_WRONG_METHOD_NAME, "wrong method name %s, expected secondtestString", fname);
        if (fname) g_free (fname);
        return FALSE;
    }
    if (fname) g_free (fname);

    {
        gint32 ret;
        gint32 xfer = 0;
        gchar *name = NULL;
        ThriftType ftype;
        gint16 fid;
        guint32 len = 0;
        gpointer data = NULL;


        /* satisfy -Wall in case these aren't used */
        THRIFT_UNUSED_VAR (len);
        THRIFT_UNUSED_VAR (data);

        /* read the struct begin marker */
        if ((ret = thrift_protocol_read_struct_begin (protocol, &name, error)) < 0)
        {
            if (name) g_free (name);
            return 0;
        }
        xfer += ret;
        if (name) g_free (name);
        name = NULL;

        /* read the struct fields */
        while (1)
        {
            /* read the beginning of a field */
            if ((ret = thrift_protocol_read_field_begin (protocol, &name, &ftype, &fid, error)) < 0)
            {
                if (name) g_free (name);
                return 0;
            }
            xfer += ret;
            if (name) g_free (name);
            name = NULL;

            /* break if we get a STOP field */
            if (ftype == T_STOP)
            {
                break;
            }

            switch (fid)
            {
            case 0:
                if (ftype == T_STRING)
                {
                    if (*_return != NULL)
                    {
                        g_free(*_return);
                        *_return = NULL;
                    }

                    if ((ret = thrift_protocol_read_string (protocol, &*_return, error)) < 0)
                        return 0;
                    xfer += ret;
                } else {
                    if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
                        return 0;
                    xfer += ret;
                }
                break;
            default:
                if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
                    return 0;
                xfer += ret;
                break;
            }
            if ((ret = thrift_protocol_read_field_end (protocol, error)) < 0)
                return 0;
            xfer += ret;
        }

        if ((ret = thrift_protocol_read_struct_end (protocol, error)) < 0)
            return 0;
        xfer += ret;

    }

    if (thrift_protocol_read_message_end (protocol, error) < 0)
        return FALSE;

    if (!thrift_transport_read_end (protocol->transport, error))
        return FALSE;

    return TRUE;
}
Exemplo n.º 7
0
static gboolean
calculator_processor_process_calculate (CalculatorProcessor *self,
                                        gint32 sequence_id,
                                        ThriftProtocol *input_protocol,
                                        ThriftProtocol *output_protocol,
                                        GError **error)
{
  gboolean result = TRUE;
  ThriftTransport * transport;
  ThriftApplicationException *xception;
  CalculatorCalculateArgs * args =
    g_object_new (TYPE_CALCULATOR_CALCULATE_ARGS, NULL);

  g_object_get (input_protocol, "transport", &transport, NULL);

  if ((thrift_struct_read (THRIFT_STRUCT (args), input_protocol, error) != -1) &&
      (thrift_protocol_read_message_end (input_protocol, error) != -1) &&
      (thrift_transport_read_end (transport, error) != FALSE))
  {
    gint logid;
    Work * w;
    InvalidOperation * ouch = NULL;
    gint return_value;
    CalculatorCalculateResult * result_struct;

    g_object_get (args,
                  "logid", &logid,
                  "w", &w,
                  NULL);

    g_object_unref (transport);
    g_object_get (output_protocol, "transport", &transport, NULL);

    result_struct = g_object_new (TYPE_CALCULATOR_CALCULATE_RESULT, NULL);
    g_object_get (result_struct, "success", &return_value, NULL);

    if (calculator_handler_calculate (CALCULATOR_IF (self->handler),
                                      (gint32 *)&return_value,
                                      logid,
                                      w,
                                      &ouch,
                                      error) == TRUE)
    {
      g_object_set (result_struct, "success", return_value, NULL);

      result =
        ((thrift_protocol_write_message_begin (output_protocol,
                                               "calculate",
                                               T_REPLY,
                                               sequence_id,
                                               error) != -1) &&
         (thrift_struct_write (THRIFT_STRUCT (result_struct),
                               output_protocol,
                               error) != -1));
    }
    else
    {
      if (ouch != NULL)
      {
        g_object_set (result_struct,
                      "ouch", ouch,
                      NULL);

        result =
          ((thrift_protocol_write_message_begin (output_protocol,
                                                 "calculate",
                                                 T_REPLY,
                                                 sequence_id,
                                                 error) != -1) &&
           (thrift_struct_write (THRIFT_STRUCT (result_struct),
                                 output_protocol,
                                 error) != -1));
      }
      else
      {
        if (*error == NULL)
          g_warning ("Calculator.calculate implementation returned FALSE "
                     "but did not set an error");

        xception =
          g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION,
                        "type",    *error != NULL ? (*error)->code :
                                   THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN,
                        "message", *error != NULL ? (*error)->message : NULL,
                        NULL);
        g_clear_error (error);

        result =
          ((thrift_protocol_write_message_begin (output_protocol,
                                                 "calculate",
                                                 T_EXCEPTION,
                                                 sequence_id,
                                                 error) != -1) &&
           (thrift_struct_write (THRIFT_STRUCT (xception),
                                 output_protocol,
                                 error) != -1));

        g_object_unref (xception);
      }
    }

    if (w != NULL)
      g_object_unref (w);
    g_object_unref (result_struct);

    if (result == TRUE)
      result =
        ((thrift_protocol_write_message_end (output_protocol, error) != -1) &&
         (thrift_transport_write_end (transport, error) != FALSE) &&
         (thrift_transport_flush (transport, error) != FALSE));
  }
  else
    result = FALSE;

  g_object_unref (transport);
  g_object_unref (args);

  return result;
}
Exemplo n.º 8
0
static gboolean
calculator_processor_process_ping (CalculatorProcessor *self,
                                   gint32 sequence_id,
                                   ThriftProtocol *input_protocol,
                                   ThriftProtocol *output_protocol,
                                   GError **error)
{
  gboolean result = TRUE;
  ThriftTransport * transport;
  ThriftApplicationException *xception;
  CalculatorPingArgs * args =
    g_object_new (TYPE_CALCULATOR_PING_ARGS, NULL);

  g_object_get (input_protocol, "transport", &transport, NULL);

  if ((thrift_struct_read (THRIFT_STRUCT (args), input_protocol, error) != -1) &&
      (thrift_protocol_read_message_end (input_protocol, error) != -1) &&
      (thrift_transport_read_end (transport, error) != FALSE))
  {
    CalculatorPingResult * result_struct;

    g_object_unref (transport);
    g_object_get (output_protocol, "transport", &transport, NULL);

    result_struct = g_object_new (TYPE_CALCULATOR_PING_RESULT, NULL);

    if (calculator_handler_ping (CALCULATOR_IF (self->handler),
                                 error) == TRUE)
    {
      result =
        ((thrift_protocol_write_message_begin (output_protocol,
                                               "ping",
                                               T_REPLY,
                                               sequence_id,
                                               error) != -1) &&
         (thrift_struct_write (THRIFT_STRUCT (result_struct),
                               output_protocol,
                               error) != -1));
    }
    else
    {
      if (*error == NULL)
        g_warning ("Calculator.ping implementation returned FALSE "
                   "but did not set an error");

      xception =
        g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION,
                      "type",    *error != NULL ? (*error)->code :
                                 THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN,
                      "message", *error != NULL ? (*error)->message : NULL,
                      NULL);
      g_clear_error (error);

      result =
        ((thrift_protocol_write_message_begin (output_protocol,
                                               "ping",
                                               T_EXCEPTION,
                                               sequence_id,
                                               error) != -1) &&
         (thrift_struct_write (THRIFT_STRUCT (xception),
                               output_protocol,
                               error) != -1));

      g_object_unref (xception);
    }

    g_object_unref (result_struct);

    if (result == TRUE)
      result =
        ((thrift_protocol_write_message_end (output_protocol, error) != -1) &&
         (thrift_transport_write_end (transport, error) != FALSE) &&
         (thrift_transport_flush (transport, error) != FALSE));
  }
  else
    result = FALSE;

  g_object_unref (transport);
  g_object_unref (args);

  return result;
}
Exemplo n.º 9
0
gboolean calculator_client_recv_calculate (CalculatorIf * iface, gint32* _return, InvalidOperation ** ouch, GError ** error)
{
  gint32 rseqid;
  gchar * fname = NULL;
  ThriftMessageType mtype;
  ThriftProtocol * protocol = SHARED_SERVICE_CLIENT (iface)->input_protocol;
  ThriftApplicationException *xception;

  if (thrift_protocol_read_message_begin (protocol, &fname, &mtype, &rseqid, error) < 0) {
    if (fname) g_free (fname);
    return FALSE;
  }

  if (mtype == T_EXCEPTION) {
    if (fname) g_free (fname);
    xception = g_object_new (THRIFT_TYPE_APPLICATION_EXCEPTION, NULL);
    thrift_struct_read (THRIFT_STRUCT (xception), protocol, NULL);
    thrift_protocol_read_message_end (protocol, NULL);
    thrift_transport_read_end (protocol->transport, NULL);
    g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR,xception->type, "application error: %s", xception->message);
    g_object_unref (xception);
    return FALSE;
  } else if (mtype != T_REPLY) {
    if (fname) g_free (fname);
    thrift_protocol_skip (protocol, T_STRUCT, NULL);
    thrift_protocol_read_message_end (protocol, NULL);
    thrift_transport_read_end (protocol->transport, NULL);
    g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_MESSAGE_TYPE, "invalid message type %d, expected T_REPLY", mtype);
    return FALSE;
  } else if (strncmp (fname, "calculate", 9) != 0) {
    thrift_protocol_skip (protocol, T_STRUCT, NULL);
    thrift_protocol_read_message_end (protocol,error);
    thrift_transport_read_end (protocol->transport, error);
    g_set_error (error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_WRONG_METHOD_NAME, "wrong method name %s, expected calculate", fname);
    if (fname) g_free (fname);
    return FALSE;
  }
  if (fname) g_free (fname);

  {
    gint32 ret;
    gint32 xfer = 0;
    gchar *name = NULL;
    ThriftType ftype;
    gint16 fid;
    guint32 len = 0;
    gpointer data = NULL;
    

    /* satisfy -Wall in case these aren't used */
    THRIFT_UNUSED_VAR (len);
    THRIFT_UNUSED_VAR (data);

    /* read the struct begin marker */
    if ((ret = thrift_protocol_read_struct_begin (protocol, &name, error)) < 0)
    {
      if (name) g_free (name);
      return 0;
    }
    xfer += ret;
    if (name) g_free (name);
    name = NULL;

    /* read the struct fields */
    while (1)
    {
      /* read the beginning of a field */
      if ((ret = thrift_protocol_read_field_begin (protocol, &name, &ftype, &fid, error)) < 0)
      {
        if (name) g_free (name);
        return 0;
      }
      xfer += ret;
      if (name) g_free (name);
      name = NULL;

      /* break if we get a STOP field */
      if (ftype == T_STOP)
      {
        break;
      }

      switch (fid)
      {
        case 0:
          if (ftype == T_I32)
          {
            if ((ret = thrift_protocol_read_i32 (protocol, &*_return, error)) < 0)
              return 0;
            xfer += ret;
          } else {
            if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
              return 0;
            xfer += ret;
          }
          break;
        case 1:
          if (ftype == T_STRUCT)
          {
            /* This struct is an exception */
            if ( *ouch != NULL)
            {
              g_object_unref (*ouch);
            }
            *ouch = g_object_new (TYPE_INVALID_OPERATION, NULL);
            if ((ret = thrift_struct_read (THRIFT_STRUCT (*ouch), protocol, error)) < 0)
            {
              g_object_unref (*ouch);
              *ouch = NULL;
              return 0;
            }
            xfer += ret;
          } else {
            if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
              return 0;
            xfer += ret;
          }
          break;
        default:
          if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
            return 0;
          xfer += ret;
          break;
      }
      if ((ret = thrift_protocol_read_field_end (protocol, error)) < 0)
        return 0;
      xfer += ret;
    }

    if ((ret = thrift_protocol_read_struct_end (protocol, error)) < 0)
      return 0;
    xfer += ret;

  }

  if (thrift_protocol_read_message_end (protocol, error) < 0)
    return FALSE;

  if (!thrift_transport_read_end (protocol->transport, error))
    return FALSE;

  if (*ouch != NULL)
  {
      g_set_error (error, INVALID_OPERATION_ERROR, INVALID_OPERATION_ERROR_CODE, "InvalidOperation");
      return FALSE;
  }
  return TRUE;
}