Пример #1
0
/*----------------------------------------------------------------------*
                            rtp_threads_init
 *----------------------------------------------------------------------*/
int rtp_threads_init (void)
{   
    NATIVE_PROFILE_PAL_NETWORK();
    int i;
    
#if (INCLUDE_RUN_TIME_CONFIG)
    IPTaskContinuation = (HAL_CONTINUATION  *) rtp_malloc(sizeof(HAL_CONTINUATION) * CFG_NIFACES);           
    InterruptTaskContinuation = (HAL_CONTINUATION  *) rtp_malloc(sizeof(HAL_CONTINUATION) * CFG_NIFACES);
    IPTaskInitialized = (int *) rtp_malloc(sizeof(int) * CFG_NIFACES);  
    InterruptTaskContInitialized = (int *) rtp_malloc(sizeof(int) * CFG_NIFACES);  

    if ( ((int)IPTaskContinuation== -1) || ((int)InterruptTaskContinuation== -1) || 
         ((int)IPTaskInitialized== -1) || ((int)InterruptTaskContInitialized== -1) )
    {
        return (-1);
    }
    if ( ((int)IPTaskContinuation== NULL) || ((int)InterruptTaskContinuation== NULL) || 
         ((int)IPTaskInitialized== NULL) || ((int)InterruptTaskContInitialized== NULL) )
    {
        return (-1);
    }
#endif

    for (i = 0; i < CFG_NIFACES; i++)
    {
        IPTaskInitialized[i] = 0;
        InterruptTaskContInitialized[i] = 0;
    }
    TimerTaskContInitialized = 0;        
    TimerTaskCompInitialized = 0;                 
    DHCPTaskInitialized = 0;                     
    
    return (0);
}   
Пример #2
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);
}
Пример #3
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);
}
Пример #4
0
/** @memo   Create a list or menu object.

    @doc    Creates a list or menu object and returns a handle that may be passed
    to other functions that add to, access and execute user dialogs.
    storage location.

    @precondition None

    @return A non null void * handle on success. 0 otherwise.
*/
void *rtp_gui_list_init(
void *pguictx,				/** Hook for GUI context (parent window handle). Zero for generic implementation. */
int  style,					/**	<br>
     RTP_LIST_STYLE_MENU     - Format as a menu.<br>
     RTP_LIST_STYLE_HELP	 - Format as a help message<br>
     RTP_LIST_STYLE_LISTBOX  - Format as a list box.<br>
	 RTP_LIST_STYLE_NOFORMAT - Do not format greyed expandable etc.<br>
*/
char *title,				/** Title to display */
char *subtitle,				/** Sub-title to display */
char *prompt				/** Prompt to use when requesting input */
)
{
struct rtp_gui_list *plist;

	plist = (struct rtp_gui_list *) rtp_malloc(sizeof(*plist));
	if (plist)
	{
		rtp_memset(plist, 0, sizeof(*plist));
		plist->pguictx = pguictx;
        plist->style = style;
        plist->title = title;
        plist->subtitle = subtitle;
        plist->prompt = prompt;
	}
	return(void *) plist;
}
Пример #5
0
/*---------------------------------------------------------------------------*/
HTTPAuthenticationRealm * _HTTP_NewRealm (
		const HTTP_CHAR* realmName,
		const HTTP_CHAR* path,
		HTTP_INT32 ttlSec,
		HTTPAuthenticationScheme scheme
	)
{
	HTTPAuthenticationRealm * realm = (HTTPAuthenticationRealm *) rtp_malloc(sizeof(HTTPAuthenticationRealm));

	if (realm)
	{
		tc_memset(realm, 0, sizeof(HTTPAuthenticationRealm));

		if (realmName)
		{
			tc_strncpy(realm->realmName, realmName, HTTP_CFG_MAX_REALMNAME_LEN-1);
			realm->realmName[HTTP_CFG_MAX_REALMNAME_LEN-1] = 0;
		}

		if (path)
		{
			tc_strncpy(realm->path, path, HTTP_CFG_MAX_PATH_LEN-1);
			realm->path[HTTP_CFG_MAX_PATH_LEN-1] = 0;
		}
		else
		{
			realm->path[0] = 0;
		}

		realm->scheme = scheme;
	}

	return (realm);
}
Пример #6
0
static HTTP_CHAR *http_demo_alloc_string(HTTP_CHAR *string)
{
HTTP_CHAR *r;
	r = rtp_malloc(rtp_strlen(string)+1);
	if (r)
		rtp_strcpy(r, string);
	return(r);
}
Пример #7
0
/*---------------------------------------------------------------------------*/
char           * _rtp_strdup (const char *str)
{
	long len = (rtp_strlen(str) + 1) * sizeof(char);
	char *s = (char *) rtp_malloc(len);
	if (s)
	{
		rtp_memcpy(s, str, len);
	}
	return (s);
}
Пример #8
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);
}
Пример #9
0
static void * safemalloc(rtsmb_size bytes)
{
   void * Result = rtp_malloc(bytes);

   if (bytes && !Result)
   {
      rtp_printf(("SMB Server: out of heap space\n"));
      exit(1);
   }
   tc_memset(Result, 0, bytes);
   return Result;
}
Пример #10
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);
}
Пример #11
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);
}
Пример #12
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);
Пример #13
0
/*---------------------------------------------------------------------------*/
HTTPAuthenticationHost * _HTTP_NewHost (
		const HTTP_CHAR* hostName,
		HTTP_UINT16 port
	)
{
	HTTPAuthenticationHost * host = (HTTPAuthenticationHost *) rtp_malloc(sizeof(HTTPAuthenticationHost));

	if (host)
	{
		tc_memset(host, 0, sizeof(HTTPAuthenticationHost));
		tc_strncpy(host->hostName, hostName, HTTP_CFG_MAX_HOSTNAME_LEN-1);
		host->hostName[HTTP_CFG_MAX_HOSTNAME_LEN-1] = 0;
		host->port = port;
		DLLIST_INIT(&host->realmList);
	}

	return (host);
}
Пример #14
0
/*----------------------------------------------------------------------*
                         rtp_sig_semaphore_alloc
 *----------------------------------------------------------------------*/
