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)!=NULL) {
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)
757 convert_2_tick(char *datestr)
760 char datebuf[BUFSIZ];
766 memset((void *)&tmstr, NULL, sizeof(struct tm));
768 strcpy(datebuf, datestr);
771 ptr = strtok(datebuf, " ");
772 if ((tmstr.tm_wday = get_wday(ptr)) == -1)
776 ptr = strtok(NULL, " ");
777 if ((tmstr.tm_mon = get_month(ptr)) == -1)
780 /* get day of month */
781 ptr = strtok(NULL, " ");
783 tmstr.tm_mday = atoi(ptr);
788 ptr = strtok(NULL, " ");
791 if ((tptr = strchr(ptr, ':')) == NULL)
795 tmstr.tm_hour = atoi(ptr);
799 if ((tptr = strchr(ptr, ':')) == NULL)
803 tmstr.tm_min = atoi(ptr);
806 tmstr.tm_sec = atoi(tptr + 1);
810 ptr = strtok(NULL, " ");
812 tmstr.tm_year = atoi(ptr) - 1900;
818 return(mktime(&tmstr));
822 add_hashed_attr_to_array(_attr_array *attrs, int num, char *value)
826 if (num > currentCalendar->entry_tbl->size)
829 if (attrs->current == attrs->total) {
830 grow_attr_array(attrs);
833 attrs->attrs[attrs->current].name.num = num;
834 attrs->attrs[attrs->current].name.name =
835 strdup(currentCalendar->entry_tbl->names[num]);
837 if (get_attr_value(currentCalendar->types[num], value,
838 &attrs->attrs[attrs->current].value) == CSA_SUCCESS)
845 add_to_attr_array(_attr_array *attrs, char *name, char *tag, char *value)
849 if (attrs->current == attrs->total) {
850 grow_attr_array(attrs);
853 attrs->attrs[attrs->current].name.name = name;
854 if ((type = get_tag_from_string(tag)) == -1)
857 if (get_attr_value(type, value, &attrs->attrs[attrs->current].value)
865 get_tag_from_string(char *tagstr)
869 if (*tagstr < '0' || *tagstr > '9')
874 if (i < CSA_VALUE_BOOLEAN || i > CSA_VALUE_OPAQUE_DATA ||
875 i == CSA_VALUE_ATTENDEE_LIST)
881 static CSA_return_code
882 get_attr_value(int type, char *valstr, cms_attribute_value **attrval)
884 char buf1[BUFSIZ], buf2[BUFSIZ];
885 char *ptr1, *ptr2, *ptr3, *ptr4;
888 CSA_opaque_data opqval;
889 CSA_return_code stat;
892 case CSA_VALUE_ENUMERATED:
893 case CSA_VALUE_SINT32:
894 stat = _DtCm_set_sint32_attrval(atoi(valstr), attrval);
896 case CSA_VALUE_BOOLEAN:
897 case CSA_VALUE_FLAGS:
898 case CSA_VALUE_UINT32:
899 sscanf(valstr, "%u", &unum);
900 stat = _DtCm_set_uint32_attrval(unum, attrval);
902 case CSA_VALUE_STRING:
903 case CSA_VALUE_DATE_TIME:
904 case CSA_VALUE_DATE_TIME_RANGE:
905 case CSA_VALUE_TIME_DURATION:
906 case CSA_VALUE_CALENDAR_USER:
907 stat = _DtCm_set_string_attrval(valstr, attrval, type);
909 case CSA_VALUE_REMINDER:
910 memset((void *)&remval, NULL, sizeof (CSA_reminder));
911 if (ptr1 = strchr(valstr, ':')) {
913 if (ptr2 = strchr(ptr1, ':')) {
915 ptr3 = strchr(ptr2, ':');
919 if (ptr1 == NULL || ptr2 == NULL) {
920 stat = CSA_E_INVALID_PARAMETER;
925 /* format = "string:number:string" */
926 remval.lead_time = valstr;
927 remval.reminder_data.size = atoi(ptr1);
928 remval.reminder_data.data = (unsigned char *)ptr2;
929 stat = _DtCm_set_reminder_attrval(&remval, attrval);
931 /* format = "string:string:number:number:string" */
933 if (ptr4 = strchr(ptr3, ':')) {
935 remval.lead_time = valstr;
936 remval.snooze_time = ptr1;
937 remval.repeat_count = atoi(ptr2);
938 remval.reminder_data.size = atoi(ptr3);
939 remval.reminder_data.data =
940 (unsigned char *)ptr4;
941 stat = _DtCm_set_reminder_attrval(&remval,
944 stat = CSA_E_INVALID_PARAMETER;
948 case CSA_VALUE_ACCESS_LIST:
949 stat = get_access_list_value(valstr, attrval);
951 case CSA_VALUE_DATE_TIME_LIST:
952 stat = get_date_time_list_value(valstr, attrval);
954 case CSA_VALUE_OPAQUE_DATA:
955 if (ptr1 = strchr(valstr, ':')) {
957 opqval.size = atoi(valstr);
958 opqval.data = (unsigned char *)ptr1;
959 stat = _DtCm_set_opaque_attrval(&opqval, attrval);
961 stat = CSA_E_INVALID_PARAMETER;
965 /* need to set type here since type may not be set correctly up there */
966 (*attrval)->type = type;
972 static CSA_return_code
973 get_access_list_value(char *valstr, cms_attribute_value **attrval)
976 cms_access_entry *a, *head, *prev;
977 CSA_return_code stat = CSA_SUCCESS;
978 cms_attribute_value *val;
980 if ((val = (cms_attribute_value *)calloc(1,
981 sizeof(cms_attribute_value))) == NULL)
982 return (CSA_E_INSUFFICIENT_MEMORY);
984 val->type = CSA_VALUE_ACCESS_LIST;
986 if (*valstr == '\0') {
988 return (CSA_SUCCESS);
992 while (ptr = strchr(valstr, ' ')) {
995 stat = get_user_access_entry(valstr, &a);
998 if (stat != CSA_SUCCESS)
1010 if (stat == CSA_SUCCESS) {
1011 if ((stat = get_user_access_entry(valstr, &a))
1020 if (stat == CSA_SUCCESS) {
1021 val->item.access_list_value = head;
1024 _DtCm_free_cms_access_entry(head);
1031 static CSA_return_code
1032 get_user_access_entry(char *string, cms_access_entry **a)
1035 cms_access_entry *item;
1037 if ((ptr = strchr(string, ':')) == NULL)
1038 return (CSA_E_INVALID_PARAMETER);
1040 if ((item = (cms_access_entry *)malloc(sizeof(cms_access_entry)))
1042 return (CSA_E_INSUFFICIENT_MEMORY);
1046 if ((item->user = strdup(string)) == NULL) {
1048 return (CSA_E_INSUFFICIENT_MEMORY);
1050 item->rights = atoi(ptr+1);
1055 return (CSA_SUCCESS);
1058 #define _DEFAULT_ARRAY_SIZE 30
1061 grow_attr_array(_attr_array *attrs)
1063 cms_attribute *newptr;
1065 if ((newptr = (cms_attribute *)realloc(attrs->attrs,
1066 sizeof(cms_attribute) * (attrs->total + _DEFAULT_ARRAY_SIZE)))
1070 attrs->total += _DEFAULT_ARRAY_SIZE;
1071 attrs->attrs = newptr;
1073 memset((void *)&attrs->attrs[attrs->current], NULL,
1074 sizeof(cms_attribute)*_DEFAULT_ARRAY_SIZE);
1077 static CSA_return_code
1078 get_date_time_list_value(char *valstr, cms_attribute_value **attrval)
1081 CSA_date_time_entry *a, *head, *prev;
1082 CSA_return_code stat = CSA_SUCCESS;
1083 cms_attribute_value *val;
1085 if (*valstr == '\0') {
1087 return (CSA_SUCCESS);
1090 if ((val = (cms_attribute_value *)calloc(1,
1091 sizeof(cms_attribute_value))) == NULL)
1092 return (CSA_E_INSUFFICIENT_MEMORY);
1094 val->type = CSA_VALUE_DATE_TIME_LIST;
1097 while (ptr = strchr(valstr, ' ')) {
1100 if (!(a = calloc(1, sizeof(CSA_date_time_entry))) ||
1101 !(a->date_time = strdup(valstr))) {
1103 stat = CSA_E_INSUFFICIENT_MEMORY;
1117 if (stat == CSA_SUCCESS) {
1118 if ((a = calloc(1, sizeof(CSA_date_time_entry))) &&
1119 (a->date_time = strdup(valstr))) {
1125 stat = CSA_E_INSUFFICIENT_MEMORY;
1128 if (stat == CSA_SUCCESS) {
1129 val->item.date_time_list_value = head;
1132 _DtCm_free_date_time_list(head);
1140 extend_entry_table(int hashednum, char *name, char *typestr)
1144 if (hashednum > _DtCM_DEFINED_ENTRY_ATTR_SIZE) {
1145 if ((type = get_tag_from_string(typestr)) == -1)
1148 (void)_DtCmExtendNameTable(name, hashednum, type,
1149 _DtCm_entry_name_tbl, _DtCM_DEFINED_ENTRY_ATTR_SIZE,
1150 _CSA_entry_attribute_names, ¤tCalendar->entry_tbl,
1151 ¤tCalendar->types);