Ejemplo n.º 1
0
    def do_POST(self):
        #print "POST path", self.path
        parsed_path = urlparse.urlparse(self.path)
        message_parts = [
                'CLIENT VALUES:',
                'client_address=%s (%s)' % (self.client_address,
                                            self.address_string()),
                'command=%s' % self.command,
                'path=%s' % self.path,
                'real path=%s' % parsed_path.path,
                'query=%s' % parsed_path.query,
                'request_version=%s' % self.request_version,
                '',
                'SERVER VALUES:',
                'server_type=%s' % "host server",
                'server_version=%s' % self.server_version,
                'sys_version=%s' % self.sys_version,
                'protocol_version=%s' % self.protocol_version,
                '',
                'HEADERS RECEIVED:',
                ]
        for name, value in sorted(self.headers.items()):
            message_parts.append('%s=%s' % (name, value.rstrip()))
        message_parts.append('')
        message = '\r\n'.join(message_parts)

        length = int(self.headers.get("Content-Length"))

        body = ""
        subpath = self.path.split("/")
        
        if subpath[1] == "msg":
            dst = subpath[2]
            src = subpath[3]

            dirname = "snapw.%d/qin/%s" % (self.pid, dst)
            config.mkdir_p(dirname)

            fname = "%s/%s" % (dirname, src)
            f, fnew = config.uniquefile(fname)
            if fname <> fnew:
                logging.warn("uniquefile?: %s; %s; %s; %s;" % (dirname, src, fname, fnew))

            length = int(self.headers.get("Content-Length"))
            #print "Content-Length", length

            try:
                nleft = length
                while nleft > 0:
                    nread = min(102400, nleft)
                    body = self.rfile.read(nread)
                    f.write(body)
                    nleft -= len(body)
            except Exception as e:
                logging.warn("file stream error: %s" % str(e))
                try:
                    f.close()
                    os.remove(fnew)
                except:
                    pass
                try:
                    self.send_response(200)
                    self.send_header('Content-Length', 0)
                    self.end_headers()
                except:
                    pass
                return
                
            f.close()
            logging.info("message %s length %d" % (fnew,  length))

            self.send_response(200)
            self.send_header('Content-Length', 0)
            self.end_headers()
            return

        length = int(self.headers.get("Content-Length"))
        #print "Content-Length", length

        body = ""
        if length  and  length > 0:
            body = self.rfile.read(length)

        # Begin the response
        self.send_response(200)
        self.end_headers()
        self.wfile.write('Client: %s\n' % str(self.client_address))
        self.wfile.write('User-agent: %s\n' % str(self.headers['user-agent']))
        self.wfile.write('Path: %s\n' % self.path)
Ejemplo n.º 2
0
    def do_POST(self):
        #print "POST path", self.path
        parsed_path = urlparse.urlparse(self.path)
        message_parts = [
                'CLIENT VALUES:',
                'client_address=%s (%s)' % (self.client_address,
                                            self.address_string()),
                'command=%s' % self.command,
                'path=%s' % self.path,
                'real path=%s' % parsed_path.path,
                'query=%s' % parsed_path.query,
                'request_version=%s' % self.request_version,
                '',
                'SERVER VALUES:',
                'server_type=%s' % "host server",
                'server_version=%s' % self.server_version,
                'sys_version=%s' % self.sys_version,
                'protocol_version=%s' % self.protocol_version,
                '',
                'HEADERS RECEIVED:',
                ]
        for name, value in sorted(self.headers.items()):
            message_parts.append('%s=%s' % (name, value.rstrip()))
        message_parts.append('')
        message = '\r\n'.join(message_parts)
        #print message

        length = int(self.headers.get("Content-Length"))
        #print "Content-Length", length

        body = ""
        if length  and  length > 0:
            body = self.rfile.read(length)

        #print "length", length
        #print "body"
        #print body

        subpath = self.path.split("/")
        #print subpath
        
        if subpath[1] == "msg":
            dst = subpath[2]
            src = subpath[3]
            #print "msg", dst, src
            #print "body", body

            dirname = "snapw.%d/qin/%s" % (self.pid, dst)
            config.mkdir_p(dirname)

            fname = "%s/%s" % (dirname, src)
            f,fnew = config.uniquefile(fname)
            f.write(body)
            f.close()
    
            line = "message %s length %d\n" % (fnew,  length)
            self.flog.write(line)
            self.flog.flush()

            self.send_response(200)
            self.send_header('Content-Length', 0)
            self.end_headers()
            return

        # Begin the response
        self.send_response(200)
        self.end_headers()
        self.wfile.write('Client: %s\n' % str(self.client_address))
        self.wfile.write('User-agent: %s\n' % str(self.headers['user-agent']))
        self.wfile.write('Path: %s\n' % self.path)