int rtp_sig_semaphore_alloc (RTP_SEMAPHORE *newSem, const char *name)
{
P_POLLOS_SIGNAL poll_sig;
    
    poll_sig = (P_POLLOS_SIGNAL)rtp_malloc(sizeof(struct pollos_signal), 0);  /* SPRZ */
    if (poll_sig)
    {
        poll_sig->signal_count = 0; 
        poll_sig->signal_timeout = 0;
        *newSem = (RTP_HANDLE)poll_sig;

        /* success, return */
        return(0);
    }

    RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_alloc: Semaphore not Created!");

    return (-1);
}
Пример #15
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;
}
Пример #16
0
static int http_server_demo_restart(void)
{
	HTTP_INT16 ipType = 4;

	/* Initialize the server */
	ExampleServerCtx.connectCtxArray = (HTTPServerConnection*) rtp_malloc(sizeof(HTTPServerConnection) * ExampleServerCtx.numConnections);
	if (!ExampleServerCtx.connectCtxArray)
		return -1;
	if (HTTP_ServerInit (
			&ExampleServerCtx.httpServer,
			DEMO_SERVER_NAME, // name
			ExampleServerCtx.rootDirectory,    // rootDir
			ExampleServerCtx.defaultFile,      // defaultFile
			1,                // httpMajorVersion
			1,                // httpMinorVersion
			0, // ExampleServerCtx.defaultIpAddr,   // Use the default IP address
			80,               // 80  ?? Use the www default port
			DEMO_IPVERSION,   // ipversion type(4 or 6)
			0,                // allowKeepAlive
			ExampleServerCtx.connectCtxArray,  // connectCtxArray
			ExampleServerCtx.numConnections,   // maxConnections
			ExampleServerCtx.numHelperThreads  // maxHelperThreads
		) < 0)
		return -1;

	/* Demonstrate using the server API by setting up virtual pages, and assigning callback handlers */
	/* Set up tables of virtual content that we will server from source code */
	http_demo_init_vcontent();

	/* Create "demo_form.html" uses a ram based web page and demonstrates froms processing */
	if (http_server_create_virtual_form(&ExampleServerCtx.httpServer) != 0)
	{
		return(-1);
	}
	/* Create a virtual default web page that we'll use as a sign on instructional page. */
	if (http_server_create_virtual_index(&ExampleServerCtx.httpServer) != 0)
	{
		return(-1);
	}
	return (0);
}
Пример #17
0
/*----------------------------------------------------------------------*
                         rtp_sig_semaphore_alloc
 *----------------------------------------------------------------------*/
int rtp_sig_semaphore_alloc (RTP_SEMAPHORE *newSem, const char *name)
{
    NATIVE_PROFILE_PAL_NETWORK();

P_POLLOS_SIGNAL	poll_sig;
 	
	poll_sig = (P_POLLOS_SIGNAL)rtp_malloc((unsigned long )sizeof(struct pollos_signal));
	
	if (poll_sig)
	{
		poll_sig->signal_count = 0; 
		poll_sig->signal_timeout = 0;
		*newSem = (RTP_HANDLE)poll_sig;

    	/* success, return */
    	return(0);
    }

   	RTP_DEBUG_OUTPUT_STR("rtp_sig_semaphore_alloc: Semaphore not Created!");

    return (-1);
}
Пример #18
0
/* Start or restart the server. Called when the application is first run and when callback handlers
   request a restart of the server because parametrs have been changed */
