]> git.proxmox.com Git - libgit2.git/blame - src/transport.c
Update Clay script
[libgit2.git] / src / transport.c
CommitLineData
8f866dae
CMN
1#include "common.h"
2#include "git2/types.h"
3#include "git2/transport.h"
4#include "git2/net.h"
5#include "transport.h"
6
7struct {
8 char *prefix;
9 git_transport_cb fn;
10} transports[] = {
ecb6ca0e 11 {"git://", git_transport_git},
8f866dae
CMN
12 {"http://", git_transport_dummy},
13 {"https://", git_transport_dummy},
14 {"file://", git_transport_local},
15 {"git+ssh://", git_transport_dummy},
16 {"ssh+git://", git_transport_dummy},
17 {NULL, 0}
18};
19
4e913309 20static git_transport_cb transport_new_fn(const char *url)
8f866dae
CMN
21{
22 int i = 0;
23
24 while (1) {
25 if (transports[i].prefix == NULL)
26 break;
27
28 if (!strncasecmp(url, transports[i].prefix, strlen(transports[i].prefix)))
29 return transports[i].fn;
30
31 ++i;
32 }
33
34 /*
35 * If we still haven't found the transport, we assume we mean a
36 * local file.
37 * TODO: Parse "example.com:project.git" as an SSH URL
38 */
39 return git_transport_local;
40}
41
42/**************
43 * Public API *
44 **************/
45
4e913309 46int git_transport_dummy(git_transport **GIT_UNUSED(transport))
8f866dae
CMN
47{
48 GIT_UNUSED_ARG(transport);
49 return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry");
50}
51
ce90a407 52int git_transport_new(git_transport **out, const char *url)
8f866dae
CMN
53{
54 git_transport_cb fn;
55 git_transport *transport;
56 int error;
57
4e913309 58 fn = transport_new_fn(url);
8f866dae 59
4e913309
CMN
60 error = fn(&transport);
61 if (error < GIT_SUCCESS)
62 return git__rethrow(error, "Failed to create new transport");
d6258deb 63
8f866dae
CMN
64 transport->url = git__strdup(url);
65 if (transport->url == NULL)
66 return GIT_ENOMEM;
67
8f866dae
CMN
68 *out = transport;
69
70 return GIT_SUCCESS;
71}