Changeset 1176f8b


Ignore:
Timestamp:
Mar 11, 2011, 1:51:42 PM (13 years ago)
Author:
Quentin Smith <quentin@…>
Branches:
no-cups
Children:
776a659
Parents:
556a285
git-author:
Quentin Smith <quentin@…> (03/11/11 13:51:42)
git-committer:
Quentin Smith <quentin@…> (03/11/11 13:51:42)
Message:

Enough of a skeleton is implemented to properly handle CUPS_GET_PRINTERS, CUPS_GET_CLASSES, and CUPS_GET_DEFAULT

Location:
server/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/lib/ipp/constants.py

    r91abb7f r1176f8b  
    104104    #CUPS_ADD_PRINTER      = 0x4003
    105105    #CUPS_DELETE_PRINTER   = 0x4004
    106     #CUPS_GET_CLASSES      = 0x4005
     106    CUPS_GET_CLASSES       = 0x4005
    107107    #CUPS_ADD_CLASS        = 0x4006
    108108    #CUPS_DELETE_CLASS     = 0x4007
  • server/lib/server.py

    rdc37ed0 r1176f8b  
    22
    33import logging, BaseHTTPServer
     4import time
    45import ipp
    56import ipp.constants as const
     7from ipp.constants import Operations
    68
    79logging.basicConfig(level=logging.DEBUG)
    810
     11def handler_for(operation):
     12    def f(func):
     13        func.ipp_operation = operation
     14        return func
     15    return f
     16
     17class IPPRequestHandler(object):
     18    def _ipp_dispatch(self, request):
     19        for d in dir(self):
     20            if getattr(getattr(self, d), "ipp_operation", None) == request.operation_id:
     21                return getattr(self, d)
     22        return self.unknown_operation
     23
     24    def unknown_operation(self, request, response):
     25        print "Received UNKNOWN OPERATION %x" % request.operation_id
     26        response.operation_id = const.StatusCodes.OPERATION_NOT_SUPPORTED
     27
     28class PrinterRequestHandler(IPPRequestHandler):
     29    def __init__(self, name):
     30        self.name = name
     31
     32    @handler_for(Operations.GET_PRINTER_ATTRIBUTES)
     33    def get_printer_attributes(self, request, response):
     34        printer_attributes = ipp.AttributeGroup(const.AttributeTags.PRINTER)
     35        printer_attributes[:] = \
     36            ipp.Attribute("printer-uri-supported",
     37                          [ipp.Value(ipp.Tags.URI,
     38                                     "ipp://localhost:8000/printers/"+self.name)]
     39                          )
     40        printer_attributes[:] = \
     41            ipp.Attribute("uri-authentication-supported",
     42                          [ipp.Value(ipp.Tags.KEYWORD,
     43                                     "none")]
     44                          )
     45        printer_attributes[:] = \
     46            ipp.Attribute("uri-security-supported",
     47                          [ipp.Value(ipp.Tags.KEYWORD,
     48                                     "none")]
     49                          )
     50        printer_attributes[:] = \
     51            ipp.Attribute("printer-name",
     52                          [ipp.Value(ipp.Tags.NAME_WITHOUT_LANGUAGE,
     53                                     self.name)]
     54                          )
     55        printer_attributes[:] = \
     56            ipp.Attribute("printer-state",
     57                          [ipp.Value(ipp.Tags.ENUM,
     58                                     const.PrinterStates.IDLE)]
     59                          )
     60        printer_attributes[:] = \
     61            ipp.Attribute("printer-state-reasons",
     62                          [ipp.Value(ipp.Tags.KEYWORD,
     63                                     "none")]
     64                          )
     65        printer_attributes[:] = \
     66            ipp.Attribute("ipp-versions-supported",
     67                          [ipp.Value(ipp.Tags.KEYWORD,
     68                                     "1.0"),
     69                           ipp.Value(ipp.Tags.KEYWORD,
     70                                     "1.1")]
     71                          )
     72        printer_attributes[:] = \
     73            ipp.Attribute("operations-supported",
     74                          [ipp.Value(ipp.Tags.ENUM,
     75                                     Operations.GET_JOBS)]
     76                          ) #XXX: We should query ourself for the supported operations
     77        printer_attributes[:] = \
     78            ipp.Attribute("charset-configured",
     79                          [ipp.Value(ipp.Tags.CHARSET,
     80                                     "utf-8")]
     81                          )
     82        printer_attributes[:] = \
     83            ipp.Attribute("charset-supported",
     84                          [ipp.Value(ipp.Tags.CHARSET,
     85                                     "utf-8")]
     86                          )
     87        printer_attributes[:] = \
     88            ipp.Attribute("natural-language-configured",
     89                          [ipp.Value(ipp.Tags.NATURAL_LANGUAGE,
     90                                     "en-us")]
     91                          )
     92        printer_attributes[:] = \
     93            ipp.Attribute("generated-natural-language-supported",
     94                          [ipp.Value(ipp.Tags.NATURAL_LANGUAGE,
     95                                     "en-us")]
     96                          )
     97        printer_attributes[:] = \
     98            ipp.Attribute("document-format-default",
     99                          [ipp.Value(ipp.Tags.MIME_MEDIA_TYPE,
     100                                     "application/octet-stream")]
     101                          )
     102        printer_attributes[:] = \
     103            ipp.Attribute("document-format-supported",
     104                          [ipp.Value(ipp.Tags.MIME_MEDIA_TYPE,
     105                                     "application/octet-stream"),
     106                           ipp.Value(ipp.Tags.MIME_MEDIA_TYPE,
     107                                     "audio/mp3")]
     108                          )
     109        printer_attributes[:] = \
     110            ipp.Attribute("printer-is-accepting-jobs",
     111                          [ipp.Value(ipp.Tags.BOOLEAN,
     112                                     True)]
     113                          )
     114        printer_attributes[:] = \
     115            ipp.Attribute("queued-job-count",
     116                          [ipp.Value(ipp.Tags.INTEGER,
     117                                     1)]
     118                          )
     119        printer_attributes[:] = \
     120            ipp.Attribute("pdl-override-supported",
     121                          [ipp.Value(ipp.Tags.KEYWORD,
     122                                     "not-attempted")]
     123                          )
     124        printer_attributes[:] = \
     125            ipp.Attribute("printer-up-time",
     126                          [ipp.Value(ipp.Tags.INTEGER,
     127                                     int(time.time()))]
     128                          )
     129        printer_attributes[:] = \
     130            ipp.Attribute("compression-supported",
     131                          [ipp.Value(ipp.Tags.KEYWORD,
     132                                     "none")]
     133                          )
     134
     135        response.attribute_groups.append(printer_attributes)
     136        response.operation_id = const.StatusCodes.OK
     137        print "get_printer_attributes called"
     138
     139class RootRequestHandler(IPPRequestHandler):
     140    printers = [PrinterRequestHandler(name="sipbmp3")]
     141
     142    @handler_for(Operations.CUPS_GET_DEFAULT)
     143    def cups_get_default(self, request, response):
     144        print "get_default called"
     145        return self.printers[0].get_printer_attributes(request, response)
     146
     147    @handler_for(Operations.CUPS_GET_PRINTERS)
     148    def cups_get_printers(self, request, response):
     149        print "get_printers called"
     150        response.operation_id = const.StatusCodes.OK
     151        for p in self.printers:
     152            # Each printer will append a new printer attribute group.
     153            p.get_printer_attributes(request, response)
     154
     155    @handler_for(Operations.CUPS_GET_CLASSES)
     156    def cups_get_classes(self, request, response):
     157        print "get_classes called"
     158        response.operation_id = const.StatusCodes.OK
     159        # We have no printer classes, so nothing to return.
     160
    9161class GutenbachIPPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
     162    def setup(self):
     163        self.root = RootRequestHandler()
     164        BaseHTTPServer.BaseHTTPRequestHandler.setup(self)
     165
    10166    def handle_one_request(self):
    11167        self.raw_requestline = self.rfile.readline()
     
    25181        response_kwargs = {}
    26182        response_kwargs['version'] = request.version
     183        response_kwargs['operation_id'] = const.StatusCodes.INTERNAL_ERROR
    27184        response_kwargs['request_id'] = request.request_id
    28         response_kwargs = self.get_jobs(request, response_kwargs)
     185        response_kwargs['attribute_groups'] = [
     186            ipp.AttributeGroup(const.AttributeTags.OPERATION,
     187                               [ipp.Attribute('attributes-charset',
     188                                              [ipp.Value(ipp.Tags.CHARSET,
     189                                                         'utf-8'
     190                                                         )]),
     191                                ipp.Attribute('attributes-natural-language',
     192                                              [ipp.Value(ipp.Tags.NATURAL_LANGUAGE,
     193                                                         'en-us'
     194                                                         )])
     195                                ])]
     196
    29197        response = ipp.Request(**response_kwargs)
     198        handler = self.root._ipp_dispatch(request)
     199        handler(request, response)
    30200        print "Sending response:", repr(response)
    31201
     
    61231                          ipp.Attribute('job-printer-uri',
    62232                                       [ipp.Value(ipp.Tags.URI,
    63                                                  'http://localhost:8000/printers/foo',
     233                                                 'ipp://localhost:8000/printers/foo',
    64234                                                 )])]
    65235
     
    95265        pass
    96266
    97     def get_printer_attributes(self, request):
    98         pass
    99 
    100267    #def get_jobs(self, request):
    101268    #    pass
     
    105272
    106273    def create_job(self, request):
    107         pass
    108 
    109     def cups_get_default(self, request):
    110         pass
    111 
    112     def cups_get_printers(self, request):
    113274        pass
    114275
Note: See TracChangeset for help on using the changeset viewer.