Example #1
0
static BongoJsonObject *
ConvertFile(const char *filename)
{
    icalparser *parser;
    FILE *f;
    icalcomponent *component;    
    BongoJsonObject *obj;

    parser = icalparser_new();
    f = fopen(filename, "r");

    if (!f) {
        printf("couldn't open input file %s\n", filename);
        return NULL;
    }
    
    icalparser_set_gen_data(parser, f);

    component = icalparser_parse(parser, ReadStream);
    icalcomponent_strip_errors(component);

    obj = BongoCalIcalToJson(component);

    return obj;
}
Example #2
0
/* read a vcalendar event given by id from file f and store the data in calnote */
GNOKII_API gn_error gn_ical2calnote(FILE *f, gn_calnote *calnote, int id)
{
#ifdef HAVE_LIBICAL
	icalparser *parser = NULL;
	icalcomponent *comp = NULL;
	gn_error retval;

	parser = icalparser_new();
	if (!parser) {
		return GN_ERR_FAILED;
	}

	icalparser_set_gen_data(parser, f);

	comp = icalparser_parse(parser, ical_fgets);
	if (!comp) {
		icalparser_free(parser);
		return GN_ERR_FAILED;
	}

	retval = gn_ical2calnote_real(comp, calnote, id);

	icalcomponent_free(comp);
	icalparser_free(parser);

	return retval;
#else
	return GN_ERR_NOTIMPLEMENTED;
#endif /* HAVE_LIBICAL */
}
Example #3
0
GNOKII_API int gn_ical2todo(FILE *f, gn_todo *ctodo, int id)
{
#ifdef HAVE_LIBICAL
	icalparser *parser = NULL;
	icalcomponent *comp = NULL;
	gn_error error;

	parser = icalparser_new();
	if (!parser) {
		return GN_ERR_FAILED;
	}

	icalparser_set_gen_data(parser, f);

	comp = icalparser_parse(parser, ical_fgets);
	if (!comp) {
		icalparser_free(parser);
		return GN_ERR_FAILED;
	}

	error = gn_ical2todo_real(comp, ctodo, id);

	icalcomponent_free(comp);
	icalparser_free(parser);

	return error;
#else
	return GN_ERR_NOTIMPLEMENTED;
#endif /* HAVE_LIBICAL */
}
icalcomponent* icalparser_parse_string(const char* str)
{
    icalcomponent *c;
    struct slg_data d;
    icalparser *p;

    icalerrorstate es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR);

    d.pos = 0;
    d.str = str;

    p = icalparser_new();
    icalparser_set_gen_data(p,&d);

    icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL);

    c = icalparser_parse(p,icalparser_string_line_generator);

    icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es);

    icalparser_free(p);

    return c;

}
/** Loads the builtin VTIMEZONE data for the given timezone. */
static void
icaltimezone_load_builtin_timezone	(icaltimezone	*zone)
{
    char *filename;
    unsigned int filename_len;
    FILE *fp;
    icalparser *parser;
    icalcomponent *comp, *subcomp;

	    /* If the location isn't set, it isn't a builtin timezone. */
    if (!zone->location || !zone->location[0])
	return;

    filename_len = strlen (get_zone_directory()) + strlen (zone->location) + 6;

    filename = (char*) malloc (filename_len);
    if (!filename) {
	icalerror_set_errno(ICAL_NEWFAILED_ERROR);
	return;
    }

    snprintf (filename, filename_len, "%s/%s.ics", get_zone_directory(),
	      zone->location);

    fp = fopen (filename, "r");
    free (filename);
    if (!fp) {
	icalerror_set_errno(ICAL_FILE_ERROR);
	return;
    }

	
	/* ##### B.# Sun, 11 Nov 2001 04:04:29 +1100 
	this is where the MALFORMEDDATA error is being set, after the call to 'icalparser_parse'
	fprintf(stderr, "** WARNING ** %s: %d %s\n", __FILE__, __LINE__, icalerror_strerror(icalerrno));
	*/

    parser = icalparser_new ();
	icalparser_set_gen_data (parser, fp);
	comp = icalparser_parse (parser, icaltimezone_load_get_line_fn);
    icalparser_free (parser);
	fclose (fp);

	
	
    /* Find the VTIMEZONE component inside the VCALENDAR. There should be 1. */
    subcomp = icalcomponent_get_first_component (comp,
						 ICAL_VTIMEZONE_COMPONENT);
    if (!subcomp) {
	icalerror_set_errno(ICAL_PARSE_ERROR);
	return;
    }

    icaltimezone_get_vtimezone_properties (zone, subcomp);

	icalcomponent_remove_component(comp,subcomp);

	icalcomponent_free(comp);

}
Example #6
0
void MainWindow::loadFromIcsFile()
{
    char* line;
    icalcomponent *c;
    icalparser *parser = icalparser_new();

    FILE* stream = fopen("/home/quentin/Public/test.ics", "r");

    icalparser_set_gen_data(parser, stream);

    do
    {
        line = icalparser_get_line(parser, read_stream);
        c = icalparser_add_line(parser, line);

        if (c != 0)
        {
            icalcomponent *inner = icalcomponent_get_first_component(c, ICAL_ANY_COMPONENT);
            while (inner != NULL)
            {
                if (icalcomponent_isa(inner) == ICAL_VTODO_COMPONENT)
                {
                    const char* name   = icalcomponent_get_summary(inner);
                    const char* uid    = icalcomponent_get_uid(inner);
                    icalproperty *p    = icalcomponent_get_first_property(inner, ICAL_RELATEDTO_PROPERTY);
                    const char* parent = icalproperty_get_relatedto(p);
                    addTask(name, uid, parent);
                }
                if (icalcomponent_isa(inner) == ICAL_VEVENT_COMPONENT)
                {
                    const char* name   = icalcomponent_get_summary(inner);
                    const char* uid    = icalcomponent_get_uid(inner);
                    icalproperty *p    = icalcomponent_get_first_property(inner, ICAL_RELATEDTO_PROPERTY);
                    const char* parent = icalproperty_get_relatedto(p);
                    p                  = icalcomponent_get_first_property(inner, ICAL_DTSTART_PROPERTY);
                    icaltimetype start = icalproperty_get_dtstart(p);
                    p                  = icalcomponent_get_first_property(inner, ICAL_DTEND_PROPERTY);
                    icaltimetype end   = icalproperty_get_dtend(p);
                    Task* task         = findTask(parent);
                    addEvent(task, uid, name, start, end);
                }
                inner = icalcomponent_get_next_component(c, ICAL_ANY_COMPONENT);
            }
        }

    } while (line != 0);
}
Example #7
0
void parse_text(int argc, char *argv[])
{

    char *line;
    FILE *stream;
    icalcomponent *c;

    /* Create a new parser object */
    icalparser *parser = icalparser_new();

    stream = fopen(argv[1], "r");

    assert(stream != 0);

    /* Tell the parser what input routie it should use. */
    icalparser_set_gen_data(parser, stream);

    do
    {

        /* Get a single content line by making one or more calls to
               read_stream()*/
        line = icalparser_get_line(parser, read_stream);

        /* Now, add that line into the parser object. If that line
               completes a component, c will be non-zero */
        c = icalparser_add_line(parser, line);


        if(c != 0)
        {
            printf("%s", icalcomponent_as_ical_string(c));

            printf("\n---------------\n");

            icalcomponent_free(c);
        }

    }
    while(line != 0);


    icalparser_free(parser);
}
Example #8
0
/**
 * e_cal_util_parse_ics_file:
 * @filename: Name of the file to be parsed.
 *
 * Parses the given file, and, if it contains a valid iCalendar object,
 * parse it and return a new #icalcomponent.
 *
 * Returns: a newly created #icalcomponent or NULL if the file doesn't
 * contain a valid iCalendar object.
 */
