aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/libldapschema/loutput.c
blob: b7e656fc29d0895295ccf4dadd2e698baa977f1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687

/*
 *  LDAP Utilities
 *  Copyright (C) 2012, 2019 David M. Syzdek <david@syzdek.net>.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are
 *  met:
 *
 *     1. Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *
 *     2. Redistributions in binary form must reproduce the above copyright
 *        notice, this list of conditions and the following disclaimer in the
 *        documentation and/or other materials provided with the distribution.
 *
 *     3. Neither the name of the copyright holder nor the names of its
 *        contributors may be used to endorse or promote products derived from
 *        this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 *  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/**
*   @file lib/libldapschema/loutput.c  contains output functions
*/
#define _LIB_LIBLDAPSCHEMA_LOUTPUT_C 1
#include "loutput.h"

///////////////
//           //
//  Headers  //
//           //
///////////////
#pragma mark - Headers

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>

#include "lspec.h"


///////////////////
//               //
//  Definitions  //
//               //
///////////////////
#pragma mark - Definitions

#define LDAPSCHEMA_WIDTH_HEADER    19
#define LDAPSCHEMA_WIDTH_INDENT    3
#define LDAPSCHEMA_WIDTH_FIELD     (LDAPSCHEMA_WIDTH_HEADER-LDAPSCHEMA_WIDTH_INDENT)
#define LDAPSCHEMA_WIDTH_VALUE      45


//////////////////
//              //
//  Prototypes  //
//              //
//////////////////
#pragma mark - Prototypes

void
ldapschema_print_data_class(
         LDAPSchema *                  lsd,
         size_t                        classid );

void
ldapschema_print_definition(
         LDAPSchema *                  lsd,
         LDAPSchemaModel *             model );

void
ldapschema_print_extensions(
         LDAPSchema *                  lsd,
         LDAPSchemaModel *             model );

void
ldapschema_print_flags(
         LDAPSchema *                  lsd,
         LDAPSchemaModel *             model );

void
ldapschema_print_issues(
         LDAPSchema *                  lsd,
         LDAPSchemaModel *             model );

void
ldapschema_print_line(
         const char *                  field,
         const char *                  input );

void
ldapschema_print_list(
         const char *                  field,
         char **                       vals );

void
ldapschema_print_list_models(
         LDAPSchema *                  lsd,
         const char *                  name,
         LDAPSchemaModel   **          list,
         size_t                        list_len );

void
ldapschema_print_unsigned(
         const char *                  field,
         uintmax_t                     u );

const char *
ldapschema_print_get_dataclass(
         size_t                        classid );

void
ldapschema_print_obj_attributetype(
         LDAPSchema *                  lsd,
         LDAPSchemaAttributeType *     attr );

void
ldapschema_print_obj_matchingrule(
         LDAPSchema *                  lsd,
         LDAPSchemaMatchingRule *      mtchngrl );

void
ldapschema_print_obj_model(
         LDAPSchema *                  lsd,
         LDAPSchemaModel *             model );
void
ldapschema_print_obj_objectclass(
         LDAPSchema *                  lsd,
         LDAPSchemaObjectclass *       objcls );

void
ldapschema_print_obj_syntax(
         LDAPSchema *                  lsd,
         LDAPSchemaSyntax *            syntax );

void
ldapschema_print_spec(
         LDAPSchema *                  lsd,
         const LDAPSchemaSpec *        spec );

void
ldapschema_print_type(
         LDAPSchema *                  lsd,
         LDAPSchemaModel *             model );


/////////////////
//             //
//  Functions  //
//             //
/////////////////
#pragma mark - Functions