Ejemplo n.º 3
0
    def do_POST(self):
        #print "POST path", self.path
        parsed_path = urlparse.urlparse(self.path)
        message_parts = [
                'CLIENT VALUES:',
                'client_address=%s (%s)' % (self.client_address,
                                            self.address_string()),
                'command=%s' % self.command,
                'path=%s' % self.path,
                'real path=%s' % parsed_path.path,
                'query=%s' % parsed_path.query,
                'request_version=%s' % self.request_version,
                '',
                'SERVER VALUES:',
                'server_type=%s' % "host server",
                'server_version=%s' % self.server_version,
                'sys_version=%s' % self.sys_version,
                'protocol_version=%s' % self.protocol_version,
                '',
                'HEADERS RECEIVED:',
                ]
        for name, value in sorted(self.headers.items()):
            message_parts.append('%s=%s' % (name, value.rstrip()))
        message_parts.append('')
        message = '\r\n'.join(message_parts)

        length = int(self.headers.get("Content-Length"))

        body = ""
        subpath = self.path.split("/")
        
        if subpath[1] == "msg":
            dst = subpath[2]
            src = subpath[3]

            dirname = "snapw.%d/qin/%s" % (self.pid, dst)
            config.mkdir_p(dirname)

            fname = "%s/%s" % (dirname, src)
            f, fnew = config.uniquefile(fname)
            if fname <> fnew:
                logging.warn("uniquefile?: %s; %s; %s; %s;" % (dirname, src, fname, fnew))

            length = int(self.headers.get("Content-Length"))
            #print "Content-Length", length

            try:
                nleft = length
                while nleft > 0:
                    nread = min(102400, nleft)
                    body = self.rfile.read(nread)
                    f.write(body)
                    nleft -= len(body)
            except Exception as e:
                logging.warn("file stream error: %s" % str(e))
                try:
                    f.close()
                    os.remove(fnew)
                except:
                    pass
                try:
                    self.send_response(200)
                    self.send_header('Content-Length', 0)
                    self.end_headers()
                except:
                    pass
                return
                
            f.close()
            logging.info("message %s length %d" % (fnew,  length))

            self.send_response(200)
            self.send_header('Content-Length', 0)
            self.end_headers()
            return

        length = int(self.headers.get("Content-Length"))
        #print "Content-Length", length

        body = ""
        if length  and  length > 0:
            body = self.rfile.read(length)

        # Begin the response
        self.send_response(200)
        self.end_headers()
        self.wfile.write('Client: %s\n' % str(self.client_address))
        self.wfile.write('User-agent: %s\n' % str(self.headers['user-agent']))
        self.wfile.write('Path: %s\n' % self.path)
Ejemplo n.º 4
0
    def do_POST(self):
        #print "POST path", self.path
        parsed_path = urlparse.urlparse(self.path)
        message_parts = [
            'CLIENT VALUES:',
            'client_address=%s (%s)' %
            (self.client_address, self.address_string()),
            'command=%s' % self.command,
            'path=%s' % self.path,
            'real path=%s' % parsed_path.path,
            'query=%s' % parsed_path.query,
            'request_version=%s' % self.request_version,
            '',
            'SERVER VALUES:',
            'server_type=%s' % "host server",
            'server_version=%s' % self.server_version,
            'sys_version=%s' % self.sys_version,
            'protocol_version=%s' % self.protocol_version,
            '',
            'HEADERS RECEIVED:',
        ]
        for name, value in sorted(self.headers.items()):
            message_parts.append('%s=%s' % (name, value.rstrip()))
        message_parts.append('')
        message = '\r\n'.join(message_parts)
        #print message

        #print "length", length
        #print "body"
        #print body

        subpath = self.path.split("/")
        #print subpath

        if subpath[1] == "msg":
            dst = subpath[2]
            src = subpath[3]
            #print "msg", dst, src
            #print "body", body

            dirname = "snapw.%d/qin/%s" % (self.pid, dst)
            config.mkdir_p(dirname)

            fname = "%s/%s" % (dirname, src)
            f, fnew = config.uniquefile(fname)

            length = int(self.headers.get("Content-Length"))
            #print "Content-Length", length

            nleft = length
            while nleft > 0:
                nread = 102400
                if nleft < nread:
                    nread = nleft

                body = self.rfile.read(nread)
                f.write(body)

                nleft -= nread

            f.close()

            line = "message %s length %d\n" % (fnew, length)
            self.flog.write(line)
            self.flog.flush()

            self.send_response(200)
            self.send_header('Content-Length', 0)
            self.end_headers()
            return

        length = int(self.headers.get("Content-Length"))
        #print "Content-Length", length

        body = ""
        if length and length > 0:
            body = self.rfile.read(length)

        # Begin the response
        self.send_response(200)
        self.end_headers()
        self.wfile.write('Client: %s\n' % str(self.client_address))
        self.wfile.write('User-agent: %s\n' % str(self.headers['user-agent']))
        self.wfile.write('Path: %s\n' % self.path)