problem using external webserver

正文 王 <[email protected]> Tue, 13 Nov 2007 10:27:00 +0800
Newsgroups gmane.linux.upnp-sdk.general
Message-ID <[email protected]>
--===============1454925822==
Content-Type: multipart/alternative;
	boundary="_e173b455-cdf1-4aca-b206-7f8cf40b90c2_"

--_e173b455-cdf1-4aca-b206-7f8cf40b90c2_
Content-Type: text/plain; charset="big5"
Content-Transfer-Encoding: quoted-printable


My device sent SSDP message repeatly until the process ends.

below is the code

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <upnptools.h>
#include <ithread.h>
#include <ixml.h>
#include <upnp/upnp.h>

int CallbackEventHandler( Upnp_EventType EventType, void* , void* );


int main(){
    int rc,port,test,code;
    char *web_dir =3D "./web";
    char desc_doc_url[200],*desc_doc_name =3D "tvdevicedesc.xml", *ip_add=
ress;

    UpnpDevice_Handle device_handle;

    rc =3D UpnpInit (NULL, 0);
    if ( UPNP_E_SUCCESS =3D=3D rc ) {
        const char* ip_address =3D UpnpGetServerIpAddress();
        unsigned short port    =3D UpnpGetServerPort();
       =20
        printf ("UPnP Initialized OK ip=3D%s, port=3D%d\n",=20
            (ip_address ? ip_address : "UNKNOWN"), port);
        //sprintf(desc_doc_url ,"http://%s:%d/%s", UpnpGetServerIpAddress=
(),port ,desc_doc_name );
        sprintf(desc_doc_url ,"http://%s/%s", UpnpGetServerIpAddress() ,d=
esc_doc_name );
        printf("desc_doc_url =3D %s\n", desc_doc_url );
    } else {
        printf ("** ERROR UpnpInit(): %d", rc);
        printf ("\n");
        exit (EXIT_FAILURE); // ---------->
    }

/*    if( UPNP_E_SUCCESS =3D=3D UpnpSetWebServerRootDir(web_dir) ){
        printf("Webserver_setdir succeed.\n");
    }else printf("Webserver_setdir failure.\n");

    if( UPNP_E_SUCCESS =3D=3D UpnpEnableWebserver(TRUE) ){
        printf("Webserver succeed.\n");
    }else printf("Webserver failure.\n");*/

    if( UPNP_E_SUCCESS =3D=3D (test =3D UpnpRegisterRootDevice( desc_doc_=
url=20
                        ,CallbackEventHandler ,&device_handle , &device_h=
andle)) ) {
printf("DEBUG point\n");
    }else printf("UpnpRegisterRootDevice failure.\n");

/*    if( UPNP_E_SUCCESS =3D=3D (test =3D UpnpRegisterRootDevice2( UPNPRE=
G_URL_DESC , desc_doc_url , 0=20
                    , 0 ,CallbackEventHandler ,&device_handle , &device_h=
andle)) ) {
printf("DEBUG point\n");
    }else printf("UpnpRegisterRootDevice2 failure.\n");*/

printf("UPNP_E =3D %d\n",test);

    if( UPNP_E_SUCCESS =3D=3D UpnpSendAdvertisement( device_handle, 30 ) =
){
        printf("device advertisement succeed.\n");
    }else printf("device advertisement failure.\n");

/*    if( UPNP_E_SUCCESS =3D=3D UpnpUnRegisterRootDevice( device_handle )=
)
        printf("Unregister succeed.\n");
    else
        printf("Unregister failure.\n");
*/
    if( UPNP_E_SUCCESS =3D=3D UpnpFinish() ){
        printf("device finish succeed.\n");
    }else printf("device finish failure.\n");
while(1){};
}
int CallbackEventHandler( Upnp_EventType EventType, void* Event, void* Co=
okie )
{
printf("in callback function...");

    switch( EventType ) {
        default:
            printf("UNKOWN EVENT TYPE\n");
    }

    return 0;
}

}


--_e173b455-cdf1-4aca-b206-7f8cf40b90c2_
Content-Type: text/html; charset="big5"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class=3D'hmmessage'>
My device sent SSDP message repeatly until the process ends.<br><br>below=
 is the code<br><br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;=
<br>#include &lt;unistd.h&gt;<br>#include &lt;upnptools.h&gt;<br>#include=
 &lt;ithread.h&gt;<br>#include &lt;ixml.h&gt;<br>#include &lt;upnp/upnp.h=
