示例#1
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);
}
示例#2
0
static int http_client_put(HTTPManagedClient* phttpClient)
{
HTTPManagedClientSession* session = 0;
char urlpath[255];
char urlfile[255];
char localfile[255];
char contenttype[255];
HTTP_INT32 result = -1;
HTTP_INT32 totalresult = 0;
HTTPResponseInfo info;
HTTP_INT32 contentLength;
RTP_HANDLE  fd;
HTTP_INT32 nread;

	rtp_strcpy(contenttype, "application/x-www-form-urlencoded"); /* content-type */

	rtp_gui_prompt_text(" ","IP Address (eg: 192.161.2.1) or domain name of host (eg: www.google.com)\n    :", &urlpath[0]);
	rtp_gui_prompt_text(" ","File name on server\n    :", &urlfile[0]);
	rtp_gui_prompt_text(" ","Local file name to put\n    :", &localfile[0]);
	rtp_gui_prompt_text(" ","Content type eg: text/html\n    :", &contenttype[0]);

	contentLength = 0;			/* Set content length to zero so we use chunked encoding */

	/* A HTTPManagedClientSession is the abstraction for a SINGLE HTTP request/response pair.
	Thus a new session must be opened for each HTTP operation
	(although this may not cause a new connection to be established, if keep alive is used),
	and closed when the operation has completed (though, again, this may not actually close a
	physical network connection) */

	if (HTTP_ManagedClientStartTransaction (
	 phttpClient,
	 &urlpath[0],
	 80,
      4,
	 HTTP_SESSION_TYPE_TCP,
	 1, /* blocking? */ &session ) < 0)
	{
	 	rtp_printf("Failed: connecting to %s\n", urlpath);
	 	return(-1);
	}


	/* Once the session is open, one command may be issued; in this case a Post */
 	HTTP_ManagedClientPut ( session,
 	urlfile, /* path */
 	contenttype,
 	contentLength /* content-length */ );

	if (rtp_file_open (&fd, (const char *) &localfile[0], RTP_FILE_O_RDONLY, 0) < 0)
	{
 		rtp_printf("Failure opening %s\n", localfile);
 		return(-1);
	}

 	/* write the POST data */
	do
	{

 		nread = rtp_file_read(fd,read_buffer, (long)read_buffer_size);
 		if (nread > 0)
			HTTP_ManagedClientWrite (session, (HTTP_UINT8*) &read_buffer[0], nread);
	} while (nread >= 0);

/* this function must be called when all data has been written */
	HTTP_ManagedClientWriteDone (session);

/* This may be called at any time after the command is issued to get information about the
   server response; this info includes the status code given, date when the request was
   processed, file mime type information (if a file is transferred as the result of a
   command), authentication information, etc. */

   HTTP_ManagedClientReadResponseInfo(session, &info);

   do { /* Read data from the session */
   		result = HTTP_ManagedClientRead(session, read_buffer, read_buffer_size);
   } while (result > 0);


   /* Now we are done; close the session (see note above about sessions) */
   HTTP_ManagedClientCloseSession(session);

   /* When all HTTP client activity is completed, the managed client context may safely be destroyed */
   HTTP_ManagedClientDestroy(phttpClient);

   rtp_file_close(fd);

   if (result == 0)
   {
   		rtp_printf("Success: putting file: %s to %s%s\n", localfile, urlpath, urlfile);
   		return(0);
	}
	else
	{
   		rtp_printf("Failed: putting file: %s to %s%s\n", localfile, urlpath, urlfile);
		return(-1);
	}
}
示例#3
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);
}
示例#4
0
static int http_client_post(HTTPManagedClient* phttpClient)
{
HTTPManagedClientSession* session = 0;
char urlpath[255];
char urlfile[255];
char datatopost[255];
char contenttype[255];
char useebssite[32];
HTTP_INT32 result = -1;
HTTP_INT32 totalresult = 0;
HTTPResponseInfo info;
HTTP_INT32 contentLength;

	rtp_strcpy(contenttype, "application/x-www-form-urlencoded"); /* content-type */
 	rtp_printf("Type Y or y to post a fixed message to www.ebsembeddedsoftware.com\n");
 	rtp_printf("Type N to be prompted for URL form name and data \n");
	rtp_gui_prompt_text(" ","Select Y or N :", &useebssite[0]);
	if (useebssite[0] == 'Y' || useebssite[0] == 'y')
	{
		rtp_strcpy(&urlpath[0], "www.ebsembeddedsoftware.com");
		rtp_strcpy(&datatopost[0], posttoebsupnpinfo);
		rtp_strcpy(&urlfile[0], posttoebsupnurl);
	}
	else
	{
		rtp_gui_prompt_text(" ","IP Address (eg: 192.161.2.1) or domain name of host (eg: www.google.com)\n   :", &urlpath[0]);
		rtp_gui_prompt_text(" ","File (form name) name: (eg: /requestinfo.php?product=RTUPNP\n    :", &urlfile[0]);
		rtp_gui_prompt_text(" ","Data to post: (eg: company=acme&product=wigits) \n    :", &datatopost[0]);
	}

	contentLength = rtp_strlen(&datatopost[0]);

	/* A HTTPManagedClientSession is the abstraction for a SINGLE HTTP request/response pair.
	Thus a new session must be opened for each HTTP operation
	(although this may not cause a new connection to be established, if keep alive is used),
	and closed when the operation has completed (though, again, this may not actually close a
	physical network connection) */

	if (HTTP_ManagedClientStartTransaction (
	 phttpClient,
	 &urlpath[0],
	 80,
      4,
	 HTTP_SESSION_TYPE_TCP,
	 1, /* blocking? */ &session ) < 0)
	{
	 	rtp_printf("Failed: connecting to %s\n", urlpath);
	 	return(-1);
	}


	/* Once the session is open, one command may be issued; in this case a Post */
 	HTTP_ManagedClientPost ( session,
 	urlfile, /* path */
 	contenttype,
 	contentLength /* content-length */ );

 	/* write the POST data */
	HTTP_ManagedClientWrite (session, (HTTP_UINT8*) &datatopost[0], contentLength);

/* this function must be called when all data has been written */
	HTTP_ManagedClientWriteDone (session);

/* This may be called at any time after the command is issued to get information about the
   server response; this info includes the status code given, date when the request was
   processed, file mime type information (if a file is transferred as the result of a
   command), authentication information, etc. */

   HTTP_ManagedClientReadResponseInfo(session, &info);

   do { /* Read data from the session */
   		result = HTTP_ManagedClientRead(session, read_buffer, read_buffer_size);
   } while (result > 0);


   /* Now we are done; close the session (see note above about sessions) */
   HTTP_ManagedClientCloseSession(session);

   /* When all HTTP client activity is completed, the managed client context may safely be destroyed */
   HTTP_ManagedClientDestroy(phttpClient);


   if (result == 0)
   {
   	rtp_printf("Success: posting to %s%s\n", totalresult, urlpath, urlfile);
	return(0);
	}
	else
	{
		rtp_printf("Failure: posting to %s%s\n", totalresult, urlpath, urlfile);
		return(-1);
	}
}
示例#5
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);
}
示例#6
0
文件: srvtst.c 项目: layerfsd/cifssmb
// ---------------------------------------------------- 
// ENTRY POINT
// ---------------------------------------------------- 
int smbservermain(void)
{
	char c;
    int go;
    int  have_printer;
    byte security_mode;
    RTP_THREAD new_thread;

    // ------------------------------------------------ 
    rtp_printf("\n\nRun Alt Port Numbers(Y/y) or Well-Known(N/n)");
    while (!kbhit ())
    {       
    }
    c = getch ();
    if (c == 'Y' || c == 'y')
    {
        rtsmb_init_port_alt ();
    }
    
    if (c == 'N' || c == 'n')
    {
        rtsmb_init_port_well_know ();
    }

    // ------------------------------------------------ 
    if (!rtp_file_mkdir (SHARE_PATH))
    {
        rtp_printf("WARNING: mkdir of SHARE_PATH failed %s\n", SHARE_PATH, 0);
    }

    rtp_printf("\nsmbservermain - enter\n");
    go = 1;
    /* Start ertfs on windows*/
    //pc_ertfs_init ();

    /* initialize server */
    rtsmb_srv_init (my_ip_srv_address, ip_srv_mask_address, 
                    NETWORK_NAME , NETWORK_GROUP);
    rtp_printf ("Initialized rtsmb\n");

#ifdef USE_CONFIG_FILE
    rtsmb_srv_read_config ("smb_config.txt");
#else

    rtp_printf("Note: The demo does not actually print data, it just captures print data to a temporary file.\n");

    {
    char printerName[32];
    char driverName[32];
    char tempPath[32];
    char prnFile[32];

        rtp_strcpy(printerName, "SmbPrinter");
        rtp_strcpy(driverName, "HP LaserJet 1100");
        rtp_strcpy(tempPath, TEMP_PATH);
        rtp_strcpy(prnFile, "SmbPrintData.prn");

        have_printer = in_printer(printerName,driverName, tempPath, prnFile);
        if (have_printer)
        {
            rtsmb_srv_share_add_printer (printerName, driverName, 1, (PSMBFILEAPI)0, tempPath, 0, (PFCHAR)0, prnFile);
        }
    }
    security_mode = in_loginmode();

    //rtsmb_srv_share_add_tree (SHARE_NAME, DESCRIPTION,  NULL, SHARE_PATH, SHARE_FLAGS_8_3, SECURITY_READWRITE, NULL);
    //rtsmb_srv_share_add_tree (SHARE_NAME, DESCRIPTION, (PSMBFILEAPI)0, SHARE_PATH, SHARE_FLAGS_CREATE, SECURITY_READWRITE, (PFCHAR)0);

    rtsmb_srv_share_add_ipc ((PFCHAR)0);

    rtsmb_srv_set_mode (security_mode);  /* AUTH_USER_MODE or AUTH_SHARE_MODE */

    rtsmb_srv_register_group ("rw_access");
    rtsmb_srv_register_group ("rd_access");

    {
    char shareName[32];
    char sharePath[32];
    char shareDesc[32];
    char sharePass[32];
    char secCode[32];

        rtp_strcpy(shareName, SHARE_NAME);
        rtp_strcpy(shareDesc, "Rtsmbshare");
        rtp_strcpy(sharePath, SHARE_PATH);
        rtp_strcpy(sharePass, "");
        rtp_strcpy(secCode,"2");

        if (in_share(security_mode, shareName, sharePath, shareDesc, sharePass, secCode))
        {
        byte security_mode; /* Defult is 2  SECURITY_READWRITE */
        char *psharePass;
            if (sharePass[0])
                psharePass = &sharePass[0];
            else
                psharePass = 0;
            security_mode = (byte)(secCode[0] -'0');
            rtsmb_srv_share_add_tree (shareName, shareDesc, (PSMBFILEAPI)0, sharePath, SHARE_FLAGS_CREATE, security_mode, (PFCHAR)psharePass);
            rtsmb_srv_set_group_permissions ("rw_access", shareName, SECURITY_READWRITE);
            rtsmb_srv_set_group_permissions ("rd_access", shareName, SECURITY_READ);
        }
    }

    //  rtsmb_srv_set_group_permissions ("rw_access", SHARE_NAME, SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("rw_access", "IPC$", SECURITY_READWRITE);
    rtsmb_srv_set_group_permissions ("rd_access", "IPC$", SECURITY_READWRITE);

    //rtsmb_srv_register_group ("ro_access");
    //rtsmb_srv_set_group_permissions ("ro_access", SHARE_NAME, SECURITY_READ);
    //rtsmb_srv_set_group_permissions ("ro_access", "IPC$", SECURITY_READWRITE);

    //rtsmb_srv_register_group ("wo_access");
    //rtsmb_srv_set_group_permissions ("wo_access", SHARE_NAME, SECURITY_WRITE);
    //rtsmb_srv_set_group_permissions ("wo_access", "IPC$", SECURITY_READWRITE);

    /* No access */
    //rtsmb_srv_register_group ("nonebs");
    //rtsmb_srv_set_group_permissions ("nonebs", SHARE_NAME, SECURITY_NONE);
    //rtsmb_srv_set_group_permissions ("nonebs", "IPC$", SECURITY_NONE);

    //rtsmb_srv_register_user (SMB_GUESTNAME, (PFCHAR)0);
    //rtsmb_srv_register_user (SMB_GUESTNAME, "ebs");
    //rtsmb_srv_add_user_to_group (SMB_GUESTNAME, "rw_access");

    if (security_mode == AUTH_USER_MODE)
    {
    char userName[32];
    char userPass[32];
    char userPerm[32];

        if (in_guestaccount())
            rtsmb_srv_register_user (SMB_GUESTNAME, (PFCHAR)0);

        rtp_strcpy(userName, "user");
        rtp_strcpy(userPass, "password");
        rtp_printf("Add users, enter a blank user to stop : ");
        while (in_user(userName, userPass, userPerm))
        {
            rtsmb_srv_register_user (userName, userPass);
            if (rtp_strcmp(userPerm, "rw") == 0)
                    {rtsmb_srv_add_user_to_group (userName, "rw_access");break;}
            else if (rtp_strcmp(userPerm, "r") == 0)
                {rtsmb_srv_add_user_to_group (userName, "rd_access");break;}
        }
    }

#endif //USE_CONFIG_FILE

#if (1)
    if (rtp_thread_spawn (
                &new_thread,
                (RTP_ENTRY_POINT_FN) rtsmb_main,
                (const char *) "RTIP_SMB_SRV",
                STACKSIZE_HUGE,
                TASKPRIO_NORMAL_INDEX,
                (void *) 0
            ) < 0)
        {
            rtp_term_puts("spawn of SMB task failed");
            return(-1);
        }
        rtp_term_puts("spawn of SMB task WORKED");

		while (1)
		{
			rtp_thread_sleep(1);
		}

#else
    //Main Loop
    while(go)
    {
        rtsmb_main ();
        if(rtp_term_kbhit())
        {
//          switch (getch())
            switch (rtp_term_getch())
            {
            case 'q':   go = 0;
                        break;
            default:    break;
            }
        }
    }

    //Shutdown
    rtp_printf("main: shutting down\n");

    rtsmb_srv_shutdown ();
    rtp_net_exit ();
#endif
    return(0);
}//main
示例#7
0
int http_server_demo(void)
{
	HTTP_INT16 ipType = DEMO_IPVERSION;
	int idle_count = 0;
	rtp_net_init();
	rtp_threads_init();

	/* Set initial default values */
	rtp_memset(&ExampleServerCtx, 0, sizeof(ExampleServerCtx));
	rtp_strcpy(ExampleServerCtx.rootDirectory, DEMO_WWW_ROOT);
	rtp_strcpy(ExampleServerCtx.defaultFile,DEMO_WWW_FILE);
	ExampleServerCtx.chunkedEncoding 		= 0;
	ExampleServerCtx.numHelperThreads 		= DEMO_MAX_HELPERS;
	ExampleServerCtx.numConnections		 	= DEMO_MAX_CONNECTIONS;
	/* If these are {0,0,0,0} use the default interface otherwise we use the configured address */
	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_printf("Using IP address %d.%d.%d.%d (all zeroes means use default interface) \n",
		ExampleServerCtx.defaultIpAddr[0],	ExampleServerCtx.defaultIpAddr[1],
		ExampleServerCtx.defaultIpAddr[2],	ExampleServerCtx.defaultIpAddr[3]);

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

	/* Now loop continuously process one request per loop. */
	for (;;)
	{
		if (HTTP_ServerProcessOneRequest (&ExampleServerCtx.httpServer, 1000*60) < 0)
		{
			/* Print an idle counter every minute the server is not accessed */
			idle_count += 1;
			if (idle_count == 1)
				rtp_printf("\n Idle %d minutes      ", idle_count);
			else
				rtp_printf("                                     \r Idle %d minutes", idle_count);
		}
		else
			idle_count = 0;

		if (ExampleServerCtx.ModuleRequestingReload)
		{
			ExampleServerCtx.ModuleRequestingReload = 0;
			HTTP_ServerDestroy(&ExampleServerCtx.httpServer, &ExampleServerCtx.connectCtxArray);
			rtp_free(ExampleServerCtx.connectCtxArray);
			ExampleServerCtx.connectCtxArray = 0;
			/* Initialize the server */
			if (http_server_demo_restart() != 0)
			{
				rtp_net_exit();
				return(-1);
			}
		}
	}

	rtp_net_exit();
	return (0);

}
示例#8
0
static int __rtp_FreeSemaphoreHeader (RTPSemaphoreHeader* pFreedSemaphore, const char* file, long line)
{
	if (!__rtp_TrackingSemaphoreHeader(pFreedSemaphore))
	{
		/* ----------------------------------- */
		/*       This semaphore does not       */
		/*       exist on the track list.      */
		/* ----------------------------------- */
		return (-1);
	}
	
	if (__rtp_InitSemaphoreDebug())
	{
		_rtp_sig_mutex_claim(rtpSemaphoreDebugLock);
		
		/* ----------------------------------- */
		/*     Remove pFreedSemaphore from     */
		/*            the track list.          */
		/* ----------------------------------- */
		if (pFreedSemaphore->prev)
		{
			pFreedSemaphore->prev->next = pFreedSemaphore->next;
		}
		else
		{
			/* ----------------------------------- */
			/*  Freeing the head, must reasign     */
			/*  and clear prev pointer to now      */
			/*  old head.                          */
			/* ----------------------------------- */
			if (gpSemaphoreList->next)
			{
				gpSemaphoreList = gpSemaphoreList->next;
				gpSemaphoreList->prev = 0;
			}
			else
			{
				gpSemaphoreList = 0;
			}
		}
		
		if (pFreedSemaphore->next)
		{
			pFreedSemaphore->next->prev = pFreedSemaphore->prev;
		}

		/* ----------------------------------- */
		/*      Link pFreedSemaphore onto      */
		/*      the top of the free list.      */
		/* ----------------------------------- */
		pFreedSemaphore->prev = 0;
		pFreedSemaphore->next = gpSemaphoreFreeList;
		
		if (gpSemaphoreFreeList)
		{
			gpSemaphoreFreeList->prev = pFreedSemaphore;
		}
		gpSemaphoreFreeList = pFreedSemaphore;
		giNumSemaphoresTracking--;

		pFreedSemaphore->seq   = 0;
		pFreedSemaphore->wait  = 0;
		pFreedSemaphore->state = gcSemaphoreFreed;
		rtp_strcpy(pFreedSemaphore->file, file);
		pFreedSemaphore->line  = line;

		_rtp_sig_mutex_release(rtpSemaphoreDebugLock);
		
		return (0);
	}
	return (-1);
}