void ldapschema_print( LDAPSchema * lsd, LDAPSchemaModel * mod )
{
   assert(lsd != NULL);
   assert(mod != NULL);
   switch(mod->type)
   {
      case LDAPSCHEMA_ATTRIBUTETYPE:
      if (mod->size != sizeof(LDAPSchemaAttributeType))
         return;
      ldapschema_print_obj_attributetype(lsd, (LDAPSchemaAttributeType *)mod);
      return;

      case LDAPSCHEMA_MATCHINGRULE:
      if (mod->size != sizeof(LDAPSchemaMatchingRule))
         return;
      ldapschema_print_obj_matchingrule(lsd, (LDAPSchemaMatchingRule *)mod);
      return;

      case LDAPSCHEMA_OBJECTCLASS:
      if (mod->size != sizeof(LDAPSchemaObjectclass))
         return;
      ldapschema_print_obj_objectclass(lsd, (LDAPSchemaObjectclass *)mod);
      return;

      case LDAPSCHEMA_SYNTAX:
      if (mod->size != sizeof(LDAPSchemaSyntax))
         return;
      ldapschema_print_obj_syntax(lsd, (LDAPSchemaSyntax *)mod);
      return;

      default:
      break;
   };
   ldapschema_print_obj_model(lsd, mod);
   return;
}


void ldapschema_printall( LDAPSchema * lsd, int type )
{
   size_t x;

   assert(lsd != NULL);

   for(x = 0; x < lsd->oids_len; x++)
   {
      if ((type))
         if (lsd->oids[x].model->type != (size_t)type)
            continue;
      ldapschema_print(lsd, lsd->oids[x].model);
      printf("\n");
   };

   return;
}


