[cc-devel] Liblicense License Chooser API

Jason Kivlighn jkivlighn at gmail.com
Sat Jul 28 01:26:00 EDT 2007

Hey all,

I'm currently adding license selection based on
Permits/Requires/Prohibits flags to liblicense.  At the moment, I'm
ironing out the API, and would appreciate any feedback.  Here's some
working sample code, with inline comments explaining the details:

    char *attributes[] = {
            "http://creativecommons.org/ns#Distribution",            //0
            "http://creativecommons.org/ns#CommercialUse",        //1
            "http://creativecommons.org/ns#DerivativeWorks",    //2
            "http://creativecommons.org/ns#ShareAlike",                //3
            "http://creativecommons.org/ns#Attribution",            //4
    //build a structure for fast searching of licenses on the given
    ll_license_chooser_t *license_chooser =
    int permits_flags, requires_flags, prohibits_flags;
    //permits Distribution(0) and DerivativeWorks(2)
    permits_flags = (1 << 0) | (1 << 2);
    //requires ShareAlike(3)
    requires_flags = (1 << 3);
    //doesn't prohibit any particular attribute, but could still
prohibit an attribute that isn't in the 'attributes' list
    prohibits_flags = 0;
    //Attribution(4) and CommercialUse(1) must be unspecified in the
license RDF.
    //If you don't want this to be the case, leave these two attributes
out of the list that is
    //passed to ll_new_license_chooser()
    //returns GPL and LGPL

    //another example:

    //permits Distribution(0)
    permits_flags = (1 << 0);
    //requires ShareAlike(3)
    requires_flags = (1 << 4);
    //prohibits CommercialUse(1)
    prohibits_flags = (1 << 1);

    //returns all by-nc-nd licenses

Doing some quick benchmarking, ll_new_license_chooser() takes .730s
(which includes a call to ll_get_all_licenses()).  After that, calls to
ll_get_licenses_from_flags() are extremely fast -- it's a constant time
algorithm (100,000,000 calls ran in less than 7 seconds); this makes it
highly effective for use in a graphical license chooser where the user
clicks checkboxs to specify the flags, and the selected license is then

The goal is to provide easily integrated license selection in
applications.  For example, a user should be able to say, "I want a
license that allows sharing, derivative works, and commercial use."  A
simple call to ll_get_licenses_from_flags() with the appropriate flags
returns what the user wants.

As-is, this code should include the functionality necessary for the
nautilus license extension (coming out with Liblicense 0.3) and the KDE4
equivalent that I'm working on (These function like the mock-ups at
http://wiki.creativecommons.org/Desktop_Integration).  Are there use
cases I'm missing?


More information about the cc-devel mailing list