#include <pakfire/client.h>
#include <pakfire/ctx.h>
#include <pakfire/builder.h>
+#include <pakfire/json.h>
#include <pakfire/util.h>
#include <pakfire/xfer.h>
return 0;
}
+
+int pakfire_builder_send_message(struct pakfire_builder* self, struct json_object* message) {
+ const char* m = NULL;
+ size_t length = 0;
+ int r;
+
+ // Return an error if we are not connected
+ if (!self->control)
+ return -ENOTCONN;
+
+ // Serialize to string
+ m = pakfire_json_to_string(message, &length);
+ if (!m) {
+ ERROR(self->ctx, "Failed to serialize message: %m\n");
+ return -errno;
+ }
+
+ // Send the message
+ r = pakfire_xfer_send_message(self->control, m, length);
+ if (r < 0) {
+ switch (-r) {
+ case EAGAIN:
+ break;
+
+ default:
+ ERROR(self->ctx, "Failed to send message: %s\n", strerror(-r));
+ return r;
+ }
+ }
+
+ return 0;
+}
int pakfire_builder_connected(struct pakfire_xfer* xfer, void* data);
int pakfire_builder_close(struct pakfire_xfer* xfer, int code, void* data);
+int pakfire_builder_send_message(struct pakfire_builder* self, struct json_object* message);
+
#endif /* PAKFIRE_BUILDER_H */
return 0;
}
-
-int pakfire_daemon_send_message(struct pakfire_daemon* self, struct json_object* message) {
- const char* m = NULL;
- size_t length = 0;
- int r;
-
-#if 0
- // Return an error if we are not connected
- if (!self->control)
- return -ENOTCONN;
-#endif
-
- // Serialize to string
- m = json_object_to_json_string_length(message,
- JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY, &length);
- if (!m) {
- ERROR(self->ctx, "Failed to serialize message: %m\n");
- return -errno;
- }
-
-#if 0
- // Send the message
- r = pakfire_xfer_send_message(self->control, m, length);
- if (r < 0) {
- switch (-r) {
- case EAGAIN:
- break;
-
- default:
- ERROR(self->ctx, "Failed to send message: %s\n", strerror(-r));
- return r;
- }
- }
-#endif
-
- return 0;
-}