Exemplo n.º 1
0
        // Overrides the IWMSEventNotificationPlugin.OnEvent method. This 
        // implementation displays a message box when a client either
        // connects or disconnects.
        public void OnEvent(
                            ref WMS_EVENT Event,
                            IWMSContext UserCtx,
                            IWMSContext PresentationCtx,
                            IWMSCommandContext CommandCtx)
        {
            try
            {
                switch (Event.Type)
                {
                    case WMS_EVENT_TYPE.WMS_EVENT_CONNECT:
                        MessageBox.Show("Client connected",
                                        "Event Plug-in",
                                        MessageBoxButtons.OK);
                        break;

                    case WMS_EVENT_TYPE.WMS_EVENT_DISCONNECT:
                        MessageBox.Show("Client disconnected",
                                        "Event Plug-in",
                                        MessageBoxButtons.OK);
                        break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message,
                               "Event Plug-in Error",
                               MessageBoxButtons.OK,
                               MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
    public void Authenticate(object responseBlob, IWMSContext pUserCtx, IWMSContext pPresentationCtx, IWMSCommandContext pCommandContext, IWMSAuthenticationCallback pCallback, object context)
    {
        // must be Unicode.  If it isn't, the
        // challenge isn't sent correctly
        Encoding enc = Encoding.Unicode;

        byte[] response;
        byte[] challenge = enc.GetBytes("");
        try
        {
            response = (byte[])responseBlob;
            if (response.Length == 0)
            {
                // The client requested authentication; prepare the
                // challenge response to send to the client.  In order to
                // do Basic authentication, be sure to return "Basic" from
                // your implementation of IWMSAuthenticationPlugin.GetProtocolName()
                string challengeTxt = "WWW-Authenticate: Basic realm=\"Domain\"";
                challenge = enc.GetBytes(challengeTxt);
                _result   = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_CONTINUE;
            }
            else
            {
                // parses Base64 encoded response and gets passed in credentials
                SetCredentials(enc.GetString(response));
                LdapConnection    ldc = new LdapConnection("Domain");
                NetworkCredential nc  = new NetworkCredential(_credentials.Username, _credentials.Password, "Domain");
                ldc.Credential = nc;
                ldc.AuthType   = AuthType.Negotiate;
                ldc.Bind(nc); // user has authenticated at this point, as the credentials were used to login to the dc.
                // must log in with a local windows account and get a handle for the account.
                // even if success is returned, the plugin still needs a valid windows account
                // to stream the file.
                bool result = LogonAPI.LogonUser("local username", "local domain", "local password", LogonAPI.LOGON32_LOGON_NETWORK, LogonAPI.LOGON32_PROVIDER_DEFAULT, ref _userToken);
                _result = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_SUCCESS;
            }
        }
        catch (LdapException e)
        {
            _result = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_DENIED;
        }
        catch (Exception e)
        {
            _result = WMS_AUTHENTICATION_RESULT.WMS_AUTHENTICATION_ERROR;
        }
        finally
        {
            pCallback.OnAuthenticateComplete(_result, challenge, context);
        }
    }
Exemplo n.º 3
0
        public void AuthorizeEvent(ref WMS_EVENT pEvent, IWMSContext pUserCtx, IWMSContext pPresentationCtx, IWMSCommandContext pCommandCtx,
                                   IWMSEventAuthorizationCallback pCallback,
                                   object Context)
        {
            int       hr            = 0; // By deafault access is granted to user
            const int ACCESS_DENIED = unchecked ((int)0x80070005);

            string initial_request = null;
            string user_ip_address = null;
            string user_agent      = null;

            pPresentationCtx.GetStringValue(WMSDefines.WMS_PRESENT_REQUEST_NAME,
                                            WMSDefines.WMS_PRESENT_REQUEST_NAME_ID,
                                            out initial_request,
                                            0);
            pUserCtx.GetStringValue(WMSDefines.WMS_USER_IP_ADDRESS_STRING,
                                    WMSDefines.WMS_USER_IP_ADDRESS_STRING_ID,
                                    out user_ip_address,
                                    0);
            if (log.IsInfoEnabled)
            {
                pUserCtx.GetStringValue(WMSDefines.WMS_USER_AGENT,
                                        WMSDefines.WMS_USER_AGENT_ID,
                                        out user_agent,
                                        0);
            }

            URLValidationExceptionTyte errortype = url_procesor.CheckURLValidity(initial_request,
                                                                                 user_ip_address);

            if (URLValidationExceptionTyte.SUCCESS != errortype)
            {
                hr = ACCESS_DENIED;
            }

            if (log.IsInfoEnabled)
            {
                StringBuilder msg = new StringBuilder();
                if (user_agent != null)
                {
                    msg.Append("User-Agent=" + user_agent);
                }
                msg.Append(" User-Ip-Address=" + user_ip_address);
                msg.Append(" Request=" + initial_request);
                msg.Append(" Autorization-Result=" + errortype.ToString());
                log.Info(msg.ToString());
            }

            pCallback.OnAuthorizeEvent(hr, Context);
        }
Exemplo n.º 4
0
        public void AuthorizeEvent(ref WMS_EVENT pEvent, IWMSContext pUserCtx, IWMSContext pPresentationCtx, IWMSCommandContext pCommandCtx,
            IWMSEventAuthorizationCallback pCallback,
            object Context)
        {
            int hr = 0; // By deafault access is granted to user
            const int ACCESS_DENIED = unchecked((int)0x80070005);

            string initial_request = null;
            string user_ip_address = null;
            string user_agent = null;

            pPresentationCtx.GetStringValue(WMSDefines.WMS_PRESENT_REQUEST_NAME,
                                            WMSDefines.WMS_PRESENT_REQUEST_NAME_ID,
                                            out initial_request,
                                            0);
            pUserCtx.GetStringValue(WMSDefines.WMS_USER_IP_ADDRESS_STRING,
                                    WMSDefines.WMS_USER_IP_ADDRESS_STRING_ID,
                                    out user_ip_address,
                                    0);
            if (log.IsInfoEnabled)
            {
                pUserCtx.GetStringValue(WMSDefines.WMS_USER_AGENT,
                                        WMSDefines.WMS_USER_AGENT_ID,
                                        out user_agent,
                                        0);

            }

            URLValidationExceptionTyte errortype = url_procesor.CheckURLValidity(initial_request,
                                                                                 user_ip_address);
            if (URLValidationExceptionTyte.SUCCESS != errortype)
            {
                hr = ACCESS_DENIED;
            }

            if (log.IsInfoEnabled)
            {
                StringBuilder msg = new StringBuilder();
                if(user_agent != null)msg.Append("User-Agent="+ user_agent);
                msg.Append(" User-Ip-Address="+user_ip_address);
                msg.Append(" Request="+initial_request);
                msg.Append(" Autorization-Result=" + errortype.ToString());
                log.Info(msg.ToString());
            }

            pCallback.OnAuthorizeEvent(hr, Context);
        }
Exemplo n.º 5
0
        public void AuthorizeEvent(ref WMS_EVENT pEvent, IWMSContext pUserCtx, IWMSContext pPresentationCtx, IWMSCommandContext pCommandCtx,
            IWMSEventAuthorizationCallback pCallback,
            object Context)
        {
            int hr = 0; // By deafault access is granted to user
            const int ACCESS_DENIED = unchecked((int)0x80070005);

            string user_ip_address = null;
            pUserCtx.GetStringValue(WMSDefines.WMS_USER_IP_ADDRESS_STRING,
                                    WMSDefines.WMS_USER_IP_ADDRESS_STRING_ID,
                                    out user_ip_address,
                                    0);

            try
            {
                DateTime lastWrite = System.IO.File.GetLastWriteTime(denylistname);

                if (denyList == null)
                {
                    denyList = IPListLoader.loadIpList(denylistname);
                    lastWriteTime = lastWrite;
                }
                else if (lastWriteTime.Ticks != lastWrite.Ticks)
                {
                    denyList = IPListLoader.loadIpList(denylistname);
                    lastWriteTime = lastWrite;
                }

                if (denyList.CheckNumber(user_ip_address))
                {
                    hr = ACCESS_DENIED;
                }
            }
            catch (Exception e) { }

            pCallback.OnAuthorizeEvent(hr, Context);
        }
Exemplo n.º 6
0
        void IWMSCacheProxy.QueryCacheMissPolicy( string bstrOriginUrl , 
            IWMSContext pUserContext , 
            IWMSCommandContext pCommandContext , 
            IWMSContext pPresentationContext , 
            object pCachePluginContext , 
            int lQueryType , 
            IWMSCacheProxyCallback pCallback , 
            object varContext )
        {
            Debug.WriteLine("IWMSCacheProxy.QueryCacheMissPolicy entered");
            int nOpenFlag = (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_OPEN;
            int nGCI = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_GET_CONTENT_INFO);
            int nReverseProxy = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_REVERSE_PROXY);
            ContentInfo ci = new ContentInfo(bstrOriginUrl,null);
            if((nOpenFlag & lQueryType)!=0) // open query
            {
                if(nReverseProxy==0) //normal mode
                {
                    // get content information
                    ci.CacheProxyCallback = pCallback;
                    ci.varContext = varContext;
                    CacheProxyServer.GetContentInformation(bstrOriginUrl,pPresentationContext,null,
                        null,this,ci);
                }
                else // it's a reverse proxy mode
                {
                    // we simply look up our table to see if there is a mapping between the requested
                    //Url and the RP url and return it
                    // we distinguish the table entry if it's a reverse proxy or not by
                    // checking the CDL data
                    // we store a special string "ReverseProxy" there for the distinction
                    // one can simply add another entry in the table to be safer
                    // as there might be some CDL data written as "ReverseProxy" !!
                    ContentInfo ciRP = null;
                    GetContentInfo(bstrOriginUrl,out ciRP);
                    WMS_CACHE_QUERY_MISS_RESPONSE Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND;
                    if((ciRP.ContentType & 1 )!=0) // it's a brodcast content
                    {
                        Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_BROADCAST;
                    }
                    else
                    {
                        Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND;
                    }

                    IWMSContext ContentInfoContext = null;
                    GetContentInfoContext(ci,out ContentInfoContext);
                    pCallback.OnQueryCacheMissPolicy(0,Response,ciRP.CacheUrl,null,ContentInfoContext,varContext);

                }

            }
            if((nGCI & lQueryType)!=0) // GCI query from downstream server
            {
                WMS_CACHE_QUERY_MISS_RESPONSE Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_FORWARD_REQUEST;
                IWMSContext ContentInfoContext = null;
                GetContentInfoContext(ci,out ContentInfoContext);
                pCallback.OnQueryCacheMissPolicy(0,Response,bstrOriginUrl,null,ContentInfoContext,varContext);
            }

            if((lQueryType & (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_CACHE_EVENT)!=0)
            {
                pCallback.OnQueryCacheMissPolicy(0,WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_FORWARD_REQUEST,
                    null,this,null,varContext);
            }

            return;
        }
Exemplo n.º 7
0
        //
        // IWMSCacheProxy
        //
        void IWMSCacheProxy.QueryCache(string bstrOriginUrl , 
            IWMSContext pUserContext , 
            IWMSCommandContext pCommandContext , 
            IWMSContext pPresentationContext , 
            int lQueryType , 
            IWMSCacheProxyCallback pCallback , 
            object varContext )
        {
            Debug.WriteLine("IWMSCacheProxy.QueryCache entered");
            // we simply return a hard coded URL for the request WMS_CACHE_QUERY_OPEN for now
            int nFlag = (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_OPEN;
            int nOpen = lQueryType & nFlag;
            int nGCI = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_GET_CONTENT_INFO);
            int nReverseProxy = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_REVERSE_PROXY);

            // either open or GCI is called
            // for GCI we don't care about CompareContentInformation
            // if not upto date, we treat as a miss
            if((nOpen!=0)||(nGCI!=0))
            {
                // allocate ContentInfoContext and DataContainerObject
                // stuff it with the information
                // and call back
                IWMSContext Context;
                WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS;

                ContentInfo ci;
                //gets allocated here
                GetContentInfo(bstrOriginUrl,out ci);
                ci.CacheProxyCallback = pCallback;
                ci.varContext = varContext;
                GetContentInfoContext(ci,out Context);

                bool bQueryCache = true;
                bool bOnDemand = true;
                if((ci.CacheUrl!=null) && (nReverseProxy==0)) // there is something in the cache
                {
                    // if content is not expired, this is a hit
                    DateTime now = DateTime.Now;
                    Debug.WriteLine(string.Format("Current local time={0}",now));
                    //covert to UTC time
                    now = now.ToUniversalTime();
                    Debug.WriteLine(string.Format("Current UTC time={0}",now));

                    Debug.WriteLine(string.Format("Expiration time={0}",ci.ExpirationTime));
                    if(ci.ExpirationTime > now)
                    {
                        if((ci.ContentType & 1 )!=0) // it's a brodcast content
                        {
                            Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_BROADCAST;
                            bOnDemand = false;
                        }
                        else
                        {
                            Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND;
                            bOnDemand = true;
                        }
                    }
                    else // content appears expired, we will have to call CompareContentInformation
                    {
                        if(nOpen!=0) // only for open queries
                        {
                            bQueryCache = false;
                        }
                    }
                }

                if(bQueryCache)
                {
                    string CacheUrl = ci.CacheUrl;
                    if(bOnDemand)
                    {
                        CacheUrl = string.Format("file://{0}",ci.CacheUrl);
                    }
                    pCallback.OnQueryCache( 0,
                        Response,
                        CacheUrl,
                        Context,
                        null,
                        varContext);
                }
                else
                {
                    CacheProxyServer.CompareContentInformation(bstrOriginUrl,Context,pPresentationContext,
                        this,null,this,(object)ci);
                }
            }
            else
            {
                // see of this is for event propagation
                int nCacheEvent = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_CACHE_EVENT);
                int nLocalEvent = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_LOCAL_EVENT);
                if((nCacheEvent | nLocalEvent)!=0)
                {
                    // we declare it as a miss
                    // and on QCP, we ask the cachemanager to forward it
                    WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS;
                    pCallback.OnQueryCache( 0,
                        Response,
                        bstrOriginUrl,
                        null,
                        null,
                        varContext);
                }

            }

            return;
        }