icalcomponent *
e_cal_util_parse_ics_file (const gchar *filename)
{
	icalparser *parser;
	icalcomponent *icalcomp;
	FILE *file;

	file = g_fopen (filename, "rb");
	if (!file)
		return NULL;

	parser = icalparser_new ();
	icalparser_set_gen_data (parser, file);

	icalcomp = icalparser_parse (parser, get_line_fn);
	icalparser_free (parser);
	fclose (file);

	return icalcomp;
}
Example #9
0
int main(int argc, char *argv[])
{
    char *line;
    FILE *stream;
    icalcomponent *c;
    icalparser *parser = icalparser_new();

    if (argc != 2) {
        fprintf(stderr, "Usage: parser [file.ics]\n");
        return 0;
    }
    stream = fopen(argv[1], "r");
    if (stream == (FILE *) NULL) {
        fprintf(stderr, "Cannot open file \"%s\" for reading\n", argv[1]);
        return 1;
    }

    icalparser_set_gen_data(parser, stream);

    do {

        line = icalparser_get_line(parser, read_stream);

        c = icalparser_add_line(parser, line);
        icalmemory_free_buffer(line);

        if (c != 0) {
            /*icalcomponent_convert_errors(c); */
            printf("%s", icalcomponent_as_ical_string(c));
            printf("\n---------------\n");
            icalcomponent_free(c);
        }

    } while (line != 0);

    icalparser_free(parser);
    fclose(stream);

    return 0;
}
Example #10
0
gint
ics_parse_file (struct ics_file *file_entry, gchar *name, gchar *filename, gboolean desc_flag, 
                gboolean count_only, GUI *appGUI) {

FILE *ics_stream;
icalparser *ics_parser;
icalcomponent *ics_component;
icalcomponent *h, *l;
icalproperty *p, *r;
struct icaltimetype tt;
struct ics_entry *item;
gint n = 0;

	ics_parser = icalparser_new ();
	g_return_val_if_fail (ics_parser != NULL, n);

	ics_stream = fopen (filename, "r");

	if (ics_stream == NULL) {
		icalparser_free (ics_parser);
		return n;
	}

	icalparser_set_gen_data (ics_parser, ics_stream);
	ics_component = icalparser_parse (ics_parser, ics_read_stream);

	if (ics_component == NULL) {
		fclose (ics_stream);
		icalparser_free (ics_parser);
		return n;
	}

	/* FIXME */
	if (icalcomponent_get_first_component (ics_component, ICAL_VEVENT_COMPONENT) != NULL) {

		for (h = icalcomponent_get_first_component (ics_component, ICAL_VEVENT_COMPONENT); h;
			 h = icalcomponent_get_next_component (ics_component, ICAL_VEVENT_COMPONENT)) {

			p = icalcomponent_get_first_property (h, ICAL_DTSTART_PROPERTY);
			tt = icaltime_from_string (icalproperty_get_value_as_string (p));

				p = icalcomponent_get_first_property (h, ICAL_SUMMARY_PROPERTY);
				if (p != NULL && count_only == FALSE) {
					r = icalcomponent_get_first_property (h, ICAL_DESCRIPTION_PROPERTY);

					item = g_malloc (sizeof (struct ics_entry));

					if (item != NULL) {

						item->date.day = tt.day;
						item->date.month = tt.month;
						item->date.year = tt.year;
						item->summary = g_strdup (icalproperty_get_value_as_string (p));

						if (r != NULL) {
							item->description = g_strdup (icalproperty_get_value_as_string (r));
						} else {
							item->description = NULL;
						}

						file_entry->entries_list = g_slist_append (file_entry->entries_list, item);
					}
				}
			n++;
		}

	} else if (icalcomponent_get_first_component (ics_component, ICAL_VCALENDAR_COMPONENT) != NULL) {

		for (l = icalcomponent_get_first_component (ics_component, ICAL_VCALENDAR_COMPONENT); l;
			 l = icalcomponent_get_next_component (ics_component, ICAL_VCALENDAR_COMPONENT)) {

			h = icalcomponent_get_first_component (l, ICAL_VEVENT_COMPONENT);
			p = icalcomponent_get_first_property (h, ICAL_DTSTART_PROPERTY);
			tt = icaltime_from_string (icalproperty_get_value_as_string (p));

				p = icalcomponent_get_first_property (h, ICAL_SUMMARY_PROPERTY);
				if (p != NULL && count_only == FALSE) {
					r = icalcomponent_get_first_property (h, ICAL_DESCRIPTION_PROPERTY);

					item = g_malloc (sizeof (struct ics_entry));

					if (item != NULL) {

						item->date.day = tt.day;
						item->date.month = tt.month;
						item->date.year = tt.year;
						item->summary = g_strdup (icalproperty_get_value_as_string(p));

						if (r != NULL) {
							item->description = g_strdup (icalproperty_get_value_as_string (r));
						} else {
							item->description = NULL;
						}

						file_entry->entries_list = g_slist_append (file_entry->entries_list, item);
					}
				}
			n++;
		}
	}

	icalcomponent_free (ics_component);
	fclose (ics_stream);
	icalparser_free (ics_parser);

	return n;
}