summaryrefslogtreecommitdiff
path: root/src/protocol.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2011-11-21 17:12:23 -0800
committerVicent Martí <tanoku@gmail.com>2011-11-21 17:12:23 -0800
commitbec92f78bf169d3cb2c058263ddff699b5055dca (patch)
tree3ec1b406fa85a4604ddd598badc7340e2009a28d /src/protocol.c
parent2744806f32c895feb2ec241320d2b64ae58e992c (diff)
parent6ac3b707b14217602152c032a11304757c88612c (diff)
downloadlibgit2-bec92f78bf169d3cb2c058263ddff699b5055dca.tar.gz
Merge pull request #492 from carlosmn/networking
Networking improvements
Diffstat (limited to 'src/protocol.c')
-rw-r--r--src/protocol.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/protocol.c b/src/protocol.c
new file mode 100644
index 000000000..1f39f105b
--- /dev/null
+++ b/src/protocol.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#include "common.h"
+#include "protocol.h"
+#include "pkt.h"
+#include "buffer.h"
+
+int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
+{
+ git_buf *buf = &p->buf;
+ git_vector *refs = p->refs;
+ int error;
+ const char *line_end, *ptr;
+
+ if (len == 0) { /* EOF */
+ if (buf->size != 0)
+ return p->error = git__throw(GIT_ERROR, "EOF and unprocessed data");
+ else
+ return 0;
+ }
+
+ git_buf_put(buf, data, len);
+ ptr = buf->ptr;
+ while (1) {
+ git_pkt *pkt;
+
+ if (buf->size == 0)
+ return 0;
+
+ error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->size);
+ if (error == GIT_ESHORTBUFFER)
+ return 0; /* Ask for more */
+ if (error < GIT_SUCCESS)
+ return p->error = git__rethrow(error, "Failed to parse pkt-line");
+
+ git_buf_consume(buf, line_end);
+ error = git_vector_insert(refs, pkt);
+ if (error < GIT_SUCCESS)
+ return p->error = git__rethrow(error, "Failed to add pkt to list");
+
+ if (pkt->type == GIT_PKT_FLUSH)
+ p->flush = 1;
+ }
+
+ return error;
+}