static int http_server_demo_restart(void)
{
	HTTP_INT16 ipType = DEMO_IPVERSION;	 /* The API supports V6 but the demo is wired for V4 right now */
	HTTP_UINT8     *pDefaultIpAddr;

	/* The demo uses 0,0,0,0 to signify use default but the API uses a null pointer so
	   map the demo methodology to the API metodology */
	if (ExampleServerCtx.defaultIpAddr[0] == 0 &&
		ExampleServerCtx.defaultIpAddr[1] == 0 &&
		ExampleServerCtx.defaultIpAddr[2] == 0 &&
		ExampleServerCtx.defaultIpAddr[3] == 0)
		pDefaultIpAddr = 0;
	else
		pDefaultIpAddr = &ExampleServerCtx.defaultIpAddr[0];

	rtp_printf("Starting or restarting server \n");

	/* Allocate and clear one server context per possible simultaneous connection. see (DEMO_MAX_CONNECTIONS) */
	if (!ExampleServerCtx.connectCtxArray)
	{
		ExampleServerCtx.connectCtxArray = (HTTPServerConnection*) rtp_malloc(sizeof(HTTPServerConnection) * ExampleServerCtx.numConnections);
		if (!ExampleServerCtx.connectCtxArray)
			return -1;
	}
	rtp_memset(ExampleServerCtx.connectCtxArray,0, sizeof(HTTPServerConnection) * ExampleServerCtx.numConnections);

	/* Initialize the server */
	if (HTTP_ServerInit (
			&ExampleServerCtx.httpServer,
			DEMO_SERVER_NAME, // name
			ExampleServerCtx.rootDirectory,    // rootDir
			ExampleServerCtx.defaultFile,      // defaultFile
			1,                // httpMajorVersion
			1,                // httpMinorVersion
			pDefaultIpAddr,
			80,               // 80  ?? Use the www default port
			DEMO_IPVERSION,   // ipversion type(4 or 6)
			0,                // allowKeepAlive
			ExampleServerCtx.connectCtxArray,  // connectCtxArray
			ExampleServerCtx.numConnections,   // maxConnections
			ExampleServerCtx.numHelperThreads  // maxHelperThreads
		) < 0)
		return -1;

	/* Set up request handlers for requests for typical index urls request index.html, index.htm and none */
	/* This api assigns _Demo_UrlRequestHandler() as a callback handler ti url "\\index.html" */
	if (HTTP_ServerAddPath(&ExampleServerCtx.httpServer,
					"\\index.html", 1,(HTTPRequestHandler)_Demo_UrlRequestHandler,
					(HTTPServerPathDestructor)_Demo_UrlRequestDestructor, (void *) 0) < 0)
		return (-1);
	/* Assign_Demo_UrlRequestHandler() as a callback handler ti url "\\index.htm" */
	if (HTTP_ServerAddPath(&ExampleServerCtx.httpServer,
					"\\index.htm", 1,(HTTPRequestHandler)_Demo_UrlRequestHandler,
					(HTTPServerPathDestructor)_Demo_UrlRequestDestructor, (void *) 0) < 0)
		return (-1);
	/* Add "\\" */
	if (HTTP_ServerAddPath(&ExampleServerCtx.httpServer,
					"\\", 1,(HTTPRequestHandler)_Demo_UrlRequestHandler,
					(HTTPServerPathDestructor)_Demo_UrlRequestDestructor, (void *) 0) < 0)
		return (-1);
	/* Add a callback for the dismiss url. This is a one liner so piggyback it on our default handler */
	if (HTTP_ServerAddPath(&ExampleServerCtx.httpServer,
					"\\dismiss.htm", 1,(HTTPRequestHandler)_Demo_UrlRequestHandler,
					(HTTPServerPathDestructor)_Demo_UrlRequestDestructor, (void *) DEMO_DISMISS_ID) < 0)
		return (-1);

	/* Call external function to initialize advanced examples */
	if (http_demo_init_vcontent(&ExampleServerCtx.httpServer) != 0)
		return(-1);
	return (0);
}
Пример #19
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);
}
Пример #20
0
/** @memo
    @doc

    @return error code
 */