&gt;<br><br>int CallbackEventHandler( Upnp_EventType EventType, void* , v=
oid* );<br><br><br>int main(){<br>&nbsp;&nbsp;&nbsp; int rc,port,test,cod=
e;<br>&nbsp;&nbsp;&nbsp; char *web_dir =3D "./web";<br>&nbsp;&nbsp;&nbsp;=
 char desc_doc_url[200],*desc_doc_name =3D "tvdevicedesc.xml", *ip_addres=
s;<br><br>&nbsp;&nbsp;&nbsp; UpnpDevice_Handle device_handle;<br><br>&nbs=
p;&nbsp;&nbsp; rc =3D UpnpInit (NULL, 0);<br>&nbsp;&nbsp;&nbsp; if ( UPNP=
_E_SUCCESS =3D=3D rc ) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; const c=
har* ip_address =3D UpnpGetServerIpAddress();<br>&nbsp;&nbsp;&nbsp; &nbsp=
;&nbsp;&nbsp; unsigned short port&nbsp;&nbsp;&nbsp; =3D UpnpGetServerPort=
();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp=
;&nbsp;&nbsp; printf ("UPnP Initialized OK ip=3D%s, port=3D%d\n", <br>&nb=
sp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (ip_address ? ip_ad=
dress : "UNKNOWN"), port);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //spr=
intf(desc_doc_url ,"http://%s:%d/%s", UpnpGetServerIpAddress(),port ,desc=
_doc_name );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sprintf(desc_doc_ur=
l ,"http://%s/%s", UpnpGetServerIpAddress() ,desc_doc_name );<br>&nbsp;&n=
bsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("desc_doc_url =3D %s\n", desc_doc_ur=
l );<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nb=
sp; printf ("** ERROR UpnpInit(): %d", rc);<br>&nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp; printf ("\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exit =
(EXIT_FAILURE); // ----------&gt;<br>&nbsp;&nbsp;&nbsp; }<br><br>/*&nbsp;=
&nbsp;&nbsp; if( UPNP_E_SUCCESS =3D=3D UpnpSetWebServerRootDir(web_dir) )=
{<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("Webserver_setdir succe=
ed.\n");<br>&nbsp;&nbsp;&nbsp; }else printf("Webserver_setdir failure.\n"=
);<br><br>&nbsp;&nbsp;&nbsp; if( UPNP_E_SUCCESS =3D=3D UpnpEnableWebserve=
r(TRUE) ){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("Webserver suc=
ceed.\n");<br>&nbsp;&nbsp;&nbsp; }else printf("Webserver failure.\n");*/<=
br><br>&nbsp;&nbsp;&nbsp; if( UPNP_E_SUCCESS =3D=3D (test =3D UpnpRegiste=
rRootDevice( desc_doc_url <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp=
;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ,C=
allbackEventHandler ,&amp;device_handle , &amp;device_handle)) ) {<br>pri=
ntf("DEBUG point\n");<br>&nbsp;&nbsp;&nbsp; }else printf("UpnpRegisterRoo=
tDevice failure.\n");<br><br>/*&nbsp;&nbsp;&nbsp; if( UPNP_E_SUCCESS =3D=3D=
 (test =3D UpnpRegisterRootDevice2( UPNPREG_URL_DESC , desc_doc_url , 0 <=
br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&=
nbsp; &nbsp;&nbsp;&nbsp; , 0 ,CallbackEventHandler ,&amp;device_handle , =
&amp;device_handle)) ) {<br>printf("DEBUG point\n");<br>&nbsp;&nbsp;&nbsp=
; }else printf("UpnpRegisterRootDevice2 failure.\n");*/<br><br>printf("UP=
NP_E =3D %d\n",test);<br><br>&nbsp;&nbsp;&nbsp; if( UPNP_E_SUCCESS =3D=3D=
 UpnpSendAdvertisement( device_handle, 30 ) ){<br>&nbsp;&nbsp;&nbsp; &nbs=
p;&nbsp;&nbsp; printf("device advertisement succeed.\n");<br>&nbsp;&nbsp;=
&nbsp; }else printf("device advertisement failure.\n");<br><br>/*&nbsp;&n=
bsp;&nbsp; if( UPNP_E_SUCCESS =3D=3D UpnpUnRegisterRootDevice( device_han=
dle ))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("Unregister succee=
d.\n");<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbs=
p; printf("Unregister failure.\n");<br>*/<br>&nbsp;&nbsp;&nbsp; if( UPNP_=
E_SUCCESS =3D=3D UpnpFinish() ){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=
 printf("device finish succeed.\n");<br>&nbsp;&nbsp;&nbsp; }else printf("=
device finish failure.\n");<br>while(1){};<br>}<br>int CallbackEventHandl=
er( Upnp_EventType EventType, void* Event, void* Cookie )<br>{<br>printf(=
"in callback function...");<br><br>&nbsp;&nbsp;&nbsp; switch( EventType )=
 {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:<br>&nbsp;&nbsp;&nbsp=
; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("UNKOWN EVENT TYPE\n");<br=
>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br><br>}<b=
r><br></body>
</html>
--_e173b455-cdf1-4aca-b206-7f8cf40b90c2_--


--===============1454925822==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
--===============1454925822==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
UPnP-SDK-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/upnp-sdk-discuss

--===============1454925822==--