void ldapschema_print_data_class(LDAPSchema * lsd, size_t classid )
{
   const char * data_class;

   assert(lsd != NULL);

   switch(classid)
   {
      case LDAPSCHEMA_CLASS_ASCII:           data_class = "ASCII";         break;
      case LDAPSCHEMA_CLASS_UTF8:            data_class = "UTF8";          break;
      case LDAPSCHEMA_CLASS_INTEGER:         data_class = "integer";       break;
      case LDAPSCHEMA_CLASS_UNSIGNED:        data_class = "unsigned";      break;
      case LDAPSCHEMA_CLASS_BOOLEAN:         data_class = "boolean";       break;
      case LDAPSCHEMA_CLASS_DATA:            data_class = "binary data";   break;
      case LDAPSCHEMA_CLASS_IMAGE:           data_class = "image";         break;
      case LDAPSCHEMA_CLASS_AUDIO:           data_class = "audio";         break;
      case LDAPSCHEMA_CLASS_UTF8_MULTILINE:  data_class = "audio";         break;
      default:
      return;
   };

   printf("%*s%-*s %s\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, "data class:", data_class);

   return;
}


void ldapschema_print_definition(LDAPSchema * lsd, LDAPSchemaModel * model)
{
   char           buff[4096];
   const char   * def;
   const char   * name;

   assert(lsd   != NULL);
   assert(model != NULL);

   name = "definition:";
   if ((def = model->definition) == NULL)
   {
      name = "spec definition:";
      ldapschema_print_line("definition:", "<not defined by server>");
      if ((def = model->spec->def) == NULL)
      return;
   };

   ldapschema_fmt_definition(buff, sizeof(buff), def, LDAPSCHEMA_WIDTH_VALUE);
   ldapschema_print_line(name, buff);

   return;
}


void ldapschema_print_extensions(LDAPSchema * lsd, LDAPSchemaModel * model)
{
   size_t                  x;
   size_t                  y;
   int                     len;
   int                     max;
   LDAPSchemaExtension   * ext;

   assert(lsd   != NULL);
   assert(model != NULL);

   if (model->extensions_len < 1)
      return;

   printf("%*s%-*s ", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, "extensions:");
   max = 0;
   for(x = 0; x < model->extensions_len; x++)
      if ((len = (int)strlen(model->extensions[x]->extension)) > max)
         max = len;
   for(x = 0; x < model->extensions_len; x++)
   {
      if (x > 0)
         printf("%*s ", LDAPSCHEMA_WIDTH_HEADER, "");
      ext = model->extensions[x];
      printf("%-*s (", max, ext->extension);
      for(y = 0; y < ext->values_len; y++)
         printf(" '%s'", ext->values[y]);
      printf(" )\n");
   };

   return;
}


void ldapschema_print_flags(LDAPSchema * lsd, LDAPSchemaModel * model)
{
   assert(lsd   != NULL);
   assert(model != NULL);

   if ((model->flags & LDAPSCHEMA_O_OBSOLETE))
      printf("%*s%-*s %s\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, "obsolete:", "yes");

   if ((model->flags & LDAPSCHEMA_O_SINGLEVALUE))
      printf("%*s%-*s %s\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, "single value:", "yes");

   if ((model->flags & LDAPSCHEMA_O_READABLE))
      printf("%*s%-*s %s\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, "readable:", "yes");

   if ((model->flags & LDAPSCHEMA_O_COLLECTIVE))
      printf("%*s%-*s %s\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, "collective:", "yes");

   if ((model->flags & LDAPSCHEMA_O_NO_USER_MOD))
      printf("%*s%-*s %s\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, "no user mod:", "yes");

   return;
}


void ldapschema_print_issues(LDAPSchema * lsd, LDAPSchemaModel * model)
{
   size_t idx;
   assert(lsd   != NULL);
   assert(model != NULL);
   if (!(model->errors))
      return;
   for(idx = 0; ((model->errors[idx])); idx++)
      ldapschema_print_line( ((!(idx))?"issues:":NULL), model->errors[idx]);
   return;
}


void ldapschema_print_line(const char * field, const char * str)
{
   const char         * bol;
   const char         * eol;

   if (!(field))
      field = "";

   if (!(str))
      return;

   bol = str;
   while((eol = index(bol, '\n')) != NULL)
   {
      if (bol == str)
         printf("%*s%-*s %.*s\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, field, (int)(eol-bol), str);
      else
         printf("%*s %.*s\n", LDAPSCHEMA_WIDTH_HEADER, "", (int)(eol-bol), bol);
      bol = &eol[1];
   };
   if (bol == str)
      printf("%*s%-*s %.*s\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, field, (int)(eol-bol), str);
   else if ((strlen(bol)))
      printf("%*s %.*s\n", LDAPSCHEMA_WIDTH_HEADER, "", (int)(eol-bol), bol);

   return;
}


void ldapschema_print_list(const char * field, char ** vals)
{
   size_t idx;

   if (!(vals))
      return;

   for(idx = 0; ((vals[idx])); idx++)
      ldapschema_print_line( ((!(idx))?field:""), vals[idx]);

   return;
}


void ldapschema_print_list_models(LDAPSchema * lsd,
   const char * name, LDAPSchemaModel ** list, size_t list_len)
{
   size_t            pos;
   const char *      key;
   size_t            buff_len;
   char              buff[256];
   size_t            lineno;

   assert(lsd != NULL);
   assert(name != NULL);
   if ( (!(list)) || (!(list_len)) )
      return;

   lineno   = 0;
   buff_len = 0;
   buff[0]  = '\0';

   for(pos = 0; (pos < list_len); pos++)
   {
      key = NULL;
      switch(list[pos]->type)
      {
         case LDAPSCHEMA_ATTRIBUTETYPE:
         if ((((LDAPSchemaAttributeType *)list[pos])->names))
            key = ((LDAPSchemaAttributeType *)list[pos])->names[0];
         break;

         case LDAPSCHEMA_MATCHINGRULE:
         if ((((LDAPSchemaMatchingRule *)list[pos])->names))
            key = ((LDAPSchemaMatchingRule *)list[pos])->names[0];
         break;

         case LDAPSCHEMA_OBJECTCLASS:
         if ((((LDAPSchemaObjectclass *)list[pos])->names))
            key = ((LDAPSchemaObjectclass *)list[pos])->names[0];
         break;

         case LDAPSCHEMA_SYNTAX:
         if ((((LDAPSchemaSyntax *)list[pos])->model.desc))
            key = ((LDAPSchemaSyntax *)list[pos])->model.desc;
         break;

         default:
         key = list[pos]->desc;
         break;
      };
      if (!(key))
         key = list[pos]->oid;
      if (!(key))
         continue;

      if ((pos + 1) < list_len)
         buff_len += (size_t)snprintf(&buff[buff_len], sizeof(buff)-buff_len, "%s, ", key );
      else
         buff_len += (size_t)snprintf(&buff[buff_len], sizeof(buff)-buff_len, "%s", key );
      if (buff_len >= LDAPSCHEMA_WIDTH_VALUE)
      {
         ldapschema_print_line( ((!(lineno))?name:NULL), buff);
         buff_len = 0;
         buff[0]  = '\0';
         lineno++;
      };
   };
   if ((buff_len))
      ldapschema_print_line( ((!(lineno))?name:NULL), buff);

   return;
}


void ldapschema_print_obj_attributetype( LDAPSchema * lsd, LDAPSchemaAttributeType * attr )
{
   const char *               str;
   LDAPSchemaAttributeType *  sup;
   size_t                     flags;
   char                       buff[256];
   LDAPSchemaSyntax *         syntax;
   LDAPSchemaMatchingRule *   mtchngrl;

   assert(lsd  != NULL);
   assert(attr != NULL);

   ldapschema_print_type(lsd, &attr->model);
   ldapschema_print_list("name(s):",     attr->names);
   ldapschema_print_line("description:", attr->model.desc);
   ldapschema_print_flags(lsd, &attr->model);

   switch(attr->usage)
   {
      case 0: // assume LDAPSCHEMA_USER_APP if value is not set
      case LDAPSCHEMA_USER_APP:        str = "userApplications";     break;
      case LDAPSCHEMA_DIRECTORY_OP:    str = "directoryOperation";   break;
      case LDAPSCHEMA_DISTRIBUTED_OP:  str = "distributedOperation"; break;
      case LDAPSCHEMA_DSA_OP:          str = "dSAOperation";         break;
      default:                         str = "unknown:";             break;
   };
   ldapschema_print_line("usage:", str);

   if ((sup = attr->sup) != NULL)
   {
      ldapschema_print_line("superior(s):", (((sup->names))?sup->names[0]:sup->model.oid)  );
      while ((sup = sup->sup) != NULL)
         ldapschema_print_line(NULL, (((sup->names))?sup->names[0]:sup->model.oid)  );
   };

   ldapschema_print_spec(lsd, attr->model.spec);

   if ((mtchngrl = attr->equality) != NULL)
      ldapschema_print_line("equality:", ((mtchngrl->names)) ? mtchngrl->names[0] : mtchngrl->model.oid);
   if ((mtchngrl = attr->ordering) != NULL)
      ldapschema_print_line("ordering:", ((mtchngrl->names)) ? mtchngrl->names[0] : mtchngrl->model.oid);
   if ((mtchngrl = attr->substr) != NULL)
      ldapschema_print_line("substr:", ((mtchngrl->names)) ? mtchngrl->names[0] : mtchngrl->model.oid);

   // print syntax information
   ldapschema_print_unsigned("min upper bound:", attr->min_upper);
   if ((syntax = attr->syntax)  != NULL)
   {
      // syntax OID/desc
      if ((syntax->model.desc))
         snprintf(buff, sizeof(buff), "%s ( %s )", syntax->model.oid, syntax->model.desc);
      else
         snprintf(buff, sizeof(buff), "%s", syntax->model.oid);
      ldapschema_print_line("syntax:", buff);

      ldapschema_print_data_class(lsd, syntax->data_class);

      flags = (size_t)syntax->model.flags;
      ldapschema_print_line("common abnf:", ((flags & LDAPSCHEMA_O_COMMON_ABNF) != 0) ? "yes" : "no");
      ldapschema_print_line("schema abnf:", ((flags & LDAPSCHEMA_O_SCHEMA_ABNF) != 0) ? "yes" : "no");
      ldapschema_print_line("abnf:",        ((!(syntax->model.spec)) ? NULL : syntax->model.spec->abnf));
   };

   ldapschema_print_extensions(lsd, &attr->model);
   ldapschema_print_list_models(lsd, "required by:", (LDAPSchemaModel **)attr->required_by, attr->required_by_len);
   ldapschema_print_list_models(lsd, "allowed by:",  (LDAPSchemaModel **)attr->allowed_by, attr->allowed_by_len);
   ldapschema_print_definition(lsd, &attr->model);
   ldapschema_print_issues(lsd, &attr->model);

   return;
}


void ldapschema_print_obj_matchingrule(LDAPSchema * lsd, LDAPSchemaMatchingRule * mtchngrl)
{
   char buff[256];

   assert(lsd        != NULL);
   assert(mtchngrl   != NULL);

   ldapschema_print_type(lsd, &mtchngrl->model);
   ldapschema_print_list("name(s):",     mtchngrl->names);
   ldapschema_print_line("description:", mtchngrl->model.desc);
   ldapschema_print_flags(lsd, &mtchngrl->model);

   if ((mtchngrl->syntax))
   {
      if ((mtchngrl->syntax->model.desc))
         snprintf(buff, sizeof(buff), "%s ( %s )", mtchngrl->syntax->model.oid, mtchngrl->syntax->model.desc);
   else
         snprintf(buff, sizeof(buff), "%s", mtchngrl->syntax->model.oid);
      ldapschema_print_line("syntax:", buff);
   };

   ldapschema_print_list_models(lsd, "used by:",  (LDAPSchemaModel **)mtchngrl->used_by, mtchngrl->used_by_len);
   ldapschema_print_extensions(lsd, &mtchngrl->model);
   ldapschema_print_definition(lsd, &mtchngrl->model);
   ldapschema_print_issues(lsd, &mtchngrl->model);

   return;
}


void ldapschema_print_obj_model(LDAPSchema * lsd, LDAPSchemaModel * model)
{
   assert(lsd   != NULL);
   assert(model != NULL);

   ldapschema_print_type(lsd, model);
   ldapschema_print_line("description:", model->desc);
   ldapschema_print_flags(lsd, model);
   ldapschema_print_extensions(lsd, model);
   ldapschema_print_definition(lsd, model);
   ldapschema_print_spec(lsd, model->spec);

   return;
}


void ldapschema_print_obj_objectclass(LDAPSchema * lsd, LDAPSchemaObjectclass * objcls)
{
   const char               * str;
   LDAPSchemaObjectclass    * sup;

   assert(lsd    != NULL);
   assert(objcls != NULL);

   ldapschema_print_type(lsd, &objcls->model);
   ldapschema_print_list("name(s):",     objcls->names);
   ldapschema_print_line("description:", objcls->model.desc);
   ldapschema_print_flags(lsd, &objcls->model);

   switch(objcls->kind)
   {
      case LDAPSCHEMA_STRUCTURAL:      str = "structural";  break;
      case LDAPSCHEMA_AUXILIARY:       str = "auxiliary";   break;
      case LDAPSCHEMA_ABSTRACT:        str = "abstract";    break;
      default:                         str = "unknown:";    break;
   };
   ldapschema_print_line("usage:", str);

   if ((sup = objcls->sup) != NULL)
   {
      ldapschema_print_line("superior(s):", (((sup->names))?sup->names[0]:sup->model.oid)  );
      while ((sup = sup->sup) != NULL)
         ldapschema_print_line(NULL, (((sup->names))?sup->names[0]:sup->model.oid)  );
   };

   ldapschema_print_list_models(lsd, "may:",             (LDAPSchemaModel **)objcls->may,          objcls->may_len);
   ldapschema_print_list_models(lsd, "must:",            (LDAPSchemaModel **)objcls->must,         objcls->must_len);
   ldapschema_print_list_models(lsd, "inherited may:",   (LDAPSchemaModel **)objcls->inherit_may,  objcls->inherit_may_len);
   ldapschema_print_list_models(lsd, "inherited must:",  (LDAPSchemaModel **)objcls->inherit_must, objcls->inherit_must_len);
   ldapschema_print_extensions(lsd, &objcls->model);
   ldapschema_print_definition(lsd, &objcls->model);
   ldapschema_print_issues(lsd, &objcls->model);

   return;
}


void ldapschema_print_obj_syntax(LDAPSchema * lsd, LDAPSchemaSyntax * syntax)
{
   assert(lsd    != NULL);
   assert(syntax != NULL);

   ldapschema_print_type(lsd, &syntax->model);
   ldapschema_print_line("description:", syntax->model.desc);
   ldapschema_print_data_class(lsd, syntax->data_class);
   ldapschema_print_flags(lsd, &syntax->model);
   ldapschema_print_extensions(lsd, &syntax->model);
   ldapschema_print_list_models(lsd, "matchingRules:",   (LDAPSchemaModel **)syntax->mtchngrls, syntax->mtchngrls_len);
   ldapschema_print_list_models(lsd, "used by:",  (LDAPSchemaModel **)syntax->attrs,     syntax->attrs_len);
   ldapschema_print_spec(lsd, syntax->model.spec);
   ldapschema_print_definition(lsd, &syntax->model);
   ldapschema_print_issues(lsd, &syntax->model);

   return;
}


void ldapschema_print_spec( LDAPSchema * lsd, const LDAPSchemaSpec * spec)
{
   assert(lsd != NULL);
   if (!(spec))
      return;
   ldapschema_print_line("spec name:",     spec->spec);
   ldapschema_print_line("spec chapter:",  spec->spec_section);
   ldapschema_print_line("spec vendor:",   spec->spec_vendor);
   ldapschema_print_line("spec source:",   spec->spec_source);
   ldapschema_print_line("spec text:",     spec->spec_text);
   ldapschema_print_line("spec notes:",    spec->notes);
   ldapschema_print_line("common abnf:",   ((spec->flags & LDAPSCHEMA_O_COMMON_ABNF) != 0) ? "yes" : "no");
   ldapschema_print_line("schema abnf:",   ((spec->flags & LDAPSCHEMA_O_SCHEMA_ABNF) != 0) ? "yes" : "no");
   ldapschema_print_line("abnf:",          spec->abnf);
   return;
}


void ldapschema_print_type(LDAPSchema * lsd, LDAPSchemaModel * model)
{
   const char * str;
   assert(lsd   != NULL);
   assert(model != NULL);
   switch(model->type)
   {
      case LDAPSCHEMA_ATTRIBUTETYPE: str = "attributeType:"; break;
      case LDAPSCHEMA_MATCHINGRULE:  str = "matchingRule:"; break;
      case LDAPSCHEMA_OBJECTCLASS:   str = "objectClass:"; break;
      case LDAPSCHEMA_SYNTAX:        str = "ldapSyntax:"; break;
      default:                       str = "unknown:"; break;
   };
   printf("%-*s %s\n", LDAPSCHEMA_WIDTH_HEADER, str, model->oid);
   return;
}


void ldapschema_print_unsigned(const char * field, uintmax_t u)
{
   if (!(u))
      return;
   if ((field))   printf("%*s%-*s %ju\n", LDAPSCHEMA_WIDTH_INDENT, "", LDAPSCHEMA_WIDTH_FIELD, field, u);
   else           printf("%*s %ju\n", LDAPSCHEMA_WIDTH_HEADER, "", u);
   return;
}

/* end of source file */