Exemplo n.º 8
0
 void IWMSCacheProxy.OnCacheClientClose( int resultHr , 
     IWMSContext pUserContext , 
     IWMSContext pPresentationContext )
 {
     Debug.WriteLine("IWMSCacheProxy.OnCacheClientClose entered");
     return;
 }
Exemplo n.º 9
0
 public void InitializePlugin(IWMSContext pServerContext, WMSNamedValues pNamedValues, IWMSClassObject pClassFactory)
 {
     log.Info("plugin initialize event");
 }
Exemplo n.º 10
0
 //[PreserveSig] can be used as well
 void IWMSProxyContext.GetCredentials(IWMSContext pUserContext, string bstrRealm, string bstrUrl, out string pbstrName, out string pbstrPassword)
 {
     Debug.WriteLine("CacheProxyPlugin::IWMSProxyContext.GetCredentials entered");
     pbstrName="";
     pbstrPassword="";
     throw new COMException("NO ERROR",1);
 }
Exemplo n.º 11
0
        //
        // IWMSCacheProxyServerCallback
        //
        void IWMSCacheProxyServerCallback.OnGetContentInformation(
            int lHr,
            IWMSContext pContentInfo,
            object varContext
            )
        {
            Debug.WriteLine("IWMSCacheProxyServerCallback::OnGetContentInformation entered");
            int nFlag=0;
            ContentInfo ci = (ContentInfo)varContext;
            bool bAddCacheItem = false;
            int nRetHr = lHr;
            // if we are called from the result of AddCacheItem, the lExpiration variable won't be 0
            // and we would simply call DownloadContent
            if(ci.lExpiration!=0) // Call result of AddCacheIrtem
            {
                bAddCacheItem=true;
                lHr=0;
            }
            // check the flags and if allowed
            // download the content and save it locally
            if(lHr==0) // would be E_ACCESSDENIED or something
                // if we didn't get content info
            {
                // if we are not allowed to cache the content
                // we simply set up proxy on demand datapath
                // else we store the information and ask cache manager
                // to download the content
                GetContentInfoFromContext(pContentInfo, ref ci);
                nFlag = ci.CacheFlags & (int)WMS_DATA_CONTAINER_VERSION_CACHE_FLAGS.WMS_DATA_CONTAINER_VERSION_ALLOW_PROXY_CACHING;

                if((nFlag!=0)||(bAddCacheItem))
                {
                    // proxying is allowed
                    // let's get all the content information
                    // and ask the cache manager to download the content
                    if((!bAddCacheItem)||(bAddCacheItem && (ci.CacheUrl==null)))
                    {
                        ci.CacheUrl = "c:\\WMSCache\\test";
                    }

                    //we check first from the database if the dowloading is already in progress
                    // and cll for downloading the content only if there is no active
                    // downloading going on
                    if(!IsDownloadInProgress(ci))
                    {
                        // add to the database that we are downloading
                        AddForDownload(ci);
                        CacheProxyServer.DownloadContent(ci.OriginUrl,ci.CacheUrl,0,0,0,0,this,
                            null,this,ci);
                    }
                    else
                    {
                        Debug.WriteLine("download arlready in progress");
                    }
                }
                // if this is a broadcast content, we are not going to download it
                // so we simply store the content information in the database with
                // empty CacheUrl, so when next request comes, we get a hit so
                // we can reply accordingly
                if((ci.ContentType & 1)!=0)
                {
                    UpdateTable(ci);
                }
            }
            else
            {
                Debug.WriteLine(string.Format("HRESULT for CacheProxyPlugin::IWMSCacheProxyServerCallback.OnGetContentInformation = {0}",
                    lHr.ToString("X")));
                if(lHr==-2147024891)
                    nRetHr=0;
            }

            // check if stream splitting is allowed
            // if so we ask cache manager to set up a brodcast connection with the player
            // otherwise we go for OD
            WMS_CACHE_QUERY_MISS_RESPONSE MissResponse = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND;
            nFlag = ci.CacheFlags & (int)WMS_DATA_CONTAINER_VERSION_CACHE_FLAGS.WMS_DATA_CONTAINER_VERSION_ALLOW_STREAM_SPLITTING;
            if(nFlag!=0)
            {
                MissResponse = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_BROADCAST;
            }

            // ask the server to setup a proxy on-demand
            if(ci.CacheProxyCallback!=null)
            {
                ci.CacheProxyCallback.OnQueryCacheMissPolicy((int)nRetHr,MissResponse
                    ,ci.OriginUrl,null,pContentInfo,ci.varContext);
            }
            return;
        }