SOAPActionState _SOAP_ParseActionRespose (
		HTTPResponseInfo* info,
		HTTPManagedClientSession* session,
		SOAPActionResponse* response
	)
{
	SOAP_INT32      result;
	SOAP_INT32      responseBytesRead = 0;
	SOAP_INT32      responseBufferSize = SOAP_RESPONSE_BUFFER_LENGTH;
	RTPXML_NodeList*  elements;
	RTPXML_Element*   envelopeElem;
    SOAP_CHAR* responseBuffer;
	SOAPActionState	state = SOAP_ACTION_ERROR;

	if(info->status == 200) //OK
	{
		response->status = SOAP_RESPONSE_NORMAL;
	}
	else
	{
		response->status = SOAP_RESPONSE_FAULT;
	}

	/* collect the response and store it in responseBuffer */
	/* Create soap envelope for the request */

	responseBuffer = (char *)rtp_malloc(SOAP_RESPONSE_BUFFER_LENGTH);
	if (!responseBuffer)
	{
		return (-1);
	}
	rtp_memset((SOAP_UINT8*)responseBuffer, 0, SOAP_RESPONSE_BUFFER_LENGTH);

	do
	{

		/* if the buffer is full, then add some space to read data into */
		if (responseBytesRead == responseBufferSize)
		{
			SOAP_CHAR* newBuffer = rtp_realloc(
				responseBuffer,
				responseBufferSize + SOAP_RESPONSE_BUFFER_LENGTH
			);
			if (newBuffer)
			{
				responseBuffer = newBuffer;
				responseBufferSize = responseBufferSize + SOAP_RESPONSE_BUFFER_LENGTH;
			}
			else
			{
				break;
			}
		}

		result = HTTP_ManagedClientRead (
				session,
				(SOAP_UINT8*)(responseBuffer + responseBytesRead),
				responseBufferSize - responseBytesRead
			);

		if (result == 0)
		{
			break;
		}

		responseBytesRead += result;
	}
	/* if we filled the buffer, then try to read more data */
	while (result > 0);

	/* If there is nothing after 500 "Description" then point the fault string at the description */
	if (responseBytesRead == 0)
	{
		response->status = SOAP_REQUEST_ERROR;
        response->fault.string = info->httpReply;
		response->fault.code = response->fault.string;
		return(SOAP_ACTION_RESPONSE_READ);
	}


	if (result == 0)
	{
		/* this is OK because we allocated an extra byte above */
		responseBuffer[responseBytesRead] = 0;
		state = SOAP_ACTION_RESPONSE_READ;

        if(rtpxmlParseBufferEx(responseBuffer, &response->envelope.doc) != RTPXML_SUCCESS)
		{
processing_error:
			response->status = SOAP_REQUEST_ERROR;
			response->fault.string = "Soap Action failed but XML error response is badly formed";
			response->fault.code = response->fault.string;
			rtp_free(responseBuffer);
			return(state);
		}

		elements = rtpxmlDocument_getElementsByTagNameNS (
			response->envelope.doc,
			"http://schemas.xmlsoap.org/soap/envelope/",
			"Envelope");
		if (!elements)
		{
			rtpxmlNodeList_free(elements);
			goto processing_error;
		}

		envelopeElem = (RTPXML_Element *) rtpxmlNodeList_item(elements, 0);
		rtpxmlNodeList_free(elements);

		if (!envelopeElem)
		{
			goto processing_error;
		}

		elements = rtpxmlElement_getElementsByTagNameNS (
			envelopeElem,
			"http://schemas.xmlsoap.org/soap/envelope/",
			"Body");

        if (elements)
		{
			response->envelope.bodyElem = (RTPXML_Element *) rtpxmlNodeList_item(elements, 0);
			rtpxmlNodeList_free(elements);
		}
		else
		{
			response->envelope.bodyElem = 0;
		}

		elements = rtpxmlElement_getElementsByTagNameNS (
			envelopeElem,
			"http://schemas.xmlsoap.org/soap/envelope/",
			"Header");

		if (elements)
		{
				response->envelope.headerElem = (RTPXML_Element *) rtpxmlNodeList_item(elements, 0);
				rtpxmlNodeList_free(elements);
		}
		else
		{
			response->envelope.headerElem = 0;
		}

        /* If action response is error, store error description */
        if(response->status == SOAP_RESPONSE_FAULT)
        {
            if (response->envelope.bodyElem)
		    {
                response->fault.code = UPnP_DOMGetElemTextInElem(response->envelope.bodyElem, "faultcode", 0);
				response->fault.string = UPnP_DOMGetElemTextInElem(response->envelope.bodyElem, "faultstring", 0);
				elements = rtpxmlElement_getElementsByTagName (
					response->envelope.bodyElem,
					"detail");
				if (elements)
				{
					response->fault.detailElem = (RTPXML_Element *) rtpxmlNodeList_item(elements, 0);
					rtpxmlNodeList_free(elements);
				}
				else
				{
					response->fault.detailElem = 0;
				}
		    }
        }
	}
    rtp_free(responseBuffer);
	return(state);
}
Пример #21
0
/* Start dragging helem. */
int webc_SlidingWindowOpen(
	HBROWSER_HANDLE hbrowser,
	HDOC_HANDLE hdoc,
	int WindowTop,
	int WindowLeft,
	int WindowHeight,
	int WindowWidth,
	HELEMENT_HANDLE SlidingElement,
	int SlidingElementStartTop,
	int SlidingElementStartLeft,
	unsigned long Controlflags,
	SlidingCallbackFunction cb)
{
struct _webcSlidingWindowView *SlideObject;
HELEMENT_HANDLE SlideWindow;
char style_buff[512];

	SlideWindow = webc_GetSlidingWindow(hbrowser, hdoc);
	if (!SlideWindow)
		goto error;

	SlideObject = (struct _webcSlidingWindowView *) rtp_malloc(sizeof(* SlideObject));
	if (!SlideObject)
		goto error;
	rtp_memset(SlideObject,0,sizeof(*SlideObject));
//	SlideObject->WindowRect.Set(WindowLeft, WindowTop, WindowLeft+WindowWidth-1, WindowTop+WindowHeight-1);

	SlideObject->WindowTop     = WindowTop;
	SlideObject->WindowLeft    = WindowLeft;
	SlideObject->WindowHeight  = WindowHeight;
	SlideObject->WindowWidth   = WindowWidth;
	SlideObject->Controlflags  = Controlflags;
	SlideObject->SlidingElement = SlidingElement;

	SlideObject->SlidingElementStartTop    =  SlidingElementStartTop;
	SlideObject->SlidingElementStartLeft   =  SlidingElementStartLeft;
	SlideObject->SlidingElementCurrentTop  =  SlidingElementStartTop;
	SlideObject->SlidingElementCurrentLeft =  SlidingElementStartLeft;
	SlideObject->cb = cb;

	/* Install a listener for display events */
	webc_ElementEnableDisplayEvents(SlidingElement);
	/* Move the start position of the element underneath us and show it */
	/* Done below too, may not be needed. */
	webc_ElementSetXYPosition(SlidingElement, SlidingElementStartLeft, SlidingElementStartTop);
	/* Hide the sliding window */
  	webc_ElementHide(SlidingElement, WEBC_TRUE);
	/* Put it inside the SlideWindow */
	if (webc_ElementGetParent(SlidingElement))
		webc_ElementRemoveChild(webc_ElementGetParent(SlidingElement),SlidingElement);
	webc_ElementInsertFirst(SlideWindow,SlidingElement);
	/* Set an event handler */
	webc_ElementSetPrivateData(SlidingElement,SlideObject);
	webc_ElementSetTagEventHandler(SlidingElement, SlidingWindowEventHandler);

	/* Show the viewport with the sliding window inside it, clipped. */
	rtp_sprintf(style_buff,"height:%dpx;width:%dpx;\"", WindowHeight, WindowWidth);
    webc_ElementSetStyleASCII(SlideWindow, style_buff, WEBC_TRUE);
	webc_ElementSetXYPosition(SlideWindow, WindowLeft, WindowTop);
   	webc_ElementHide(SlideWindow, WEBC_FALSE);

	/* Move the start position of the element underneath us and show it */
	webc_ElementSetXYPosition(SlidingElement, SlidingElementStartLeft, SlidingElementStartTop);
	webc_ElementHide(SlidingElement, WEBC_FALSE);

	return 0;
error:
	assert(0);
	return -1;
}
Пример #22
0
/** SOAP callback for UPnP.  Handles a single incoming SOAP control request by
    parsing the action document and calling the device callback.

    @return error code; tells SOAP whether the action was successful or
            generated a fault
 */
