]>
Commit | Line | Data |
---|---|---|
bb742ede VM |
1 | /* |
2 | * Copyright (C) 2009-2011 the libgit2 contributors | |
3 | * | |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
8f866dae CMN |
7 | #include "common.h" |
8 | #include "git2/types.h" | |
d88d4311 | 9 | #include "git2/remote.h" |
8f866dae CMN |
10 | #include "git2/net.h" |
11 | #include "transport.h" | |
12 | ||
2869f404 | 13 | static struct { |
8f866dae CMN |
14 | char *prefix; |
15 | git_transport_cb fn; | |
16 | } transports[] = { | |
ecb6ca0e | 17 | {"git://", git_transport_git}, |
3d975abc | 18 | {"http://", git_transport_http}, |
8f866dae CMN |
19 | {"https://", git_transport_dummy}, |
20 | {"file://", git_transport_local}, | |
21 | {"git+ssh://", git_transport_dummy}, | |
22 | {"ssh+git://", git_transport_dummy}, | |
23 | {NULL, 0} | |
24 | }; | |
25 | ||
86360ffd | 26 | #define GIT_TRANSPORT_COUNT (sizeof(transports)/sizeof(transports[0])) - 1 |
2869f404 VM |
27 | |
28 | static git_transport_cb transport_find_fn(const char *url) | |
8f866dae | 29 | { |
2869f404 | 30 | size_t i = 0; |
8f866dae | 31 | |
2869f404 | 32 | /* TODO: Parse "example.com:project.git" as an SSH URL */ |
8f866dae | 33 | |
2869f404 | 34 | for (i = 0; i < GIT_TRANSPORT_COUNT; ++i) { |
8f866dae CMN |
35 | if (!strncasecmp(url, transports[i].prefix, strlen(transports[i].prefix))) |
36 | return transports[i].fn; | |
8f866dae CMN |
37 | } |
38 | ||
2869f404 | 39 | return NULL; |
8f866dae CMN |
40 | } |
41 | ||
42 | /************** | |
43 | * Public API * | |
44 | **************/ | |
45 | ||
4e913309 | 46 | int 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 | 52 | int 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 | ||
2869f404 VM |
58 | fn = transport_find_fn(url); |
59 | ||
60 | /* | |
61 | * If we haven't found the transport, we assume we mean a | |
62 | * local file. | |
63 | */ | |
64 | if (fn == NULL) | |
65 | fn = &git_transport_local; | |
8f866dae | 66 | |
4e913309 CMN |
67 | error = fn(&transport); |
68 | if (error < GIT_SUCCESS) | |
69 | return git__rethrow(error, "Failed to create new transport"); | |
d6258deb | 70 | |
8f866dae CMN |
71 | transport->url = git__strdup(url); |
72 | if (transport->url == NULL) | |
73 | return GIT_ENOMEM; | |
74 | ||
8f866dae CMN |
75 | *out = transport; |
76 | ||
77 | return GIT_SUCCESS; | |
78 | } | |
d88d4311 VM |
79 | |
80 | /* from remote.h */ | |
81 | int git_remote_valid_url(const char *url) | |
82 | { | |
83 | return transport_find_fn(url) != NULL; | |
84 | } | |
85 |