Exemplo n.º 12
0
        void GetContentInfoFromContext(IWMSContext pContentInfo, ref ContentInfo ci)
        {
            Debug.WriteLine("CacheProxyPlugin::GetContentInfoFromContext entered");
            int nFlag=0;
            int lCacheFlags=0;
            IWMSDataContainerVersion DCV = null;
            Type t = typeof(IWMSDataContainerVersion);
            Guid guid = t.GUID;
            object odcv = (object)DCV;
            pContentInfo.GetAndQueryIUnknownValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION_ID,ref guid,out odcv, 0);
            DCV = (IWMSDataContainerVersion)odcv;
            DCV.GetCacheFlags(out lCacheFlags);
            nFlag = lCacheFlags & (int)WMS_DATA_CONTAINER_VERSION_CACHE_FLAGS.WMS_DATA_CONTAINER_VERSION_ALLOW_PROXY_CACHING;

            ci.CacheFlags = lCacheFlags;
            //content size
            int nLowVal=0, nHighVal=0;
            DCV.GetContentSize(out nLowVal,out nHighVal);
            ci.ContentSize = nLowVal;

            //content type
            int nContentType = 0;
            pContentInfo.GetLongValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_TYPE,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_TYPE_ID,out nContentType,0);
            ci.ContentType = nContentType;

            //expiration time
            DateTime time = new DateTime(0);

            //last modified
            DCV.GetLastModifiedTime(out time);
            ci.LastModified = time;

            //following call throws exception
            // when this is a bpp sourcing from encoder
            // so we don't call it based on the lastmodified time

            if(((ci.ContentType &1)!=0) && time.Year==1899)
            {
            }
            else
            {
                DCV.GetExpirationTime(out time);
                try
                {
                    ci.ExpirationTime = time;
                }
                catch(Exception e)
                {
                    //if this call fails, we just ignore
                    Debug.WriteLine(e);
                }
            }
            //Subscription flags
            int nSubFlag=0;
            pContentInfo.GetLongValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_EVENT_SUBSCRIPTIONS
                ,WMSDefines.WMS_CACHE_CONTENT_INFORMATION_EVENT_SUBSCRIPTIONS_ID,out nSubFlag,0);
            ci.SubscriptionFlag = nSubFlag;

            //clear previous entries
            ci.EntityTags.Clear();
            int nTagCount = 0;
            DCV.GetEntityTagCount(out nTagCount);
            for(int i=0;i<nTagCount;i++)
            {
                string tag;
                DCV.GetEntityTag(i,out tag);
                ci.EntityTags.Insert(i,tag);
            }
        }
