## C examples

## C example: Define a password schema

Each stored password has a set of attributes which are later used to lookup the password. The names and types of the attributes are defined in a schema. The schema is usually defined once globally. Here's how to define a schema:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    /* in a header: */

    const SecretSchema * example_get_schema (void) G_GNUC_CONST;

    #define EXAMPLE_SCHEMA  example_get_schema ()

    /* in a .c file: */

    const SecretSchema *
    example_get_schema (void)
    {
    	static const SecretSchema the_schema = {
    		"org.example.Password", SECRET_SCHEMA_NONE,
    		{
    			{  "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
    			{  "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
    			{  "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
    			{  "NULL", 0 },
    		}
    	};
    	return &the_schema;
    }

See the other examples for how to use the schema.