int UPnP_DeviceControlSOAPCallback (
		SOAPServerContext *ctx, /** the SOAP context */
		SOAPRequest *request,   /** the action request */
		void *cookie            /** the UPnPService being controlled */)
{
UPnPService *service = (UPnPService *) cookie;
UPnPRootDevice *rootDevice = service->device->rootDevice;

	/* first to check if the device callback is set */
	if (rootDevice->userCallback)
	{
		/* parse the service type URI and the action name out of the
		   SOAPAction header string */
		UPNP_CHAR *soapAction = (UPNP_CHAR *) rtp_malloc(
				(rtp_strlen(request->in.soapAction) + 1) * sizeof(UPNP_CHAR));

		if (soapAction)
		{
			UPNP_CHAR *actionName;
			UPNP_CHAR *serviceTypeURI;
			char *str;

			/* work with a copy of the soapAction since we'll be
			   chopping it up */
			rtp_strcpy(soapAction, request->in.soapAction);

			serviceTypeURI = soapAction;

			/* SOAPAction is often quote-enclosed */
			if (*serviceTypeURI == '"')
			{
				serviceTypeURI++;
			}

			/* '#' signals the beginning of the action tag name */
			str = rtp_strstr(serviceTypeURI, "#");
			if (str)
			{
				long len;
				RTPXML_NodeList *nodeList;

				*str = 0;
				str++;
				actionName = str;

				len = rtp_strlen(actionName);

				/* remove the trailing quote if there is one */
				if (actionName[len-1] == '"')
				{
					actionName[len-1] = 0;
				}

				/* the action tag must be qualified by the xml namespace
				   of the service type */
	  			nodeList = rtpxmlElement_getElementsByTagNameNS (
	  							request->in.envelope.bodyElem,
	  							serviceTypeURI,
	  							actionName);

	  			if (nodeList)
	  			{
	  				RTPXML_Element *actionElement;

	  				actionElement = (RTPXML_Element *) rtpxmlNodeList_item(nodeList, 0);
	  				rtpxmlNodeList_free(nodeList);

	  				if (actionElement)
	  				{
		  				UPnPActionRequest actionRequest;

		  				rtp_memset(&actionRequest, 0, sizeof(UPnPActionRequest));

		  				actionRequest.in.actionName = actionName;
		  				actionRequest.in.serviceTypeURI = serviceTypeURI;
		  				actionRequest.in.actionElement = actionElement;
		  				actionRequest.in.serviceId = service->serviceId;
		  				actionRequest.in.deviceUDN = service->device->UDN;
		  				actionRequest.in.clientAddr = request->in.clientAddr;

		  				rootDevice->userCallback(rootDevice->userData,
						                         rootDevice->deviceRuntime,
						                         rootDevice,
						                         UPNP_DEVICE_EVENT_ACTION_REQUEST,
						                         &actionRequest);

						if (actionRequest.out.errorCode == 0)
						{
							/* success */
							request->out.body = actionRequest.out.result;
							rtp_free(soapAction);
							return (0);
						}
						else
						{
							/* fault */
							char temp[UPNP_MAX_ERROR_DESC_LEN + 176];

							rtp_sprintf(temp, "<UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\">"
							                 "<errorCode>%d</errorCode>"
							                 "<errorDescription>%s</errorDescription>"
							                 "</UPnPError>",
							           actionRequest.out.errorCode,
							           actionRequest.out.errorDescription);

							rtp_strcpy(request->out.fault.code, "s:Client");
							rtp_strcpy(request->out.fault.string, "UPnPError");

							/* XML document will be freed by SOAP */
							request->out.fault.detail = rtpxmlParseBuffer(temp);
							rtp_free(soapAction);

							return (-1);
						}
	  				}
	  			}
			}

			rtp_free(soapAction);
		}
	}

	return (-1);
}
Пример #23
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);
}
Пример #24
0
/** @memo   Read lines from a file to a buffer.

    @doc    Read lines from a file to buf or if the end of the file 
    or the line has not been reached yet, reads (buflen-1) of data.
    
    @precondition Should not mix rtp_stdio_fread and rtpstdio_fgets
    calls.
    
    @return Number of bytes written, -1 otherwise.
 */
