Example #1
0
/** Stop control on a service. Removes the HTTP server binding for this
    service's control URL.

    @return error code
 */
int  UPnP_DeviceControlUnBindService (
		UPnPDeviceRuntime *deviceRuntime, /** the device runtime that owns the
		                                      service. */
		UPnPService *service              /** the service to unbind */)
{
HTTP_CHAR *path = _getControlURL(service->device->rootDevice->descDoc, service->serviceElement);

	if (path)
	{
		/* build the event URL from the baseURL and eventSubURL in the DOM */

		if (HTTP_ServerRemovePath(&deviceRuntime->upnpRuntime->httpServer,
								  path) < 0)
		{
			rtp_free(path);
			return (-1);
		}

		SOAP_ServerShutdown(&service->soapContext);

		rtp_free(path);
		return (0);
	}

	return (-1);
}
Example #2
0
/** Initialize a service for control. Binds a service control URL to the
    HTTP server to enable SOAP action processing for that service.

    @return error code
 */
int  UPnP_DeviceControlBindService (
		UPnPDeviceRuntime *deviceRuntime, /** the device runtime that owns the
		                                      service. */
        UPnPService *service              /** the service to bind */)
{
	HTTP_CHAR *path = _getControlURL(service->device->rootDevice->descDoc, service->serviceElement);

	if (path)
	{
		if (SOAP_ServerInit(&service->soapContext, UPnP_DeviceControlSOAPCallback, service) < 0)
		{
			rtp_free(path);
			return (-1);
		}

		if (HTTP_ServerAddPath(&deviceRuntime->upnpRuntime->httpServer,
							   path,
							   1,
							   (HTTPRequestHandler)SOAP_ServerProcessRequest,
							   0,
							   &service->soapContext) < 0)
		{
			rtp_free(path);
			SOAP_ServerShutdown(&service->soapContext);
			return (-1);
		}

		rtp_free(path);
		return (0);
	}

	return (-1);
}
Example #3
0
/** @memo   Close a file.

    @doc    Closes a file that was opened with rtp_stdio_fopen.

    @return 0 if successful, -1 otherwise.
 */
int rtp_stdio_fclose (
  void * rtpfile                        /** File handle used to close the file. */
  )
{
int result = (-1);

    if( !rtpfile || (((RTP_STDIO_FILE *)rtpfile)->verify != RTP_FILE_VERIFICATION_VALUE) )
    {
        /* --------------------------------------- */
        /*  Application passed an RTP_HANDLE       */
        /*  instead of an RTP_STDIO_FILE. Should   */
		/*  use low level rtp_file_close().        */
        /* --------------------------------------- */
        return (-1);
    }

    result = rtp_file_close (((RTP_STDIO_FILE *)rtpfile)->handle);
    if (((RTP_STDIO_FILE *)rtpfile)->buffer)
    {
        rtp_free ((void *)((RTP_STDIO_FILE *)rtpfile)->buffer);
    }
    rtp_free (rtpfile);
    rtpfile = (void *) 0;
    return (result);
}
Example #4
0
static void http_demo_release_vcontent(HTTP_INT32 virtUrlId, char **pContent)
{
	HTTP_INT32 length = 0;
	char **_pContent = pContent;
	while (*_pContent)
	{
		rtp_free(*_pContent);
		_pContent++;
	}
	rtp_free(pContent);
}
Example #5
0
/*----------------------------------------------------------------------*
                             rtp_wfile_gfirst
 *----------------------------------------------------------------------*/
int rtp_wfile_gfirst (void ** dirobj, unsigned short * name)
{
#if (_WIN32_WINNT) >= 0x0400
WFSOBJ* winDirObj;

#ifdef RTP_DEBUG
  
    SetLastError (0);
#endif

    winDirObj = (WFSOBJ*) malloc(sizeof(WFSOBJ));
    memset(winDirObj, 0, sizeof(WFSOBJ));

    name = _rtp_unicode_name_to_winname(name);
    winDirObj->fsObject.attrib = _A_NORMAL | _A_SUBDIR;
    winDirObj->handle = _wfindfirst((const unsigned short *) name, &(winDirObj->fsObject));
    if (winDirObj->handle == (long)(-1))
    {
        rtp_free (winDirObj);
#ifdef RTP_DEBUG
		RTP_DEBUG_OUTPUT_ERRNO("rtp_wfile_gfirst:");
#endif
        return (-1);
    }

    *dirobj = (void*) winDirObj;
    return (0);
#endif
	return (-1);
}
Example #6
0
/*----------------------------------------------------------------------*
                         rtp_sig_semaphore_free
 *----------------------------------------------------------------------*/
