Index: tea4cups/trunk/tea4cups
===================================================================
--- tea4cups/trunk/tea4cups (revision 579)
+++ tea4cups/trunk/tea4cups (revision 581)
@@ -31,4 +31,11 @@
 import tempfile
 import ConfigParser
+from struct import unpack
+
+OPERATION_ATTRIBUTES_TAG = 0x01
+JOB_ATTRIBUTES_TAG = 0x02
+END_OF_ATTRIBUTES_TAG = 0x03
+PRINTER_ATTRIBUTES_TAG = 0x04
+UNSUPPORTED_ATTRIBUTES_TAG = 0x05
 
 class TeeError(Exception):
@@ -45,4 +52,136 @@
     pass 
     
+class IPPError(TeeError) :    
+    """IPP related exceptions."""
+    pass 
+    
+class IPPMessage :
+    """A class for IPP message files."""
+    def __init__(self, data) :
+        """Initializes an IPP Message object."""
+        self.data = data
+        self._attributes = {}
+        self.curname = None
+        self.tags = [ None ] * 256      # by default all tags reserved
+        
+        # Delimiter tags
+        self.tags[0x01] = "operation-attributes-tag"
+        self.tags[0x02] = "job-attributes-tag"
+        self.tags[0x03] = "end-of-attributes-tag"
+        self.tags[0x04] = "printer-attributes-tag"
+        self.tags[0x05] = "unsupported-attributes-tag"
+        
+        # out of band values
+        self.tags[0x10] = "unsupported"
+        self.tags[0x11] = "reserved-for-future-default"
+        self.tags[0x12] = "unknown"
+        self.tags[0x13] = "no-value"
+        
+        # integer values
+        self.tags[0x20] = "generic-integer"
+        self.tags[0x21] = "integer"
+        self.tags[0x22] = "boolean"
+        self.tags[0x23] = "enum"
+        
+        # octetString
+        self.tags[0x30] = "octetString-with-an-unspecified-format"
+        self.tags[0x31] = "dateTime"
+        self.tags[0x32] = "resolution"
+        self.tags[0x33] = "rangeOfInteger"
+        self.tags[0x34] = "reserved-for-collection"
+        self.tags[0x35] = "textWithLanguage"
+        self.tags[0x36] = "nameWithLanguage"
+        
+        # character strings
+        self.tags[0x20] = "generic-character-string"
+        self.tags[0x41] = "textWithoutLanguage"
+        self.tags[0x42] = "nameWithoutLanguage"
+        # self.tags[0x43] = "reserved"
+        self.tags[0x44] = "keyword"
+        self.tags[0x45] = "uri"
+        self.tags[0x46] = "uriScheme"
+        self.tags[0x47] = "charset"
+        self.tags[0x48] = "naturalLanguage"
+        self.tags[0x49] = "mimeMediaType"
+        
+        # now parses the IPP message
+        self.parse()
+        
+    def __getattr__(self, attrname) :    
+        """Allows self.attributes to return the attributes names."""
+        if attrname == "attributes" :
+            keys = self._attributes.keys()
+            keys.sort()
+            return keys
+        raise AttributeError, attrname
+            
+    def __getitem__(self, ippattrname) :    
+        """Fakes a dictionnary d['key'] notation."""
+        value = self._attributes.get(ippattrname)
+        if value is not None :
+            if len(value) == 1 :
+                value = value[0]
+        return value        
+    get = __getitem__    
+        
+    def parseTag(self) :    
+        """Extracts information from an IPP tag."""
+        pos = self.position
+        valuetag = self.tags[ord(self.data[pos])]
+        # print valuetag.get("name")
+        pos += 1
+        posend = pos2 = pos + 2
+        namelength = unpack(">H", self.data[pos:pos2])[0]
+        if not namelength :
+            name = self.curname
+        else :    
+            posend += namelength
+            self.curname = name = self.data[pos2:posend]
+        pos2 = posend + 2
+        valuelength = unpack(">H", self.data[posend:pos2])[0]
+        posend = pos2 + valuelength
+        value = self.data[pos2:posend]
+        oldval = self._attributes.setdefault(name, [])
+        oldval.append(value)
+        return posend - self.position
+        
+    def operation_attributes_tag(self) : 
+        """Indicates that the parser enters into an operation-attributes-tag group."""
+        return self.parseTag()
+        
+    def job_attributes_tag(self) : 
+        """Indicates that the parser enters into an operation-attributes-tag group."""
+        return self.parseTag()
+        
+    def printer_attributes_tag(self) : 
+        """Indicates that the parser enters into an operation-attributes-tag group."""
+        return self.parseTag()
+        
+    def parse(self) :
+        """Parses an IPP Message.
+        
+           NB : Only a subset of RFC2910 is implemented.
+           We are only interested in textual informations for now anyway.
+        """
+        self.version = "%s.%s" % (ord(self.data[0]), ord(self.data[1]))
+        self.operation_id = "0x%04x" % unpack(">H", self.data[2:4])[0]
+        self.request_id = "0x%08x" % unpack(">I", self.data[4:8])[0]
+        self.position = 8
+        try :
+            tag = ord(self.data[self.position])
+            while tag != END_OF_ATTRIBUTES_TAG :
+                self.position += 1
+                name = self.tags[tag]
+                if name is not None :
+                    func = getattr(self, name.replace("-", "_"), None)
+                    if func is not None :
+                        self.position += func()
+                        if ord(self.data[self.position]) > UNSUPPORTED_ATTRIBUTES_TAG :
+                            self.position -= 1
+                            continue
+                tag = ord(self.data[self.position])
+        except IndexError :
+            raise IPPError, "Unexpected end of IPP message."
+            
 class FakeConfig :    
     """Fakes a configuration file parser."""
@@ -232,5 +371,5 @@
         self.PrinterName = os.environ.get("PRINTER", "")
         self.Directory = self.getPrintQueueOption(self.PrinterName, "directory")
-        self.DataFile = os.path.join(self.Directory, "%s-%s-%s" % (self.myname, self.PrinterName, self.JobId))
+        self.DataFile = os.path.join(self.Directory, "%s-%s-%s-%s" % (self.myname, self.PrinterName, self.UserName, self.JobId))
             
     def exportAttributes(self) :    
@@ -289,7 +428,10 @@
         """Launches each tee defined for the current print queue."""
         branches = self.enumTeeBranches(self.PrinterName)
-        for (branch, command) in branches.items() :
-            self.logDebug("Launching %s : %s" % (branch, command))
-            os.system(command)
+        if self.isTrue(self.getPrintQueueOption(self.PrinterName, "serialize", ignore=1)) :
+            for (branch, command) in branches.items() :
+                self.logDebug("Launching %s : %s" % (branch, command))
+                os.system(command)
+        else :        
+            raise TeeError, "Forking tees not yet implemented."
         
 if __name__ == "__main__" :    
Index: tea4cups/trunk/tea4cups.conf
===================================================================
--- tea4cups/trunk/tea4cups.conf (revision 580)
+++ tea4cups/trunk/tea4cups.conf (revision 581)
@@ -91,3 +91,4 @@
 # A reflector which produces 4 copies each time :
 #tee_4copies : lp -dotherprinter -n4 $CUPSDATAFILE 
-#
+# A simple accounting mechanism 
+#tee_accounting : echo $TEAPRINTERNAME $TEAJOBID $TEAUSERNAME `pkpgcounter $TEADATAFILE` >/var/log/printaccounting.log
