Checkin for sman. Support for remote CAPI and User def's
git-svn-id: svn://10.0.0.236/trunk@9642 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
0f24b39bdf
commit
0fba81dc0a
90
mozilla/calendar/modules/network/capi/inc/JulianParser.h
Normal file
90
mozilla/calendar/modules/network/capi/inc/JulianParser.h
Normal file
@ -0,0 +1,90 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* jparser.h
|
||||
* John Sun
|
||||
* 4/28/98 10:45:21 AM
|
||||
*/
|
||||
#ifndef __NSQQnsCalStreamReader_H_
|
||||
#define __NSQQnsCalStreamReader_H_
|
||||
|
||||
#include "ptrarray.h"
|
||||
#include "icalredr.h"
|
||||
#include "nsCapiCallbackReader.h"
|
||||
#include "jutility.h"
|
||||
#include "nspr.h"
|
||||
|
||||
/**
|
||||
* This class will be removed later. It is a hack I created to
|
||||
* parse the MIME-message from the CS&T server fetch results.
|
||||
* I will try to extract the iCalendar information from it.
|
||||
* I will need to handle multi-threaded parsing somehow as well.
|
||||
*/
|
||||
class nsCalStreamReader
|
||||
{
|
||||
private:
|
||||
/*char * m_Buffer;*/
|
||||
|
||||
static JulianUtility::MimeEncoding stringToEncodingType(UnicodeString & propVal);
|
||||
|
||||
JulianPtrArray * m_OutCalendars;
|
||||
nsCapiCallbackReader * m_Reader;
|
||||
t_bool m_bParseStarted;
|
||||
t_bool m_bParseFinished;
|
||||
PRThread * m_Thread;
|
||||
|
||||
public:
|
||||
nsCalStreamReader();
|
||||
nsCalStreamReader(nsCapiCallbackReader * reader, JulianPtrArray * outCalendars,
|
||||
PRThread * thread);
|
||||
/*
|
||||
void setBuffer(char * buf)
|
||||
{
|
||||
strcat(m_Buffer, buf);
|
||||
}
|
||||
*/
|
||||
|
||||
t_bool isParseStarted() const { return m_bParseStarted; }
|
||||
void setParseStarted() { m_bParseStarted = TRUE; }
|
||||
|
||||
t_bool isParseFinished() const { return m_bParseFinished; }
|
||||
void setParseFinished() { m_bParseFinished = TRUE; }
|
||||
|
||||
nsCapiCallbackReader * getReader() const { return m_Reader; }
|
||||
PRThread * getThread() const { return m_Thread; }
|
||||
|
||||
void ParseCalendars(ICalReader * reader,
|
||||
JulianPtrArray * outCalendars);
|
||||
|
||||
void ParseCalendars();
|
||||
|
||||
};
|
||||
|
||||
#ifdef XP_CPLUSPLUS
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
void jparser_ParseCalendarsZero(void * jp, void *);
|
||||
|
||||
#ifdef XP_CPLUSPLUS
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* __NSQQnsCalStreamReader_H_ */
|
||||
|
||||
@ -15,6 +15,10 @@ EXPORTS = \
|
||||
PRIVATE_EXPORTS = \
|
||||
nsCapiLocal.h \
|
||||
nsCapiCST.h \
|
||||
JulianParser.h \
|
||||
nsCalStreamReader.h \
|
||||
nsCapiCallbackReader.h \
|
||||
nscapiexport.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = trex
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __NSQQnsCalStreamReader_H_
|
||||
#define __NSQQnsCalStreamReader_H_
|
||||
|
||||
#include "nscapiexport.h"
|
||||
#include "ptrarray.h"
|
||||
#include "icalredr.h"
|
||||
#include "nsCapiCallbackReader.h"
|
||||
#include "jutility.h"
|
||||
#include "nspr.h"
|
||||
|
||||
/**
|
||||
* This class will be removed later. It is a hack I created to
|
||||
* parse the MIME-message from the CS&T server fetch results.
|
||||
* I will try to extract the iCalendar information from it.
|
||||
* I will need to handle multi-threaded parsing somehow as well.
|
||||
*/
|
||||
CLASS_EXPORT_CAPI nsCalStreamReader
|
||||
{
|
||||
private:
|
||||
static JulianUtility::MimeEncoding stringToEncodingType(UnicodeString & propVal);
|
||||
|
||||
JulianPtrArray * m_OutCalendars;
|
||||
nsCapiCallbackReader * m_Reader;
|
||||
t_bool m_bParseStarted;
|
||||
t_bool m_bParseFinished;
|
||||
PRThread * m_Thread;
|
||||
void * m_CallerData;
|
||||
|
||||
public:
|
||||
nsCalStreamReader();
|
||||
nsCalStreamReader(
|
||||
nsCapiCallbackReader * reader,
|
||||
JulianPtrArray * outCalendars,
|
||||
PRThread * thread,
|
||||
void* condvar);
|
||||
t_bool isParseStarted() const { return m_bParseStarted; }
|
||||
void setParseStarted() { m_bParseStarted = TRUE; }
|
||||
|
||||
t_bool isParseFinished() const { return m_bParseFinished; }
|
||||
void setParseFinished() { m_bParseFinished = TRUE; }
|
||||
|
||||
nsCapiCallbackReader * getReader() const { return m_Reader; }
|
||||
PRThread * getThread() const { return m_Thread; }
|
||||
void * getCallerData() const { return m_CallerData; }
|
||||
|
||||
void ParseCalendars(
|
||||
ICalReader * reader,
|
||||
JulianPtrArray * outCalendars);
|
||||
|
||||
void ParseCalendars();
|
||||
};
|
||||
|
||||
#ifdef XP_CPLUSPLUS
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
void NS_CAPIEXPORT main_CalStreamReader(void * jp);
|
||||
|
||||
#ifdef XP_CPLUSPLUS
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* __NSQQnsCalStreamReader_H_ */
|
||||
|
||||
165
mozilla/calendar/modules/network/capi/inc/nsCapiCallbackReader.h
Normal file
165
mozilla/calendar/modules/network/capi/inc/nsCapiCallbackReader.h
Normal file
@ -0,0 +1,165 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* capiredr.h
|
||||
* John Sun
|
||||
* 4/16/98 3:31:51 PM
|
||||
*/
|
||||
#ifndef __NSQQnsCapiCallbackReader_H_
|
||||
#define __NSQQnsCapiCallbackReader_H_
|
||||
|
||||
#include "nscapiexport.h"
|
||||
#include "jdefines.h"
|
||||
#include <unistring.h>
|
||||
#include "ptrarray.h"
|
||||
#include "icalredr.h"
|
||||
#include "prmon.h"
|
||||
#include "jutility.h"
|
||||
/**
|
||||
* nsCapiCallbackReader is a subclass of ICalReader. It implements
|
||||
* the ICalReader interface to work with CAPI callback method
|
||||
* to parse from stream.
|
||||
* Uses multiple threads.
|
||||
*/
|
||||
CLASS_EXPORT_CAPI nsCapiCallbackReader
|
||||
{
|
||||
private:
|
||||
/*-----------------------------
|
||||
** MEMBERS
|
||||
**---------------------------*/
|
||||
/* current buffer of iCal information,
|
||||
* when CAPI has information to return to
|
||||
* the buffer, it must append to this buffer
|
||||
* when no more full-lines can be made from the
|
||||
* buffer, block on the monitor. Will be
|
||||
* notified when CAPI gets back more information
|
||||
*/
|
||||
char * m_Buffer;
|
||||
t_int32 m_BufferSize;
|
||||
t_bool m_Init;
|
||||
t_int32 m_Mark;
|
||||
t_int32 m_ChunkMark;
|
||||
t_int32 m_Pos;
|
||||
t_int32 m_ChunkIndex;
|
||||
|
||||
/** encoding of stream */
|
||||
JulianUtility::MimeEncoding m_Encoding;
|
||||
|
||||
JulianPtrArray * m_Chunks;
|
||||
|
||||
static const t_int32 m_MAXBUFFERSIZE;
|
||||
static const t_int32 m_NOMORECHUNKS;
|
||||
|
||||
/* finished getting input from CAPI callback */
|
||||
t_bool m_bFinished;
|
||||
|
||||
PRMonitor * m_Monitor;
|
||||
/*-----------------------------
|
||||
** PRIVATE METHODS
|
||||
**---------------------------*/
|
||||
|
||||
UnicodeString & createLine(t_int32 oldPos, t_int32 oldChunkIndex,
|
||||
t_int32 newPos, t_int32 newChunkIndex, UnicodeString & aLine);
|
||||
|
||||
static void deleteUnicodeStringVector(JulianPtrArray * stringVector);
|
||||
|
||||
nsCapiCallbackReader();
|
||||
public:
|
||||
/*-----------------------------
|
||||
** CONSTRUCTORS and DESTRUCTORS
|
||||
**---------------------------*/
|
||||
nsCapiCallbackReader(PRMonitor * monitor,
|
||||
JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit);
|
||||
~nsCapiCallbackReader();
|
||||
|
||||
/*-----------------------------
|
||||
** ACCESSORS (GET AND SET)
|
||||
**---------------------------*/
|
||||
|
||||
virtual void * getMonitor() { return m_Monitor; }
|
||||
|
||||
void setFinished() { m_bFinished = TRUE; }
|
||||
void setEncoding(JulianUtility::MimeEncoding encoding) { m_Encoding = encoding; }
|
||||
t_bool isFinished() const { return m_bFinished; }
|
||||
/**
|
||||
* Sets a the buffer to read from.
|
||||
* Appends the m_Buffer.
|
||||
*/
|
||||
/*virtual void setBuffer(const char * capiChunk);*/
|
||||
|
||||
|
||||
/**
|
||||
* Don't delete u until this object is deleted.
|
||||
* @param UnicodeString * u
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void AddChunk(UnicodeString * u);
|
||||
|
||||
/*-----------------------------
|
||||
** UTILITIES
|
||||
**---------------------------*/
|
||||
|
||||
void mark() { m_Mark = m_Pos; m_ChunkMark = m_ChunkIndex;}
|
||||
|
||||
void reset() { m_Pos = m_Mark; m_ChunkIndex = m_ChunkMark;}
|
||||
|
||||
/**
|
||||
* Read next character from file.
|
||||
*
|
||||
* @param status, return 1 if no more characters
|
||||
* @return next character of string
|
||||
*/
|
||||
virtual t_int8 read(ErrorCode & status);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read the next ICAL full line of the file. The definition
|
||||
* of a full ICAL line can be found in the ICAL spec.
|
||||
* Basically, a line followed by a CRLF and a space character
|
||||
* signifies that the next line is a continuation of the previous line.
|
||||
* Uses the readLine, read methods.
|
||||
*
|
||||
* @param aLine, returns next full line of string
|
||||
* @param status, return 1 if no more lines
|
||||
*
|
||||
* @return next full line of string
|
||||
*/
|
||||
virtual UnicodeString & readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 i = 0);
|
||||
|
||||
/**
|
||||
* Read next line of file. A line is defined to be
|
||||
* characters terminated by either a '\n', '\r' or "\r\n".
|
||||
* @param aLine, return next line of string
|
||||
* @param status, return 1 if no more lines
|
||||
*
|
||||
* @return next line of string
|
||||
*/
|
||||
virtual UnicodeString & readLine(UnicodeString & aLine, ErrorCode & status);
|
||||
public:
|
||||
|
||||
/*virtual UnicodeString & readLineZero(UnicodeString & aLine, ErrorCode & status);*/
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* __NSQQnsCapiCallbackReader_H_ */
|
||||
|
||||
43
mozilla/calendar/modules/network/capi/inc/nscapiexport.h
Normal file
43
mozilla/calendar/modules/network/capi/inc/nscapiexport.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* MODULE NOTES:
|
||||
* @update gess 4/1/98
|
||||
*/
|
||||
|
||||
#ifndef nscapiexport_h___
|
||||
#define nscapiexport_h___
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#ifdef _IMPL_NS_CAPI
|
||||
#define NS_CAPIEXPORT NS_EXPORT
|
||||
#else
|
||||
#define NS_CAPIEXPORT NS_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(XP_MAC)
|
||||
#define CLASS_EXPORT_CAPI NS_CAPIEXPORT class
|
||||
#else
|
||||
#define CLASS_EXPORT_CAPI class NS_CAPIEXPORT
|
||||
#endif
|
||||
|
||||
#endif /* nscapiexport_h___ */
|
||||
|
||||
|
||||
@ -130,6 +130,51 @@ void *CAPI_memset( void *dest, int c, size_t count )
|
||||
return memset(dest,c,count);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/**
|
||||
* This is a useful piece of code but it's in the wrong
|
||||
* place. Given a path, it ensures that the path exists, creating
|
||||
* whatever needs to be created.
|
||||
* @return 0 on success
|
||||
* file creation errors otherwise.
|
||||
*/
|
||||
PRInt32 CAPI_EnsureUserPath( JulianString& sPath )
|
||||
{
|
||||
JulianString sTmp;
|
||||
PRInt32 i;
|
||||
nsCurlParser::ConvertToFileChars(sPath);
|
||||
for (i = 0; -1 != (i = sPath.Strpbrk(i,"/\\")); i++ )
|
||||
{
|
||||
sTmp = sPath.Left(i);
|
||||
if (PR_SUCCESS != PR_Access(sTmp.GetBuffer(), PR_ACCESS_EXISTS))
|
||||
{
|
||||
/*
|
||||
* Try to create it...
|
||||
*/
|
||||
if (PR_SUCCESS != PR_MkDir(sTmp.GetBuffer(),PR_RDWR))
|
||||
{
|
||||
PRInt32 iError = PR_GetError();
|
||||
return iError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* OK, the path was there or it has been created. Now make
|
||||
* sure we can write to it.
|
||||
*/
|
||||
if (PR_SUCCESS != PR_Access(sPath.GetBuffer(), PR_ACCESS_WRITE_OK))
|
||||
{
|
||||
PRInt32 iError = PR_GetError();
|
||||
return iError;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************************************************
|
||||
*** MIME / ICAL ASSEMBLY FUNCTIONS
|
||||
*****************************************************************/
|
||||
@ -627,7 +672,7 @@ CAPIStatus CAPI_FetchEventsByRange(
|
||||
int32 j = 0;
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
UnicodeString uFilename = "calendar.ics";
|
||||
UnicodeString uFilename;
|
||||
UnicodeString uTemp;
|
||||
|
||||
if (0 == pSession)
|
||||
@ -822,6 +867,12 @@ CAPIStatus CAPI_FetchEventsByRange(
|
||||
pCopy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Signal the end of transmission...
|
||||
*/
|
||||
(*pStream->pfnRcvCallback)(pStream->userDataRcv,p,0,&iAmountHandled);
|
||||
|
||||
}
|
||||
|
||||
FBRANGE_EXIT:
|
||||
@ -833,6 +884,7 @@ FBRANGE_EXIT:
|
||||
delete pRedr;
|
||||
if (0 != pCopy)
|
||||
delete pCopy;
|
||||
|
||||
return iRetStatus;
|
||||
}
|
||||
|
||||
@ -853,7 +905,7 @@ CAPIStatus CAPI_GetHandle(
|
||||
*pH = 0;
|
||||
if (0 == pHandle)
|
||||
return CAPI_ERR_NO_MEMORY;
|
||||
pHandle->psFile = CAPI_strdup(u);
|
||||
|
||||
pHandle->pSession = pSession;
|
||||
pHandle->pCurl = new nsCurlParser(u);
|
||||
|
||||
@ -863,6 +915,19 @@ CAPIStatus CAPI_GetHandle(
|
||||
*/
|
||||
*pHandle->pCurl |= *pSession->pCurl;
|
||||
|
||||
char* psLocalFile = pHandle->pCurl->ToLocalFile();
|
||||
pHandle->psFile = CAPI_strdup(psLocalFile);
|
||||
PR_Free(psLocalFile);
|
||||
|
||||
JulianString sPath = pHandle->pCurl->CSIDPath();
|
||||
if (NS_OK != CAPI_EnsureUserPath( sPath ))
|
||||
{
|
||||
// XXX do some error thing here...
|
||||
// we should probably pop up a file dialog and let
|
||||
// the user point us to a path to use.
|
||||
return 1;
|
||||
}
|
||||
|
||||
*pH = pHandle;
|
||||
return CAPI_ERR_OK;
|
||||
}
|
||||
@ -963,7 +1028,7 @@ CAPIStatus CAPI_SetStreamCallbacks (
|
||||
PCAPISESSION *pSession = (PCAPISESSION*)s;
|
||||
PCAPIStream* pRet = (PCAPIStream *)pOpaqueStream;
|
||||
|
||||
if (0 == pRet)
|
||||
if (0 == *pOpaqueStream)
|
||||
{
|
||||
pRet = (PCAPIStream *) CAPI_malloc(sizeof(PCAPIStream));
|
||||
if (0 == pRet)
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
# are specifed as dependencies within rules.mk.
|
||||
#
|
||||
|
||||
CFLAGS +=-D_IMPL_NS_XPFC -DNSPR20
|
||||
CFLAGS +=-D_IMPL_NS_CAPI -DNSPR20
|
||||
INCLUDES += -I../inc -I$(GDEPTH)/include
|
||||
|
||||
LIBRARY_NAME = capiinterface
|
||||
|
||||
@ -20,6 +20,8 @@ MODULE = trex
|
||||
CPPSRCS = \
|
||||
nsCapiLocal.cpp \
|
||||
nsCapiCST.cpp \
|
||||
nsCalStreamReader.cpp \
|
||||
nsCapiCallbackReader.cpp \
|
||||
$(NULL)
|
||||
|
||||
REQUIRES = raptor xpcom trex julian nls
|
||||
|
||||
207
mozilla/calendar/modules/network/capi/src/nsCalStreamReader.cpp
Normal file
207
mozilla/calendar/modules/network/capi/src/nsCalStreamReader.cpp
Normal file
@ -0,0 +1,207 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "jdefines.h"
|
||||
|
||||
#include <unistring.h>
|
||||
#include "nsCalStreamReader.h"
|
||||
#include "prprty.h"
|
||||
#include "tmbevent.h"
|
||||
#include "nscal.h"
|
||||
#include "jlog.h"
|
||||
#include "keyword.h"
|
||||
#include "icalsrdr.h"
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
nsCalStreamReader::nsCalStreamReader()
|
||||
{
|
||||
m_Reader = 0;
|
||||
m_OutCalendars = 0;
|
||||
m_Thread = 0;
|
||||
m_CallerData = 0;
|
||||
m_bParseStarted = FALSE;
|
||||
m_bParseFinished = FALSE;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
nsCalStreamReader::nsCalStreamReader(nsCapiCallbackReader * reader,
|
||||
JulianPtrArray * outCalendars,
|
||||
PRThread * thread, void* condVar)
|
||||
{
|
||||
m_Reader = reader;
|
||||
m_OutCalendars = outCalendars;
|
||||
m_Thread = thread;
|
||||
m_CallerData = condVar;
|
||||
m_bParseStarted = FALSE;
|
||||
m_bParseFinished = FALSE;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
JulianUtility::MimeEncoding
|
||||
nsCalStreamReader::stringToEncodingType(UnicodeString & propVal)
|
||||
{
|
||||
if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_s7bit) == 0)
|
||||
{
|
||||
return JulianUtility::MimeEncoding_7bit;
|
||||
}
|
||||
else if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sQUOTED_PRINTABLE) == 0)
|
||||
{
|
||||
return JulianUtility::MimeEncoding_QuotedPrintable;
|
||||
}
|
||||
else if (propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sBase64) == 0)
|
||||
{
|
||||
return JulianUtility::MimeEncoding_Base64;
|
||||
}
|
||||
else
|
||||
return JulianUtility::MimeEncoding_7bit;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
void nsCalStreamReader::ParseCalendars()
|
||||
{
|
||||
nsCalStreamReader::ParseCalendars((ICalReader *) m_Reader, m_OutCalendars);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
void nsCalStreamReader::ParseCalendars(ICalReader * reader,
|
||||
JulianPtrArray * outCalendars)
|
||||
{
|
||||
if (outCalendars == 0)
|
||||
return;
|
||||
|
||||
JulianPtrArray * parameters = new JulianPtrArray();
|
||||
|
||||
// TODO: this needs to be changed to capireader later
|
||||
PR_ASSERT(parameters != 0);
|
||||
if (parameters != 0)
|
||||
{
|
||||
JLog * log = 0;
|
||||
ErrorCode status = ZERO_ERROR;
|
||||
UnicodeString strLine, propName, propVal;
|
||||
JulianUtility::MimeEncoding encoding = JulianUtility::MimeEncoding_7bit;
|
||||
|
||||
nsCapiCallbackReader * cr = (nsCapiCallbackReader *) reader;
|
||||
|
||||
while(TRUE)
|
||||
{
|
||||
//PR_EnterMonitor((PRMonitor *) cr->getMonitor());
|
||||
//reader->readFullLine(strLine, status);
|
||||
cr->readFullLine(strLine, status);
|
||||
ICalProperty::Trim(strLine);
|
||||
|
||||
#if TESTING_ITIPRIG
|
||||
if (FALSE) TRACE("\t--Parser: line (size = %d) = ---%s---\r\n",
|
||||
strLine.size(), strLine.toCString(""));
|
||||
#endif
|
||||
if (FAILURE(status) && strLine.size() == 0)
|
||||
{
|
||||
//PR_Notify((PRMonitor *) cr->getMonitor());
|
||||
if (cr->isFinished())
|
||||
{
|
||||
break;
|
||||
}
|
||||
#if TESTING_ITIPRIG
|
||||
if (FALSE) TRACE("\t--jParser: yielding\r\n");
|
||||
#endif
|
||||
PR_Sleep(PR_INTERVAL_NO_WAIT);
|
||||
//break;
|
||||
}
|
||||
|
||||
ICalProperty::parsePropertyLine(strLine, propName,
|
||||
propVal, parameters);
|
||||
|
||||
#if TESTING_ITIPRIG
|
||||
if (TRUE) TRACE("\t--Parser: propName = --%s--, propVal = --%s--,paramSize = %d\r\n",
|
||||
propName.toCString(""), propVal.toCString(""), parameters->GetSize());
|
||||
#endif
|
||||
if ((propName.compareIgnoreCase(JulianKeyword::Instance()->ms_sBEGIN) == 0) &&
|
||||
(propVal.compareIgnoreCase(JulianKeyword::Instance()->ms_sVCALENDAR) == 0))
|
||||
{
|
||||
// parse an NSCalendar, add it to outCalendars
|
||||
NSCalendar * cal = new NSCalendar(log);
|
||||
UnicodeString fileName;
|
||||
cal->parse(reader, fileName, encoding);
|
||||
outCalendars->Add(cal);
|
||||
}
|
||||
else if (propName.compareIgnoreCase(
|
||||
JulianKeyword::Instance()->ms_sCONTENT_TRANSFER_ENCODING) == 0)
|
||||
{
|
||||
ICalProperty::Trim(propVal);
|
||||
encoding = stringToEncodingType(propVal);
|
||||
cr->setEncoding(encoding);
|
||||
}
|
||||
ICalProperty::deleteICalParameterVector(parameters);
|
||||
parameters->RemoveAll();
|
||||
|
||||
//PR_ExitMonitor((PRMonitor *)cr->getMonitor());
|
||||
}
|
||||
|
||||
ICalProperty::deleteICalParameterVector(parameters);
|
||||
parameters->RemoveAll();
|
||||
delete parameters; parameters = 0;
|
||||
setParseFinished();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
void main_CalStreamReader(void* p)
|
||||
{
|
||||
/*
|
||||
* We've been started. We must wait until our parent thread
|
||||
* signals to begin working...
|
||||
*/
|
||||
nsCalStreamReader * pStreamReader = (nsCalStreamReader *) p;
|
||||
PRMonitor * pMon = (PRMonitor*)pStreamReader->getCallerData();
|
||||
PR_EnterMonitor(pMon); /* wait until the other thread releases this */
|
||||
PR_ExitMonitor(pMon); /* now that we've got it, let both threads run */
|
||||
|
||||
/*
|
||||
* We only enter the Monitor when the parent has exited it. So,
|
||||
* our parent thread has signaled us to begin the work at hand.
|
||||
*/
|
||||
pStreamReader->ParseCalendars();
|
||||
|
||||
/*
|
||||
* The parent will try to re-enter the monitor when it is waiting for
|
||||
* this thread to complete parsing the calendars.
|
||||
*/
|
||||
PR_EnterMonitor(pMon);
|
||||
pStreamReader->setParseFinished();
|
||||
PR_Notify(pMon);
|
||||
PR_ExitMonitor(pMon);
|
||||
|
||||
/*
|
||||
* We're done.
|
||||
*/
|
||||
#if 0
|
||||
PR_ProcessExit(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,442 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* capiredr.cpp
|
||||
* John Sun
|
||||
* 4/16/98 3:42:19 PM
|
||||
*/
|
||||
|
||||
#include "nsCapiCallbackReader.h"
|
||||
#include "nspr.h"
|
||||
//#include "xp_mcom.h"
|
||||
|
||||
const t_int32 nsCapiCallbackReader::m_MAXBUFFERSIZE = 1024;
|
||||
const t_int32 nsCapiCallbackReader::m_NOMORECHUNKS = 404;
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
nsCapiCallbackReader::nsCapiCallbackReader()
|
||||
{
|
||||
PR_ASSERT(FALSE);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
void
|
||||
nsCapiCallbackReader::AddChunk(UnicodeString * u)
|
||||
{
|
||||
if (m_Chunks == 0)
|
||||
m_Chunks = new JulianPtrArray();
|
||||
PR_ASSERT(m_Chunks != 0);
|
||||
if (m_Chunks != 0)
|
||||
{
|
||||
m_Chunks->Add(u);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
nsCapiCallbackReader::nsCapiCallbackReader(PRMonitor * monitor,
|
||||
JulianUtility::MimeEncoding encoding)
|
||||
{
|
||||
m_Monitor = monitor;
|
||||
m_bFinished = FALSE;
|
||||
|
||||
m_ChunkIndex = 0;
|
||||
m_Chunks = 0;
|
||||
m_Init = TRUE;
|
||||
m_Pos = 0;
|
||||
m_Mark = 0;
|
||||
m_ChunkMark = 0;
|
||||
m_Encoding = encoding;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
void nsCapiCallbackReader::deleteUnicodeStringVector(JulianPtrArray * stringVector)
|
||||
{
|
||||
t_int32 i;
|
||||
if (stringVector != 0)
|
||||
{
|
||||
for (i = stringVector->GetSize() - 1; i >= 0; i--)
|
||||
{
|
||||
delete ((UnicodeString *) stringVector->GetAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
nsCapiCallbackReader::~nsCapiCallbackReader()
|
||||
{
|
||||
if (m_Chunks != 0)
|
||||
{
|
||||
deleteUnicodeStringVector(m_Chunks);
|
||||
delete m_Chunks; m_Chunks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
t_int8 nsCapiCallbackReader::read(ErrorCode & status)
|
||||
{
|
||||
t_int32 i = 0;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (m_Chunks == 0 || m_Chunks->GetSize() == 0 ||
|
||||
m_ChunkIndex >= m_Chunks->GetSize())
|
||||
{
|
||||
status = m_NOMORECHUNKS; // no more chunks, should block
|
||||
return -1;
|
||||
// block?
|
||||
}
|
||||
else
|
||||
{
|
||||
// read from linked list of UnicodeString's
|
||||
// delete front string when finished reading from it
|
||||
|
||||
UnicodeString string = *((UnicodeString *) m_Chunks->GetAt(m_ChunkIndex));
|
||||
if (m_Pos < string.size())
|
||||
{
|
||||
// return index of this
|
||||
status = ZERO_ERROR;
|
||||
|
||||
if (m_Encoding == JulianUtility::MimeEncoding_QuotedPrintable)
|
||||
{
|
||||
if ((string)[(TextOffset) m_Pos] == '=')
|
||||
{
|
||||
if (string.size() >= (t_int32)(m_Pos + 3))
|
||||
{
|
||||
if (ICalReader::isHex((t_int8) string[(TextOffset)(m_Pos + 1)]) &&
|
||||
ICalReader::isHex((t_int8) string[(TextOffset)(m_Pos + 2)]))
|
||||
{
|
||||
t_int8 c;
|
||||
c = ICalReader::convertHex(
|
||||
(char) string[(TextOffset) (m_Pos + 1)],
|
||||
(char) string[(TextOffset) (m_Pos + 2)]
|
||||
);
|
||||
m_Pos += 3;
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (t_int8) (string)[(TextOffset) m_Pos++];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
t_int32 lenDiff = string.size() - m_Pos;
|
||||
char fToken;
|
||||
char sToken;
|
||||
t_bool bSetFToken = FALSE;
|
||||
t_int32 tempIndex = m_ChunkIndex;
|
||||
UnicodeString token;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
|
||||
// lenDiff = 1, 2 always
|
||||
// the =XX spans different chunks
|
||||
// if last chunk, return out of chunks status
|
||||
if (tempIndex == m_Chunks->GetSize() - 1)
|
||||
{
|
||||
status = m_NOMORECHUNKS;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnicodeString nextstring = *((UnicodeString *) m_Chunks->GetAt(tempIndex + 1));
|
||||
tempIndex++;
|
||||
|
||||
if (nextstring.size() >= 2)
|
||||
{
|
||||
t_int8 c;
|
||||
if (lenDiff == 2)
|
||||
{
|
||||
|
||||
fToken = (char) string[(TextOffset) (string.size() - 1)];
|
||||
sToken = (char) nextstring[(TextOffset) 0];
|
||||
|
||||
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
|
||||
{
|
||||
c = ICalReader::convertHex(fToken, sToken);
|
||||
|
||||
m_Pos = 1;
|
||||
m_ChunkIndex = tempIndex;
|
||||
bSetFToken = FALSE;
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (t_int8) (string)[(TextOffset) m_Pos++];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// lenDiff = 1
|
||||
|
||||
if (bSetFToken)
|
||||
{
|
||||
sToken = (char)nextstring[(TextOffset) 0];
|
||||
}
|
||||
else
|
||||
{
|
||||
fToken = (char)nextstring[(TextOffset) 0];
|
||||
sToken = (char)nextstring[(TextOffset) 1];
|
||||
}
|
||||
|
||||
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
|
||||
{
|
||||
c = ICalReader::convertHex(fToken, sToken);
|
||||
|
||||
m_Pos = 2;
|
||||
m_ChunkIndex = tempIndex;
|
||||
bSetFToken = FALSE;
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (t_int8) (string)[(TextOffset) m_Pos++];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nextstring.size() > 0)
|
||||
{
|
||||
if (!bSetFToken)
|
||||
{
|
||||
fToken = (char)nextstring[(TextOffset) 0];
|
||||
bSetFToken = TRUE;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
sToken = (char)nextstring[(TextOffset) 0];
|
||||
|
||||
if (ICalReader::isHex(fToken) && ICalReader::isHex(sToken))
|
||||
{
|
||||
char c;
|
||||
c = ICalReader::convertHex(fToken, sToken);
|
||||
|
||||
m_Pos = 1;
|
||||
m_ChunkIndex = tempIndex;
|
||||
bSetFToken = FALSE;
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (t_int8) (string)[(TextOffset) m_Pos++];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (t_int8) (string)[(TextOffset) m_Pos++];
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return (t_int8) (string)[(TextOffset) m_Pos++];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete front string from list, try reading from next chunk
|
||||
m_Pos = 0;
|
||||
m_ChunkIndex++;
|
||||
|
||||
//delete ((UnicodeString *) m_Chunks->GetAt(i));
|
||||
//m_Chunks->RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
status = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
UnicodeString &
|
||||
nsCapiCallbackReader::createLine(t_int32 oldPos, t_int32 oldChunkIndex,
|
||||
t_int32 newPos, t_int32 newChunkIndex,
|
||||
UnicodeString & aLine)
|
||||
{
|
||||
PR_ASSERT(oldChunkIndex <= newChunkIndex);
|
||||
UnicodeString u;
|
||||
if (oldChunkIndex == newChunkIndex)
|
||||
{
|
||||
u = *((UnicodeString *) m_Chunks->GetAt(oldChunkIndex));
|
||||
u.extractBetween(oldPos, newPos, aLine);
|
||||
return aLine;
|
||||
}
|
||||
else {
|
||||
//(oldChunkIndex < newChunkIndex)
|
||||
|
||||
t_int32 i;
|
||||
UnicodeString v, temp;
|
||||
u = *((UnicodeString *) m_Chunks->GetAt(oldChunkIndex));
|
||||
u.extractBetween(oldPos, u.size(), aLine);
|
||||
v = *((UnicodeString *) m_Chunks->GetAt(newChunkIndex));
|
||||
v.extractBetween(0, newPos, temp);
|
||||
i = oldChunkIndex + 1;
|
||||
while (i < newChunkIndex)
|
||||
{
|
||||
v = *((UnicodeString *) m_Chunks->GetAt(i));
|
||||
aLine += v;
|
||||
i++;
|
||||
}
|
||||
aLine += temp;
|
||||
return aLine;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
UnicodeString &
|
||||
nsCapiCallbackReader::readFullLine(UnicodeString & aLine, ErrorCode & status, t_int32 iTemp)
|
||||
{
|
||||
status = ZERO_ERROR;
|
||||
t_int32 i;
|
||||
|
||||
#if 1
|
||||
PR_EnterMonitor(m_Monitor);
|
||||
#endif
|
||||
|
||||
t_int32 oldpos = m_Pos;
|
||||
t_int32 oldChunkIndex = m_ChunkIndex;
|
||||
|
||||
readLine(aLine, status);
|
||||
if (status == m_NOMORECHUNKS)
|
||||
{
|
||||
if (m_bFinished)
|
||||
{
|
||||
// do nothing.
|
||||
}
|
||||
else
|
||||
{
|
||||
PR_Wait(m_Monitor,PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
UnicodeString aSubLine;
|
||||
while (TRUE)
|
||||
{
|
||||
mark();
|
||||
i = read(status);
|
||||
if (status == m_NOMORECHUNKS)
|
||||
{
|
||||
if (m_bFinished)
|
||||
{
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
PR_Wait(m_Monitor,PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
}
|
||||
else if (i == ' ')
|
||||
{
|
||||
aLine += readLine(aSubLine, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
PR_ExitMonitor(m_Monitor);
|
||||
#endif
|
||||
|
||||
return aLine;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
UnicodeString &
|
||||
nsCapiCallbackReader::readLine(UnicodeString & aLine, ErrorCode & status)
|
||||
{
|
||||
status = ZERO_ERROR;
|
||||
t_int8 c = 0;
|
||||
t_int32 oldPos = m_Pos;
|
||||
t_int32 oldChunkIndex = m_ChunkIndex;
|
||||
|
||||
aLine = "";
|
||||
|
||||
//PR_EnterMonitor(m_Monitor);
|
||||
|
||||
c = read(status);
|
||||
while (!(FAILURE(status)))
|
||||
{
|
||||
if (status == m_NOMORECHUNKS)
|
||||
{
|
||||
// block
|
||||
break;
|
||||
}
|
||||
/* Break on '\n', '\r\n', and '\r' */
|
||||
else if (c == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (c == '\r')
|
||||
{
|
||||
mark();
|
||||
c = read(status);
|
||||
if (FAILURE(status))
|
||||
{
|
||||
// block(), reset()?
|
||||
break;
|
||||
}
|
||||
else if (c == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if 1
|
||||
aLine += c;
|
||||
//if (FALSE) TRACE("aLine = %s: -%c,%d-\r\n", aLine.toCString(""), c, c);
|
||||
#endif
|
||||
c = read(status);
|
||||
|
||||
}
|
||||
#if 0
|
||||
createLine(oldPos, oldChunkIndex, m_Pos, m_ChunkIndex, aLine);
|
||||
#endif
|
||||
|
||||
//if (FALSE) TRACE("\treadLine returned %s\r\n", aLine.toCString(""));
|
||||
return aLine;
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
@ -28,6 +28,7 @@ PRIVATE_EXPORTS = \
|
||||
nsCalendarShell.h \
|
||||
nsCalendarWidget.h \
|
||||
nsCalShellFactory.h \
|
||||
nsCalScheduler.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = trex
|
||||
|
||||
66
mozilla/calendar/modules/shell/inc/nsCalScheduler.h
Normal file
66
mozilla/calendar/modules/shell/inc/nsCalScheduler.h
Normal file
@ -0,0 +1,66 @@
|
||||
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2
|
||||
-*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* nsCalScheduler
|
||||
* Wraps all the capi and parsing code. A more convenient
|
||||
* interface for performing scheduling tasks.
|
||||
*
|
||||
* sman
|
||||
*/
|
||||
|
||||
#if !defined(AFX_NSCALSCHEDULER_H__A53027E1_42D1_11D2_8ED8_0060088A4B1D__INCLUDED_)
|
||||
#define AFX_NSCALSCHEDULER_H__A53027E1_42D1_11D2_8ED8_0060088A4B1D__INCLUDED_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsError.h"
|
||||
#include "nsCom.h"
|
||||
#include "capi.h"
|
||||
#include "julnstr.h"
|
||||
#include "nsDateTime.h"
|
||||
|
||||
class nsCalScheduler
|
||||
{
|
||||
public:
|
||||
nsCalScheduler();
|
||||
virtual ~nsCalScheduler();
|
||||
|
||||
/**
|
||||
* Fetch events from the supplied curl that overlap the
|
||||
* supplied date range.
|
||||
* @param sCurl the curl describing the data source
|
||||
* @param u the user who is asking for the data
|
||||
* @param psPassword the password needed to login to this url
|
||||
* @param dStart range start time
|
||||
* @param dEnd range end time
|
||||
* @param ppsPropList array of property names to load
|
||||
* @param iPropCount number of items in ppsPropList
|
||||
* @param pCal the calendar into which these events should be loaded
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult FetchEventsByRange(
|
||||
const JulianString& sCurl,
|
||||
DateTime dStart,
|
||||
DateTime dEnd,
|
||||
char** ppsPropList,
|
||||
int iPropCount,
|
||||
NSCalendar* pCal);
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_NSCALSCHEDULER_H__A53027E1_42D1_11D2_8ED8_0060088A4B1D__INCLUDED_)
|
||||
@ -31,11 +31,11 @@
|
||||
class nsCalUser
|
||||
{
|
||||
private:
|
||||
JulianString m_sUserName; /* example: sman */
|
||||
nsString m_sDisplayName; /* example: Steve Mansour */
|
||||
JulianPtrArray m_CalAddrList; /* a list of JulianString CalURL strings */
|
||||
NSCalendar* m_pCal; /* the preferred calendar account (the only one for now) */
|
||||
JulianPtrArray m_CalList; /* an array of calendars owned by this user */
|
||||
JulianString m_sUserName; /* example: sman */
|
||||
nsString m_sDisplayName; /* example: Steve Mansour */
|
||||
JulianPtrArray m_CalAddrList; /* a list of JulianString CalURL strings */
|
||||
NSCalendar* m_pCal; /* the preferred calendar account (the only one for now) */
|
||||
JulianPtrArray m_CalList; /* an array of calendars owned by this user */
|
||||
void InitMembers();
|
||||
|
||||
public:
|
||||
|
||||
@ -91,6 +91,7 @@ public:
|
||||
NS_IMETHOD ReceiveCommand(nsString& aCommand, nsString& aReply);
|
||||
|
||||
private:
|
||||
NS_METHOD InitialLoadData();
|
||||
NS_METHOD RegisterFactories();
|
||||
NS_METHOD SetDefaultPreferences();
|
||||
NS_METHOD EnvVarsToValues(JulianString& s);
|
||||
|
||||
@ -53,6 +53,7 @@ LD_LIBS += \
|
||||
calui10 \
|
||||
calnetwork10 \
|
||||
calparser10 \
|
||||
calcapi10 \
|
||||
util10 \
|
||||
$(NATIVE_RAPTOR_GFX) \
|
||||
$(RAPTOR_GFX) \
|
||||
|
||||
145
mozilla/calendar/modules/shell/src/nsCalScheduler.cpp
Normal file
145
mozilla/calendar/modules/shell/src/nsCalScheduler.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2
|
||||
-*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* nsCalScheduler
|
||||
* Wraps all the capi and parsing code. A more convenient
|
||||
* interface for performing scheduling tasks.
|
||||
*
|
||||
* sman
|
||||
*/
|
||||
|
||||
|
||||
#include "nsCalScheduler.h"
|
||||
|
||||
nsCalScheduler::nsCalScheduler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsCalScheduler::~nsCalScheduler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch events from the supplied curl that overlap the
|
||||
* supplied date range.
|
||||
* @param sCurl the curl describing the data source
|
||||
* @param u the user who is asking for the data
|
||||
* @param psPassword the password needed to login to this url
|
||||
* @param dStart range start time
|
||||
* @param dEnd range end time
|
||||
* @param ppsPropList array of property names to load
|
||||
* @param iPropCount number of items in ppsPropList
|
||||
* @param pCal the calendar into which these events should be loaded
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult FetchEventsByRange(
|
||||
const JulianString& sCurl,
|
||||
const nsCalUser& u,
|
||||
const char* psPassword,
|
||||
DateTime dStart,
|
||||
DateTime dEnd,
|
||||
char** ppsPropList,
|
||||
int iPropCount,
|
||||
nsCalendar* pCal)
|
||||
{
|
||||
User * pFromUser;
|
||||
User * pToUser;
|
||||
nsCurlParser Curl(sCurl);
|
||||
|
||||
JulianPtrArray CompList;
|
||||
JulianPtrArray RecipList;
|
||||
JulianPtrArray ModifierList;
|
||||
|
||||
UnicodeString name = "John Sun";
|
||||
UnicodeString email = "jsun@netscape.com";
|
||||
UnicodeString capaddr = "jsunCAP";
|
||||
t_int32 xitemid = 32432;
|
||||
UnicodeString iripaddr = "jsunIRIP";
|
||||
UnicodeString subject = "a subject";
|
||||
UnicodeString password = "z8j20bwm";
|
||||
UnicodeString hostname = "calendar-1";
|
||||
UnicodeString node = "10000";
|
||||
pFromUser = new User(name, email, capaddr, xitemid, iripaddr);
|
||||
|
||||
// TODO: set pFromUser's CS&T info for now
|
||||
pFromUser->setCAPIInfo("", password, hostname, node);
|
||||
|
||||
assert(pFromUser != 0);
|
||||
|
||||
pToUser = new User(name, email, capaddr, xitemid, iripaddr);
|
||||
assert(pToUser != 0);
|
||||
|
||||
recipients->Add(pToUser);
|
||||
|
||||
ModifierList->Add(new UnicodeString("19980220T112233Z"));
|
||||
ModifierList->Add(new UnicodeString("19980228T112233Z"));
|
||||
|
||||
/*
|
||||
TransactionObject *
|
||||
TransactionObjectFactory::Make(NSCalendar & cal,
|
||||
JulianPtrArray & CompList,
|
||||
User & user,
|
||||
JulianPtrArray & recipients,
|
||||
UnicodeString & subject,
|
||||
JulianPtrArray & modifiers,
|
||||
JulianForm * jf,
|
||||
MWContext * context,
|
||||
UnicodeString & attendeeName,
|
||||
TransactionObject::EFetchType fetchType)
|
||||
*/
|
||||
TransactionObject * gto;
|
||||
gto = TransactionObjectFactory::Make(
|
||||
*pCal, /* ical components are loaded into this calendar */
|
||||
CompList, /* a list of pointers to the components loaded */
|
||||
*pFromUser,
|
||||
*recipients,
|
||||
subject,
|
||||
*ModifierList,
|
||||
NULL,
|
||||
NULL,
|
||||
m_Name,
|
||||
GetTransactionObject::EFetchType_DateRange);
|
||||
assert(gto != 0);
|
||||
JulianPtrArray * out = new JulianPtrArray(); assert(out != 0);
|
||||
|
||||
TransactionObject::ETxnErrorCode txnStatus;
|
||||
gto->executeCAPI(out, txnStatus);
|
||||
|
||||
NSCalendar * aCal;
|
||||
char sBuf[5000];
|
||||
t_int32 size = out->GetSize();
|
||||
t_int32 eventSize = 0;
|
||||
|
||||
char * acc;
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
aCal = (NSCalendar *) out->GetAt(i);
|
||||
if (aCal->getEvents() != 0)
|
||||
eventSize = aCal->getEvents()->GetSize();
|
||||
|
||||
pMsg->SendReply(sBuf);
|
||||
acc = aCal->toICALString().toCString("")
|
||||
pMsg->SendReply(acc);
|
||||
delete [] acc;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -35,6 +35,7 @@
|
||||
#include "nsICapi.h"
|
||||
#include "nsICapiLocal.h"
|
||||
#include "nsCapiCIID.h"
|
||||
#include "nsCurlParser.h"
|
||||
|
||||
static NS_DEFINE_IID(kCCapiLocalCID, NS_CAPI_LOCAL_CID);
|
||||
static NS_DEFINE_IID(kCCapiCSTCID, NS_CAPI_CST_CID);
|
||||
@ -95,54 +96,85 @@ nsCalSession::~nsCalSession()
|
||||
*/
|
||||
nsresult nsCalSession::GetSession(CAPISession& Session, const char* psPassword)
|
||||
{
|
||||
CAPIStatus s;
|
||||
Session = 0;
|
||||
nsICapiLocal * capi_local = nsnull;
|
||||
|
||||
if ( m_sCurl == "")
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* Create an nsICapi Instance
|
||||
*
|
||||
* TODO: The CID should be based on the type of url passed in!
|
||||
* For now, do local capi
|
||||
*/
|
||||
|
||||
nsresult res = NS_OK;
|
||||
if (0 == m_Session)
|
||||
{
|
||||
CAPIStatus s;
|
||||
Session = 0;
|
||||
nsICapiLocal * capi_local = nsnull;
|
||||
|
||||
res = nsRepository::CreateInstance(kCCapiLocalCID,
|
||||
nsnull,
|
||||
kICapiIID,
|
||||
(void**)&mCapi);
|
||||
if ( m_sCurl == "")
|
||||
return 1;
|
||||
|
||||
if (NS_OK != res)
|
||||
return res;
|
||||
/*
|
||||
* Create an nsICapi Instance
|
||||
*
|
||||
* TODO: The CID should be based on the type of url passed in!
|
||||
* For now, do local capi
|
||||
*/
|
||||
res = 1;
|
||||
nsCurlParser cp(m_sCurl);
|
||||
switch ( cp.GetProtocol() )
|
||||
{
|
||||
case nsCurlParser::eFILE:
|
||||
res = nsRepository::CreateInstance(kCCapiLocalCID,nsnull,kICapiIID,(void**)&mCapi);
|
||||
break;
|
||||
|
||||
mCapi->Init();
|
||||
case nsCurlParser::eCAPI:
|
||||
{
|
||||
res = nsRepository::CreateInstance(kCCapiCSTCID,nsnull, kICapiIID, (void**)&mCapi);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Since we believe this to be local capi, see if the capi
|
||||
* object we created supports the nsICapiLocal interface
|
||||
*/
|
||||
if (NS_OK != res)
|
||||
return res;
|
||||
|
||||
res = mCapi->QueryInterface(kICapiLocalIID,(void**)&capi_local);
|
||||
mCapi->Init();
|
||||
|
||||
if (NS_OK != res)
|
||||
return res;
|
||||
/*
|
||||
* Since we believe this to be local capi, see if the capi
|
||||
* object we created supports the nsICapiLocal interface
|
||||
*/
|
||||
res = mCapi->QueryInterface(kICapiLocalIID,(void**)&capi_local);
|
||||
|
||||
/*
|
||||
* Do the CAPI login
|
||||
*/
|
||||
if (NS_OK == res)
|
||||
{
|
||||
/*
|
||||
* Do the CAPI login
|
||||
*/
|
||||
s = capi_local->CAPI_LogonCurl(m_sCurl.GetBuffer(), psPassword, m_lFlags, &m_Session);
|
||||
NS_RELEASE(capi_local);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* use standard login...
|
||||
* Try several things for the user name
|
||||
*/
|
||||
JulianString sName;
|
||||
JulianString sPW;
|
||||
JulianString sHost = cp.GetHost();
|
||||
if ( cp.GetUser() != "" )
|
||||
sName = cp.GetUser();
|
||||
else
|
||||
sName = cp.GetExtra();
|
||||
|
||||
s = capi_local->CAPI_LogonCurl(m_sCurl.GetBuffer(), psPassword, m_lFlags, &m_Session);
|
||||
if (cp.GetPassword() != "")
|
||||
sPW = cp.GetPassword();
|
||||
else
|
||||
sPW = psPassword;
|
||||
|
||||
NS_RELEASE(capi_local);
|
||||
s = mCapi->CAPI_Logon(
|
||||
sName.GetBuffer(), sPW.GetBuffer(),
|
||||
sHost.GetBuffer(), m_lFlags, &m_Session);
|
||||
}
|
||||
|
||||
if (CAPI_ERR_OK != s)
|
||||
return res;
|
||||
if (CAPI_ERR_OK != s)
|
||||
return res;
|
||||
++m_iCount;
|
||||
}
|
||||
|
||||
++m_iCount;
|
||||
Session = m_Session;
|
||||
|
||||
return res;
|
||||
|
||||
@ -39,10 +39,16 @@
|
||||
#include "nsCalCommandCanvas.h"
|
||||
#include "nlsloc.h"
|
||||
#include "nsCapiCIID.h"
|
||||
#include "nspr.h"
|
||||
#include "prcvar.h"
|
||||
|
||||
#include "capi.h"
|
||||
#include "nsICapi.h"
|
||||
|
||||
/* for CAPI to work in general form */
|
||||
#include "nsCapiCallbackReader.h"
|
||||
#include "nsCalStreamReader.h"
|
||||
|
||||
#ifdef NS_WIN32
|
||||
#include "windows.h"
|
||||
#endif
|
||||
@ -87,10 +93,76 @@ nsresult NS_RegisterApplicationShellFactory()
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* CAPI Callback used to fetch data from a general CAPI location
|
||||
* Gets nsCalStreamReader object.
|
||||
* If parse not started yet.
|
||||
* Start the parser - the parser will block automatically when
|
||||
* no more data to parse.
|
||||
* When parse is blocked, set size handled
|
||||
*/
|
||||
int RcvData(void * pData,
|
||||
char * pBuf,
|
||||
size_t iSize,
|
||||
size_t * piTransferred)
|
||||
{
|
||||
nsCalStreamReader * pCalStreamReader = (nsCalStreamReader *) pData;
|
||||
nsCapiCallbackReader * pCapiCallbackReader = pCalStreamReader->getReader();
|
||||
if (!pCalStreamReader->isParseStarted())
|
||||
{
|
||||
PRMonitor * pMon = (PRMonitor*) pCalStreamReader->getCallerData();
|
||||
pCalStreamReader->setParseStarted();
|
||||
|
||||
/*
|
||||
* Start up the thread that will receive the ical data
|
||||
*/
|
||||
PR_ExitMonitor(pMon);
|
||||
}
|
||||
|
||||
/*
|
||||
* We're going to be adding a new buffer (unicode string) to the
|
||||
* list of data. We don't want the other thread accessing the list
|
||||
* while we're doing this. So, we enter the monitor...
|
||||
*/
|
||||
PR_EnterMonitor((PRMonitor *)pCapiCallbackReader->getMonitor());
|
||||
|
||||
/*
|
||||
* if we're finished, set the CapiCallbackReader to finished.
|
||||
*/
|
||||
if (iSize == 0)
|
||||
{
|
||||
pCapiCallbackReader->setFinished();
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* XXX: may want to ensure that pBuf is 0 terminated.
|
||||
*/
|
||||
pCapiCallbackReader->AddChunk(new UnicodeString(pBuf));
|
||||
*piTransferred = iSize;
|
||||
}
|
||||
|
||||
/*
|
||||
* The parsing thread may be waiting on more data before it
|
||||
* can continue. When this happens, it enters a PR_WAIT for
|
||||
* this monitor. We've just finished adding more data, so we
|
||||
* want to notify the other thread now if it's waiting.
|
||||
*/
|
||||
PR_Notify((PRMonitor *)pCapiCallbackReader->getMonitor());
|
||||
PR_ExitMonitor((PRMonitor *)pCapiCallbackReader->getMonitor());
|
||||
|
||||
/*
|
||||
* Now that another buffer is available for parsing, we want
|
||||
* the parsing thread to take over. This will help keep the
|
||||
* list of unparsed buffers to a minimum.
|
||||
*/
|
||||
PR_Sleep(PR_INTERVAL_NO_WAIT);
|
||||
return iSize > 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* nsCalendarShell Definition
|
||||
*/
|
||||
|
||||
nsCalendarShell::nsCalendarShell()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
@ -229,13 +301,155 @@ nsresult nsCalendarShell::EnsureUserPath( JulianString& sPath )
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX Define some error codes ... and use them.
|
||||
/*
|
||||
* required to set gasViewPropList and giViewPropListCount for now
|
||||
* will need to change local CAPI so null gasViewPropList will return
|
||||
* all properties.
|
||||
*/
|
||||
char * gasViewPropList[10] = {
|
||||
"ATTENDEE", "DTSTART", "DTEND", "UID", "RECURRENCE-ID",
|
||||
"DTSTAMP", "SUMMARY", "DESCRIPTION", "ORGANIZER", "TRANSP"
|
||||
};
|
||||
int giViewPropListCount = 10;
|
||||
|
||||
/**
|
||||
* Given an nsICapi interface, log in and get some initial data.
|
||||
* @return NS_OK on success.
|
||||
*/
|
||||
nsresult nsCalendarShell::InitialLoadData()
|
||||
{
|
||||
nsresult res;
|
||||
ErrorCode status = ZERO_ERROR;
|
||||
DateTime d;
|
||||
char * psDTStart = 0;
|
||||
char * psDTEnd = 0;
|
||||
CAPIStream RcvStream = 0;
|
||||
CAPIStatus capiStatus;
|
||||
JulianPtrArray * pParsedCalList = new JulianPtrArray();
|
||||
nsCalStreamReader * pCalStreamReader = 0;
|
||||
PRThread * parseThread = 0;
|
||||
PRThread * mainThread = 0;
|
||||
PRMonitor * pCBReaderMonitor = 0;
|
||||
PRMonitor *pThreadMonitor = 0;
|
||||
|
||||
/*
|
||||
* Select the capi interface to use for this operation...
|
||||
*/
|
||||
nsICapi* pCapi = m_SessionMgr.GetAt(0L)->mCapi;
|
||||
|
||||
/*
|
||||
* Begin a calendar for the logged in user...
|
||||
*/
|
||||
m_pCalendar = new NSCalendar(0);
|
||||
SetNSCalendar(m_pCalendar);
|
||||
|
||||
/*
|
||||
* Set up the range of time for which we'll pull events...
|
||||
*/
|
||||
int iOffset = 30;
|
||||
d.prevDay(iOffset);
|
||||
psDTStart = d.toISO8601().toCString("");
|
||||
d.nextDay(2 * iOffset);
|
||||
psDTEnd = d.toISO8601().toCString("");
|
||||
|
||||
/*
|
||||
* The data is actually read and parsed in another thread. Set it all
|
||||
* up here...
|
||||
*/
|
||||
mainThread = PR_CurrentThread();
|
||||
pCBReaderMonitor = PR_NewMonitor();
|
||||
nsCapiCallbackReader * capiReader = new nsCapiCallbackReader(pCBReaderMonitor);
|
||||
pThreadMonitor = ::PR_NewMonitor();
|
||||
PR_EnterMonitor(pThreadMonitor);
|
||||
pCalStreamReader = new nsCalStreamReader(capiReader, pParsedCalList, parseThread, pThreadMonitor);
|
||||
parseThread = PR_CreateThread(PR_USER_THREAD,
|
||||
main_CalStreamReader,
|
||||
pCalStreamReader,
|
||||
PR_PRIORITY_HIGH,
|
||||
PR_LOCAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
4096);
|
||||
|
||||
capiStatus = pCapi->CAPI_SetStreamCallbacks(
|
||||
mCAPISession, &RcvStream, 0,0,RcvData, pCalStreamReader,0);
|
||||
|
||||
if (CAPI_ERR_OK != capiStatus)
|
||||
return 1; /* XXX: really need to fix this up */
|
||||
|
||||
{
|
||||
/* XXX: Get rid of the local variables as soon as
|
||||
* local capi can take a null list or as soon as
|
||||
* cs&t capi can take a list.
|
||||
*/
|
||||
nsCurlParser sessionURL(msCalURL);
|
||||
char** asList = gasViewPropList;
|
||||
int iListSize = giViewPropListCount;
|
||||
|
||||
if (nsCurlParser::eCAPI == sessionURL.GetProtocol())
|
||||
{
|
||||
asList = 0;
|
||||
iListSize = 0;
|
||||
}
|
||||
|
||||
|
||||
capiStatus = pCapi->CAPI_FetchEventsByRange(
|
||||
mCAPISession, &mCAPIHandle, 1, 0,
|
||||
psDTStart, psDTEnd,
|
||||
asList, iListSize, RcvStream);
|
||||
}
|
||||
|
||||
if (CAPI_ERR_OK != capiStatus)
|
||||
return 1; /* XXX: really need to fix this up */
|
||||
|
||||
/*
|
||||
* Wait here until we know the thread completed.
|
||||
*/
|
||||
if (!pCalStreamReader->isParseFinished() )
|
||||
{
|
||||
PR_EnterMonitor(pThreadMonitor);
|
||||
PR_Wait(pThreadMonitor,PR_INTERVAL_NO_TIMEOUT);
|
||||
PR_ExitMonitor(pThreadMonitor);
|
||||
}
|
||||
|
||||
delete [] psDTStart; psDTStart = 0;
|
||||
delete [] psDTEnd; psDTEnd = 0;
|
||||
|
||||
PR_DestroyMonitor(pThreadMonitor);
|
||||
|
||||
/*
|
||||
* Load the retrieved events ito our calendar...
|
||||
*/
|
||||
int i,j;
|
||||
NSCalendar* pCal;
|
||||
JulianPtrArray* pEventList;
|
||||
ICalComponent* pEvent;
|
||||
for ( i = 0; i < pParsedCalList->GetSize(); i++)
|
||||
{
|
||||
pCal = (NSCalendar*)pParsedCalList->GetAt(i);
|
||||
pEventList = pCal->getEvents();
|
||||
if (0 != pEventList)
|
||||
{
|
||||
for (j = 0; j < pEventList->GetSize(); j++)
|
||||
{
|
||||
pEvent = (ICalComponent*)pEventList->GetAt(j);
|
||||
if (0 != pEvent)
|
||||
m_pCalendar->addEvent(pEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* register the calendar...
|
||||
*/
|
||||
if (NS_OK != (res = m_CalList.Add(m_pCalendar)))
|
||||
return res;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method establishes a logged in user and opens a connection to
|
||||
* the calendar server (or local database file if they're working offline).
|
||||
* HACK: currently it is loading the entire calendar into memory.
|
||||
* We need to load events as needed.
|
||||
*
|
||||
* @return NS_OK on success
|
||||
* 1 = could not create or write to a local capi directory
|
||||
@ -245,32 +459,6 @@ nsresult nsCalendarShell::Logon()
|
||||
CAPIStatus s;
|
||||
nsresult res;
|
||||
|
||||
/*
|
||||
* Ask the session manager for a session...
|
||||
*/
|
||||
res = m_SessionMgr.GetSession(msCalURL.GetBuffer(), 0L, GetCAPIPassword(), mCAPISession);
|
||||
|
||||
#if 0
|
||||
s = m_SessionMgr.GetAt(0L)->mCapi->CAPI_LogonCurl( msCalURL.GetBuffer(), GetCAPIPassword(), 0L, &mCAPISession);
|
||||
|
||||
if (CAPI_ERR_OK != s)
|
||||
return NS_OK;
|
||||
#endif
|
||||
|
||||
s = m_SessionMgr.GetAt(0L)->mCapi->CAPI_GetHandle(mCAPISession, mpLoggedInUser->GetUserName().GetBuffer(), 0, &mCAPIHandle);
|
||||
|
||||
if (CAPI_ERR_OK != s)
|
||||
return NS_OK;
|
||||
|
||||
/*
|
||||
* Load some data...
|
||||
*/
|
||||
ICalReader * pRedr = 0;
|
||||
ErrorCode status = ZERO_ERROR;
|
||||
UnicodeString uFilename;
|
||||
m_pCalendar = new NSCalendar(0);
|
||||
SetNSCalendar(m_pCalendar);
|
||||
|
||||
/*
|
||||
* Getting the first calendar by user name should be reviewed.
|
||||
*/
|
||||
@ -278,55 +466,46 @@ nsresult nsCalendarShell::Logon()
|
||||
nsCurlParser sessionURL(msCalURL);
|
||||
theURL |= sessionURL;
|
||||
|
||||
/*
|
||||
* Ask the session manager for a session...
|
||||
*/
|
||||
res = m_SessionMgr.GetSession(
|
||||
msCalURL.GetBuffer(), // may contain a password, if so it will be used
|
||||
0L,
|
||||
GetCAPIPassword(),
|
||||
mCAPISession);
|
||||
|
||||
char* psHandle = mpLoggedInUser->GetUserName().GetBuffer();
|
||||
|
||||
|
||||
/*
|
||||
* XXX: we need to make this more general...
|
||||
*/
|
||||
if (nsCurlParser::eCAPI == theURL.GetProtocol())
|
||||
psHandle = ":/S=User1/G=Test/";
|
||||
|
||||
|
||||
s = m_SessionMgr.GetAt(0L)->mCapi->CAPI_GetHandle(
|
||||
mCAPISession,
|
||||
psHandle,
|
||||
0,
|
||||
&mCAPIHandle);
|
||||
|
||||
if (CAPI_ERR_OK != s)
|
||||
return NS_OK;
|
||||
|
||||
switch(theURL.GetProtocol())
|
||||
{
|
||||
case nsCurlParser::eFILE:
|
||||
{
|
||||
char* psLocalFile = theURL.ToLocalFile();
|
||||
JulianString sPath = theURL.CSIDPath();
|
||||
if (NS_OK != EnsureUserPath( sPath ))
|
||||
{
|
||||
// XXX do some error thing here...
|
||||
// we should probably pop up a file dialog and let
|
||||
// the user point us to a path to use.
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* load data into memory...
|
||||
*/
|
||||
pRedr = (ICalReader *) new ICalFileReader(psLocalFile, status);
|
||||
if (pRedr == 0)
|
||||
return NS_OK;
|
||||
if (FAILURE(status))
|
||||
return NS_OK;
|
||||
uFilename = psLocalFile;
|
||||
m_pCalendar->parse(pRedr, uFilename);
|
||||
|
||||
/*
|
||||
* register the calendar...
|
||||
*/
|
||||
if (NS_OK != (res = m_CalList.Add(m_pCalendar)))
|
||||
return res;
|
||||
|
||||
/*
|
||||
* clean up...
|
||||
*/
|
||||
PR_Free(psLocalFile);
|
||||
delete pRedr;
|
||||
pRedr = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case nsCurlParser::eCAPI:
|
||||
{
|
||||
// UNHANDLED
|
||||
InitialLoadData();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
// unhandled
|
||||
/* need to report that this is an unhandled curl type */
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -445,9 +624,7 @@ nsresult nsCalendarShell::EnvVarsToValues(JulianString& s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -878,4 +1055,4 @@ nsresult nsCalendarShell::StartCommandServer()
|
||||
mCommandServer->Init((nsIApplicationShell *)this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,11 +13,12 @@ EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
PRIVATE_EXPORTS = \
|
||||
nsCurlParser.h \
|
||||
nsCurlParser.h \
|
||||
nsDateTime.h \
|
||||
nsDuration.h \
|
||||
nsDuration.h \
|
||||
nsCalUtilCIID.h \
|
||||
nscalexport.h \
|
||||
nsX400Parser.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = trex
|
||||
|
||||
@ -20,16 +20,19 @@
|
||||
/**
|
||||
* This class manages a string in one of the following forms:
|
||||
*
|
||||
* protocol://host.domain[:port]/CSID[:extra]
|
||||
* protocol://user:password@host.domain[:port]/CSID[:extra]
|
||||
* mailto:user@host.domain
|
||||
*
|
||||
* Examples:
|
||||
* capi://calendar-1.mcom.com/sman
|
||||
* capi://jason:badguy@calendar-1.mcom.com/sman
|
||||
* capi://localhost/c|/temp/junk.ics
|
||||
* mailto:sman@netscape.com
|
||||
*
|
||||
* The component parts of a calendar URL are:
|
||||
* protocol: currently supported are CAPI, IMIP (mailto), and IRIP
|
||||
* user: the user making the access
|
||||
* password: the password for the user
|
||||
* host: the host.domain where the calendar server resides
|
||||
* port: optional, tells what port to use
|
||||
* CSID: a unique string identifying a calendar store. It
|
||||
@ -64,6 +67,8 @@ public:
|
||||
private:
|
||||
JulianString m_sCurl;
|
||||
ePROTOCOL m_eProto;
|
||||
JulianString m_sUser;
|
||||
JulianString m_sPassword;
|
||||
JulianString m_sHost;
|
||||
PRInt32 m_iPort;
|
||||
JulianString m_sCSID;
|
||||
@ -86,6 +91,8 @@ public:
|
||||
ePROTOCOL GetProtocol();
|
||||
JulianString GetProtocolString();
|
||||
JulianString GetHost();
|
||||
JulianString GetUser();
|
||||
JulianString GetPassword();
|
||||
PRInt32 GetPort();
|
||||
JulianString GetCSID();
|
||||
JulianString GetPath();
|
||||
@ -127,25 +134,64 @@ public:
|
||||
*/
|
||||
nsCurlParser& operator=(const nsCurlParser& that);
|
||||
|
||||
nsresult SetCurl(JulianString& sCurl);
|
||||
/**
|
||||
* Set the curl to the supplied string.
|
||||
* @param sCurl new calendar url for this object
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult SetCurl(const JulianString& sCurl);
|
||||
|
||||
/**
|
||||
* Set the curl to the supplied string.
|
||||
* @param psCurl new calendar url for this object
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult SetCurl(const char* psCurl);
|
||||
|
||||
/**
|
||||
* Set the protocol for this curl to one of the enumerated types
|
||||
* @param e the protocol
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult SetProtocol(ePROTOCOL e);
|
||||
nsresult SetHost(JulianString& sHost);
|
||||
nsresult SetHost(const JulianString& sHost);
|
||||
nsresult SetHost(const char* sHost);
|
||||
nsresult SetPort(PRInt32 iPort);
|
||||
nsresult SetCSID(JulianString& sCSID);
|
||||
nsresult SetUser(const JulianString& sUser);
|
||||
nsresult SetUser(const char* sUser);
|
||||
nsresult SetPassword(const JulianString& sPassword);
|
||||
nsresult SetPassword(const char* sPassword);
|
||||
nsresult SetCSID(const JulianString& sCSID);
|
||||
nsresult SetCSID(const char* sCSID);
|
||||
nsresult SetPath(const char* sPath);
|
||||
nsresult SetPath(JulianString& sPath);
|
||||
nsresult SetExtra(JulianString& sExtra);
|
||||
nsresult SetPath(const JulianString& sPath);
|
||||
nsresult SetExtra(const JulianString& sExtra);
|
||||
nsresult SetExtra(const char* sExtra);
|
||||
|
||||
/**
|
||||
* Encode any illegal characters in username, password, CSID,
|
||||
* and extra fields. No status is kept on whether or not any
|
||||
* of the fields are currently encoded or not. The encoding
|
||||
* is done blindly.
|
||||
* @result NS_OK on success
|
||||
*/
|
||||
nsresult URLEncode();
|
||||
|
||||
/**
|
||||
* Decode any illegal characters in username, password, CSID,
|
||||
* and extra fields. No status is kept on whether or not any
|
||||
* of the fields is currently decoded or not. The decoding is
|
||||
* done blindly.
|
||||
* @result NS_OK on success
|
||||
*/
|
||||
nsresult URLDecode();
|
||||
|
||||
/**
|
||||
* Filter the characters in the CSID portion of the curl so that it
|
||||
* is in acceptable format for OS specific file operations.
|
||||
* @result 0 on success
|
||||
*/
|
||||
nsresult ResolveFileURL();
|
||||
nsresult ResolveFileURL();
|
||||
|
||||
/**
|
||||
* @return a JulianString the path portion of the CSID
|
||||
@ -163,4 +209,4 @@ private:
|
||||
NS_METHOD_(char *) ResourceToFile();
|
||||
};
|
||||
|
||||
#endif /* _NS_CURL_PARSER_H */
|
||||
#endif /* _NS_CURL_PARSER_H */
|
||||
|
||||
BIN
mozilla/calendar/modules/util/inc/nsX400Parser.h
Normal file
BIN
mozilla/calendar/modules/util/inc/nsX400Parser.h
Normal file
Binary file not shown.
@ -20,17 +20,21 @@
|
||||
/**
|
||||
* This class manages a string in one of the following forms:
|
||||
*
|
||||
* protocol://host.domain[:port]/CSID[:extra]
|
||||
* protocol://[user[:password]@]host.domain[:port]/CSID[:extra]
|
||||
* mailto:user@host.domain
|
||||
*
|
||||
* Examples:
|
||||
* capi://calendar-1.mcom.com/sman
|
||||
* capi://jason:badguy@calendar-1.mcom.com/sman
|
||||
* capi://guest@calendar-1.mcom.com/sman
|
||||
* file://localhost/c|/temp/junk.ics
|
||||
* file:///c|/temp/junk.ics
|
||||
* mailto:sman@netscape.com
|
||||
*
|
||||
* The component parts of a calendar URL are:
|
||||
* protocol: currently supported are CAPI, IMIP (mailto), and IRIP
|
||||
* user: the user making the access
|
||||
* password: the password for the user
|
||||
* host: the host.domain where the calendar server resides
|
||||
* port: optional, tells what port to use
|
||||
* CSID: a unique string identifying a calendar store. It
|
||||
@ -113,6 +117,8 @@ void nsCurlParser::Init()
|
||||
{
|
||||
m_eProto = eUNKNOWN;
|
||||
m_sHost = "";
|
||||
m_sUser = "";
|
||||
m_sPassword = "";
|
||||
m_iPort = -1;
|
||||
m_sCSID = "";
|
||||
m_sExtra = "";
|
||||
@ -144,6 +150,17 @@ void nsCurlParser::Assemble()
|
||||
{
|
||||
m_sCurl = GetProtocolString();
|
||||
m_sCurl += "://";
|
||||
if (m_sUser != "" || m_sPassword != "")
|
||||
{
|
||||
if (m_sUser != "")
|
||||
m_sCurl += m_sUser;
|
||||
if (m_sPassword != "")
|
||||
{
|
||||
m_sCurl += ":";
|
||||
m_sCurl += m_sPassword;
|
||||
}
|
||||
m_sCurl += "@";
|
||||
}
|
||||
m_sCurl += m_sHost;
|
||||
if (m_iPort > 0)
|
||||
{
|
||||
@ -154,7 +171,7 @@ void nsCurlParser::Assemble()
|
||||
m_sCurl += m_sCSID;
|
||||
if (m_sExtra != "")
|
||||
{
|
||||
m_sCurl += ":";
|
||||
m_sCurl += "#";
|
||||
m_sCurl += m_sExtra;
|
||||
}
|
||||
m_bAssemblyNeeded = PR_FALSE;
|
||||
@ -231,19 +248,48 @@ void nsCurlParser::Parse()
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for a port number. If it's there, we have a host of the form
|
||||
* host.domain:port
|
||||
* Check for a username, password, and port number.
|
||||
* The general form for the host part is:
|
||||
* <username>:<password>@<host>.<domain>:<port>
|
||||
*/
|
||||
if (m_sHost != "")
|
||||
{
|
||||
iHead = m_sHost.Find(':',0);
|
||||
if (iHead > 0)
|
||||
int iTmpHead, iTmpTail;
|
||||
/*
|
||||
* Look for a username/password. If it is present there
|
||||
* will be an '@' character.
|
||||
*/
|
||||
iTmpHead = m_sHost.Find('@',0);
|
||||
if (iTmpHead > 0)
|
||||
{
|
||||
m_sUser = m_sHost.Left(iTmpHead);
|
||||
/*
|
||||
* There may be a password embedded in the user name...
|
||||
*/
|
||||
iTmpTail = m_sUser.Find(':');
|
||||
if (iTmpTail >= 0)
|
||||
{
|
||||
m_sPassword = m_sUser.Right(m_sUser.GetStrlen()-iTmpTail-1);
|
||||
m_sUser.GetBuffer()[iTmpTail] = 0;
|
||||
m_sUser.DoneWithBuffer();
|
||||
}
|
||||
|
||||
JulianString sTemp = m_sHost.indexSubstr(iTmpHead+1,m_sHost.GetStrlen());
|
||||
m_sHost = sTemp;
|
||||
}
|
||||
|
||||
/*
|
||||
* look for a port number. If it is present there will
|
||||
* be a ':' present.
|
||||
*/
|
||||
iTmpHead = m_sHost.Find(':',0);
|
||||
if (iTmpHead > 0)
|
||||
{
|
||||
int iPort;
|
||||
if (1 == sscanf( m_sHost.GetBuffer(),"%d",&iPort))
|
||||
{
|
||||
m_iPort = iPort;
|
||||
m_sHost.GetBuffer()[iHead] = 0;
|
||||
m_sHost.GetBuffer()[iTmpHead] = 0;
|
||||
m_sHost.DoneWithBuffer();
|
||||
}
|
||||
}
|
||||
@ -264,14 +310,48 @@ void nsCurlParser::Parse()
|
||||
if (m_sCSID.GetStrlen() > (size_t)iHead)
|
||||
{
|
||||
m_sExtra = m_sCSID(iHead, m_sCSID.GetStrlen());
|
||||
m_sCSID.GetBuffer()[iHead] = 0;
|
||||
m_sCSID.GetBuffer()[iHead-1] = 0;
|
||||
m_sCSID.DoneWithBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
//m_sCurl = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode any illegal characters in username, password, CSID,
|
||||
* and extra fields. No status is kept on whether or not any
|
||||
* of the fields are currently encoded or not. The encoding
|
||||
* is done blindly.
|
||||
* @result NS_OK on success
|
||||
*/
|
||||
nsresult nsCurlParser::URLEncode()
|
||||
{
|
||||
m_sUser.URLEncode();
|
||||
m_sPassword.URLEncode();
|
||||
m_sCSID.URLEncode();
|
||||
m_sExtra.URLEncode();
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decode any illegal characters in username, password, CSID,
|
||||
* and extra fields. No status is kept on whether or not any
|
||||
* of the fields is currently decoded or not. The decoding is
|
||||
* done blindly.
|
||||
* @result NS_OK on success
|
||||
*/
|
||||
nsresult nsCurlParser::URLDecode()
|
||||
{
|
||||
m_sUser.URLDecode();
|
||||
m_sPassword.URLDecode();
|
||||
m_sCSID.URLDecode();
|
||||
m_sExtra.URLDecode();
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -288,7 +368,7 @@ JulianString nsCurlParser::GetCurl()
|
||||
* Set a new value for this Curl. Parse it into its component parts
|
||||
* @return 0 = success
|
||||
*/
|
||||
nsresult nsCurlParser::SetCurl(JulianString& sCurl)
|
||||
nsresult nsCurlParser::SetCurl(const JulianString& sCurl)
|
||||
{
|
||||
m_sCurl = sCurl;
|
||||
Parse();
|
||||
@ -449,10 +529,76 @@ JulianString nsCurlParser::GetProtocolString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the host for this curl
|
||||
* Set the user for this curl
|
||||
* @param sUser the user name
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult nsCurlParser::SetHost(JulianString& s)
|
||||
nsresult nsCurlParser::SetUser(const JulianString& sUser)
|
||||
{
|
||||
m_sUser = sUser;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user for this curl
|
||||
* @param sUser the user name
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult nsCurlParser::SetUser(const char* sUser)
|
||||
{
|
||||
m_sUser = sUser;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user name
|
||||
* @result an JulianString containing the current user name.
|
||||
*/
|
||||
JulianString nsCurlParser::GetUser()
|
||||
{
|
||||
if (m_bAssemblyNeeded)
|
||||
Assemble();
|
||||
return m_sUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the password for this curl
|
||||
* @param sPassword the password
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult nsCurlParser::SetPassword(const JulianString& sPassword)
|
||||
{
|
||||
m_sPassword = sPassword;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsresult nsCurlParser::SetPassword(const char* sPassword)
|
||||
{
|
||||
m_sPassword = sPassword;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user name
|
||||
* @result an JulianString containing the current user name.
|
||||
*/
|
||||
JulianString nsCurlParser::GetPassword()
|
||||
{
|
||||
if (m_bAssemblyNeeded)
|
||||
Assemble();
|
||||
return m_sPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the host for this curl
|
||||
* @param s the host name
|
||||
* @return 0 on success
|
||||
*/
|
||||
nsresult nsCurlParser::SetHost(const JulianString& s)
|
||||
{
|
||||
m_sHost = s;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
@ -495,13 +641,10 @@ nsresult nsCurlParser::SetPort(PRInt32 iPort)
|
||||
* Set the CSID (the calendar store id) for this curl
|
||||
* @result 0 on success
|
||||
*/
|
||||
nsresult nsCurlParser::SetCSID(JulianString& s)
|
||||
nsresult nsCurlParser::SetCSID(const JulianString& s)
|
||||
{
|
||||
if ( m_sCSID.CompareTo(s,PR_TRUE))
|
||||
{
|
||||
m_sCSID = s;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
}
|
||||
m_sCSID = s;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -607,7 +750,7 @@ nsresult nsCurlParser::SetPath(const char* p)
|
||||
*
|
||||
* @return 0 success
|
||||
*/
|
||||
nsresult nsCurlParser::SetPath(JulianString& s)
|
||||
nsresult nsCurlParser::SetPath(const JulianString& s)
|
||||
{
|
||||
return SetPath(s.GetBuffer());
|
||||
}
|
||||
@ -663,13 +806,10 @@ nsresult nsCurlParser::ResolveFileURL()
|
||||
* Set the extra info
|
||||
* @return 0 success
|
||||
*/
|
||||
nsresult nsCurlParser::SetExtra(JulianString& s)
|
||||
nsresult nsCurlParser::SetExtra(const JulianString& s)
|
||||
{
|
||||
if ( m_sExtra.CompareTo(s,PR_TRUE))
|
||||
{
|
||||
m_sExtra = s;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
}
|
||||
m_sExtra = s;
|
||||
m_bAssemblyNeeded = PR_TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user