Index: /pkipplib/trunk/bin/cupssubscribe
===================================================================
--- /pkipplib/trunk/bin/cupssubscribe (revision 29)
+++ /pkipplib/trunk/bin/cupssubscribe (revision 30)
@@ -21,4 +21,7 @@
 # $Id$
 
+"""cupssubscribe is a command line tool which can be used to create
+or delete IPP subscriptions."""
+
 import sys
 import locale
@@ -37,5 +40,5 @@
     except :
         gettext.NullTranslations().install()
-    parser = optparse.OptionParser(usage="cupssubscribe [options]")
+    parser = optparse.OptionParser(usage="cupssubscribe [options] [subscriptions ids]")
     parser.add_option("-v", "--version", 
                             action="store_true", 
@@ -50,4 +53,8 @@
                             dest="debug",
                             help=_("activate debug mode."))
+    parser.add_option("-X", "--delete", 
+                            action="store_true", 
+                            dest="delete",
+                            help=_("deletes subscriptions."))
     parser.add_option("-p", "--printer", 
                             dest="printer",
@@ -94,10 +101,10 @@
         print "cupssubscribe v%(__version__)s" % globals()
     else :
-        if not options.events :
+        if not options.events and not options.delete :
             sys.stderr.write(_("You MUST pass a list of events to subscribe to.\n"))
-        elif not options.cups :    
-            sys.stderr.write(_("You MUST pass an URL to the CUPS server.\n"))
-        elif not options.recipient :    
+        elif not options.recipient and not options.delete :    
             sys.stderr.write(_("You MUST pass a recipient for the subscription.\n"))
+        elif options.delete and not arguments :    
+            sys.stderr.write(_("You MUST pass a subscriptions ids at the end of your command line.\n"))
         else :    
             cups = pkipplib.CUPS(options.cups,
@@ -114,19 +121,29 @@
             else :    
                 url = baseurl
-            answer = cups.createSubscription(url,
-                                             [e.strip() for e in options.events.split(",")],
-                                             userdata=options.userdata,
-                                             recipient=options.recipient,
-                                             pullmethod=options.pullmethod,
-                                             charset=options.charset,
-                                             naturallanguage=options.language,
-                                             leaseduration=options.duration,
-                                             timeinterval=options.interval,
-                                             jobid=options.job)
-            try :                                 
-                subscriptionid = answer.subscription["notify-subscription-id"][0][1]
-            except KeyError :
-                sys.stderr.write("%s\n" % answer.operation["status-message"][0][1])
-            else :    
-                print "Subscription %i registered." % subscriptionid
+            if not options.delete :    
+                answer = cups.createSubscription(url,
+                                                 [e.strip() for e in options.events.split(",")],
+                                                 userdata=options.userdata,
+                                                 recipient=options.recipient,
+                                                 pullmethod=options.pullmethod,
+                                                 charset=options.charset,
+                                                 naturallanguage=options.language,
+                                                 leaseduration=options.duration,
+                                                 timeinterval=options.interval,
+                                                 jobid=options.job)
+                try :                                 
+                    subscriptionid = answer.subscription["notify-subscription-id"][0][1]
+                except KeyError :
+                    sys.stderr.write("%s\n" % answer.operation["status-message"][0][1])
+                else :    
+                    print "Subscription %i registered." % subscriptionid
+            else :        
+                for subid in [int(arg) for arg in arguments] :
+                    answer = cups.cancelSubscription(url, subid, options.job)
+                    try :
+                        error = answer.operation["status-message"][0][1]
+                    except KeyError :    
+                        print "Subscription %i cancelled." % subid
+                    else :
+                        sys.stderr.write("%s\n" % error)
 
Index: /pkipplib/trunk/pkipplib/pkipplib.py
===================================================================
--- /pkipplib/trunk/pkipplib/pkipplib.py (revision 28)
+++ /pkipplib/trunk/pkipplib/pkipplib.py (revision 30)
@@ -716,7 +716,13 @@
                                       timeinterval=None,
                                       jobid=None) :
-        """Creates a printer or server subscription."""
-        req = self.newRequest(IPP_CREATE_PRINTER_SUBSCRIPTION)
-        req.operation["printer-uri"] = ("uri", uri)
+        """Creates a job, printer or server subscription."""
+        if jobid is not None :
+            opid = IPP_CREATE_JOB_SUBSCRIPTION
+            uritype = "job-uri"
+        else :
+            opid = IPP_CREATE_PRINTER_SUBSCRIPTION
+            uritype = "printer-uri"
+        req = self.newRequest(opid)
+        req.operation[uritype] = ("uri", uri)
         for event in events :
             req.subscription["notify-events"] = ("keyword", event)
@@ -739,4 +745,14 @@
         return self.doRequest(req)
             
+    def cancelSubscription(self, uri, subscriptionid, jobid=None) :    
+        """Cancels a subscription."""
+        req = self.newRequest(IPP_CANCEL_SUBSCRIPTION)
+        if jobid is not None :
+            uritype = "job-uri"
+        else :
+            uritype = "printer-uri"
+        req.operation[uritype] = ("uri", uri)
+        req.event_notification["notify-subscription-id"] = ("integer", subscriptionid)
+        return self.doRequest(req)
         
 if __name__ == "__main__" :            
