예제 #1
0
            private static int Action(
                out IntPtr stream,
                IntPtr subtransport,
                IntPtr url,
                GitSmartSubtransportAction action)
            {
                stream = IntPtr.Zero;

                SmartSubtransport t           = GCHandle.FromIntPtr(Marshal.ReadIntPtr(subtransport, GitSmartSubtransport.GCHandleOffset)).Target as SmartSubtransport;
                String            urlAsString = LaxUtf8Marshaler.FromNative(url);

                if (null != t &&
                    !String.IsNullOrEmpty(urlAsString))
                {
                    try
                    {
                        stream = t.Action(urlAsString, action).GitSmartTransportStreamPointer;

                        return(0);
                    }
                    catch (Exception ex)
                    {
                        Proxy.git_error_set_str(GitErrorCategory.Net, ex);
                    }
                }

                return((int)GitErrorCode.Error);
            }
예제 #2
0
        protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)
        {
            string postContentType = null;
            string serviceUri;

            switch (action)
            {
            case GitSmartSubtransportAction.UploadPackList:
                serviceUri = url + "/info/refs?service=git-upload-pack";
                break;

            case GitSmartSubtransportAction.UploadPack:
                serviceUri      = url + "/git-upload-pack";
                postContentType = "application/x-git-upload-pack-request";
                break;

            case GitSmartSubtransportAction.ReceivePackList:
                serviceUri = url + "/info/refs?service=git-receive-pack";
                break;

            case GitSmartSubtransportAction.ReceivePack:
                serviceUri      = url + "/git-receive-pack";
                postContentType = "application/x-git-receive-pack-request";
                break;

            default:
                throw new InvalidOperationException();
            }

            // Grab the credentials from the user.
            var httpClient = new HttpClient {
                Timeout = TimeSpan.FromMinutes(1.0),
            };

            var res = httpClient.GetAsync(serviceUri).Result;

            if (res.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                var cred = (UsernamePasswordCredentials)GitCredentials.TryGet(url, "", SupportedCredentialTypes.UsernamePassword, GitCredentialsType.Tfs);

                httpClient = new HttpClient(new HttpClientHandler {
                    Credentials = new System.Net.NetworkCredential(cred.Username, cred.Password)
                })
                {
                    Timeout = TimeSpan.FromMinutes(1.0),
                };
                res = httpClient.GetAsync(serviceUri).Result;
                if (res.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    GitCredentials.StoreCredentials(GitCredentialsType.Tfs);
                }
            }

            return(new TfsSmartSubtransportStream(this)
            {
                HttpClient = httpClient,
                ServiceUri = new Uri(serviceUri),
                PostContentType = postContentType,
            });
        }
            protected override SmartSubtransportStream Action(String url, GitSmartSubtransportAction action)
            {
                String endpointUrl, contentType = null;
                bool   isPost = false;

                switch (action)
                {
                case GitSmartSubtransportAction.UploadPackList:
                    endpointUrl = String.Concat(url, "/info/refs?service=git-upload-pack");
                    break;

                case GitSmartSubtransportAction.UploadPack:
                    endpointUrl = String.Concat(url, "/git-upload-pack");
                    contentType = "application/x-git-upload-pack-request";
                    isPost      = true;
                    break;

                case GitSmartSubtransportAction.ReceivePackList:
                    endpointUrl = String.Concat(url, "/info/refs?service=git-receive-pack");
                    break;

                case GitSmartSubtransportAction.ReceivePack:
                    endpointUrl = String.Concat(url, "/git-receive-pack");
                    contentType = "application/x-git-receive-pack-request";
                    isPost      = true;
                    break;

                default:
                    throw new InvalidOperationException();
                }

                return(new MockSmartSubtransportStream(this, endpointUrl, isPost, contentType));
            }
        protected override SmartSubtransportStream Action(String url, GitSmartSubtransportAction action)
        {
            String endpointUrl, contentType = null;
                bool isPost = false;

                switch (action)
                {
                    case GitSmartSubtransportAction.UploadPackList:
                        endpointUrl = String.Concat(url, "/info/refs?service=git-upload-pack");
                        break;

                    case GitSmartSubtransportAction.UploadPack:
                        endpointUrl = String.Concat(url, "/git-upload-pack");
                        contentType = "application/x-git-upload-pack-request";
                        isPost = true;
                        break;

                    case GitSmartSubtransportAction.ReceivePackList:
                        endpointUrl = String.Concat(url, "/info/refs?service=git-receive-pack");
                        break;

                    case GitSmartSubtransportAction.ReceivePack:
                        endpointUrl = String.Concat(url, "/git-receive-pack");
                        contentType = "application/x-git-receive-pack-request";
                        isPost = true;
                        break;

                    default:
                        throw new InvalidOperationException();
                }

                return new MockSmartSubtransportStream(this, endpointUrl, isPost, contentType);
        }
		protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)
		{
			string postContentType = null;
			string serviceUri;

			switch (action) {
			case GitSmartSubtransportAction.UploadPackList:
				serviceUri = url + "/info/refs?service=git-upload-pack";
				break;
			case GitSmartSubtransportAction.UploadPack:
				serviceUri = url + "/git-upload-pack";
				postContentType = "application/x-git-upload-pack-request";
				break;
			case GitSmartSubtransportAction.ReceivePackList:
				serviceUri = url + "/info/refs?service=git-receive-pack";
				break;
			case GitSmartSubtransportAction.ReceivePack:
				serviceUri = url + "/git-receive-pack";
				postContentType = "application/x-git-receive-pack-request";
				break;
			default:
				throw new InvalidOperationException();
			}

			// Grab the credentials from the user.
			var httpClient = new HttpClient {
				Timeout = TimeSpan.FromMinutes (1.0),
			};

			var res = httpClient.GetAsync (serviceUri).Result;
			if (res.StatusCode == System.Net.HttpStatusCode.Unauthorized) {
				var cred = (UsernamePasswordCredentials)GitCredentials.TryGet (url, "", SupportedCredentialTypes.UsernamePassword, GitCredentialsType.Tfs);

				httpClient = new HttpClient (new HttpClientHandler { Credentials = new System.Net.NetworkCredential (cred.Username, cred.Password) }) {
					Timeout = TimeSpan.FromMinutes (1.0),
				};
				res = httpClient.GetAsync (serviceUri).Result;
				if (res.StatusCode == System.Net.HttpStatusCode.OK) {
					GitCredentials.StoreCredentials (GitCredentialsType.Tfs);
				}
			}

			return new TfsSmartSubtransportStream(this) {
				HttpClient = httpClient,
				ServiceUri = new Uri (serviceUri),
				PostContentType = postContentType,
			};
		}
            private static int Action(
                out IntPtr stream,
                IntPtr subtransport,
                IntPtr url,
                GitSmartSubtransportAction action)
            {
                stream = IntPtr.Zero;

                SmartSubtransport t = GCHandle.FromIntPtr(Marshal.ReadIntPtr(subtransport, GitSmartSubtransport.GCHandleOffset)).Target as SmartSubtransport;
                String urlAsString = LaxUtf8Marshaler.FromNative(url);

                if (t == null)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Net, "no subtransport provided");
                    return (int)GitErrorCode.Error;
                }

                if (String.IsNullOrEmpty(urlAsString))
                {
                    urlAsString = t.LastActionUrl;
                }

                if (String.IsNullOrEmpty(urlAsString))
                {
                    Proxy.git_error_set_str(GitErrorCategory.Net, "no url provided");
                    return (int)GitErrorCode.Error;
                }

                try
                {
                    stream = t.Action(urlAsString, action).GitSmartTransportStreamPointer;
                    t.LastActionUrl = urlAsString;
                    return 0;
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Net, ex);
                    return (int)GitErrorCode.Error;
                }
            }
        protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)
        {
            switch (action)
            {
            // Both of these mean we're starting a new connection
            case GitSmartSubtransportAction.UploadPackList:
                _stream = new SshExeTransportStream(this, url, "git-upload-pack");
                break;

            case GitSmartSubtransportAction.ReceivePackList:
                _stream = new SshExeTransportStream(this, url, "git-receive-pack");
                break;

            case GitSmartSubtransportAction.UploadPack:
            case GitSmartSubtransportAction.ReceivePack:
                break;

            default:
                throw new InvalidOperationException("Invalid action for subtransport");
            }

            return(_stream);
        }
