Theater SDK Banner 

Art
[Previous][Next]

Pay-per-View Authorization Component Sample

The Pay-per-View Authorization Component sample, written in C++, provides a working example of how to write a NetShow Theater Server authorization plug-in component. The source code can be found in the \NetShowTheaterRoot\SDK\Samples\Authorization\ppv directory. Here, \NetShowTheaterRoot is the root directory in which NetShow Theater Server is installed.

You can build and register the sample component either in Visual Studio 97 (by opening NSPayPerViewPlugin.dsw workspace file and then, on the Tools menu, clicking Build) or from an MS-DOS shell (by typing the NMAKE -f NSPayPerViewPlugin.mak command).

You also must run the ppv.reg script in the \NetShowTheaterRoot\SDK\Samples\Commerce\Dlls\ directory to add the \HKEY_LOCAL\MACHINE\Software\Microsoft\NetShow\Servers\Default\Event Notification\PayPerView Module key to the registry. The computer running NetShow Theater Server uses this key to determine if this sample authorization plug-in component is to be used for event authorization. The registry entry contains the information about the data source as well as the user name and/or password that must be used to access the data source. The database schema is specified in \NetShowTheaterRoot\SDK\Samples\Commerce\Store\Config\SQL\SQLSvr\schema.sql.

About the Component and its Design

The Pay-per-View authorization component implements a business logic to grant permission for a client to view a NetShow Theater Server title if the user has paid for that title. Authorization is performed against the information available in the connected database. The time frame in which the user is allowed to view the title is determined by entries in the database that were set when the user made the payment. The user can view the entire title as long as he or she starts viewing it before the allotted time expires. For example, if a movie is 90 minutes long and the user starts to watch it one minute before the payment schedule expires, the user can watch the whole movie without any restrictions. The Pay-per-View authorization component is only activated when the open title has the PPV Charge Type attribute.

The main class is NSPayPerView, which implements the INNSEventNotification and INNSEventAuthorization interfaces for NetShow Theater Server event notification and authorization. The NSPayPerView class handles all the communications to and from the computer running NetShow Theater Server. It notifies the server of the type of events it will handle for notification and/or authorization (see GetHandledEvents and GetAuthorizedEvents). It responds to NetShow Theater Server authorization requests and event notifications from the server (see AuthorizeEvent, OnEvent, OnHeartBeat). It notifies the server of the result of authorization, by invoking the OnEventAuthorized callback function, after receiving an AuthorizeEvent call. Because calls to AuthorizeEvent, OnEvent, and OnHeartBeat must return asynchronously (so as not to tie up a server thread for too long), most of the actual work involved in authorization and event notification is passed to separate worker threads (see WorkerThreadProc) through a Windows I/O completion port. The NSPayPerView class also uses the CDataAccess class to maintain a connection to an ADO/ODBC data source for executing database queries and updates. The NSPayPerView and CDataAccess classes are contained in the NSPayPerView.cpp and CDataAccess.cpp files, respectively.

NSPayPerView Object

The NSPayPerView object uses a CAuthRequest data structure to hold information regarding an authorization request in order to pass information from the authorization request to the OPEN and CLOSE events. A pointer to this data structure is stored in the PPVContextPointer attribute of the presentation context,

Upon initialization, the NSPayPerView object first retrieves the data source and database user logon information from the \HKEY_LOCAL_MACHINE\Software\NetShow\Servers\Default\Event Notification\PayPerView Module registry key. It then creates an instance of the CDataAccess class that uses the user name and password retrieved from the registry to open a connection to the data source. It also spawns a number of worker threads that are later used to process the authorization and event handling requests.

The GetHandledEvents method specifies that the component handles only OPEN and CLOSE events, while the GetAuthorizedEvents method specifies that only SKIP_AUTHENTICATION and OPEN events are subject to authorization. You can customize these methods if you have different authorization and event notification needs.

When a user attempts to open a title, the computer running NetShow Theater Server first queries the component to determine whether authentication is required. The component then checks if the title is of the PPV Charge Type, and, if so, responds that authentication is required.

After authenticating the user by using a separate authentication component, the server then requests that the Pay-per-View component authorize the OPEN event. The component authorizes the OPEN event if the user has paid for this specific PPV title and the current time is within the allotted time slot. When this happens, a counter is incremented in the PPV record in the database to ensure that only one user at a time is watching the title.

At this point, a CAuthRequest data structure is created and stored in the PPVContextPointer attribute of the presentation context. When the server notifies the component of the CLOSE event, the counter is decremented to allow for future viewing (as long as it is within the allotted time frame).

Data Access Object

The Data Access Object, an instance of the CDataAccess class, manages connections to an ADO/ODBC data source in order to carry out queries and updates to the database. Following is a summary of the database-related operations:

Verifying that the Pay-per-View payment plan is required for playing a given title (see the RequirePayment method). Verifying that the viewer has paid the fee to watch a title (see the CheckPayment method). Updating the active count of the title when the user opens the stream (see the CommitOpenViewing method). Updating the active count when the user closes the stream (see the CommitCloseViewing method).

[Previous][Next]



© 1996-1998 Microsoft Corporation. All rights reserved