Exemplo n.º 13
0
 public void InitializePlugin(IWMSContext pServerContext, WMSNamedValues pNamedValues, IWMSClassObject pClassFactory)
 {
     log.Info("plugin initialize event");
 }
Exemplo n.º 14
0
 void IWMSBasicPlugin.InitializePlugin(IWMSContext ServerContext,
                               WMSNamedValues NamedValues,
                               IWMSClassObject ClassFactory)
 {
 }
Exemplo n.º 15
0
        // based on the response
        // we reply as a hit or miss
        // and update database accordingly
        void IWMSCacheProxyServerCallback.OnCompareContentInformation(
			int lHr,
			WMS_CACHE_VERSION_COMPARE_RESPONSE CompareResponse,
			IWMSContext pNewContentInfo,
			object varContext
			)
        {
            Debug.WriteLine("CacheProxyPlugin::IWMSCacheProxyServerCallback.OnCompareContentInformation entered");
            WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS;
            ContentInfo ci = (ContentInfo)varContext;
            // we use this content info  to call back by default
            // it changes if the CI in our database is valid
            IWMSContext pContenInfo = pNewContentInfo;
            // if the call failed, we have to go for protocol rollover etc
            if(lHr==0)
            {
                switch (CompareResponse)
                {
                    case WMS_CACHE_VERSION_COMPARE_RESPONSE.WMS_CACHE_VERSION_CACHE_STALE:
                    {
                        RemoveEntryFromDatabase(ci,true);
                    }
                        break;

                    case WMS_CACHE_VERSION_COMPARE_RESPONSE.WMS_CACHE_VERSION_CACHE_UP_TO_DATE:
                    {
                        if((ci.ContentType & 1 )!=0) // it's a brodcast content
                        {
                            Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_BROADCAST;
                        }
                        else
                        {
                            Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND;
                        }
                        // update the database with the new information
                        RemoveEntryFromDatabase(ci,false);
                        GetContentInfoFromContext(pNewContentInfo,ref ci);
                        UpdateTable(ci);

                        GetContentInfoContext(ci,out pContenInfo);
                    }
                        break;
                    case WMS_CACHE_VERSION_COMPARE_RESPONSE.WMS_CACHE_VERSION_FAIL_TO_CHECK_VERSION:
                    {
                    }
                        break;

                    default:
                        break;
                }

                Debug.WriteLine("CacheProxyPlugin::IWMSCacheProxyServerCallback.OnCompareContentInformation -> calling OnQueryCache");

                // crude test...look up if we have :// embedded in the URL, if not prefix it with file://
                // otherwise just let it go
                int nIndex = ci.CacheUrl.IndexOf("://");
                string strCacheUrl = ci.CacheUrl;
                if(nIndex==-1)
                {
                    strCacheUrl = string.Format("file://{0}",ci.CacheUrl);
                }

                ci.CacheProxyCallback.OnQueryCache(0,Response,strCacheUrl,pContenInfo,
                    null,ci.varContext);

            }

            return;
        }
