コード例 #1
0
ファイル: bongo-import-tz.c プロジェクト: bongo-project/bongo
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;
}
コード例 #2
0
ファイル: vcal.c プロジェクト: ihipop/I-GNOKII
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 */
}
コード例 #3
0
ファイル: vcal.c プロジェクト: ihipop/I-GNOKII
GNOKII_API int gn_icalstr2todo(const char * ical, 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;
	}

	comp = icalparser_parse_string (ical);
	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 */
}
コード例 #4
0
ファイル: vcal.c プロジェクト: ihipop/I-GNOKII
/* 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 */
}
コード例 #5
0
ファイル: vcal.c プロジェクト: ihipop/I-GNOKII
/* read a vcalendar event given by id from string ical and store the data in calnote */
GNOKII_API gn_error gn_icalstr2calnote(const char * ical, 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;
	}

	comp = icalparser_parse_string (ical);
	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 */
}
コード例 #6
0
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;

}
コード例 #7
0
/** 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);

}
コード例 #8
0
ファイル: mainwindow.cpp プロジェクト: pyridiss/Sablier
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);
}
コード例 #9
0
int main(int argc, char* argv[])
{
    char* line; 
    FILE* stream;
    icalcomponent *c; 
    icalparser *parser = icalparser_new();



long lSize;
char *buffer;
//while (__AFL_LOOP(1000)){
    stream = fopen(argv[1],"r");
fseek( stream , 0L , SEEK_END);
lSize = ftell( stream );
rewind( stream );

/* allocate memory for entire content */
buffer = calloc( 1, lSize+1 );
if( !buffer ) fclose(stream),fputs("memory alloc fails",stderr),exit(1);

/* copy the file into the buffer */
if( 1!=fread( buffer , lSize, 1 , stream) )
  fclose(stream),free(buffer),fputs("entire read fails",stderr),exit(1);

icalparser_parse_string(buffer);

//    icalparser_set_gen_data(parser,stream);

  //  do{
  // 
//	line = icalparser_get_line(parser,read_stream);

//	c = icalparser_add_line(parser,line);

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

  //  } while ( line != 0);
//}
    return 0;
 }
コード例 #10
0
ファイル: parse_text.c プロジェクト: serghei/kde3-kdepim
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);
}
コード例 #11
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;
}
コード例 #12
0
ファイル: icaltestparser.c プロジェクト: cyrusimap/libical
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;
}
コード例 #13
0
ファイル: calendar_ical.c プロジェクト: rosedu/osmo
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;
}
コード例 #14
0
ファイル: dates_callbacks.c プロジェクト: GNOME/dates
gboolean
dates_import_calendar_data_from_file (ECal *cal, gchar *filename, GError **error)
{
  GError *tmp_error = NULL;
  GIOChannel *channel = NULL;
  gchar *line;
  gsize length;
  gint num_comp_imported = 0;

  channel = g_io_channel_new_file (filename, "r", &tmp_error);

  if (tmp_error != NULL)
  {
    g_warning ("Error when opening file: %s", tmp_error->message);
    g_propagate_error (error, tmp_error);
    return FALSE;
  } else {
    GIOStatus status;
    icalparser *parser = icalparser_new ();

    /* set the channel as binary mode and let icalparser_add_line
     * handle encoding */
    g_io_channel_set_encoding (channel, NULL, &tmp_error);
    if (tmp_error != NULL)
    {
      g_warning ("Error when set encoding: %s", tmp_error->message);
      g_propagate_error (error, tmp_error);
      g_io_channel_unref (channel);
      return FALSE;
    }

    /* Read the from the file line by line and until EOF */
    while ((status = g_io_channel_read_line (channel, &line, &length, NULL, &tmp_error))
        == G_IO_STATUS_NORMAL)
    {
      icalcomponent *icomp = NULL;

      /* The parser returns an icalcomponent when it has one */
      icomp = icalparser_add_line (parser, line);
      g_free (line);

    if (icomp)
      {
        gchar *uid = NULL;
        icalcompiter iter;
        icalcomponent *subcomp;

        /* The component is a top-level one and e_cal_create_object only
         * accepts VEVENTs. Iterate through the VEVENTS. */
        iter = icalcomponent_begin_component (icomp, ICAL_VEVENT_COMPONENT);

        while ((subcomp = icalcompiter_deref (&iter)) != NULL) 
        {
          if (!e_cal_create_object (cal, subcomp, &uid, &tmp_error))
          {
            g_warning ("Creation of imported event failed: %s", tmp_error->message);
            g_propagate_error (error, tmp_error);

            if (parser)
              icalparser_free (parser);

            if (icomp)
              icalcomponent_free (icomp);

            if (channel)
              g_io_channel_unref (channel);

            g_free (uid);
            return FALSE;
          }
					
          num_comp_imported ++;
          
          icalcompiter_next (&iter);
          g_free (uid);
        }

        icalcomponent_free (icomp);
      }
    }

    if (parser)
      icalparser_free (parser);

    if (tmp_error != NULL)
    {
      g_warning ("Error when reading from file: %s", tmp_error->message);
      g_propagate_error (error, tmp_error);

      g_io_channel_unref (channel);
      return FALSE;
    }
  }

  if (channel)
    g_io_channel_unref (channel);
  
  if (num_comp_imported > 0)
  {
    return TRUE;
  }
  else 
  {
    *error = g_error_new_literal
      (g_quark_from_string ("Dates"), 1, _("No calendar events found."));
    return FALSE;
  }
}