Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-05-17 00:07:08 +0400
committerCarlos Martín Nieto <carlos@cmartin.tk>2011-06-26 20:18:11 +0400
commit8f866daee5a0a43702f349c7fa46d3274542650c (patch)
treeb9988e5566c79f5ec9b6a064ddb1d7706a51e109 /src/transport.c
parentc5b2622d6810eed5a4b90123ab0e7fc6d4583831 (diff)
Lay down the fundations for the network code
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/transport.c')
-rw-r--r--src/transport.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/transport.c b/src/transport.c
new file mode 100644
index 000000000..c08345968
--- /dev/null
+++ b/src/transport.c
@@ -0,0 +1,77 @@
+#include "common.h"
+#include "git2/types.h"
+#include "git2/transport.h"
+#include "git2/net.h"
+#include "transport.h"
+
+struct {
+ char *prefix;
+ git_transport_cb fn;
+} transports[] = {
+ {"git://", git_transport_dummy},
+ {"http://", git_transport_dummy},
+ {"https://", git_transport_dummy},
+ {"file://", git_transport_local},
+ {"git+ssh://", git_transport_dummy},
+ {"ssh+git://", git_transport_dummy},
+ {NULL, 0}
+};
+
+static git_transport_cb transport_fill_fn(const char *url)
+{
+ int i = 0;
+
+ while (1) {
+ if (transports[i].prefix == NULL)
+ break;
+
+ if (!strncasecmp(url, transports[i].prefix, strlen(transports[i].prefix)))
+ return transports[i].fn;
+
+ ++i;
+ }
+
+ /*
+ * If we still haven't found the transport, we assume we mean a
+ * local file.
+ * TODO: Parse "example.com:project.git" as an SSH URL
+ */
+ return git_transport_local;
+}
+
+/**************
+ * Public API *
+ **************/
+
+int git_transport_dummy(git_transport *GIT_UNUSED(transport))
+{
+ GIT_UNUSED_ARG(transport);
+ return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry");
+}
+
+int git_transport_new(git_transport **out, git_repository *repo, const char *url)
+{
+ git_transport_cb fn;
+ git_transport *transport;
+ int error;
+
+ fn = transport_fill_fn(url);
+
+ transport = git__malloc(sizeof(git_transport));
+ if (transport == NULL)
+ return GIT_ENOMEM;
+
+ transport->url = git__strdup(url);
+ if (transport->url == NULL)
+ return GIT_ENOMEM;
+
+ transport->repo = repo;
+
+ error = fn(transport);
+ if (error < GIT_SUCCESS)
+ return git__rethrow(error, "Failed to create new transport");
+
+ *out = transport;
+
+ return GIT_SUCCESS;
+}