Skip to content
pi-c Documentation
Login

Documentation

/* The one way pic reaches a Fossil peer: a libfossil sync channel
 * (fsl_sc_stream_init) over pic's own TCP and TLS (net.c, BearSSL), so
 * libfossil does the HTTP and the sync protocol and pic owns the bytes.
 * https:// and http:// (loopback only, as net.c allows) are served;
 * zit: is not yet. */
#ifndef PIC_XFER_H
#define PIC_XFER_H

#include <stddef.h>

#include "libfossil.h"

/* A byte stream, one per round trip: net.c's unless a test supplies one.
 * read returns > 0 bytes, 0 at a clean end, PIC_STREAM_UNCLEAN when the
 * peer closed without ending TLS, or -1 on error (error() says why). */
#define PIC_STREAM_UNCLEAN (-3)
typedef struct pic_stream {
    int (*connect)(void *state, const char *host, int port, int tls, int idle_seconds);
    long (*read)(void *state, void *buf, size_t cap);
    int (*write)(void *state, const void *buf, size_t len);
    void (*close)(void *state);
    const char *(*error)(void *state);
    void *state;
} pic_stream;

typedef struct pic_xfer pic_xfer;

/* Points cfg (fsl_xfer_config_empty, owned and cleaned up by the caller)
 * at URL through a channel of pic's, ready for fsl_sync_client: its url,
 * its channel, and no password saved or looked up in the repository
 * (Fossil's last-sync-pw is never written). stream NULL is net.c. *out
 * must outlive the transfers and is freed with pic_xfer_close. 0, or -1
 * with err (an unknown scheme, zit:, no trust anchors). */
int pic_xfer_open(const char *url, const pic_stream *stream, fsl_xfer_config *cfg, pic_xfer **out, char *err,
                  size_t errcap);
void pic_xfer_close(pic_xfer *x);

#endif