|
@ -13,18 +13,14 @@ import logging, logging.config |
|
|
logging.config.fileConfig('pylog.conf') |
|
|
logging.config.fileConfig('pylog.conf') |
|
|
logger = logging.getLogger('meshenger'+'.clientserve') |
|
|
logger = logging.getLogger('meshenger'+'.clientserve') |
|
|
|
|
|
|
|
|
# this variable is set from main, to be called when new messages available |
|
|
|
|
|
# build_index_callback = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
|
|
|
|
|
|
messageDir = "msg" |
|
|
messageDir = "msg" |
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
Serve index and messages |
|
|
|
|
|
""" |
|
|
|
|
|
def do_GET(self): |
|
|
def do_GET(self): |
|
|
|
|
|
""" |
|
|
|
|
|
Serve index and messages |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
if self.path == '/index' or self.path.startswith( "/"+self.messageDir ): |
|
|
if self.path == '/index' or self.path.startswith( "/"+self.messageDir ): |
|
|
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) |
|
|
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) |
|
@ -44,10 +40,10 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
self.wfile.write(the_file.read()) |
|
|
self.wfile.write(the_file.read()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
Allow clients to post messages |
|
|
|
|
|
""" |
|
|
|
|
|
def do_POST(self): |
|
|
def do_POST(self): |
|
|
|
|
|
""" |
|
|
|
|
|
Allow clients to post messages |
|
|
|
|
|
""" |
|
|
if self.path == '/send': |
|
|
if self.path == '/send': |
|
|
logger.info('incoming message from client!') |
|
|
logger.info('incoming message from client!') |
|
|
length = int(self.headers['Content-Length']) |
|
|
length = int(self.headers['Content-Length']) |
|
@ -69,7 +65,9 @@ class ClientServeHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
def writeMessage(self, time, message): |
|
|
def writeMessage(self, time, message): |
|
|
|
|
|
""" |
|
|
|
|
|
Write message to disk |
|
|
|
|
|
""" |
|
|
f = os.path.join( self.messageDir, time) |
|
|
f = os.path.join( self.messageDir, time) |
|
|
if os.path.isfile( f ): |
|
|
if os.path.isfile( f ): |
|
|
return |
|
|
return |
|
|