return 0;
}
+int
+rxpd_file_save (struct rxpd_file* self)
+{
+ FILE* f = fopen (self->filename, "w");
+ // TODO error handling
+ if (f)
+ {
+ LLIST_FOREACH (&self->rules, n)
+ {
+ struct rxpd_rule* node = (struct rxpd_rule*)n;
+ fprintf (f, "%s\n", node->string);
+ }
+
+ fclose (f);
+ return 1;
+ }
+ else
+ return 0;
+}
+
int
rxpd_file_cmp (const void* A, const void* B)
{
rxpd_connection_cmd_SAVE (int fd, short event, void* ptr)
{
struct rxpd_connection* self = (struct rxpd_connection*) ptr;
- rxpd_buffer_printf (&self->out, "#ERROR: unimplemented command %s\n", &__func__[20]);
+
+ if (!event)
+ {
+ if (self->file)
+ {
+ if (rxpd_file_save (self->file))
+ {
+ rxpd_buffer_printf (&self->out, "#OK:\n");
+ }
+ else
+ {
+ rxpd_buffer_printf (&self->out, "#ERROR: saving file '%s'\n", (const char*)self->file->node.key);
+ }
+ }
+ else
+ rxpd_buffer_printf (&self->out, "#ERROR: no such file\n");
+ close (fd);
+ }
}
void
int
rxpd_file_load (struct rxpd_file* self);
+int
+rxpd_file_save (struct rxpd_file* self);
+
int
rxpd_file_cmp (const void* A, const void* B);