also imported the vcardconverter program from the Funambol CVS
git-svn-id: https://zeitsenke.de/svn/SyncEvolution/trunk@144 15ad00c4-1369-45f4-8270-35d70d36bdcd
This commit is contained in:
parent
2384393e85
commit
aaa1b67294
|
@ -14,24 +14,29 @@ synccompare : normalize_vcard.pl
|
|||
cp $< $@
|
||||
chmod u+x $@
|
||||
|
||||
VOCL_SOURCES = \
|
||||
vocl/VObject.h \
|
||||
vocl/VProperty.h \
|
||||
vocl/VConverter.h \
|
||||
vocl/posixadapter.h \
|
||||
\
|
||||
vocl/VObject.cpp \
|
||||
vocl/VProperty.cpp \
|
||||
vocl/VConverter.cpp
|
||||
|
||||
CORE_SOURCES = \
|
||||
EvolutionContactSource.h \
|
||||
EvolutionCalendarSource.h \
|
||||
EvolutionSmartPtr.h \
|
||||
EvolutionSyncClient.h \
|
||||
EvolutionSyncSource.h \
|
||||
vocl/VObject.h \
|
||||
vocl/VProperty.h \
|
||||
vocl/VConverter.h \
|
||||
vocl/posixadapter.h \
|
||||
\
|
||||
EvolutionSyncSource.cpp \
|
||||
EvolutionSyncClient.cpp \
|
||||
EvolutionCalendarSource.cpp \
|
||||
EvolutionContactSource.cpp \
|
||||
vocl/VObject.cpp \
|
||||
vocl/VProperty.cpp \
|
||||
vocl/VConverter.cpp
|
||||
\
|
||||
$(VOCL_SOURCES)
|
||||
|
||||
CORE_LDADD = @EPACKAGE_LIBS@ @SYNC4J_LIBS@ @LIBS@
|
||||
|
||||
|
@ -56,6 +61,13 @@ TestEvolution_CFLAGS = `cppunit-config --cflags`
|
|||
TestEvolution_LDFLAGS = `cppunit-config --libs`
|
||||
TestEvolution_LDADD = $(CORE_LDADD)
|
||||
|
||||
EXTRA_PROGRAMS += vcardconverter
|
||||
vcardconverter_SOURCES = \
|
||||
vocl/vcardconverter.cpp \
|
||||
$(VOCL_SOURCES)
|
||||
vcardconverter_LDADD = $(CORE_LDADD)
|
||||
|
||||
|
||||
# SYNC4J_SUBDIR specifies the directory where we compile
|
||||
# the client library by invoking make there.
|
||||
# Installing its source is done explicitly.
|
||||
|
@ -68,8 +80,9 @@ BUILT_SOURCES = $(SYNC4J_SUBDIR)/all
|
|||
clean distclean mostlyclean distdir maintainer-clean : % : $(SYNC4J_SUBDIR)/%
|
||||
clean : testclean
|
||||
|
||||
TestEvolution syncevolution : $(SYNC4J_SUBDIR)/src/libsync4j.la
|
||||
test : TestEvolution addressbook.tests calendar.tests todo.tests synccompare
|
||||
TestEvolution syncevolution vcardconverter : \
|
||||
$(SYNC4J_SUBDIR)/src/libsync4j.la
|
||||
test : TestEvolution addressbook.tests calendar.tests todo.tests synccompare vcardconverter
|
||||
|
||||
# test files are in CVS under a different name so that they
|
||||
# can be copied to the work directory under the name expected
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2006 Funambol
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* This program reads one vcard from the file
|
||||
* given as first parameter and applies certain
|
||||
* conversions to it.
|
||||
*
|
||||
* The content of the file has to be ASCII or
|
||||
* UTF-8 encoded.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <memory>
|
||||
|
||||
#include "posixadapter.h"
|
||||
#include "VConverter.h"
|
||||
#include "base/util/utils.h"
|
||||
|
||||
using namespace vocl;
|
||||
|
||||
// very simply auto_ptr for arrays
|
||||
template <class T> class auto_array {
|
||||
T *m_array;
|
||||
public:
|
||||
auto_array(T *array = 0) : m_array(array) {}
|
||||
~auto_array() { if (m_array) delete [] m_array; }
|
||||
|
||||
void operator = (T *array) {
|
||||
if (m_array) delete [] m_array;
|
||||
m_array = array;
|
||||
}
|
||||
operator T * () { return m_array; }
|
||||
T *get() { return m_array; }
|
||||
T &operator [] (int index) { return m_array[index]; }
|
||||
};
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
char *sep = TEXT("--------------- %s -----------------------\n");
|
||||
char *sep2 = TEXT("-----------------------------------------------------------\n");
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stdout, "usage: %s <vcard file>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// read as char *
|
||||
char *buffer;
|
||||
size_t len;
|
||||
if (!readFile(argv[1], &buffer, &len, true)) {
|
||||
fprintf(stdout, "%s: reading failed", argv[1]);
|
||||
}
|
||||
auto_array<char> vcard(buffer);
|
||||
|
||||
// convert to wchar_t
|
||||
auto_array<wchar_t> wvcard(toWideChar(vcard));
|
||||
fwprintf(stdout, sep, TEXT("original vcard"));
|
||||
fwprintf(stdout, TEXT("%s\n"), wvcard.get());
|
||||
fwprintf(stdout, sep2);
|
||||
fwprintf(stdout, TEXT("\n"));
|
||||
|
||||
// parse it
|
||||
std::auto_ptr<VObject> vobj(VConverter::parse(wvcard));
|
||||
if (vobj.get() == 0) {
|
||||
fprintf(stdout, "VConverter::parse()failed\n");
|
||||
return 1;
|
||||
}
|
||||
vobj->toNativeEncoding();
|
||||
|
||||
VProperty *fileas = vobj->getProperty(TEXT("X-EVOLUTION-FILE-AS"));
|
||||
VProperty *n = vobj->getProperty(TEXT("FN"));
|
||||
fwprintf(stdout,
|
||||
TEXT("version: %s\nprodid: %s\nfull name: %s\nfile-as: %s\n\n"),
|
||||
vobj->getVersion(),
|
||||
vobj->getProdID(),
|
||||
n ? n->getValue() : TEXT("<not set>"),
|
||||
fileas ? fileas->getValue() : TEXT("<not set>"));
|
||||
|
||||
// convert into the other version, then back again
|
||||
wchar_t *versions[2];
|
||||
if (!wcscmp(vobj->getVersion(), TEXT("3.0"))) {
|
||||
versions[0] = TEXT("2.1");
|
||||
versions[1] = TEXT("3.0");
|
||||
} else {
|
||||
versions[0] = TEXT("3.0");
|
||||
versions[1] = TEXT("2.1");
|
||||
}
|
||||
for (int index = 0; index < 2; index++) {
|
||||
vobj->setVersion(versions[index]);
|
||||
VProperty *vprop = vobj->getProperty(TEXT("VERSION"));
|
||||
|
||||
for (int property = vobj->propertiesCount() - 1;
|
||||
property >= 0;
|
||||
property--) {
|
||||
VProperty *vprop = vobj->getProperty(property);
|
||||
|
||||
// replace 3.0 ENCODING=B with 2.1 ENCODING=BASE64 and vice versa
|
||||
char *encoding = vprop->getParameterValue("ENCODING");
|
||||
if (encoding &&
|
||||
(!wcsicmp(TEXT("B"), encoding) || !wcsicmp(TEXT("BASE64"), encoding))) {
|
||||
vprop->removeParameter("ENCODING");
|
||||
vprop->addParameter("ENCODING",
|
||||
!wcscmp(versions[index], TEXT("2.1")) ?
|
||||
"BASE64" : "b");
|
||||
}
|
||||
}
|
||||
|
||||
vprop->setValue(versions[index]);
|
||||
vobj->fromNativeEncoding();
|
||||
wvcard = vobj->toString();
|
||||
vobj->toNativeEncoding();
|
||||
fwprintf(stdout, sep, versions[index]);
|
||||
fwprintf(stdout, TEXT("%s\n"), wvcard.get());
|
||||
fwprintf(stdout, sep2);
|
||||
fwprintf(stdout, TEXT("\n"));
|
||||
}
|
||||
|
||||
#if 0
|
||||
// convert into validated contact
|
||||
vCardConverter converter;
|
||||
converter.setSource(wvcard);
|
||||
Contact *contactPtr;
|
||||
long errorCode;
|
||||
if (!converter.convert(lastErrorMsg, &errorCode)) {
|
||||
fwprintf(stdout, TEXT("converter failed: %s (%ld)\n"), lastErrorMsg, errorCode);
|
||||
return 1;
|
||||
}
|
||||
converter.getContact(&contactPtr);
|
||||
std::auto_ptr<Contact> contact(contactPtr);
|
||||
wvcard = contact->toString();
|
||||
fwprintf(stdout, sep, TEXT("after parsing"));
|
||||
fwprintf(stdout, TEXT("%s\n"), wvcard.get());
|
||||
fwprintf(stdout, sep2);
|
||||
fwprintf(stdout, TEXT("\n"));
|
||||
|
||||
// let's see how the Contact class interprets the properties
|
||||
Name *name = contact->getName();
|
||||
vCardProperty *displayname = name->getDisplayName();
|
||||
fwprintf(stdout,
|
||||
TEXT("display name\nencoding: %s\ncharset: %s\nlanguage: %s\nvalue: %s\n\n"),
|
||||
displayname->getEncoding(),
|
||||
displayname->getCharset(),
|
||||
displayname->getLanguage(),
|
||||
displayname->getValue());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue