avaparse.y 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. %{
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <string.h>
  10. #include "libaccess/ava.h"
  11. #include "libaccess/avapfile.h"
  12. #include "netsite.h"
  13. extern int linenum;
  14. extern char yytext[];
  15. static void AddDefType (int defType, char *defId);
  16. static void AddAVA (char* userID);
  17. void yyerror(const char* string);
  18. extern void logerror(const char* string,int num, char *file);
  19. AVAEntry tempEntry;
  20. AVATable entryTable;
  21. %}
  22. %union {
  23. char *string;
  24. int num;
  25. }
  26. %token DEF_C DEF_CO DEF_OU DEF_CN EQ_SIGN DEF_START
  27. %token DEF_L DEF_E DEF_ST
  28. %token <string> USER_ID DEF_ID
  29. %type <num> def.type
  30. %start source
  31. %%
  32. source: ava.database
  33. |
  34. ;
  35. ava.database: ava.database ava
  36. | ava
  37. ;
  38. ava: USER_ID definitions {AddAVA($1);};
  39. definitions: definition.list
  40. |
  41. ;
  42. definition.list: definition.list definition
  43. | definition
  44. ;
  45. definition: def.type EQ_SIGN DEF_ID {AddDefType($1, $3);};
  46. def.type: DEF_C {$$ = DEF_C; }
  47. | DEF_CO {$$ = DEF_CO;}
  48. | DEF_OU {$$ = DEF_OU;}
  49. | DEF_CN {$$ = DEF_CN;}
  50. | DEF_L {$$ = DEF_L; }
  51. | DEF_E {$$ = DEF_E; }
  52. | DEF_ST {$$ = DEF_ST;}
  53. ;
  54. %%
  55. void yyerror(const char* string) {
  56. logerror(string,linenum,currFile);
  57. }
  58. void AddDefType (int defType, char *defId) {
  59. switch (defType) {
  60. case DEF_C:
  61. tempEntry.country = defId;
  62. break;
  63. case DEF_CO:
  64. tempEntry.company = defId;
  65. break;
  66. case DEF_OU:
  67. if (tempEntry.numOrgs % ORGS_ALLOCSIZE == 0) {
  68. if (tempEntry.numOrgs == 0) {
  69. tempEntry.organizations =
  70. PERM_MALLOC (sizeof (char*) * ORGS_ALLOCSIZE);
  71. } else {
  72. char **temp;
  73. temp =
  74. PERM_MALLOC(sizeof(char*) * (tempEntry.numOrgs + ORGS_ALLOCSIZE));
  75. memcpy (temp, tempEntry.organizations,
  76. sizeof(char*)*tempEntry.numOrgs);
  77. PERM_FREE (tempEntry.organizations);
  78. tempEntry.organizations = temp;
  79. }
  80. }
  81. tempEntry.organizations[tempEntry.numOrgs++] = defId;
  82. break;
  83. case DEF_CN:
  84. tempEntry.CNEntry = defId;
  85. break;
  86. case DEF_E:
  87. tempEntry.email = defId;
  88. break;
  89. case DEF_L:
  90. tempEntry.locality = defId;
  91. break;
  92. case DEF_ST:
  93. tempEntry.state = defId;
  94. break;
  95. default:
  96. break;
  97. }
  98. }
  99. void AddAVA (char* userID) {
  100. AVAEntry *newAVA;
  101. newAVA = (AVAEntry*)PERM_MALLOC(sizeof(AVAEntry));
  102. if (!newAVA) {
  103. yyerror ("Out of Memory in AddAVA");
  104. return;
  105. }
  106. *newAVA = tempEntry;
  107. newAVA->userid = userID;
  108. _addAVAtoTable (newAVA, &entryTable);
  109. tempEntry.CNEntry = tempEntry.userid = tempEntry.country = tempEntry.company = 0;
  110. tempEntry.email = tempEntry.locality = tempEntry.state = NULL;
  111. tempEntry.numOrgs = 0;
  112. }