1 /* -*- Mode: C -*- */
2 /*======================================================================
3 FILE: icalenum.c
4 CREATOR: eric 29 April 1999
5
6 $Id: icalenums.c,v 1.16 2008-01-15 23:17:40 dothebart Exp $
7
8
9 (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
10 http://www.softwarestudio.org
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of either:
14
15 The LGPL as published by the Free Software Foundation, version
16 2.1, available at: http://www.fsf.org/copyleft/lesser.html
17
18 Or:
19
20 The Mozilla Public License Version 1.0. You may obtain a copy of
21 the License at http://www.mozilla.org/MPL/
22
23 The original code is icalenum.c
24
25 ======================================================================*/
26
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include "icalenums.h"
33
34 #include <stdio.h> /* For fprintf */
35 #include <stdio.h> /* For stderr */
36 #include <string.h> /* For strncmp */
37 #include <assert.h>
38 #include "icalmemory.h"
39
40 #ifdef WIN32
41 #if defined(_MSC_VER) && (_MSC_VER < 1900)
42 #define snprintf _snprintf
43 #endif
44 #endif
45
46
47 /*** @brief Allowed request status values
48 */
49 static const struct {
50 enum icalrequeststatus kind;
51 int major;
52 int minor;
53 const char* str;
54 } request_status_map[] = {
55 {ICAL_2_0_SUCCESS_STATUS, 2,0,"Success."},
56 {ICAL_2_1_FALLBACK_STATUS, 2,1,"Success but fallback taken on one or more property values."},
57 {ICAL_2_2_IGPROP_STATUS, 2,2,"Success, invalid property ignored."},
58 {ICAL_2_3_IGPARAM_STATUS, 2,3,"Success, invalid property parameter ignored."},
59 {ICAL_2_4_IGXPROP_STATUS, 2,4,"Success, unknown non-standard property ignored."},
60 {ICAL_2_5_IGXPARAM_STATUS, 2,5,"Success, unknown non standard property value ignored."},
61 {ICAL_2_6_IGCOMP_STATUS, 2,6,"Success, invalid calendar component ignored."},
62 {ICAL_2_7_FORWARD_STATUS, 2,7,"Success, request forwarded to Calendar User."},
63 {ICAL_2_8_ONEEVENT_STATUS, 2,8,"Success, repeating event ignored. Scheduled as a single component."},
64 {ICAL_2_9_TRUNC_STATUS, 2,9,"Success, truncated end date time to date boundary."},
65 {ICAL_2_10_ONETODO_STATUS, 2,10,"Success, repeating VTODO ignored. Scheduled as a single VTODO."},
66 {ICAL_2_11_TRUNCRRULE_STATUS, 2,11,"Success, unbounded RRULE clipped at some finite number of instances "},
67 {ICAL_3_0_INVPROPNAME_STATUS, 3,0,"Invalid property name."},
68 {ICAL_3_1_INVPROPVAL_STATUS, 3,1,"Invalid property value."},
69 {ICAL_3_2_INVPARAM_STATUS, 3,2,"Invalid property parameter."},
70 {ICAL_3_3_INVPARAMVAL_STATUS, 3,3,"Invalid property parameter value."},
71 {ICAL_3_4_INVCOMP_STATUS, 3,4,"Invalid calendar component."},
72 {ICAL_3_5_INVTIME_STATUS, 3,5,"Invalid date or time."},
73 {ICAL_3_6_INVRULE_STATUS, 3,6,"Invalid rule."},
74 {ICAL_3_7_INVCU_STATUS, 3,7,"Invalid Calendar User."},
75 {ICAL_3_8_NOAUTH_STATUS, 3,8,"No authority."},
76 {ICAL_3_9_BADVERSION_STATUS, 3,9,"Unsupported version."},
77 {ICAL_3_10_TOOBIG_STATUS, 3,10,"Request entity too large."},
78 {ICAL_3_11_MISSREQCOMP_STATUS, 3,11,"Required component or property missing."},
79 {ICAL_3_12_UNKCOMP_STATUS, 3,12,"Unknown component or property found."},
80 {ICAL_3_13_BADCOMP_STATUS, 3,13,"Unsupported component or property found"},
81 {ICAL_3_14_NOCAP_STATUS, 3,14,"Unsupported capability."},
82 {ICAL_3_15_INVCOMMAND, 3,15,"Invalid command."},
83 {ICAL_4_0_BUSY_STATUS, 4,0,"Event conflict. Date/time is busy."},
84 {ICAL_4_1_STORE_ACCESS_DENIED, 4,1,"Store Access Denied."},
85 {ICAL_4_2_STORE_FAILED, 4,2,"Store Failed."},
86 {ICAL_4_3_STORE_NOT_FOUND, 4,3,"Store not found."},
87 {ICAL_5_0_MAYBE_STATUS, 5,0,"Request MAY supported."},
88 {ICAL_5_1_UNAVAIL_STATUS, 5,1,"Service unavailable."},
89 {ICAL_5_2_NOSERVICE_STATUS, 5,2,"Invalid calendar service."},
90 {ICAL_5_3_NOSCHED_STATUS, 5,3,"No scheduling support for user."},
91 {ICAL_6_1_CONTAINER_NOT_FOUND, 6,1,"Container not found."},
92 {ICAL_9_0_UNRECOGNIZED_COMMAND, 9,0,"An unrecognized command was received."},
93 {ICAL_UNKNOWN_STATUS, 0,0,"Error: Unknown request status"}
94 };
95
96
97 /*** @brief Return the descriptive text for a request status
98 */
icalenum_reqstat_desc(icalrequeststatus stat)99 const char* icalenum_reqstat_desc(icalrequeststatus stat)
100 {
101 int i;
102
103 for (i=0; request_status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) {
104 if ( request_status_map[i].kind == stat) {
105 return request_status_map[i].str;
106 }
107 }
108
109 return 0;
110 }
111
icalenum_reqstat_code(icalrequeststatus stat)112 char* icalenum_reqstat_code(icalrequeststatus stat)
113 {
114 char *buf;
115 buf = icalenum_reqstat_code_r(stat);
116 icalmemory_add_tmp_buffer(buf);
117 return buf;
118 }
119
120
121 /*** @brief Return the code for a request status
122 */
icalenum_reqstat_code_r(icalrequeststatus stat)123 char* icalenum_reqstat_code_r(icalrequeststatus stat)
124 {
125 int i, major, minor;
126 char tmpbuf[36];
127
128 for (i=0; request_status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) {
129 if ( request_status_map[i].kind == stat) {
130 major = request_status_map[i].major;
131 minor = request_status_map[i].minor;
132 snprintf(tmpbuf, sizeof(tmpbuf), "%i.%i", major, minor);
133 return icalmemory_strdup(tmpbuf);
134 }
135 }
136 return NULL;
137 }
138
139 /*** @brief Return the major number for a request status
140 */
icalenum_reqstat_major(icalrequeststatus stat)141 short icalenum_reqstat_major(icalrequeststatus stat)
142 {
143 int i;
144
145 for (i=0; request_status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) {
146 if ( request_status_map[i].kind == stat) {
147 return request_status_map[i].major;
148 }
149 }
150 return -1;
151 }
152
153 /*** @brief Return the minor number for a request status
154 */
icalenum_reqstat_minor(icalrequeststatus stat)155 short icalenum_reqstat_minor(icalrequeststatus stat)
156 {
157 int i;
158
159 for (i=0; request_status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) {
160 if ( request_status_map[i].kind == stat) {
161 return request_status_map[i].minor;
162 }
163 }
164 return -1;
165 }
166
167
168 /*** @brief Return a request status for major/minor status numbers
169 */
icalenum_num_to_reqstat(short major,short minor)170 icalrequeststatus icalenum_num_to_reqstat(short major, short minor)
171 {
172 int i;
173
174 for (i=0; request_status_map[i].kind != ICAL_UNKNOWN_STATUS; i++) {
175 if ( request_status_map[i].major == major && request_status_map[i].minor == minor) {
176 return request_status_map[i].kind;
177 }
178 }
179 return 0;
180 }
181
182
183
184