Exemplo n.º 16
0
        void IWMSCacheProxyServerCallback.OnDownloadContentProgress(
			int lHr,
			WMS_RECORD_PROGRESS_OPCODE opCode,
			IWMSContext pArchiveContext,
			object varContext
			)
        {
            Debug.WriteLine("CacheProxyPlugin::IWMSCacheProxyServerCallback.OnDownloadContentProgress entered");
            if(lHr==0)
            {
                if(opCode==WMS_RECORD_PROGRESS_OPCODE.WMS_RECORD_PROGRESS_ARCHIVE_STARTED)
                {
                    INSSBuffer NSBuffer=null;
                    Guid guid = typeof(INSSBuffer).GUID;
                    Object obj;
                    pArchiveContext.GetAndQueryIUnknownValue(WMSDefines.WMS_ARCHIVE_CONTENT_DESCRIPTION_LIST_BUFFER,
                        WMSDefines.WMS_ARCHIVE_CONTENT_DESCRIPTION_LIST_BUFFER_ID,ref guid,out obj ,0);
                    NSBuffer = (INSSBuffer)obj;

                    // get the file name
                    string CacheFile;
                    pArchiveContext.GetStringValue(WMSDefines.WMS_ARCHIVE_FILENAME,
                        WMSDefines.WMS_ARCHIVE_FILENAME_ID,out CacheFile,0);

                    ContentInfo ci = (ContentInfo)varContext;

                    string s = GetStringFromNSSBuffer(NSBuffer);
                    if((ci.ContentType & 2)==0) // not a playlist
                    {
                        ci.CDLData = s;
                        ci.CacheUrl = CacheFile;
                    }
                    else
                    {
                        PlaylistItem Item = new PlaylistItem();
                        Item.CacheUrl = CacheFile;
                        Item.CDLData = s;
                        ci.CDL.Add((object)Item);
                    }
                }
            }
            return;
        }
