Beispiel #1
0
DLLEXPORT(void) cleanVObject(VObject *o)
{
    if (o == 0) return;
    if (o->prop) {
	/* destroy time: cannot use the iterator here.
	   Have to break the cycle in the circular link
	   list and turns it into regular NULL-terminated
	   list -- since at some point of destruction,
	   the reference entry for the iterator to work
	   will not longer be valid.
	   */
	VObject *p;
	p = o->prop->next;
	o->prop->next = 0;
	do {
	   VObject *t = p->next;
	   cleanVObject(p);
	   p = t;
	   } while (p);
	}
    switch (VALUE_TYPE(o)) {
	case VCVT_STRINGZ:
	case VCVT_RAW:
	    // assume they are all allocated by malloc.
	    free((char*)STRINGZ_VALUE_OF(o));
	    break;
	case VCVT_VOBJECT:
	    cleanVObject(VOBJECT_VALUE_OF(o));
	    break;
	}
    deleteVObject(o);
}
NS_IMETHODIMP nsAbManager::EscapedVCardToAbCard(const char *aEscapedVCardStr, nsIAbCard **aCard)
{
    NS_ENSURE_ARG_POINTER(aEscapedVCardStr);
    NS_ENSURE_ARG_POINTER(aCard);

    nsCOMPtr <nsIAbCard> cardFromVCard = do_CreateInstance(NS_ABCARDPROPERTY_CONTRACTID);
    if (!cardFromVCard)
        return NS_ERROR_FAILURE;

    // aEscapedVCardStr will be "" the first time, before you have a vCard
    if (*aEscapedVCardStr != '\0') {
        nsCString unescapedData;
        MsgUnescapeString(nsDependentCString(aEscapedVCardStr), 0, unescapedData);

        VObject *vObj = parse_MIME(unescapedData.get(), unescapedData.Length());
        if (vObj)
        {
          convertFromVObject(vObj, cardFromVCard);

          cleanVObject(vObj);
        }
        else
          NS_WARNING("Parse of vCard failed");
    }

    NS_IF_ADDREF(*aCard = cardFromVCard);
    return NS_OK;
}
bool ODateBookAccessBackend_VCal::save() {
    if (!m_changed)
        return true;

    QFile file( m_file );
    if (!file.open(IO_WriteOnly ) )
        return false;

    VObject *obj;
    obj = newVObject( VCCalProp );
    addPropValue( obj, VCVersionProp, "1.0" );
    VObject *vo;
    for(QMap<int, OPimEvent>::ConstIterator it=m_raw.begin(); it !=m_raw.end(); ++it ){
        vo = createVObject( it.data() );
        addVObjectProp(obj, vo );
    }
    for(QMap<int, OPimEvent>::ConstIterator it=m_rep.begin(); it !=m_rep.end(); ++it ){
        vo = createVObject( it.data() );
        addVObjectProp(obj, vo );
    }
    writeVObject( file.fh, obj ); //FIXME: HACK!!!
    cleanVObject( obj );
    cleanStrTbl();

    m_changed = false;
    return true;
}
bool OContactAccessBackend_VCard::save()
{
    if (!m_dirty )
        return true;

    QFileDirect file( m_file );
    if (!file.open(IO_WriteOnly ) )
        return false;

    VObject *obj;
    obj = newVObject( VCCalProp );
    addPropValue( obj, VCVersionProp, "1.0" );

    VObject *vo;
    for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ) {
        vo = createVObject( *it );
        writeVObject( file.directHandle() , vo );
        cleanVObject( vo );
    }
    cleanStrTbl();
    deleteVObject( obj );

    m_dirty = false;
    return true;


}
/* This tries to load in a vCalendar file and convert it to an icalcomponent.
 * It returns NULL on failure. */
