1 /* $XConsortium: parser.y /main/6 1996/11/11 11:50:41 drk $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Novell, Inc.
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
11 #include <EUSCompat.h>
15 #if (defined(sun) && defined(_XOPEN_SOURCE)) || defined(__linux__)
22 #include "cmscalendar.h"
33 extern _DtCmsCalendar *currentCalendar;
35 extern void yyerror(char*);
36 extern void report_err(char*);
37 extern char *str_to_cr(char*);
38 extern time_t convert_2_tick(char *);
46 static int currentVersion;
47 static _attr_array currentAttrs;
50 /*****************************************************************************
51 * forward declaration of static functions used within the file
52 *****************************************************************************/
53 static void add_hashed_attr_to_array(_attr_array *attrs, int num, char *value);
54 static void add_to_attr_array(_attr_array *attrs, char *name,
55 char *tag, char *value);
56 static void grow_attr_array(_attr_array *attrs);
57 static CSA_enum get_tag_from_string(char *tagstr);
58 static CSA_return_code get_attr_value(int type, char *valstr,
59 cms_attribute_value **attrval);
60 static CSA_return_code get_access_list_value(char *valstr,
61 cms_attribute_value **attrval);
62 static CSA_return_code get_user_access_entry(char *string,
63 cms_access_entry **a);
64 static CSA_return_code get_date_time_list_value(char *valstr,
65 cms_attribute_value **attrval);
66 static int extend_entry_table(int hashednum, char *name, char *typestr);
77 Attribute_4 *attributelist_4;
78 Except_4 *exceptionlist;
79 Access_Entry_4 *accesslist;
82 Appt_Status_4 apptstatVal;
83 Privacy_Level_4 privacyVal;
87 %token VERSION COLON NUMBER QUOTEDSTRING DETAILS DURATION PERIODVAL NTIMES COMMA
88 %token OPENPAREN CLOSEPAREN WHAT REMOVE ADD ADDENTRY PERIOD EXCEPTION MAILTO NTH ENDDATE
89 %token AUTHOR ATTRIBUTES_4 ACCESS DENY PRIVACY PRIVACYENUM
90 %token KEY READ WRITE DELETE EXEC CONNECT BROWSE INSERT UPDATE
92 %token APPTSTATUS APPTSTATUSVAL
93 %token PRIVACYLEVEL PRIVACYVAL
94 %token ATTRIBUTES_5 CALATTRS
95 %token HASHEDATTRS TABLE
97 %type <s> quotedString what details mailto author
98 %type <number> number tick key ntimes duration accesstype nth enddate
99 %type <entry> appointmentBody
100 %type <attributelist_4> attributes_4 attributelist_4 attributeitem_4
101 %type <periodVal> period
102 %type <exceptionlist> exceptions exceptionlist exceptitem
103 %type <accesslist> accesses accesslist accessitem
104 %type <taglist> tags taglist tagitem
105 %type <apptstatVal> apptstat
106 %type <privacyVal> privacy
108 %% /* Begining of rules section */
110 calendar : versionStamp eventlist
114 versionStamp : VERSION COLON number
116 if ($3 > _DtCMS_VERSION4) {
117 report_err("Unable to read callog file, unsupported version\n");
121 if (_DtCmsSetFileVersion(
122 currentCalendar, $3))
128 yyerror("Error reading callog file");
135 $$ = externNumberVal;
143 event : name_type_table
150 add : OPENPAREN ADD appointmentBody CLOSEPAREN
152 if (currentVersion == _DtCMS_VERSION1) {
153 if (_DtCmsInsertAppt(currentCalendar,
154 (Appt_4 *)$3) != CSA_SUCCESS) {
155 _DtCm_free_appt4((Appt_4 *)$3);
158 "Failed to insert appt at line %d\n",
163 if (_DtCmsInsertEntry4Parser(
164 currentCalendar, (cms_entry *)$3)
167 fprintf(stderr, "Failed to insert entry at line %d\n",
171 _DtCm_free_cms_attributes(
172 ((cms_entry *)$3)->num_attrs,
173 ((cms_entry *)$3)->attrs);
179 remove : OPENPAREN REMOVE tick key CLOSEPAREN
185 if (currentVersion == _DtCMS_VERSION1) {
188 _DtCmsDeleteAppt(currentCalendar,
189 NULL, 0, &key, &appt4);
191 _DtCm_free_appt4(appt4);
195 _DtCmsDeleteEntry(currentCalendar, NULL,
201 access : OPENPAREN ACCESS accesstype accesses CLOSEPAREN
203 _DtCmsSetAccess4Parser(currentCalendar, $4, $3);
207 calendar_attrs: OPENPAREN CALATTRS attributelist_5 CLOSEPAREN
209 _DtCmsSetCalendarAttrs4Parser(currentCalendar,
210 currentAttrs.current,
213 _DtCm_free_cms_attributes(currentAttrs.current,
215 currentAttrs.total = 0;
216 currentAttrs.current = 0;
217 currentAttrs.attrs = NULL;
222 * The attribute name and type hash table, each item contains
223 * the hash number for the corresponding attribute, the attribute name,
224 * and the value type of the attribute.
226 name_type_table : OPENPAREN TABLE name_type_list CLOSEPAREN
228 currentCalendar->hashed = B_TRUE;
232 name_type_list : name_type_item
233 | name_type_item name_type_list
236 name_type_item : OPENPAREN number quotedString quotedString CLOSEPAREN
238 if (extend_entry_table($2, $3, $4)) {
239 fprintf(stderr, "Failed to parse entry table at line # %d\n",
246 /* 1 2 3 4 5 6 7 8 9 10
249 appointmentBody : tick key what details duration period nth enddate ntimes exceptions mailto author attributes_4 tags apptstat privacy attributes_5 hashedattrs
257 if (currentVersion == _DtCMS_VERSION1) {
258 newp = _DtCm_make_appt4(B_TRUE);
259 newp->appt_id.tick = $1;
260 newp->appt_id.key = $2;
262 newp->client_data = $4;
264 newp->period.period = $6;
265 newp->period.nth = $7;
266 newp->period.enddate = $8;
268 newp->exception = $10;
275 if (temp != NULL && (*temp)!='\0') {
278 if(strcmp(item->attr, "ml")==0) {
279 item->clientdata= temp;
287 newp->appt_status = $15;
292 newe = (cms_entry *)calloc(1,
296 newe->num_attrs = currentAttrs.current;
297 newe->attrs = currentAttrs.attrs;
298 currentAttrs.total = 0;
299 currentAttrs.current = 0;
300 currentAttrs.attrs = NULL;
316 if (strlen($1) == 24)
317 $$ = convert_2_tick($1);
319 _csa_iso8601_to_tick($1, &time);
326 quotedString : QUOTEDSTRING
328 $$ = externQuotedString;
346 | WHAT COLON quotedString
353 details : /* empty */
357 | DETAILS COLON quotedString
367 | MAILTO COLON quotedString
373 duration : /* empty */
377 | DURATION COLON number
387 | PERIOD COLON PERIODVAL
389 $$ = externPeriod.period;
403 enddate : /* empty */
407 | ENDDATE COLON quotedString
409 $$ = convert_2_tick($3);
414 privacy : /* empty */
418 | PRIVACY COLON PRIVACYVAL
424 apptstat : /* empty */
428 | APPTSTATUS COLON APPTSTATUSVAL
430 $$ = externApptStatus;
438 | NTIMES COLON number
448 | AUTHOR COLON quotedString
464 $$ = access_delete_4;
472 accesses : /* empty */
482 accesslist : accessitem
487 | accessitem accesslist
489 Access_Entry_4 *e = $1;
495 accessitem : quotedString
498 (Access_Entry_4 *)malloc(
499 sizeof(Access_Entry_4));
501 e->next = (Access_Entry_4 *)NULL;
506 hashedattrs : /* empty */
507 | HASHEDATTRS COLON OPENPAREN hashedattrlist CLOSEPAREN
510 hashedattrlist : hashedattritem
511 | hashedattritem hashedattrlist
514 hashedattritem :OPENPAREN number quotedString CLOSEPAREN
516 add_hashed_attr_to_array(¤tAttrs, $2, $3);
520 attributes_5 : /* empty */
521 | ATTRIBUTES_5 COLON OPENPAREN attributelist_5 CLOSEPAREN
524 attributelist_5 : attributeitem_5
525 | attributeitem_5 attributelist_5
528 attributeitem_5 :OPENPAREN quotedString COMMA quotedString COMMA quotedString CLOSEPAREN
530 if (currentAttrs.total == currentAttrs.current)
532 grow_attr_array(¤tAttrs);
534 add_to_attr_array(¤tAttrs, $2, $4, $6);
538 attributes_4 : /* empty */
542 | ATTRIBUTES_4 COLON OPENPAREN attributelist_4 CLOSEPAREN
548 attributelist_4 : attributeitem_4
552 | attributeitem_4 attributelist_4
559 attributeitem_4 :OPENPAREN quotedString COMMA quotedString COMMA quotedString CLOSEPAREN
561 Attr_4 newattr = _DtCm_make_attr4();
562 newattr->next = (Attr_4)NULL;
565 newattr->clientdata = $6;
568 | OPENPAREN quotedString COMMA quotedString CLOSEPAREN
570 Attr_4 newattr = _DtCm_make_attr4();
571 newattr->next = (Attr_4)NULL;
580 Tag_4 *t = (Tag_4 *)malloc(sizeof(Tag_4));
581 t->next = (Tag_4 *)NULL;
582 t->tag = appointment_4;
586 | TAGS COLON OPENPAREN taglist CLOSEPAREN
604 tagitem : OPENPAREN TAGSVAL COMMA number CLOSEPAREN
606 Tag_4 *t = (Tag_4 *)malloc(sizeof(Tag_4));
607 t->next = (Tag_4 *)NULL;
608 t->tag = externTag.tag;
615 exceptions : /* empty */
619 | EXCEPTION COLON OPENPAREN exceptionlist CLOSEPAREN
625 exceptionlist : exceptitem
629 | exceptitem exceptionlist
638 Exception_4 newexcept =
639 (Exception_4)malloc(sizeof(Except_4));
640 newexcept->next = (Exception_4)NULL;
641 newexcept->ordinal = $1;
647 %% /* Begining of subroutine section */
652 (void)fprintf (stderr, "%s: %s\n", pgname, s);
653 (void)fprintf (stderr, "at line %d\n", yylineno);
659 (void)fprintf (stderr, "%s", s);
668 if (s==NULL) return(NULL);
671 newstr= (char *)calloc(1, (unsigned)i + 1);
673 for (j=0; j<i; j++) {
679 else if (s[j+1]=='\\') {
683 else if (s[j+1]=='\"') {
706 if (strncmp(wday, "Sun", 3) == 0)
708 else if (strncmp(wday, "Mon", 3) == 0)
710 else if (strncmp(wday, "Tue", 3) == 0)
712 else if (strncmp(wday, "Wed", 3) == 0)
714 else if (strncmp(wday, "Thu", 3) == 0)
716 else if (strncmp(wday, "Fri", 3) == 0)
718 else if (strncmp(wday, "Sat", 3) == 0)
725 get_month(char *month)
730 if (strncmp(month, "Jan", 3) == 0)
732 if (strncmp(month, "Feb", 3) == 0)
734 if (strncmp(month, "Mar", 3) == 0)
736 if (strncmp(month, "Apr", 3) == 0)
738 if (strncmp(month, "May", 3) == 0)
740 if (strncmp(month, "Jun", 3) == 0)
742 if (strncmp(month, "Jul", 3) == 0)
744 if (strncmp(month, "Aug", 3) == 0)
746 if (strncmp(month, "Sep", 3) == 0)
748 if (strncmp(month, "Oct", 3) == 0)
750 if (strncmp(month, "Nov", 3) == 0)
752 if (strncmp(month, "Dec", 3) == 0)
759 convert_2_tick(char *datestr)
762 char datebuf[BUFSIZ];
768 memset((void *)&tmstr, 0, sizeof(struct tm));
770 snprintf(datebuf, sizeof(datebuf), "%s", datestr);
773 ptr = strtok(datebuf, " ");
774 if ((tmstr.tm_wday = get_wday(ptr)) == -1)
778 ptr = strtok(NULL, " ");
779 if ((tmstr.tm_mon = get_month(ptr)) == -1)
782 /* get day of month */
783 ptr = strtok(NULL, " ");
785 tmstr.tm_mday = atoi(ptr);
790 ptr = strtok(NULL, " ");
793 if ((tptr = strchr(ptr, ':')) == NULL)
797 tmstr.tm_hour = atoi(ptr);
801 if ((tptr = strchr(ptr, ':')) == NULL)
805 tmstr.tm_min = atoi(ptr);
808 tmstr.tm_sec = atoi(tptr + 1);
812 ptr = strtok(NULL, " ");
814 tmstr.tm_year = atoi(ptr) - 1900;
820 return(mktime(&tmstr));
824 add_hashed_attr_to_array(_attr_array *attrs, int num, char *value)
828 if (num > currentCalendar->entry_tbl->size)
831 if (attrs->current == attrs->total) {
832 grow_attr_array(attrs);
835 attrs->attrs[attrs->current].name.num = num;
836 attrs->attrs[attrs->current].name.name =
837 strdup(currentCalendar->entry_tbl->names[num]);
839 if (get_attr_value(currentCalendar->types[num], value,
840 &attrs->attrs[attrs->current].value) == CSA_SUCCESS)
847 add_to_attr_array(_attr_array *attrs, char *name, char *tag, char *value)
851 if (attrs->current == attrs->total) {
852 grow_attr_array(attrs);
855 attrs->attrs[attrs->current].name.name = name;
856 if ((type = get_tag_from_string(tag)) == -1)
859 if (get_attr_value(type, value, &attrs->attrs[attrs->current].value)
867 get_tag_from_string(char *tagstr)
871 if (*tagstr < '0' || *tagstr > '9')
876 if (i < CSA_VALUE_BOOLEAN || i > CSA_VALUE_OPAQUE_DATA ||
877 i == CSA_VALUE_ATTENDEE_LIST)
883 static CSA_return_code
884 get_attr_value(int type, char *valstr, cms_attribute_value **attrval)
886 char buf1[BUFSIZ], buf2[BUFSIZ];
887 char *ptr1, *ptr2, *ptr3, *ptr4;
890 CSA_opaque_data opqval;
891 CSA_return_code stat = CSA_SUCCESS;
894 case CSA_VALUE_ENUMERATED:
895 case CSA_VALUE_SINT32:
896 stat = _DtCm_set_sint32_attrval(atoi(valstr), attrval);
898 case CSA_VALUE_BOOLEAN:
899 case CSA_VALUE_FLAGS:
900 case CSA_VALUE_UINT32:
901 sscanf(valstr, "%u", &unum);
902 stat = _DtCm_set_uint32_attrval(unum, attrval);
904 case CSA_VALUE_STRING:
905 case CSA_VALUE_DATE_TIME:
906 case CSA_VALUE_DATE_TIME_RANGE:
907 case CSA_VALUE_TIME_DURATION:
908 case CSA_VALUE_CALENDAR_USER:
909 stat = _DtCm_set_string_attrval(valstr, attrval, type);
911 case CSA_VALUE_REMINDER:
912 memset((void *)&remval, 0, sizeof (CSA_reminder));
913 if (ptr1 = strchr(valstr, ':')) {
915 if (ptr2 = strchr(ptr1, ':')) {
917 ptr3 = strchr(ptr2, ':');
921 if (ptr1 == NULL || ptr2 == NULL) {
922 stat = CSA_E_INVALID_PARAMETER;
927 /* format = "string:number:string" */
928 remval.lead_time = valstr;
929 remval.reminder_data.size = atoi(ptr1);
930 remval.reminder_data.data = (unsigned char *)ptr2;
931 stat = _DtCm_set_reminder_attrval(&remval, attrval);
933 /* format = "string:string:number:number:string" */
935 if (ptr4 = strchr(ptr3, ':')) {
937 remval.lead_time = valstr;
938 remval.snooze_time = ptr1;
939 remval.repeat_count = atoi(ptr2);
940 remval.reminder_data.size = atoi(ptr3);
941 remval.reminder_data.data =
942 (unsigned char *)ptr4;
943 stat = _DtCm_set_reminder_attrval(&remval,
946 stat = CSA_E_INVALID_PARAMETER;
950 case CSA_VALUE_ACCESS_LIST:
951 stat = get_access_list_value(valstr, attrval);
953 case CSA_VALUE_DATE_TIME_LIST:
954 stat = get_date_time_list_value(valstr, attrval);
956 case CSA_VALUE_OPAQUE_DATA:
957 if (ptr1 = strchr(valstr, ':')) {
959 opqval.size = atoi(valstr);
960 opqval.data = (unsigned char *)ptr1;
961 stat = _DtCm_set_opaque_attrval(&opqval, attrval);
963 stat = CSA_E_INVALID_PARAMETER;
967 /* need to set type here since type may not be set correctly up there */
968 (*attrval)->type = type;
974 static CSA_return_code
975 get_access_list_value(char *valstr, cms_attribute_value **attrval)
978 cms_access_entry *a, *head, *prev;
979 CSA_return_code stat = CSA_SUCCESS;
980 cms_attribute_value *val;
982 if ((val = (cms_attribute_value *)calloc(1,
983 sizeof(cms_attribute_value))) == NULL)
984 return (CSA_E_INSUFFICIENT_MEMORY);
986 val->type = CSA_VALUE_ACCESS_LIST;
988 if (*valstr == '\0') {
990 return (CSA_SUCCESS);
994 while (ptr = strchr(valstr, ' ')) {
997 stat = get_user_access_entry(valstr, &a);
1000 if (stat != CSA_SUCCESS)
1012 if (stat == CSA_SUCCESS) {
1013 if ((stat = get_user_access_entry(valstr, &a))
1022 if (stat == CSA_SUCCESS) {
1023 val->item.access_list_value = head;
1026 _DtCm_free_cms_access_entry(head);
1033 static CSA_return_code
1034 get_user_access_entry(char *string, cms_access_entry **a)
1037 cms_access_entry *item;
1039 if ((ptr = strchr(string, ':')) == NULL)
1040 return (CSA_E_INVALID_PARAMETER);
1042 if ((item = (cms_access_entry *)malloc(sizeof(cms_access_entry)))
1044 return (CSA_E_INSUFFICIENT_MEMORY);
1048 if ((item->user = strdup(string)) == NULL) {
1050 return (CSA_E_INSUFFICIENT_MEMORY);
1052 item->rights = atoi(ptr+1);
1057 return (CSA_SUCCESS);
1060 #define _DEFAULT_ARRAY_SIZE 30
1063 grow_attr_array(_attr_array *attrs)
1065 cms_attribute *newptr;
1067 if ((newptr = (cms_attribute *)realloc(attrs->attrs,
1068 sizeof(cms_attribute) * (attrs->total + _DEFAULT_ARRAY_SIZE)))
1072 attrs->total += _DEFAULT_ARRAY_SIZE;
1073 attrs->attrs = newptr;
1075 memset((void *)&attrs->attrs[attrs->current], 0,
1076 sizeof(cms_attribute)*_DEFAULT_ARRAY_SIZE);
1079 static CSA_return_code
1080 get_date_time_list_value(char *valstr, cms_attribute_value **attrval)
1083 CSA_date_time_entry *a = NULL, *head, *prev;
1084 CSA_return_code stat = CSA_SUCCESS;
1085 cms_attribute_value *val;
1087 if (*valstr == '\0') {
1089 return (CSA_SUCCESS);
1092 if ((val = (cms_attribute_value *)calloc(1,
1093 sizeof(cms_attribute_value))) == NULL)
1094 return (CSA_E_INSUFFICIENT_MEMORY);
1096 val->type = CSA_VALUE_DATE_TIME_LIST;
1099 while (ptr = strchr(valstr, ' ')) {
1102 if (!(a = calloc(1, sizeof(CSA_date_time_entry))) ||
1103 !(a->date_time = strdup(valstr))) {
1105 stat = CSA_E_INSUFFICIENT_MEMORY;
1119 if (stat == CSA_SUCCESS) {
1120 if ((a = calloc(1, sizeof(CSA_date_time_entry))) &&
1121 (a->date_time = strdup(valstr))) {
1128 stat = CSA_E_INSUFFICIENT_MEMORY;
1132 if (stat == CSA_SUCCESS) {
1133 val->item.date_time_list_value = head;
1136 _DtCm_free_date_time_list(head);
1144 extend_entry_table(int hashednum, char *name, char *typestr)
1148 if (hashednum > _DtCM_DEFINED_ENTRY_ATTR_SIZE) {
1149 if ((type = get_tag_from_string(typestr)) == -1)
1152 (void)_DtCmExtendNameTable(name, hashednum, type,
1153 _DtCm_entry_name_tbl, _DtCM_DEFINED_ENTRY_ATTR_SIZE,
1154 _CSA_entry_attribute_names, ¤tCalendar->entry_tbl,
1155 ¤tCalendar->types);