Changeset c216863


Ignore:
Timestamp:
Oct 30, 2010, 11:35:37 PM (14 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
84e8137
Parents:
efee0f1
git-author:
Jessica B. Hamrick <jhamrick@…> (10/30/10 23:35:37)
git-committer:
Jessica B. Hamrick <jhamrick@…> (10/30/10 23:35:37)
Message:

Add an IPPRequest class/module to deal with storing and parsing IPP
requests.

Location:
server/lib
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • server/lib/ipp.py

    refee0f1 rc216863  
    11#!/usr/bin/env python
    22
    3 # Adapted from the Quickprint IPP server code (http://quickprint.mit.edu)
     3# Adapted from the Quickprint IPP server code (http://quikprint.mit.edu)
    44# Modifications and additions written by Jessica Hamrick (jhamrick@mit.edu)
    55
    66# Notes and Todo:
    77#   - make sure package creates gutenbach folder in /var/log
    8 #   - ok, so ipplib actually seems to be an unsupported library.
    9 #     Maybe want to write this in perl instead since there is
    10 #     Net::IPP::IPPRequest
    118
    129import os, sys
     
    3532    error("Could not create temporary directory '%s'" % TEMPDIR)
    3633
    37 
    38 authfail = False
    39 try:
    40     printer_uri = 'http://%s%s' % (os.environ['SERVER_NAME'], os.environ['REQUEST_URI'])
    41 except:
    42     pass
    43 
    44 try:
    45     argv = cgi.parse(os.environ['QUERY_STRING'])
    46     webauth = argv['BASIC']
    47     if type(webauth) is list:
    48         webauth = webauth[0]
    49     webauth = webauth.split(' ')[1]
    50     if not len(webauth):
    51         authfail = True
    52     else:
    53         (authu, authp) = webauth.decode('base64').split(':')
    54         db=MySQLdb.connect(read_default_file="/mit/gutenbach/.my.cnf")
    55         c = db.cursor()
    56         c.execute("SELECT 1 FROM auth WHERE auser=%s AND apass=%s LIMIT 1", (authu,authp,))
    57         if c.fetchone() is None:
    58             authfail = True
    59 except Exception, e:
    60     authfail = True
    61 
    62 if authfail:
    63     print "Status: 401 Authorization Required"
    64     print "WWW-Authenticate: Basic realm=\"Gutenbach\""
    65     print "Content-type: application/ipp\n"
    66     sys.exit(0)
    67 else:
    68     AUTH = authu.lower()
    69 
     34# print the content type for our request
    7035print "Content-type: application/ipp\n"
    7136
    7237class IPPServer(object):
     38   
     39    # nothing to do in the init
    7340    def __init__(self):
    7441        pass
     42
     43    # this function processes an IPP request and sends a response
    7544    def process(self, request_in, response_out):
    76         data_in = request_in.read()
    77         if not len(data_in):
    78             return
    79         request = IPPRequest(data=data_in)
    80         request.parse()
     45
    8146
    8247        response = IPPRequest(version=request.version,
    83                             operation_id=request.operation_id,
    84                             request_id=request.request_id)
     48                              operation_id=request.operation_id,
     49                              request_id=request.request_id)
    8550        #file('/mit/gutenbach/tmp/requests/'+str(request.operation_id)).write()
    8651        handler = getattr(self, "_operation_%d" % request.operation_id, None)
Note: See TracChangeset for help on using the changeset viewer.