int rtp_stdio_fgets (
  char * buf,                           /** Buffer to store the read. */
  int buflen,                           /** Number of bytes to read. */
  void * rtpfile                        /** Handle of file to be read. */
  )
{
    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_read().         */
        /* --------------------------------------- */
        return ((long) -1);
    }
    
    if (buflen <= 0)
    {
        return (-1);
    }
    buflen--;

    if ( !(((RTP_STDIO_FILE *)rtpfile)->buffer) )
    {
        /* --------------------------------------- */
        /* Allocate buffer. If successful, use it. */
        /* --------------------------------------- */

        /* --------------------------------------- */
        /* Assume no line is larger than           */
        /* RTP_READLINE_BUFFER characters. Then we */
        /* can use a buffer RTP_READLINE_BUFFER    */
        /* bytes and only read that many bytes at  */
        /* a time to speed up reading.             */
        /* --------------------------------------- */
        ((RTP_STDIO_FILE *)rtpfile)->buffer = (char *) rtp_malloc ((unsigned int)RTP_READLINE_BUFFER, 0);  /* SPRZ */
        if (((RTP_STDIO_FILE *)rtpfile)->buffer)
        {
            ((RTP_STDIO_FILE *)rtpfile)->bufsiz = RTP_READLINE_BUFFER;
        }
        /* --------------------------------------- */
        /* ((RTP_STDIO_FILE *)rtpfile)->bufpos = 0;*/
        /* ((RTP_STDIO_FILE *)rtpfile)->buffil = 0;*/
        /* --------------------------------------- */
    }

    while (((RTP_STDIO_FILE *)rtpfile)->buffer)
    {
        int i;
        int n;

        if (buflen == 0)
        {
            buf[0] = 0;
            return (0);
        }

        /* --------------------------------------- */
        /*  check if we still got a line worth in  */
        /*  there...                               */
        /* --------------------------------------- */
        for (i = ((RTP_STDIO_FILE *)rtpfile)->bufpos; i < ((RTP_STDIO_FILE *)rtpfile)->buffil; i++)
        {
            if (((RTP_STDIO_FILE *)rtpfile)->buffer[i] == '\n')
            {
                /* --------------------------------------- */
                /*                Have a line.             */
                /* --------------------------------------- */
                i = i + 1 - ((RTP_STDIO_FILE *)rtpfile)->bufpos;
                if (buflen < i)
                {
                    i = buflen;
                }
                rtp_memmove(buf, ((RTP_STDIO_FILE *)rtpfile)->buffer + ((RTP_STDIO_FILE *)rtpfile)->bufpos, i);
                ((RTP_STDIO_FILE *)rtpfile)->bufpos += i;
                buf[i] = 0;
                return (i);
            }
        }

        /* --------------------------------------- */
        /*  no more lines in buffer: get new data  */
        /*  in there.  FIRST: move what we've got  */
        /*  to front.                              */
        /* --------------------------------------- */
        if (((RTP_STDIO_FILE *)rtpfile)->bufpos < ((RTP_STDIO_FILE *)rtpfile)->buffil)
        {
            rtp_memmove(((RTP_STDIO_FILE *)rtpfile)->buffer,
				       ((RTP_STDIO_FILE *)rtpfile)->buffer +
					   ((RTP_STDIO_FILE *)rtpfile)->bufpos,
					   ((RTP_STDIO_FILE *)rtpfile)->buffil -
					   ((RTP_STDIO_FILE *)rtpfile)->bufpos);
            ((RTP_STDIO_FILE *)rtpfile)->buffil -= ((RTP_STDIO_FILE *)rtpfile)->bufpos;
            ((RTP_STDIO_FILE *)rtpfile)->bufpos = 0;
        }
        else
        {
            ((RTP_STDIO_FILE *)rtpfile)->buffil = 0;
            ((RTP_STDIO_FILE *)rtpfile)->bufpos = 0;
        }

        /* --------------------------------------- */
        /*  Get more data. Assume we don't mix     */
        /*  fgets() with fread().                  */
        /* --------------------------------------- */
        if (((((RTP_STDIO_FILE *)rtpfile)->bufsiz - ((RTP_STDIO_FILE *)rtpfile)->buffil) & ~(RTP_READLINE_BUFFER-1)) > 0)
        {
            /* --------------------------------------- */
            /*         load alligned: sector           */
            /* --------------------------------------- */
            n = rtp_file_read (((RTP_STDIO_FILE *)rtpfile)->handle, 
                               (unsigned char *) ((RTP_STDIO_FILE *)rtpfile)->buffer + ((RTP_STDIO_FILE *)rtpfile)->buffil, 
                               (unsigned int)    ((((RTP_STDIO_FILE *)rtpfile)->bufsiz - ((RTP_STDIO_FILE *)rtpfile)->buffil) & ~(RTP_READLINE_BUFFER-1)));

            if (n > 0)
            {
                ((RTP_STDIO_FILE *)rtpfile)->buffil += n;

                /* --------------------------------------- */
                /* check if we got a line worth in there.  */
                /* --------------------------------------- */
                for (i = ((RTP_STDIO_FILE *)rtpfile)->bufpos; i < ((RTP_STDIO_FILE *)rtpfile)->buffil; i++)
                {
                    if (((RTP_STDIO_FILE *)rtpfile)->buffer[i] == '\n')
                    {
                        /* --------------------------------------- */
                        /*                Have line.               */
                        /* --------------------------------------- */
                        i = i + 1 - ((RTP_STDIO_FILE *)rtpfile)->bufpos;
                        if (buflen < i)
                        {
                            i = buflen;
                        }
                        rtp_memmove(buf, ((RTP_STDIO_FILE *)rtpfile)->buffer + ((RTP_STDIO_FILE *)rtpfile)->bufpos, i);
                        ((RTP_STDIO_FILE *)rtpfile)->bufpos += i;
                        buf[i] = 0;
                        return (i);
                    }
                }
            }
        }

        /* --------------------------------------- */
        /*         load as much as possible.       */
        /* --------------------------------------- */
        if (((RTP_STDIO_FILE *)rtpfile)->bufsiz > ((RTP_STDIO_FILE *)rtpfile)->buffil)
        {
            /* --------------------------------------- */
            /*              load UNalligned            */
            /* --------------------------------------- */
            n = rtp_file_read (((RTP_STDIO_FILE *)rtpfile)->handle, 
                               (unsigned char *) ((RTP_STDIO_FILE *)rtpfile)->buffer + ((RTP_STDIO_FILE *)rtpfile)->buffil, 
                               (unsigned int)    (((RTP_STDIO_FILE *)rtpfile)->bufsiz - ((RTP_STDIO_FILE *)rtpfile)->buffil));

            if (n > 0)
            {
                ((RTP_STDIO_FILE *)rtpfile)->buffil += n;

                /* --------------------------------------- */
                /* check if we got a line worth in there.  */
                /* --------------------------------------- */
                for (i = ((RTP_STDIO_FILE *)rtpfile)->bufpos; i < ((RTP_STDIO_FILE *)rtpfile)->buffil; i++)
                {
                    if (((RTP_STDIO_FILE *)rtpfile)->buffer[i] == '\n')
                    {
                        /* --------------------------------------- */
                        /*               Have line.                */
                        /* --------------------------------------- */
                        i = i + 1 - ((RTP_STDIO_FILE *)rtpfile)->bufpos;
                        if (buflen < i)
                        {
                            i = buflen;
                        }
                        rtp_memmove(buf, ((RTP_STDIO_FILE *)rtpfile)->buffer + ((RTP_STDIO_FILE *)rtpfile)->bufpos, i);
                        ((RTP_STDIO_FILE *)rtpfile)->bufpos += i;
                        buf[i] = 0;
                        return (i);
                    }
                }
            }
        }

        /* --------------------------------------- */
        /* If we get here, the line is too long or */
        /* we're stuck with the last line, which   */
        /* is NOT '\n' terminated.                 */
        /* --------------------------------------- */
        if (((RTP_STDIO_FILE *)rtpfile)->buffil > ((RTP_STDIO_FILE *)rtpfile)->bufpos)
        {
            i = ((RTP_STDIO_FILE *)rtpfile)->buffil - ((RTP_STDIO_FILE *)rtpfile)->bufpos;
            if (buflen < i)
            {
                i = buflen;
            }
            rtp_memmove(buf, ((RTP_STDIO_FILE *)rtpfile)->buffer + ((RTP_STDIO_FILE *)rtpfile)->bufpos, i);
            ((RTP_STDIO_FILE *)rtpfile)->bufpos += i;
            buf[i] = 0;
            /* --------------------------------------- */
            /* This may be part of a very large line.  */
            /* So correct pointers and everything and  */
            /* loop.                                   */
            /* --------------------------------------- */
            buflen -= i;
            buf += i;
            if (buflen == 0)
            {
                return (0);
            }
        }

        /* --------------------------------------- */
        /* We just copied the remains of our       */
        /* buffer into the user buffer. Set pos to */
        /* 0 and try one last ALLIGNED load to see */
        /* if we still got data coming in. But     */
        /* shift remaining data, if any, to FRONT  */
        /* first.                                  */
        /* --------------------------------------- */
        if (((RTP_STDIO_FILE *)rtpfile)->bufpos < ((RTP_STDIO_FILE *)rtpfile)->buffil)
        {
            rtp_memmove(((RTP_STDIO_FILE *)rtpfile)->buffer, 
				       ((RTP_STDIO_FILE *)rtpfile)->buffer + 
					   ((RTP_STDIO_FILE *)rtpfile)->bufpos, 
					   ((RTP_STDIO_FILE *)rtpfile)->buffil - 
					   ((RTP_STDIO_FILE *)rtpfile)->bufpos);
            ((RTP_STDIO_FILE *)rtpfile)->buffil -= ((RTP_STDIO_FILE *)rtpfile)->bufpos;
            ((RTP_STDIO_FILE *)rtpfile)->bufpos = 0;
        }
        else
        {
            ((RTP_STDIO_FILE *)rtpfile)->buffil = 0;
            ((RTP_STDIO_FILE *)rtpfile)->bufpos = 0;
        }

        /* --------------------------------------- */
        /* Get more data. And check if there's any */
        /* left.                                   */
        /* --------------------------------------- */

        /* --------------------------------------- */
        /*           load alligned: sector         */
        /* --------------------------------------- */
        n = rtp_file_read (((RTP_STDIO_FILE *)rtpfile)->handle, 
                           (unsigned char *) ((RTP_STDIO_FILE *)rtpfile)->buffer + ((RTP_STDIO_FILE *)rtpfile)->buffil, 
                           (unsigned int)    ((((RTP_STDIO_FILE *)rtpfile)->bufsiz - ((RTP_STDIO_FILE *)rtpfile)->buffil) & ~(RTP_READLINE_BUFFER-1)));

        if (n > 0)
        {
            ((RTP_STDIO_FILE *)rtpfile)->buffil += n;
        }
        else
        {
            /* --------------------------------------- */
            /*       EOF reached and buffer empty.     */
            /* --------------------------------------- */
            ((RTP_STDIO_FILE *)rtpfile)->eofBool = 1;
            ((RTP_STDIO_FILE *)rtpfile)->buffer = 0;
            return (0);
        }

        /* --------------------------------------- */
        /* we get here, iff we are reading a very  */
        /* long line that is larger than our       */
        /* '((RTP_STDIO_FILE *)rtpfile)->buffer':  */
		/* add next piece to output 'buf'.         */
        /* --------------------------------------- */
    }
    return (-1);
}
Пример #25
0
int _UPnP_DeviceSendRootDeviceByeBye (
     UPnPRootDevice *rootDevice, /** address of the root device */
     int deep                    /** if 1, send advertisements for all embedded devices
                                     and services.<br>if 0, send advertisements for the
                                     device under the root and its associated services */)
{
    char         notifySubType[13];  /* holds ssdp:bye-bye */
    char         notifyType[16];     /* holds upnp:rootdevice */
    UPnPService *service;
    UPnPDevice  *device;
    DLListNode  *serviceListNode;
    DLListNode  *deviceListNode;
    char        *usn;
    char        *descLocation;
    int          result = -1;
	char destAddr[RTP_NET_NI_MAXHOST];
	int ipType = rootDevice->deviceRuntime->upnpRuntime->ssdpContext.ipType;

    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 usn to hold UDN, upnp:rootdevice, :: and a string terminator */
		usn = (char *) rtp_malloc((rtp_strlen(rootDevice->device.UDN) + 18));

		if (usn)
		{

			/* create a notify type using device UDN and device type */
			rtp_strcpy(usn, rootDevice->device.UDN);
			rtp_strcat(usn, "::");
			rtp_strcat(usn, "upnp:rootdevice");

			rtp_strcpy(notifySubType, "ssdp:bye-bye");
			rtp_strcpy(notifyType, "upnp:rootdevice");

			/* send root specific advertisement */
			if(SSDP_SendByebye (&rootDevice->deviceRuntime->upnpRuntime->ssdpContext,
			                   notifyType, usn) >= 0)
			{
				result = 0;

				if (deep == 0) /* advertise the device under rootdevice and its associated services */
				{
					if (_UPnP_DeviceSendDeviceByeBye(&rootDevice->device) < 0)
					{
						result = -1;
					}

					if (result == 0)
					{
						/* advertise all services associated with this device */
						serviceListNode = rootDevice->serviceList.next;
						while(serviceListNode != &rootDevice->serviceList)
						{
							service = (UPnPService *) serviceListNode;

							if (_UPnP_DeviceSendServiceByeBye(service) < 0)
							{
								result = -1;
								break;
							}

							serviceListNode = serviceListNode->next;
						}

						if (result == 0)
						{
							/* advertise all devices in the device list */
							deviceListNode = rootDevice->deviceList.next;
							while(deviceListNode != &rootDevice->deviceList)
							{
								device = (UPnPDevice *)deviceListNode;

								if(_UPnP_DeviceSendDeviceByeBye(device) < 0)
								{
									result = -1;
									break;
								}

								deviceListNode = deviceListNode->next;
							}
						}
					}
				}
			}

			rtp_free(usn);
		}

		_freeLocation(rootDevice, descLocation);
	}

	return(0);
}
Пример #26
0
/**
	@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);
}
Пример #27
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);
}