Solaris Common Desktop Environment: Programmer's Guide

Looking Up Entries in a Calendar


Example 10-7 Looking up Calendar Entries; Reading Attribute Values

#include <csa/csa.h>  

CSA_return_code		stat; 
CSA_session_handle	cal;
CSA_attribute		attrs[4]; 
CSA_attribute_value	attr_val[4]; 
CSA_enum		ops[4];
CSA_uint32		i; 
CSA_uint32		num_entries;
 CSA_entry_handle	*entries;
CSA_uint32		num_attributes; 
CSA_attribute		*entry_attrs;  

/* find all entries with the following criteria:
  * (all appointments in the month of August 1996 UTC time)
  * start date equals to or after 00:00:00 Aug 1 1996 UTC time
  * and start date before 00:00:00 Sep 1 1996 UTC time
  * and type equals to CSA_TYPE_EVENT
  * and sub-type equals CSA_SUBTYPE_APPOINTMENT
  */  

i = 0;  

/* start date equals to or after 00:00:00 Aug 1 1996 UTC time */ 
attrs[i].name = CSA_ENTRY_ATTR_START_DATE; 
attrs[i].value = &attr_val[i]; 
attrs[i].attribute_extensions = NULL; 
attr_val[i].type = CSA_VALUE_DATE_TIME;
attr_val[i].item.date_time_value = "19960801T000000Z"; 
ops[i] = CSA_MATCH_GREATER_THAN_OR_EQUAL_TO; 
i++;  

/* start date before 00:00:00 Sep 1 1996 UTC time */ 
attrs[i].name = CSA_ENTRY_ATTR_START_DATE; 
attrs[i].value = &attr_val[i]; 
attrs[i].attribute_extensions = NULL; 
attr_val[i].type = CSA_VALUE_DATE_TIME; 
attr_val[i].item.date_time_value = "19960901T000000Z" 
ops[i] = CSA_MATCH_LESS_THAN; 
i++;  

/* type equals to CSA_TYPE_EVENT */ 
attrs[i].name = CSA_ENTRY_ATTR_TYPE; 
attrs[i].value = &attr_val[i]; 
attrs[i].attribute_extensions = NULL; 
attr_val[i].type = CSA_VALUE_UINT32; 
attr_val[i].item.sint32_value = CSA_TYPE_EVENT; 
ops[i] = CSA_MATCH_EQUAL_TO; 
i++;  

/* sub-type equals CSA_SUBTYPE_APPOINTMENT */ 
attrs[i].name = CSA_ENTRY_ATTR_SUBTYPE; 
attrs[i].value = &attr_val[i]; 
attrs[i].attribute_extensions = NULL; 
attr_val[i].type = CSA_VALUE_STRING; 
attr_val[i].item.string_value = CSA_SUBTYPE_APPOINTMENT; 
ops[i] = CSA_MATCH_EQUAL_TO; 
i++;  

/* do look up */ 
stat = csa_list_entries(csa, i, attrs, ops, &num_entries, &entries, NULL);

  if (stat == CSA_SUCCESS) {
     for (i = 0; i < num_entries; i++) {
 	/* get all attribute values of the entry;
 	 * specifying 0 for number_names and NULL for attribute_names
 	 * will cause all attribute values to be returned
 	 */ 	
   stat = csa_read_entry_attributes(cal, entries[i], 0, NULL,
 					 &num_attributes, &entry_attrs,
 					 NULL); 	if (stat == CSA_SUCCESS) {
 	    /* use the returned attribute values,
 	     * free the memory when done
 	     */
 	    csa_free(entry_attrs);
 	} else {
 	    /* handle error */
 	}
     }
 } else {
     /* handle error */ 
}   

Example: Change the end time of the returned appointments to be
 	 one hour later. 

CSA_attribute_reference	name = CSA_ENTRY_ATTR_END_DATE; 
char			buffer[80]; 
time_t			endtime; 
CSA_entry_handle	new_entry;  

for (i = 0; i < num_entries; i++) {
     /* get the end time of the appointment */
     stat = csa_read_entry_attributes(cal, entries[i], 0, &name,
 				    &num_attributes, &entry_attrs, NULL);
     if (stat == CSA_SUCCESS) {
 	/* change the end time to be one hour later */
 	from_iso8601_time(entry_attrs[0].value->item.date_time_value, &endtime);
 	endtime += 60*60 /* number of second in an hour */
 	to_iso8601_time(endtime, buffer);
  	attrs[0].name = CSA_ENTRY_ATTR_END_DATE;
   attrs[0].value = &attr_val[i];
 	attrs[0].attribute_extensions = NULL;	
   attr_val[0].type = CSA_VALUE_DATE_TIME;
 	attr_val[0].item.date_time_value = buffer;
  	stat = csa_update_entry_attributes(cal, entries[0], CSA_SCOPE_ALL,
 			      	CSA_FALSE, 1, attrs, &new_entry,
 					   NULL);
 	if (stat == CSA_SUCCESS) {
 	    csa_free(new_entry);
 	} else {
 	    /* handle error */
 	}
  	csa_free(entry_attrs);
      } else {
 	    /* handle error */
     } 
}