void icalerror_set_errno(icalerrorenum x) { icalerrno = x; if(icalerror_get_error_state(x) == ICAL_ERROR_FATAL || (icalerror_get_error_state(x) == ICAL_ERROR_DEFAULT && icalerror_errors_are_fatal == 1)) { icalerror_warn(icalerror_strerror(x)); assert(0); } }
NS_IMETHODIMP calIcalProperty::GetIcalString(nsACString &str) { char const* icalstr = icalproperty_as_ical_string(mProperty); if (icalstr == 0) { #ifdef DEBUG fprintf(stderr, "Error getting ical string: %d (%s)\n", icalerrno, icalerror_strerror(icalerrno)); #endif return static_cast<nsresult>(calIErrors::ICS_ERROR_BASE + icalerrno); } str.Assign(icalstr); return NS_OK; }
NS_IMETHODIMP calIcalProperty::GetPropertyName(nsACString &name) { const char *icalstr = icalproperty_get_property_name(mProperty); if (!icalstr) { #ifdef DEBUG fprintf(stderr, "Error getting property name: %d (%s)\n", icalerrno, icalerror_strerror(icalerrno)); #endif return NS_ERROR_FAILURE; } name.Assign(icalstr); return NS_OK; }
void program_errors() { /*Most routines will set icalerrno on errors. This is an enumeration defined in icalerror.h */ icalerror_clear_errno(); (void)icalcomponent_new(ICAL_VEVENT_COMPONENT); if (icalerrno != ICAL_NO_ERROR){ fprintf(stderr,"Horrible libical error: %s\n", icalerror_strerror(icalerrno)); } }
NS_IMETHODIMP calIcalProperty::GetValue(nsACString &str) { icalvalue *value = icalproperty_get_value(mProperty); icalvalue_kind valuekind = icalvalue_isa(value); const char *icalstr; if (valuekind == ICAL_TEXT_VALUE) { icalstr = icalvalue_get_text(value); } else if (valuekind == ICAL_X_VALUE) { icalstr = icalvalue_get_x(value); } else if (valuekind == ICAL_ATTACH_VALUE) { icalattach *attach = icalvalue_get_attach(value); if (icalattach_get_is_url(attach)) { icalstr = icalattach_get_url(attach); } else { icalstr = (const char *)icalattach_get_data(attach); } } else { icalstr = icalproperty_get_value_as_string(mProperty); } if (!icalstr) { if (icalerrno == ICAL_BADARG_ERROR) { str.Truncate(); // Set string to null, because we don't have a value // (which is something different then an empty value) str.SetIsVoid(true); return NS_OK; } #ifdef DEBUG fprintf(stderr, "Error getting string value: %d (%s)\n", icalerrno, icalerror_strerror(icalerrno)); #endif return NS_ERROR_FAILURE; } str.Assign(icalstr); return NS_OK; }
NS_IMETHODIMP calIcalProperty::GetValueAsIcalString(nsACString &str) { const char *icalstr = icalproperty_get_value_as_string(mProperty); if (!icalstr) { if (icalerrno == ICAL_BADARG_ERROR) { str.Truncate(); // Set string to null, because we don't have a value // (which is something different then an empty value) str.SetIsVoid(true); return NS_OK; } #ifdef DEBUG fprintf(stderr, "Error getting string value: %d (%s)\n", icalerrno, icalerror_strerror(icalerrno)); #endif return NS_ERROR_FAILURE; } str.Assign(icalstr); return NS_OK; }
nsresult calIcalComponent::Serialize(char **icalstr) { NS_ENSURE_ARG_POINTER(icalstr); // add the timezone bits if (icalcomponent_isa(mComponent) == ICAL_VCALENDAR_COMPONENT && mReferencedTimezones.Count() > 0) { mReferencedTimezones.EnumerateRead(AddTimezoneComponentToIcal, mComponent); } *icalstr = icalcomponent_as_ical_string(mComponent); if (!*icalstr) { // xxx todo: what about NS_ERROR_OUT_OF_MEMORY? #ifdef DEBUG fprintf(stderr, "Error serializing: %d (%s)\n", icalerrno, icalerror_strerror(icalerrno)); #endif // The return values in calIError match with libical errnos, // so no need for a conversion table or anything. return static_cast<nsresult>(calIErrors::ICS_ERROR_BASE + icalerrno); } return NS_OK; }
const char *icalerror_perror(void) { return icalerror_strerror(icalerrno); }
int main(int c, char *argv[]){ icalset *clusterin, *clusterout = NULL; icalcomponent *itr; int count=0; int tostdout = 0; if(c < 2 || c > 3){ usage(argv[0]); exit(1); } if (c == 2){ tostdout = 1; } /*icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL);*/ #ifdef SIGALRM signal(SIGALRM,sig_alrm); alarm(10); #endif clusterin = icalfileset_new(argv[1]); #ifdef SIGALRM alarm(0); #endif if (clusterin == 0){ printf("Could not open input cluster \"%s\"\n",argv[1]); if(icalerrno!= ICAL_NO_ERROR){ printf("Error: %s\n",icalerror_strerror(icalerrno)); } exit(1); } if (!tostdout){ #ifdef SIGALRM alarm(10); #endif clusterout = icalfileset_new(argv[2]); #ifdef SIGALRM alarm(0); #endif if (clusterout == 0){ printf("Could not open output cluster \"%s\"\n",argv[2]); exit(1); } } for (itr = icalset_get_first_component(clusterin); itr != 0; itr = icalset_get_next_component(clusterin)){ icalerror_set_error_state(ICAL_BADARG_ERROR, ICAL_ERROR_NONFATAL); icalrestriction_check(itr); icalerror_set_error_state(ICAL_BADARG_ERROR, ICAL_ERROR_DEFAULT); if (itr != 0){ if(tostdout){ printf("--------------\n%s\n",icalcomponent_as_ical_string(itr)); } else { icalfileset_add_component(clusterout, icalcomponent_new_clone(itr)); } count++; } else { printf("Got NULL component"); } } printf("Transfered %d components\n",count); icalset_free(clusterin); if (!tostdout){ icalfileset_mark(clusterout); icalset_free(clusterout); } return 0; }
char *icalerror_perror() { return icalerror_strerror(icalerrno); }