XML-RPC server via xinetd

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jos Vos

    #1

    XML-RPC server via xinetd

    Hi,

    I'm trying to figure out how to implement a XML-RPC server that
    is called by xinetd i.s.o. listening on a TCP socket itself.

    I already have implemented a stand-alone XML-RPC server using
    SimpleXMLRPCSer ver, but I now want something similar, that is
    started via xinetd (i.e. reading/writing via stdin/stdout).

    Any hints or code examples?

    Thanks,

    --
    -- Jos Vos <jos@xos.nl>
    -- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
    -- Amsterdam, The Netherlands | Fax: +31 20 6948204
  • Martin P. Hellwig

    #2
    Re: XML-RPC server via xinetd

    Jos Vos wrote:[color=blue]
    > Hi,
    >
    > I'm trying to figure out how to implement a XML-RPC server that
    > is called by xinetd i.s.o. listening on a TCP socket itself.
    >
    > I already have implemented a stand-alone XML-RPC server using
    > SimpleXMLRPCSer ver, but I now want something similar, that is
    > started via xinetd (i.e. reading/writing via stdin/stdout).
    >
    > Any hints or code examples?
    >
    > Thanks,
    >[/color]

    Isn't this just a standard daemon functionality?
    So if you could wrap up your program in a daemon like fashion (e.g.
    http://homepage.hispeed.ch/py430/python/daemon.py) and then point the
    xinetd configuration to the right script, it should just work?

    Beware that I didn't try this myself yet ;-) though should do in the
    near future so if you could give a head ups on your progress I would
    appreciate it.

    --
    mph

    Comment

    • Jos Vos

      #3
      Re: XML-RPC server via xinetd

      On Sun, Apr 16, 2006 at 10:13:19PM +0200, Martin P. Hellwig wrote:
      [color=blue]
      > Isn't this just a standard daemon functionality?[/color]

      What is "a standard daemon"? :-)
      [color=blue]
      > So if you could wrap up your program in a daemon like fashion (e.g.
      > http://homepage.hispeed.ch/py430/python/daemon.py) and then point the
      > xinetd configuration to the right script, it should just work?[/color]

      In fact, the standard use *is* a daemon (that is, accepting connections
      on a certain port) and I want it to be *not* a daemon. For the daemon
      method I use something similar to "daemonize" , but now I want it to
      *not* do the binds etc. to listen on a port.

      The problem is that the server initialization *requires* a server
      address (host, port pair), but I don't see how to tell it to use
      the stdin socket (and I'm afraid this is not possible, but I'm not
      sure).

      --
      -- Jos Vos <jos@xos.nl>
      -- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
      -- Amsterdam, The Netherlands | Fax: +31 20 6948204

      Comment

      • Martin P. Hellwig

        #4
        Re: XML-RPC server via xinetd

        Jos Vos wrote:
        <cut>[color=blue]
        >
        > The problem is that the server initialization *requires* a server
        > address (host, port pair), but I don't see how to tell it to use
        > the stdin socket (and I'm afraid this is not possible, but I'm not
        > sure).
        >[/color]

        If I understood it correctly you want the python server bind be
        depending on whatever is configured in xinetd.conf and not be defined in
        the your program itself?

        I tested a bit around with my FreeBSD machine but indeed the OS
        environment gives me nothing interesting back, leaving that option out
        but I do can specify command line arguments so you could pick them up
        with sys.argv.

        I looked up how you can specify arguments in xinetd and according to
        various resources I filtered out (gotta over these gnu type
        documentation.. .) that you can use "server_arg s" in the per service
        configuration to specify arguments.

        Although not really elegant it is doable to do an on the fly port binding.

        Now I just hope I understood your problem :-)

        --
        mph

        Comment

        • Nick Craig-Wood

          #5
          Re: XML-RPC server via xinetd

          Jos Vos <jos@xos.nl> wrote:[color=blue]
          > I'm trying to figure out how to implement a XML-RPC server that
          > is called by xinetd i.s.o. listening on a TCP socket itself.
          >
          > I already have implemented a stand-alone XML-RPC server using
          > SimpleXMLRPCSer ver, but I now want something similar, that is
          > started via xinetd (i.e. reading/writing via stdin/stdout).
          >
          > Any hints or code examples?[/color]

          UTSL ;-)

          Look at /usr/lib/python2.4/SimpleXMLRPCSer ver.py (adjust as per your
          distro) and in particular the definition of the CGIXMLRPCReques tHandler class.

          That looks as thought it almost, or maybe completely, does what you
          want, ie an XMLRPC subclass which reads from stdin and writes to
          stdout.

          --
          Nick Craig-Wood <nick@craig-wood.com> -- http://www.craig-wood.com/nick

          Comment

          • Jos Vos

            #6
            Re: XML-RPC server via xinetd

            On Mon, Apr 17, 2006 at 02:07:37AM +0200, Martin P. Hellwig wrote:
            [color=blue]
            > If I understood it correctly you want the python server bind be
            > depending on whatever is configured in xinetd.conf and not be defined in
            > the your program itself?
            >
            > I tested a bit around with my FreeBSD machine but indeed the OS
            > environment gives me nothing interesting back, leaving that option out
            > but I do can specify command line arguments so you could pick them up
            > with sys.argv.
            >
            > I looked up how you can specify arguments in xinetd and according to
            > various resources I filtered out (gotta over these gnu type
            > documentation.. .) that you can use "server_arg s" in the per service
            > configuration to specify arguments.
            >
            > Although not really elegant it is doable to do an on the fly port binding.
            >
            > Now I just hope I understood your problem :-)[/color]

            No, you didn't :-). I could add these options or even write an
            xinetd-only program, that's all fine with me.

            The problem is that I do not see how to let an SimpleXMLRPCSer ver
            instance *not* bind to a port or what other class I can use to just
            build a XML-RPC request handler reading/writing from stdin/stdout,
            i.s.o. carrying all the server class stuff with it.

            --
            -- Jos Vos <jos@xos.nl>
            -- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
            -- Amsterdam, The Netherlands | Fax: +31 20 6948204

            Comment

            • Brian Quinlan

              #7
              Re: XML-RPC server via xinetd

              Jos Vos wrote:[color=blue]
              > The problem is that I do not see how to let an SimpleXMLRPCSer ver
              > instance *not* bind to a port or what other class I can use to just
              > build a XML-RPC request handler reading/writing from stdin/stdout,
              > i.s.o. carrying all the server class stuff with it.[/color]

              I think that the problem here is that we are confusing transport with
              request handling.

              If you take a look at CGIXMLRPCReques tHandler
              (http://docs.python.org/lib/node564.html), you will see an example of
              how to write an XMLRPCRequestHa ndler without HTTP.

              Cheers,
              Brian

              Comment

              • Jos Vos

                #8
                Re: XML-RPC server via xinetd

                On Mon, Apr 17, 2006 at 12:10:15PM +0200, Brian Quinlan wrote:
                [color=blue]
                > If you take a look at CGIXMLRPCReques tHandler
                > (http://docs.python.org/lib/node564.html), you will see an example of
                > how to write an XMLRPCRequestHa ndler without HTTP.[/color]

                Thanks, this might work for me, will try it.

                --
                -- Jos Vos <jos@xos.nl>
                -- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
                -- Amsterdam, The Netherlands | Fax: +31 20 6948204

                Comment

                • Jos Vos

                  #9
                  Re: XML-RPC server via xinetd

                  On Mon, Apr 17, 2006 at 03:30:04AM -0500, Nick Craig-Wood wrote:
                  [color=blue]
                  > UTSL ;-)
                  >
                  > Look at /usr/lib/python2.4/SimpleXMLRPCSer ver.py (adjust as per your
                  > distro) and in particular the definition of the CGIXMLRPCReques tHandler class.[/color]

                  I did this before posting my question, in fact, but I did not look
                  good enough maybe, as at first sight I thought tghe CGI... class
                  would be too CGI-specific (it looks for environment variables etc.
                  given by the HTTP server), but maybe it's good enough.
                  [color=blue]
                  > That looks as thought it almost, or maybe completely, does what you
                  > want, ie an XMLRPC subclass which reads from stdin and writes to
                  > stdout.[/color]

                  Will try...

                  --
                  -- Jos Vos <jos@xos.nl>
                  -- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
                  -- Amsterdam, The Netherlands | Fax: +31 20 6948204

                  Comment

                  • Brian Quinlan

                    #10
                    Re: XML-RPC server via xinetd

                    Jos Vos wrote:[color=blue]
                    > On Mon, Apr 17, 2006 at 03:30:04AM -0500, Nick Craig-Wood wrote:
                    >[color=green]
                    >> UTSL ;-)
                    >>
                    >> Look at /usr/lib/python2.4/SimpleXMLRPCSer ver.py (adjust as per your
                    >> distro) and in particular the definition of the CGIXMLRPCReques tHandler class.[/color]
                    >
                    > I did this before posting my question, in fact, but I did not look
                    > good enough maybe, as at first sight I thought tghe CGI... class
                    > would be too CGI-specific (it looks for environment variables etc.
                    > given by the HTTP server), but maybe it's good enough.[/color]

                    I don't know exactly what your usage pattern is, but you might be able
                    to use SimpleXMLRPCDis patcher directly e.g.
                    [color=blue][color=green][color=darkred]
                    >>> s = SimpleXMLRPCDis patcher()
                    >>> s.register_func tion(pow)
                    >>> s._marshaled_di spatch('<?xml version="1.0".. .)[/color][/color][/color]
                    '<?xml version="1.0".. .

                    Cheers,
                    Brian

                    Comment

                    • Fredrik Lundh

                      #11
                      Re: XML-RPC server via xinetd

                      Nick Craig-Wood wrote:
                      [color=blue]
                      > Look at /usr/lib/python2.4/SimpleXMLRPCSer ver.py (adjust as per your
                      > distro) and in particular the definition of the CGIXMLRPCReques tHandler class.
                      >
                      > That looks as thought it almost, or maybe completely, does what you
                      > want, ie an XMLRPC subclass which reads from stdin and writes to
                      > stdout.[/color]

                      except that if the OP's expecting the other end to use an ordinary XML-RPC
                      library, he needs to implement some minimal HTTP handling as well.

                      import sys
                      import mimetools, xmlrpclib

                      command = sys.stdin.readl ine()
                      # optional: check command syntax (POST url HTTP/1.X)

                      headers = mimetools.Messa ge(sys.stdin)
                      # optional: check content-type etc

                      bytes = int(headers.get ("content-length", 0))
                      # optional: check request size, etc

                      params, method = xmlrpclib.loads (sys.stdin.read (bytes))

                      # handle the method
                      result = ...

                      # marshaller expects a tuple
                      result = (result, )

                      response = xmlrpclib.dumps (result, methodresponse= 1)

                      print "HTTP/1.0 200 OK"
                      print "Content-Type: text/xml"
                      print "Content-Length:", len(response)
                      print
                      print response

                      (based on code from http://effbot.org/zone/xmlrpc-cgi.htm )

                      </F>



                      Comment

                      • Jos Vos

                        #12
                        Re: XML-RPC server via xinetd

                        On Mon, Apr 17, 2006 at 12:36:18PM +0200, Brian Quinlan wrote:
                        [color=blue]
                        > I don't know exactly what your usage pattern is, but you might be able
                        > to use SimpleXMLRPCDis patcher directly e.g.
                        >[color=green][color=darkred]
                        > >>> s = SimpleXMLRPCDis patcher()
                        > >>> s.register_func tion(pow)
                        > >>> s._marshaled_di spatch('<?xml version="1.0".. .)[/color][/color]
                        > '<?xml version="1.0".. .[/color]

                        Will look at that too, but as I want to be able to use the same XML-RPC
                        client as I talk to with my SimpleXMLRPCSer ver (thus talking HTTP), I
                        think I need to CGI sugar.

                        Note that the main reason I'm looking to the "xinetd way" is that
                        I want to use proper SSL-based traffic and the SecureXMLRPCSer ver
                        flying around, using pyOpenSSL (or so), does not do a complete job
                        (because pyOpenSSL does not do a complete job IIRC) and needs to
                        be tweaked anyway, so I now hope to use stunnel.

                        --
                        -- Jos Vos <jos@xos.nl>
                        -- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
                        -- Amsterdam, The Netherlands | Fax: +31 20 6948204

                        Comment

                        • Jos Vos

                          #13
                          Re: XML-RPC server via xinetd

                          On Mon, Apr 17, 2006 at 12:42:00PM +0200, Fredrik Lundh wrote:
                          [color=blue]
                          > except that if the OP's expecting the other end to use an ordinary XML-RPC
                          > library, he needs to implement some minimal HTTP handling as well.[/color]

                          Which makes me wondering why the classes (this also applies to
                          BaseHTTPServer / BaseHTTPRequest Handler) ae designed the way they
                          are. The underlying stream medium (TCP sockets or plain file
                          streams like stdin/stdout) should not be integrated with the
                          protocol (HTTP) handling, IMHO...

                          --
                          -- Jos Vos <jos@xos.nl>
                          -- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
                          -- Amsterdam, The Netherlands | Fax: +31 20 6948204

                          Comment

                          Working...