Exemplo n.º 17
0
        bool IsContentCached(string Url, out string ReturnURL, out IWMSContext Context, out int ContentType)
        {
            Debug.WriteLine("CacheProxyPlugin::IsContentCached entered");
            ContentType=0;
            ReturnURL=null;

            System.IntPtr punk;
            Type t = typeof(IWMSContext);
            System.Guid guid = t.GUID;
            ClassObject.AllocIWMSContext(ref guid,
                WMS_CONTEXT_TYPE.WMS_CACHE_CONTENT_INFORMATION_CONTEXT_TYPE
                ,null, out punk);
            Context = (IWMSContext)Marshal.GetObjectForIUnknown(punk);

            t = typeof(IWMSDataContainerVersion);
            guid = t.GUID;
            ClassObject.CreateInstance(ref guid, out punk);
            IWMSDataContainerVersion DataContainer =
                (IWMSDataContainerVersion)Marshal.GetObjectForIUnknown(punk);

            Context.SetIUnknownValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION_ID,DataContainer,0);

            // search the database if the specified URL exists
            DataTable dt = DS.Tables["CachedItems"];
            if(dt==null)
            {
                return false;
            }

            string filexpr = string.Format("OriginUrl = '{0}'",Url);

            DataRow[] drows = dt.Select(filexpr);
            if(drows.Length==0)
            {
                return false;
            }

            // we simply assume there will be only one row returned as we enforce
            // primary key constraint

            object ob = (drows[0]["ContentType"]);
            int nVal = Convert.ToInt32(ob);
            Context.SetLongValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_TYPE,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_TYPE_ID,nVal,0);
            ContentType = nVal;

            nVal = Convert.ToInt32((drows[0]["SubscriptionFlag"]));
            Context.SetLongValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_EVENT_SUBSCRIPTIONS,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_EVENT_SUBSCRIPTIONS_ID,nVal,0);

            System.DateTime date = Convert.ToDateTime((drows[0]["LastModified"]));
            DataContainer.SetLastModifiedTime(date);

            date = Convert.ToDateTime(drows[0]["ExpirationTime"]);
            DataContainer.SetExpirationTime(date);

            nVal = Convert.ToInt32((drows[0]["SubscriptionFlag"]));
            DataContainer.SetCacheFlags(nVal);

            System.Int64 n64Val = Convert.ToInt64(drows[0]["ContentSize"]);
            DataContainer.SetContentSize((int)n64Val,0);
            /*
                        string tag = Convert.ToString(drows[0]["EntityTags"]);
                        DataContainer.SetEntityTag(tag);
            */

            string cacheurl=null;
            try
            {
                cacheurl = Convert.ToString(drows[0]["CacheUrl"]);
            }
            catch(Exception e)
            {
                Debug.WriteLine(e);
            }

            // there is no CacheUrl for broadcast content, so we should reply with
            // the OriginUrl
            if((ContentType & 1 )!=0) // it's a brodcast content
            {
                ReturnURL = Url;
            }
            else
            {
                ReturnURL = string.Format("file://{0}",cacheurl);
            }

            return true;
        }