void rtp_sig_semaphore_free (RTP_SEMAPHORE semHandle)
{
    NATIVE_PROFILE_PAL_NETWORK();

	rtp_free((void *)semHandle);

}
Example #7
0
int _UPnP_DeviceSendServiceAlive(
     UPnPService *service /** pointer to the service */)
{
    char notifySubType[11];  /* holds ssdp:alive */
    char destAddr[RTP_NET_NI_MAXHOST];
    char *usn;
    UPnPRootDevice *rootDevice = service->device->rootDevice;
    char *descLocation;
    int result = -1;
    int ipType = service->device->rootDevice->deviceRuntime->upnpRuntime->ssdpContext.ipType;

    /* proceed if complete device information is available */
    if(!service->serviceId || !service->serviceType || !service->device->rootDevice->descLocation)
    {
        return (-1);
    }

    if (ipType == RTP_NET_TYPE_IPV4)
    {
	    rtp_strcpy(destAddr, (const char *) v4mcastAddr);
	}
	else if (ipType == RTP_NET_TYPE_IPV6)
	{
		rtp_strcpy(destAddr, IPV6_LINK_LOCAL_ADDRESS);
	}

	descLocation = _getLocation((unsigned char *) destAddr, mcastPort, ipType, rootDevice);

	if (descLocation)
	{
		/* allocate memory to notifytype to hold UDN, devicetype, :: and a string terminator */
		usn = (char *) rtp_malloc((rtp_strlen(service->serviceId) + rtp_strlen(service->serviceType) + 3));

		if (usn)
		{
			/* create a notify type using device UDN and device type */
			rtp_strcpy(usn, service->serviceId);
			rtp_strcat(usn, "::");
			rtp_strcat(usn, service->serviceType);

			rtp_strcpy(notifySubType, "ssdp:alive");

			/* service advertisement */
			if(SSDP_SendAlive (&rootDevice->deviceRuntime->upnpRuntime->ssdpContext,
			                   service->serviceType,
			                   usn,
			                   descLocation,
			                   (SSDP_UINT32*)&rootDevice->deviceRuntime->remoteCacheTimeoutSec) >= 0)
			{
				result = 0;
			}

			rtp_free(usn);
		}

		_freeLocation(rootDevice, descLocation);
	}

    return (result);
}
static int DestroySlidingWindow(HBROWSER_HANDLE hbrowser, HDOC_HANDLE hdoc, struct _webcSlidingWindowView *slideObject)
{
HELEMENT_HANDLE SlideWindow;

	SlideWindow = webc_ElementGetParent(slideObject->SlidingElement);
	if (!SlideWindow)
		goto error;
	/* Hide the sliding window */
  	webc_ElementHide(slideObject->SlidingElement, WEBC_TRUE);
	/* Hide the viewport window */
  	webc_ElementHide(SlideWindow, WEBC_TRUE);
	/* Remove the slidewindow from the viewport */
	webc_ElementRemoveChild(SlideWindow,slideObject->SlidingElement);
	/* Delete the selections we */
	webc_ElementDeleteChildren(slideObject->SlidingElement);
	/* Delete the slider */
	webc_ElementDelete(slideObject->SlidingElement);
	/* Delete the viewport window */
	webc_ElementRemoveChild (webc_GetRootContainer(hdoc),SlideWindow);
	webc_ElementDelete(SlideWindow);

// webc_ElementRedraw(webc_GetRootContainer(hdoc));

	rtp_free(slideObject);
	return 0;
error:
	assert(0);
	return -1;
}
Example #9
0
void _freeLocation (UPnPRootDevice *rootDevice, char *str)
{
	if (rootDevice->autoAddr)
	{
		rtp_free(str);
	}
}
Example #10
0
/*----------------------------------------------------------------------*
                             rtp_file_gfirst
 *----------------------------------------------------------------------*/
