pkt.h 1.77 KB
Newer Older
1
/*
schu committed
2
 * Copyright (C) 2009-2012 the libgit2 contributors
3
 *
Vicent Marti committed
4 5
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
6 7
 */

Vicent Marti committed
8 9 10 11
#ifndef INCLUDE_pkt_h__
#define INCLUDE_pkt_h__

#include "common.h"
12
#include "transport.h"
13
#include "buffer.h"
14
#include "posix.h"
15 16 17 18 19
#include "git2/net.h"

enum git_pkt_type {
	GIT_PKT_CMD,
	GIT_PKT_FLUSH,
20
	GIT_PKT_REF,
21
	GIT_PKT_HAVE,
Carlos Martín Nieto committed
22
	GIT_PKT_ACK,
Carlos Martín Nieto committed
23 24
	GIT_PKT_NAK,
	GIT_PKT_PACK,
25
	GIT_PKT_COMMENT,
26
	GIT_PKT_ERR,
27 28
	GIT_PKT_DATA,
	GIT_PKT_PROGRESS,
Carlos Martín Nieto committed
29 30 31 32 33 34 35 36
};

/* Used for multi-ack */
enum git_ack_status {
	GIT_ACK_NONE,
	GIT_ACK_CONTINUE,
	GIT_ACK_COMMON,
	GIT_ACK_READY
37 38 39
};

/* This would be a flush pkt */
40
typedef struct {
41
	enum git_pkt_type type;
42
} git_pkt;
43 44 45 46 47 48 49 50 51

struct git_pkt_cmd {
	enum git_pkt_type type;
	char *cmd;
	char *path;
	char *host;
};

/* This is a pkt-line with some info in it */
52
typedef struct {
53 54
	enum git_pkt_type type;
	git_remote_head head;
55
	char *capabilities;
56
} git_pkt_ref;
57

Carlos Martín Nieto committed
58 59 60 61 62 63 64
/* Useful later */
typedef struct {
	enum git_pkt_type type;
	git_oid oid;
	enum git_ack_status status;
} git_pkt_ack;

65 66 67 68 69
typedef struct {
	enum git_pkt_type type;
	char comment[GIT_FLEX_ARRAY];
} git_pkt_comment;

70 71
typedef struct {
	enum git_pkt_type type;
72 73 74 75 76 77 78 79
	int len;
	char data[GIT_FLEX_ARRAY];
} git_pkt_data;

typedef git_pkt_data git_pkt_progress;

typedef struct {
	enum git_pkt_type type;
80 81 82
	char error[GIT_FLEX_ARRAY];
} git_pkt_err;

Carlos Martín Nieto committed
83
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
84
int git_pkt_buffer_flush(git_buf *buf);
85
int git_pkt_send_flush(GIT_SOCKET s);
86
int git_pkt_buffer_done(git_buf *buf);
87
int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_buf *buf);
88
int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
89
void git_pkt_free(git_pkt *pkt);
Vicent Marti committed
90 91

#endif