Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

PUPnP usage on iPhone

Help
tom dev
2011-01-09
2012-12-14
  • tom dev
    tom dev
    2011-01-09

    Hi all,
    I am a reasonably proficient iPhone dev but have not come from a linux background and am at a complete loss as to how to build and use this library on the iPhone. Is there an idiots guide somewhere or can someone gently nudge me in the right direction?

    I'm guessing the best approach would be to create a static library in XCode with the pUPnP stack, anyone got any experience doing this?

     
  • tom dev
    tom dev
    2011-01-10

    so after a bit more experimentation I managed to create an iPhone library, add the source files from the ixml, threadutil, upnp and inc directory. this builds successfully and can now be used from another iphone project. Note that I had to add code for strndup() as iOS doesn't seem to know what this function is. I got the code for the function from here and added it to UpnpStrings.c

    http://www.opensource.apple.com/source/gcc/gcc-5646/libiberty/strndup.c

    So I pulled the sample util code into the iphone project and calling TvCtrlPointStart() seems to set things going and I get plenty of console output including discovery messages etc when running under iPhone simulator.

    Now I have a glimmer of life I guess I have a ton more reading to find my way round the SDK. I will also try to build and run the sample util on my mac to have a tv device for the iphone app to discover.

    I would like to implement a simple content browser. Any suggestions on how to approach this task? General tips, architectural (where does split between obj c and the lib come etc) or any pointers to example code would be appreciate.

    Thanks

     
  • tom dev
    tom dev
    2011-01-10

    Building the sample app under OSX seems to work and launching the ctrl point app prints lots of sensible looking discovery messages to the terminal albeit with "Error finding URLBase in XML Node" before every TvCtrlPointPrintList.

    However if i run the tv_device I get the following error:
    Error registering the rootdevice : -108

    I know this has been discussed in an old thread but I am using libupnp-1.6.10 and I followed the instructions in the README to add a folder called /tvdevice/web in the sample directory but running tv_device still gives the same error

     
  • Hi tomdev2,

    This is what I get when I run the tv_device sample:

    $ ./tv_device
    Initializing UPnP Sdk with
            ipaddress = {NULL} port = 0
    UPnP Initialized
            ipaddress = 192.168.1.2 port = 49152
    Specifying the webserver root directory - ./web
    Registering the RootDevice
             with desc_doc_url: http://192.168.1.2:49152/tvdevicedesc.xml
    RootDevice Registered
    Initializing State Table
    common/sample_util.c(221): Error finding URLBase in XML Node
    Found service: urn:schemas-upnp-org:service:tvcontrol:1
    serviceId: urn:upnp-org:serviceId:tvcontrol1
    common/sample_util.c(221): Error finding URLBase in XML Node
    Found service: urn:schemas-upnp-org:service:tvpicture:1
    serviceId: urn:upnp-org:serviceId:tvpicture1
    State Table Initialized
    Advertisements Sent

    The message "Error finding URLBase in XML Node" is ok, maybe we should suppress it, but requires some analysis in the code to be sure.

    I have no problems registering the root device, but I am using the latest code in the git repository, could you try it? The 1.6.10 release sample code is buggy. If you think there is still a bug, it would be nice if we could fix it before releasing 1.6.11.

    Regards,
    Marcelo.

     
  • tom dev
    tom dev
    2011-01-10

    Hi Marcelo,
    I downloaded a snapshot of the last commit in the Git repository but there doesn't seem to be a configure file so

    ./configure

    returns:

    -bash: ./configure: No such file or directory

    Regards
    Tom

     
  • Tom,

    You must generate one when getting the sources from the repository. Do:

    $ ./bootstrap

    You must have autoconf/automake installed.

    Regards,
    Marcelo.

     
  • tom dev
    tom dev
    2011-01-10

    I have the last commit  (pupnp-82207a3) and am using OSX 10.6.6.
    I installed mac ports then autoconf, automake and libtool

    running ./bootstrap then ./configure then make looks like it runs through the whole build process successfully. Then I built the sample code

    Now when I run the tv_ctrlpt example (which worked with libupnp-1.6.10) it fails as follows:

    Initializing UPnP Sdk with
    ipaddress = {NULL} port = 0
    UPnP Initialized
    ipaddress = 192.168.0.8 port = 49152
    Registering Control Point
    Control Point Registered

    >> dyld: lazy symbol binding failed: Symbol not found: _strndup
      Referenced from: /Users/Tom/pupnp-82207a3/upnp/.libs/libupnp.6.dylib
      Expected in: flat namespace

    dyld: Symbol not found: _strndup
      Referenced from: /Users/Tom/pupnp-82207a3/upnp/.libs/libupnp.6.dylib
      Expected in: flat namespace

    Trace/BPT trap
    logout

    And running tv_device fails as before:
    Initializing UPnP Sdk with
    ipaddress = {NULL} port = 0
    UPnP Initialized
    ipaddress = 192.168.0.8 port = 49152
    Specifying the webserver root directory - ./web
    Registering the RootDevice
    with desc_doc_url: http://192.168.0.8:49152/tvdevicedesc.xml
    Error registering the rootdevice : -108

    Regards
    Tom

     
  • Try to replace line 41 of /upnp/src/api/UpnpString.c:

    #elif defined(WIN32)

    with this line

    #else

    And then please report back. Are you using gcc? Which version? If you are using gcc, please post the result of

    gcc -dM -E - < /dev/null | sort

    Regards,
    Marcelo.

     
  • tom dev
    tom dev
    2011-01-11

    Hi Marcelo,
    I changed the line but still has the same problem with strndup not found. I had to fix a similar problem when compiling for iPhone as I don't think OSX has strndup (at least that what google told me). I had to substitute the following code to make it work:

    http://www.opensource.apple.com/source/gcc/gcc-5646/libiberty/strndup.c

    like this:

    /* strndup() is a GNU extension. Other systems must fix it with elif's. */
    #ifdef __GNUC__
    char *strndup (const char *s, size_t n)
    {
    char *result;
    size_t len = strlen (s);

    if (n < len)
    len = n;

    result = (char *) malloc (len + 1);
    if (!result)
    return 0;

    result = '\0';
    return (char *) memcpy (result, s, len);
    }
    #endif

    My compiler gives the following:

    #define OBJC_NEW_PROPERTIES 1
    #define _LP64 1
    #define __APPLE_CC__ 5664
    #define __APPLE__ 1
    #define __BLOCKS__ 1
    #define __CHAR_BIT__ 8
    #define __CONSTANT_CFSTRINGS__ 1
    #define __DBL_DENORM_MIN__ 4.9406564584124654e-324
    #define __DBL_DIG__ 15
    #define __DBL_EPSILON__ 2.2204460492503131e-16
    #define __DBL_HAS_DENORM__ 1
    #define __DBL_HAS_INFINITY__ 1
    #define __DBL_HAS_QUIET_NAN__ 1
    #define __DBL_MANT_DIG__ 53
    #define __DBL_MAX_10_EXP__ 308
    #define __DBL_MAX_EXP__ 1024
    #define __DBL_MAX__ 1.7976931348623157e+308
    #define __DBL_MIN_10_EXP__ (-307)
    #define __DBL_MIN_EXP__ (-1021)
    #define __DBL_MIN__ 2.2250738585072014e-308
    #define __DEC128_DEN__ 0.000000000000000000000000000000001E-6143DL
    #define __DEC128_EPSILON__ 1E-33DL
    #define __DEC128_MANT_DIG__ 34
    #define __DEC128_MAX_EXP__ 6144
    #define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
    #define __DEC128_MIN_EXP__ (-6143)
    #define __DEC128_MIN__ 1E-6143DL
    #define __DEC32_DEN__ 0.000001E-95DF
    #define __DEC32_EPSILON__ 1E-6DF
    #define __DEC32_MANT_DIG__ 7
    #define __DEC32_MAX_EXP__ 96
    #define __DEC32_MAX__ 9.999999E96DF
    #define __DEC32_MIN_EXP__ (-95)
    #define __DEC32_MIN__ 1E-95DF
    #define __DEC64_DEN__ 0.000000000000001E-383DD
    #define __DEC64_EPSILON__ 1E-15DD
    #define __DEC64_MANT_DIG__ 16
    #define __DEC64_MAX_EXP__ 384
    #define __DEC64_MAX__ 9.999999999999999E384DD
    #define __DEC64_MIN_EXP__ (-383)
    #define __DEC64_MIN__ 1E-383DD
    #define __DECIMAL_DIG__ 21
    #define __DEC_EVAL_METHOD__ 2
    #define __DYNAMIC__ 1
    #define __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 1066
    #define __FINITE_MATH_ONLY__ 0
    #define __FLT_DENORM_MIN__ 1.40129846e-45F
    #define __FLT_DIG__ 6
    #define __FLT_EPSILON__ 1.19209290e-7F
    #define __FLT_EVAL_METHOD__ 0
    #define __FLT_HAS_DENORM__ 1
    #define __FLT_HAS_INFINITY__ 1
    #define __FLT_HAS_QUIET_NAN__ 1
    #define __FLT_MANT_DIG__ 24
    #define __FLT_MAX_10_EXP__ 38
    #define __FLT_MAX_EXP__ 128
    #define __FLT_MAX__ 3.40282347e+38F
    #define __FLT_MIN_10_EXP__ (-37)
    #define __FLT_MIN_EXP__ (-125)
    #define __FLT_MIN__ 1.17549435e-38F
    #define __FLT_RADIX__ 2
    #define __GNUC_GNU_INLINE__ 1
    #define __GNUC_MINOR__ 2
    #define __GNUC_PATCHLEVEL__ 1
    #define __GNUC__ 4
    #define __GXX_ABI_VERSION 1002
    #define __INTMAX_MAX__ 9223372036854775807L
    #define __INTMAX_TYPE__ long int
    #define __INT_MAX__ 2147483647
    #define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
    #define __LDBL_DIG__ 18
    #define __LDBL_EPSILON__ 1.08420217248550443401e-19L
    #define __LDBL_HAS_DENORM__ 1
    #define __LDBL_HAS_INFINITY__ 1
    #define __LDBL_HAS_QUIET_NAN__ 1
    #define __LDBL_MANT_DIG__ 64
    #define __LDBL_MAX_10_EXP__ 4932
    #define __LDBL_MAX_EXP__ 16384
    #define __LDBL_MAX__ 1.18973149535723176502e+4932L
    #define __LDBL_MIN_10_EXP__ (-4931)
    #define __LDBL_MIN_EXP__ (-16381)
    #define __LDBL_MIN__ 3.36210314311209350626e-4932L
    #define __LITTLE_ENDIAN__ 1
    #define __LONG_LONG_MAX__ 9223372036854775807LL
    #define __LONG_MAX__ 9223372036854775807L
    #define __LP64__ 1
    #define __MACH__ 1
    #define __MMX__ 1
    #define __NO_INLINE__ 1
    #define __PIC__ 2
    #define __PTRDIFF_TYPE__ long int
    #define __REGISTER_PREFIX__
    #define __SCHAR_MAX__ 127
    #define __SHRT_MAX__ 32767
    #define __SIZE_TYPE__ long unsigned int
    #define __SSE2_MATH__ 1
    #define __SSE2__ 1
    #define __SSE3__ 1
    #define __SSE_MATH__ 1
    #define __SSE__ 1
    #define __SSP__ 1
    #define __STDC_HOSTED__ 1
    #define __STDC__ 1
    #define __UINTMAX_TYPE__ long unsigned int
    #define __USER_LABEL_PREFIX__ _
    #define __VERSION__ "4.2.1 (Apple Inc. build 5664)"
    #define __WCHAR_MAX__ 2147483647
    #define __WCHAR_TYPE__ int
    #define __WINT_TYPE__ int
    #define __amd64 1
    #define __amd64__ 1
    #define __block __attribute__((__blocks__(byref)))
    #define __k8 1
    #define __k8__ 1
    #define __pic__ 2
    #define __strong
    #define __tune_core2__ 1
    #define __weak __attribute__((objc_gc(weak)))
    #define __x86_64 1
    #define __x86_64__ 1

     
  • Hi Tom,

    Thanks for your help, please try the latest git code.

    Regards,
    Marcelo.

     
  • tom dev
    tom dev
    2011-01-17

    Hi Marcelo,
    I tried the latest Git and the build now works, Great!
    I also got the TV device working by creating a tvdevice folder, moving the web folder into the tvdevice folder then launching the program from the command line (rather than double clicking from the Finder window). It does actually explain this in the README file but it is slightly out of date. This is what it currently says:

    _
    will build the sample device "$(LIBUPNP)/upnp/upnp_tv_device" and
    sample control point "$(LIBUPNP)/upnp/upnp_tv_ctrlpt".
    Note : the sample device won't be built if -disable-device has been
    configured, and the sample control point won't be build if -disable-client
    has been configured.

    To run the sample device, you need the "$(LIBUPNP)/upnp/sample/tvdevice/web"
    sub-directory. Example :

    % cd $(LIBUPNP)/upnp/sample/tvdevice
    % ../../upnp_tv_device
    _

    But it should say something like:

    _
    will build the sample device "$(LIBUPNP)/upnp/tv_device" and
    sample control point "$(LIBUPNP)/upnp/tv_ctrlpt".
    Note : the sample device won't be built if -disable-device has been
    configured, and the sample control point won't be build if -disable-client
    has been configured.

    To run the sample device, you need to create a tvdevice directory and move the web directory there, giving: "$(LIBUPNP)/upnp/sample/tvdevice/web".
    To run the sample invoke from the command line as follows:

    % cd $(LIBUPNP)/upnp/sample/tvdevice
    % ../tv_device
    _

     
  • Hi Tom,

    Thank you for your help, the modification you suggested has been committed.

    Regards,
    Marcelo.

     
  • Hao Hu
    Hao Hu
    2011-07-11

    Hi Tom,
    Thanks for you post. I tried to compile the libupnp on Mac OS X for iOS, the configure seems no problem. But when I try to "make", I got the error /usr/bin/ranlib: file: .libs/libupnp.a(libupnp_la-soap_common.o) has no symbols
    /usr/bin/ranlib: file: .libs/libupnp.a(libupnp_la-inet_pton.o) has no symbols
    libtool: link: ranlib .libs/libupnp.a
    ranlib: file: .libs/libupnp.a(libupnp_la-soap_common.o) has no symbols
    ranlib: file: .libs/libupnp.a(libupnp_la-inet_pton.o) has no symbols
    sed: Projects/libupnp-1.6.13/threadutil/libthreadutil.la: No such file or directory
    libtool: link: `Projects/libupnp-1.6.13/threadutil/libthreadutil.la' is not a valid libtool archive
    make: ***  Error 1
    make: ***  Error 1
    make: ***  Error 1
    make: ***  Error 2

    Could you please post your entire configure with parameters, thanks very much for any help.
    Cheers,
    Hao