int rtp_file_gfirst (void ** dirobj, char * name)
{
VDSTAT* nativeDirObj;

#ifdef RTP_DEBUG
    int result;
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    set_errno (0);
#endif

    nativeDirObj = (VDSTAT*) rtp_malloc(sizeof(VDSTAT));
    rtp_memset(nativeDirObj, 0, sizeof(VDSTAT));

	if (!vf_gfirst(nativeDirObj, (PFCHAR) name))
    {
        rtp_free(nativeDirObj);
#ifdef RTP_DEBUG
        result = xn_getlasterror( );
        RTP_DEBUG_OUTPUT_STR("rtp_file_gfirst: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }

    *dirobj = (void*) nativeDirObj;
    return (0);
}
Example #11
0
SSDP_INT32 SSDP_SendResponse (
    SSDPServerContext *ctx,       /** pointer to SSDP context */
    SSDPPendingResponse *response /** buffer holding response information */)
{
    SSDP_CHAR     *msgBuffer;
    SSDP_SOCKET    responseSock = ctx->announceSocket;

    msgBuffer = (SSDP_CHAR *) rtp_malloc(sizeof(SSDP_CHAR) * SSDP_BUFFER_SIZE);

    if (msgBuffer)
    {
        /* Send response */
        rtp_sprintf(msgBuffer,"HTTP/1.1 200 OK\r\n"
                    "LOCATION: %s\r\n"
                    "EXT: \r\n"
                    "USN: %s\r\n"
                    "SERVER: %s\r\n"
                    "CACHE-CONTROL: max-age=%d\r\n"
                    "ST: %s\r\n"
                    "\r\n",
                    response->targetLocation,
                    response->targetUSN,
                    ctx->serverName,
                    response->targetTimeoutSec,
                    response->searchTarget);

        RTP_LOG_WRITE("SSDPSendResponse SEND", msgBuffer, rtp_strlen(msgBuffer))

        /* Send response to the requesting client */
        if (rtp_net_sendto(responseSock, (unsigned char*)msgBuffer,
                           rtp_strlen(msgBuffer),
                           response->clientAddr.ipAddr,
                           response->clientAddr.port,
                           response->clientAddr.type) < 0)
        {
            SSDP_ProcessError("Response");
            rtp_free(msgBuffer);
            return(-1);
        }

        /* Free up the allocated memory */
        rtp_free(msgBuffer);
    }
    else
    {
        return (-1);
Example #12
0
static void FlyingWindowCloseCallback(int UserIntParm, void *UserVoidParm)
{
	wcWinClose((wcCtx*)UserVoidParm);
	rtp_free(UserVoidParm);
	if (!FlyWithNoSpriteDone)
		StartFlyingWindowDemo(0,10, 0);
	FlyWithNoSpriteDone = 1;
}
Example #13
0
/** @memo   Release all memory used by a list or menu object.

    @doc    Releases all memory used by the list or menu object. Must be called to release memory
	allocated while the object was created and populated.

    @precondition rtp_gui_list_init must be called first

    @return Nothing
*/
void rtp_gui_list_destroy(void *vplist /** Handle returned from rtp_gui_list_init() */)
{
	struct rtp_gui_list *plist;
	plist = (struct rtp_gui_list *) vplist;
	{
	struct rtp_gui_list_item *pnext, *pthis;
		pthis = plist->itemlist;
		while (pthis)
		{
			if (pthis->item)
				rtp_free(pthis->item);
			pnext = pthis->pnext;
			rtp_free(pthis);
			pthis = pnext;
		}
	}
	rtp_free(plist);
}
Example #14
0
File: upnp.c Project: maojxsir/upnp
/**
	@memo Destroy a UPnPRuntime

	@doc
		Must be called after all other UPnP SDK calls to clean up runtime
		data for UPnP.

    @return error code
 */
void UPnP_RuntimeDestroy (
		UPnPRuntime* rt   /** pointer to \Ref{UPnPRuntime} struct */
	)
{
	HTTPServerConnection* connectCtxArray;

	SSDP_ServerDestroy(&rt->ssdpContext);
	HTTP_ServerDestroy(&rt->httpServer, &connectCtxArray);
	rtp_free(connectCtxArray);
}
Example #15
0
SOAP_INT32 SOAP_SendActionRequest (
		SOAPAction* action
	)
{
	SOAP_CHAR*    requestBuffer;
	SOAP_INT32    contentLen;
	HTTPRequest   request;

	/* Create soap envelope for the request */
	requestBuffer = (char *)rtp_malloc(action->bodyLen +
						SOAP_ACTION_ENVELOPE_LENGTH);
	if (requestBuffer)
	{
		rtp_sprintf(requestBuffer, SOAP_ACTION_REQUEST_TEMPLATE,
					   action->bodyStr);

		/* get the length of the envelope which is the content length of SOAP Request */
		contentLen = rtp_strlen(requestBuffer);

		/* send a Post or a M-Post request */
		switch(action->state)
		{
			case SOAP_ACTION_CONNECTING_POST:
				/* Create soap envelope for the request */
#if (USE_EXPERIMENTAL_REQUEST)
				HTTP_ManagedClientRequestExExperimental(action->httpSession, "POST", action->postTargetURL.field.http.path, NULL,
					"text/xml; charset=\"utf-8\"", &contentLen, &request, "SOAPAction", action->soapAction);
#else
				HTTP_ManagedClientRequestEx (action->httpSession, "POST", action->postTargetURL.field.http.path, NULL,
					"text/xml; charset=\"utf-8\"", contentLen, &request);
#endif
				break;

			case SOAP_ACTION_CONNECTING_M_POST:
				HTTP_ManagedClientRequestEx (action->httpSession, "M-POST", action->postTargetURL.field.http.path, NULL,
					"text/xml; charset=\"utf-8\"", contentLen, &request);
				HTTP_SetRequestHeaderStr (&request, "Man", "\"http://schemas.xmlsoap.org/soap/envelope/\"; ns=s");
				HTTP_SetRequestHeaderStr (&request, "s-SOAPAction", action->soapAction);
				break;
		}
		HTTP_ManagedClientRequestHeaderDone (action->httpSession, &request);

		/* write the POST data */
		HTTP_ManagedClientWrite (action->httpSession, (SOAP_UINT8*)requestBuffer, contentLen);

		/* signal that the request is compete */
		HTTP_ManagedClientWriteDone (action->httpSession);

		rtp_free(requestBuffer);

		return(0);
	}

	return (-1);
}
Example #16
0
static int _LoadPalleteFromPalletTemplate(HBROWSER_HANDLE hbrowser, HDOC_HANDLE hdoc, int isShadow)
{
char newhtml[256];
IXML_Element *ParentElement;
IXML_Element *xmlElement;
IXML_Document *Doc = PalletTemplate;
char *lbuffer,*p;
HELEMENT_HANDLE h;

	p = (char *) rtp_malloc(100000);
	lbuffer = p;
	*p = 0;
	newhtml[0] = 0;
	if (isShadow)
		h = webc_DocFindElement (hdoc, "ShadowPallete", 0, HTML_ELEMENT_ANY, 0);
	else
		h = webc_DocFindElement (hdoc, "Pallete", 0, HTML_ELEMENT_ANY, 0);
	if (!h)
		goto error;
	xmlElement = 0;
	ParentElement = rtpxmlGetElemInDocFromDomStr(Doc, PALLETDOMSTR); /* "PalletImages" */
	if (ParentElement)
		xmlElement = (IXML_Element *)ixmlNode_getFirstChild((IXML_Node*) ParentElement);
	while (xmlElement)
	{
		if (xmlPalletElementToHtml(xmlElement, newhtml, isShadow) != 0)
			goto error;
		rtp_strcat(p,newhtml); p += rtp_strlen(p);
		xmlElement = (IXML_Element *) ixmlNode_getNextSibling((IXML_Node*) xmlElement);
	}
	webc_ElementSetInnerHtmlASCII (h, lbuffer);
	if (lbuffer)
		rtp_free(lbuffer);
	return 0;
error:
	if (lbuffer)
		rtp_free(lbuffer);
	printf("Error CreatePalleteFromPalletTemplate()\n");
	assert(0);
  	return -1;
}
Example #17
0
/*----------------------------------------------------------------------*
                           rtp_threads_shutdown
 *----------------------------------------------------------------------*/
void rtp_threads_shutdown (void)
{
    NATIVE_PROFILE_PAL_NETWORK();
    int i;
    
    for (i = 0; i < CFG_NIFACES; i++)
    {
        IPTaskInitialized[i] = 0;
        InterruptTaskContInitialized[i] = 0;
    }
    TimerTaskContInitialized = 0;        
    TimerTaskCompInitialized = 0;                 
    DHCPTaskInitialized = 0;                     
    
#if (INCLUDE_RUN_TIME_CONFIG)
     rtp_free(IPTaskContinuation);           
     rtp_free(InterruptTaskContinuation);
     rtp_free(IPTaskInitialized);  
     rtp_free(InterruptTaskContInitialized);  
#endif
}
Example #18
0
/** @memo   Add an text entry and a void * value a list or menu object.

    @doc    Adds text and to a list or object. Also provides a void * value to attach to the item that will be returned
    when the item is selected. <br>
    If rtp_gui_list_execute() is called itemvalue will be returned. <br>
    If rtp_gui_list_execute_handle() is called the handle to the item is returned.

    @precondition rtp_gui_list_init must be called first.

    @return A handle to the menu or list entry object.
*/
void *rtp_gui_list_add_item(void *vplist, /** Handle returned from rtp_gui_list_init(). */
char *item, 							  /** Text to display for the choice. */
void *itemvalue,						  /** void *value to return when the item is selected. */
int indentlevel, 						  /** Spaces to indent when text is displayed. */
int isgreyed, 							  /** 1 if the item may not be selected. */
int style								  /** Additional style attributes. <br>
RTP_LIST_ITEM_STYLE_NOBREAK - Display this and the next list item side by side. <br>
RTP_LIST_ITEM_STYLE_SUBMENU - Itemvalue is a menu or list handle returned from rtp_gui_list_init(). <br>
RTP_LIST_ITEM_STYLE_COLLAPSED - Don't display the submenu/sublist.<br>
RTP_LIST_ITEM_STYLE_EXPANDED  - Expand and display the submenu/sublist. <br>
*/
)
{
	struct rtp_gui_list *plist;
	struct rtp_gui_list_item *newitem;

	plist = (struct rtp_gui_list *) vplist;

	newitem = (struct rtp_gui_list_item *) rtp_malloc(sizeof(*newitem));
	if (!newitem)
		return(0);
	rtp_memset(newitem, 0, sizeof(*newitem));
	newitem->item = rtp_strdup(item);
	if (!newitem->item)
	{
		rtp_free(newitem);
		return(0);
	}
	newitem->itemid = itemvalue;
	newitem->indentlevel = indentlevel;
	newitem->isgreyed = isgreyed;
	newitem->style = style;
	{
	struct rtp_gui_list_item *pthis;
		pthis = plist->itemlist;
		if (!pthis)
			plist->itemlist = newitem;
		else
		{
			while (pthis->pnext)
			{
				pthis = pthis->pnext;
			}
			pthis->pnext = newitem;
		}
	}
	plist->itemlistcount += 1;
	return((void *) newitem);
}
Example #19
0
/** @memo
    @doc
close the session ::
    @return error code
 */
void SOAP_ActionDestroy (
		SOAPAction* action
	)
{
	if (action->postTargetURL.buffer)
    {
        rtp_free(action->postTargetURL.buffer);
    }

    if (action->httpSession)
	{
		HTTP_ManagedClientCloseSession(action->httpSession);
		action->httpSession = 0;
	}
}
Example #20
0
/** @memo   Opens a file using the supplied name.

    @doc    Opens a file using the mode settings, and sets the 
    file information.

    @return 0 if successful, -1 on failure, and -2 if a non-fatal 
    error occurred.
 */
int rtp_stdio_fopen (
  void ** rtpfile,                      /** A pointer to the address of an RTP_FILE to store the file information. */
  const char * fname,                   /** The name of the file to open. */
  const char * mode                     /** For the mode argument:<br>
	<pre>
|		"r"     Open a file for reading only                RTP_FILE_O_RDONLY
|		"r+"    Open a file for reading and writing         RTP_FILE_O_RDWR
|		"w"     Open a file for writing only                RTP_FILE_O_WRONLY
|		        Create a file if it does not exist          RTP_FILE_O_CREAT
|		        Truncate a file to 0 bytes after opening    RTP_FILE_O_TRUNC
|		"w+"    Open a file for reading and writing         RTP_FILE_O_RDWR
|		        Create a file if it does not exist          RTP_FILE_O_CREAT
|		        Truncate a file to 0 bytes after opening    RTP_FILE_O_TRUNC
|		"a"     All writes will be appended to the file     RTP_FILE_O_APPEND
|		        Create a file if it does not exist          RTP_FILE_O_CREAT
|		"a+"    Open a file for reading and writing         RTP_FILE_O_RDWR
|		        All writes will be appended to the file     RTP_FILE_O_APPEND
|		        Create a file if it does not exist          RTP_FILE_O_CREAT
|		"b..."  b prepended to the mode in the open call    
|		        causes the file to be opened in binary mode RTP_FILE_O_BINARY
|		"t..."  t prepended to the mode in the open call    
|		        causes the file to be opened in text mode   RTP_FILE_O_TEXT
|		Note:   If neither the b or t are prepended, text   
|		        mode is the default implementation.         
	</pre> */
  )
{
RTP_STDIO_FILE * p;
int result;

    result = (-1);
    p = (RTP_STDIO_FILE *) rtp_malloc ((unsigned int) sizeof (*p), 0);  /* SPRZ */
    if (p)
    {
        rtp_memset(p, 0, sizeof(*p));
        p->verify = RTP_FILE_VERIFICATION_VALUE;
     
        if ((result = rtp_file_open (&(p->handle), fname, _rtp_mode_to_permission(mode), RTP_FILE_S_IWRITE | RTP_FILE_S_IREAD)) != 0)
        {
            /* --------------------------------------- */
            /*       ERROR: drop the handle block.     */
            /* --------------------------------------- */
            rtp_free ((void *)p);
        }
    }
    *rtpfile = (void *)p;
    return (result);
}
Example #21
0
int http_server_demo(void)
{
	HTTP_INT16 ipType = 4;
	rtp_net_init();
	rtp_threads_init();


	rtp_memset(&ExampleServerCtx, 0, sizeof(ExampleServerCtx));
	rtp_strcpy(ExampleServerCtx.rootDirectory, DEMO_WWW_ROOT);
	ExampleServerCtx.chunkedEncoding 		= 0;
	ExampleServerCtx.numHelperThreads 		= DEMO_MAX_HELPERS;
	ExampleServerCtx.numConnections		 	= DEMO_MAX_CONNECTIONS;
	rtp_strcpy(ExampleServerCtx.defaultFile,"index.htm");
	ExampleServerCtx.defaultIpAddr[0] = DEFAULT_DEMO_IPADDRESS[0];
	ExampleServerCtx.defaultIpAddr[1] = DEFAULT_DEMO_IPADDRESS[1];
	ExampleServerCtx.defaultIpAddr[2] = DEFAULT_DEMO_IPADDRESS[2];
	ExampleServerCtx.defaultIpAddr[3] = DEFAULT_DEMO_IPADDRESS[3];
	rtp_sprintf(ExampleServerCtx.defaultIpAddrstr, "%d.%d.%d.%d",
	ExampleServerCtx.defaultIpAddr[0],	ExampleServerCtx.defaultIpAddr[1],
	ExampleServerCtx.defaultIpAddr[2],	ExampleServerCtx.defaultIpAddr[3]);


	/* Initialize the server */
	if (http_server_demo_restart() != 0)
		return(-1);


	for (;;)
	{
		HTTP_ServerProcessOneRequest (&ExampleServerCtx.httpServer, 1000*60);
		if (ExampleServerCtx.timeToReload)
		{
			ExampleServerCtx.timeToReload = 0;
			HTTP_ServerDestroy(&ExampleServerCtx.httpServer, &ExampleServerCtx.connectCtxArray);
			rtp_free(ExampleServerCtx.connectCtxArray);
			/* Initialize the server */
			if (http_server_demo_restart() != 0)
				return(-1);
		}
	}


	rtp_net_exit();
	return (0);

}
Example #22
0
/*----------------------------------------------------------------------*
                             rtp_wfile_gfirst
 *----------------------------------------------------------------------*/
int rtp_wfile_gfirst (void ** dirobj, unsigned short * name)
{
#if (_WIN32_WINNT) >= 0x0400
WFSOBJ* winDirObj;

#ifdef RTP_DEBUG
    int result;
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    SetLastError (0);
#endif

    winDirObj = (WFSOBJ*) malloc(sizeof(WFSOBJ));
    memset(winDirObj, 0, sizeof(WFSOBJ));

    name = _rtp_unicode_name_to_winname(name);
    winDirObj->fsObject.attrib = _A_NORMAL | _A_SUBDIR;
    winDirObj->handle = _wfindfirst((const unsigned short *) name, &(winDirObj->fsObject));
    if (winDirObj->handle == (long)(-1))
    {
        rtp_free (winDirObj);
#ifdef RTP_DEBUG
        result = GetLastError();
        RTP_DEBUG_OUTPUT_STR("rtp_wfile_gfirst: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }

    *dirobj = (void*) winDirObj;
    return (0);
#endif
	return (-1);
}
Example #23
0
static HTMLEventStatus FlyingWindowBodyCallback(wcCtx* Ctx,	wcEL element,HTMLEvent* event,	char* param)
{ /* Close the Browser window when the dismiss button is clicked. */
int CycleTimer = 0;
int MaxX,MaxY;
struct flyingwindowcontrol *pcontrol;

	MaxX = 600;	// Should call get canvas
	MaxY = 600;

    if (event->type == HTML_EVENT_OBJECT_CREATED)
	{
		struct flyingwindowcontrol *pcontrol;
		pcontrol = (struct flyingwindowcontrol *)rtp_malloc(sizeof(struct flyingwindowcontrol));
		pcontrol->iteration = 0;
		pcontrol->xstep = 4;
		pcontrol->ystep = 2;
		wcPushData(Ctx, element, (void*) pcontrol);
    	CycleTimer = 1;
	}
    else if (event->type == HTML_EVENT_MOUSEDOWN)
	{ // experimental
		pcontrol = (struct flyingwindowcontrol *) wcGetData(Ctx, element);
		wcPopData(Ctx, element);
		rtp_free(pcontrol);
		wcWinClose(Ctx);
		StartFlyingWindowDemo(0, 10, WF_SPRITE);
		return (HTML_EVENT_STATUS_HALT);
	}
    else if (event->type == HTML_EVENT_TIMER)
	{
	int left,top,width,height;
		pcontrol = (struct flyingwindowcontrol *) wcGetData(Ctx, element);
		pcontrol->iteration += 1;
		if (pcontrol->iteration >= FLYINGWINDOWITERATIONS)
		{
			// free private data
			wcPopData(Ctx, element);
			rtp_free(pcontrol);
			// Make a private copy of the stack based context to pass to the Global timer handler
			wcCtx* KillCtx;
			KillCtx = (wcCtx*)rtp_malloc(sizeof(*Ctx));
			*KillCtx = *Ctx;
			// Tell the global timer to call our close callback routine
			wcTimedCallback(FlyingWindowCloseCallback,0, 0, (void *) KillCtx);
			return (HTML_EVENT_STATUS_CONTINUE);
		}
		wcWinGetPos(Ctx, &left, &top, &width, &height);
		left += pcontrol->xstep;
		if (left < 0)
		{
			left = 0;
			pcontrol->xstep *= -1;
		}
		else if (left+width >= MaxX)
		{
			left -= pcontrol->xstep;
			pcontrol->xstep *= -1;
		}
		top += pcontrol->ystep;
		if (top < 0)
		{
			top = 0;
			pcontrol->ystep *= -1;
		}
		else if (top+height >= MaxY)
		{
			top -= pcontrol->ystep;
			pcontrol->ystep *= -1;
		}
		wcWinSetPos(Ctx, left, top, width, height);
    	CycleTimer = 1;
	}

	if (CycleTimer)
	{
		HTMLEvent NewEvent;
		rtp_memset(&NewEvent, 0 ,sizeof(NewEvent));
		NewEvent.type = HTML_EVENT_TIMER;
		wcTriggerEvent(element, &NewEvent, FLYINGWINDOWPERIOD);
    }
	return (HTML_EVENT_STATUS_CONTINUE);
}
Example #24
0
/*---------------------------------------------------------------------------*/
void _HTTP_DeleteHost (
		HTTPAuthenticationHost *host
	)
{
	rtp_free(host);
}
Example #25
0
/*---------------------------------------------------------------------------*/
void _HTTP_DeleteRealm (
		HTTPAuthenticationRealm *realm
	)
{
	rtp_free(realm);
}
Example #26
0
int _UPnP_DeviceSendDeviceByeBye (
     UPnPDevice *device /** address of the device */)
{
    char notifySubType[13];  /* holds ssdp:bye-bye */
    char *usn;
	char *descLocation;
	int   result = -1;
	char destAddr[RTP_NET_NI_MAXHOST];
	int ipType = device->rootDevice->deviceRuntime->upnpRuntime->ssdpContext.ipType;

    /* proceed if complete device information is available */
    if(!device->UDN || !device->deviceType || !device->rootDevice->descLocation)
    {
        return (-1);
    }

	if (ipType == RTP_NET_TYPE_IPV4)
    {
	    rtp_strcpy(destAddr, (const char *) v4mcastAddr);
	}
	else if (ipType == RTP_NET_TYPE_IPV6)
	{
		rtp_strcpy(destAddr, IPV6_LINK_LOCAL_ADDRESS);
	}

	descLocation = _getLocation((unsigned char *) destAddr, mcastPort, ipType, device->rootDevice);


	if (descLocation)
	{
		rtp_strcpy(notifySubType, "ssdp:bye-bye");

		/* first device message of a specific device */
		if(SSDP_SendByebye(&device->rootDevice->deviceRuntime->upnpRuntime->ssdpContext,
						   device->UDN, device->UDN) >= 0)

		{

			/* allocate memory to notifytype to hold UDN, devicetype, :: and a string terminator */
			usn = (char *) rtp_malloc((rtp_strlen(device->UDN) + rtp_strlen(device->deviceType) + 3));
			if (usn)
			{
				/* create a notify type using device UDN and device type */
				rtp_strcpy(usn, device->UDN);
				rtp_strcat(usn, "::");
				rtp_strcat(usn, device->deviceType);

				/* Second device message of a specific device */
				if(SSDP_SendByebye(&device->rootDevice->deviceRuntime->upnpRuntime->ssdpContext,
					   device->UDN, device->UDN) >= 0)
				{
					result = 0;
				}

				rtp_free(usn);
			}
		}

		_freeLocation(device->rootDevice, descLocation);
	}

    return (result);
}
Example #27
0
/*----------------------------------------------------------------------*
                             rtp_file_gdone
 *----------------------------------------------------------------------*/
void rtp_file_gdone (void * dirobj)
{
	vf_gdone((VDSTAT*) dirobj);
    rtp_free(dirobj);
}
Example #28
0
File: upnp.c Project: maojxsir/upnp
/**
	@memo Initialize a UPnPRuntime

	@doc
		Initializes the given \Ref{UPnPRuntime} struct, and sets up an HTTP
		server instance to receive control/event messages.  This function
		must be called before any other function in the UPnP SDK.

    @return error code
 */
int UPnP_RuntimeInit (
		UPnPRuntime* rt,             /** pointer to uninitialized \Ref{UPnPRuntime} struct */
		UPNP_UINT8* serverAddr,      /** ip address to bind HTTP server to (NULL for IP_ADDR_ANY) */
		UPNP_UINT16 serverPort,      /** port to bind HTTP server to (0 for ANY_PORT) */
		UPNP_INT16 ipType,           /** type of ip version used (ipv4 or ipv6), (RTP_NET_TYPE_IPV4 for v4 and RTP_NET_TYPE_IPV6 for v6) */
		UPNP_CHAR* wwwRootDir,       /** HTTP root dir on local file system */
		UPNP_INT16 maxConnections,   /** the maximum limit on simultaneous HTTP server connections */
		UPNP_INT16 maxHelperThreads  /** if UPNP_MULTITHREAD is defined, the max number of helper threads to spawn */
	)
{
	HTTPServerConnection* connectCtxArray;
	rt->ipType = ipType;

	connectCtxArray = (HTTPServerConnection*) rtp_malloc(sizeof(HTTPServerConnection) * maxConnections);
	if (connectCtxArray)
	{
		if (HTTP_ServerInit (
				&rt->httpServer,
				UPNP_SERVER_NAME, // name
				wwwRootDir,       // rootDir
				"index.html",     // defaultFile
				1,                // httpMajorVersion
				1,                // httpMinorVersion
				serverAddr,       // ipAddr
				serverPort,       // port,
				ipType,           // ipversion type(4 or 6)
				0,                // allowKeepAlive
				connectCtxArray,  // connectCtxArray
				maxConnections,   // maxConnections
				maxHelperThreads  // maxHelperThreads
			) >= 0)
		{
			if (SSDP_ServerInit (
					&rt->ssdpContext,
                    serverAddr,
					ipType,
                    "RTPlatform/1.0, UPnP/1.0, EBS UPnPSDK/2.9",
                    UPnP_SSDPCallback,
                    rt
				) >= 0)
			{
			 #ifdef UPNP_MULTITHREAD
                if (rtp_sig_mutex_alloc(&rt->mutex, 0) >= 0)
				{
					rt->daemonState = UPNP_DAEMON_STOPPED;
             #endif /* UPNP_MULTITHREAD */

                    rt->deviceRuntime = 0;
					rt->controlPoint = 0;
					return (0);

             #ifdef UPNP_MULTITHREAD
				}
             #endif /* UPNP_MULTITHREAD */

				SSDP_ServerDestroy(&rt->ssdpContext);
			}

			HTTP_ServerDestroy(&rt->httpServer, &connectCtxArray);
		}

		rtp_free(connectCtxArray);
	}

	return (-1);
}
Example #29
0
/*----------------------------------------------------------------------*
                         rtp_sig_semaphore_free
 *----------------------------------------------------------------------*/
void rtp_sig_semaphore_free (RTP_SEMAPHORE semHandle)
{
    rtp_free((RTP_PFCHAR)semHandle);
}
Example #30
0
SSDP_INT32 SSDP_SendByebye (
    SSDPServerContext *ctx,         /** pointer to SSDP context */
    const SSDP_CHAR *notifyType,    /** the notification type (NT) string */
    const SSDP_CHAR *usn           /** pointer to string containing USN header */)
{
    SSDP_CHAR     ipAddr[RTP_NET_NI_MAXHOST];
    SSDP_CHAR     *msgBfr;
    SSDP_SOCKET    notifySock = ctx->announceSocket;

    if(ctx->ipType == RTP_NET_TYPE_IPV6)
    {
        rtp_sprintf(ipAddr, "[FF02::C]:1900");
    }
    else if (ctx->ipType == RTP_NET_TYPE_IPV4)
    {
        rtp_sprintf(ipAddr, "239.255.255.250:1900");
    }

    msgBfr = (SSDP_CHAR *) rtp_malloc(sizeof(SSDP_CHAR) * SSDP_BUFFER_SIZE);

    if (!msgBfr)
    {
        return (-1);
    }

    /* Send Advertisements */

    /* Fix (03/18/2007) - Correct formatting changed format fields from:
                      "HOST:%s\r\n"
                      "Cache-Control:max-age=%d\r\n"
                      "Location:%s\r\n"
                      "NT:%s\r\n"
                      "NTS:%s\r\n"
                      "Server:%s\r\n"
                      "USN:%s\r\n"

    */
#if (USE_INTEL_SDK_ORDER)
    rtp_sprintf(msgBfr,"NOTIFY * HTTP/1.1\r\n"
                "HOST: %s\r\n"
                "NTS: ssdp:byebye\r\n"
                "USN: %s\r\n"
                "NT: %s\r\n"
                "\r\n",
                ipAddr,
                usn,
                notifyType);
#else
    rtp_sprintf(msgBfr,"NOTIFY * HTTP/1.1\r\n"
                "HOST: %s\r\n"
                "NT: %s\r\n"
                "NTS: ssdp:byebye\r\n"
                "USN: %s\r\n"
                "\r\n",
                ipAddr,
                notifyType,
                usn);
#endif
    if(ctx->ipType == RTP_NET_TYPE_IPV6)
    {
        rtp_strcpy(ipAddr, IPV6_LINK_LOCAL_ADDRESS);
    }
    else if (ctx->ipType == RTP_NET_TYPE_IPV4)
    {
        rtp_strcpy(ipAddr, (const char*)v4mcastAddr);
    }
    RTP_LOG_WRITE("SSDP_SendByeBye SEND", msgBfr, rtp_strlen(msgBfr))
    /* Send the message to the multicast channel */
    if (rtp_net_sendto(notifySock, (unsigned char*)msgBfr, rtp_strlen(msgBfr),(unsigned char *) ipAddr, mcastPort, ctx->ipType) < 0)
    {
        SSDP_ProcessError("SendTo");
        rtp_free(msgBfr);
        return(-1);
    }

    /* Free up the allocated memory */
    rtp_free(msgBfr);
    return(0);
}