bump to 1.0.0 and clean up spec file
[platform/upstream/libical.git] / src / libical / icalenums.c
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 #if defined(_MSC_VER)
41 #define snprintf _snprintf
42 #endif
43
44 /*** @brief Allowed request status values
45  */
46 static const struct {
47          enum icalrequeststatus kind;
48         int major;
49         int minor;
50         const char* str;
51 } request_status_map[] = {
52     {ICAL_2_0_SUCCESS_STATUS, 2,0,"Success."},
53     {ICAL_2_1_FALLBACK_STATUS, 2,1,"Success but fallback taken  on one or more property  values."},
54     {ICAL_2_2_IGPROP_STATUS, 2,2,"Success, invalid property ignored."},
55     {ICAL_2_3_IGPARAM_STATUS, 2,3,"Success, invalid property parameter ignored."},
56     {ICAL_2_4_IGXPROP_STATUS, 2,4,"Success, unknown non-standard property ignored."},
57     {ICAL_2_5_IGXPARAM_STATUS, 2,5,"Success, unknown non standard property value  ignored."},
58     {ICAL_2_6_IGCOMP_STATUS, 2,6,"Success, invalid calendar component ignored."},
59     {ICAL_2_7_FORWARD_STATUS, 2,7,"Success, request forwarded to Calendar User."},
60     {ICAL_2_8_ONEEVENT_STATUS, 2,8,"Success, repeating event ignored. Scheduled as a  single component."},
61     {ICAL_2_9_TRUNC_STATUS, 2,9,"Success, truncated end date time to date boundary."},
62     {ICAL_2_10_ONETODO_STATUS, 2,10,"Success, repeating VTODO ignored. Scheduled as a  single VTODO."},
63     {ICAL_2_11_TRUNCRRULE_STATUS, 2,11,"Success, unbounded RRULE clipped at some finite  number of instances  "},
64     {ICAL_3_0_INVPROPNAME_STATUS, 3,0,"Invalid property name."},
65     {ICAL_3_1_INVPROPVAL_STATUS, 3,1,"Invalid property value."},
66     {ICAL_3_2_INVPARAM_STATUS, 3,2,"Invalid property parameter."},
67     {ICAL_3_3_INVPARAMVAL_STATUS, 3,3,"Invalid property parameter  value."},
68     {ICAL_3_4_INVCOMP_STATUS, 3,4,"Invalid calendar component."},
69     {ICAL_3_5_INVTIME_STATUS, 3,5,"Invalid date or time."},
70     {ICAL_3_6_INVRULE_STATUS, 3,6,"Invalid rule."},
71     {ICAL_3_7_INVCU_STATUS, 3,7,"Invalid Calendar User."},
72     {ICAL_3_8_NOAUTH_STATUS, 3,8,"No authority."},
73     {ICAL_3_9_BADVERSION_STATUS, 3,9,"Unsupported version."},
74     {ICAL_3_10_TOOBIG_STATUS, 3,10,"Request entity too large."},
75     {ICAL_3_11_MISSREQCOMP_STATUS, 3,11,"Required component or property missing."},
76     {ICAL_3_12_UNKCOMP_STATUS, 3,12,"Unknown component or property found."},
77     {ICAL_3_13_BADCOMP_STATUS, 3,13,"Unsupported component or property found"},
78     {ICAL_3_14_NOCAP_STATUS, 3,14,"Unsupported capability."},
79     {ICAL_3_15_INVCOMMAND, 3,15,"Invalid command."},
80     {ICAL_4_0_BUSY_STATUS, 4,0,"Event conflict. Date/time  is busy."},
81     {ICAL_4_1_STORE_ACCESS_DENIED, 4,1,"Store Access Denied."},
82     {ICAL_4_2_STORE_FAILED, 4,2,"Store Failed."},
83     {ICAL_4_3_STORE_NOT_FOUND, 4,3,"Store not found."},
84     {ICAL_5_0_MAYBE_STATUS, 5,0,"Request MAY supported."},
85     {ICAL_5_1_UNAVAIL_STATUS, 5,1,"Service unavailable."},
86     {ICAL_5_2_NOSERVICE_STATUS, 5,2,"Invalid calendar service."},
87     {ICAL_5_3_NOSCHED_STATUS, 5,3,"No scheduling support for  user."},
88     {ICAL_6_1_CONTAINER_NOT_FOUND, 6,1,"Container not found."},
89     {ICAL_9_0_UNRECOGNIZED_COMMAND, 9,0,"An unrecognized command was received."},
90     {ICAL_UNKNOWN_STATUS, 0,0,"Error: Unknown request status"}
91 };
92
93
94 /*** @brief Return the descriptive text for a request status
95  */
96 const char* icalenum_reqstat_desc(icalrequeststatus stat)
97 {
98     int i;
99
100     for (i=0; request_status_map[i].kind  != ICAL_UNKNOWN_STATUS; i++) {
101         if ( request_status_map[i].kind ==  stat) {
102             return request_status_map[i].str;
103         }
104     }
105
106     return 0;
107 }
108
109 char* icalenum_reqstat_code(icalrequeststatus stat)
110 {
111         char *buf;
112         buf = icalenum_reqstat_code_r(stat);
113         icalmemory_add_tmp_buffer(buf);
114         return buf;
115 }
116
117
118 /*** @brief Return the code for a request status
119  */
120 char* icalenum_reqstat_code_r(icalrequeststatus stat)
121 {
122     int i, major, minor;
123     char tmpbuf[36];
124
125     for (i=0; request_status_map[i].kind  != ICAL_UNKNOWN_STATUS; i++) {
126         if ( request_status_map[i].kind ==  stat) {
127             major = request_status_map[i].major;
128             minor = request_status_map[i].minor;
129             snprintf(tmpbuf, sizeof(tmpbuf), "%i.%i", major, minor);
130             return icalmemory_strdup(tmpbuf);
131         }
132     }
133     return NULL;
134 }
135
136 /*** @brief Return the major number for a request status
137  */
138 short icalenum_reqstat_major(icalrequeststatus stat)
139 {
140     int i;
141
142     for (i=0; request_status_map[i].kind  != ICAL_UNKNOWN_STATUS; i++) {
143         if ( request_status_map[i].kind ==  stat) {
144             return request_status_map[i].major;
145         }
146     }
147     return -1;
148 }
149
150 /*** @brief Return the minor number for a request status
151  */
152 short icalenum_reqstat_minor(icalrequeststatus stat)
153 {
154     int i;
155
156     for (i=0; request_status_map[i].kind  != ICAL_UNKNOWN_STATUS; i++) {
157         if ( request_status_map[i].kind ==  stat) {
158             return request_status_map[i].minor;
159         }
160     }
161     return -1;
162 }
163
164
165 /*** @brief Return a request status for major/minor status numbers
166  */
167 icalrequeststatus icalenum_num_to_reqstat(short major, short minor)
168 {
169     int i;
170
171     for (i=0; request_status_map[i].kind  != ICAL_UNKNOWN_STATUS; i++) {
172         if ( request_status_map[i].major ==  major && request_status_map[i].minor ==  minor) {
173             return request_status_map[i].kind;
174         }
175     }
176     return 0;
177 }
178
179
180