예제 #8
0
 /// <summary>
 /// Invoked by libgit2 to create a connection using this subtransport.
 /// </summary>
 /// <param name="url">The endpoint to connect to</param>
 /// <param name="action">The type of connection to create</param>
 /// <returns>A SmartSubtransportStream representing the connection</returns>
 protected abstract SmartSubtransportStream Action(String url, GitSmartSubtransportAction action);
예제 #9
0
            private static int Action(
                out IntPtr stream,
                IntPtr subtransport,
                IntPtr url,
                GitSmartSubtransportAction action)
            {
                stream = IntPtr.Zero;

                SmartSubtransport t = GCHandle.FromIntPtr(Marshal.ReadIntPtr(subtransport, GitSmartSubtransport.GCHandleOffset)).Target as SmartSubtransport;
                String urlAsString = LaxUtf8Marshaler.FromNative(url);

                if (null != t &&
                    !String.IsNullOrEmpty(urlAsString))
                {
                    try
                    {
                        stream = t.Action(urlAsString, action).GitSmartTransportStreamPointer;

                        return 0;
                    }
                    catch (Exception ex)
                    {
                        Proxy.giterr_set_str(GitErrorCategory.Net, ex);
                    }
                }

                return (int)GitErrorCode.Error;
            }
예제 #10
0
 /// <summary>
 /// Invoked by libgit2 to create a connection using this subtransport.
 /// </summary>
 /// <param name="url">The endpoint to connect to</param>
 /// <param name="action">The type of connection to create</param>
 /// <returns>A SmartSubtransportStream representing the connection</returns>
 protected abstract SmartSubtransportStream Action(String url, GitSmartSubtransportAction action);