コード例 #1
0
 def do_GET(self):
     url = self.path
     tokenizedUrl = urlParser.parseUrl(url)
     
     #get the database from the url
     database = urlParser.getDatabase(tokenizedUrl)
     
     cookie = self.headers.get("Cookie", "")
     
     if currentDatabases.has_key(database): 
         currentDatabase = currentDatabases.get(database)
         currentDatabase.updateAuthDict()
         
         connected = currentDatabase.authenticateCookie(cookie)
         if not connected:
             self.send_response(401) #unathorized
         else:
             if len(tokenizedUrl) == 3:
                 command = sqlConverter.converSelect(tokenizedUrl)
                 try:
                     results = currentDatabase.executeSelectCommand(command)
                     self.send_response(302) # Found
                     self.send_header("Content-type", "text")
                     self.end_headers()
                     
                     self.wfile.write(jsonParser.createJsonResultForSelect(results))
                 except:
                     self.send_response(400) #bad request
             else:
                 self.send_response(400) #bad request
     else:
         self.send_response(400) #bad request
コード例 #2
0
 def do_DELETE(self):
     url = self.path
     tokenizedUrl = urlParser.parseUrl(url)
     
     #get the database from the url
     database = urlParser.getDatabase(tokenizedUrl)
     
     cookie = self.headers.get("Cookie", "")
     
     if currentDatabases.has_key(database): 
         currentDatabase = currentDatabases.get(database)
         currentDatabase.updateAuthDict()
         
         connected = currentDatabase.authenticateCookie(cookie)
         if not connected:
             self.send_response(401) #unathorized
         else:
             if len(tokenizedUrl) >= 3:
                 command = sqlConverter.convertDelete(tokenizedUrl)
                 if not currentDatabase.runCommand(command):
                     self.send_error(400) #Bad request
                 else:
                     self.send_response(202) #OK
             else:
                 self.send_response(400) #bad request
     else:
         self.send_response(400) #bad request
コード例 #3
0
 def do_PUT(self):
     url = self.path
     tokenizedUrl = urlParser.parseUrl(url)
     
     #get the database from the url
     database = urlParser.getDatabase(tokenizedUrl)
     
     varLen = int(self.headers.get("Content-Length", 0))
     data = self.rfile.read(varLen)
     
     cookie = self.headers.get("Cookie", "")
     
     if currentDatabases.has_key(database): 
         currentDatabase = currentDatabases.get(database)
         currentDatabase.updateAuthDict()
         
         connected = currentDatabase.authenticateCookie(cookie)
         if not connected:
             self.send_response(401) #unathorized
         else:
             if len(tokenizedUrl) >= 2:
                 command = ""
                 if tokenizedUrl[1].lower() == "insert":
                     state = jsonParser.getJsonTypeFromInsert(data)
                     if state == 1:
                         currentData = jsonParser.getJson(data)
                         command = sqlConverter.convertInput(tokenizedUrl, currentData, 1)
                         print command
                     elif state == 2:
                         currentData = jsonParser.getJson(data)
                         command = sqlConverter.convertInput(tokenizedUrl, currentData, 2)
                 elif tokenizedUrl[1].lower() == "create":
                     if len(tokenizedUrl) == 4:
                         command = sqlConverter.convertCreate(tokenizedUrl)
                 elif tokenizedUrl[1].lower() == "createifnotexists":
                     command = sqlConverter.convertCreateIfNotExists(tokenizedUrl)
                 elif tokenizedUrl[1].lower() == "raw":
                     command = data
 
                 if isinstance(command, list):
                     for i in command:
                         if not currentDatabase.runCommand(i):
                             self.send_error(400) #Bad request
                     
                     self.send_response(202) #OK
                 elif command == "":
                     self.send_error(400) #Bad request
                 else:
                     print command
                     if not currentDatabase.runCommand(command):
                         self.send_error(400) #Bad request
                     else:
                         self.send_response(202) #OK
             else:
                 self.send_response(400) #Bad request
     else:
         self.send_response(400) #Bad request
コード例 #4
0
 def do_CONNECT(self):
     url = self.path
     tokenizedUrl = urlParser.parseUrl(url)
     
     database = urlParser.getDatabase(tokenizedUrl)
     
     if currentDatabases.has_key(database): 
         currentDatabase = currentDatabases.get(database)
         currentDatabase.updateAuthDict()
          
         if len(tokenizedUrl) >= 2 and len(tokenizedUrl[1]) == 4:
             username = ""
             password = ""
             if tokenizedUrl[1][0] == "USERNAME":
                 username = tokenizedUrl[1][1]
             elif tokenizedUrl[1][0] == "PASSWORD":
                 password = tokenizedUrl[1][1]
             else:
                 self.send_error(400)    #bad request
                 return
             if tokenizedUrl[1][2] == "USERNAME":
                 username = tokenizedUrl[1][3]
             elif tokenizedUrl[1][2] == "PASSWORD":
                 password = tokenizedUrl[1][3]
             else:
                 self.send_error(400)    #bad request
                 return
             
             result = currentDatabase.authenticate(username, password)
             if result[0] == 0:
                 self.send_response(304) #not modified
                 self.send_header("Set-Cookie", result[1])
             elif result[0] == 1:
                 self.send_response(401) #not authorized
             elif result[0] == 2:
                 setCookie = result[1]
                 self.send_response(202) #ok
                 self.send_header("Set-Cookie", setCookie)
             elif result[0] == 3:
                 self.send_response(401) #not authorized
         else:
             self.send_error(400) #bad request