Example #1
0
        //ORIGINAL void Curl_flush_cookies(struct SessionHandle *data, int cleanup)
        public static void FlushCookies(UserDefined data/*, int cleanup*/)
        {
            string cookieJar = data.Str[(int)DupString.COOKIEJAR] as string;

            if (!String.IsNullOrEmpty(cookieJar))
            {
                var cookies = data.Cookies;

                string fullPath = Path.Combine(ScriptContext.CurrentContext.WorkingDirectory, cookieJar);


                //TODO: check the file lock Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
                try
                {
                    CookieOutput(cookies, cookieJar);
                }
                catch (Exception ex)
                {
                    // do nothing
                    PhpException.Throw(PhpError.Warning, String.Format("WARNING: failed to save cookies in {0}; {1}\n", cookieJar, ex.Message));
                }

                //  }
                //  else {
                //    if(cleanup && data->change.cookielist)
                //      /* since nothing is written, we can just free the list of cookie file
                //         names */
                //      curl_slist_free_all(data->change.cookielist); /* clean up list */
                //    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
                //  }

                //  if(cleanup && (!data->share || (data->cookies != data->share->cookies))) {
                //    Curl_cookie_cleanup(data->cookies);
                //  }
                //  Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
            }

        }
Example #2
0
        private void setTimeOut(UserDefined data)
        {
            // Curl default is 300000 milliseconds == five minutes
            // .NET default is 100000 milliseconds, we'll leave it there as a default

            int timeout_set = 0;

            if (data.Timeout > 0)
                timeout_set |= 1;

            if (data.ConnectTimeout > 0)
                timeout_set |= 2;

            switch (timeout_set)
            {
                case 1:
                    request.Timeout = data.Timeout;
                    break;
                case 2:
                    request.Timeout = data.ConnectTimeout;
                    break;
                case 3:
                    if (data.Timeout < data.ConnectTimeout)
                        request.Timeout = data.Timeout;
                    else
                        request.Timeout = data.ConnectTimeout;
                    break;
            }

        }
Example #3
0
 /// <summary>
 /// Initialize a new handle of cURL session
 /// </summary>
 public PhpCurlResource()
     : base("Curl")
 {
     data = new UserDefined();
     handler = CurlHandler.Create(CurlProto.HTTP);// for now we just support HTTP handeling
 }
Example #4
0
        private Curl_HttpReq setRequestMethod(UserDefined data)
        {
            Curl_HttpReq httpreq = data.Httpreq;

            if ( // (conn->handler->protocol&(CURLPROTO_HTTP|CURLPROTO_FTP)) && //(MB) I'm handeling http request, so I don't need to check this
                data.Upload)
            {
                httpreq = Curl_HttpReq.PUT;
            }

            // Now set the request.Method to the proper request string
            if (data.Str[(int)DupString.CUSTOMREQUEST] != null)
                request.Method = PhpVariable.AsString(data.Str[(int)DupString.CUSTOMREQUEST]);
            else
            {
                if (data.OptNoBody)
                    request.Method = "HEAD";
                else
                {
                    switch (httpreq)
                    {
                        case Curl_HttpReq.POST:
                        case Curl_HttpReq.POST_FORM:
                            request.Method = "POST";
                            break;
                        case Curl_HttpReq.PUT:
                            request.Method = "PUT";
                            break;
                        default: /* this should never happen */
                        case Curl_HttpReq.GET:
                            request.Method = "GET";
                            break;
                        case Curl_HttpReq.HEAD:
                            request.Method = "HEAD";
                            break;
                    }
                }
            }

            return httpreq;
        }
Example #5
0
 private void setHttpVersion(UserDefined data)
 {
     switch (data.HttpVersion)
     {
         //case CurlHttpVersion.CURL_HTTP_VERSION_NONE:
         //case CurlHttpVersion.CURL_HTTP_VERSION_LAST:
         //    do nothing, default will be used
         //    break;
         case CurlHttpVersion.CURL_HTTP_VERSION_1_0:
             request.ProtocolVersion = HttpVersion.Version10;
             break;
         case CurlHttpVersion.CURL_HTTP_VERSION_1_1:
             request.ProtocolVersion = HttpVersion.Version11;
             break;
     }
 }
Example #6
0
        private void setProxy(UserDefined data)
        {
            string proxyAddress;
            WebProxy myProxy;

            if (data.Str[(int)DupString.PROXY] == null)
                return;

            if (data.ProxyType != CURLproxyType.CURLPROXY_HTTP)
                return;

            myProxy = new WebProxy();
            proxyAddress = PhpVariable.AsString(data.Str[(int)DupString.PROXY]);

            // Create a new Uri object.
            Uri uri = Utils.CompleteUri(proxyAddress, Scheme, data.ProxyPort);

            // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
            myProxy.Address = uri;
            // Create a NetworkCredential object and associate it with the 
            // Proxy property of request object.

            if (data.Str[(int)DupString.PROXYUSERNAME] != null)
            {
                //data.proxyauth set to CURLAUTH_ANY is .NET default because it will use right authentication protocol

                myProxy.Credentials = new NetworkCredential(
                    PhpVariable.AsString(data.Str[(int)DupString.PROXYUSERNAME]),
                    data.Str[(int)DupString.PROXYPASSWORD] != null ? PhpVariable.AsString(data.Str[(int)DupString.PROXYPASSWORD]) : String.Empty);

            }

            request.Proxy = myProxy;

        }
Example #7
0
        private void setCredentials(UserDefined data)
        {
            if (data.Str[(int)DupString.USERNAME] != null)
            {
                //This is obvious way, but unfortunatelly it doesn't work
                //httpauth set to CURLAUTH_ANY is .NET default because it will use right authentication protocol
                //request.Credentials = new NetworkCredential(
                //    PhpVariable.AsString(data.Str[(int)DupString.USERNAME]),
                //    data.Str[(int)DupString.PASSWORD] != null ? PhpVariable.AsString(data.Str[(int)DupString.PASSWORD]) : String.Empty);

                //We only support BASIC
                HttpUtils.SetBasicAuthHeader(request,
                    PhpVariable.AsString(data.Str[(int)DupString.USERNAME]),
                    data.Str[(int)DupString.PASSWORD] != null ? PhpVariable.AsString(data.Str[(int)DupString.PASSWORD]) : String.Empty);

            }
        }
Example #8
0
 private void setCookies(UserDefined data)
 {
     //if (data.Cookies.Count > 0)
     //{
     var container = new CookieContainer();
     container.Add(data.Cookies);
     request.CookieContainer = container;
     //}
 }