Exemplo n.º 18
0
 //[PreserveSig] can be used as well
 void IWMSProxyContext.FindProxyForURL(IWMSContext pUserContext, string bstrUrl, out string pbstrProxyServer, out uint pdwProxyPort)
 {
     Debug.WriteLine("CacheProxyPlugin::IWMSProxyContext.FindProxyForURL entered");
     throw new COMException("NO ERROR",1);
 }
Exemplo n.º 19
0
 void IWMSCacheItemDescriptor.GetContentInformation(out IWMSContext contentinfo)
 {
     contentinfo=null;
     try
     {
         ContentInfo ci;
         Collection.Plugin.GetContentInfo(Convert.ToString(Row["OriginUrl"]),out ci);
         Collection.Plugin.GetContentInfoContext(ci,out contentinfo);
     }
     catch(Exception e)
     {
         Debug.WriteLine(e);
         throw new COMException("NO ERROR",1);
     }
 }
Exemplo n.º 20
0
        void AddCDLToContext(IWMSContext pContentInfo,ContentInfo ci)
        {
            IWMSDataContainerVersion DCV = null;
            Type t = typeof(IWMSDataContainerVersion);
            Guid guid = t.GUID;
            object odcv = (object)DCV;
            /*
            pContentInfo.GetAndQueryIUnknownValue("WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION",
                3,ref guid,out odcv, 0);
            */
            pContentInfo.GetAndQueryIUnknownValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION_ID,ref guid,out odcv, 0);
            DCV = (IWMSDataContainerVersion)odcv;

            if(ci.EntityTags!=null)
            {
                foreach(string str in ci.EntityTags)
                {
                    DCV.SetEntityTag(str);
                }
            }
        }
