]>
git.proxmox.com Git - libgit2.git/blob - src/transport.c
2 * Copyright (C) 2009-2011 the libgit2 contributors
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.
8 #include "git2/types.h"
9 #include "git2/remote.h"
11 #include "transport.h"
17 {"git://", git_transport_git
},
18 {"http://", git_transport_http
},
19 {"https://", git_transport_dummy
},
20 {"file://", git_transport_local
},
21 {"git+ssh://", git_transport_dummy
},
22 {"ssh+git://", git_transport_dummy
},
26 #define GIT_TRANSPORT_COUNT (sizeof(transports)/sizeof(transports[0])) - 1
28 static git_transport_cb
transport_find_fn(const char *url
)
32 /* TODO: Parse "example.com:project.git" as an SSH URL */
34 for (i
= 0; i
< GIT_TRANSPORT_COUNT
; ++i
) {
35 if (!strncasecmp(url
, transports
[i
].prefix
, strlen(transports
[i
].prefix
)))
36 return transports
[i
].fn
;
46 int git_transport_dummy(git_transport
**GIT_UNUSED(transport
))
48 GIT_UNUSED_ARG(transport
);
49 return git__throw(GIT_ENOTIMPLEMENTED
, "This protocol isn't implemented. Sorry");
52 int git_transport_new(git_transport
**out
, const char *url
)
55 git_transport
*transport
;
58 fn
= transport_find_fn(url
);
61 * If we haven't found the transport, we assume we mean a
65 fn
= &git_transport_local
;
67 error
= fn(&transport
);
68 if (error
< GIT_SUCCESS
)
69 return git__rethrow(error
, "Failed to create new transport");
71 transport
->url
= git__strdup(url
);
72 if (transport
->url
== NULL
)
81 int git_remote_valid_url(const char *url
)
83 return transport_find_fn(url
) != NULL
;