Example #1
0
/* Return the first category that is not equal to GNOKII */
static const char *comp_get_category(icalcomponent *comp)
{
	icalproperty *cat = NULL;
	const char *str;

	for (cat = icalcomponent_get_first_property(comp, ICAL_CATEGORIES_PROPERTY);
	     cat;
	     cat = icalcomponent_get_next_property(comp, ICAL_CATEGORIES_PROPERTY)) {
		str = icalproperty_get_categories(cat);
		if (strncasecmp("GNOKII", str, 6) != 0)
			return str;
	}
	return NULL;
}
//TODO:
void ical2exchange_property_CATEGORIES(struct ical2exchange *ical2exchange)
{
	struct StringArray_r *sArray;
	char **stringArray = NULL;
	char string[256];
	char *value;
	char *tok;
	icalproperty *categoriesProp;
	uint32_t i = 0;

	/*sanity check*/
 	if(!ical2exchange->categoriesEvent) return;
	
	sArray = talloc(ical2exchange->mem_ctx, struct StringArray_r);
	
	categoriesProp = icalcomponent_get_first_property(ical2exchange->categoriesEvent, ICAL_CATEGORIES_PROPERTY);
	sArray->cValues = 0;
	while(categoriesProp){
	
		value = strdup(icalproperty_get_categories(categoriesProp));
		tok = strtok(value, ",");
		while(tok){
			if(!stringArray){
				stringArray = talloc_array(ical2exchange->mem_ctx, char *, 1);
			} else {
				stringArray = talloc_realloc(ical2exchange->mem_ctx, stringArray, char *, sArray->cValues+2);
			}
			strcpy(string, "");
			while(tok[i]){
				if (strlen(string) == 255) break;
				//remove beginning and ending white spaces
				if((tok[i]!= ' ' || (tok[i+1] && tok[i+1] != ' ')) && (strlen(string) || tok[i]!=' ')){
					strncat(string, &tok[i], 1);
				}
				i++;
			}
			stringArray[sArray->cValues] = talloc_strdup(ical2exchange->mem_ctx, string);
			sArray->cValues++;
			i=0;
			tok= strtok(NULL, ",");
		}