static icalcomponent *
load_vcalendar_file (const gchar *filename)
{
	icalvcal_defaults defaults = { NULL };
	icalcomponent *icalcomp = NULL;
	gchar *contents;
	gchar *default_alarm_filename;

	default_alarm_filename = g_build_filename (
		EVOLUTION_SOUNDDIR,
		"default_alarm.wav",
		NULL);
	defaults.alarm_audio_url = g_filename_to_uri (
		default_alarm_filename,
		NULL, NULL);
	g_free (default_alarm_filename);
	defaults.alarm_audio_fmttype = (gchar *) "audio/x-wav";
	defaults.alarm_description = (gchar *) _("Reminder!");

	if (g_file_get_contents (filename, &contents, NULL, NULL)) {
		VObject *vcal;

		/* parse the file */
		vcal = Parse_MIME (contents, strlen (contents));
		g_free (contents);

		if (vcal) {
			icalcomp = icalvcal_convert_with_defaults (
				vcal, &defaults);
			cleanVObject (vcal);
		}
	}

	return icalcomp;
}
Beispiel #6
0
DLLEXPORT(void) cleanVObjects(VObject *list)
{
    while (list) {
	VObject *t = list;
	list = nextVObjectInList(list);
	cleanVObject(t);
	}
}
bool OContactAccessBackend_VCard::load ()
{
    m_map.clear();
    m_dirty = false;

    VObject* obj = 0l;

    if ( QFile::exists(m_file) ) {
        obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
        if ( !obj )
            return false;
    } else {
        qWarning("File \"%s\" not found !", m_file.latin1() );
        return false;
    }

    while ( obj ) {
        OContact con = parseVObject( obj );
        /*
         * if uid is 0 assign a new one
         * this at least happens on
         * Nokia6210
         */
        if ( con.uid() == 0 ) {
            con.setUid( 1 );
            qWarning("assigned new uid %d",con.uid() );
        }

        m_map.insert( con.uid(), con );

        VObject *t = obj;
        obj = nextVObjectInList(obj);
        cleanVObject( t );
    }

    return true;

}
Beispiel #8
0
bool OPimTodoAccessVCal::save()
{
    if (!m_dirty )
        return true;

    QFile file( m_file );
    if (!file.open(IO_WriteOnly ) )
        return false;

    VObject *obj;
    obj = newVObject( VCCalProp );
    addPropValue( obj, VCVersionProp, "1.0" );
    VObject *vo;
    for(QMap<int, OPimTodo>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){
        vo = vobjByEvent( it.data() );
        addVObjectProp(obj, vo );
    }
    writeVObject( file.fh, obj ); //FIXME: HACK!!!
    cleanVObject( obj );
    cleanStrTbl();

    m_dirty = false;
    return true;
}
static gboolean
vcal_supported (EImport *ei,
                EImportTarget *target,
                EImportImporter *im)
{
	gchar *filename;
	gchar *contents;
	gboolean ret = FALSE;
	EImportTargetURI *s;

	if (target->type != E_IMPORT_TARGET_URI)
		return FALSE;

	s = (EImportTargetURI *) target;
	if (s->uri_src == NULL)
		return TRUE;

	if (strncmp (s->uri_src, "file:///", 8) != 0)
		return FALSE;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (!filename)
		return FALSE;

	/* Z: Wow, this is *efficient* */

	if (g_file_get_contents (filename, &contents, NULL, NULL)) {
		VObject *vcal;
		icalcomponent *icalcomp;

		icalcomp = e_cal_util_parse_ics_string (contents);

		if (icalcomp && is_icalcomp_usable (icalcomp)) {
			/* If we can create proper iCalendar from the file, then
			 * rather use ics importer, because it knows to read more
			 * information than older version, the vCalendar. */
			ret = FALSE;
			g_free (contents);
		} else {
			if (icalcomp)
				icalcomponent_free (icalcomp);

			/* parse the file */
			vcal = Parse_MIME (contents, strlen (contents));
			g_free (contents);

			if (vcal) {
				icalcomp = icalvcal_convert (vcal);

				if (icalcomp) {
					icalcomponent_free (icalcomp);
					ret = TRUE;
				}

				cleanVObject (vcal);
			}
		}
	}
	g_free (filename);

	return ret;
}