Exemplo n.º 21
0
        public void GetContentInfoContext(ContentInfo ci, out IWMSContext Context)
        {
            Debug.WriteLine("CacheProxyPlugin::GetContentInfoContext entered");
            System.IntPtr punk;
            Type t = typeof(IWMSContext);
            System.Guid guid = t.GUID;
            ClassObject.AllocIWMSContext(ref guid,
                WMS_CONTEXT_TYPE.WMS_CACHE_CONTENT_INFORMATION_CONTEXT_TYPE
                ,null, out punk);
            Context = (IWMSContext)Marshal.GetObjectForIUnknown(punk);

            t = typeof(IWMSDataContainerVersion);
            guid = t.GUID;
            ClassObject.CreateInstance(ref guid, out punk);
            IWMSDataContainerVersion DataContainer =
                (IWMSDataContainerVersion)Marshal.GetObjectForIUnknown(punk);
            Context.SetIUnknownValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_DATA_CONTAINER_VERSION_ID,DataContainer,0);

            Context.SetLongValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_TYPE,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_TYPE_ID,ci.ContentType,0);
            Context.SetLongValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_EVENT_SUBSCRIPTIONS,
                WMSDefines.WMS_CACHE_CONTENT_INFORMATION_EVENT_SUBSCRIPTIONS_ID,ci.SubscriptionFlag,0);
            DataContainer.SetLastModifiedTime(ci.LastModified);
            DataContainer.SetExpirationTime(ci.ExpirationTime);
            DataContainer.SetCacheFlags(ci.CacheFlags);
            DataContainer.SetContentSize((int)ci.ContentSize,0);

            if(ci.EntityTags!=null)
            {
                foreach(string str in ci.EntityTags)
                {
                    DataContainer.SetEntityTag(str);
                }
            }

            guid = typeof(IWMSContext).GUID;
            if((ci.ContentType & 2) == 0) // not a playlist
            {
                //create a CDL context and make it point to the INSSBuffer that we persisted
                ClassObject.AllocIWMSContext(ref guid,
                    WMS_CONTEXT_TYPE.WMS_UNKNOWN_CONTEXT_TYPE
                    ,null, out punk);
                IWMSContext CDLContext = (IWMSContext)Marshal.GetObjectForIUnknown(punk);
                INSSBufferImpl Buffer = new INSSBufferImpl();
                Buffer.SetBuffer(ci.CDLData);
                INSSBuffer pBuffer = Buffer as INSSBuffer;
                CDLContext.SetIUnknownValue("CDL",0,(object)pBuffer,2);

                Context.SetIUnknownValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_DESCRIPTION_LISTS,
                    WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_DESCRIPTION_LISTS_ID,(object)CDLContext,0);
            }
            else
            {
                // create CDL for each file of the playlist
                // get the list of entries from PlaylistItem table corresponding to this Origin URL
                // for each of the entry
                // create CDL data and stuff it with the Context
                // query would be like select * from PlaylistEntries where OriginUrl=ci.OriginUrl
                DataTable dtPlaylist = DS.Tables["PlaylistEntries"];
                string filter = string.Format("OriginUrl='{0}'",ci.OriginUrl);
                DataRow[] rows = dtPlaylist.Select(filter);

                ClassObject.AllocIWMSContext(ref guid,
                    WMS_CONTEXT_TYPE.WMS_UNKNOWN_CONTEXT_TYPE
                    ,null, out punk);
                IWMSContext CDLContext = (IWMSContext)Marshal.GetObjectForIUnknown(punk);
                foreach( DataRow row in rows)
                {

                    INSSBufferImpl Buffer = new INSSBufferImpl();
                    Buffer.SetBuffer(Convert.ToString(row["CDLData"]));
                    INSSBuffer pBuffer = Buffer as INSSBuffer;
                    CDLContext.SetIUnknownValue(Convert.ToString(row["CacheID"]),0,(object)pBuffer,2);
                }
                Context.SetIUnknownValue(WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_DESCRIPTION_LISTS
                    ,WMSDefines.WMS_CACHE_CONTENT_INFORMATION_CONTENT_DESCRIPTION_LISTS_ID
                    ,(object)CDLContext,0);

            }
        }
Exemplo n.º 22
0
        void IWMSBasicPlugin.InitializePlugin(IWMSContext pServerContext, 
            WMSNamedValues pNamedValues, 
            IWMSClassObject pClassFactory)
        {
            Debug.WriteLine("CacheProxyPlugin::InitializePlugin entered");
            Console.WriteLine( "IWMSBasicPlugin.InitializePlugin entered" );
            ClassObject = pClassFactory;
            Type t = typeof(IWMSCacheProxyServer);
            Guid guid = t.GUID;
            Object obj;
            pServerContext.GetAndQueryIUnknownValue(WMSDefines.WMS_SERVER_CACHE_MANAGER,WMSDefines.WMS_SERVER_CACHE_MANAGER_ID,
                ref guid,out obj ,0);
            CacheProxyServer = (IWMSCacheProxyServer)obj;

            //load config file
            LoadConfig();
            if( null != AdminSettings )
            {
                AdminSettings.NamedValues = pNamedValues;
            }
        }
Exemplo n.º 23
0
 public void InitializePlugin(IWMSContext pServerContext, WMSNamedValues pNamedValues, IWMSClassObject pClassFactory)
 {
 }