Index: .darcs_binaries =================================================================== --- .darcs_binaries (.../vendor/psi/psi-0.10) (revision 39233) +++ .darcs_binaries (.../trunk/im/psi-0.10) (revision 39233) @@ -1,41 +0,0 @@ -# Binary file regexps: -\.png$ -\.PNG$ -\.gz$ -\.GZ$ -\.pdf$ -\.PDF$ -\.jpg$ -\.JPG$ -\.gif$ -\.GIF$ -\.tar$ -\.TAR$ -\.bz2$ -\.BZ2$ -\.z$ -\.Z$ -\.zip$ -\.ZIP$ -\.jar$ -\.JAR$ -\.so$ -\.SO$ -\.a$ -\.A$ -\.tgz$ -\.TGZ$ -\.jpeg$ -\.JPEG$ -\.mpg$ -\.MPG$ -\.mpeg$ -\.MPEG$ -\.iso$ -\.ISO$ -\.exe$ -\.EXE$ -\.doc$ -\.DOC$ -\.jisp$ -\.JISP$ Index: ChangeLog =================================================================== --- ChangeLog (.../vendor/psi/psi-0.10) (revision 39233) +++ ChangeLog (.../trunk/im/psi-0.10) (revision 39233) @@ -1,678 +0,0 @@ - -2005-08-22, Kevin Smith - Made the auto-expanding text input the default. - -2005-08-22, Remko Troncon - Added a UI option for auto-resizing text input. - - Added a message dialog suggesting you should restart. - - Fixed Mac OS X focus problem in GC dialog. - This is the same patch as the earlier one for the chat dialog. - - Reverted Fran's checkboxes for every sound event. (due to bugs) - - Agents now get other types of initial presence as well (FS#464). - Patch by IceRAM. - - Fixed authorization ping-pong issue. - Upon automatically granting authorzation, Psi no longer requests auth - when the subscription is already To or Both. - -2005-08-21, Michail Pishchagin - Fixed single-line edit. Now it should behave ok when pasting large chunks - of text at a time. - -2005-06-24, Remko Troncon - Added an option to set roster & chat dialog opacity (Win & Mac) - - Moved Misc. Appearance options to a separate tab - -2005-06-23, Remko Troncon - Added new appearance tweak options: - The group headings and account headings can now be assigned separate - foreground and background colours. - The group headings can now be set in 'slim' mode from the options dialog. - The outline of the headings can be toggled. - -2005-06-21, Remko Troncon - Hide unavailable platform-specific options from the UI - - Added 'Dock Bounce' option to the options dialog - - Changed 'MacOS X' into 'Mac OS X' here and there - -2005-06-19, Remko Troncon - Clarified the JID field of the 'Register Account' dialog - -2005-06-14, Remko Troncon - Mac OS X Dock icon changes: - Added an option to bounce the dock once/never/forever. - Added an overlayed event count to the dock icon. - -2005-06-08, Remko Troncon - Separate checkboxes for every sound event + global checkbox in options - dialog. Patch by Fran. - -2005-05-24, Kevin Smith - Finally fixed that tabs bug that could cause segfaults and strange behaviours - -2005-05-14, Remko Troncon - Updates to the About Dialog - - Fixed a memory leak in the Growl notification popups - - Change Gadu-Gadu version string to the registered one (patch by - Maciek Niedzielski) - - Fixed Mac OS X focus problems in the Chat Dialog - - Flattened account context menu - - Moved 'Check Status' dialog into the 'User Info' (VCard) dialog - - Merged all iconset tabs into the appearance tab - Applied Kris Vandenbroek's fix for the iconset tabs - Misc. iconset details dialog improvements - - Added 'Chat' button to the event dialog - - Cleaning up the Account Dialog - -2005-05-04, Kevin Smith - Changed the default from off to on for the previous patch - -2005-05-01, Remko Troncon - Added an option to be notified of receiving authorization. Turned off by - default (as in about every IM client out there). In combination with - 'auto-authorize', this makes a temporary solution for clean registration - with transports. - -2005-04-16, Remko Troncon - Support clicking on Growl notifications. Fix some possible memory leaks - in GrowlNotifier. - -2005-04-14, Remko Troncon - Translated all the Growl strings. - -2005-04-14, Remko Troncon - Modified the VCard dialog to enable displaying and setting of the photo - field (patch by Fran Rodrguez) - -2005-04-12, Kevin Smith - Commiting Remko's growl patch. Strings aren't properly translated, he'll - have to fix this sometime - -2005-04-07, Kevin Smith - Committed a Linux From Scratch detection patch by Christopher Beppler - -2005-04-07, Kevin Smith - Committed Remko's avatars patch to enable people to work on a central - codebase. - -2005-03-29, Kevin Smith - Machekku's selection Auto-copy patch. - -2005-03-22, Michail Pishchagin - Updated roster auto-resize code. Now it should work for toggling self - contact too. - -2005-03-12, Michail Pishchagin - Fixed bug: when loading eventqueue. If account name for event is not - specified or incorrect, it's unable to display that message. - -2005-03-09, Michail Pishchagin - Now, appending lines to the history files would not require index. - Thus, major speedup. - -2005-03-05, Michail Pishchagin - Ctrl-I shortcut will now trigger VCard dialog in MainWin, ChatDlg and - EventDlg. - - Single-line edit should now work fine in tabbed chats too. - -2005-02-28, Kevin Smith - Added icons and close buttons to each tab, getting rid of the unsightly one - in the corner. - -2005-02-28, Kevin Smith - Added the option to have tabs at the bottom of windows instead, and - added drag and drop between tab windows. - -2005-02-28, Kevin Smith - Patch by PSZ to make Psi remember the last-used paths for file dialogs - on exit. - -2005-02-24, Michail Pishchagin - Now Shift+Space and Ctrl+Shift+Space global shortcuts should work on - Linux too. And the GlobalAccel feature should now be used by everyone ;) - -2005-02-22, Kevin Smith - Remko's patch for the mac menu. - -2005-02-20, Michail Pishchagin - Psi won't stick to hidden windows anymore. - - Now, config.xml should not be saved when processing new events. - - Slightly better auto-roster-resizing on account enabling/disabling. - -2005-02-13, Michail Pishchagin - New AdvancedWidget template class, which implements sticking to screen - edges, and to other top-level widgets of the same app. Also implements - taskbar flashing. Chat, GroupChat, MainWin, Message dialogs are now - AdvancedWidget-enabled. - -2005-02-13, Kevin Smith - Newer version of the tabs code. Hopefully now it'll compile on non-linux without problems - -2005-02-13, Kevin Smith - Remko's menubar patch - -2005-01-23, Kevin Smith - Remko's memory leak in eventdb patch - -2005-02-06, Michail Pishchagin - New autoRosterSize option, which automatically resizes your roster window - to fit as many contacts as possible. Please test it well ;) - - Automatically resolve names of newly added contacts, if they don't have - assigned name yet. Could be useful when ICQ Transport is configured to - automatically add ICQ users to your roster. Also it could save you some - time, clicking the Resolve button if you want to keep default nickname. - -2005-01-30, Michail Pishchagin - Groupchat with single-line edit enabled would no longer be unneedlessly - resized during nick completion. - -2005-01-29, Michail Pishchagin - Small chats now have effect on groupchats too. As well as single-line edit. - - Mac: In single-line enabled chats and groupchats, the lineedits would be - paned by empty space from left and right and also would be centered. - -2005-01-27, Michail Pishchagin - Now scrollbar in single-line chat edit should no longer flicker. - -2005-01-26, Michail Pishchagin - Reduced flickering in single-line edit. Removed horizontal scrollbar. - Does not resize the dialog when it takes more than 90% of desktop's - area. - -2005-01-24, Michail Pishchagin - Experimental single-line edit in chat dialog. Seems to be useable. - -2005-01-17, Kevin Smith - Basic tab support. DO NOT USE THIS YET. - -2005-01-09, Kevin Smith - Added the SystemWatch stuff for power saving notification on windows and osx - -2005-01-09, Michail Pishchagin - Now IconButton class would try to specify icon using QIconSet whenever - possible, what should improve the looks of disabled buttons. - - Now Process Next Event would process events from a non-DND account prior - to the DND one. - - On MacOS, Psi dock icon would no longer bounce on messages from DND accounts. - - Global Shortcuts patch by GreyCat. At the moment, if you want it, you - should configure the keys by editing the config.xml file. - ----- Psi 0.9.3 Release ---- - -2005-01-08, Kevin Smith - Minor compiler error fix, and Release 0.9.3 - -2004-12-28, Kevin Smith - Two patches, one various x:data fixes, and the other a fix for the accounts - combobox, which now only includes available accounts. - Thanks to Remko for both. - -2004-11-20, Kevin Smith - Minor change of defaults (particularly colour scheme on OSX) and removal of - ugly bar when there's no scrollbars on OSX (Thanks Remko). - -2004-11-19, Kevin Smith - GUI option for smallChats (thanks Pintail). Various string consistencies and - clarifications (thanks Remko). New Mac build scripts (thanks Remko) - -2004-11-19, Kevin Smith - Previously enabling "Ignore events from non-roster contacts" ignored private - groupchat messages, now it doesn't (although there's an xml option to revert) - -2004-10-31, Michail Pishchagin - Corrected the name of AlertIcon class (it messed up the caching of - MTray icons). - - QPixmapTray will be cleared on iconset change. - - IceRAM's patch for beauty tray icons on Linux. - -2004-10-29, Kevin Smith - Committed Misha's fix to the MTray segfaults. - Fixed the Segfault when a contact went offline during regrouping. - -2004-10-28, Kevin Smith - Windows 2003 detection code added. (MichalJ) - QT Translations (Skazi) - -2004-10-20, Michail Pishchagin - Message events patch by Remko Troncon. - - No toolbars on Mac by default by Remko Troncon. - -2004-10-11, Michail Pishchagin - http://ftp.xiaoka.com/friends/skazi/psi/patches/ - psi-tooltip_version_noslash-mod.diff - -2004-10-03, Michail Pishchagin - Another set of patches by Remko: - - * Ability to disable online accounts, in which case a dialog will pop - up. - * Ability to enter empty status messages. - * Removed badly-looking icons on Mac. - * Some changes in menu layout on Mac. - * Modifications to system iconset, so there will be different icons - for Roster and Advanced tabs in options. - -2004-09-24, Michail Pishchagin - Corrected 'Use Sounds' setting loading. Thanks to Marcel Naziri for - writing a fix! - -2004-09-06, Michail Pishchagin - Dynamic 'avatars', 'vcard' and 'history' directory recreation, and - removal of unused 'info' dir. - -2004-08-18, Michail Pishchagin - TrayIcon correction by William Waghorn, so it should work correctly - on Gnome from now on. But there'll be dependency on PsiApplication :-/ - - Disabled the unfinished avatar support in preparations for 0.9.3 - release. Patch by Remko. - -2004-08-16, Michail Pishchagin - Small fix for default profile by Remko. - - Created general-like menu on MacOS by Remko. - -2004-08-12, Michail Pishchagin - Now tooltip of account will display number of online contacts and - total number of contacts in roster by Remko. - - Fixes to the Mac menu by Remko. - -2004-08-09, Michail Pishchagin - Now IconAction should correctly remove unnecessary cached QPopupMenu - pointers, and shouldn't crash. - -2004-08-08, Michail Pishchagin - Major speedup when parsing disco#items results in Service Discovery - dialog. - -2004-08-05, Michail Pishchagin - Now MainWin uses new action customization framework. Test it, break it, - fix it :-) - -2004-08-03, Michail Pishchagin - Now ShowSelf action will be shown in the mac menu too - (thanks to Remko, as usual) - -2004-08-02, Michail Pishchagin - Ability to initiate file transfers by dropping files in the ChatDlg - by Remko: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/filetrans-chatdlg_psi.diff - - Fixed joining groupchat rooms by Remko: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/accountscombobox-fix_psi.diff - http://www.cs.kuleuven.ac.be/~remko/psi/patches/eventdlg-onlineonly_psi.diff - - Selfcontact action + account tip by Remko: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/selfcontact+accounttip_psi.diff - -2004-07-25, Michail Pishchagin - Changed the toolbars configuration format in config.xml. Do not use - older Psi's after upgrading to this one, or your toolbar configuation - will be lost! - -2004-07-18, Michail Pishchagin - x:data support for iq:register dialog. - x:data support for iq:search dialog. - - SkaZi's offline status message patch. - - Default profile Remko's patch: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/defaultprofile_psi.diff - - Select only online accounts in Join Groupchat dialog by Remko: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/groupchat-onlineonly_psi.diff - -2004-07-14, Michail Pishchagin - Avatar patch by Remko: - * Added new icons & updated others - * When a new VCard is retrieved, the corresponding avatar is updated - automatically - * Added run-time options for avatars (enable switch + dimension) - * Added 'Clear avatar' context menu. Grouped avatar-related context menu - in 1 popup. - * When there is no avatar, show no avatar (instead of showing a default one) - * When a contact is removed, remove its associated avatar too. - * Comments are now Psi-style - -2004-07-11, Michail Pishchagin - Support for getting VCard image as avatar by Remko. - -2004-07-10, Michail Pishchagin - Improved the avatar in the tooltip appearance somewhat. - Thanks to IceRAM. - - Now CVS builds will be timestamped. - -2004-07-09, Michail Pishchagin - Fixed crash in groupchat's rosters' tooltips. Thanks, Remko! - -2004-07-08, Michail Pishchagin - Now status buttons should have effect on connecting accounts too. - -2004-07-07, Michail Pishchagin - Now ChatDlg uses toolbar to display it's toolbuttons. Later it should - become customizeable!! - -2004-07-05, Kevin Smith - Added Passive Popup for file transfers: - ftp://ftp.patryk.one.pl/pub/windows/siec/psi/selfmade/patches/psi-popup_file.diff - -2004-07-05, Kevin Smith - Added Skazi, Remko, Hal and IceRam to the thanks page of the about dialog. - Thanks Guys. - - Added support for static (locally defined) avatars. Haven't added a toggle - yet, I'm waiting to see if anyone actually *doesn't* want it. - -2004-07-01, Michail Pishchagin - Show 'Insert Emoticon' toolbutton in chat dialog when it's not in compact - mode: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/chatdlg-emot_psi.diff - - Smart change status button: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/statuschange_psi.diff - - Now dragging multiple files at once will result in many FT dialogs. - Thanks to Remko Troncon ;-) - - Now Service Disovery dialog uses PsiToolBar. - -2004-06-30, Michail Pishchagin - Added 'Get vCard' and 'Resolve Nick' buttons to the Add new user dialog. - Removed 'XML Console' from 'Psi' menu. - - Fixed translations of compact chat mode: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/chatdlg-menu_psi.diff - - Drag-n-Drop support for File Transfer: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/dragdropfile_psi.diff - - Mac menu: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/macmenu_psi.diff - - Mac roster grip: - http://www.cs.kuleuven.ac.be/~remko/psi/patches/macstatusbottom_psi.diff - -2004-06-14, Michail Pishchagin - Now Psi wouldn't load successfully with the absent default icons. - ----- Psi 0.9.2 Release ---- - -2004-06-05, Michail Pishchagin - Added 'Psi Handbook' entry to the Help menu. - -2004-05-29, Michail Pishchagin - Fixed Tip of The Day's What's This string. - -2004-05-26, Michail Pishchagin - Fixed tab order in Sound tab in Options dialog. - -2004-05-04, Justin Karneges - Added file transfer manager. - -2004-05-04, Michail Pishchagin - Fixed a bug, when you had some popups on the screen, and quitted psi, - it always segfaulted. - -2004-05-01, Michail Pishchagin - Added "Incoming File Transfer" and "File Transfer Complete" sounds to the - Sound tab in Options dialog and common.h. - Now it's up to Justin to actually use them :) - - Now sounds from iconsets shouldn't be played when sounds are disabled. - - Hopefully fixed the 'next' button's icon on non-X11 platforms. - - Fixed line endings in Export History dialog. - -2004-04-30, Michail Pishchagin - ed2k:// patch by SkaZi. - - Bug with IRC gateway icon and Service Discovery dialog. - - Added selection of Popup Font. - - New looks of Appearance tab in the Options dialog. - -2004-04-18, Michail Pishchagin - Added conference/irc type to the list of known disco identities. - Now the disco dialog should display IRC gate icon just ok. - -2004-04-05, Michail Pishchagin - The bug-reporting patch by SkaZi. - (http://psi.affinix.com/flyspray/index.php?do=details&id=238) - -2004-04-04, Michail Pishchagin - Update the (C) year in About dialog to 2004. - -2004-04-01, Michail Pishchagin - Added the Transfer Manager action to the main window. - -2004-03-30, Michail Pishchagin - Now chat and event dialogs do not linkify the status tooltips of the - contact. - - Now service discovery dialog should be able to search JUD on jabber.org - (since it started to support Service Discovery) when protocol is set - to A (Auto) or D (Disco). - - Now Psi shouldn't crash on exit with the ~PsiTextView as the cause. - -2004-03-25, Michail Pishchagin - Fixed the slotScroll() slot in GroupChat dialog, and scrolling to bottom - should actually work now. - -2004-03-18, Michail Pishchagin - Now type ahead in contact view will reset after 3 seconds of inactivity. - -2004-03-16, Michail Pishchagin - Bug: Groupchat dialog was not always scrolled to bottom. Fixed now. - -2004-03-15, Justin Karneges - New history features: erase all and export to friendly text. - -2004-03-15, Michail Pishchagin - Delete old settings in HKLM on Windows systems. - -2004-03-12, Michail Pishchagin - Updated default icons (they're now made smaller in size, all thanks to - Piotr Iwo Skrodzewicz). - - Added --nocrash command-line option. - -2004-03-10, Michail Pishchagin - Fixed silly bug when loading sort style for contacts in roster. - - Added ArchLinux to the list of detectable Linux distrox (thanks to IceRAM). - -2004-03-08, Michail Pishchagin - Now 'crash' support will not be built-in by default. - - Fixed bug in disco dialog, when doing Refresh Item on parent item, its - child loses all features and identities. - -2004-03-03, Justin Karneges - ContactView shortcuts were broken, fixed. - 'configure' updated to not bundle qxml unless necessary. - -2004-03-03, Michail Pishchagin - Small code cleanup by SkaZi - -2004-03-02, Justin Karneges - Data transfer settings - -2004-02-29, Michail Pishchagin - Added vertical splitter to the groupchat dialog (thanks to IceRAM for the - hint) - - Now Psi should compile with Qt 3.1.x on Windows again - -2004-02-28, Michail Pishchagin - Now only one trackbar exists at a time in groupchat dialog (patch by - Bastian Hoyer) - -2004-02-27, Michail Pishchagin - Reverted the hide/show roster code to the old one, which was used in 0.8.7 - -2004-02-26, Michail Pishchagin - Fixed replying to replied plain messages. In 0.9.1 subject became empty - in that case. - -2004-02-25, Michail Pishchagin - Real fix for now: Now in nick-completion the space is not added when - completion is not at the start of the string (thanks to IceRAM for the - hint) - -2004-02-23, Kevin Smith - Added an xml option to have the xml console visible and enabled at login. - Some people wanted this for debugging. - -2004-02-23, Michail Pishchagin - Fixed the emoticonify function: now it will correctly handle this case: - ";-) - :-P(blah-blah-blah)" - - Now MainWin's position will not be saved, if the X or Y coordinate is - fever than -30000 (I think that it should work, but it needs testing). - - Now IconSelect can take up to 3/4 of the screen's - MIN(screen.width, screen.height). - -2004-02-21, Michail Pishchagin - Now in nick-completion the space is not added when copletion is not at - the start of the string (thanks to IceRAM for the hint) - - Now Psi should be able to load attachments from messages that it saved - to the event queue on the disk (thanks to SkaZi for the patch) - -2004-02-16, Kevin Smith - Added a trackbar to the groupchat dialog - -2004-02-16, Michail Pishchagin - Fix for nick completion bug in groupchat dialog, which showed only - when there were people with identical-starting nicks, but in other - cases (ex: IceRAM vs. infiniti) - - "Crash" patch by Juan F. Codagnone. - -2004-02-13, Michail Pishchagin - Fix for type ahead by Juan F. Codagnone. - -2004-02-11, Michail Pishchagin - Fix for crash on startup if iconset could not be loaded. (thx to SkaZi) - - Fix for multiline descriptions in url attachments by SkaZi. - - Fix for text color in groupchat dialog by SkaZi. - -2004-01-27, Michail Pishchagin - Event queue sorting patch by SkaZi. - -2004-01-26, Michail Pishchagin - Received messages are now queued to disk - (to PsiDataDir/profiles/profilename/events-accountname.xml) - -2004-01-25, Michail Pishchagin - Hidden group patch by SkaZi. - -2004-01-25, Michail Pishchagin - Updated EventQueue saving/loading code (but it's still not perfect, - though). - -2004-01-23, Michail Pishchagin - Fixed a bug in PsiIconset::Private::loadIconset(): If original icon have - Anim, and new icon doesn't have Anim, old Anim was not deleted, which - caused incorrect animations to appear (example: psi/chat icon in - LightBulb iconset). - -2004-01-21, Michail Pishchagin - Small fix to the resource search path under Windows. - -2004-01-21, Michail Pishchagin - Patch by Juan F. Codagnone: - This patch was called originaly "miranda like type-ahead patch" after the - Mozilla's and Miranda IM's feature. It lets you go to any contact in your - roster, typing his name. (at the moment, in psi, when you want to search for - some one, you need to type the first character of the nickname you are - searching for). - -2004-01-19, Michail Pishchagin - Moved Configure Toolbars out of main Psi menu, to the toolbars' own - context menus. - -2004-01-17, Michail Pishchagin - Tip of the Day is back! Please contribute your useful tips and tricks, - so they will be there in 0.9.2 ;) - -2004-01-17, Michail Pishchagin - Fixed grammar, spelling, and other errors/typos in translatable - strings (in psi/src/options). - -2004-01-16, Michail Pishchagin - now Sound Player option is separated to tokens by the ' ' (space) char. - it is possible to use complex sound player commands now. - Patch by "wwp " - -2004-01-11, Kevin Smith - XML option to turn off the numbers in group headers. - -2004-01-10, Michail Pishchagin - Added nick-completion in Groupchat dialog. Press Tab key to complete and - to iterate through the nicks - -2004-01-06, Kevin Smith - Accounts can now be enabled and disabled in account settings (Skazi's - patch) - -2004-01-05, Kevin Smith - Emoticonified text now also shows *text* as bold, /text/ as italic, - and _text_ as underlined. - -2004-01-05, Kevin Smith - Support for multiple contact adds from the services dialog (Mike - Fawcett (deviant)) - -2004-01-04, Kevin Smith - Started this ChangeLog. - - Presets in status dialog are now sorted alphabetically. (Skazi's patch) - Status Dialog has a tickbox to save the status message as a preset (Remko's Patch) - Seperated headlines from messages for sound and popups. - -2003-01-03, Kevin Smith - Small chat support, there's a global default in the config (no option yet) and - right click per-dialog - -2004-01-02, Michail Pishchagin - Service registration dialog corrections by SkaZi: - - 'register' is the default button - - first line in form is focused - ----- Psi 0.9.1 Release ---- Index: psi.desktop =================================================================== --- psi.desktop (.../vendor/psi/psi-0.10) (revision 39233) +++ psi.desktop (.../trunk/im/psi-0.10) (revision 39233) @@ -1,28 +0,0 @@ -[Desktop Entry] -Type=Application -Version=0.9.4 -Encoding=UTF-8 -Name=Psi -GenericName=Jabber Client -Comment=Communicate over the Jabber network -Icon=psi -Exec=psi -Terminal=false -Categories=Qt;Network;InstantMessaging; -StartupNotify=true - -# Translations -GenericName[nl]=Jabber Client -Comment[nl]=Communiceer over het Jabber netwerk -GenericName[sl]=Odjemalec za Jabber -Comment[sl]=Komuniciranje prek omrežja Jabber -GenericName[mk]=Клиент за Jabber -Comment[mk]=Комуницирајте преку Jabber мрежата -GenericName[ca]=Client Jabber -Comment[ca]=Comuniqui's a través de la xarxa Jabber -GenericName[eo]=Ĵabbera Klientilo -Comment[eo]=Komunikiĝu per la ĵabbera reto -GenericName[pl]=Klient Jabber -Comment[pl]=Komunikacja poprzez sieć Jabber -GenericName[pt_BR]=Cliente Jabber -Comment[pt_BR]=Comunique-se através da rede Jabber Index: TODO =================================================================== --- TODO (.../vendor/psi/psi-0.10) (revision 39233) +++ TODO (.../trunk/im/psi-0.10) (revision 39233) @@ -1,201 +0,0 @@ -Required - File Transfer - XML Encryption - add status message presets from the statussetdlg - Ability to prompt for status message when choosing "Offline" (signoff status) - ability to flag accounts as enabled/disabled. disabled means they are not usable and won't show in roster. - groupchat should log presence changes - gcuserview: proper sorting of contacts based on status / alphabetical (like ContactView) - message events (composing, delivery, etc) - misha: JEP-0038: emoticon sets - server info: - show server version in tooltip - ssl information dialog (show cert and maybe connection info) - separate message history / info for each account - eventQueue: toXml, fromXml (for saving unread messages) - local contact settings: - checkboxes for accepting various things: messages; files; URLs; chats \ - [each has a checkbox option: only from my contact list, or... only from this GROUP on my contact list] - be alerted when the contact changes status or comes online (etc) - option: ignore headline messages (die MSN) - annotations (notes about the user) - log history or not - activity log window - high level logging of connection status, presence changes, messages - timestamps - "find" feature - Richtext messages - revamp history system: ability to restore entire chats, show in normal order, not reverse - "properties" dialog (could be last entry in cvlist context) for setting groups and subscription, etc. \ - it could also show client time / version - file downloading - nice dialog - after file received, there should be the options: "Open" and "Open folder" - put each received file into a folder for the contact (optional) - if a specific directory is chosen, the dialog should have a history of the most recent download \ - folders (10 maybe?) - Advanced Alerts (sound, popups, etc) - Ignore list - plugin system - -Important - clicking on a chatdlg when bringing focus should always set focus to the input widget (eat the click) - 'find' feature for chatdlg - checkbox to keep eventdlg open (both send and recv). for send, it should reset the content after sending. - statussetdlg should automatically click ok in 10 seconds (unless you press a key) - ability to flag which accounts are affected by the mass status change button (should be in account context menu) - cv: remember the open/closed state of groups - cv: group headings should have a better design than just a rectangle (gradient?) - add "Go to Website" and x:oob in presence - use arts for sound on unix (or custom, for things like "play") - ability to do various iq requests to arbitrary jids: version, time, info - multi-monitor support: windows should pop up on the same display as the main window? - "last seen" time for contacts - emoticon menu button - merge all contacts into one column, rather than dividing by account - consolidated contacts - send contacts - save/load contacts (hint: use QCheckListItem for dialogs) - exporting - dialog for selecting contacts to export to file - write to file - importing - import a list from file - dialog for selecting contacts to import - tell the server about the new contacts - check for dups - offline animation (door slam) - chathistorydlg - a nice window to display chat history - maybe a menubar with some features like "save to file" ? - show/hide times - show/hide/rename other person (for privacy) - WM dock - floating contacts (controlled by cvlist?) - full message archive dialog (tree/explorer view for choosing contacts on left, display area on the right). - Update all (mass user info check) - Detecting network connection status. option to auto-connect when network is available. - startup argument to select profile - ability to execute a shell command on event - option to display (in realtime) the cvlist as 'flat', ie without groups - voice chat - option to launch on startup (platform dependent, good luck) - different color choices for different group types - transport-specific roster icons - deal with presence errors when subscribing - command line args? psi.exe --psi-data dir - have separate status presets depending on the status type - -Extra - there should be a way to copy a url to clipboard from the eventdlg attachment - ability to flag a contact or group to always be shown even if they would not be (due to visibility toggles) - how about adding "Add Contact", "New Blank Message", "Manage services" and "Join Groupchat" to the cv \ - rightclick menu for each of the servers? - allow eventdlg and chatdlg inputs to drag / drop URLs (in both directions) - chatdlg separator: "snap" to font height? - transport iconsets (misha?) - translation packs for the Qt library itself?? - check to see if app is already running when launched. if it is, then: - ask if they really want to open it again - if they say yes, then disable auto-open for profiles - save presence changes to history? - win32: docking (all optional) - grapple to edge of screen, like ICQ for windows - auto hide: after a certain period of inactivity, "slide" the window off the screen - auto hide delay: time to wait before sliding off - right-click in chat/eventdlg should have options to paste your current URL or IP address - Avatars (Buddy Icons) - KDE-enhanced mode - "previous" button in the eventdlg? - Autoresponses? (with general and customized texts) - auto close chat windows that are not in focus after so many minutes of inactivity - The Main Window's Icon should change when new messages arrive, just like the dock icon does. - Ability to filter messages based on words (maybe even shell command filters) - Ability to compose messages and send at a later specific date (or when you or the recipient go online) - option to autohide main roster window after a set period of time - supporting BOLD and ITALIC in jabber msges by using * and / like you do in newsgroups .. - Licq supports replacing some %s with information on the sender of the - message and other things. (There's a list below) IT supports these in - OnEvent, auto responses (check status), and utilities - For example: sound player "~/scripts/say", on message "%a has just sent you an I.C.Q. message" - %a - user alias - %e - email - %f - first name - %h - phone number - %i - user ip - %l - last name - %m - # pending messages - %n - full name - %o - last seen online - %O - online since - %p - user port - %s - full status - %S - abbreviated status - %u - uin - %w - webpage - Ability to specify an arbitrary time for chatdlgs to stay active (x minutes/hours/days) - "small mode" - put mainwin buttons (and toolbuttons) into the cvlist right-click - option to have sounds not play when XA (but still play when Away) - option to have mainwin/dock status follow a specific account rather than "best choice" - option to show status message in parenthesis to the right of the contact (like yahoo) - ability to "auto-reconnect" to a transport? - cv: let the user choose how the list is sorted - Spell check - pictures for users - group ideas: - option: sort or not - choose order of groups and contacts with drag and drop - save order on the server - support empty groups that get removed on signoff - Have a way of marking some people as 'important' contacts, so they will always trigger sound - psuedo-chat support like Mirabilis ICQ / Licq (ie, split window, but still used like normal messages) - friendlier infodlg. get rid of those lame tabs - maybe an XML-based skins support (not only colors, sounds, images, key \ - bindings, but also window positions, shapes, etc) \ - Microsoft Windows Media Player supports XML-based skinning. Basically \ - this consists of a file which has a bunch of JavaScript glueing the \ - entire skin together with code, and several images for hilite graphics, \ - background graphics, alpha-map graphics, etc. Very flexible. \ - Justin's opinion: if you want to fork Psi to do this, be my guest.. - cvlist sorting options - sort by group, online/offline split - sort by group, online/offline together - sort by group and by status - sort by group and alphanumerically - sort by status without groups - sort alphanumerically without groups - sort by online/offline - straight alphanumerical sort - chatdlg: optionally tabbed like GAIM? - cvlist select multiple? - right-clicking on status button should bring up a list of accounts, each with submenus that would set \ - the status of the chosen account. - option to have psi remember your password for the running session - Remember last status when psi quits (even if improperly shut down). restore this status when psi is run again? - if you get a msg from someone in a closed group, it should not expand the whole group - "diskless" mode - -Bugs - connection timeouts are reported as "connection refused" (qt) - slowdown when receiving a chat message? or a problem with QTextEdit debug messages? - -Miscellaneous - change PsiIconSet::type2anim() to be const (and return const) - properly sort cvlist accounts if one of them gets renamed - class Options: cpp'ify (reset, toXml, fromXml) - convert some of the preferences into their own classes (or lists), like fonts, colors, sounds, etc - field for author/license information in lang packs (display in About box) - 'find' function in historydlg should show the found result in the center of 50 results, rather than the top - Check for libqssl without needing a restart? - finish jidlink and formalize the linktest process () - replies should only close a window that it is associated with (use QGuardedPtr?) - custombrowser, mailer, and sound player should be called as a shell command, not arg0 - don't allow send/recv of blank messages (all content is whitespace or empty) - allow blank password entry - don't prompt for password until actually connected. reprompt if wrong?? - iconset: universal anim support (so eventdlg / mainwin / contactview can share) (misha?) - proper dialog button order depending on platform - when entering a text string into "Server to browse", any whitespace before or after is not trimmed. lots of \ - fields like this should have some sort of auto-trim. - when opening a new chat window of a contact with pending events, the presence is logged to the chat window \ - before the messages are, which have an earlier timestamp (looks weird) Index: COPYING =================================================================== --- COPYING (.../vendor/psi/psi-0.10) (revision 39233) +++ COPYING (.../trunk/im/psi-0.10) (revision 39233) @@ -1,296 +0,0 @@ - - As a special exception, the copyright holder(s) give permission to link - this program with the Qt Library (commercial or non-commercial edition), - and distribute the resulting executable, without including the source - code for the Qt library in the source distribution. - - As a special exception, the copyright holder(s) give permission to link - this program with any other library, and distribute the resulting - executable, without including the source code for the library in the - source distribution, provided that the library interfaces with this - program only via the following plugin interfaces: - - 1. The Qt Plugin APIs, only as authored by Trolltech - 2. The QCA Plugin API, only as authored by Justin Karneges - - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS Index: .darcs_boring =================================================================== --- .darcs_boring (.../vendor/psi/psi-0.10) (revision 39233) +++ .darcs_boring (.../trunk/im/psi-0.10) (revision 39233) @@ -1,64 +0,0 @@ -# Boring file regexps: -\.hi$ -#\.o$ -\.o\.cmd$ -\.ko$ -\.ko\.cmd$ -\.mod\.c$ -(^|/)\.tmp_versions($|/) -#(^|/)CVS($|/) -(^|/)RCS($|/) -~$ -#(^|/)\.[^/] -(^|/)_darcs($|/) -\.bak$ -\.BAK$ -\.orig$ -(^|/)vssver\.scc$ -\.swp$ -(^|/)MT($|/) -(^|/)\{arch\}($|/) -(^|/).arch-ids($|/) -(^|/), -\.class$ -\.prof$ -(^|/)\.DS_Store$ -(^|/)BitKeeper($|/) -(^|/)ChangeSet($|/) -(^|/)\.svn($|/) -\.py[co]$ -\# -#\.cvsignore$ -(^|/)Thumbs\.db$ - -# Binaries -^src/psi$ -^src/psi.app$ - -# Mac binaries -^mac/disk -^mac/Psi-.* -^mac/(template|wc)\.dmg($|\.bz2$) - -# Windows -^psiwin/.*$ - -# libpsi -^libpsi/psiwidgets/.*\.(o|moc|dylib)$ -^libpsi/psiwidgets/moc_.*\.cpp$ - -# QMake makefiles -^Makefile -^src/Makefile -^libpsi/psiwidgets/Makefile - -# QConf -^conf.log -^conf.pri -^extra.pri -^src/config.h - -# Qt dirs -(^|/).ui($|/) -(^|/).obj($|/) -(^|/).moc($|/) Index: qcm/openssl.qcm =================================================================== --- qcm/openssl.qcm (.../vendor/psi/psi-0.10) (revision 0) +++ qcm/openssl.qcm (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,100 @@ +/* +-----BEGIN QCMOD----- +name: OpenSSL +arg: with-openssl-inc=[path],Path to OpenSSL include files +arg: with-openssl-lib=[path],Path to OpenSSL library files +-----END QCMOD----- +*/ +class qc_openssl : public ConfObj +{ +public: + qc_openssl(Conf *c) : ConfObj(c) {} + QString name() const { return "OpenSSL"; } + QString shortname() const { return "openssl"; } + bool exec() + { + QString inc, lib; + QString s; + bool kb = false; + QString kbdir = "/usr/kerberos/include"; + + // Redhat 9? + if(QFileInfo(kbdir).exists()) + kb = true; + + s = conf->getenv("QC_WITH_OPENSSL_INC"); + if(!s.isEmpty()) { + if(!conf->checkHeader(s, "openssl/ssl.h")) + return false; + inc = s; + } + else { + if(!conf->findHeader("openssl/ssl.h", QStringList(), &s)) + return false; + inc = s; + } + + s = conf->getenv("QC_WITH_OPENSSL_LIB"); + if(!s.isEmpty()) { + if(!conf->checkLibrary(s, "ssl")) + return false; + lib = s; + } + else { + if(!conf->findLibrary("ssl", &s)) + return false; + lib = s; + } + + // is it at least openssl 0.9.7? + QString str = + "#include\n" + "int main()\n" + "{\n" + " unsigned long x = OPENSSL_VERSION_NUMBER;\n" + " if(x >= 0x00907000) return 0; else return 1;\n" + "}\n"; + QString ext; + if(!inc.isEmpty()) + ext += QString("-I") + inc + ' '; + if(kb) + ext += QString("-I") + kbdir + ' '; + if(!lib.isEmpty()) + ext += QString("-L") + lib + " -lssl -lcrypto "; + int ret; + if(!conf->doCompileAndLink(str, ext, &ret)) + return false; + if(ret == 0) + conf->addDefine("OSSL_097"); + + // is it at least openssl 0.9.8? + str = + "#include\n" + "int main()\n" + "{\n" + " unsigned long x = OPENSSL_VERSION_NUMBER;\n" + " if(x >= 0x00908000) return 0; else return 1;\n" + "}\n"; + ext = QString(); + if(!inc.isEmpty()) + ext += QString("-I") + inc + ' '; + if(kb) + ext += QString("-I") + kbdir + ' '; + if(!lib.isEmpty()) + ext += QString("-L") + lib + " -lssl -lcrypto "; + if(!conf->doCompileAndLink(str, ext, &ret)) + return false; + if(ret == 0) + conf->addDefine("OSSL_098"); + + if(!inc.isEmpty()) + conf->addIncludePath(inc); + if(kb) + conf->addIncludePath(kbdir); + if(!lib.isEmpty()) + conf->addLib(QString("-L") + s); + conf->addLib("-lssl -lcrypto"); + + return true; + } +}; Index: qcm/conf.qcm =================================================================== --- qcm/conf.qcm (.../vendor/psi/psi-0.10) (revision 39233) +++ qcm/conf.qcm (.../trunk/im/psi-0.10) (revision 39233) @@ -1,6 +1,6 @@ /* -----BEGIN QCMOD----- -name: Psi Configuration +name: Barracuda Configuration -----END QCMOD----- */ @@ -11,18 +11,18 @@ { public: qc_conf(Conf *c) : ConfObj(c) {} - QString name() const { return "Psi Configuration"; } + QString name() const { return "Barracuda Configuration"; } QString shortname() const { return "conf"; } QString checkString() const { return "Writing configuration ..."; } bool exec() { conf->addExtra(QString("PREFIX=%1").arg(conf->getenv("PREFIX"))); - conf->addExtra(QString("DATADIR=%1/psi").arg(conf->getenv("DATADIR"))); + conf->addExtra(QString("DATADIR=%1/barracuda").arg(conf->getenv("DATADIR"))); QFile file("src/config.h"); if ( file.open( IO_WriteOnly ) ) { QTextStream stream( &file ); - stream << "#define PSI_DATADIR \"" << conf->getenv("DATADIR") << "/psi\"" << endl; + stream << "#define PSI_DATADIR \"" << conf->getenv("DATADIR") << "/barracuda\"" << endl; } conf->addDefine("HAVE_CONFIG"); Index: qcm/xercesc.qcm =================================================================== --- qcm/xercesc.qcm (.../vendor/psi/psi-0.10) (revision 0) +++ qcm/xercesc.qcm (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,55 @@ +/* +-----BEGIN QCMOD----- +name: Xerces-C++ +arg: with-xercesc-inc=[path],Path to Xerces-C++ include files +arg: with-xercesc-lib=[path],Path to Xerces-C++ library files +-----END QCMOD----- +*/ + +//---------------------------------------------------------------------------- +// qc_xercesc +//---------------------------------------------------------------------------- +class qc_xercesc : public ConfObj +{ +public: + qc_xercesc(Conf *c) : ConfObj(c) {} + QString name() const { return "Xerces-C++"; } + QString shortname() const { return "xercesc"; } + bool exec() + { + QString inc, lib; + QString s; + + s = conf->getenv("QC_WITH_XERCESC_INC"); + if(!s.isEmpty()) { + if(!conf->checkHeader(s, "xercesc/util/XercesVersion.hpp")) + return false; + inc = s; + } + else { + if(!conf->findHeader("xercesc/util/XercesVersion.hpp", QStringList(), &s)) + return false; + inc = s; + } + + s = conf->getenv("QC_WITH_XERCESC_LIB"); + if(!s.isEmpty()) { + if(!conf->checkLibrary(s, "xerces-c")) + return false; + lib = s; + } + else { + if(!conf->findLibrary("xerces-c", &s)) + return false; + lib = s; + } + + if(!inc.isEmpty()) + conf->addIncludePath(inc); + if(!lib.isEmpty()) + conf->addLib(QString("-L") + s); + conf->addLib("-lxerces-c"); + + return true; + } +}; Index: configure =================================================================== --- configure (.../vendor/psi/psi-0.10) (revision 39233) +++ configure (.../trunk/im/psi-0.10) (revision 39233) @@ -1,6 +1,6 @@ #!/bin/sh # -# Generated by qconf 1.2-CVS ( http://delta.affinix.com/qconf/ ) +# Generated by qconf 1.3 ( http://delta.affinix.com/qconf/ ) # show_usage() { @@ -14,14 +14,16 @@ --bindir=[path] Directory for binaries. Default: PREFIX/bin --datadir=[path] Directory for data. Default: PREFIX/share --qtdir=[path] Directory where Qt is installed. - --debug Enable debug output. + --verbose Show extra configure output. --help This help text. Dependency options: - --with-qca-inc=[path] Path to QCA include files - --with-qca-lib=[path] Path to QCA library files --with-zlib-inc=[path] Path to zlib include files --with-zlib-lib=[path] Path to zlib library files + --with-openssl-inc=[path] Path to OpenSSL include files + --with-openssl-lib=[path] Path to OpenSSL library files + --with-xercesc-inc=[path] Path to Xerces-C++ include files + --with-xercesc-lib=[path] Path to Xerces-C++ library files --disable-growl Disable use of Growl --with-growl=[path] Path to the Growl framework --disable-xss Disable use of the XScreenSaver extension @@ -121,44 +123,55 @@ } while [ $# -gt 0 ]; do + optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` case "$1" in --prefix=*) - PREFIX="${1#--prefix=}" + PREFIX=$optarg shift ;; --bindir=*) - BINDIR="${1#--bindir=}" + BINDIR=$optarg shift ;; --datadir=*) - DATADIR="${1#--datadir=}" + DATADIR=$optarg shift ;; --qtdir=*) - EX_QTDIR="${1#--qtdir=}" + EX_QTDIR=$optarg shift ;; - --with-qca-inc=*) - QC_WITH_QCA_INC="${1#--with-qca-inc=}" + --with-zlib-inc=*) + QC_WITH_ZLIB_INC=$optarg shift ;; - --with-qca-lib=*) - QC_WITH_QCA_LIB="${1#--with-qca-lib=}" + --with-zlib-lib=*) + QC_WITH_ZLIB_LIB=$optarg shift ;; - --with-zlib-inc=*) - QC_WITH_ZLIB_INC="${1#--with-zlib-inc=}" + --with-openssl-inc=*) + QC_WITH_OPENSSL_INC=$optarg shift ;; - --with-zlib-lib=*) - QC_WITH_ZLIB_LIB="${1#--with-zlib-lib=}" + --with-openssl-lib=*) + QC_WITH_OPENSSL_LIB=$optarg + shift + ;; + + --with-xercesc-inc=*) + QC_WITH_XERCESC_INC=$optarg + shift + ;; + + --with-xercesc-lib=*) + QC_WITH_XERCESC_LIB=$optarg shift ;; @@ -168,7 +181,7 @@ ;; --with-growl=*) - QC_WITH_GROWL="${1#--with-growl=}" + QC_WITH_GROWL=$optarg shift ;; @@ -187,7 +200,7 @@ shift ;; - --debug) + --verbose) QC_DEBUG="Y" shift ;; @@ -200,7 +213,7 @@ BINDIR=${BINDIR:-$PREFIX/bin} DATADIR=${DATADIR:-$PREFIX/share} -echo "Configuring Psi ..." +echo "Configuring Barracuda IM Client ..." if [ "$QC_DEBUG" = "Y" ]; then echo @@ -208,10 +221,12 @@ echo BINDIR=$BINDIR echo DATADIR=$DATADIR echo EX_QTDIR=$EX_QTDIR -echo QC_WITH_QCA_INC=$QC_WITH_QCA_INC -echo QC_WITH_QCA_LIB=$QC_WITH_QCA_LIB echo QC_WITH_ZLIB_INC=$QC_WITH_ZLIB_INC echo QC_WITH_ZLIB_LIB=$QC_WITH_ZLIB_LIB +echo QC_WITH_OPENSSL_INC=$QC_WITH_OPENSSL_INC +echo QC_WITH_OPENSSL_LIB=$QC_WITH_OPENSSL_LIB +echo QC_WITH_XERCESC_INC=$QC_WITH_XERCESC_INC +echo QC_WITH_XERCESC_LIB=$QC_WITH_XERCESC_LIB echo QC_DISABLE_growl=$QC_DISABLE_growl echo QC_WITH_GROWL=$QC_WITH_GROWL echo QC_DISABLE_xss=$QC_DISABLE_xss @@ -323,49 +338,49 @@ return false; } }; -#line 1 "qca.qcm" +#line 1 "zlib.qcm" /* -----BEGIN QCMOD----- -name: QCA 1.0 -arg: with-qca-inc=[path],Path to QCA include files -arg: with-qca-lib=[path],Path to QCA library files +name: zlib +arg: with-zlib-inc=[path],Path to zlib include files +arg: with-zlib-lib=[path],Path to zlib library files -----END QCMOD----- */ //---------------------------------------------------------------------------- -// qc_qca +// qc_zlib //---------------------------------------------------------------------------- -class qc_qca : public ConfObj +class qc_zlib : public ConfObj { public: - qc_qca(Conf *c) : ConfObj(c) {} - QString name() const { return "QCA 1.0"; } - QString shortname() const { return "qca"; } + qc_zlib(Conf *c) : ConfObj(c) {} + QString name() const { return "zlib"; } + QString shortname() const { return "zlib"; } bool exec() { QString inc, lib; QString s; - s = conf->getenv("QC_WITH_QCA_INC"); + s = conf->getenv("QC_WITH_ZLIB_INC"); if(!s.isEmpty()) { - if(!conf->checkHeader(s, "qca.h")) + if(!conf->checkHeader(s, "zlib.h")) return false; inc = s; } else { - if(!conf->findHeader("qca.h", QStringList(), &s)) + if(!conf->findHeader("zlib.h", QStringList(), &s)) return false; inc = s; } - s = conf->getenv("QC_WITH_QCA_LIB"); + s = conf->getenv("QC_WITH_ZLIB_LIB"); if(!s.isEmpty()) { - if(!conf->checkLibrary(s, "qca")) + if(!conf->checkLibrary(s, "z")) return false; lib = s; } else { - if(!conf->findLibrary("qca", &s)) + if(!conf->findLibrary("z", &s)) return false; lib = s; } @@ -374,54 +389,155 @@ conf->addIncludePath(inc); if(!lib.isEmpty()) conf->addLib(QString("-L") + s); - conf->addLib("-lqca"); + conf->addLib("-lz"); return true; } }; -#line 1 "zlib.qcm" +#line 1 "openssl.qcm" /* -----BEGIN QCMOD----- -name: zlib -arg: with-zlib-inc=[path],Path to zlib include files -arg: with-zlib-lib=[path],Path to zlib library files +name: OpenSSL +arg: with-openssl-inc=[path],Path to OpenSSL include files +arg: with-openssl-lib=[path],Path to OpenSSL library files +-----END QCMOD----- +*/ +class qc_openssl : public ConfObj +{ +public: + qc_openssl(Conf *c) : ConfObj(c) {} + QString name() const { return "OpenSSL"; } + QString shortname() const { return "openssl"; } + bool exec() + { + QString inc, lib; + QString s; + bool kb = false; + QString kbdir = "/usr/kerberos/include"; + + // Redhat 9? + if(QFileInfo(kbdir).exists()) + kb = true; + + s = conf->getenv("QC_WITH_OPENSSL_INC"); + if(!s.isEmpty()) { + if(!conf->checkHeader(s, "openssl/ssl.h")) + return false; + inc = s; + } + else { + if(!conf->findHeader("openssl/ssl.h", QStringList(), &s)) + return false; + inc = s; + } + + s = conf->getenv("QC_WITH_OPENSSL_LIB"); + if(!s.isEmpty()) { + if(!conf->checkLibrary(s, "ssl")) + return false; + lib = s; + } + else { + if(!conf->findLibrary("ssl", &s)) + return false; + lib = s; + } + + // is it at least openssl 0.9.7? + QString str = + "#include\n" + "int main()\n" + "{\n" + " unsigned long x = OPENSSL_VERSION_NUMBER;\n" + " if(x >= 0x00907000) return 0; else return 1;\n" + "}\n"; + QString ext; + if(!inc.isEmpty()) + ext += QString("-I") + inc + ' '; + if(kb) + ext += QString("-I") + kbdir + ' '; + if(!lib.isEmpty()) + ext += QString("-L") + lib + " -lssl -lcrypto "; + int ret; + if(!conf->doCompileAndLink(str, ext, &ret)) + return false; + if(ret == 0) + conf->addDefine("OSSL_097"); + + // is it at least openssl 0.9.8? + str = + "#include\n" + "int main()\n" + "{\n" + " unsigned long x = OPENSSL_VERSION_NUMBER;\n" + " if(x >= 0x00908000) return 0; else return 1;\n" + "}\n"; + ext = QString(); + if(!inc.isEmpty()) + ext += QString("-I") + inc + ' '; + if(kb) + ext += QString("-I") + kbdir + ' '; + if(!lib.isEmpty()) + ext += QString("-L") + lib + " -lssl -lcrypto "; + if(!conf->doCompileAndLink(str, ext, &ret)) + return false; + if(ret == 0) + conf->addDefine("OSSL_098"); + + if(!inc.isEmpty()) + conf->addIncludePath(inc); + if(kb) + conf->addIncludePath(kbdir); + if(!lib.isEmpty()) + conf->addLib(QString("-L") + s); + conf->addLib("-lssl -lcrypto"); + + return true; + } +}; +#line 1 "xercesc.qcm" +/* +-----BEGIN QCMOD----- +name: Xerces-C++ +arg: with-xercesc-inc=[path],Path to Xerces-C++ include files +arg: with-xercesc-lib=[path],Path to Xerces-C++ library files -----END QCMOD----- */ //---------------------------------------------------------------------------- -// qc_zlib +// qc_xercesc //---------------------------------------------------------------------------- -class qc_zlib : public ConfObj +class qc_xercesc : public ConfObj { public: - qc_zlib(Conf *c) : ConfObj(c) {} - QString name() const { return "zlib"; } - QString shortname() const { return "zlib"; } + qc_xercesc(Conf *c) : ConfObj(c) {} + QString name() const { return "Xerces-C++"; } + QString shortname() const { return "xercesc"; } bool exec() { QString inc, lib; QString s; - s = conf->getenv("QC_WITH_ZLIB_INC"); + s = conf->getenv("QC_WITH_XERCESC_INC"); if(!s.isEmpty()) { - if(!conf->checkHeader(s, "zlib.h")) + if(!conf->checkHeader(s, "xercesc/util/XercesVersion.hpp")) return false; inc = s; } else { - if(!conf->findHeader("zlib.h", QStringList(), &s)) + if(!conf->findHeader("xercesc/util/XercesVersion.hpp", QStringList(), &s)) return false; inc = s; } - s = conf->getenv("QC_WITH_ZLIB_LIB"); + s = conf->getenv("QC_WITH_XERCESC_LIB"); if(!s.isEmpty()) { - if(!conf->checkLibrary(s, "z")) + if(!conf->checkLibrary(s, "xerces-c")) return false; lib = s; } else { - if(!conf->findLibrary("z", &s)) + if(!conf->findLibrary("xerces-c", &s)) return false; lib = s; } @@ -430,7 +546,7 @@ conf->addIncludePath(inc); if(!lib.isEmpty()) conf->addLib(QString("-L") + s); - conf->addLib("-lz"); + conf->addLib("-lxerces-c"); return true; } @@ -756,7 +872,7 @@ #line 1 "conf.qcm" /* -----BEGIN QCMOD----- -name: Psi Configuration +name: Barracuda Configuration -----END QCMOD----- */ @@ -767,18 +883,18 @@ { public: qc_conf(Conf *c) : ConfObj(c) {} - QString name() const { return "Psi Configuration"; } + QString name() const { return "Barracuda Configuration"; } QString shortname() const { return "conf"; } QString checkString() const { return "Writing configuration ..."; } bool exec() { conf->addExtra(QString("PREFIX=%1").arg(conf->getenv("PREFIX"))); - conf->addExtra(QString("DATADIR=%1/psi").arg(conf->getenv("DATADIR"))); + conf->addExtra(QString("DATADIR=%1/barracuda").arg(conf->getenv("DATADIR"))); QFile file("src/config.h"); if ( file.open( IO_WriteOnly ) ) { QTextStream stream( &file ); - stream << "#define PSI_DATADIR \"" << conf->getenv("DATADIR") << "/psi\"" << endl; + stream << "#define PSI_DATADIR \"" << conf->getenv("DATADIR") << "/barracuda\"" << endl; } conf->addDefine("HAVE_CONFIG"); @@ -792,10 +908,13 @@ o = new qc_qt31(conf); o->required = true; o->disabled = false; - o = new qc_qca(conf); + o = new qc_zlib(conf); + o->required = true; + o->disabled = false; + o = new qc_openssl(conf); o->required = true; o->disabled = false; - o = new qc_zlib(conf); + o = new qc_xercesc(conf); o->required = true; o->disabled = false; o = new qc_growl(conf); @@ -1222,10 +1341,12 @@ export BINDIR export DATADIR export EX_QTDIR -export QC_WITH_QCA_INC -export QC_WITH_QCA_LIB export QC_WITH_ZLIB_INC export QC_WITH_ZLIB_LIB +export QC_WITH_OPENSSL_INC +export QC_WITH_OPENSSL_LIB +export QC_WITH_XERCESC_INC +export QC_WITH_XERCESC_LIB export QC_DISABLE_growl export QC_WITH_GROWL export QC_DISABLE_xss Index: LICENSE =================================================================== --- LICENSE (.../vendor/psi/psi-0.10) (revision 0) +++ LICENSE (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,299 @@ + The Barracuda IM Client is based on the GNU General Public License + Version 2 with a few special linking exceptions given by authors of + libraries. + + All of Barracuda's changes and enhancements to the original PSI XMPP + program are available in source code form via the download page included + with the Barracuda IM Firewall + + ------------------------------------------------------------------------ + + As a special exception, Justin Karneges gives permission to link + this program with the Qt Library (commercial or non-commercial edition), + and distribute the resulting executable, without including the source + code for the Qt library in the source distribution. + + As a special exception, Justin Karneges gives permission to link + this program with the OpenSSL Library. + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS Index: libpsi/psiwidgets/iconwidget.h =================================================================== --- libpsi/psiwidgets/iconwidget.h (.../vendor/psi/psi-0.10) (revision 39233) +++ libpsi/psiwidgets/iconwidget.h (.../trunk/im/psi-0.10) (revision 39233) @@ -138,6 +138,9 @@ void setIcon(const QString &); const QString &iconName() const; + // ###cuda + void setUseBigPixmap(bool uses_big); + public: class Private; private: Index: libpsi/psiwidgets/iconaction.cpp =================================================================== --- libpsi/psiwidgets/iconaction.cpp (.../vendor/psi/psi-0.10) (revision 39233) +++ libpsi/psiwidgets/iconaction.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -43,6 +43,9 @@ IconAction *action; QPopupMenu *popup; + // ###cuda + bool uses_big; + Private(IconAction *act) { icon = 0; action = act; @@ -88,18 +91,24 @@ d = new Private(this); } -IconAction::IconAction(const QString &text, const QString &icon, const QString &menuText, QKeySequence accel, QObject *parent, const char *name, bool toggle) +IconAction::IconAction(const QString &text, const QString &icon, const QString &menuText, QKeySequence accel, QObject *parent, const char *name, bool toggle, bool uses_big) : QAction(text, menuText, accel, parent, name, toggle) { d = new Private(this); - setIcon(icon); + // ###cuda + d->uses_big = uses_big; + //setIcon(icon); + setIcon(icon, uses_big); } -IconAction::IconAction(const QString &text, const QString &menuText, QKeySequence accel, QObject *parent, const char *name, bool toggle) +IconAction::IconAction(const QString &text, const QString &menuText, QKeySequence accel, QObject *parent, const char *name, bool toggle, bool uses_big) : QAction(text, menuText, accel, parent, name, toggle) { d = new Private(this); + + // ###cuda + d->uses_big = uses_big; } IconAction::~IconAction() @@ -116,7 +125,7 @@ return d->icon; } -void IconAction::setIcon(const Icon *i) +void IconAction::setIcon(const Icon *i, bool uses_big) { if ( d->icon ) { disconnect(d->icon, 0, this, 0 ); @@ -139,6 +148,9 @@ for ( QPtrListIterator it(d->buttons); it.current(); ++it ) { IconToolButton *btn = it.current(); btn->setIcon ( d->icon ); + + // ###cuda + btn->setUseBigPixmap(uses_big); } #ifndef Q_WS_MAC @@ -151,9 +163,11 @@ } } -void IconAction::setIcon(const QString &name) +void IconAction::setIcon(const QString &name, bool uses_big) { - setIcon( IconsetFactory::iconPtr(name) ); + // ###cuda + //setIcon( IconsetFactory::iconPtr(name) ); + setIcon( IconsetFactory::iconPtr(name), uses_big ); } const QString &IconAction::iconName() const @@ -176,6 +190,9 @@ btn->setIcon ( d->icon, false ); btn->setEnabled ( isEnabled() ); + // ###cuda + btn->setUseBigPixmap(d->uses_big); + if ( d->popup ) btn->setPopup( d->popup ); btn->setPopupDelay (1); // the popup will be displayed immediately @@ -278,6 +295,15 @@ for ( QPtrListIterator it(d->buttons); it.current(); ++it ) { IconToolButton *btn = it.current(); btn->setTextLabel(t); + + // ###cuda +#ifdef Q_WS_MAC + QFont f("Sans", 9, QFont::Normal); +#else + QFont f("Sans", 7, QFont::Normal); +#endif + btn->setUsesTextLabel(true); + btn->setFont(f); } #ifndef Q_WS_MAC Index: libpsi/psiwidgets/iconaction.h =================================================================== --- libpsi/psiwidgets/iconaction.h (.../vendor/psi/psi-0.10) (revision 39233) +++ libpsi/psiwidgets/iconaction.h (.../trunk/im/psi-0.10) (revision 39233) @@ -35,15 +35,25 @@ Q_OBJECT public: IconAction(QObject *parent, const char *name = 0); - IconAction(const QString &text, const QString &icon, const QString &menuText, QKeySequence accel, QObject *parent, const char *name = 0, bool toggle = FALSE); - IconAction(const QString &text, const QString &menuText, QKeySequence accel, QObject *parent, const char *name = 0, bool toggle = FALSE); + + // ###cuda + //IconAction(const QString &text, const QString &icon, const QString &menuText, QKeySequence accel, QObject *parent, const char *name = 0, bool toggle = FALSE); + //IconAction(const QString &text, const QString &menuText, QKeySequence accel, QObject *parent, const char *name = 0, bool toggle = FALSE); + IconAction(const QString &text, const QString &icon, const QString &menuText, QKeySequence accel, QObject *parent, const char *name = 0, bool toggle = FALSE, bool uses_big = false); + IconAction(const QString &text, const QString &menuText, QKeySequence accel, QObject *parent, const char *name = 0, bool toggle = FALSE, bool uses_big = false); + ~IconAction(); virtual bool addTo(QWidget *); const Icon *icon() const; - void setIcon(const Icon *); - void setIcon(const QString &); + + // ###cuda + //void setIcon(const Icon *); + //void setIcon(const QString &); + void setIcon(const Icon *, bool uses_big = false); + void setIcon(const QString &, bool uses_big = false); + const QString &iconName() const; QPopupMenu *popup() const; Index: libpsi/psiwidgets/iconwidget.cpp =================================================================== --- libpsi/psiwidgets/iconwidget.cpp (.../vendor/psi/psi-0.10) (revision 39233) +++ libpsi/psiwidgets/iconwidget.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -759,6 +759,7 @@ { setWFlags(getWFlags() | WRepaintNoErase); d = new Private(this); + setUsesBigPixmap(false); // ###cuda } IconToolButton::~IconToolButton() @@ -786,6 +787,12 @@ #endif } +// ###cuda +void IconToolButton::setUseBigPixmap(bool uses_big) +{ + setUsesBigPixmap(uses_big); +} + const QString &IconToolButton::iconName() const { #ifndef WIDGET_PLUGIN Index: onion/onion/HandlerConn.h =================================================================== --- onion/onion/HandlerConn.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerConn.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,38 @@ +/* + Http header handler for "Connection" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerConn.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERCONN_H +#define ONION_HEADER_HANDLERCONN_H 1 + +#include +#include + +class CHandlerConn : public CResponseHeaderHandler +{ + public: + CHandlerConn(); + ~CHandlerConn(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); +}; + +#endif /*ONION_HEADER_HANDLERCONN_H*/ Index: onion/onion/DavSSLCertificateList.h =================================================================== --- onion/onion/DavSSLCertificateList.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavSSLCertificateList.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + List of SSL certificates + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSSLCertificateList.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSSLCERTIFICATELIST_H +#define ONION_HEADER_DAVSSLCERTIFICATELIST_H 1 + +#include +#include +#include + +class CDavSSLCertificate; + +class CDavSSLCertificateList +{ + private: + typedef std::vector SSLCERTLIST, *PSSLCERTLIST; + typedef SSLCERTLIST::iterator SSLCERTITERATOR; + public: + CDavSSLCertificateList(); + ~CDavSSLCertificateList(); + unsigned int GetCount(); + void Clear(); + void AddCertificate(CDavSSLCertificate* pCert); + CDavSSLCertificate* GetCertificate(unsigned int unIndex); + CDavSSLCertificate* operator[](unsigned int unIndex); + private: + SSLCERTLIST m_vecCertificateList; +}; + +#endif /*ONION_HEADER_DAVSSLCERTIFICATELIST_H*/ Index: onion/onion/DavXmlInputSource.h =================================================================== --- onion/onion/DavXmlInputSource.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavXmlInputSource.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,43 @@ +/* + Input source needed by XML parser + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlInputSource.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVXMLINPUTSOURCE_H +#define ONION_HEADER_DAVXMLINPUTSOURCE_H 1 + +#include +#include + +//forward declaration +class CDavResponseBody; + +class CDavXmlInputSource : public XNS(InputSource) +{ + public: + CDavXmlInputSource(CDavResponseBody* pBody); + ~CDavXmlInputSource(); + + virtual XNS(BinInputStream)* makeStream() const; + private: + CDavResponseBody* m_pBody; +}; + +#endif /*ONION_HEADER_DAVXMLINPUTSOURCE_H*/ Index: onion/onion/PBCSMMemBuffer.h =================================================================== --- onion/onion/PBCSMMemBuffer.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/PBCSMMemBuffer.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,42 @@ +/* + Response body consumer that writes to memory buffer + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMMemBuffer.h,v 1.1.1.1 2004/07/15 06:58:43 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_PBCSMMEMBUFFER_H +#define ONION_HEADER_PBCSMMEMBUFFER_H 1 + +#include +#include + +class CPBCSMMemBuffer : public CResponseBodyConsumer +{ + public: + CPBCSMMemBuffer(CDavRequest* pReq); + virtual ~CPBCSMMemBuffer(); + + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_PBC_TYPE GetType(); + virtual OI_RESULT PullResponseBody(CDavResponseBody* pBody); +}; + +#endif /*ONION_HEADER_PBCSMMEMBUFFER_H*/ Index: onion/onion/HandlerAuth.h =================================================================== --- onion/onion/HandlerAuth.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerAuth.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,45 @@ +/* + Http header handler for "Auth" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerAuth.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERAUTH_H +#define ONION_HEADER_HANDLERAUTH_H 1 + +#include +#include + +//forward declarations +class CDavAuthSession; +class CResponseBodyConsumer; + +class CHandlerAuth : public CResponseHeaderHandler +{ + public: + CHandlerAuth(CDavRequest* pReq, CDavAuthSession* pAuthSession); + ~CHandlerAuth(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + private: + CDavAuthSession* m_pAuthSession; + CResponseBodyConsumer* m_pPBConsumer; +}; + +#endif /*ONION_HEADER_HANDLERAUTH_H*/ Index: onion/onion/DavSSLCertificate.h =================================================================== --- onion/onion/DavSSLCertificate.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavSSLCertificate.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,56 @@ +/* + SSL certificate + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSSLCertificate.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSSLCERTIFICATE_H +#define ONION_HEADER_DAVSSLCERTIFICATE_H 1 + +#include +#include + +class CDavSSLCertificate +{ + friend class CDavWorkSession; + public: + CDavSSLCertificate(); + ~CDavSSLCertificate(); + void Attach(X509* pX509); + X509* Detach(); + void ParseDNames(); + void ParseTime(); + CDavSSLCertificate& operator=(const CDavSSLCertificate& master); + bool operator ==(const CDavSSLCertificate& other); + bool operator ==(const X509* pOther); + protected: + CDavSSLCertificate(X509* pX509, unsigned long ulFailures = 0); + private: + void asn1TimeToString(ASN1_TIME* pTime, OI_STRING_A& strOut); + public: + CDavSSLDName m_dnSubject; + CDavSSLDName m_dnIssuer; + unsigned long m_ulFailures; + time_t m_tmNotBefore; + time_t m_tmNotAfter; + private: + X509* m_pX509; +}; + +#endif /*ONION_HEADER_DAVSSLCERTIFICATE_H*/ Index: onion/onion/RBPVDXmlPropfind.h =================================================================== --- onion/onion/RBPVDXmlPropfind.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDXmlPropfind.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for PROPFIND method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlPropfind.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDXMLPROPFIND_H +#define ONION_HEADER_RBPVDXMLPROPFIND_H 1 + +#include +#include + +class CRBPVDXmlPropfind : public CRBPVDXml +{ + public: + CRBPVDXmlPropfind(); + ~CRBPVDXmlPropfind(); +}; + +#endif /*ONION_HEADER_RBPVDXMLPROPFIND_H*/ Index: onion/onion/DavSSLDName.h =================================================================== --- onion/onion/DavSSLDName.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavSSLDName.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,60 @@ +/* + Distinguish name of SSL certificates + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSSLDName.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSSLDNAME_H +#define ONION_HEADER_DAVSSLDNAME_H 1 + +#include +#include +#include +#include + +//forward declaration +class CDavSSLDNameField; + +class CDavSSLDName +{ + friend class CDavSSLCertificate; + private: + typedef std::map DNAMEFIELDS, *PDNAMEFIELDS; + typedef DNAMEFIELDS::iterator DNAMEFIELDITERATOR; + public: + unsigned int GetFieldCount(); + const CDavSSLDNameField* GetField(const char* pszName); + const CDavSSLDNameField* GetFirstField(OI_STRING_A& strName); + const CDavSSLDNameField* GetNextField(OI_STRING_A& strName); + const CDavSSLDNameField* operator[](const char* pszName); + CDavSSLDName& operator =(const CDavSSLDName& master); + bool operator ==(const CDavSSLDName& other); + bool operator ==(const X509_NAME* pOther); + void Clear(); + protected: + CDavSSLDName(); + ~CDavSSLDName(); + bool parseDName(X509_NAME* pName); + private: + X509_NAME* m_pX509Name; + DNAMEFIELDS m_mapFields; + DNAMEFIELDITERATOR m_itrCurrent; +}; + +#endif /*ONION_HEADER_DAVSSLDNAME_H*/ Index: onion/onion/OnionDef.h =================================================================== --- onion/onion/OnionDef.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/OnionDef.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,221 @@ +/* + Definitions of onion library + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: OnionDef.h,v 1.2 2004/07/15 07:22:09 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_ONIONDEF_H +#define ONION_HEADER_ONIONDEF_H 1 + +#ifndef NULL +#define NULL 0 +#endif /* NULL */ + +#define OI_GENBUFSIZE 1024 +#define OI_LINEBUFSIZE 512 + +//debug +// MIKE +//#define _DEBUG +#ifdef _DEBUG +# define OI_ASSERT(x) assert(x) +# define OI_VERIFY(x) OI_ASSERT(x) +# ifdef WIN32 +# define OI_DEBUG ATLTRACE +# else +# define OI_DEBUG OnionDebugOutput +# endif /*WIN32*/ +#else +# define OI_ASSERT(x) ((void)0) +# define OI_VERIFY(x) (x) +# define OI_DEBUG if(0)OnionDebugOutput +#endif /*_DEBUG*/ + + +#define OI_DEBUG_SILENT 0x00000001 +#define OI_DEBUG_FLUSH 0x00000002 + + +//the Xerces namespace stuff +#if defined(XERCES_HAS_CPP_NAMESPACE) +# define XNS(name) XERCES_CPP_NAMESPACE::name +#else +# define XNS(name) name +#endif /*XERCES_HAS_CPP_NAMESPACE*/ + +//http +#define OI_MAX_HDR_LEN 8192 +#define OI_MAX_HDR_FLD 100 + +#define OI_METHOD_CONNECT "CONNECT" +#define OI_METHOD_COPY "COPY" +#define OI_METHOD_DELETE "DELETE" +#define OI_METHOD_GET "GET" +#define OI_METHOD_LOCK "LOCK" +#define OI_METHOD_MKCOL "MKCOL" +#define OI_METHOD_MOVE "MOVE" +#define OI_METHOD_OPTIONS "OPTIONS" +#define OI_METHOD_POST "POST" +#define OI_METHOD_PROPFIND "PROPFIND" +#define OI_METHOD_PROPPATCH "PROPPATCH" +#define OI_METHOD_PUT "PUT" +#define OI_METHOD_UNLOCK "UNLOCK" +#define OI_METHOD_SEARCH "SEARCH" +#define OI_METHOD_HEAD "HEAD" + +//request header names +#define OI_REQHDR_AUTH "Authorization" +#define OI_REQHDR_CONTENTTYPE "Content-Type" +#define OI_REQHDR_DEPTH "Depth" +#define OI_REQHDR_DESTINATION "Destination" +#define OI_REQHDR_IF "If" +#define OI_REQHDR_LOCKTOKEN "Lock-Token" +#define OI_REQHDR_OVERWRITE "Overwrite" +#define OI_REQHDR_PROXYAUTH "Proxy-Authorization" +#define OI_REQHDR_TIMEOUT "Timeout" + +//response header names +#define OI_RSPHDR_ALLOW "Allow" +#define OI_RSPHDR_AUTH "WWW-Authenticate" +#define OI_RSPHDR_AUTHINFO "Authentication-Info" +#define OI_RSPHDR_CLENGTH "Content-Length" +#define OI_RSPHDR_CONN "Connection" +#define OI_RSPHDR_CTYPE "Content-Type" +#define OI_RSPHDR_DASL "DASL" +#define OI_RSPHDR_DAV "DAV" +#define OI_RSPHDR_KEEPALIVE "Keep-Alive" +#define OI_RSPHDR_MSV "MS-Author-Via" +#define OI_RSPHDR_PROXYAUTH "Proxy-Authenticate" +#define OI_RSPHDR_PROXYAUTHINFO "Proxy-Authentication-Info" +#define OI_RSPHDR_PROXYCONN "Proxy-Connection" +#define OI_RSPHDR_SERVER "Server" +#define OI_RSPHDR_TE "Transfer-Encoding" + +//socket +#define OI_SOCKBUFSIZE 4096 +#define OI_SOCKTIMEOUTSEC 120 +#define OI_SOCK_VER_MINOR 2 +#define OI_SOCK_VER_MAJOR 2 +#define OI_SOCK_TIMEOUTSEC 10 +#define OI_SOCK_MAXTIMEOUTSEC 120 +#define OI_SOCK_MAXRETRY 3 + + +//xml +#define OI_MAX_ELEM_LEN 256 +#define OI_XMLCACHE_DOCNAME "Onion_Xml_Cache" +#define OI_XMLPOLICY_DOCNAME "Onion_Default_Policy" +#define OI_XML_NSURI "http://www.w3.org/2000/xmlns/" +#define OI_XML_DAVNAMESPACE "DAV:" +#define OI_XML_CUTELEMENT "response" +#define OI_XML_CUTELEMENT_LOCK "activelock" +#define OI_XML_COPYDOCNAME "D:propertybehavior" +#define OI_XML_LOCKDOCNAME "D:lockinfo" +#define OI_XML_MOVEDOCNAME "D:propertybehavior" +#define OI_XML_PROPFINDDOCNAME "D:propfind" +#define OI_XML_PROPPATCHDOCNAME "D:propertyupdate" +#define OI_XML_SEARCHDOCNAME "D:searchrequest" +#define OI_XML_DEFAULTLOCKOWNER "foo@bar.com" + +//dav resource node parse +#define OI_RNP_RESOURCETYPE 0x00000001 +#define OI_RNP_DISPLAYNAME 0x00000002 +#define OI_RNP_CONTENTLENGTH 0x00000004 +#define OI_RNP_LASTMODIFIED 0x00000008 +#define OI_RNP_CREATIONDATE 0x00000010 +#define OI_RNP_ETAG 0x00000020 +#define OI_RNP_CONTENTTYPE 0x00000040 +#define OI_RNP_CONTENTLANGUAGE 0x00000080 +#define OI_RNP_CLASS1 0x000000ff + + +#define OI_RNP_EXTRAPROPERTIES 0x00100000 + +#define OI_RNP_EXCLUSIVELOCK 0x02000000 +#define OI_RNP_SHAREDLOCK 0x04000000 +#define OI_RNP_LOCK 0x06000000 +#define OI_RNP_ELOCKSUPPORTED 0x00010000 +#define OI_RNP_SLOCKSUPPORTED 0x00020000 +#define OI_RNP_LOCKSUPPORTED 0x00030000 + +#define OI_RNP_QUOTA 0x00000200 +#define OI_RNP_QUOTAUSED 0x00000400 + +#define OI_RNP_EVERYTHING 0x060306ff +#define OI_RNP_CONVENTIONAL 0x0603003f + + +//Lock Infomation Valid Flags +#define OI_LIVF_TYPE 0x00000001 +#define OI_LIVF_SCOPE 0x00000002 +#define OI_LIVF_DEPTH 0x00000004 +#define OI_LIVF_TOKEN 0x00000008 +#define OI_LIVF_TIMEOUT 0x00000010 +#define OI_LIVF_OWNER 0x00000020 +#define OI_LIVF_ALL 0x0000003f + + +//ssl certificate problems +#define OI_SSL_ERR_UNABLE_TO_GET_ISSUER_CERT 0x00000001 +#define OI_SSL_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 0x00000002 +#define OI_SSL_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 0x00000004 +#define OI_SSL_ERR_CERT_SIGNATURE_FAILURE 0x00000008 +#define OI_SSL_ERR_CERT_NOT_YET_VALID 0x00000010 +#define OI_SSL_ERR_CERT_HAS_EXPIRED 0x00000020 +#define OI_SSL_ERR_OUT_OF_MEM 0x00000040 +#define OI_SSL_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 0x00000080 +#define OI_SSL_ERR_SELF_SIGNED_CERT_IN_CHAIN 0x00000100 +#define OI_SSL_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 0x00000200 +#define OI_SSL_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 0x00000400 +#define OI_SSL_ERR_CERT_CHAIN_TOO_LONG 0x00000800 +#define OI_SSL_ERR_CERT_REVOKED 0x00001000 +#define OI_SSL_ERR_INVALID_CA 0x00002000 +#define OI_SSL_ERR_PATH_LENGTH_EXCEEDED 0x00004000 +#define OI_SSL_ERR_INVALID_PURPOSE 0x00008000 +#define OI_SSL_ERR_CERT_UNTRUSTED 0x00010000 +#define OI_SSL_ERR_CERT_REJECTED 0x00020000 +#define OI_SSL_ERR_SUBJECT_ISSUER_MISMATCH 0x00040000 +#define OI_SSL_ERR_AKID_SKID_MISMATCH 0x00080000 +#define OI_SSL_ERR_AKID_ISSUER_SERIAL_MISMATCH 0x00100000 +#define OI_SSL_ERR_KEYUSAGE_NO_CERTSIGN 0x00200000 + +//various formats + +/* ISO8601: 2001-01-01T12:30:00Z */ +/* RFC1123: Sun, 06 Nov 1994 08:49:37 GMT */ +/* RFC850: Sunday, 06-Nov-94 08:49:37 GMT */ +/* asctime: Wed Jun 30 21:49:08 1993 */ +/* RFC2459: Sep 9 23:59:59 2004 GMT */ +#define OI_TIMEFORMAT_ISO8601_Z "%04d-%02d-%02dT%02d:%02d:%lfZ" +#define OI_TIMEFORMAT_ISO8601_M "%04d-%02d-%02dT%02d:%02d:%lf-%02d:%02d" +#define OI_TIMEFORMAT_ISO8601_P "%04d-%02d-%02dT%02d:%02d:%lf+%02d:%02d" + +#define OI_TIMEFORMAT_RFC1123 "%3s, %02d %3s %4d %02d:%02d:%02d GMT" +#define OI_TIMEFORMAT_RFC1036 "%s %2d-%3s-%2d %2d:%2d:%2d GMT" +#define OI_TIMEFORMAT_ASC "%3s %3s %2d %2d:%2d:%2d %4d" +#define OI_TIMEFORMAT_RFC2459 "%3s %d %02d:%02d:%02d %4d GMT" + + +//memory buffer +#define OI_MEMBUF_INITSIZE 4096 +#define OI_MEMBUF_INCRSIZE 4096 +#define OI_MEMBUF_SIZELIMIT 4*1024*1024 + + +#endif /*ONION_HEADER_ONIONDEF_H*/ Index: onion/onion/HandlerServer.h =================================================================== --- onion/onion/HandlerServer.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerServer.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,43 @@ +/* + Http header handler for "Server" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerServer.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERSERVER_H +#define ONION_HEADER_HANDLERSERVER_H 1 + +#include +#include + +//forward declaration +class CDavWorkSession; + +class CHandlerServer : public CResponseHeaderHandler +{ + public: + CHandlerServer(CDavWorkSession* pSession); + ~CHandlerServer(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + private: + CDavWorkSession* m_pSession; +}; + +#endif /*ONION_HEADER_HANDLERSERVER_H*/ Index: onion/onion/DavSSLDNameField.h =================================================================== --- onion/onion/DavSSLDNameField.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavSSLDNameField.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,47 @@ +/* + Field of distinguish name + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSSLDNameField.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSSLDNAMEFIELD_H +#define ONION_HEADER_DAVSSLDNAMEFIELD_H 1 + +#include +#include + +class CDavSSLDNameField +{ + private: + typedef std::vector VALUELIST, *PVALUELIST; + typedef VALUELIST::iterator VALUEITERATOR; + public: + CDavSSLDNameField(); + ~CDavSSLDNameField(); + void AddValue(const char* pszValue); + void Clear(); + unsigned int GetCount(); + const char* GetValue(unsigned int unIndex); + const char* operator[](unsigned int unIndex); + CDavSSLDNameField& operator=(const CDavSSLDNameField& master); + private: + VALUELIST m_vecValues; +}; + +#endif /*ONION_HEADER_DAVSSLDNAMEFIELD_H*/ Index: onion/onion/ResponseHeaderHandler.h =================================================================== --- onion/onion/ResponseHeaderHandler.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/ResponseHeaderHandler.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,43 @@ +/* + Prototype of http response header handler + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: ResponseHeaderHandler.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RESPONSEHEADERHANDLER_H +#define ONION_HEADER_RESPONSEHEADERHANDLER_H 1 + +#include + +//forward declarations +class CDavRequest; + +class CResponseHeaderHandler +{ + public: + CResponseHeaderHandler(void); + virtual ~CResponseHeaderHandler(void); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName() = 0; + public: + OI_STRING_A m_strValue; +}; + +#endif /*ONION_HEADER_RESPONSEHEADERHANDLER_H*/ Index: onion/onion/DavResponseBody.h =================================================================== --- onion/onion/DavResponseBody.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavResponseBody.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,58 @@ +/* + Http response body infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavResponseBody.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVRESPONSEBODY_H +#define ONION_HEADER_DAVRESPONSEBODY_H 1 + +#include + +//forward declarations +class CDavRequest; +class CDavSocket; + +/** Internal interface used by CRDavRequest + * + */ +class CDavResponseBody +{ + public: + CDavResponseBody(CDavRequest* pReq, CDavSocket* pSocket); + virtual ~CDavResponseBody(); + OI_RESULT Read(char* pszBuf, size_t unBufLen, size_t* punReadLen); + size_t Read(unsigned char* toFill, size_t maxToRead); + public: + OI_RSP_MODE m_enuMode; + OI_STRING_A m_strContentType; + OI_RESULT m_enuLastErr; + unsigned int m_unChunkNo; + size_t m_unReadLen; + size_t m_unChunkLeft; + size_t m_unChunkLen; + size_t m_unBodyLeft; + size_t m_unBodyLen; + private: + char* m_pszLocalBuf; //local buffer for readline + CDavRequest* m_pReq; + CDavSocket* m_pSocket; +}; + +#endif /*ONION_HEADER_DAVRESPONSEBODY_H*/ Index: onion/onion/RBPVDXmlLock.h =================================================================== --- onion/onion/RBPVDXmlLock.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDXmlLock.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,40 @@ +/* + Request body provider that provides XML for LOCK method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlLock.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDXMLLOCK_H +#define ONION_HEADER_RBPVDXMLLOCK_H 1 + +#include +#include + +//forward declarations +class CDavLock; + +class CRBPVDXmlLock : public CRBPVDXml +{ + public: + CRBPVDXmlLock(CDavLock* pLock); + ~CRBPVDXmlLock(); +}; + +#endif /*ONION_HEADER_RBPVDXMLLOCK_H*/ Index: onion/onion/DavXmlParser.h =================================================================== --- onion/onion/DavXmlParser.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavXmlParser.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,59 @@ +/* + SAX-DOM hybrid mode XML parser + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlParser.h,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVXMLPARSER_H +#define ONION_HEADER_DAVXMLPARSER_H 1 + +#include +#include + +//forward declarations +class CPBCSMXml; + +class CDavXmlParser : public XNS(XercesDOMParser) +{ + public: + CDavXmlParser(CPBCSMXml* pConsumer, const char* pszCutElement = NULL); + ~CDavXmlParser(); + + void error (const unsigned int errCode, + const XMLCh *const errDomain, + const ErrTypes type, + const XMLCh *const errorText, + const XMLCh *const systemId, + const XMLCh *const publicId, + const XMLSSize_t lineNum, + const XMLSSize_t colNum); + virtual void docCharacters (const XMLCh *const chars, + const unsigned int length, + const bool cdataSection); + virtual void endElement(const XNS(XMLElementDecl)& elemDecl, + const unsigned int urlId, + const bool isRoot, + const XMLCh* const elemPrefix); + + private: + OI_STRING_A m_strCutElement; + CPBCSMXml* m_pConsumer; +}; + +#endif /*ONION_HEADER_DAVXMLPARSER_H*/ Index: onion/onion/DavHost.h =================================================================== --- onion/onion/DavHost.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavHost.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Host infomation wrapper + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavHost.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVHOST_H +#define ONION_HEADER_DAVHOST_H 1 + +#include + +/**CDavHost is a wrapper to hold details + * regarding how to locate a dav server + */ +class CDavHost +{ + public: + CDavHost(); + CDavHost(const char *pszName, unsigned short usPort); + CDavHost(const CDavHost& old); + ~CDavHost(void); + const char* GetHostName(); + unsigned short GetPort(); + void SetHostName(const char *pszName); + void SetPort(unsigned short usPort); + CDavHost& operator=(const CDavHost& old); + private: + OI_STRING_A m_strHostName; + unsigned short m_usPort; + void copy(const CDavHost& old); +}; + +#endif /*ONION_HEADER_DAVHOST_H*/ Index: onion/onion/HandlerDAV.h =================================================================== --- onion/onion/HandlerDAV.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerDAV.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,40 @@ +/* + Http header handler for "DAV" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerDAV.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERDAV_H +#define ONION_HEADER_HANDLERDAV_H 1 + +#include +#include + + +class CHandlerDAV : public CResponseHeaderHandler +{ + public: + CHandlerDAV(); + ~CHandlerDAV(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + OI_STRING_A m_strDAV; +}; + +#endif /*ONION_HEADER_HANDLERDAV_H*/ Index: onion/onion/DavHttpStatus.h =================================================================== --- onion/onion/DavHttpStatus.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavHttpStatus.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,47 @@ +/* + Http status line infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavHttpStatus.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVHTTPSTATUS_H +#define ONION_HEADER_DAVHTTPSTATUS_H 1 + +#include + +/** CDavHttpStatus is an internal member of + * CDavRequest. + * It is used to parse status line of each HTTP response and hold + * relevant infomation. + */ +class CDavHttpStatus +{ + public: + CDavHttpStatus(); + ~CDavHttpStatus(); + OI_RESULT Parse(const char* pszBuf); + public: + int m_nMajorVersion; + int m_nMinorVersion; + int m_nCode; + int m_nCodeClass; + OI_STRING_A m_strReason; +}; + +#endif /*ONION_HEADER_DAVHTTPSTATUS_H*/ Index: onion/onion/PBCSMDummy.h =================================================================== --- onion/onion/PBCSMDummy.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/PBCSMDummy.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,42 @@ +/* + Response body consumer which bypasses all data + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMDummy.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_PBCSMDUMMY_H +#define ONION_HEADER_PBCSMDUMMY_H 1 + +#include +#include + +class CPBCSMDummy : public CResponseBodyConsumer +{ + public: + CPBCSMDummy(CDavRequest* pReq); + virtual ~CPBCSMDummy(); + + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_PBC_TYPE GetType(); + virtual OI_RESULT PullResponseBody(CDavResponseBody* pBody); +}; + +#endif /*ONION_HEADER_PBCSMDUMMY_H*/ Index: onion/onion/HandlerDASL.h =================================================================== --- onion/onion/HandlerDASL.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerDASL.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,39 @@ +/* + Http header handler for "DASL" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerDASL.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERDASL_H +#define ONION_HEADER_HANDLERDASL_H 1 + +#include +#include + +class CHandlerDASL : public CResponseHeaderHandler +{ + public: + CHandlerDASL(); + ~CHandlerDASL(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + OI_STRING_A m_strDASL; +}; + +#endif /*ONION_HEADER_HANDLERDASL_H*/ Index: onion/onion/DavWorkSession.h =================================================================== --- onion/onion/DavWorkSession.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavWorkSession.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,191 @@ +/* + Dav session handler + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavWorkSession.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVWORKSESSION_H +#define ONION_HEADER_DAVWORKSESSION_H 1 + +#include +#include +#include +#include +#include + +//forward declarations +class CDavSocket; +class CDavLock; +class CDavServerPolicy; +class CDavRequest; +class CDavResourceNode; +class CDavAuthManager; +class CDavMemBuffer; +class CDavXmlBuffer; +class CDavSSLCertificateList; +class CRBPVDXmlCopy; +class CRBPVDXmlMove; +class CRBPVDXmlProppatch; +class CRBPVDXmlSearch; +class CRequestBodyProvider; +class CResponseBodyConsumer; + +class CDavWorkSession : public CDavSession +{ + //friends + friend class CDavRequest; + friend class CDavSocket; + friend class CPBCSMXml; + public: + CDavWorkSession(); + virtual ~CDavWorkSession(); + void Disconnect(); + bool IsExpecting100(); + bool IsPersistent(); + bool IsHttp11(); + bool IsUsingSSL(); + bool IsUsingProxy(); + const char* GetServerString(); + size_t GetReadBytes(); + size_t GetWrittenBytes(); + CDavServerPolicy* GetServerPolicy(); + + void SetExpecting100(bool bValue); + void SetPersistent(bool bValue); + void SetHttp11(bool bValue); + void SetUseSSL(bool bValue); + void SetUseProxy(bool bValue); + OI_RESULT Connect(CDavRequest* pReq); + OI_CONN_STATE GetConnectState(); + CDavXmlBuffer* GetXmlBuffer(); + CDavMemBuffer* GetMemBuffer(); + CDavSSLCertificateList* GetUnauthenticCertificates(); + + virtual bool OnAuthentication(const char* pszRealm, + OI_STRING_A& strUsername, + OI_STRING_A& strPasswd, + int nRetry, + OI_AUTH_CLASS enuAuthClass); + + virtual void OnCancelSend(CDavRequest* pReq, + CRequestBodyProvider* pRBProvider); + virtual void OnCancelReceive(CDavRequest* pReq, + CResponseBodyConsumer* pPBConsumer); + + //override for request + virtual void OnCreateRequest(CDavRequest* pReq); + virtual void OnPreSendRequest(CDavRequest* pReq); + virtual void OnPostSendRequest(CDavRequest* pReq); + virtual void OnPreRecvResponse(CDavRequest* pReq); + virtual void OnPostRecvResponse(CDavRequest* pReq); + virtual void OnDestroyRequest(CDavRequest* pReq); + + virtual bool ProcessExtraHeader(CDavRequest* pReq, + const char* pszName, + const char* pszValue); + virtual bool MatchServerString(const char* pszHeaderValue, + const char* pszConfigValue); + //progress callbacks + virtual bool OnSendProgress(CDavRequest* pReq, + size_t unProgress, + size_t unTotal); + virtual bool OnReceiveProgress(CDavRequest* pReq, + size_t unProgress, + size_t unTotal, + bool bCLength); + virtual void OnResourceFound(CDavResourceNode* pNode); + virtual void OnSearchResponse(XNS(DOMNode)* pNode); + + //SSL callbacks + virtual bool OnVerifyCertificates(CDavSSLCertificateList* pUnauthenticCerts); + + //dav methods + OI_RESULT DoCopy(const char* pszSrc, + const char* pszDest, + CRBPVDXmlCopy* pXml = NULL, + bool bOverwrite = false, + const char* pszIfHeader = NULL); + OI_RESULT DoDelete(const char* pszURI, + const char* pszIfHeader = NULL); + OI_RESULT DoGet(const char* pszURI, + const char* pszLocalPath); + OI_RESULT DoHead(const char* pszURI); + OI_RESULT DoLock(const char* pszURI, + CDavLock* pLock, + const char* pszIfHeader = NULL); + OI_RESULT DoMkcol(const char* pszURI, + const char* pszIfHeader = NULL); + OI_RESULT DoMove(const char* pszSrc, + const char* pszDest, + CRBPVDXmlMove* pXml = NULL, + bool bOverwrite = false, + const char* pszIfHeader = NULL); + OI_RESULT DoOptions(const char* pszURI, + OI_STRING_A& strAllow, + OI_STRING_A& strDAV, + OI_STRING_A& strDASL, + OI_STRING_A& strMSV); + OI_RESULT DoPropfind(const char* pszURI, + OI_PFIND_DEPTH enuDepth = D_PFIND_ONE); + OI_RESULT DoProppatch(const char* pszURI, + CRBPVDXmlProppatch* pXml, + const char* pszIfHeader = NULL); + OI_RESULT DoPut(const char* pszURI, + const char* pszLocalPath, + const char* pszIfHeader = NULL, + const char* pszContentType = NULL); + OI_RESULT DoSearch(const char* pszURI, + CRBPVDXmlSearch* pXml); + OI_RESULT DoUnlock(const char* pszURI, + const char* pszLockToken); + + protected: + CDavSocket* getSocket(); + void addUnauthenticCert(X509* pX509, unsigned long ulFailures); + void OnResponseFound(CDavRequest* pReq, XNS(DOMNode)* pNode); + private: + void init(); + OI_RESULT proxyTunnel(); + OI_RESULT negotiateSSL(); + public: + int m_nLastStatusCode; + //in how many requests will current connection expire (-1 means never) + int m_nMaxConnections; + //when will current connection expire (-1 means never) + time_t m_tmConnectionTTL; + OI_STRING_A m_strServerString; + private: + bool m_bExpect100; + bool m_bHttp11; + bool m_bPersistent; + bool m_bUseSSL; + bool m_bUseProxy; + bool m_bPassiveMode; + CDavSocket* m_pSocket; + CDavAuthManager* m_pAuthManager; + CDavXmlBuffer* m_pXmlBuffer; + CDavMemBuffer* m_pMemBuffer; + CDavServerPolicy* m_pServerPolicy; + CDavSSLCertificateList* m_pUnauthenticCerts; + CDavLock* m_pCurrentLock; //pass info to/from callback in lock methods + OI_CONN_STATE m_enuConnState; + OI_OPCODE m_enuLastOperation; +}; + +#endif /*ONION_HEADER_DAVWORKSESSION_H*/ Index: onion/onion/DavServerPolicy.h =================================================================== --- onion/onion/DavServerPolicy.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavServerPolicy.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,100 @@ +/* + Configration to handle different kinds of servers + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavServerPolicy.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSERVERPOLICY_H +#define ONION_HEADER_DAVSERVERPOLICY_H 1 + +#include +#include +#include +#include + +//forward declarations +class CDavWorkSession; + +/**Container of server policy. + * + */ +class CDavServerPolicy +{ + public: + CDavServerPolicy(void); + ~CDavServerPolicy(void); + void Reset(); + void WriteDefaultConfig(const char* pszPath); + bool Load(const char* pszPath); + bool Load(CDavXmlBuffer* pXmlBuffer); + OI_RESULT CheckResponse(CDavWorkSession* pSession, + const char* pszServerString, + const char* pszRequest, + int nStatus, + const char* pszContentType, + OIOPERATION *pOperation); + private: + bool secureConfig(); + void generateDefault(); + bool initConfig(); + XNS(DOMElement)* appendElement(XNS(DOMElement)* pParent, + const XMLCh* pszName); + XNS(DOMElement)* appendMethod(XNS(DOMElement)* pParent, + const XMLCh* pszMethod, + const XMLCh* pszDefaultOp, + const XMLCh* pszDefaultErr); + XNS(DOMElement)* appendStatus(XNS(DOMElement)* pParent, + const XMLCh* pszStatus, + const XMLCh* pszChkBody, + const XMLCh* pszDefErr, + const XMLCh* pszDefOp); + XNS(DOMElement)* appendCType(XNS(DOMElement)* pParent, + const XMLCh* pszType, + const XMLCh* pszErrCode, + const XMLCh* pszOpCode); + private: + bool m_bReady; + + XNS(DOMDocument)* m_pConfig; + XNS(DOMElement)* m_pRoot; + XNS(DOMElement)* m_pDefaultMethods; + XNS(DOMElement)* m_pDefaultStatuses; + + /* + XNS(XercesDOMParser)* m_pParser; + XNS(ErrorHandler)* m_pErrHandler; + */ + CDavXmlBuffer m_xbfConfig; + + enum OI_OPCODE m_enuOpCode; + enum OI_RESULT m_enuError; + + //strings + const XMLCh* m_pszCType; + const XMLCh* m_pszType; + const XMLCh* m_pszErrCode; + const XMLCh* m_pszOpCode; + const XMLCh* m_pszChkBody; + const XMLCh* m_pszDefErr; + const XMLCh* m_pszDefOp; + const XMLCh* m_pszDefaultOp; + const XMLCh* m_pszDefaultErr; +}; + +#endif /*ONION_HEADER_DAVSERVERPOLICY_H*/ Index: onion/onion/RequestBodyProvider.h =================================================================== --- onion/onion/RequestBodyProvider.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RequestBodyProvider.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Prototype of http request body provider + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RequestBodyProvider.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_REQUESTBODYPROVIDER_H +#define ONION_HEADER_REQUESTBODYPROVIDER_H 1 + +#include + +//forward declaration +class CDavRequest; + +class CRequestBodyProvider +{ + public: + CRequestBodyProvider(void); + virtual ~CRequestBodyProvider(void); + + virtual OI_RBP_TYPE GetType() = 0; + virtual void Close() = 0; + virtual OI_RESULT Open() = 0; + virtual OI_RESULT Rewind() = 0; + virtual size_t GetBodyLength() = 0; + virtual void OnCancel(CDavRequest* pReq); + virtual OI_RESULT Read(CDavRequest* pReq, + char* pszBuf, + size_t* punReadLen) = 0; +}; + +#endif /*ONION_HEADER_REQUESTBODYPROVIDER_H*/ Index: onion/onion/DavSocket.h =================================================================== --- onion/onion/DavSocket.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavSocket.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,121 @@ +/* + Socket wrapper for http operations + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSocket.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSOCKET_H +#define ONION_HEADER_DAVSOCKET_H 1 + +#include +#include + +#if defined(__BEOS__) && !defined(BONE_VERSION) +# define ONION_WRITE(a,b,c) send(a,b,c,0) +# define ONION_READ(a,b,c) recv(a,b,c,0) +# define ONION_CLOSE(s) closesocket(s) +# define ONION_INVALIDSOCKET -1 +# define onion_errno errno +# define ONION_SOCKERR (-1) +# define ONION_EINTR EINTR +# define ONION_ISRESET(e) ((e) == ECONNRESET) +#elif defined(WIN32) +# define ONION_WRITE(a,b,c) send(a,b,c,0) +# define ONION_READ(a,b,c) recv(a,b,c,0) +# define ONION_CLOSE(s) closesocket(s) +# define ONION_INVALIDSOCKET INVALID_SOCKET +# define onion_errno WSAGetLastError() +# define ONION_SOCKERR SOCKET_ERROR +# define ONION_EINTR WSAEINTR +# define ONION_ISRESET(e) ((e == WSAECONNABORTED) || (e == WSAETIMEDOUT) ||\ + (e == WSAECONNRESET) || (e == WSAENETRESET)) +#else /* UNIX */ +# define ONION_WRITE(a,b,c) send(a,b,c, 0) +# define ONION_READ(a,b,c) recv(a,b,c, 0) +# define ONION_CLOSE(s) close(s) +# define ONION_INVALIDSOCKET -1 +# define onion_errno errno +# define ONION_SOCKERR (-1) +# define ONION_EINTR EINTR +# define ONION_ISRESET(e) ((e) == ECONNRESET) +#endif + +//forward declarations +class CDavWorkSession; +class IDavSocketIO; +class CDavSocketIOSSL; +class CDavSocketIORaw; + +/** Internal wrapper of socket + */ +class CDavSocket +{ + friend class IDavSocketIO; + friend class CDavSocketIOSSL; + friend class CDavSocketIORaw; + friend class CDavWorkSession; + public: + CDavSocket(CDavWorkSession* pSession); + virtual ~CDavSocket(void); + void ResetBuffer(); + void Disconnect(); + bool UseSSL(bool bUse); + bool IsUsingSSL(); + OI_RESULT Connect(const char* pszAddr, unsigned short usPort); + int GetHandle(); + unsigned int GetTimeout(); + void SetTimeout(unsigned int unTimeout); + size_t GetReadBytes(); + size_t GetWrittenBytes(); + CDavWorkSession* GetSession(); + OI_RESULT Read(char *pszBuf, size_t *punReadLen); + OI_RESULT ReadLine(char *pszBuf, size_t *punReadLen); + OI_RESULT FullRead(char *pszBuf, size_t *punReadLen); + OI_RESULT Peek(char *pszBuf, size_t *punReadLen); + OI_RESULT Write(const char *pszBuf, size_t *punWrittenLen); + void AddUnauthenticCert(X509* pX509, unsigned long ulFailures); + protected: + OI_RESULT connect(const struct sockaddr* pSockaddr, int nSockaddrLen); + OI_RESULT connectSSL(); + void cleanupSSL(); + void cleanupSSLSession(); + private: + OI_RESULT init(); + OI_RESULT initSSL(); + OI_RESULT destroySocket(); + private: + CDavWorkSession* m_pSession; + CDavSocketIORaw* m_pIOFuncRaw; + CDavSocketIOSSL* m_pIOFuncSSL; + IDavSocketIO* m_pIOFunc; + int m_hSocket; + bool m_bReady; + bool m_bConnected; + char* m_pszBuffer; + char* m_pszBufPos; + size_t m_unContentLen; + size_t m_unWriteCounter; + size_t m_unReadCounter; + unsigned int m_unTimeout; + SSL* m_pSSL; + SSL_SESSION* m_pSSLSession; + X509* m_pServerCertificate; +}; + +#endif /*ONION_HEADER_DAVSOCKET_H*/ Index: onion/onion/RBPVDXmlSearch.h =================================================================== --- onion/onion/RBPVDXmlSearch.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDXmlSearch.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for SEARCH method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlSearch.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDXMLSEARCH_H +#define ONION_HEADER_RBPVDXMLSEARCH_H 1 + +#include +#include + +class CRBPVDXmlSearch : public CRBPVDXml +{ + public: + CRBPVDXmlSearch(); + ~CRBPVDXmlSearch(); +}; + +#endif /*ONION_HEADER_RBPVDXMLSEARCH_H*/ Index: onion/onion/DavSocketIORaw.h =================================================================== --- onion/onion/DavSocketIORaw.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavSocketIORaw.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Raw socket I/O methods + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSocketIORaw.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSOCKETIORAW_H +#define ONION_HEADER_DAVSOCKETIORAW_H 1 + +#include +#include + +/** Class for raw socket IO operations. + * + */ +class CDavSocketIORaw : public IDavSocketIO +{ + public: + CDavSocketIORaw(); + ~CDavSocketIORaw(); + + OI_RESULT Readable(CDavSocket* pSocket, + int nSecs); + OI_RESULT Read(CDavSocket* pSocket, + char* pszBuf, + size_t* punReadLen, + int nSecs); + OI_RESULT Write(CDavSocket* pSocket, + const char* pszBuf, + size_t* punWrittenLen); +}; + +#endif /*ONION_HEADER_DAVSOCKETIORAW_H*/ Index: onion/onion/PBCSMXml.h =================================================================== --- onion/onion/PBCSMXml.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/PBCSMXml.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,60 @@ +/* + Response body consumer that parses body as an XML stream + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMXml.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_PBCSMXML_H +#define ONION_HEADER_PBCSMXML_H 1 + +#include +#include +#include + +//forward declarations +class CDavXmlBuffer; +class CDavXmlErrorHandler; +class CDavXmlParser; + +class CPBCSMXml : public CResponseBodyConsumer +{ + public: + CPBCSMXml(CDavRequest* pReq, + const char* pszCutElement = NULL, + CDavXmlBuffer* pXmlReceiver = NULL); + virtual ~CPBCSMXml(); + + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_PBC_TYPE GetType(); + virtual OI_RESULT CheckCType(const char* pszCType); + virtual OI_RESULT PullResponseBody(CDavResponseBody* pBody); + + virtual void OnResponseFound(XNS(DOMNode)* pNode); + XNS(DOMDocument)* GetDocument(); + private: + OI_STRING_A m_strCutElement; + CDavXmlErrorHandler* m_pErrorHandler; + CDavXmlParser* m_pXmlParser; + CDavXmlBuffer* m_pXmlReceiver; + int m_nResponseCounter; +}; + +#endif /*ONION_HEADER_PBCSMXML_H*/ Index: onion/onion/RBPVDXmlMove.h =================================================================== --- onion/onion/RBPVDXmlMove.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDXmlMove.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for MOVE method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlMove.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDXMLMOVE_H +#define ONION_HEADER_RBPVDXMLMOVE_H 1 + +#include +#include + +class CRBPVDXmlMove : public CRBPVDXml +{ + public: + CRBPVDXmlMove(); + ~CRBPVDXmlMove(); +}; + +#endif /*ONION_HEADER_RBPVDXMLMOVE_H*/ Index: onion/onion/DavXmlInputStream.h =================================================================== --- onion/onion/DavXmlInputStream.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavXmlInputStream.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,47 @@ +/* + Input stream needed by input source + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlInputStream.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVXMLINPUTSTREAM_H +#define ONION_HEADER_DAVXMLINPUTSTREAM_H 1 + +#include +#include + +//forward declarations +class CDavResponseBody; + +class CDavXmlInputStream : public XNS(BinInputStream) +{ + public: + CDavXmlInputStream(CDavResponseBody* pBody); + virtual ~CDavXmlInputStream(); + + virtual unsigned int readBytes(XMLByte* const toFill, + const unsigned int maxToRead); + virtual unsigned int curPos() const; + + private: + CDavResponseBody* m_pBody; + size_t m_unByteCounter; +}; + +#endif /*ONION_HEADER_DAVXMLINPUTSTREAM_H*/ Index: onion/onion/PBCSMAuthBasic.h =================================================================== --- onion/onion/PBCSMAuthBasic.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/PBCSMAuthBasic.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,42 @@ +/* + Response body consumer in case of basic authentication + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMAuthBasic.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_PBCSMAUTHBASIC_H +#define ONION_HEADER_PBCSMAUTHBASIC_H 1 + +#include +#include + +class CPBCSMAuthBasic : public CResponseBodyConsumer +{ + public: + CPBCSMAuthBasic(CDavRequest* pReq); + virtual ~CPBCSMAuthBasic(); + + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_PBC_TYPE GetType(); + virtual OI_RESULT PullResponseBody(CDavResponseBody* pBody); +}; + +#endif /*ONION_HEADER_PBCSMAUTHBASIC_H*/ Index: onion/onion/RBPVDDummy.h =================================================================== --- onion/onion/RBPVDDummy.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDDummy.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,48 @@ +/* + Request body provider that provides nothing + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDDummy.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDDUMMY_H +#define ONION_HEADER_RBPVDDUMMY_H 1 + +#include +#include + +class CRBPVDDummy : public CRequestBodyProvider +{ + public: + CRBPVDDummy(); + virtual ~CRBPVDDummy(); + + virtual OI_RBP_TYPE GetType(); + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_RESULT Rewind(); + virtual size_t GetBodyLength(); + virtual void OnCancel(CDavRequest* pReq); + virtual OI_RESULT Read(CDavRequest* pReq, + char* pszBuf, + size_t* punReadLen); + +}; + +#endif /*ONION_HEADER_RBPVDDUMMY_H*/ Index: onion/onion/RBPVDXmlCopy.h =================================================================== --- onion/onion/RBPVDXmlCopy.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDXmlCopy.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for COPY method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlCopy.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDXMLCOPY_H +#define ONION_HEADER_RBPVDXMLCOPY_H 1 + +#include +#include + +class CRBPVDXmlCopy : public CRBPVDXml +{ + public: + CRBPVDXmlCopy(); + ~CRBPVDXmlCopy(); +}; + +#endif /*ONION_HEADER_RBPVDXMLCOPY_H*/ Index: onion/onion/DavSocketIOSSL.h =================================================================== --- onion/onion/DavSocketIOSSL.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavSocketIOSSL.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,52 @@ +/* + SSL socket I/O methods + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSocketIOSSL.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSOCKETIOSSL_H +#define ONION_HEADER_DAVSOCKETIOSSL_H 1 + +#include +#include + +/** Class for SSL socket IO operations. + * + */ + +class CDavSocketIOSSL : public IDavSocketIO +{ + public: + CDavSocketIOSSL(); + ~CDavSocketIOSSL(); + + OI_RESULT Readable(CDavSocket* pSocket, + int nSecs); + OI_RESULT Read(CDavSocket* pSocket, + char* pszBuf, + size_t* punReadLen, + int nSecs); + OI_RESULT Write(CDavSocket* pSocket, + const char* pszBuf, + size_t* punWrittenLen); + OI_RESULT ossl_error(CDavSocket *pSocket, + int nErrCode); +}; + +#endif /*ONION_HEADER_DAVSOCKETIOSSL_H*/ Index: onion/onion/HandlerProxyConn.h =================================================================== --- onion/onion/HandlerProxyConn.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerProxyConn.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,38 @@ +/* + Http header handler for "Proxy-Connection" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerProxyConn.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERPROXYCONN_H +#define ONION_HEADER_HANDLERPROXYCONN_H 1 + +#include +#include + +class CHandlerProxyConn : public CResponseHeaderHandler +{ + public: + CHandlerProxyConn(); + ~CHandlerProxyConn(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); +}; + +#endif /*ONION_HEADER_HANDLERPROXYCONN_H*/ Index: onion/onion/RBPVDXml.h =================================================================== --- onion/onion/RBPVDXml.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDXml.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,71 @@ +/* + Request body provider that provides XML contents + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXml.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDXML_H +#define ONION_HEADER_RBPVDXML_H 1 + +#include +#include +#include + +#include +#include +#include + +class CRBPVDXml : public CRequestBodyProvider +{ + public: + CRBPVDXml(const char* pszDocName = OI_XML_PROPFINDDOCNAME); + virtual ~CRBPVDXml(); + + virtual OI_RBP_TYPE GetType(); + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_RESULT Rewind(); + virtual size_t GetBodyLength(); + virtual void OnCancel(CDavRequest* pReq); + virtual OI_RESULT Read(CDavRequest* pReq, + char* pszBuf, + size_t* punReadLen); + + void AddRootElement(const char* pszNS, const char* pszName); + void AddNamespaceMapping(const char* pszPrefix, const char* pszURI); + void SetDocumentName(const char* pszName); + bool Load(const char* pszPath); + bool Load(CDavXmlBuffer* pXmlBuffer); + protected: + void GenerateXml(); + + protected: + CDavXmlBuffer m_xbfBody; + char* m_pszBuf; + + size_t m_unBufLen; + size_t m_unCurPos; + private: + + XNS(DOMWriter)* m_pDomWriter; + XNS(MemBufFormatTarget)* m_pFormatTarget; +}; + +#endif /*ONION_HEADER_RBPVDXML_H*/ Index: onion/onion/DavAuthSession.h =================================================================== --- onion/onion/DavAuthSession.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavAuthSession.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,106 @@ +/* + Authentication session + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavAuthSession.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVAUTHSESSION_H +#define ONION_HEADER_DAVAUTHSESSION_H 1 + +#include + +//forward declarations +class CDavAuthManager; +class CDavRequest; +/** CDavAuthSession manages all authentication activities. + * Each CDavWorkSession will create 2 auth sessions upon + * construction, one for server auth and the other for proxy auth. + */ +class CDavAuthSession +{ + public: + CDavAuthSession(CDavAuthManager* pMgr, + const char* pszRequestHeader, + const char* pszResponseHeader, + const char* pszResponseInfoHeader, + unsigned int unStatusCode, + OI_AUTH_CLASS enuClass); + ~CDavAuthSession(); + private: + CDavAuthManager* m_pAuthManager; + const char* m_pszRequestHeader; + const char* m_pszResponseHeader; + const char* m_pszResponseInfoHeader; + OI_STRING_A m_strAuthInfoHeader; + OI_STRING_A m_strDigest; + OI_STRING_A m_strStoredDigest; + OI_STRING_A m_strOpaque; + OI_STRING_A m_strBasic; + OI_STRING_A m_strNonce; + OI_STRING_A m_strCNonce; + OI_STRING_A m_strRealm; + OI_STRING_A m_strPasswd; + OI_STRING_A m_strUsername; + OI_STRING_A m_strHA1; + int m_nStatusCode; + unsigned int m_unNonceCount; + unsigned int m_unAttempt; + + bool m_bGotAuthHeader; //got Auth Header field + bool m_bGotAuthInfoHeader; //got Auth Info Header field + bool m_bGotQop; //got Auth QOP field + bool m_bGotAlgorithm; //got Algorithm field + bool m_bGotStale; //got Stale field + bool m_bGotOpaque; //got Qpaque field + bool m_bGotNonce; //got Nonce field + bool m_bGotRealm; //got Realm field + bool m_bGotScheme; //got Scheme field + bool m_bStale; //session needs refresh + OI_AUTH_CLASS m_enuClass; + OI_AUTH_SCHEME m_enuScheme; + OI_AUTH_STATE m_enuState; + OI_AUTH_QOP m_enuQop; + public: + const char* GetUsername(); + const char* GetPasswd(); + const char* GetAuthHeaderName(); + const char* GetAuthInfoHeaderName(); + OI_AUTH_SCHEME GetAuthScheme(); + OI_AUTH_STATE GetAuthState(); + void SetUsername(const char* pszUsername); + void SetPasswd(const char* pszPasswd); + void Reset(); + void SetAuthInfoHeader(const char* pszValue); + void ParseAuthHeader(const char* pszValue); + virtual OI_RESULT OnCreateRequest(CDavRequest* pReq); + virtual OI_RESULT OnPreSendRequest(CDavRequest* pReq); + virtual OI_RESULT QueryEndRequest(CDavRequest* pReq); + private: + OI_RESULT challenge(); + OI_RESULT basicChallenge(); + OI_RESULT digestChallenge(); + OI_RESULT verifyResponse(CDavRequest* pReq, + const char* pszValue, + const char* pszURI); + bool requestDigest(CDavRequest* pReq); + bool requestCredential(); + void updateCNonce(); +}; + +#endif /*ONION_HEADER_DAVAUTHSESSION_H*/ Index: onion/onion/Utils.h =================================================================== --- onion/onion/Utils.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/Utils.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,144 @@ +/* + Utility functions + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: Utils.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_UTILS_H +#define ONION_HEADER_UTILS_H 1 + +#include + +typedef void (*OSSLLOCKCALLBACK)(int nMode, + int nType, + const char *pszFile, + int nLine); +typedef void (*ONIONDEBUGLOCKCALLBACK)(const char *pszFile, + int nLine); + +extern OI_RESULT OnionInitialize(OSSLLOCKCALLBACK sslLockCallback = NULL); +extern void OnionTerminate(); +extern int OnionNumOfLocks(); +extern void OnionSetDebugLockCallback(ONIONDEBUGLOCKCALLBACK debugLockCallback); +extern OI_RESULT OnionRedirectDebugOutput(const char* pszPath, + const char* pszMode = "w"); +extern void OnionDebugOutput(const char* pszFormat, ...); +extern void OnionSetDebugOptions(unsigned int unOptions); +extern const char* GetErrorDescription(OI_RESULT enuResult); + +extern void MakeLowerA(OI_STRING_A& strAnsi); +extern void TrimLeftA(OI_STRING_A& strAnsi); +extern void TrimRightA(OI_STRING_A& strAnsi); +extern OI_STRING_A Utf8ToAnsi(const OI_STRING_A& sUtf8); +extern OI_STRING_A AnsiToUtf8(const OI_STRING_A& sAnsi); +extern OI_STRING_A Unescape(const OI_STRING_A& uri); +extern OI_STRING_A Escape(const OI_STRING_A& uri); +extern OI_STRING_A Base64Encode(const OI_STRING_A& input); +extern OI_STRING_A Base64Decode(const OI_STRING_A& input); +/*MD5 hash for strings*/ +extern OI_STRING_A HashString(const OI_STRING_A& input); +/*string hash with ms algorithm*/ +extern unsigned int FastHash(const OI_STRING_A& input); + +extern time_t ParseTime(const char* pszTime); +extern time_t ParseTimeASC(const char* pszTime); +extern time_t ParseTimeISO8601(const char* pszTime); +extern time_t ParseTimeRFC1036(const char* pszTime); +extern time_t ParseTimeRFC1123(const char* pszTime); +extern time_t ParseTimeRFC2459(const char* pszTime); +extern time_t GmtToLocal(time_t gmt); + +/** Wrapper class for MD5 hash algorithm + */ +class CDavMD5 +{ + public: + CDavMD5(); + ~CDavMD5(); + void Init(); + void UpdateHash(const void *pvData, unsigned int unLen); + void Finalize(unsigned char yBuf[16]); + OI_STRING_A GetHashString(); + private: + MD5_UINT32 m_unA; + MD5_UINT32 m_unB; + MD5_UINT32 m_unC; + MD5_UINT32 m_unD; + MD5_UINT32 m_unTotal[2]; + MD5_UINT32 m_unBufLen; + char m_szBuf[128]; + void updateBlock(const void *pvData, unsigned int unLen); + void getHash(unsigned char yBuf[16]); +}; + +//light wrapper for tokenize function +//Warning: this class is intended for local use only +//all pointers must remain valid during tokenization +//process +class CDavStringTokenizer +{ + public: + CDavStringTokenizer(const char* pszInput, const char* pszDelimiters = " "); + ~CDavStringTokenizer(); + private: + bool m_bInQuote; + const char* m_pszDelimiters; + const char* m_pszCurrentPos; + const char* m_pszHead; + public: + bool GetNextToken(OI_STRING_A& strOutput); + void SetToken(const char* pszInput); + void SetDelimiter(const char* pszDelimiter); + private: + bool IsDelimiter(char chInput); +}; + +class CDavXmlString +{ + public: + CDavXmlString(); + CDavXmlString(const CDavXmlString& master); + CDavXmlString(const char* pszANSIStr); + CDavXmlString(const XMLCh* pszXMLStr); + CDavXmlString(const XMLByte* pszUTF8Str); + ~CDavXmlString(); + unsigned int Length(); + char* UTF8(); + operator const char*(); + operator const XMLCh*(); + CDavXmlString& operator=(const CDavXmlString& master); + CDavXmlString& operator=(const char* pszANSIStr); + CDavXmlString& operator=(const XMLCh* pszXMLStr); + CDavXmlString& operator=(const XMLByte* pszUTF8Str); + CDavXmlString& toEscapedUTF8(); + private: + void cleanup(); + void copy(const char* pszANSIStr); + void copy(const XMLCh* pszXMLStr); + void copy(const CDavXmlString& master); + void transcode(const XMLByte* pszUTF8Str); + private: + XMLCh* m_pszXMLStr; + char* m_pszANSIStr; +}; + +typedef CDavXmlString X; + +#endif /*ONION_HEADER_UTILS_H*/ Index: onion/onion/OnionCfg.h =================================================================== --- onion/onion/OnionCfg.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/OnionCfg.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,35 @@ +/* + General config of onion library + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: OnionCfg.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_ONIONCFG_H +#define ONION_HEADER_ONIONCFG_H 1 + +#ifdef WIN32 +# include +#endif //WIN32 +#include +#include +#include +#include +#include + +#endif /*ONION_HEADER_ONIONCFG_H*/ Index: onion/onion/DavXmlErrorHandler.h =================================================================== --- onion/onion/DavXmlErrorHandler.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavXmlErrorHandler.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,38 @@ +/* + Error handler needed by XML parser + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlErrorHandler.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVXMLERRORHANDLER_H +#define ONION_HEADER_DAVXMLERRORHANDLER_H 1 + +#include +#include + +class CDavXmlErrorHandler : public XNS(HandlerBase) +{ + public: + CDavXmlErrorHandler(void); + ~CDavXmlErrorHandler(void); + virtual void error(const XNS(SAXParseException) &exception); + virtual void fatalError(const XNS(SAXParseException) &exception); +}; + +#endif /*ONION_HEADER_DAVXMLERRORHANDLER_H*/ Index: onion/onion/DavMemBuffer.h =================================================================== --- onion/onion/DavMemBuffer.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavMemBuffer.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,58 @@ +/* + Variable length buffer + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavMemBuffer.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVMEMBUFFER_H +#define ONION_HEADER_DAVMEMBUFFER_H 1 + +#include + +/** Variable length buffer + * + */ +class CDavMemBuffer +{ + public: + CDavMemBuffer(size_t unInitSize = OI_MEMBUF_INITSIZE, + size_t unSizeLimit = OI_MEMBUF_SIZELIMIT, + size_t unIncrSize = OI_MEMBUF_INCRSIZE); + ~CDavMemBuffer(); + void Clear(); + size_t GetBufferSize(); + size_t GetDataSize(); + size_t GetIncrementSize(); + size_t Write(const void* pyData, size_t unDataLen); + const void* GetData(); + size_t SetIncrementSize(size_t unNewSize); + private: + size_t grow(size_t unNewSize); + bool ensureCapacity(size_t unWriteSize); + public: + OI_STRING_A m_strContentType; + private: + size_t m_unBufLen; + size_t m_unDataLen; + size_t m_unIncrSize; + size_t m_unSizeLimit; + void* m_pyBufHead; +}; + +#endif /*ONION_HEADER_DAVMEMBUFFER_H*/ Index: onion/onion/HandlerKeepAlive.h =================================================================== --- onion/onion/HandlerKeepAlive.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerKeepAlive.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,38 @@ +/* + Http header handler for "Keep-Alive" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerKeepAlive.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERKEEPALIVE_H +#define ONION_HEADER_HANDLERKEEPALIVE_H 1 + +#include +#include + +class CHandlerKeepAlive : public CResponseHeaderHandler +{ + public: + CHandlerKeepAlive(); + ~CHandlerKeepAlive(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); +}; + +#endif /*ONION_HEADER_HANDLERKEEPALIVE_H*/ Index: onion/onion/HandlerMSV.h =================================================================== --- onion/onion/HandlerMSV.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerMSV.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,40 @@ +/* + Http header handler for "MS-Author-Via" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerMSV.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERMSV_H +#define ONION_HEADER_HANDLERMSV_H 1 + +#include +#include + + +class CHandlerMSV : public CResponseHeaderHandler +{ + public: + CHandlerMSV(); + ~CHandlerMSV(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + OI_STRING_A m_strMSV; +}; + +#endif /*ONION_HEADER_HANDLERMSV_H*/ Index: onion/onion/HandlerTE.h =================================================================== --- onion/onion/HandlerTE.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerTE.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,43 @@ +/* + Http header handler for "Transfer-Encoding" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerTE.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERTE_H +#define ONION_HEADER_HANDLERTE_H 1 + +#include +#include + +//forward declarations +class CDavResponseBody; + +class CHandlerTE : public CResponseHeaderHandler +{ + public: + CHandlerTE(CDavResponseBody* pBody); + ~CHandlerTE(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + private: + CDavResponseBody* m_pBody; +}; + +#endif /*ONION_HEADER_HANDLERTE_H*/ Index: onion/onion/OnionTypes.h =================================================================== --- onion/onion/OnionTypes.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/OnionTypes.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,259 @@ +/* + Types of onion library + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: OnionTypes.h,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_ONIONTYPES_H +#define ONION_HEADER_ONIONTYPES_H 1 +#include +#include + +enum OI_RESULT{ + //generic errors + OIGEUNKNOWN = -1, //unknown generic error + OIGENOTIMPLEMENTED = -2, //feature not implemented + OIGEINVALIDARG = -3, //invalid argument + OIGECANTOPENFILE = -4, //can not open file + OIGEPASSIVELOCK = -5, //the session is locked in passive mode + + //status code + OI_OK = 0, + OI_RETRY = 1, + OI_USERCANCELED = 2, + + //encryption(ssl) errors + OIEEGENERIC = 201, //Generic SSL Error + OIEENOENTROPY = 202, //No entropy source found. could not seed PRNG + OIEELACKOFENTROPY = 203, //SSL disabled due to lack of entropy + OIEEDATAINITFAILED = 204, //SSL data initialization failed + OIEESSLINITFAILED = 205, //SSL initialization failed + OIEENOSERVERCERT = 206, //SSL server certificate did not present + OIEEINVALIDCERT = 207, //SSL server certificate invalid + OIEECERTCHANGED = 208, //Server certificate changed, connection may be intercepted + OIEECERTCHECKFAILED = 209, //Certificate check failed + OIEECNMISMATCH = 210, //CN Mismatch + OIEETUNNELFAILED = 211, //proxy tunnel failed + + //HTTP protocol errors + OIHELINETOOLONG = 301, //HeaderLine Too Long + OIHETOOMANYHEADERS = 302, //Too many header fields + OIHEPROTOCOLPANIC = 303, //The response in not a Http status + OIHECHUNKSIZE = 304, //response chunk size parse error + + //XML errors + OIXEINITFAILED = 401, //Xerces init failed + + //socket errors + OISEGEN = 501, //generic(unclear) error + OISETIMEOUT = 502, + OISECLOSED = 503, //Socket Closed + OISERESET = 504, + OISELINETOOLONG = 505, //Line Too Long + OISECONNABORTED = 506, //Connection aborted by server + + OISEINITFAILED = 507, //socket version too low + OISEINITIALIZED = 508, //socket already initialized + OISECLEANUPFAILED = 509, //socket clean up failed + OISEHOSTNOTFOUND = 510, //host not found + OISEINVALIDSOCK = 511, //can not get sock from system + OISESOCKVER = 512, //socket version not supported by OS + OISECONNFAILED = 513, //system connection failed + OISETRUNC = 514, + + //resource parse errors + OIRESYNTAX = 601, //XML syntax error + OIREHREFNOTFOUND = 602, //href element not found while parsing response + + //authentication errors + OIAEHEADERSYNTAX = 701, //header is not well-formed + OIAEFAILEDTOGETCRED = 702, //failed to get credential(the OnAuthentication handler returned false) + OIAEDIGMISMATCH = 703, //Digest mismatch, connection could be intercepted + OIAEINVALIDSCHEME = 704, //invalid auth scheme + OIAECNONCEMISMATCH = 705, //cnonce mismatch + OIAENONCEMISMATCH = 706, //nonce mismatch + + //DAV errors + OIDENOCONTENT = 801, //204 no content + OIDEMULTISTATUS = 802, //207 multistatus + OIDEBADREQUEST = 803, //400 Bad Request + OIDEFORBIDDEN = 804, //403 forbidden + OIDENOTFOUND = 805, //404 not found + OIDENOTALLOWED = 806, //405 not allowed + OIDECONFLICT = 807, //409 conflict + OIDEPCONFAILED = 808, //412 Precondition Failed + OIDELOCKED = 809, //423 Locked + OIDEFAILEDDEPS = 810, //424 Failed Dependency + OIDEINTRSVRERR = 812, //500 Internal Server Error + OIDEBADGATEWAY = 813, //502 Bad Gateway + OIDESERVICENOTAVAIL = 814, //503 Service Not Available + OIDECTYPEMISMATCH = 818, //unexpected content type + OIDEREDIRECT = 819, //301 Moved + OIDEINSUFFSTG = 820, //507 Insufficient Storage + OIDEPAYMENTREQUIRED = 821, //402 Payment Required + + //system errors + OIYEREQNOTFOUND = 901, //request not found in library's config + OIYESTATUSNOTFOUND = 902, //status code not found in library's config + OIYECTYPENOTFOUND = 903, //content type mismatch(no such type in library's config) + OIYECONFINITFAILED = 904, //server profile config initialization failed + OIYECONFSYNTAX = 905, //server profile config syntax error +}; + +enum OI_OPCODE + { + OP_NONE = -1, + OP_USE_DEFAULT = 0, //use default body consumer + OP_SIMPLE_ERR = 1, //return simple error code(currently same as OP_USE_DEFAULT) + // OP_COMP_ERR = 2, //????? //not used + OP_PARSE_ERR_XML = 3, //construct an xml parser and parse xml error + OP_CACHE_HTML = 4, //put response body in session cache + OP_PARSE_LOCK = 5, //construct an xml parser and parse lock out of the body + OP_PARSE_RESPONSE = 6, //for PROPFIND, parse response from stream + OP_AUTHENTICATE = 7, //use auth-manager to handle authentication header + }; + +enum OI_REQ_TYPE + { + T_REQ_INVALID = 0, + T_REQ_CONNECT = 1, + T_REQ_COPY = 2, + T_REQ_DELETE = 3, + T_REQ_GET = 4, + T_REQ_LOCK = 5, + T_REQ_MKCOL = 6, + T_REQ_MOVE = 7, + T_REQ_OPTIONS = 8, + T_REQ_POST = 9, + T_REQ_PROPFIND = 10, + T_REQ_PROPPATCH = 11, + T_REQ_PUT = 12, + T_REQ_UNLOCK = 13, + T_REQ_SEARCH = 14, + T_REQ_HEAD = 15, + }; + +enum OI_RSP_MODE + { + M_RSP_TILLEOF = 0, // read till eof + M_RSP_NO_BODY = 1, // implicitly no body (method HEAD, 204 No Content, 304) + M_RSP_CHUNKED = 2, // using chunked transfer-encoding + M_RSP_CLENGTH = 3, // using given content-length + }; + +enum OI_CONN_STATE + { + S_CONN_DISCONNECTED, + S_CONN_RESOLVE, // resolving host name + S_CONN_CONNECTING, // connection + S_CONN_CONNECTED, // normal connection established + S_CONN_TUNNELED // proxy tunnel established + }; + + +enum OI_RBP_TYPE + { + T_RBP_UNKNOWN = -1, + T_RBP_DUMMY = 0, + T_RBP_BUFFER = 1, + T_RBP_CUSTOM = 2, + T_RBP_FILE = 3, + T_RBP_XML = 4, + }; + +enum OI_PBC_TYPE + { + T_PBC_UNKNOWN = -1, + T_PBC_DUMMY = 0, + T_PBC_BUFFER = 1, + T_PBC_FILE = 3, + T_PBC_XML = 4, + }; + +enum OI_AUTH_CLASS + { + C_AUTH_INVALID = 0, + C_AUTH_SERVER = 1, + C_AUTH_PROXY = 2, + }; + +enum OI_AUTH_SCHEME + { + H_AUTH_INVALID = 0, + H_AUTH_NOAUTH = 1, + H_AUTH_BASIC = 2, + H_AUTH_DIGEST = 3, + }; + +enum OI_AUTH_STATE + { + S_AUTH_UNAUTHENTICATED = 1, + S_AUTH_AUTHENTICATED = 2, + }; + +enum OI_AUTH_QOP + { + Q_AUTH_NONE = 1, + Q_AUTH_AUTH = 2, + Q_AUTH_AUTHINT = 3, + }; + +//resource node type +enum OI_RES_TYPE + { + T_RES_NORMAL = 1, + T_RES_COLLECTION = 2, + }; + +enum OI_LOCK_TYPE + { + T_LOCK_WRITE = 1, + }; + +enum OI_LOCK_SCOPE + { + SCP_LOCK_EXCLUSIVE = 1, + SCP_LOCK_SHARED = 2, + }; + +enum OI_LOCK_DEPTH + { + D_LOCK_ZERO = 1, + D_LOCK_INFINITE = 2, + }; + +enum OI_PFIND_DEPTH + { + D_PFIND_ZERO = 1, + D_PFIND_ONE = 2, + D_PFIND_INFINITE = 3, + }; + +typedef unsigned int MD5_UINT32; +typedef std::basic_string OI_STRING_A; +typedef std::stringstream OI_STRSTREAM_A; + +typedef struct tagOIOPERATION +{ + OI_OPCODE enuOpCode; + OI_RESULT enuErrCode; + char szCutElement[OI_MAX_ELEM_LEN + 1]; +}OIOPERATION, *POIOPERATION; + +#endif /*ONION_HEADER_ONIONTYPES_H*/ Index: onion/onion/HandlerAuthInfo.h =================================================================== --- onion/onion/HandlerAuthInfo.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerAuthInfo.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,43 @@ +/* + Http header handler for "AuthInfo" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerAuthInfo.h,v 1.1.1.1 2004/07/15 06:58:43 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERAUTHINFO_H +#define ONION_HEADER_HANDLERAUTHINFO_H 1 + +#include +#include + +//forward declarations +class CDavAuthSession; + +class CHandlerAuthInfo : public CResponseHeaderHandler +{ + public: + CHandlerAuthInfo(CDavRequest* pReq, CDavAuthSession* pAuthSession); + ~CHandlerAuthInfo(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + private: + CDavAuthSession* m_pAuthSession; +}; + +#endif /*ONION_HEADER_HANDLERAUTHINFO_H*/ Index: onion/onion/HandlerAllow.h =================================================================== --- onion/onion/HandlerAllow.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerAllow.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,40 @@ +/* + Http header handler for "Allow" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerAllow.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERALLOW_H +#define ONION_HEADER_HANDLERALLOW_H 1 + +#include +#include + + +class CHandlerAllow : public CResponseHeaderHandler +{ + public: + CHandlerAllow(); + ~CHandlerAllow(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + OI_STRING_A m_strAllow; +}; + +#endif /*ONION_HEADER_HANDLERALLOW_H*/ Index: onion/onion/DavSession.h =================================================================== --- onion/onion/DavSession.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavSession.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,50 @@ +/* + Main session infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSession.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVSESSION_H +#define ONION_HEADER_DAVSESSION_H 1 + +#include +#include +/** Base class of CDavWorkSession. + * This is only an abstraction regarding how + * to connect to a dav server. + */ +class CDavSession +{ + public: + CDavSession(void); + ~CDavSession(void); + const char* GetUserAgent(); + void SetUserAgent(const char* pszUserAgent); + CDavHost& GetHost(); + CDavHost& GetProxy(); + void SetHost(const CDavHost& Server); + void SetProxy(const CDavHost& Server); + protected: + CDavHost m_Server; + CDavHost m_Proxy; + private: + OI_STRING_A m_strUserAgent; +}; + +#endif /*ONION_HEADER_DAVSESSION_H*/ Index: onion/onion/PBCSMLocalFile.h =================================================================== --- onion/onion/PBCSMLocalFile.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/PBCSMLocalFile.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,45 @@ +/* + Response body consumer that writes to a local file + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMLocalFile.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_PBCSMLOCALFILE_H +#define ONION_HEADER_PBCSMLOCALFILE_H 1 + +#include +#include + +class CPBCSMLocalFile : public CResponseBodyConsumer +{ + public: + CPBCSMLocalFile(CDavRequest* pReq, int nHandle); + virtual ~CPBCSMLocalFile(); + + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_PBC_TYPE GetType(); + virtual OI_RESULT PullResponseBody(CDavResponseBody* pBody); + private: + int m_nHandle; + //long m_lPosition; +}; + +#endif /*ONION_HEADER_PBCSMLOCALFILE_H*/ Index: onion/onion/RBPVDXmlProppatch.h =================================================================== --- onion/onion/RBPVDXmlProppatch.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDXmlProppatch.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for PROPPATCH method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlProppatch.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDXMLPROPPATCH_H +#define ONION_HEADER_RBPVDXMLPROPPATCH_H 1 + +#include +#include + +class CRBPVDXmlProppatch: public CRBPVDXml +{ + public: + CRBPVDXmlProppatch(); + ~CRBPVDXmlProppatch(); +}; + +#endif /*ONION_HEADER_RBPVDXMLPROPPATCH_H*/ Index: onion/onion/HandlerCType.h =================================================================== --- onion/onion/HandlerCType.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerCType.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,41 @@ +/* + Http header handler for "Content-Type" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerCType.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERCTYPE_H +#define ONION_HEADER_HANDLERCTYPE_H 1 + +#include +#include + +class CHandlerCType : public CResponseHeaderHandler +{ + public: + CHandlerCType(); + ~CHandlerCType(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + const char* GetContentType(); + private: + OI_STRING_A m_strCType; +}; + +#endif /*ONION_HEADER_HANDLERCTYPE_H*/ Index: onion/onion/HandlerCLength.h =================================================================== --- onion/onion/HandlerCLength.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/HandlerCLength.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,43 @@ +/* + Http header handler for "Content-Length" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerCLength.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_HANDLERCLENGTH_H +#define ONION_HEADER_HANDLERCLENGTH_H 1 + +#include +#include + +//forward declarations +class CDavResponseBody; + +class CHandlerCLength : public CResponseHeaderHandler +{ + public: + CHandlerCLength(CDavResponseBody* pBody); + ~CHandlerCLength(); + virtual bool Execute(CDavRequest* pReq, const char *pszValue); + virtual const char* GetHeaderName(); + private: + CDavResponseBody* m_pBody; +}; + +#endif /*ONION_HEADER_HANDLERCLENGTH_H*/ Index: onion/onion/DavLock.h =================================================================== --- onion/onion/DavLock.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavLock.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,51 @@ +/* + Lock infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavLock.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVLOCK_H +#define ONION_HEADER_DAVLOCK_H 1 + +#include +#include + +/** CDavLock holds information for each + * lock. CDavResourceNode constructs a + * list of CDavLock for each DAV resource. + * CDavWorkSession uses this class as + * input of CDavWorkSession::DoLock() + */ +class CDavLock +{ + public: + CDavLock(); + ~CDavLock(); + CDavLock& operator=(const CDavLock& master); + public: + unsigned int m_unMask; + OI_LOCK_TYPE m_enuType; + OI_LOCK_SCOPE m_enuScope; + OI_LOCK_DEPTH m_enuDepth; + long m_lTimeout; //0 means infinite + OI_STRING_A m_strToken; + XNS(DOMNode)* m_pOwner; +}; + +#endif /*ONION_HEADER_DAVLOCK_H*/ Index: onion/onion/DavRequest.h =================================================================== --- onion/onion/DavRequest.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavRequest.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,116 @@ +/* + Http request handler + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavRequest.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVREQUEST_H +#define ONION_HEADER_DAVREQUEST_H 1 + +#include +#include +#include +#include + +//forward declarations +class CDavSocket; +class CResponseHeaderHandler; +class CDavWorkSession; +class CRequestBodyProvider; +class CResponseBodyConsumer; +class CDavResponseBody; + +/** CDavRequest is the core of HTTP processing. + * + */ +class CDavRequest +{ + friend class CHandlerKeepAlive; + friend class CPBCSMDummy; + friend class CPBCSMAuthBasic; + friend class CPBCSMAuthDigest; + friend class CPBCSMLocalFile; + friend class CPBCSMMemBuffer; + friend class CPBCSMXml; + friend class CDavResponseBody; + private: + typedef std::map HEADERFIELDMAP, *PHEADERFIELDMAP; + typedef HEADERFIELDMAP::iterator HEADITERATOR; + typedef std::map HANDLERMAP, + *PHANDLERMAP; + typedef HANDLERMAP::iterator HANDLERITERATOR; + public: + CDavRequest(CDavWorkSession* pSession); //null not allowed + virtual ~CDavRequest(void); + void ClearHandlers(); + bool AddHandler(CResponseHeaderHandler* pHandler, const char *pszName = 0); + bool RemoveHandler(const char* pszName); + void AddHeader(const char* pszName, const char* pszValue); + bool RemoveHeader(const char* pszName); + void SetPersistent(bool bValue); + OI_REQ_TYPE GetMethod(); + const char* GetMethodStr(); + void Create(OI_REQ_TYPE enuType, const char *pszMethod, const char *pszURI); + OI_RESULT Dispatch(CRequestBodyProvider* pRBProvider, + CResponseBodyConsumer* pPBConsumer); + const char* GetURI(); + int GetStatusClass(); + int GetStatusCode(); + protected: + virtual void OnCreate(); + virtual void OnDestroy(); + virtual void OnPreSend(); + virtual void OnPreRecv(); + virtual void OnPostSend(); + virtual void OnPostRecv(); + private: + void addFixedHeaders(); + void stripEOL(char* pszBuf, size_t* punLen); + OI_RESULT connect(); + OI_RESULT begin(CDavResponseBody* pBody); + OI_RESULT end(CDavResponseBody* pBody); + void disconnect(); + void softDisconnect(); + OI_RESULT build(); + OI_RESULT discard_headers(); + OI_RESULT discard_body(CDavResponseBody* pBody); + OI_RESULT read_msg_header(char* pszBuf, size_t unLen); + OI_RESULT read_resp_headers(); + OI_RESULT read_status_line(bool bRetry); + OI_RESULT send(); + OI_RESULT send_body(CRequestBodyProvider* pRBProvider); + public: + OI_STRING_A m_strServerString; + protected: + char m_szBuffer[OI_GENBUFSIZE]; //request local buffer + OI_STRING_A m_strMethod; + OI_STRING_A m_strURI; + OI_REQ_TYPE m_enuType; + OI_STRING_A m_strHeaderBuf; //request header string buffer + HEADERFIELDMAP m_mapHeaderFields; //request header fields + HANDLERMAP m_mapHeaderHandlers; //handlers for response headers + CDavHttpStatus m_HttpStatus; + bool m_bExpect100; //local cache of session variable + CRequestBodyProvider* m_pRBProvider; + CResponseBodyConsumer* m_pPBConsumer; + CDavWorkSession* m_pSession; + clock_t m_clkLastClock; //for debug output +}; + +#endif /*ONION_HEADER_DAVREQUEST_H*/ Index: onion/onion/IDavSocketIO.h =================================================================== --- onion/onion/IDavSocketIO.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/IDavSocketIO.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,45 @@ +/* + Interface of socket I/O methods + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: IDavSocketIO.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_IDAVSOCKETIO_H +#define ONION_HEADER_IDAVSOCKETIO_H 1 + +#include + +//forward declarations +class CDavSocket; + +class IDavSocketIO +{ + public: + virtual OI_RESULT Readable(CDavSocket* pSocket, + int nSecs) = 0; + virtual OI_RESULT Read(CDavSocket* pSocket, + char* pszBuf, + size_t* punReadLen, + int nSecs) = 0; + virtual OI_RESULT Write(CDavSocket* pSocket, + const char* pszBuf, + size_t* punWrittenLen) = 0; +}; + +#endif /*ONION_HEADER_IDAVSOCKETIO_H*/ Index: onion/onion/DavXmlBuffer.h =================================================================== --- onion/onion/DavXmlBuffer.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavXmlBuffer.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,50 @@ +/* + Container of XML nodes + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlBuffer.h,v 1.1.1.1 2004/07/15 06:58:43 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVXMLBUFFER_H +#define ONION_HEADER_DAVXMLBUFFER_H 1 + +#include +#include +#include + +class CDavXmlBuffer +{ + public: + CDavXmlBuffer(const char* pszDocName = OI_XMLCACHE_DOCNAME); + ~CDavXmlBuffer(); + void Clear(); + void AppendChild(XNS(DOMElement)* pElement); + XNS(DOMDocument)* GetDocument(); + bool ImportDocument(XNS(DOMDocument)* pDoc); + XNS(DOMNode)* ImportNode(XNS(DOMNode)* pNode); + bool SaveAs(const char* pszPath); + bool Load(const char* pszPath); + CDavXmlBuffer& operator=(CDavXmlBuffer& master); + private: + OI_STRING_A m_strDocName; + XNS(DOMDocument)* m_pDoc; + private: + void initDocument(); +}; + +#endif /*ONION_HEADER_DAVXMLBUFFER_H*/ Index: onion/onion/PBCSMAuthDigest.h =================================================================== --- onion/onion/PBCSMAuthDigest.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/PBCSMAuthDigest.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,42 @@ +/* + Response body consumer in case of digest authentication + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMAuthDigest.h,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_PBCSMAUTHDIGEST_H +#define ONION_HEADER_PBCSMAUTHDIGEST_H 1 + +#include +#include + +class CPBCSMAuthDigest : public CResponseBodyConsumer +{ + public: + CPBCSMAuthDigest(CDavRequest* pReq); + virtual ~CPBCSMAuthDigest(); + + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_PBC_TYPE GetType(); + virtual OI_RESULT PullResponseBody(CDavResponseBody* pBody); +}; + +#endif /*ONION_HEADER_PBCSMAUTHDIGEST_H*/ Index: onion/onion/DavAuthManager.h =================================================================== --- onion/onion/DavAuthManager.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavAuthManager.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,68 @@ +/* + Authentication manager + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavAuthManager.h,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVAUTHMANAGER_H +#define ONION_HEADER_DAVAUTHMANAGER_H 1 + +#include + +//forward declarations +class CDavAuthSession; +class CDavWorkSession; +class CDavRequest; + +/** CDavAuthManager relays username and password between + * CDavAuthSession and CDavWorkSession. + */ +class CDavAuthManager +{ + public: + CDavAuthManager(CDavWorkSession* pWorkSession); + ~CDavAuthManager(void); + + virtual bool OnAuthentication(const char* pszRealm, + OI_STRING_A& strUsername, + OI_STRING_A& strPasswd, + int nRetry, + OI_AUTH_CLASS enuAuthClass); + + void Reset(); + void ResetServer(); + void ResetProxy(); + + const char* GetUsername(); + const char* GetPasswd(); + const char* GetProxyUsername(); + const char* GetProxyPasswd(); + + virtual OI_RESULT OnCreateRequest(CDavRequest* pReq); + virtual OI_RESULT OnPreSendRequest(CDavRequest* pReq); + virtual OI_RESULT QueryEndRequest(CDavRequest* pReq); + + + private: + CDavAuthSession* m_pServerAuthSession; + CDavAuthSession* m_pProxyAuthSession; + CDavWorkSession* m_pWorkSession; +}; + +#endif /*ONION_HEADER_DAVAUTHMANAGER_H*/ Index: onion/onion/DavResourceNode.h =================================================================== --- onion/onion/DavResourceNode.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/DavResourceNode.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,105 @@ +/* + Dav resource infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavResourceNode.h,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + +#ifndef ONION_HEADER_DAVRESOURCENODE_H +#define ONION_HEADER_DAVRESOURCENODE_H 1 + +#include +#include +#include +#include +#include +#include +/** This is the interface to get DAV resource infomation from. + * Each time a "response" element is received, + * CDavWorkSession::OnResponseFound() will be called and the + * resource node will be passed. + */ +class CDavResourceNode +{ + private: + typedef std::vector LOCKLIST, *PLOCKLIST; + typedef LOCKLIST::iterator LOCKITERATOR; + typedef std::map PROPSTATMAP, *PPROPSTATMAP; + typedef PROPSTATMAP::iterator PROPSTATITERATOR; + public: + CDavResourceNode(); + ~CDavResourceNode(); + OI_RESULT Parse(XNS(DOMNode)* pResponse, + unsigned long ulPropsToParse = OI_RNP_CONVENTIONAL); + void Reset(); + const char* GetURI(); + OI_RES_TYPE GetResourceType(); + const char* GetDisplayName(); + int GetContentLength(); + time_t GetLastModified(); + time_t GetCreationDate(); + const char* GetETag(); + const char* GetContentType(); + const char* GetContentLanguage(); + long GetQuota(); + long GetQuotaUsed(); + unsigned long GetFlags(); + XNS(DOMNode)* GetProp(int nStatusCode); + int GetLockCount(); + CDavLock* GetLock(unsigned int unIndex); + static bool parseLockStatic(XNS(DOMNode)* pNode, CDavLock* pLock); + private: + int getStatusCode(XNS(DOMNode)* pStatus); + void parseProp(XNS(DOMNode)* pProp); + void parseResourceType(XNS(DOMNode)* pProp); + void parseContentLength(XNS(DOMNode)* pProp); + void parseDisplayName(XNS(DOMNode)* pProp); + void parseLastModified(XNS(DOMNode)* pProp); + void parseCreationDate(XNS(DOMNode)* pProp); + void parseETag(XNS(DOMNode)* pProp); + void parseContentType(XNS(DOMNode)* pProp); + void parseContentLanguage(XNS(DOMNode)* pProp); + void parseSupportedLock(XNS(DOMNode)* pProp); + void parseActiveLock(XNS(DOMNode)* pProp); + void parseQuota(XNS(DOMNode)* pProp); + void parseQuotaUsed(XNS(DOMNode)* pProp); + void removeUnprocessed(XNS(DOMNode)* pProp, int nStatus); + private: + unsigned long m_ulPropsToParse; + unsigned long m_ulValidProps; + + OI_RES_TYPE m_enuResourceType; + int m_nContentLength; + + OI_STRING_A m_strContentLanguage; + OI_STRING_A m_strContentType; + OI_STRING_A m_strDisplayName; + OI_STRING_A m_strETag; + OI_STRING_A m_strURI; + + time_t m_tmCreationDate; + time_t m_tmLastModified; + + long m_lQuota; + long m_lQuotaUsed; + + PROPSTATMAP m_mapPropStats; + LOCKLIST m_vecLocklist; +}; + +#endif /*ONION_HEADER_DAVRESOURCENODE_H*/ Index: onion/onion/RBPVDLocalFile.h =================================================================== --- onion/onion/RBPVDLocalFile.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/RBPVDLocalFile.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Request body provider that provides body from a local file + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDLocalFile.h,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RBPVDLOCALFILE_H +#define ONION_HEADER_RBPVDLOCALFILE_H 1 + +#include +#include + +class CRBPVDLocalFile : public CRequestBodyProvider +{ + public: + CRBPVDLocalFile(int nHandle); + virtual ~CRBPVDLocalFile(); + + virtual OI_RBP_TYPE GetType(); + virtual void Close(); + virtual OI_RESULT Open(); + virtual OI_RESULT Rewind(); + virtual size_t GetBodyLength(); + virtual void OnCancel(CDavRequest* pReq); + virtual OI_RESULT Read(CDavRequest* pReq, + char* pszBuf, + size_t* punReadLen); + private: + int m_nHandle; +}; + +#endif /*ONION_HEADER_RBPVDLOCALFILE_H*/ Index: onion/onion/ResponseBodyConsumer.h =================================================================== --- onion/onion/ResponseBodyConsumer.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion/ResponseBodyConsumer.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Prototype of http response body consumer + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: ResponseBodyConsumer.h,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + + +#ifndef ONION_HEADER_RESPONSEBODYCONSUMER_H +#define ONION_HEADER_RESPONSEBODYCONSUMER_H 1 + +#include + +//forward declarations +class CDavRequest; +class CDavResponseBody; + +class CResponseBodyConsumer +{ + friend class CDavRequest; + public: + CResponseBodyConsumer(CDavRequest* pReq); + ~CResponseBodyConsumer(void); + virtual OI_RESULT CheckCType(const char *pszCType); + virtual OI_RESULT PullResponseBody(CDavResponseBody* pBody)=0; + virtual void Close() = 0; + virtual OI_RESULT Open() = 0; + virtual OI_PBC_TYPE GetType() = 0; + virtual void OnCancel(CDavRequest* pReq); + protected: + CDavRequest* m_pRequest; +}; + +#endif /*ONION_HEADER_RESPONSEBODYCONSUMER_H*/ Index: onion/src/RBPVDXml.cpp =================================================================== --- onion/src/RBPVDXml.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDXml.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,205 @@ +/* + Request body provider that provides XML contents + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXml.cpp,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + + +CRBPVDXml::CRBPVDXml(const char* pszDocName): + m_xbfBody(pszDocName) +{ + OI_ASSERT(pszDocName); + m_pszBuf = NULL; + m_unBufLen = 0; + m_unCurPos = 0; + + XNS(DOMImplementation) *pImpl = + XNS(DOMImplementationRegistry)::getDOMImplementation(X("LS")); + + //creating document + //set default namespace mapping + //seems unnecessary in Xercesc 2.3.0 + /* + DOMAttr* pAttr = m_pDoc->createAttributeNS(X(OI_XML_NSURI), X("xmlns:D")); + pAttr->setValue(X("DAV:")); + DOMElement* pRoot = m_pDoc->getDocumentElement(); + pRoot->setAttributeNode(pAttr); + */ + + //creating the writer + m_pDomWriter = ((XNS(DOMImplementationLS)*)pImpl)->createDOMWriter(); + m_pFormatTarget = new XNS(MemBufFormatTarget); + +} + +CRBPVDXml::~CRBPVDXml() +{ + m_pDomWriter->release(); + //if(m_pFormatTarget) + delete m_pFormatTarget; +} + +OI_RBP_TYPE +CRBPVDXml::GetType() +{ + return T_RBP_XML; +} + +void +CRBPVDXml::OnCancel(CDavRequest* pReq) +{ +} + +void +CRBPVDXml::Close() +{ + m_pFormatTarget->reset(); +} + +size_t +CRBPVDXml::GetBodyLength() +{ + return m_unBufLen; +} + +OI_RESULT +CRBPVDXml::Rewind() +{ + m_unCurPos = 0; + return OI_OK; +} + +void +CRBPVDXml::GenerateXml() +{ + if(!(m_pDomWriter && m_pFormatTarget)) + return; + + XNS(DOMDocument)* pDoc = m_xbfBody.GetDocument(); + OI_ASSERT(pDoc); + XNS(DOMNode)* pRoot = (XNS(DOMNode)*)pDoc; + m_pDomWriter->writeNode(m_pFormatTarget, *pRoot); + m_pszBuf = (char*)(m_pFormatTarget->getRawBuffer()); + + m_unBufLen = m_pFormatTarget->getLen(); + m_unCurPos = 0; +} + +OI_RESULT +CRBPVDXml::Open() +{ + GenerateXml(); + return OI_OK; +} + +OI_RESULT +CRBPVDXml::Read(CDavRequest* pReq, char* pszBuf, size_t* punReadLen) +{ + if(m_unBufLen == 0 || (m_unCurPos >= m_unBufLen)){ + *punReadLen = 0; + return OI_OK; + } + + size_t unReadLen = m_unBufLen - m_unCurPos; + + if(unReadLen > *punReadLen) + unReadLen = *punReadLen; + memcpy(pszBuf, m_pszBuf + m_unCurPos, unReadLen); + //TODO: memcpy is not always available + m_unCurPos += unReadLen; + *punReadLen = unReadLen; + + return OI_RETRY; +} + + +void +CRBPVDXml::AddRootElement(const char* pszNS, const char* pszName) +{ + OI_ASSERT(pszNS); + OI_ASSERT(pszName); + + XNS(DOMDocument)* pDoc = m_xbfBody.GetDocument(); + OI_ASSERT(pDoc); + + XNS(DOMElement)* pRoot = pDoc->getDocumentElement(); + XNS(DOMElement)* pProp = pDoc->createElementNS(X(pszNS),X(pszName)); + pRoot->appendChild(pProp); +} + + +void +CRBPVDXml::AddNamespaceMapping(const char* pszPrefix, const char* pszURI) +{ + OI_ASSERT(pszPrefix); + OI_ASSERT(pszURI); + + + XNS(DOMDocument)* pDoc = m_xbfBody.GetDocument(); + OI_ASSERT(pDoc); + + XNS(DOMElement)* pRoot = pDoc->getDocumentElement(); + if(!pRoot) + return; + pRoot->setAttribute(X(pszPrefix), X(pszURI)); +} + + +void +CRBPVDXml::SetDocumentName(const char* pszName) +{ + OI_ASSERT(pszName); + + XNS(DOMDocument)* pDoc = m_xbfBody.GetDocument(); + OI_ASSERT(pDoc); + + XNS(DOMElement)* pRoot = pDoc->getDocumentElement(); + pDoc->renameNode(pRoot, X(OI_XML_DAVNAMESPACE), X(pszName)); +} + + +bool +CRBPVDXml::Load(const char* pszPath) +{ + if(!pszPath) + return false; + + bool bRet = m_xbfBody.Load(pszPath); + return bRet; +} + + +bool +CRBPVDXml::Load(CDavXmlBuffer* pXmlBuffer) +{ + if(!pXmlBuffer) + return false; + m_xbfBody = *pXmlBuffer; + return true; +} + Index: onion/src/DavAuthSession.cpp =================================================================== --- onion/src/DavAuthSession.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavAuthSession.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,587 @@ +/* + Authentication session + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavAuthSession.cpp,v 1.1.1.1 2004/07/15 06:58:43 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include +#include + +CDavAuthSession::CDavAuthSession(CDavAuthManager* pMgr, + const char* pszRequestHeader, + const char* pszResponseHeader, + const char* pszResponseInfoHeader, + unsigned int unStatusCode, + OI_AUTH_CLASS enuClass) +{ + OI_ASSERT(pMgr); + OI_ASSERT(pszRequestHeader); + OI_ASSERT(pszResponseHeader); + OI_ASSERT(pszResponseInfoHeader); + + m_pAuthManager = pMgr; + m_pszRequestHeader = pszRequestHeader; + m_pszResponseHeader = pszResponseHeader; + m_pszResponseInfoHeader =pszResponseInfoHeader; + m_nStatusCode = (int)unStatusCode; + m_enuClass = enuClass; + + Reset(); +} + +CDavAuthSession::~CDavAuthSession() +{ +} + +void +CDavAuthSession::updateCNonce() +{ + unsigned char yData[256]; + CDavMD5 md5; + + if(RAND_pseudo_bytes(yData, sizeof(yData)) >= 0) + md5.UpdateHash(yData, sizeof(yData)); + + m_strCNonce = md5.GetHashString(); +} + +const char* +CDavAuthSession::GetPasswd() +{ + return m_strPasswd.c_str(); +} + +const char* +CDavAuthSession::GetUsername() +{ + return m_strUsername.c_str(); +} + +void +CDavAuthSession::SetPasswd(const char* pszPasswd) +{ + if(pszPasswd) + m_strPasswd = pszPasswd; +} + +void +CDavAuthSession::SetUsername(const char* pszUsername) +{ + if(pszUsername) + m_strUsername = pszUsername; +} + +const char* +CDavAuthSession::GetAuthHeaderName() +{ + return m_pszResponseHeader; +} + +const char* +CDavAuthSession::GetAuthInfoHeaderName() +{ + return m_pszResponseInfoHeader; +} + +OI_AUTH_SCHEME +CDavAuthSession::GetAuthScheme() +{ + return m_enuScheme; +} + +OI_AUTH_STATE +CDavAuthSession::GetAuthState() +{ + return m_enuState; +} + +void +CDavAuthSession::SetAuthInfoHeader(const char* pszValue) +{ + if(pszValue){ + m_strAuthInfoHeader = pszValue; + m_bGotAuthInfoHeader = true; + } +} + +void +CDavAuthSession::Reset() +{ + m_enuScheme = H_AUTH_NOAUTH; + m_enuState = S_AUTH_UNAUTHENTICATED; + m_enuQop = Q_AUTH_NONE; + + m_unAttempt = 0; + m_unNonceCount = 0; + m_bGotQop = false; + m_bGotAlgorithm = false; + m_bGotStale = false; + m_bGotOpaque = false; + m_bGotNonce = false; + m_bGotRealm = false; + m_bGotScheme = false; + m_bStale = false; + m_bGotAuthHeader = false; + m_bGotAuthInfoHeader = false; + + m_strUsername.erase(); + m_strPasswd.erase(); + m_strBasic.erase(); + m_strDigest.erase(); + m_strCNonce.erase(); + m_strAuthInfoHeader.erase(); + m_strHA1.erase(); + +} + +OI_RESULT +CDavAuthSession::OnCreateRequest(CDavRequest* pReq) +{ + pReq->AddHandler(new CHandlerAuth(pReq, this), m_pszResponseHeader); + pReq->AddHandler(new CHandlerAuthInfo(pReq, this), m_pszResponseInfoHeader); + return OI_OK; +} + +void +CDavAuthSession::ParseAuthHeader(const char* pszValue) +{ + m_bGotAuthHeader = true; + + CDavStringTokenizer headers(pszValue, ", "); + OI_STRING_A strField; + + for(;headers.GetNextToken(strField);){ + CDavStringTokenizer field(strField.c_str(), "= "); + OI_STRING_A strName, strValue; + if(field.GetNextToken(strName)){ + bool bIsScheme = !(field.GetNextToken(strValue)); + if(bIsScheme){ + m_bGotScheme = true; + if(!stricmp(strName.c_str(), "digest")){ + m_enuScheme = H_AUTH_DIGEST; + } else if(!stricmp(strName.c_str(), "basic")){ + m_enuScheme = H_AUTH_BASIC; + } else { + m_enuScheme = H_AUTH_INVALID; + } + } else { + //remove quotation marks from value + OI_STRING_A::size_type npos = (OI_STRING_A::size_type)-1; + OI_STRING_A::size_type pos; + + for(; (pos = strValue.find_first_of('\"')) != npos;) + strValue.erase(pos, 1); + + for(; (pos = strValue.find_first_of('\'')) != npos;) + strValue.erase(pos, 1); + + if(!stricmp(strName.c_str(), "realm")){ + m_bGotRealm = true; + m_strRealm = strValue; + } else if(!stricmp(strName.c_str(), "nonce")){ + m_bGotNonce = true; + m_strNonce = strValue; + } else if(!stricmp(strName.c_str(), "opaque")){ + m_bGotOpaque = true; + m_strOpaque = strValue; + } else if(!stricmp(strName.c_str(), "stale")){ + m_bGotStale = true; + m_bStale = (!stricmp(strValue.c_str(), "true")); + } else if(!stricmp(strName.c_str(), "algorithm")){ + m_bGotAlgorithm = true; + if(stricmp(strValue.c_str(), "MD5")){ + //TODO: handle this case + //OI_ASSERT(false); + } else { + //TODO: unsupported algorithm + OI_ASSERT(false); + } + } else if(!stricmp(strName.c_str(), "qop")){ + m_bGotQop = true; + if(!stricmp(strValue.c_str(), "auth")){ + m_enuQop = Q_AUTH_AUTH; + } else if(!stricmp(strValue.c_str(), "auth-int")){ + m_enuQop = Q_AUTH_AUTHINT; + } else { + m_enuQop = Q_AUTH_NONE; + } + } else { + //TODO: handle this case + OI_DEBUG("*** unknown auth header field: [%s] ***\n", + strName.c_str()); + //OI_ASSERT(false); + } + } + } + } +} + +OI_RESULT +CDavAuthSession::OnPreSendRequest(CDavRequest* pReq) +{ + switch(m_enuScheme){ + case H_AUTH_BASIC: + pReq->AddHeader(m_pszRequestHeader, m_strBasic.c_str()); + break; + case H_AUTH_DIGEST: + requestDigest(pReq); + pReq->AddHeader(m_pszRequestHeader, m_strDigest.c_str()); + break; + case H_AUTH_NOAUTH: + default: + //H_AUTH_INVALID is handled in QueryEndRequest + break; + } + return OI_OK; +} + +OI_RESULT +CDavAuthSession::verifyResponse(CDavRequest* pReq, + const char* pszValue, + const char* pszURI) +{ + OI_RESULT enuRet = OIAEDIGMISMATCH; + + bool bGotNextNonce = false; + bool bGotRspAuth = false; + bool bGotCNonce = false; + bool bGotQop = false; + bool bGotNonceCount = false; + + OI_STRING_A strNextNonce; + OI_STRING_A strRspAuth; + OI_STRING_A strCNonce; + OI_STRING_A strQop; + + unsigned int unNonceCount; + OI_AUTH_QOP enuQop = Q_AUTH_NONE; + + if(m_enuScheme != H_AUTH_DIGEST) + return OIAEHEADERSYNTAX; + + CDavStringTokenizer fields(pszValue, ", "); + OI_STRING_A strValPair; + for(;fields.GetNextToken(strValPair);){ + CDavStringTokenizer field(strValPair.c_str(), "= "); + OI_STRING_A strName, strValue; + if(field.GetNextToken(strName)){ + bool bIsValid = field.GetNextToken(strValue); + if(!bIsValid){ + //every field in RFC2069 has its own value, + //however, 2069 did not mention the 'rspauth' field, + //which appeared in 2831. Further investigation is needed + return OIAEHEADERSYNTAX; + } + + //removing quotations + OI_STRING_A::size_type npos = (OI_STRING_A::size_type)-1; + OI_STRING_A::size_type pos; + + for(; (pos = strValue.find_first_of('\"')) != npos;) + strValue.erase(pos, 1); + + for(; (pos = strValue.find_first_of('\'')) != npos;) + strValue.erase(pos, 1); + + if(stricmp(strName.c_str(), "qop") == 0){ + bGotQop = true; + strQop = strValue; + if(stricmp(strQop.c_str(), "auth-int") == 0){ + enuQop = Q_AUTH_AUTHINT; + } else if(stricmp(strQop.c_str(), "auth") == 0){ + enuQop = Q_AUTH_AUTH; + } else { + enuQop = Q_AUTH_NONE; + } + } else if(stricmp(strName.c_str(), "nextnonce") == 0){ + bGotNextNonce = true; + strNextNonce = strValue; + } + else if(stricmp(strName.c_str(), "rspauth") == 0){ + bGotRspAuth = true; + strRspAuth = strValue; + } else if(stricmp(strName.c_str(), "cnonce") == 0){ + bGotCNonce = true; + strCNonce = strValue; + } else if(stricmp(strName.c_str(), "nc") == 0){ + bGotNonceCount = true; + if(!sscanf(strValue.c_str(), "%x", &unNonceCount)) + return OIAEHEADERSYNTAX; + } + } + } + + if(bGotQop && (enuQop != Q_AUTH_NONE)){ + if(!(bGotRspAuth && bGotCNonce && bGotNonceCount)) + return OIAEHEADERSYNTAX; + if(strCNonce != m_strCNonce){ + OI_DEBUG("cnonce mismatch!\n"); + return OIAECNONCEMISMATCH; + } else if(unNonceCount != m_unNonceCount){ + OI_DEBUG("nonce mismatch!\n"); + return OIAENONCEMISMATCH; + } else { + CDavMD5 md5; + OI_STRING_A strTmp = ":"; + + strTmp += AnsiToUtf8(pszURI); + if(enuQop == Q_AUTH_AUTHINT){ + //TODO: Implement this + OI_ASSERT(false); + } + + if(enuQop != Q_AUTH_NONE){ + m_strStoredDigest += strQop; + m_strStoredDigest += ":"; + } + + OI_STRING_A strDigest = HashString(strTmp); + m_strStoredDigest += strDigest; + + //H_A2 + strDigest = HashString(m_strStoredDigest); + + if(strDigest == strRspAuth){ + enuRet = OI_OK; + } else { + enuRet = OIAEDIGMISMATCH; + } + } + } else { + //No qop directive, auth okay + enuRet = OI_OK; + } + + if(bGotNextNonce){ + OI_DEBUG("got next nonce\n"); + m_strNonce = strNextNonce; + } + + return enuRet; +} + +OI_RESULT +CDavAuthSession::QueryEndRequest(CDavRequest* pReq) +{ + OI_RESULT enuRet; + int nStatusCode = pReq->GetStatusCode(); + if(m_enuScheme == H_AUTH_INVALID) { + return OIAEINVALIDSCHEME; + }else if(m_bGotAuthInfoHeader) { + OI_STRING_A strUTF8URI = Escape(AnsiToUtf8(pReq->GetURI())); + enuRet = verifyResponse(pReq, m_strAuthInfoHeader.c_str(), + strUTF8URI.c_str()); + //reset the flag + m_bGotAuthInfoHeader = false; + return enuRet; + } else if(nStatusCode == m_nStatusCode){ + //server-auth + if(!m_bGotAuthHeader) return OIAEHEADERSYNTAX; + enuRet = challenge(); + //reset the flag + m_bGotAuthHeader = false; + if(OI_OK != enuRet){ + return enuRet; + } else { + m_enuState = S_AUTH_UNAUTHENTICATED; + return OI_RETRY; + } + } else { + //TODO: handle other situations + } + return OI_OK; +} + +OI_RESULT +CDavAuthSession::challenge() +{ + if(m_bGotScheme){ + switch(m_enuScheme){ + case H_AUTH_BASIC: + return basicChallenge(); + case H_AUTH_DIGEST: + return digestChallenge(); + } + } else { + return OIAEHEADERSYNTAX; + } + return OI_OK; +} + +bool +CDavAuthSession::requestCredential() +{ + OI_STRING_A strRealm = Utf8ToAnsi(Unescape(m_strRealm)); + bool bRet = m_pAuthManager->OnAuthentication(strRealm.c_str(), + m_strUsername, + m_strPasswd, + m_unAttempt, + m_enuClass); + + if(bRet) + m_unAttempt++; + return bRet; +} + +OI_RESULT +CDavAuthSession::basicChallenge() +{ + if(!m_bGotScheme) + return OIAEHEADERSYNTAX; + + if(!requestCredential()) + return OIAEFAILEDTOGETCRED; + + OI_STRING_A strClearText = m_strUsername; + strClearText += ":"; + strClearText += m_strPasswd; + + m_strBasic = "Basic "; + m_strBasic += Base64Encode(strClearText); + return OI_OK; +} + +OI_RESULT +CDavAuthSession::digestChallenge() +{ + OI_STRING_A strHash; + + if(!requestCredential()) + return OIAEFAILEDTOGETCRED; + + if(m_bGotStale) + OI_DEBUG("got stale challenge\n"); + + if(m_bGotQop) + m_unNonceCount = 0; + + if(!m_bStale){ + strHash = m_strUsername; + strHash += ":"; + strHash += m_strRealm; + strHash += ":"; + strHash += m_strPasswd; + m_strHA1 = HashString(strHash); + } + + return OI_OK; +} + +bool +CDavAuthSession::requestDigest(CDavRequest* pReq) +{ + OI_STRING_A strTmp, strQop, strNonceCount; + OI_STRING_A strHA2, strRDigest; + char chBuf[80]; + + if(m_enuQop != Q_AUTH_NONE) { + if(T_REQ_HEAD == pReq->GetMethod()) { + m_unNonceCount = 0; + } else { + m_unNonceCount++; + } + sprintf(chBuf, "%08x", m_unNonceCount); + strNonceCount = chBuf; + } + + updateCNonce(); + switch(m_enuQop) { + case Q_AUTH_AUTH: + strQop = "auth"; + break; + case Q_AUTH_AUTHINT: + //TODO: implement + strQop = "auth-int"; + OI_ASSERT(false); + break; + default: + //TODO: error code + OI_ASSERT(false); + break; + } + strTmp = pReq->GetMethodStr(); + strTmp += ":"; + strTmp += (const char*)(X(pReq->GetURI()).toEscapedUTF8()); + + strHA2 = HashString(strTmp); + strTmp = m_strHA1; + strTmp += ":"; + strTmp += m_strNonce; + strTmp += ":"; + + if(m_enuQop != Q_AUTH_NONE) { + strTmp += strNonceCount; + strTmp += ":"; + strTmp += m_strCNonce; + strTmp += ":"; + + //store a copy of digest + m_strStoredDigest = strTmp; + + strTmp += strQop; + strTmp += ":"; + } else { + //store a copy of digest + m_strStoredDigest = strTmp; + } + + strTmp += strHA2; + strRDigest = HashString(strTmp); + + m_strDigest = "Digest username=\""; + m_strDigest += m_strUsername; + m_strDigest += "\", realm=\""; + m_strDigest += m_strRealm; + m_strDigest += "\", nonce=\""; + m_strDigest += m_strNonce; + m_strDigest += "\", uri=\""; + m_strDigest += (const char*)(X(pReq->GetURI()).toEscapedUTF8()); + m_strDigest += "\", response=\""; + m_strDigest += strRDigest; + m_strDigest += "\", algorithm=\""; + m_strDigest += "MD5"; + m_strDigest += "\""; + + if(m_bGotOpaque) { + m_strDigest += ", opaque=\""; + m_strDigest += m_strOpaque; + m_strDigest += "\""; + } + + if(m_enuQop != Q_AUTH_NONE) { + m_strDigest += ", cnonce=\""; + m_strDigest += m_strCNonce; + m_strDigest += "\", nc=\""; + m_strDigest += strNonceCount; + m_strDigest += "\", qop=\""; + m_strDigest += strQop; + m_strDigest += "\""; + } + + return true; +} Index: onion/src/Utils.cpp =================================================================== --- onion/src/Utils.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/Utils.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,1343 @@ +/* + Utilty functions + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: Utils.cpp,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include /* for PKCS12_PBE_add */ +#include +#include +#include + +#ifdef WORDS_BIGENDIAN +# define OI_SWAP(n) (((n) << 24) | \ + (((n) & 0xff00) << 8) | \ + (((n) >> 8) & 0xff00) | \ + ((n) >> 24)) +#else +# define OI_SWAP(n) (n) +#endif + + +#define OI_ASC2HEX(x) (((x) <= '9') ? ((x) - '0') : (tolower((x)) + 10 - 'a')) +#define OI_HEX2ASC(x) ((x) > 9 ? ((x) - 10 + 'a') : ((x) + '0')) + + +/* + +//////////////////////////////////// +//Hash algorithm of CMapStringToPtr +//////////////////////////////////// + +inline UINT CMapStringToPtr::HashKey(LPCTSTR key) const +{ +UINT nHash = 0; +while (*key) +nHash = (nHash<<5) + nHash + *key++; +return nHash; +} + +*/ + +//Global variables +SSL_CTX* g_pSSLCtx = NULL; +XNS(XMLUTF8Transcoder)* g_pUTF8Transcoder = NULL; +ONIONDEBUGLOCKCALLBACK g_pfnDebugLockCallback = NULL; +FILE* g_pDebugStream = NULL; +unsigned int g_unDebugOptions = 0; +//Global functions +int +OnionNumOfLocks() +{ + return CRYPTO_num_locks(); +} + +void +OnionSetDebugLockCallback(ONIONDEBUGLOCKCALLBACK pfnDebugLockCallback) +{ + g_pfnDebugLockCallback = pfnDebugLockCallback; +} + +OI_RESULT +OnionRedirectDebugOutput(const char* pszPath, const char* pszMode) +{ + if(g_pDebugStream){ + fclose(g_pDebugStream); + g_pDebugStream = NULL; + } + if(pszPath && pszMode){ + g_pDebugStream = freopen(pszPath, pszMode, stderr); + if(!g_pDebugStream) + return OIGECANTOPENFILE; + } + return OI_OK; +} + +void +OnionDebugOutput(const char* pszFormat, ...) +{ + OI_ASSERT(pszFormat); + if(g_unDebugOptions & OI_DEBUG_SILENT) + return; + va_list params; + va_start(params, pszFormat); + vfprintf(stderr, pszFormat, params); + va_end(params); + if(g_unDebugOptions & OI_DEBUG_FLUSH) + fflush(stderr); +} + +void +OnionSetDebugOptions(unsigned int unOptions) +{ + g_unDebugOptions = unOptions; +} + + +OI_RESULT +OnionInitialize(OSSLLOCKCALLBACK sslLockCallback) +{ + XNS(XMLPlatformUtils)::Initialize(); + if(!g_pUTF8Transcoder){ + XNS(XMLTransService)::Codes resValue; + g_pUTF8Transcoder = (XNS(XMLUTF8Transcoder)*)XNS(XMLPlatformUtils):: + fgTransService->makeNewTranscoderFor(XNS(XMLRecognizer)::UTF_8, + resValue, + 16384); + if(!g_pUTF8Transcoder) + return OIXEINITFAILED; + } + + if(sslLockCallback) + CRYPTO_set_locking_callback(sslLockCallback); + SSL_load_error_strings(); + SSL_library_init(); + PKCS12_PBE_add(); // !!! not sure why this is needed. + if(!g_pSSLCtx) + g_pSSLCtx = SSL_CTX_new(SSLv23_client_method()); + + if (RAND_status() == 1) + return OI_OK; // already seeded internally by OpenSSL + + //***** NOTICE: the RAND_status() always returns 1 + //***** so the following code is neve executed + char* pszFile = getenv("EGDSOCKET"); + if (pszFile && RAND_egd(pszFile) != -1) + return OI_OK; + + pszFile = getenv("HOME"); + if (pszFile){ + OI_STRING_A strPath; + strPath = pszFile; + strPath += "/.entropy"; + /* + char szPath[1024]; + sprintf(szPath, "%s/.entropy", pszFile); + if (RAND_egd(szPath) != -1) + return OI_OK; + */ + if (RAND_egd(strPath.c_str()) != -1) + return OI_OK; + } + return OIEENOENTROPY; +} + +void +OnionTerminate() +{ + if(g_pDebugStream){ + fclose(g_pDebugStream); + g_pDebugStream = NULL; + } + if(g_pSSLCtx){ + SSL_CTX_free(g_pSSLCtx); + g_pSSLCtx = NULL; + } + CRYPTO_set_locking_callback(NULL); + /* in case OpenSSL does not cleanup automatically + EVP_cleanup(); + ENGINE_cleanup(); + CRYPTO_cleanup_all_ex_data(); + ERR_remove_state(0); + ERR_free_strings(); + */ + + if(g_pUTF8Transcoder) + delete g_pUTF8Transcoder; + XNS(XMLPlatformUtils)::Terminate(); +} + +const char* +GetErrorDescription(OI_RESULT enuResult) +{ + switch(enuResult){ + case OIGEUNKNOWN: + return "unknown generic error"; + case OIGENOTIMPLEMENTED: + return "feature not implemented"; + case OIGEINVALIDARG: + return "invalid argument"; + case OIGECANTOPENFILE: + return "can not open file"; + case OIGEPASSIVELOCK: + return "the session is locked in passive mode"; + + //status code + case OI_OK: + return "No Error"; + case OI_RETRY: + return "Retry"; + case OI_USERCANCELED: + return "User canceled operation"; + + //encryption(ssl) errors + case OIEEGENERIC: + return "Generic SSL Error"; + case OIEENOENTROPY: + return "No entropy source found. could not seed PRNG"; + case OIEELACKOFENTROPY: + return "SSL disabled due to lack of entropy"; + case OIEEDATAINITFAILED: + return "SSL data initialization failed"; + case OIEESSLINITFAILED: + return "SSL initialization failed"; + case OIEENOSERVERCERT: + return "SSL server certificate did not present"; + case OIEEINVALIDCERT: + return "SSL server certificate invalid"; + case OIEECERTCHANGED: + return "Server certificate changed, connection may be intercepted"; + case OIEECERTCHECKFAILED: + return "Certificate check failed"; + case OIEECNMISMATCH: + return "CN Mismatch"; + case OIEETUNNELFAILED: + return "proxy tunnel failed"; + + //HTTP protocol errors + case OIHELINETOOLONG: + return "HeaderLine Too Long"; + case OIHETOOMANYHEADERS: + return "Too many header fields"; + case OIHEPROTOCOLPANIC: + return "The response in not a Http status"; + case OIHECHUNKSIZE: + return "response chunk size parse error"; + + //XML errors + case OIXEINITFAILED: + return "Xerces init failed"; + + //socket errors + case OISEGEN: + return "generic(unclear) error"; + case OISETIMEOUT: + return "Connection timed out"; + case OISECLOSED: + return "Socket Closed"; + case OISERESET: + return "Connection reset by server"; + case OISELINETOOLONG: + return "http status line Too Long"; + case OISECONNABORTED: + return "Connection aborted by server"; + + case OISEINITFAILED: + return "socket version too low"; + case OISEINITIALIZED: + return "socket already initialized"; + case OISECLEANUPFAILED: + return "socket clean up failed"; + case OISEHOSTNOTFOUND: + return "host not found"; + case OISEINVALIDSOCK: + return "can not get sock from system"; + case OISESOCKVER: + return "socket version not supported by OS"; + case OISECONNFAILED: + return "system connection failed"; + case OISETRUNC: + return "connection truncated"; + + //resource parse errors + case OIRESYNTAX: + return "XML syntax error"; + case OIREHREFNOTFOUND: + return "href element not found while parsing response"; + + //authentication errors + case OIAEHEADERSYNTAX: + return "header is not well-formed"; + case OIAEFAILEDTOGETCRED: + return "failed to get credential(the OnAuthentication handler returned false)"; + case OIAEDIGMISMATCH: + return "Digest mismatch, connection could be intercepted"; + case OIAEINVALIDSCHEME: + return "invalid auth scheme"; + case OIAECNONCEMISMATCH: + return "cnonce mismatch"; + case OIAENONCEMISMATCH: + return "nonce mismatch"; + + + //DAV errors + case OIDENOCONTENT: + return "204 no content"; + case OIDEMULTISTATUS: + return "207 multistatus"; + case OIDEBADREQUEST: + return "400 Bad Request"; + case OIDEFORBIDDEN: + return "403 forbidden"; + case OIDENOTFOUND: + return "404 not found"; + case OIDENOTALLOWED: + return "405 not allowed"; + case OIDECONFLICT: + return "409 conflict"; + case OIDEPCONFAILED: + return "412 Precondition Failed"; + case OIDELOCKED: + return "423 Locked"; + case OIDEFAILEDDEPS: + return "424 Failed Dependency"; + case OIDEINTRSVRERR: + return "500 Internal Server Error"; + case OIDEBADGATEWAY: + return "502 Bad Gateway"; + case OIDESERVICENOTAVAIL: + return "503 Service Not Available"; + case OIDECTYPEMISMATCH: + return "unexpected content type"; + case OIDEREDIRECT: + return "301 Moved"; + case OIDEINSUFFSTG: + return "507 Insufficient Storage"; + case OIDEPAYMENTREQUIRED: + return "402 Payment Required"; + + //system errors + case OIYEREQNOTFOUND: + return "request not found in library's config"; + case OIYESTATUSNOTFOUND: + return "status code not found in library's config"; + case OIYECTYPENOTFOUND: + return "content type mismatch(no such type in library's config)"; + case OIYECONFINITFAILED: + return "server profile config initialization failed "; + case OIYECONFSYNTAX: + return "server profile config syntax error"; + default: + return "error not found"; + } +} + +OI_STRING_A +Unescape(const OI_STRING_A& uri) +{ + OI_STRING_A::const_iterator it = uri.begin(); + OI_STRSTREAM_A ss; + char buf[5] = { "0x00" }; + + while(it != uri.end()){ + if(*it == '%'){ + if(!isxdigit(*(it+1)) || !isxdigit(*(it+2))){ + //invalid escapped string format + return ss.str(); + } + + buf[2] = *(++it); + buf[3] = *(++it); + ss << (char)strtol(buf, NULL, 16); + } else { + ss << *it; + } + it++; + } + return ss.str(); +} + + +/* RFC2396 spake: + * "Data must be escaped if it does not have a representation + * using an unreserved character". + */ + +/* Lookup table: character classes from 2396. (This is overkill) */ + +#define SP 0 /* space = */ +#define CO 0 /* control = */ +#define DE 0 /* delims = "<" | ">" | "#" | "%" | <"> */ +#define UW 0 /* unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`" */ +#define MA 1 /* mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" */ +#define AN 2 /* alphanum = alpha | digit */ +#define RE 2 /* reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," */ + +static const char chUriChars[128] = { + /* +2 +4 +6 +8 +10 +12 +14 */ + /* 0 */ CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, + /* 16 */ CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, CO, + /* 32 */ SP, MA, DE, DE, RE, DE, RE, MA, MA, MA, MA, RE, RE, MA, MA, RE, + /* 48 */ AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, RE, RE, DE, RE, DE, RE, + /* 64 */ RE, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, + /* 80 */ AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, UW, UW, UW, UW, MA, + /* 96 */ UW, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, + /* 112 */ AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, UW, UW, UW, MA, CO +}; + +#define ESCAPE(ch) (((const signed char)(ch) < 0 || \ + chUriChars[(unsigned int)(ch)] == 0)) + +#undef SP +#undef CO +#undef DE +#undef UW +#undef MA +#undef AN +#undef RE + +OI_STRING_A +Escape(const OI_STRING_A& uri) +{ + OI_STRING_A::const_iterator it = uri.begin(); + OI_STRSTREAM_A ss; + char buf[4] = {"???"}; + + while(it != uri.end()){ + if(ESCAPE(*it)){ + sprintf(buf,"%%%02x", (unsigned char)*it); + ss<= 3; inlen -= 3, it += 3){ + ss << chB64Alphabet[(*it) >> 2]; + ss << chB64Alphabet[((*it) << 4 & 0x30) | (*(it+1))>>4]; + ss << chB64Alphabet[((*(it + 1)) << 2 & 0x3c) | (*(it + 2)) >> 6]; + ss << chB64Alphabet[(*(it + 2)) & 0x3f]; + } + + //processing the trailing bytes if any + if(inlen > 0){ + ss << chB64Alphabet[(*it) >> 2]; + ss << chB64Alphabet[(((*it) << 4 & 0x30) | (inlen == 2 ? (*(it + 1)) >> 4 : 0))]; + ss << (inlen==1 ? '=' : chB64Alphabet[ (*(it + 1)) << 2 & 0x3c]); + ss << '='; + } + return ss.str(); +} + +#define VALID_B64(ch) (((ch) >= 'A' && (ch) <= 'Z') || \ + ((ch) >= 'a' && (ch) <= 'z') || \ + ((ch) >= '0' && (ch) <= '9') || \ + (ch) == '/' || (ch) == '+' || (ch) == '=') + +#define DECODE_B64(ch) ((ch) >= 'a' ? ((ch) + 26 - 'a') : \ + ((ch) >= 'A' ? ((ch) - 'A') : \ + ((ch) >= '0' ? ((ch) + 52 - '0') : \ + ((ch) == '+' ? 62 : 63)))) + +OI_STRING_A +Base64Decode(const OI_STRING_A& input) +{ + OI_STRSTREAM_A ss; + const char* empty = ""; + + int inlen = (int)input.length(); + if((inlen > 0) && (inlen % 4 == 0)){ + for(OI_STRING_A::const_iterator it = input.begin(); + it != input.end(); + it += 4){ + unsigned int tmp; + if(!VALID_B64(it[0]) || !VALID_B64(it[1]) || !VALID_B64(it[2]) || + !VALID_B64(it[3]) || it[0] == '=' || it[1] == '=' || + (it[2] == '=' && it[3] != '=')){ + return empty; + } + + tmp = (DECODE_B64(it[0]) & 0x3f) << 18 | + (DECODE_B64(it[1]) & 0x3f) << 12; + unsigned char ch = (tmp >> 16) & 0xff; + ss << ch; + + if (it[2] != '='){ + tmp |= (DECODE_B64(it[2]) & 0x3f) << 6; + ch = (tmp >> 8) & 0xff; + ss << ch; + if (it[3] != '='){ + tmp |= DECODE_B64(it[3]) & 0x3f; + ch = tmp & 0xff; + ss << ch; + } + } + } + } + return ss.str(); +} + +#undef DECODE_B64 + +#undef VALID_B64 + +OI_STRING_A +Utf8ToAnsi(const OI_STRING_A& sUtf8) +{ + return (const char*)X((XMLByte*)sUtf8.c_str()); +} + +OI_STRING_A +AnsiToUtf8(const OI_STRING_A& sAnsi) +{ + OI_STRING_A strRet; + char* pszUTF8 = (char*)(const char*)X(sAnsi.c_str()).UTF8(); + if(pszUTF8){ + strRet = pszUTF8; + delete[] pszUTF8; + } + return strRet; +} + +void +MakeLowerA(OI_STRING_A& strAnsi) +{ + for(OI_STRING_A::iterator itCh = strAnsi.begin(); + itCh != strAnsi.end(); itCh++){ + *itCh = tolower(*itCh); + } +} + +void +TrimLeftA(OI_STRING_A& strAnsi) +{ + int nPos; + nPos = (int)strAnsi.find_first_not_of(' '); + if(nPos > 0) + strAnsi.erase(0, nPos); //trim left +} + +void +TrimRightA(OI_STRING_A& strAnsi) +{ + int nPos; + nPos = (int)strAnsi.find_last_not_of(' '); + if(nPos > 0) + strAnsi.erase(nPos + 1); //trim right +} + +/* This array contains the bytes used to pad the buffer to the next + 64-byte boundary. (RFC 1321, 3.1: Step 1) */ +static const unsigned char chPadding[64] = { 0x80, 0 /* , 0, 0, ... */ }; + +CDavMD5::CDavMD5() +{ + Init(); +} + +CDavMD5::~CDavMD5() +{ +} + +void +CDavMD5::Init() +{ + m_unA = 0x67452301; + m_unB = 0xefcdab89; + m_unC = 0x98badcfe; + m_unD = 0x10325476; + + m_unTotal[0] = m_unTotal[1] = 0; + m_unBufLen = 0; +} + +void +CDavMD5::getHash(unsigned char yBuf[16]) +{ + if(!yBuf) + return; + + ((MD5_UINT32*) yBuf)[0] = OI_SWAP(m_unA); + ((MD5_UINT32*) yBuf)[1] = OI_SWAP(m_unB); + ((MD5_UINT32*) yBuf)[2] = OI_SWAP(m_unC); + ((MD5_UINT32*) yBuf)[3] = OI_SWAP(m_unD); +} + +OI_STRING_A +CDavMD5::GetHashString() +{ + char szBuf[33]; + unsigned char yHash[16]; + + Finalize(yHash); + + for(int nIndex = 0; nIndex < 16; nIndex++){ + szBuf[nIndex*2] = OI_HEX2ASC(yHash[nIndex] >> 4); + szBuf[nIndex*2+1] = OI_HEX2ASC(yHash[nIndex] & 0x0f); + } + + szBuf[32] = '\0'; + return szBuf; +} + +/* These are the four functions used in the four steps of the MD5 algorithm + and defined in the RFC 1321. The first function is a little bit optimized + (as found in Colin Plumbs public domain implementation). */ +#define FF(b, c, d) (d ^ (b & (c ^ d))) +#define FG(b, c, d) FF (d, b, c) +#define FH(b, c, d) (b ^ c ^ d) +#define FI(b, c, d) (c ^ (b | ~d)) + +void +CDavMD5::updateBlock(const void *pvData, unsigned int unLen) +{ + MD5_UINT32 unCorrectWords[16]; + const unsigned char* pvWords = (const unsigned char*)pvData; + const unsigned char* pvEnd = (const unsigned char*)pvData + unLen; + + MD5_UINT32 A = m_unA; + MD5_UINT32 B = m_unB; + MD5_UINT32 C = m_unC; + MD5_UINT32 D = m_unD; + + /* First increment the byte count. RFC 1321 specifies the possible + length of the file up to 2^64 bits. Here we only compute the + number of bytes. Do a double word increment. */ + m_unTotal[0] += unLen; + if(m_unTotal[0] < unLen) + ++m_unTotal[1]; + + /* Process all bytes in the buffer with 64 bytes in each round of + the loop. */ + while(pvWords < pvEnd){ + MD5_UINT32 *punWord = unCorrectWords; + MD5_UINT32 A_save = A; + MD5_UINT32 B_save = B; + MD5_UINT32 C_save = C; + MD5_UINT32 D_save = D; + /* First round: using the given function, the context and a constant + the next context is computed. Because the algorithms processing + unit is a 32-bit word and it is determined to work on words in + little endian byte order we perhaps have to change the byte order + before the computation. To reduce the work for the next steps + we store the swapped words in the array CORRECT_WORDS. */ +#define OP(a, b, c, d, s, T) { \ + MD5_UINT32 WORD_ = \ + (MD5_UINT32)pvWords[0] | \ + ((MD5_UINT32)pvWords[1] << 8) | \ + ((MD5_UINT32)pvWords[2] << 16) | \ + ((MD5_UINT32)pvWords[3] << 24); \ + a += FF (b, c, d) + \ + (*punWord++ = WORD_) + T; \ + pvWords += 4; \ + CYCLIC (a, s); \ + a += b; \ + }; + + /* It is unfortunate that C does not provide an operator for + cyclic rotation. Hope the C compiler is smart enough. */ +#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s))) + + /* Before we start, one word to the strange constants. + They are defined in RFC 1321 as + + T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 + */ + + /* Round 1. */ + OP (A, B, C, D, 7, 0xd76aa478); + OP (D, A, B, C, 12, 0xe8c7b756); + OP (C, D, A, B, 17, 0x242070db); + OP (B, C, D, A, 22, 0xc1bdceee); + OP (A, B, C, D, 7, 0xf57c0faf); + OP (D, A, B, C, 12, 0x4787c62a); + OP (C, D, A, B, 17, 0xa8304613); + OP (B, C, D, A, 22, 0xfd469501); + OP (A, B, C, D, 7, 0x698098d8); + OP (D, A, B, C, 12, 0x8b44f7af); + OP (C, D, A, B, 17, 0xffff5bb1); + OP (B, C, D, A, 22, 0x895cd7be); + OP (A, B, C, D, 7, 0x6b901122); + OP (D, A, B, C, 12, 0xfd987193); + OP (C, D, A, B, 17, 0xa679438e); + OP (B, C, D, A, 22, 0x49b40821); + + /* For the second to fourth round we have the possibly swapped words + in CORRECT_WORDS. Redefine the macro to take an additional first + argument specifying the function to use. */ +#undef OP +#define OP(f, a, b, c, d, k, s, T) { \ + a += f (b, c, d) + \ + unCorrectWords[k] + T; \ + CYCLIC (a, s); \ + a += b; \ + } + /* Round 2. */ + OP (FG, A, B, C, D, 1, 5, 0xf61e2562); + OP (FG, D, A, B, C, 6, 9, 0xc040b340); + OP (FG, C, D, A, B, 11, 14, 0x265e5a51); + OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa); + OP (FG, A, B, C, D, 5, 5, 0xd62f105d); + OP (FG, D, A, B, C, 10, 9, 0x02441453); + OP (FG, C, D, A, B, 15, 14, 0xd8a1e681); + OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8); + OP (FG, A, B, C, D, 9, 5, 0x21e1cde6); + OP (FG, D, A, B, C, 14, 9, 0xc33707d6); + OP (FG, C, D, A, B, 3, 14, 0xf4d50d87); + OP (FG, B, C, D, A, 8, 20, 0x455a14ed); + OP (FG, A, B, C, D, 13, 5, 0xa9e3e905); + OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8); + OP (FG, C, D, A, B, 7, 14, 0x676f02d9); + OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a); + + /* Round 3. */ + OP (FH, A, B, C, D, 5, 4, 0xfffa3942); + OP (FH, D, A, B, C, 8, 11, 0x8771f681); + OP (FH, C, D, A, B, 11, 16, 0x6d9d6122); + OP (FH, B, C, D, A, 14, 23, 0xfde5380c); + OP (FH, A, B, C, D, 1, 4, 0xa4beea44); + OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9); + OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60); + OP (FH, B, C, D, A, 10, 23, 0xbebfbc70); + OP (FH, A, B, C, D, 13, 4, 0x289b7ec6); + OP (FH, D, A, B, C, 0, 11, 0xeaa127fa); + OP (FH, C, D, A, B, 3, 16, 0xd4ef3085); + OP (FH, B, C, D, A, 6, 23, 0x04881d05); + OP (FH, A, B, C, D, 9, 4, 0xd9d4d039); + OP (FH, D, A, B, C, 12, 11, 0xe6db99e5); + OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8); + OP (FH, B, C, D, A, 2, 23, 0xc4ac5665); + + /* Round 4. */ + OP (FI, A, B, C, D, 0, 6, 0xf4292244); + OP (FI, D, A, B, C, 7, 10, 0x432aff97); + OP (FI, C, D, A, B, 14, 15, 0xab9423a7); + OP (FI, B, C, D, A, 5, 21, 0xfc93a039); + OP (FI, A, B, C, D, 12, 6, 0x655b59c3); + OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92); + OP (FI, C, D, A, B, 10, 15, 0xffeff47d); + OP (FI, B, C, D, A, 1, 21, 0x85845dd1); + OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f); + OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0); + OP (FI, C, D, A, B, 6, 15, 0xa3014314); + OP (FI, B, C, D, A, 13, 21, 0x4e0811a1); + OP (FI, A, B, C, D, 4, 6, 0xf7537e82); + OP (FI, D, A, B, C, 11, 10, 0xbd3af235); + OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb); + OP (FI, B, C, D, A, 9, 21, 0xeb86d391); + + /* Add the starting values of the context. */ + A += A_save; + B += B_save; + C += C_save; + D += D_save; + } + m_unA = A; + m_unB = B; + m_unC = C; + m_unD = D; +} + +void +CDavMD5::UpdateHash(const void *pvData, unsigned int unLen) +{ + if(m_unBufLen > 0){ + unsigned int unLeftOver = m_unBufLen; + unsigned int unAdd = 128 - unLeftOver > unLen ? unLen : 128 - unLeftOver; + + memcpy (&m_szBuf[unLeftOver], pvData, unAdd); + m_unBufLen += unAdd; + + if (unLeftOver + unAdd > 64){ + updateBlock (m_szBuf, (unLeftOver + unAdd) & ~63); + /* The regions in the following copy operation cannot overlap. */ + memcpy (m_szBuf, &m_szBuf[(unLeftOver + unAdd) & ~63], + (unLeftOver + unAdd) & 63); + m_unBufLen = (unLeftOver + unAdd) & 63; + } + + pvData = (const char *) pvData + unAdd; + unLen -= unAdd; + } + + /* Process available complete blocks. */ + if (unLen > 64){ + updateBlock (pvData, unLen & ~63); + pvData = (const char *) pvData + (unLen & ~63); + unLen &= 63; + } + + /* Move remaining bytes in internal pvData. */ + if (unLen > 0){ + memcpy (m_szBuf, pvData, unLen); + m_unBufLen = unLen; + } +} + +void +CDavMD5::Finalize(unsigned char yBuf[16]) +{ + /* Take yet unprocessed unBytes into account. */ + MD5_UINT32 unBytes = m_unBufLen; + unsigned int unPad; + + /* Now count remaining unBytes. */ + m_unTotal[0] += unBytes; + if (m_unTotal[0] < unBytes) + ++m_unTotal[1]; + + unPad = unBytes >= 56 ? 64 + 56 - unBytes : 56 - unBytes; + memcpy (&m_szBuf[unBytes], chPadding, unPad); + + /* Put the 64-bit file length in *bits* at the end of the buffer. */ + *(MD5_UINT32 *) &m_szBuf[unBytes + unPad] = OI_SWAP (m_unTotal[0] << 3); + *(MD5_UINT32 *) &m_szBuf[unBytes + unPad + 4] = OI_SWAP ((m_unTotal[1] << 3) | + (m_unTotal[0] >> 29)); + + /* Process last unBytes. */ + updateBlock (m_szBuf, unBytes + unPad + 8); + + getHash(yBuf); +} + + +CDavXmlString::CDavXmlString() +{ + m_pszANSIStr = NULL; + m_pszXMLStr = NULL; +} + +CDavXmlString::CDavXmlString(const char* pszANSIStr) +{ + copy(pszANSIStr); +} + +CDavXmlString::CDavXmlString(const XMLCh* pszXMLStr) +{ + copy(pszXMLStr); +} + +CDavXmlString::CDavXmlString(const XMLByte* pszUTF8Str) +{ + transcode(pszUTF8Str); +} + +CDavXmlString::CDavXmlString(const CDavXmlString& master) +{ + copy(master); +} + +void +CDavXmlString::copy(const char* pszANSIStr) +{ + m_pszANSIStr = XNS(XMLString)::replicate(pszANSIStr); + m_pszXMLStr = NULL; +} + +void +CDavXmlString::copy(const XMLCh* pszXMLStr) +{ + m_pszANSIStr = NULL; + m_pszXMLStr = XNS(XMLString)::replicate(pszXMLStr); +} + +void +CDavXmlString::copy(const CDavXmlString& master) +{ + if(master.m_pszANSIStr) + m_pszANSIStr = XNS(XMLString)::replicate(master.m_pszANSIStr); + else + m_pszANSIStr = NULL; + + if(master.m_pszXMLStr) + m_pszXMLStr = XNS(XMLString)::replicate(master.m_pszXMLStr); + else + m_pszXMLStr = NULL; +} + +void +CDavXmlString::transcode(const XMLByte* pszUTF8Str) +{ + m_pszXMLStr = NULL; + int nUTF8Len = XNS(XMLString)::stringLen((const char*)pszUTF8Str) + 1; + int nUCS2Len = nUTF8Len; + XMLCh* pszUCS2 = new XMLCh[nUCS2Len]; + unsigned char* pSizeChars = new unsigned char[nUCS2Len]; + unsigned int unBytesEaten = 0; + int nTranscodedLen = + g_pUTF8Transcoder->transcodeFrom(pszUTF8Str, + nUTF8Len, + pszUCS2, + nUCS2Len, + unBytesEaten, + pSizeChars); + delete[] pSizeChars; + m_pszANSIStr = XNS(XMLString)::transcode(pszUCS2); + delete[] pszUCS2; +} + +void +CDavXmlString::cleanup() +{ + if (m_pszXMLStr) + XNS(XMLString)::release(&m_pszXMLStr); + if (m_pszANSIStr) + XNS(XMLString)::release(&m_pszANSIStr); +} + +CDavXmlString::~CDavXmlString() +{ + cleanup(); +} + +CDavXmlString& +CDavXmlString::operator =(const CDavXmlString& master) +{ + cleanup(); + copy(master); + return *this; +} + +CDavXmlString& +CDavXmlString::operator =(const char* pszANSIStr) +{ + cleanup(); + copy(pszANSIStr); + return *this; +} + +CDavXmlString& +CDavXmlString::operator =(const XMLCh* pszXMLStr) +{ + cleanup(); + copy(pszXMLStr); + return *this; +} + +CDavXmlString& +CDavXmlString::operator =(const XMLByte* pszUTF8Str) +{ + cleanup(); + transcode(pszUTF8Str); + return *this; +} + +unsigned int +CDavXmlString::Length() +{ + if(m_pszXMLStr){ + return XNS(XMLString)::stringLen(m_pszXMLStr); + } else if(m_pszANSIStr) { + return XNS(XMLString)::stringLen(m_pszANSIStr); + } else { + return 0; + } +} + +CDavXmlString& +CDavXmlString::toEscapedUTF8() +{ + const XMLCh* pszXMLCh = operator const XMLCh*(); + int nLen = Length() + 1; + int nUTF8Len = (nLen) * 6; + XMLByte* pszUTF8 = new XMLByte[nUTF8Len]; + unsigned int unCharsEaten = 0; + unsigned int nTranscodedLen = + g_pUTF8Transcoder->transcodeTo(pszXMLCh, + nLen, + pszUTF8, + nUTF8Len, + unCharsEaten, + XNS(XMLTranscoder)::UnRep_RepChar); + //perhaps should be UnRep_Throw + + char* pszEscaped = new char[nUTF8Len * 3]; + char buf[4] = {"???"}; + XMLByte* pchUTF8 = pszUTF8; + char* pchEscaped = pszEscaped; + char chUTF8; + + for( ; chUTF8 = *pchUTF8 ; pchUTF8++){ + if(ESCAPE(chUTF8)){ + sprintf(pchEscaped,"%%%02x", (unsigned char)chUTF8); + pchEscaped += 3; + } else { + *pchEscaped = chUTF8; + pchEscaped++; + } + } + *pchEscaped = '\0'; + + cleanup(); + copy(pszEscaped); + delete[] pszEscaped; + delete[] pszUTF8; + return *this; +} + +char* +CDavXmlString::UTF8() +{ + const XMLCh* pszXMLCh = operator const XMLCh*(); + int nLen = Length() + 1; + int nUTF8Len = (nLen) * 6; + XMLByte* pszRet = new XMLByte[nUTF8Len]; + unsigned int unCharsEaten = 0; + unsigned int nTranscodedLen = + g_pUTF8Transcoder->transcodeTo(pszXMLCh, + nLen, + pszRet, + nUTF8Len, + unCharsEaten, + XNS(XMLTranscoder)::UnRep_RepChar); + //perhaps should be UnRep_Throw + return (char*)pszRet; +} + + +CDavXmlString::operator const char*() +{ + if(!m_pszANSIStr){ + if(m_pszXMLStr) + m_pszANSIStr = XNS(XMLString)::transcode(m_pszXMLStr); + if(!m_pszANSIStr) + m_pszANSIStr = XNS(XMLString)::replicate(""); + } + return m_pszANSIStr; +} + +CDavXmlString::operator const XMLCh*() +{ + if(!m_pszXMLStr){ + if(m_pszANSIStr) + m_pszXMLStr = XNS(XMLString)::transcode(m_pszANSIStr); + if(!m_pszXMLStr) + m_pszXMLStr = XNS(XMLString)::transcode(""); + } + return m_pszXMLStr; +} + +CDavStringTokenizer::CDavStringTokenizer(const char* pszInput, + const char* pszDelimiters): + m_pszHead(pszInput), + m_pszCurrentPos(pszInput), + m_pszDelimiters(pszDelimiters), + m_bInQuote(false) +{ +} + +CDavStringTokenizer::~CDavStringTokenizer() +{ +} + +void +CDavStringTokenizer::SetDelimiter(const char* pszDelimiters) +{ + if(pszDelimiters) + m_pszDelimiters = pszDelimiters; +} + +void +CDavStringTokenizer::SetToken(const char* pszInput) +{ + if(pszInput){ + m_pszCurrentPos = pszInput; + m_pszHead = pszInput; + m_bInQuote = false; + } +} + +bool +CDavStringTokenizer::IsDelimiter(char chInput) +{ + const char* pszDelimiter; + for(pszDelimiter = m_pszDelimiters; + *pszDelimiter != '\0'; + pszDelimiter++){ + if(chInput == *pszDelimiter) + return true; + } + return false; +} + +bool +CDavStringTokenizer::GetNextToken(OI_STRING_A& strOutput) +{ + if(!m_pszHead || !m_pszCurrentPos) + return false; + + bool bHasToken = false; + strOutput.erase(); + + char chCurrent; + + for(;(chCurrent = *m_pszCurrentPos) != '\0'; m_pszCurrentPos++){ + if(!m_bInQuote){ + if(IsDelimiter(chCurrent)) + if(bHasToken) + return true; + else + continue; + } + //hard code quotation as an arbitraty delimiter + if(chCurrent == '\"'){ + m_bInQuote = !m_bInQuote; + } + strOutput += chCurrent; + bHasToken = true; + } + return bHasToken; +} + +OI_STRING_A +HashString(const OI_STRING_A& input) +{ + CDavMD5 md5; + md5.UpdateHash(input.c_str(), (unsigned int)input.length()); + return md5.GetHashString(); +} + +unsigned int +FastHash(const OI_STRING_A& input) +{ + unsigned int unOutput = 0; + for(OI_STRING_A::const_iterator it = input.begin(); + it != input.end(); + it++){ + unOutput = (unOutput<<5) + unOutput + *it; + } + return unOutput; +} + +//time parsing functions +static const char* pszRFC1123Weekdays[7] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +static const char* pszShortMonths[12] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + + +static const char* pszRFC2459Months[12] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +//ASN1 time uses RFC2459 format +time_t +ParseTimeRFC2459(const char* pszTime) +{ + struct tm gmt = {0}; + int n; + char mon[4]; + n = sscanf(pszTime, OI_TIMEFORMAT_RFC2459, + mon, &gmt.tm_mday, + &gmt.tm_hour, &gmt.tm_min, &gmt.tm_sec, + &gmt.tm_year); + gmt.tm_year -= 1900; + /* portable to check n here? */ + for (n=0; n<12; n++){ + if (strcmp(mon, pszRFC2459Months[n]) == 0) + break; + } + /* tm_mon comes out as 12 if the month is corrupt, which is desired, + * since the mktime will then fail */ + gmt.tm_mon = n; + gmt.tm_isdst = -1; + return mktime(&gmt);// + GMTOFF(gmt); +} + +time_t +ParseTime(const char* pszTime) +{ + time_t tmp; + tmp = ParseTimeRFC1123(pszTime); + if (tmp == -1) { + tmp = ParseTimeRFC1036(pszTime); + if (tmp == -1) + tmp = ParseTimeASC(pszTime); + } + return tmp; +} + +time_t +ParseTimeASC(const char* pszTime) +{ + struct tm gmt = {0}; + int n; + char wkday[4], mon[4]; + n = sscanf(pszTime, OI_TIMEFORMAT_ASC, + wkday, mon, &gmt.tm_mday, + &gmt.tm_hour, &gmt.tm_min, &gmt.tm_sec, + &gmt.tm_year); + /* portable to check n here? */ + for (n=0; n<12; n++) + if (strcmp(mon, pszShortMonths[n]) == 0) + break; + /* tm_mon comes out as 12 if the month is corrupt, which is desired, + * since the mktime will then fail */ + gmt.tm_mon = n; + gmt.tm_isdst = -1; + return mktime(&gmt);// + GMTOFF(gmt); +} + +time_t +ParseTimeISO8601(const char* pszTime) +{ + struct tm gmt = {0}; + int off_hour, off_min; + double sec; + off_t fix; + int n; + + if ((n = sscanf(pszTime, OI_TIMEFORMAT_ISO8601_P, + &gmt.tm_year, &gmt.tm_mon, &gmt.tm_mday, + &gmt.tm_hour, &gmt.tm_min, &sec, + &off_hour, &off_min)) == 8) { + /* it goes: ISO8601: 2001-01-01T12:30:00+03:30 */ + gmt.tm_sec = (int)sec; + fix = - off_hour * 3600 - off_min * 60; + } else if ((n = sscanf(pszTime, OI_TIMEFORMAT_ISO8601_M, + &gmt.tm_year, &gmt.tm_mon, &gmt.tm_mday, + &gmt.tm_hour, &gmt.tm_min, &sec, + &off_hour, &off_min)) == 8) { + /* it goes: ISO8601: 2001-01-01T12:30:00-03:30 */ + gmt.tm_sec = (int)sec; + fix = off_hour * 3600 + off_min * 60; + } else if ((n = sscanf(pszTime, OI_TIMEFORMAT_ISO8601_Z, + &gmt.tm_year, &gmt.tm_mon, &gmt.tm_mday, + &gmt.tm_hour, &gmt.tm_min, &sec)) == 6) { + /* it goes: ISO8601: 2001-01-01T12:30:00Z */ + gmt.tm_sec = (int)sec; + fix = 0; + } else { + return (time_t)-1; + } + + gmt.tm_year -= 1900; + gmt.tm_isdst = -1; + gmt.tm_mon--; + + return mktime(&gmt) + fix; +} + +time_t +ParseTimeRFC1036(const char* pszTime) +{ + struct tm gmt = {0}; + int n; + char wkday[10], mon[4]; + /* RFC850/1036 style dates: Sunday, 06-Nov-94 08:49:37 GMT */ + n = sscanf(pszTime, OI_TIMEFORMAT_RFC1036, + wkday, &gmt.tm_mday, mon, &gmt.tm_year, + &gmt.tm_hour, &gmt.tm_min, &gmt.tm_sec); + if (n != 7) { + return (time_t)-1; + } + + /* portable to check n here? */ + for (n=0; n<12; n++) + if (strcmp(mon, pszShortMonths[n]) == 0) + break; + /* tm_mon comes out as 12 if the month is corrupt, which is desired, + * since the mktime will then fail */ + + /* Defeat Y2K bug. */ + if (gmt.tm_year < 50) + gmt.tm_year += 100; + + gmt.tm_mon = n; + gmt.tm_isdst = -1; + return mktime(&gmt);// + GMTOFF(gmt); +} + +time_t +ParseTimeRFC1123(const char* pszTime) +{ + struct tm gmt = {0}; + char wkday[4], mon[4]; + int n; + /* it goes: Sun, 06 Nov 1994 08:49:37 GMT */ + n = sscanf(pszTime, OI_TIMEFORMAT_RFC1123, + wkday, &gmt.tm_mday, mon, &gmt.tm_year, &gmt.tm_hour, + &gmt.tm_min, &gmt.tm_sec); + /* Is it portable to check n==7 here? */ + gmt.tm_year -= 1900; + for (n=0; n<12; n++) + if (strcmp(mon, pszShortMonths[n]) == 0) + break; + /* tm_mon comes out as 12 if the month is corrupt, which is desired, + * since the mktime will then fail */ + gmt.tm_mon = n; + gmt.tm_isdst = -1; + return mktime(&gmt);// + GMTOFF(gmt); +} + + +time_t +GmtToLocal(time_t gmt) +{ +#ifdef WIN32 + if (gmt == -1) + return -1; + + TIME_ZONE_INFORMATION tzinfo; + DWORD dwStandardDaylight = GetTimeZoneInformation(&tzinfo); + long bias = tzinfo.Bias; + if (dwStandardDaylight == TIME_ZONE_ID_STANDARD) + bias += tzinfo.StandardBias; + + if (dwStandardDaylight == TIME_ZONE_ID_DAYLIGHT) + bias += tzinfo.DaylightBias; + + return gmt - (bias * 60); +#else + return gmt; //TODO: implement this +#endif //WIN32 +} + + Index: onion/src/DavXmlErrorHandler.cpp =================================================================== --- onion/src/DavXmlErrorHandler.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavXmlErrorHandler.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,46 @@ +/* + Error handler needed by XML parser + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlErrorHandler.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CDavXmlErrorHandler::CDavXmlErrorHandler(void) +{ +} + +CDavXmlErrorHandler::~CDavXmlErrorHandler(void) +{ +} + +void +CDavXmlErrorHandler::error(const XNS(SAXParseException) &exception) +{ +} + +void +CDavXmlErrorHandler::fatalError(const XNS(SAXParseException) &exception) +{ +} + Index: onion/src/DavMemBuffer.cpp =================================================================== --- onion/src/DavMemBuffer.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavMemBuffer.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,148 @@ +/* + Variable length buffer + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavMemBuffer.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + + +CDavMemBuffer::CDavMemBuffer(size_t unInitSize, + size_t unSizeLimit, size_t unIncrSize) +{ + if(unSizeLimit > OI_MEMBUF_SIZELIMIT || + unSizeLimit == 0) unSizeLimit = OI_MEMBUF_SIZELIMIT; + if(unInitSize > unSizeLimit) unInitSize = unSizeLimit; + + m_unSizeLimit = unSizeLimit; + m_unIncrSize = unIncrSize; + + m_pyBufHead = malloc(unInitSize + 4); + m_unBufLen = unInitSize; + Clear(); +} + +CDavMemBuffer::~CDavMemBuffer() +{ + if(m_pyBufHead) + free(m_pyBufHead); +} + +size_t +CDavMemBuffer::grow(size_t unNewSize) +{ + if(unNewSize <= m_unBufLen || unNewSize > m_unSizeLimit) + return m_unBufLen; + + void* pNewBuf = realloc(m_pyBufHead, unNewSize + 4); + + if(pNewBuf){ + m_pyBufHead = pNewBuf; + m_unBufLen = unNewSize; + } + return m_unBufLen; +} + +bool +CDavMemBuffer::ensureCapacity(size_t unWriteSize) +{ + if(m_unDataLen + unWriteSize < m_unBufLen) + return true; + + size_t unNewSize; + if(m_unIncrSize > 0) + unNewSize = ((m_unDataLen + unWriteSize)/m_unIncrSize + 1) * m_unIncrSize; + else + unNewSize = (m_unDataLen + unWriteSize) * 2; + + size_t unNewBufLen = grow(unNewSize); + + if(unNewBufLen < unNewSize) + return false; + else + return true; +} + +size_t +CDavMemBuffer::Write(const void* pyData, size_t unDataLen) +{ + if(!ensureCapacity(unDataLen) || unDataLen <= 0 || pyData == NULL) + return 0; + + memcpy((unsigned char*)m_pyBufHead + m_unDataLen, pyData, unDataLen); + m_unDataLen += unDataLen; + return unDataLen; +} + +const void* +CDavMemBuffer::GetData() +{ + unsigned char* pyTail = (unsigned char*)m_pyBufHead + m_unDataLen; + + *(pyTail + 0) = 0; + *(pyTail + 1) = 0; + *(pyTail + 2) = 0; + *(pyTail + 3) = 0; + + return m_pyBufHead; +} + +void +CDavMemBuffer::Clear() +{ + unsigned char* pHead = (unsigned char*)m_pyBufHead; + m_unDataLen = 0; + *(pHead + 0) = 0; + *(pHead + 1) = 0; + *(pHead + 2) = 0; + *(pHead + 3) = 0; + m_strContentType.erase(); +} + +size_t +CDavMemBuffer::GetBufferSize() +{ + return m_unBufLen; +} + +size_t +CDavMemBuffer::GetDataSize() +{ + return m_unDataLen; +} + +size_t +CDavMemBuffer::GetIncrementSize() +{ + return m_unIncrSize; +} + +size_t +CDavMemBuffer::SetIncrementSize(size_t unNewSize) +{ + size_t unOldValue = m_unIncrSize; + + m_unIncrSize = (unNewSize > OI_MEMBUF_SIZELIMIT)? + OI_MEMBUF_SIZELIMIT:unNewSize; + return unOldValue; +} Index: onion/src/HandlerKeepAlive.cpp =================================================================== --- onion/src/HandlerKeepAlive.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerKeepAlive.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,70 @@ +/* + Http header handler for "Keep-Alive" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerKeepAlive.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +CHandlerKeepAlive::CHandlerKeepAlive(void) +{ +} + +CHandlerKeepAlive::~CHandlerKeepAlive(void) +{ +} + +bool +CHandlerKeepAlive::Execute(CDavRequest* pReq, const char *pszValue) +{ + //OI_DEBUG("value : %s\n", pszValue); + CDavStringTokenizer tokKeepAlive(pszValue, ", "); + OI_STRING_A strField; + OI_STRING_A strName; + OI_STRING_A strValue; + for(;tokKeepAlive.GetNextToken(strField);){ + CDavStringTokenizer tokField(strField.c_str(), "= "); + if(!tokField.GetNextToken(strName)) + continue; + if(!tokField.GetNextToken(strValue)) + continue; + MakeLowerA(strName); + if(strName == "timeout"){ + long nTimeout = atol(strValue.c_str()); + time_t tmNow = time(NULL); + pReq->m_pSession->m_tmConnectionTTL = tmNow + nTimeout; + } else if(strName == "max"){ + int nMax = atoi(strValue.c_str()); + pReq->m_pSession->m_nMaxConnections = nMax; + } + } + return true; +} + +const char* +CHandlerKeepAlive::GetHeaderName() +{ + return OI_RSPHDR_KEEPALIVE; +} Index: onion/src/HandlerMSV.cpp =================================================================== --- onion/src/HandlerMSV.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerMSV.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Http header handler for "MS-Author-Via" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerMSV.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CHandlerMSV::CHandlerMSV() +{ +} + +CHandlerMSV::~CHandlerMSV() +{ +} + +bool +CHandlerMSV::Execute(CDavRequest* pReq, const char *pszValue) +{ + m_strMSV += pszValue; + m_strMSV += "\n"; + return true; +} + +const char* +CHandlerMSV::GetHeaderName() +{ + return OI_RSPHDR_MSV; +} Index: onion/src/HandlerTE.cpp =================================================================== --- onion/src/HandlerTE.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerTE.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,55 @@ +/* + Http header handler for "Transfer-Encoding" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerTE.cpp,v 1.1.1.1 2004/07/15 06:58:43 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +CHandlerTE::CHandlerTE(CDavResponseBody* pBody) +{ + m_pBody = pBody; +} + +CHandlerTE::~CHandlerTE(void) +{ +} + +bool +CHandlerTE::Execute(CDavRequest* pReq, const char *pszValue) +{ + char szChunked[] = "chunked"; + if(strnicmp(pszValue, szChunked, strlen(szChunked)) == 0){ + m_pBody->m_enuMode = M_RSP_CHUNKED; + m_pBody->m_unChunkLeft = 0; + } + return true; +} + +const char* +CHandlerTE::GetHeaderName() +{ + return OI_RSPHDR_TE; +} Index: onion/src/config.h =================================================================== --- onion/src/config.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/config.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,5 @@ +#ifdef WIN32 +# include "config_win.h" +#else +# include "config_unix.h" +#endif Index: onion/src/HandlerAuthInfo.cpp =================================================================== --- onion/src/HandlerAuthInfo.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerAuthInfo.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,52 @@ +/* + Http header handler for "AuthInfo" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerAuthInfo.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +CHandlerAuthInfo::CHandlerAuthInfo(CDavRequest* pReq, + CDavAuthSession* pAuthSession) +{ + OI_ASSERT(pAuthSession); + m_pAuthSession = pAuthSession; +} + +CHandlerAuthInfo::~CHandlerAuthInfo() +{ +} + +bool +CHandlerAuthInfo::Execute(CDavRequest* pReq, const char *pszValue) +{ + m_pAuthSession->SetAuthInfoHeader(pszValue); + return true; +} + +const char* CHandlerAuthInfo::GetHeaderName() +{ + return m_pAuthSession->GetAuthInfoHeaderName(); +} + Index: onion/src/HandlerAllow.cpp =================================================================== --- onion/src/HandlerAllow.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerAllow.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Http header handler for "Allow" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerAllow.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CHandlerAllow::CHandlerAllow() +{ +} + +CHandlerAllow::~CHandlerAllow() +{ +} + +bool +CHandlerAllow::Execute(CDavRequest* pReq, const char *pszValue) +{ + m_strAllow += pszValue; + m_strAllow += "\n"; + return true; +} + +const char* +CHandlerAllow::GetHeaderName() +{ + return OI_RSPHDR_ALLOW; +} Index: onion/src/DavSession.cpp =================================================================== --- onion/src/DavSession.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavSession.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,74 @@ +/* + Main session infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSession.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CDavSession::CDavSession(void) +{ +} + +CDavSession::~CDavSession(void) +{ +} + +CDavHost& +CDavSession::GetHost() +{ + return m_Server; +} + +CDavHost& +CDavSession::GetProxy() +{ + return m_Proxy; +} + +const char* +CDavSession::GetUserAgent() +{ + return m_strUserAgent.c_str(); +} + +void +CDavSession::SetUserAgent(const char* pszUserAgent) +{ + m_strUserAgent.erase(); + if(pszUserAgent) + m_strUserAgent = pszUserAgent; +} + +void +CDavSession::SetHost(const CDavHost& Server) +{ + m_Server = Server; +} + +void +CDavSession::SetProxy(const CDavHost& Proxy) +{ + m_Proxy = Proxy; +} + Index: onion/src/PBCSMLocalFile.cpp =================================================================== --- onion/src/PBCSMLocalFile.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/PBCSMLocalFile.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,101 @@ +/* + Response body consumer that writes to a local file + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMLocalFile.cpp,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include + +#ifdef WIN32 +# include +#elif HAVE_UNISTD_H +# include +#endif /*HAVE_UNISTD_H*/ + +CPBCSMLocalFile::CPBCSMLocalFile(CDavRequest* pReq, int nHandle): + CResponseBodyConsumer(pReq), + m_nHandle(nHandle) +{ + OI_ASSERT(nHandle); + //m_lPosition = tell(nHandle); +} + +CPBCSMLocalFile::~CPBCSMLocalFile() +{ +} + +void +CPBCSMLocalFile::Close() +{ +} + +OI_RESULT +CPBCSMLocalFile::Open() +{ + return OI_OK; +} + +OI_PBC_TYPE +CPBCSMLocalFile::GetType() +{ + return T_PBC_FILE; +} + +OI_RESULT +CPBCSMLocalFile::PullResponseBody(CDavResponseBody* pBody) +{ + OI_RESULT enuRet; + bool bContinue; + size_t unReadLen, unBufLen; + char* pszBuf = m_pRequest->m_szBuffer; //we use request buffer here + + for(enuRet = OI_RETRY, unBufLen = OI_GENBUFSIZE; + enuRet == OI_RETRY; + unReadLen = OI_GENBUFSIZE){ + enuRet = pBody->Read(pszBuf, unBufLen, &unReadLen); + if(enuRet != OI_OK && enuRet != OI_RETRY) + return enuRet; + + //increment session progress and query for continue + bContinue = + m_pRequest->m_pSession->OnReceiveProgress(m_pRequest, + pBody->m_unReadLen, + pBody->m_unBodyLen, + (pBody->m_enuMode == M_RSP_CLENGTH)); + if(!bContinue){ + //TODO: this might be bad for server + //perhaps we should jettison all the body + m_pRequest->m_pSession->Disconnect(); + return OI_USERCANCELED; + } + + //TODO:error handling + write(m_nHandle, pszBuf, unReadLen); + } + return enuRet; +} + Index: onion/src/RBPVDXmlProppatch.cpp =================================================================== --- onion/src/RBPVDXmlProppatch.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDXmlProppatch.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for PROPPATCH method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlProppatch.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CRBPVDXmlProppatch::CRBPVDXmlProppatch(): + CRBPVDXml(OI_XML_PROPPATCHDOCNAME) +{ +} + +CRBPVDXmlProppatch::~CRBPVDXmlProppatch() +{ +} Index: onion/src/HandlerCType.cpp =================================================================== --- onion/src/HandlerCType.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerCType.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,57 @@ +/* + Http header handler for "Content-Type" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerCType.cpp,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + + +CHandlerCType::CHandlerCType(void) +{ +} + +CHandlerCType::~CHandlerCType(void) +{ +} + + +bool +CHandlerCType::Execute(CDavRequest* pReq, const char *pszValue) +{ + m_strCType = pszValue; + return true; +} + +const char* +CHandlerCType::GetHeaderName() +{ + return OI_RSPHDR_CTYPE; +} + +const char* +CHandlerCType::GetContentType() +{ + return m_strCType.c_str(); +} Index: onion/src/HandlerCLength.cpp =================================================================== --- onion/src/HandlerCLength.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerCLength.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,59 @@ +/* + Http header handler for "Content-Length" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerCLength.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +CHandlerCLength::CHandlerCLength(CDavResponseBody* pBody) +{ + m_pBody = pBody; +} + +CHandlerCLength::~CHandlerCLength() +{ +} + +bool +CHandlerCLength::Execute(CDavRequest* pReq, const char *pszValue) +{ + char* pchPos = 0; + size_t unBodyLen = strtoul(pszValue, &pchPos, 0); + if(unBodyLen != ULONG_MAX && + m_pBody->m_enuMode == M_RSP_TILLEOF){ + m_pBody->m_enuMode = M_RSP_CLENGTH; + m_pBody->m_unBodyLen = unBodyLen; + m_pBody->m_unBodyLeft = unBodyLen; + } + return true; +} + +const char* +CHandlerCLength::GetHeaderName() +{ + return OI_RSPHDR_CLENGTH; +} + Index: onion/src/DavLock.cpp =================================================================== --- onion/src/DavLock.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavLock.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,51 @@ +/* + Lock infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavLock.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + + +CDavLock::CDavLock() +{ + m_unMask = 0; +} + +CDavLock::~CDavLock() +{ +} + +CDavLock& +CDavLock::operator =(const CDavLock& master) +{ + m_unMask = master.m_unMask; + m_enuType = master.m_enuType; + m_enuScope = master.m_enuScope; + m_enuDepth = master.m_enuDepth; + m_lTimeout = master.m_lTimeout; + m_strToken = master.m_strToken; + m_pOwner = master.m_pOwner; + return *this; +} + Index: onion/src/DavRequest.cpp =================================================================== --- onion/src/DavRequest.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavRequest.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,853 @@ +/* + Http request handler + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavRequest.cpp,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RETRY_RET(retry, code, acode) \ + ((((code) == OISECLOSED || (code) == OISERESET || \ + (code) == OISECONNABORTED || (code) == OISETRUNC) \ + && retry) ? OI_RETRY : (acode)) + + +CDavRequest::CDavRequest(CDavWorkSession* pSession): + m_pSession(pSession) +{ + OI_ASSERT(pSession); + m_enuType = T_REQ_INVALID; + m_pRBProvider = 0; + m_pPBConsumer = 0; +} + +CDavRequest::~CDavRequest(void) +{ + ClearHandlers(); +} + +const char* +CDavRequest::GetURI() +{ + return m_strURI.c_str(); +} + +OI_REQ_TYPE +CDavRequest::GetMethod() +{ + return m_enuType; +} + +const char* +CDavRequest::GetMethodStr() +{ + return m_strMethod.c_str(); +} + +int +CDavRequest::GetStatusCode() +{ + return m_HttpStatus.m_nCode; +} + +int +CDavRequest::GetStatusClass() +{ + return m_HttpStatus.m_nCodeClass; +} + +void +CDavRequest::ClearHandlers() +{ + for(HANDLERITERATOR it = m_mapHeaderHandlers.begin(); + it != m_mapHeaderHandlers.end(); + it++){ + delete it->second; + } + m_mapHeaderHandlers.clear(); +} + +bool +CDavRequest::AddHandler(CResponseHeaderHandler* pHandler, const char* pszName) +{ + OI_ASSERT(pHandler); + + bool bExists = false; + OI_STRING_A strName = (pszName) ? pszName : pHandler->GetHeaderName(); + TrimLeftA(strName); + TrimRightA(strName); + //OI_DEBUG("Adding Handler <%s>\n", strName.c_str()); + //convert the name into lower case + MakeLowerA(strName); + HANDLERITERATOR it = m_mapHeaderHandlers.find(strName); + if(it != m_mapHeaderHandlers.end()){ + bExists = true; + delete it->second; + } + m_mapHeaderHandlers[strName] = pHandler; + return bExists; +} + +bool +CDavRequest::RemoveHandler(const char *pszName) +{ + OI_ASSERT(pszName); + + bool bExists = false; + OI_STRING_A strName = pszName; + //strName.erase(0, strName.find_first_not_of(' ')); + //strName.erase(strName.find_last_not_of(' ') + 1); + //convert the name into lower case + for(OI_STRING_A::iterator itCh = strName.begin(); + itCh != strName.end(); itCh++){ + *itCh = tolower(*itCh); + } + HANDLERITERATOR it = m_mapHeaderHandlers.find(strName); + if(it != m_mapHeaderHandlers.end()){ + bExists = true; + delete it->second; + m_mapHeaderHandlers.erase(it); + } + return bExists; +} + +void +CDavRequest::AddHeader(const char *pszName, const char *pszValue) +{ + OI_ASSERT(pszName); + OI_ASSERT(pszValue); + //OI_DEBUG("Adding Header <%s = %s>\n", pszName, pszValue); + m_mapHeaderFields[pszName] = pszValue; +} + +void +CDavRequest::SetPersistent(bool bValue) +{ + m_pSession->SetPersistent(bValue); +} + +bool +CDavRequest::RemoveHeader(const char *pszName) +{ + OI_ASSERT(pszName); + bool bExists = false; + HEADITERATOR it = m_mapHeaderFields.find(pszName); + if(it != m_mapHeaderFields.end()){ + bExists = true; + m_mapHeaderFields.erase(it); + } + return bExists; +} + +void +CDavRequest::addFixedHeaders() +{ + OI_STRING_A strUserAgent = m_pSession->GetUserAgent(); + + if(strUserAgent.length() > 0) + AddHeader("User-Agent", strUserAgent.c_str()); + /* + if(m_pSession->IsHttp11() || m_pSession->IsUsingProxy()) + AddHeader("Connection", "TE"); + else + { + */ //???Squid does not accept the above header + AddHeader("Connection", "TE, Keep-Alive"); + AddHeader("Keep-Alive", ""); + /* + }*/ +} + +void +CDavRequest::stripEOL(char* pszBuf, size_t* punLen) +{ + char* pCh = &pszBuf[*punLen-1]; + while (pCh >= pszBuf && (*pCh == '\r' || *pCh == '\n')){ + *pCh-- = '\0'; + (*punLen)--; + } +} + +void +CDavRequest::Create(OI_REQ_TYPE enuType, + const char *pszMethod, + const char *pszURI) +{ + OI_ASSERT(pszMethod); + OI_ASSERT(pszURI); + OI_ASSERT(strlen(pszURI) > 0); + + m_enuType = enuType; + m_strMethod = pszMethod; + m_strURI = pszURI; + addFixedHeaders(); + AddHandler(new CHandlerConn); + AddHandler(new CHandlerKeepAlive); + AddHandler(new CHandlerProxyConn); + AddHandler(new CHandlerServer(m_pSession)); + AddHandler(new CHandlerCType); + + OnCreate(); +} + +OI_RESULT +CDavRequest::build() +{ + OI_STRSTREAM_A ssURI, ssHostPort, ssHeaderBuf; + CDavHost& Server = m_pSession->GetHost(); + + if(m_pSession->IsUsingProxy() && + //m_pSession->IsUsingSSL() && + m_strURI[0] == '/'){ + ssURI << "http://" << Server.GetHostName() << ":"; + ssURI << Server.GetPort(); + ssURI << m_strURI; + } else { + ssURI << m_strURI; + } + + ssHostPort << Server.GetHostName() << ":"; + ssHostPort << Server.GetPort(); + + ssHeaderBuf << m_strMethod << " "; + ssHeaderBuf << Escape(AnsiToUtf8(ssURI.str())); + ssHeaderBuf << " HTTP/1.1\r\n"; + ssHeaderBuf << "Host: " << ssHostPort.str() << "\r\n"; + + if(m_bExpect100) + ssHeaderBuf << "Expect: 100-continue\r\n"; + + for(HEADITERATOR it = m_mapHeaderFields.begin(); + it != m_mapHeaderFields.end(); + it++){ + ssHeaderBuf << it->first << ": " << it->second << "\r\n"; + } + + ssHeaderBuf << "\r\n"; + m_strHeaderBuf = ssHeaderBuf.str().c_str(); + return OI_OK; +} + +OI_RESULT +CDavRequest::discard_headers() +{ + OI_RESULT enuRet; + size_t unLen = OI_GENBUFSIZE; + + CDavSocket* pSocket = m_pSession->getSocket(); + do{ + enuRet = pSocket->ReadLine(m_szBuffer, &unLen); + if(OI_OK != enuRet) return enuRet; + + unLen = OI_GENBUFSIZE; + } while(strcmp(m_szBuffer, "\r\n") != 0); + + return OI_OK; +} + +OI_RESULT +CDavRequest::discard_body(CDavResponseBody* pBody) +{ + OI_RESULT enuRet; + size_t unReadLen, unBufLen = OI_GENBUFSIZE; + for(enuRet = OI_RETRY; enuRet == OI_RETRY;){ + enuRet = pBody->Read(m_szBuffer, unBufLen, &unReadLen); + } + return enuRet; +} + +OI_RESULT +CDavRequest::read_msg_header(char* pszBuf, const size_t unLen) +{ + OI_RESULT enuRet; + size_t unBufLen = unLen; //save buffer length + size_t n = unBufLen; + CDavSocket* pSocket = m_pSession->getSocket(); + + enuRet = pSocket->ReadLine(pszBuf, &n); + if(OI_OK != enuRet ) + return enuRet; + + stripEOL(pszBuf, &n); + + if(n==0){ + // No continuation of this header: stop reading + return OI_OK; + } + + pszBuf += n; + unBufLen -= n; + + while(unBufLen > 0){ + size_t unReadLen = 1; + char ch; + enuRet = pSocket->Peek(&ch, &unReadLen); + if(OI_OK != enuRet){ + OI_ASSERT(false); + //abort... + //TODO: should be "return Abort(...)" + return OIGEUNKNOWN; + } + if (ch != ' ' && ch != '\t'){ + // No continuation of this header: stop reading. + return OI_RETRY; + } + + n = unBufLen; + // Otherwise, read the next line onto the end of 'buf'. + enuRet = pSocket->ReadLine(pszBuf, &n); + if(OI_OK != enuRet){ + //abort... + //return aborted(req, _("Error reading response headers"), n); + } + stripEOL(pszBuf, &n); + + // assert(buf[0] == ch), which implies len(buf) > 0. + // Otherwise the TCP stack is lying, but we'll be paranoid. + // This might be a \t, so replace it with a space to be + // friendly to applications (2616 says we MAY do this). + if (n){ + pszBuf[0] = ' '; + } + + // ready for the next header. + pszBuf += n; + unBufLen -= n; + } + + //response header line too long + return OIHELINETOOLONG; +} + +OI_RESULT +CDavRequest::read_resp_headers() +{ + OI_DEBUG("------------------------------\n"); + OI_RESULT enuRet; + OI_STRING_A strName, strValue; + + int nColon, nCount = 0; + char szHeader[OI_MAX_HDR_LEN]; + size_t unHeaderLen = OI_MAX_HDR_LEN; + + for( ;(enuRet = read_msg_header(szHeader, unHeaderLen)) == OI_RETRY + && ++nCount < OI_MAX_HDR_FLD ;){ + strName = szHeader; + TrimLeftA(strName); + TrimRightA(strName); + + nColon = (int)strName.find_first_of(':'); + + if(nColon < 0) + continue; + + strValue = strName.substr(nColon + 1); + strName.erase(nColon); + + TrimRightA(strName); + TrimLeftA(strValue); + + OI_DEBUG("%20s\t", strName.c_str()); + + MakeLowerA(strName); + + CResponseHeaderHandler* pHandler; + if(strName.length() > 0){ + HANDLERITERATOR it = m_mapHeaderHandlers.find(strName); + if(it != m_mapHeaderHandlers.end()){ + pHandler = it->second; + pHandler->m_strValue = strValue; + pHandler->Execute(this, strValue.c_str()); + OI_DEBUG("[handled] -- %s\n", strValue.c_str()); + } else { + bool bHandled = m_pSession->ProcessExtraHeader(this, + strName.c_str(), + strValue.c_str()); + OI_DEBUG("%s\n", bHandled ? "[handled by session]" : strValue.c_str()); + } + } + } + + if(nCount >= OI_MAX_HDR_FLD){ + return OIHETOOMANYHEADERS; + } + + OI_DEBUG("\n"); + return enuRet; +} + +OI_RESULT +CDavRequest::read_status_line(bool bRetry) +{ + OI_RESULT enuRet; + CDavSocket* pSocket = m_pSession->getSocket(); + size_t unLen = OI_GENBUFSIZE; + + enuRet = pSocket->ReadLine(m_szBuffer, &unLen); + + if(OI_OK != enuRet) + return RETRY_RET(bRetry, enuRet, enuRet); //TODO: decide the abort code + + stripEOL(m_szBuffer, &unLen); + + enuRet = m_HttpStatus.Parse(m_szBuffer); + OI_DEBUG("\tStatus: %d %s\n", m_HttpStatus.m_nCode, + m_HttpStatus.m_strReason.c_str()); + + if(OI_OK != enuRet) + return enuRet; + + return OI_OK; +} + +OI_RESULT +CDavRequest::send() +{ + OI_RESULT enuRet; + //OI_STRSTREAM_A ssCLen; + size_t unBodyLen; + bool bRetry; + + m_strHeaderBuf.erase(); + + enuRet = m_pRBProvider->Open(); + if(OI_OK == enuRet){ + m_pRBProvider->Rewind(); + unBodyLen = m_pRBProvider->GetBodyLength(); + + //ssCLen << unBodyLen; + //AddHeader("Content-Length", ssCLen.str().c_str()); + char chCLen[30]; //should be long enough for 64 bit + sprintf(chCLen, "%u", unBodyLen); + AddHeader("Content-Length", chCLen); + } else { + return enuRet; + } + + //TODO: error handling + build(); + + enuRet = connect(); + if(OI_OK != enuRet) + return enuRet; + + bRetry = m_pSession->IsPersistent(); + CDavSocket* pSocket = m_pSession->getSocket(); + pSocket->ResetBuffer(); + + size_t unWritten = (size_t)m_strHeaderBuf.length(); + + enuRet = pSocket->Write(m_strHeaderBuf.c_str(), &unWritten); + + if(OI_OK != enuRet){ + m_pRBProvider->Close(); + return RETRY_RET(bRetry, enuRet, enuRet); //TODO: decide the abort code + } + + //sending body + if(unBodyLen > 0 && !m_bExpect100){ + enuRet = send_body(m_pRBProvider); + if(OI_OK != enuRet){ + m_pRBProvider->Close(); + RETRY_RET(bRetry, enuRet, enuRet); //TODO: decide the abort code + } + } + + while((enuRet = read_status_line(bRetry)) == OI_OK + && m_HttpStatus.m_nCodeClass == 1){ + bRetry = false; + if((enuRet = discard_headers()) != OI_OK) + break; + if(m_bExpect100 && m_HttpStatus.m_nCode == 100){ + enuRet = send_body(m_pRBProvider); + if(OI_OK != enuRet) + break; + } + } + + m_pRBProvider->Close(); + + return enuRet; +} + +OI_RESULT +CDavRequest::send_body(CRequestBodyProvider* pRBProvider) +{ + OI_RESULT enuRet; + + CDavSocket* pSocket = m_pSession->getSocket(); + size_t unProgress = 0; + size_t unTotal = pRBProvider->GetBodyLength(); + size_t unReadLen = OI_GENBUFSIZE; + + pRBProvider->Rewind(); + + while((enuRet = pRBProvider->Read(this, m_szBuffer, &unReadLen)) + == OI_RETRY){ + unProgress += unReadLen; + if(! m_pSession->OnSendProgress(this, unProgress, unTotal)){ + pRBProvider->OnCancel(this); + m_pSession->OnCancelSend(this, pRBProvider); + m_pSession->Disconnect(); + return OI_USERCANCELED; + } + + enuRet = pSocket->Write(m_szBuffer, &unReadLen); + if(OI_OK != enuRet) + return enuRet; + + //restore the buffer size variable + unReadLen = OI_GENBUFSIZE; + } + + return enuRet; +} + + +OI_RESULT +CDavRequest::begin(CDavResponseBody* pBody) +{ + OI_RESULT enuRet; + int nRetry; + + m_bExpect100 = (m_pSession->IsExpecting100() + && m_pRBProvider->GetBodyLength() > 1024 //TODO: Improve this + && m_pSession->IsHttp11()); + + //m_pSession->m_nLastStatusCode = -1; + OnPreSend(); + enuRet = send(); + + for(nRetry = 0; + nRetry < OI_SOCK_MAXRETRY && enuRet == OI_RETRY + && m_pSession->IsPersistent(); + nRetry++){ + //DEBUG("Persistent connection timeout, retrying...\n") + disconnect(); + enuRet = send(); + } + + OnPostSend(); + + if((OI_RETRY == enuRet) && (nRetry >= OI_SOCK_MAXRETRY)) + return OISECLOSED; + + if(OI_OK != enuRet) + return enuRet; + + //send() called read_status_line() so the return code is now available + //check if session is HTTP 1.1 and thus can be set to persistent + if(m_HttpStatus.m_nMajorVersion > 1 || + (m_HttpStatus.m_nMajorVersion == 1 && m_HttpStatus.m_nMinorVersion > 0)){ + m_pSession->SetHttp11(true); + } else { + m_pSession->SetHttp11(false); + SetPersistent(false); + } + + m_pSession->m_nLastStatusCode = m_HttpStatus.m_nCode; + enuRet = read_resp_headers(); + if(OI_OK != enuRet) + return enuRet; + + if(m_enuType == T_REQ_CONNECT && m_HttpStatus.m_nCodeClass == 2){ + pBody->m_enuMode = M_RSP_NO_BODY; + SetPersistent(true); + } + + if(m_enuType == T_REQ_HEAD || + m_HttpStatus.m_nCode == 204 || + m_HttpStatus.m_nCode == 304){ + pBody->m_enuMode = M_RSP_NO_BODY; + } + + return OI_OK; +} + +OI_RESULT +CDavRequest::end(CDavResponseBody* pBody) +{ + OI_RESULT enuRet = OI_OK; + + if(S_CONN_CONNECTED == m_pSession->GetConnectState()) + if(M_RSP_CHUNKED == pBody->m_enuMode) + enuRet = read_resp_headers(); + + return enuRet; +} + +OI_RESULT +CDavRequest::connect() +{ + return m_pSession->Connect(this); +} + +void +CDavRequest::disconnect() +{ + m_pSession->Disconnect(); +} + +void +CDavRequest::softDisconnect() +{ + if(!m_pSession->IsPersistent()) + disconnect(); +} + +OI_RESULT +CDavRequest::Dispatch(CRequestBodyProvider* pRBProvider, + CResponseBodyConsumer* pPBConsumer) +{ + OI_RESULT enuRet; + + for(enuRet = OI_RETRY; enuRet == OI_RETRY;){ + CDavResponseBody body(this, m_pSession->getSocket()); + CDavXmlBuffer* pXmlBuffer = m_pSession->GetXmlBuffer(); + CDavMemBuffer* pMemBuffer = m_pSession->GetMemBuffer(); + m_pRBProvider = pRBProvider; + m_pPBConsumer = pPBConsumer; + + pXmlBuffer->Clear(); + pMemBuffer->Clear(); + + enuRet = begin(&body); + if(enuRet != OI_OK) + break; + /* + if(m_enuType != T_REQ_CONNECT) + { + */ + //checking content type + OI_STRING_A strHandlerName = OI_RSPHDR_CTYPE; //Content-Type + MakeLowerA(strHandlerName); + HANDLERITERATOR it = m_mapHeaderHandlers.find(strHandlerName); + OI_ASSERT(it != m_mapHeaderHandlers.end()); + CHandlerCType* pCTypeHandler; + pCTypeHandler = (CHandlerCType*)it->second; + const char* pszCType = pCTypeHandler->GetContentType(); + + //pszCType will never be NULL because it's returned from c_str() + body.m_strContentType = pszCType; + OI_STRING_A strCType = pszCType; + + //chop off tail after semicolon for later use + OI_STRING_A::size_type nSemiColon = strCType.find(';'); + if(nSemiColon != OI_STRING_A::npos) + strCType.erase(nSemiColon); + + OI_STRING_A strServer = m_strServerString; + int nStatus = m_HttpStatus.m_nCode; + CDavServerPolicy* pPolicy = m_pSession->m_pServerPolicy; + OIOPERATION opr; + + enuRet = pPolicy->CheckResponse(m_pSession, + strServer.c_str(), + m_strMethod.c_str(), + nStatus, strCType.c_str(), + &opr); + if(enuRet != OI_OK) + break; + + m_pSession->m_enuLastOperation = opr.enuOpCode; + enuRet = opr.enuErrCode; + OI_RESULT enuPullResult = OI_OK; + switch(opr.enuOpCode){ + case OP_CACHE_HTML: + { + CPBCSMMemBuffer bufWriter(this); + //?call OnPreRecv? + enuPullResult = bufWriter.PullResponseBody(&body); + //?call OnPostRecv? + if(OI_OK != enuPullResult) + enuRet = enuPullResult; + break; + } + case OP_PARSE_ERR_XML: + { + if(opr.szCutElement[0] == '\0') + strcpy(opr.szCutElement, OI_XML_CUTELEMENT); //"response" + CPBCSMXml errorConsumer(this, opr.szCutElement, pXmlBuffer); + enuPullResult = errorConsumer.PullResponseBody(&body); + if(OI_OK != enuPullResult) + enuRet = enuPullResult; + break; + } + case OP_PARSE_LOCK: + case OP_PARSE_RESPONSE: + { + CDavXmlBuffer* pXmlReceiver = m_pSession->GetXmlBuffer(); + OI_ASSERT(m_pPBConsumer->GetType() == T_PBC_XML); + if(OI_OK == m_pPBConsumer->CheckCType(strCType.c_str())){ + //TODO:open?close? + OnPreRecv(); + enuPullResult = m_pPBConsumer->PullResponseBody(&body); + OnPostRecv(); + if(OI_OK != enuPullResult) + enuRet = enuPullResult; + } else { + //TODO: decide whether to put response in xmlbuffer or + //use callback + CPBCSMXml responseConsumer(this); //default "response", NULL + OnPreRecv(); + enuPullResult = responseConsumer.PullResponseBody(&body); + OnPostRecv(); + if(OI_OK != enuPullResult) + enuRet = enuPullResult; + } + break; + } + case OP_SIMPLE_ERR: + { + enuRet = opr.enuErrCode; + break; + } + case OP_USE_DEFAULT: + { + CDavXmlBuffer* pXmlReceiver = m_pSession->GetXmlBuffer(); + if(M_RSP_NO_BODY == body.m_enuMode){ + enuPullResult = OI_OK; + break; + } + enuPullResult = m_pPBConsumer->CheckCType(strCType.c_str()); + if(OI_OK != enuPullResult){ + enuRet = enuPullResult; + enuPullResult = OI_OK; + discard_body(&body); + } else { + enuPullResult = m_pPBConsumer->Open(); + if(OI_OK != enuPullResult){ + enuRet = enuPullResult; + break; + } + + OnPreRecv(); + enuPullResult = m_pPBConsumer->PullResponseBody(&body); + OnPostRecv(); + + m_pPBConsumer->Close(); + } + break; + } + case OP_AUTHENTICATE: + { + CPBCSMMemBuffer bufWriter(this); + + //call OnPreRecv() ? + enuPullResult = bufWriter.PullResponseBody(&body); + //call OnPostRecv() ? + + if(OI_OK != enuPullResult){ + enuRet = enuPullResult; + break; + } + + enuRet = m_pSession->m_pAuthManager->QueryEndRequest(this); + break; + } + default: + OI_ASSERT(false); + discard_body(&body); + break; + } + + + if(OI_OK != enuPullResult){ + //something's wrong, disconnect immediately + disconnect(); + } else { + //do the clean up + OI_RESULT enuEndResult = end(&body); + if(OI_OK != enuEndResult){ + enuRet = enuEndResult; + break; + } + softDisconnect(); + } + //} + } + softDisconnect(); + return enuRet; +} + +void +CDavRequest::OnCreate() +{ + m_pSession->m_nLastStatusCode = -1; + m_pSession->m_pAuthManager->OnCreateRequest(this); + m_pSession->OnCreateRequest(this); +} + +void +CDavRequest::OnDestroy() +{ + m_pSession->OnDestroyRequest(this); + m_pSession->getSocket()->ResetBuffer(); +} + +void +CDavRequest::OnPreSend() +{ + m_clkLastClock = clock(); + m_pSession->m_pAuthManager->OnPreSendRequest(this); + m_pSession->OnPreSendRequest(this); +} + +void +CDavRequest::OnPostSend() +{ + m_pSession->OnPostSendRequest(this); +} + +void +CDavRequest::OnPreRecv() +{ + m_pSession->OnPreRecvResponse(this); + m_pSession->m_nMaxConnections--; +} + +void +CDavRequest::OnPostRecv() +{ + m_pSession->OnPostRecvResponse(this); + OI_DEBUG("elapsed time: %d clocks\n", clock() - m_clkLastClock); +} + +#undef RETRY_RET + Index: onion/src/DavXmlBuffer.cpp =================================================================== --- onion/src/DavXmlBuffer.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavXmlBuffer.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,177 @@ +/* + Container of XML nodes + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlBuffer.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include + +CDavXmlBuffer::CDavXmlBuffer(const char* pszDocName) +{ + OI_ASSERT(pszDocName); + m_pDoc = NULL; + m_strDocName = pszDocName; + initDocument(); +} + +CDavXmlBuffer::~CDavXmlBuffer() +{ + m_pDoc->release(); +} + +void +CDavXmlBuffer::AppendChild(XNS(DOMElement)* pElement) +{ + OI_ASSERT(m_pDoc); + if(!pElement) return; + if(pElement->getOwnerDocument() == m_pDoc) return; + + XNS(DOMElement)* pRoot = m_pDoc->getDocumentElement(); + XNS(DOMNode)* pNewNode = m_pDoc->importNode(pElement, true); + pRoot->appendChild(pNewNode); + + const XMLCh* pszPrefix = pElement->getPrefix(); //D + const XMLCh* pszNS = pElement->getNamespaceURI(); //DAV: + + OI_STRING_A strPrefix = "xmlns:"; + strPrefix += X(pszPrefix); + pRoot->setAttribute(X(strPrefix.c_str()), pszNS); +} + +void +CDavXmlBuffer::initDocument() +{ + if(m_strDocName.empty()) + m_strDocName = OI_XMLCACHE_DOCNAME; + + if(m_pDoc) + m_pDoc->release(); + XNS(DOMImplementation) *pImpl = + XNS(DOMImplementationRegistry)::getDOMImplementation(X("LS")); + + //creating the document object + m_pDoc = pImpl->createDocument(X(OI_XML_DAVNAMESPACE), + X(m_strDocName.c_str()), NULL); + + //setting default namespace mapping + XNS(DOMAttr)* pAttr = m_pDoc->createAttributeNS(X(OI_XML_NSURI), + X("xmlns:D")); + pAttr->setValue(X("DAV:")); +} + +void +CDavXmlBuffer::Clear() +{ + initDocument(); +} + +XNS(DOMDocument)* +CDavXmlBuffer::GetDocument() +{ + return m_pDoc; +} + +bool +CDavXmlBuffer::ImportDocument(XNS(DOMDocument)* pDoc) +{ + if(!pDoc || !m_pDoc) + return false; + if(pDoc == m_pDoc) + return true; + XNS(DOMElement)* pExternRoot = pDoc->getDocumentElement(); + if(!pExternRoot) + return false; + XNS(DOMElement)* pInternalRoot = m_pDoc->getDocumentElement(); + if(pInternalRoot){ + m_pDoc->removeChild(pInternalRoot); + pInternalRoot->release(); + } + pInternalRoot = (XNS(DOMElement)*)(m_pDoc->importNode(pExternRoot, true)); + m_pDoc->appendChild(pInternalRoot); + return true; + +} + +XNS(DOMNode)* +CDavXmlBuffer::ImportNode(XNS(DOMNode)*pNode) +{ + OI_ASSERT(pNode); + XNS(DOMDocument)* pDoc = pNode->getOwnerDocument(); + if(!pDoc) + return NULL; + if(pDoc == m_pDoc) + return pNode; + XNS(DOMNode)* pImported = m_pDoc->importNode(pNode, true); + return pImported; +} + +bool +CDavXmlBuffer::SaveAs(const char* pszPath) +{ + bool bRet = false; + XNS(DOMWriter)* pWriter; + XNS(LocalFileFormatTarget)* pFormatTarget; + XNS(DOMImplementation) *pImpl = + XNS(DOMImplementationRegistry)::getDOMImplementation(X("LS")); + pWriter = ((XNS(DOMImplementationLS)*)pImpl)->createDOMWriter(); + pFormatTarget = new XNS(LocalFileFormatTarget)(pszPath); + pWriter->setFeature(XNS(XMLUni)::fgDOMWRTFormatPrettyPrint, true); + pWriter->setNewLine(X("\r\n")); + bRet = pWriter->writeNode(pFormatTarget, *m_pDoc); + pWriter->release(); + delete pFormatTarget; + return bRet; +} + +bool +CDavXmlBuffer::Load(const char* pszPath) +{ + bool bRet; + if(!pszPath) + return false; + XNS(XercesDOMParser)* pParser = new XNS(XercesDOMParser); + XNS(ErrorHandler)* pErrHandler = new CDavXmlErrorHandler; + pParser->setDoNamespaces(true); + pParser->setIncludeIgnorableWhitespace(false); + pParser->setExitOnFirstFatalError(true); + pParser->setErrorHandler(pErrHandler); + + pParser->parse(pszPath); + bRet = ImportDocument(pParser->getDocument()); + + delete pParser; + delete pErrHandler; + return bRet; +} + +CDavXmlBuffer& +CDavXmlBuffer::operator=(CDavXmlBuffer& master) +{ + XNS(DOMDocument)* pDoc = master.GetDocument(); + ImportDocument(pDoc); + return *this; +} Index: onion/src/PBCSMAuthDigest.cpp =================================================================== --- onion/src/PBCSMAuthDigest.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/PBCSMAuthDigest.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,81 @@ +/* + Response body consumer in case of digest authentication + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMAuthDigest.cpp,v 1.1.1.1 2004/07/15 06:58:43 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include + +CPBCSMAuthDigest::CPBCSMAuthDigest(CDavRequest* pReq): + CResponseBodyConsumer(pReq) +{ +} + +CPBCSMAuthDigest::~CPBCSMAuthDigest() +{ +} + +void +CPBCSMAuthDigest::Close() +{ +} + +OI_RESULT +CPBCSMAuthDigest::Open() +{ + return OI_OK; +} + +OI_PBC_TYPE +CPBCSMAuthDigest::GetType() +{ + return T_PBC_DUMMY; +} + +OI_RESULT CPBCSMAuthDigest::PullResponseBody(CDavResponseBody* pBody) +{ + OI_RESULT enuRet; + size_t unReadLen, unBufLen = OI_GENBUFSIZE; + bool bCLength = (pBody->m_enuMode == M_RSP_CLENGTH); + bool bContinue; + + char* pszBuf = m_pRequest->m_szBuffer; + for(enuRet = OI_RETRY; enuRet == OI_RETRY;){ + enuRet = pBody->Read(pszBuf, unBufLen, &unReadLen); + bContinue = m_pRequest->m_pSession->OnReceiveProgress(m_pRequest, + pBody->m_unReadLen, + pBody->m_unBodyLen, + bCLength); + if(!bContinue){ + m_pRequest->disconnect(); + return OI_USERCANCELED; + } + //unReadLen = OI_GENBUFSIZE; + } + return enuRet; +} + Index: onion/src/DavAuthManager.cpp =================================================================== --- onion/src/DavAuthManager.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavAuthManager.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,141 @@ +/* + Authentication manager + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavAuthManager.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +CDavAuthManager::CDavAuthManager(CDavWorkSession* pWorkSession) +{ + OI_ASSERT(pWorkSession); + + m_pWorkSession = pWorkSession; + m_pServerAuthSession = new CDavAuthSession(this, OI_REQHDR_AUTH, + OI_RSPHDR_AUTH, + OI_RSPHDR_AUTHINFO, + 401, + C_AUTH_SERVER); + m_pProxyAuthSession = new CDavAuthSession(this, OI_REQHDR_PROXYAUTH, + OI_RSPHDR_PROXYAUTH, + OI_RSPHDR_PROXYAUTHINFO, + 407, + C_AUTH_PROXY); + Reset(); +} + +CDavAuthManager::~CDavAuthManager(void) +{ + delete m_pServerAuthSession; + delete m_pProxyAuthSession; +} + +void +CDavAuthManager::Reset() +{ + m_pServerAuthSession->Reset(); + m_pProxyAuthSession->Reset(); +} + +void +CDavAuthManager::ResetServer() +{ + m_pServerAuthSession->Reset(); +} + +void +CDavAuthManager::ResetProxy() +{ + m_pProxyAuthSession->Reset(); +} + +const char* +CDavAuthManager::GetUsername() +{ + return m_pServerAuthSession->GetUsername(); +} + +const char* +CDavAuthManager::GetPasswd() +{ + return m_pServerAuthSession->GetPasswd(); +} + +const char* +CDavAuthManager::GetProxyUsername() +{ + return m_pProxyAuthSession->GetUsername(); +} + +const char* +CDavAuthManager::GetProxyPasswd() +{ + return m_pProxyAuthSession->GetPasswd(); +} + +bool +CDavAuthManager::OnAuthentication(const char* pszRealm, + OI_STRING_A& strUsername, + OI_STRING_A& strPasswd, + int nRetry, + OI_AUTH_CLASS enuAuthClass) +{ + return m_pWorkSession->OnAuthentication(pszRealm, + strUsername, + strPasswd, + nRetry, + enuAuthClass); +} + +OI_RESULT +CDavAuthManager::OnCreateRequest(CDavRequest* pReq) +{ + m_pProxyAuthSession->OnCreateRequest(pReq); + m_pServerAuthSession->OnCreateRequest(pReq); + return OI_OK; +} + +OI_RESULT +CDavAuthManager::OnPreSendRequest(CDavRequest* pReq) +{ + m_pProxyAuthSession->OnPreSendRequest(pReq); + m_pServerAuthSession->OnPreSendRequest(pReq); + return OI_OK; +} + +OI_RESULT +CDavAuthManager::QueryEndRequest(CDavRequest* pReq) +{ + OI_RESULT enuRet; + + enuRet = m_pProxyAuthSession->QueryEndRequest(pReq); + if(OI_RETRY == enuRet) + return enuRet; + enuRet = m_pServerAuthSession->QueryEndRequest(pReq); + return enuRet; +} + + + Index: onion/src/DavResourceNode.cpp =================================================================== --- onion/src/DavResourceNode.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavResourceNode.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,838 @@ +/* + Dav resource infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavResourceNode.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +CDavResourceNode::CDavResourceNode() +{ + m_nContentLength = 0; +} + +CDavResourceNode::~CDavResourceNode() +{ +} + +void +CDavResourceNode::Reset() +{ + m_ulValidProps = 0L; + m_ulPropsToParse = OI_RNP_CONVENTIONAL; + m_enuResourceType = T_RES_NORMAL; + m_nContentLength = 0; + m_tmCreationDate = -1; + m_tmLastModified = -1; + m_lQuota = -1; + m_lQuotaUsed = -1; + m_strContentLanguage.erase(); + m_strContentType.erase(); + m_strDisplayName.erase(); + m_strETag.erase(); + m_strURI.erase(); + m_mapPropStats.clear(); + m_vecLocklist.clear(); +} + +const char* +CDavResourceNode::GetURI() +{ + return m_strURI.c_str(); +} + +OI_RES_TYPE +CDavResourceNode::GetResourceType() +{ + return m_enuResourceType; +} + +const char* +CDavResourceNode::GetDisplayName() +{ + return m_strDisplayName.c_str(); +} + +int +CDavResourceNode::GetContentLength() +{ + return m_nContentLength; +} + +time_t +CDavResourceNode::GetLastModified() +{ + return m_tmLastModified; +} + +time_t +CDavResourceNode::GetCreationDate() +{ + return m_tmCreationDate; +} + +const char* +CDavResourceNode::GetETag() +{ + return m_strETag.c_str(); +} + +const char* +CDavResourceNode::GetContentType() +{ + return m_strContentType.c_str(); +} + +const char* +CDavResourceNode::GetContentLanguage() +{ + return m_strContentLanguage.c_str(); +} + +long +CDavResourceNode::GetQuota() +{ + return m_lQuota; +} + +long +CDavResourceNode::GetQuotaUsed() +{ + return m_lQuotaUsed; +} + +unsigned long +CDavResourceNode::GetFlags() +{ + return m_ulValidProps; +} + +OI_RESULT +CDavResourceNode::Parse(XNS(DOMNode)* pResponse, unsigned long ulPropsToParse) +{ + OI_ASSERT(pResponse); + + m_ulPropsToParse = ulPropsToParse; + + if(XNS(DOMNode)::ELEMENT_NODE != pResponse->getNodeType()) + return OIRESYNTAX; //TODO: better error codes + + XNS(DOMNode) *pEnum, *pProp; + XNS(DOMNodeList) *pNodeList, *pPropNodeList; + X strDavNS(OI_XML_DAVNAMESPACE); + + //getting href + pNodeList = + ((XNS(DOMElement)*)pResponse)->getElementsByTagNameNS(strDavNS, X("href")); + if(pNodeList->getLength() < 1) + return OIREHREFNOTFOUND; + + pEnum = pNodeList->item(0); + pEnum = pEnum->getFirstChild(); + if(!pEnum) + return OIREHREFNOTFOUND; + if(XNS(DOMNode)::TEXT_NODE != pEnum->getNodeType()) + return OIREHREFNOTFOUND; + + m_strURI = Utf8ToAnsi(Unescape((const char*)X(pEnum->getNodeValue()))); + + + //getting propstat list and parse it + pNodeList = + ((XNS(DOMElement)*)pResponse)->getElementsByTagNameNS(strDavNS, X("propstat")); + int nLength = pNodeList->getLength(); + + for(int nIndex = 0; nIndex < nLength; nIndex++){ + pEnum = pNodeList->item(nIndex); + pPropNodeList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(strDavNS, X("prop")); + pProp = pPropNodeList->item(0); + + if(!pProp) + continue; + + int nStatus = getStatusCode(pEnum); + + if(nStatus == 200){ + parseProp(pProp); + removeUnprocessed(pProp, 200); + } else if(nStatus < 0) { + continue; + } else { + removeUnprocessed(pProp, nStatus); + } + + PROPSTATITERATOR it = m_mapPropStats.find(200); + if(it != m_mapPropStats.end()){ + //do we have unparsed 200 properties? + if(it->second->hasChildNodes()) + m_ulValidProps |= OI_RNP_EXTRAPROPERTIES; + } + } + + return OI_OK; +} + +XNS(DOMNode)* +CDavResourceNode::GetProp(int nStatusCode) +{ + PROPSTATITERATOR it = m_mapPropStats.find(nStatusCode); + if(it == m_mapPropStats.end()) + return NULL; + else + return it->second; +} + +int +CDavResourceNode::GetLockCount() +{ + return m_vecLocklist.size(); +} + +CDavLock* +CDavResourceNode::GetLock(unsigned int unIndex) +{ + if(unIndex >= m_vecLocklist.size()) + return NULL; + else + return &m_vecLocklist[unIndex]; +} + +int +CDavResourceNode::getStatusCode(XNS(DOMNode)* pStatus) +{ + if(!pStatus) return -1; + if(XNS(DOMNode)::ELEMENT_NODE != pStatus->getNodeType()) return -1; + + XNS(DOMNodeList)* pNodeList = + ((XNS(DOMElement)*)pStatus)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("status")); + + XNS(DOMNode)* pEnum = pNodeList->item(0); + if(!pEnum) + return -1; + if(XNS(DOMNode)::ELEMENT_NODE != pEnum->getNodeType()) + return -1; + + pEnum = pEnum->getFirstChild(); + if(!pEnum) + return -1; + if(XNS(DOMNode)::TEXT_NODE != pEnum->getNodeType()) + return -1; + OI_STRING_A strStatus = (const char*)X(pEnum->getNodeValue()); + TrimLeftA(strStatus); + TrimRightA(strStatus); + + int nMajor, nMinor, nStatus; + if(sscanf(strStatus.c_str(), + "HTTP/%d.%d %3d", + &nMajor, + &nMinor, + &nStatus) != 3) + return -1; + return nStatus; +} + +void +CDavResourceNode::parseProp(XNS(DOMNode)* pProp) +{ + if(m_ulPropsToParse & OI_RNP_RESOURCETYPE) + parseResourceType(pProp); + if(m_ulPropsToParse & OI_RNP_CONTENTLENGTH) + parseContentLength(pProp); + if(m_ulPropsToParse & OI_RNP_DISPLAYNAME) + parseDisplayName(pProp); + if(m_ulPropsToParse & OI_RNP_LASTMODIFIED) + parseLastModified(pProp); + if(m_ulPropsToParse & OI_RNP_CREATIONDATE) + parseCreationDate(pProp); + if(m_ulPropsToParse & OI_RNP_ETAG) + parseETag(pProp); + if(m_ulPropsToParse & OI_RNP_CONTENTTYPE) + parseContentType(pProp); + if(m_ulPropsToParse & OI_RNP_CONTENTLANGUAGE) + parseContentLanguage(pProp); + if(m_ulPropsToParse & OI_RNP_LOCKSUPPORTED) + parseSupportedLock(pProp); + if(m_ulPropsToParse & OI_RNP_LOCK) + parseActiveLock(pProp); + if(m_ulPropsToParse & OI_RNP_QUOTA) + parseQuota(pProp); + if(m_ulPropsToParse & OI_RNP_QUOTAUSED) + parseQuotaUsed(pProp); +} + +void +CDavResourceNode::parseResourceType(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("resourcetype")); + pEnum = pList->item(0); + if(!pEnum) + return; + + m_ulValidProps |= OI_RNP_RESOURCETYPE; + XNS(DOMNode)* pResourceType = pEnum->getFirstChild(); + if(pResourceType){ + if(XNS(DOMNode)::ELEMENT_NODE == pResourceType->getNodeType()){ + const XMLCh* pszResourceType = pResourceType->getLocalName(); + if(XNS(XMLString)::compareString(pszResourceType, X("collection")) == 0){ + m_enuResourceType = T_RES_COLLECTION; + } + } + } else { + m_enuResourceType = T_RES_NORMAL; + } + + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseContentLength(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("getcontentlength")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pContentLength = pEnum->getFirstChild(); + if(pContentLength){ + if(XNS(DOMNode)::TEXT_NODE == pContentLength->getNodeType()){ + m_nContentLength = XNS(XMLString)::parseInt(pContentLength->getNodeValue()); + m_ulValidProps |= OI_RNP_CONTENTLENGTH; + } + } + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseDisplayName(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("displayname")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pDisplayName = pEnum->getFirstChild(); + if(pDisplayName){ + if(XNS(DOMNode)::TEXT_NODE == pDisplayName->getNodeType()){ + m_strDisplayName = X(pDisplayName->getNodeValue()); + m_ulValidProps |= OI_RNP_DISPLAYNAME; + } + } + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseLastModified(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("getlastmodified")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pLastModified = pEnum->getFirstChild(); + if(pLastModified){ + if(XNS(DOMNode)::TEXT_NODE == pLastModified->getNodeType()){ + //m_tmLastModified = GmtToLocal(ParseTime(X(pLastModified->getNodeValue()))); + m_tmLastModified = ParseTime(X(pLastModified->getNodeValue())); + m_ulValidProps |= OI_RNP_LASTMODIFIED; + } + } + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseCreationDate(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("creationdate")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pCreationDate = pEnum->getFirstChild(); + if(pCreationDate){ + if(XNS(DOMNode)::TEXT_NODE == pCreationDate->getNodeType()){ + //m_tmCreationDate = GmtToLocal(ParseTimeISO8601(X(pCreationDate->getNodeValue()))); + m_tmCreationDate = ParseTimeISO8601(X(pCreationDate->getNodeValue())); + m_ulValidProps |= OI_RNP_CREATIONDATE; + } + } + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseETag(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("getetag")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pETag = pEnum->getFirstChild(); + if(pETag){ + if(XNS(DOMNode)::TEXT_NODE == pETag->getNodeType()){ + m_strETag =X(pETag->getNodeValue()); + m_ulValidProps |= OI_RNP_ETAG; + } + } + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseContentType(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("getcontenttype")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pContentType = pEnum->getFirstChild(); + if(pContentType){ + if(XNS(DOMNode)::TEXT_NODE == pContentType->getNodeType()){ + m_strContentType =X(pContentType->getNodeValue()); + m_ulValidProps |= OI_RNP_CONTENTTYPE; + } + } + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseContentLanguage(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("getcontentlanguage")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pContentLanguage = pEnum->getFirstChild(); + if(pContentLanguage){ + if(XNS(DOMNode)::TEXT_NODE == pContentLanguage->getNodeType()){ + m_strContentLanguage =X(pContentLanguage->getNodeValue()); + m_ulValidProps |= OI_RNP_CONTENTLANGUAGE; + } + } + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseSupportedLock(XNS(DOMNode)* pProp) +{ + X pszDAV(OI_XML_DAVNAMESPACE); + XNS(DOMNode)* pSupportedLock; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(pszDAV, + X("supportedlock")); + pSupportedLock = pList->item(0); + if(!pSupportedLock) + return; + + pList = + ((XNS(DOMElement)*)pSupportedLock)->getElementsByTagNameNS(pszDAV, + X("lockentry")); + int nLength = pList->getLength(); + + for(int nIndex = 0; nIndex < nLength; nIndex++){ + XNS(DOMNode)* pLockEntry = pList->item(nIndex); + XNS(DOMNodeList)* pScopeList = + ((XNS(DOMElement)*)pLockEntry)->getElementsByTagNameNS(pszDAV, + X("lockscope")); + XNS(DOMNode)* pScope = pScopeList->item(0); + if(pScope){ + XNS(DOMNodeList)* pValueList = + ((XNS(DOMElement)*)pScope)->getElementsByTagNameNS(pszDAV, X("*")); + XNS(DOMNode)* pValue = pValueList->item(0); + if(pValue){ + const XMLCh* pszScope = pValue->getLocalName(); + if(XNS(XMLString)::compareString(pszScope, X("exclusive")) == 0) + m_ulValidProps |= OI_RNP_ELOCKSUPPORTED; + else if(XNS(XMLString)::compareString(pszScope, X("shared")) == 0) + m_ulValidProps |= OI_RNP_SLOCKSUPPORTED; + } + } + } + pProp->removeChild(pSupportedLock); +} + +void +CDavResourceNode::parseActiveLock(XNS(DOMNode)* pProp) +{ + X pszDAV(OI_XML_DAVNAMESPACE); + XNS(DOMNode) *pEnum, *pLockDiscovery; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(pszDAV, X("lockdiscovery")); + pLockDiscovery = pList->item(0); + + if(!pLockDiscovery) + return; + pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(pszDAV, X("activelock")); + int nLength = pList->getLength(); + + for(int nIndex = 0; nIndex < nLength; nIndex++){ + pEnum = pList->item(nIndex); + + //getting + XNS(DOMNodeList)* pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(pszDAV, X("locktoken")); + XNS(DOMNode)* pLockProp = pLockPropList->item(0); + if(!pLockProp) + continue; + //the element + const XMLCh* pszToken; + pLockProp = pLockProp->getFirstChild(); + if(!pLockProp) + continue; + if(XNS(DOMNode)::ELEMENT_NODE != pLockProp->getNodeType()) + continue; + //the text value of + XNS(DOMNode)* pValue = pLockProp->getFirstChild(); + if(!pValue) + continue; + if(XNS(DOMNode)::TEXT_NODE != pValue->getNodeType()) + continue; + pszToken = pValue->getNodeValue(); + + //getting + OI_LOCK_SCOPE enuScope; + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(pszDAV, X("lockscope")); + pLockProp = pLockPropList->item(0); + if(!pLockProp) + continue; + pValue = pLockProp->getFirstChild(); + if(!pValue) + continue; + if(XNS(DOMNode)::ELEMENT_NODE != pValue->getNodeType()) + continue; + const XMLCh* pszScope = pValue->getLocalName(); + if(XNS(XMLString)::compareString(pszScope, X("exclusive")) == 0) + enuScope = SCP_LOCK_EXCLUSIVE; + else if(XNS(XMLString)::compareString(pszScope, X("shared")) == 0) + enuScope = SCP_LOCK_SHARED; + else + continue; + + //getting + OI_LOCK_DEPTH enuDepth; + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(pszDAV, X("depth")); + pLockProp = pLockPropList->item(0); + if(!pLockProp) + continue; + pValue = pLockProp->getFirstChild(); + if(!pValue) + continue; + if(XNS(DOMNode)::TEXT_NODE != pValue->getNodeType()) + continue; + const XMLCh* pszDepth = pValue->getNodeValue(); + if(!pszDepth) + continue; + if(XNS(XMLString)::compareString(pszDepth, X("0")) == 0) + enuDepth = D_LOCK_ZERO; + else if(XNS(XMLString)::compareString(pszDepth, X("infinity")) == 0) + //TODO: In RFC it is Infinity, investigation needed + enuDepth = D_LOCK_INFINITE; + else + continue; + + + //getting + long lTimeout; + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(pszDAV, X("timeout")); + pLockProp = pLockPropList->item(0); + if(!pLockProp) + continue; + pValue = pLockProp->getFirstChild(); + if(!pValue) + continue; + if(XNS(DOMNode)::TEXT_NODE != pValue->getNodeType()) + continue; + const XMLCh* pszTimeout = pValue->getNodeValue(); + if(!pszTimeout) + continue; + OI_STRING_A strTimeout = (const char*)X(pszTimeout); + if(1 != sscanf(strTimeout.c_str(), "Second-%ld", &lTimeout)) + //TODO: put the format into Def file + lTimeout = 0; + + //TODO: is owner node required for a valid lock object? + //getting + XNS(DOMNode)* pOwner; + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(pszDAV, X("owner")); + pOwner = pLockPropList->item(0); + + //setting the flag + unsigned int unMask = OI_LIVF_ALL; + if(!pOwner) + unMask &= ~OI_LIVF_OWNER; + + + //we have everything, construct a lock object + //and insert it into the list + CDavLock theLock; + theLock.m_strToken = X(pszToken); + theLock.m_enuType = T_LOCK_WRITE; + theLock.m_enuScope = enuScope; + theLock.m_enuDepth = enuDepth; + theLock.m_lTimeout = lTimeout; + theLock.m_pOwner = pOwner; + theLock.m_unMask = unMask; + + m_vecLocklist.push_back(theLock); + m_ulValidProps |= OI_RNP_LOCK; + } + + pProp->removeChild(pLockDiscovery); +} + +bool +CDavResourceNode::parseLockStatic(XNS(DOMNode)* pNode, CDavLock* pLock) +{ + OI_ASSERT(pNode && pLock); + + pLock->m_unMask = 0; + XNS(DOMNode)* pEnum = pNode; + + //processing element + XNS(DOMNodeList)* pLockPropList; + XNS(DOMNode)* pLockProp, *pValNode; + + //getting the element + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("locktoken")); + pLockProp = pLockPropList->item(0); + if(pLockProp){ + //getting the element + pLockProp = pLockProp->getFirstChild(); + if(pLockProp){ + if(XNS(DOMNode)::ELEMENT_NODE == pLockProp->getNodeType()){ + XNS(DOMNode)* pTextNode = pLockProp->getFirstChild(); + if(pTextNode){ + if(XNS(DOMNode)::TEXT_NODE == pTextNode->getNodeType()){ + pLock->m_strToken = X(pTextNode->getNodeValue()); + pLock->m_unMask |= OI_LIVF_TOKEN; + } + } + } + } + } + + //getting the element + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("lockscope")); + pLockProp = pLockPropList->item(0); + if(pLockProp){ + pValNode = pLockProp->getFirstChild(); + if(pValNode){ + if(XNS(DOMNode)::ELEMENT_NODE == pValNode->getNodeType()){ + const XMLCh* pszScope = X(pValNode->getLocalName()); + if(XNS(XMLString)::compareString(pszScope, X("exclusive")) == 0){ + pLock->m_enuScope = SCP_LOCK_EXCLUSIVE; + pLock->m_unMask |= OI_LIVF_SCOPE; + } else if(XNS(XMLString)::compareString(pszScope, X("shared")) == 0) { + pLock->m_enuScope = SCP_LOCK_SHARED; + pLock->m_unMask |= OI_LIVF_SCOPE; + } + } + } + } + + //getting the element + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("locktype")); + pLockProp = pLockPropList->item(0); + if(pLockProp){ + pValNode = pLockProp->getFirstChild(); + if(pValNode){ + if(XNS(DOMNode)::ELEMENT_NODE == pValNode->getNodeType()){ + const XMLCh* pszType = pValNode->getLocalName(); + if(XNS(XMLString)::compareString(pszType, X("write")) == 0){ + pLock->m_enuType = T_LOCK_WRITE; + pLock->m_unMask |= OI_LIVF_TYPE; + } + } + } + } + + //getting the element + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("depth")); + pLockProp = pLockPropList->item(0); + if(pLockProp){ + //getting the text content of the node + pValNode = pLockProp->getFirstChild(); + if(pValNode){ + if(XNS(DOMNode)::TEXT_NODE == pValNode->getNodeType()){ + const XMLCh* pszDepth = pValNode->getNodeValue(); + if(XNS(XMLString)::compareString(pszDepth, X("0")) == 0){ + pLock->m_enuDepth = D_LOCK_ZERO; + pLock->m_unMask |= OI_LIVF_DEPTH; + } else if(XNS(XMLString)::compareIString(pszDepth, X("infinity")) == 0){ + pLock->m_enuDepth = D_LOCK_INFINITE; + pLock->m_unMask |= OI_LIVF_DEPTH; + } + } + } + } + + //getting the element + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("timeout")); + pLockProp = pLockPropList->item(0); + if(pLockProp){ + //getting the text content of the node + pValNode = pLockProp->getFirstChild(); + if(pValNode){ + if(XNS(DOMNode)::TEXT_NODE == pValNode->getNodeType()){ + const XMLCh* pszTimeout = pValNode->getNodeValue(); + if(XNS(XMLString)::startsWith(pszTimeout, X("Second-"))){ + pszTimeout += XNS(XMLString)::stringLen ("Second-"); + //TODO: handle the xml NumberFormatException + pLock->m_lTimeout = atol(X(pszTimeout)); + pLock->m_unMask |= OI_LIVF_TIMEOUT; + } else if(XNS(XMLString)::compareIString(pszTimeout,X("Infinite")) == 0){ + pLock->m_lTimeout = 0; + pLock->m_unMask |= OI_LIVF_TIMEOUT; + } else { + pLock->m_lTimeout = 0; + } + } + } + } + + //getting the element, it's up to client program to parse the content + pLockPropList = + ((XNS(DOMElement)*)pEnum)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("owner")); + pLockProp = pLockPropList->item(0); + if(pLockProp) { + pLock->m_pOwner = pLockProp; + pLock->m_unMask |= OI_LIVF_OWNER; + } + + if(pLock->m_unMask & OI_LIVF_ALL) + return true; + else + return false; +} + +void +CDavResourceNode::parseQuota(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("quota-bytes")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pQuota = pEnum->getFirstChild(); + if(pQuota){ + if(XNS(DOMNode)::TEXT_NODE == pQuota->getNodeType()){ + const XMLCh* pszQuota = pQuota->getNodeValue(); + if(pszQuota){ + if(1 == sscanf(X(pszQuota), "%ld", &m_lQuota)) + m_ulValidProps |= OI_RNP_QUOTA; + } + } + } + pProp->removeChild(pEnum); +} + +void +CDavResourceNode::parseQuotaUsed(XNS(DOMNode)* pProp) +{ + XNS(DOMNode)* pEnum; + XNS(DOMNodeList)* pList = + ((XNS(DOMElement)*)pProp)->getElementsByTagNameNS(X(OI_XML_DAVNAMESPACE), + X("quota-used-bytes")); + pEnum = pList->item(0); + if(!pEnum) + return; + + XNS(DOMNode)* pQuotaUsed = pEnum->getFirstChild(); + if(pQuotaUsed){ + if(XNS(DOMNode)::TEXT_NODE == pQuotaUsed->getNodeType()){ + const XMLCh* pszQuotaUsed = pQuotaUsed->getNodeValue(); + if(pszQuotaUsed){ + if(1 == sscanf(X(pszQuotaUsed), "%ld", &m_lQuotaUsed)) + m_ulValidProps |= OI_RNP_QUOTAUSED; + } + } + } + pProp->removeChild(pEnum); +} + + +void +CDavResourceNode::removeUnprocessed(XNS(DOMNode)* pProp, int nStatus) +{ + if(!pProp) + return; + PROPSTATITERATOR it = m_mapPropStats.find(nStatus); + if(it == m_mapPropStats.end()){ + m_mapPropStats[nStatus] = pProp; + } else { + XNS(DOMNode)* pOldProp = it->second; + OI_ASSERT(pProp != pOldProp); + for(XNS(DOMNode)* pUnprocessed = pProp->getFirstChild(); + pUnprocessed; + pUnprocessed = pUnprocessed->getNextSibling()){ + pProp->removeChild(pUnprocessed); + pOldProp->appendChild(pUnprocessed); + } + } +} Index: onion/src/RBPVDLocalFile.cpp =================================================================== --- onion/src/RBPVDLocalFile.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDLocalFile.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,100 @@ +/* + Request body provider that provides body from a local file + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDLocalFile.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +#ifdef WIN32 +#include +#elif HAVE_UNISTD_H +#include +#endif /*HAVE_UNISTD_H*/ + + +CRBPVDLocalFile::CRBPVDLocalFile(int nHandle): + m_nHandle(nHandle) +{ + OI_ASSERT(nHandle); +} + +CRBPVDLocalFile::~CRBPVDLocalFile() +{ +} + +OI_RBP_TYPE +CRBPVDLocalFile::GetType() +{ + return T_RBP_FILE; +} + +void +CRBPVDLocalFile::Close() +{ +} + +OI_RESULT +CRBPVDLocalFile::Open() +{ + return OI_OK; +} + +void +CRBPVDLocalFile::OnCancel(CDavRequest* pReq) +{ +} + +size_t +CRBPVDLocalFile::GetBodyLength() +{ + struct stat st; + fstat(m_nHandle, &st); + return st.st_size; +} + +OI_RESULT +CRBPVDLocalFile::Rewind() +{ + lseek(m_nHandle, 0, SEEK_SET); + return OI_OK; +} + +OI_RESULT +CRBPVDLocalFile::Read(CDavRequest* pReq, char* pszBuf, size_t* punReadLen) +{ + size_t unReadLen = *punReadLen; //buffer length + + //TODO: IO error handling + unReadLen = read(m_nHandle, pszBuf, unReadLen); + *punReadLen = unReadLen; + + if(unReadLen > 0) + return OI_RETRY; + else + return OI_OK; +} + Index: onion/src/ResponseBodyConsumer.cpp =================================================================== --- onion/src/ResponseBodyConsumer.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/ResponseBodyConsumer.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,48 @@ +/* + Prototype of http response body consumer + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: ResponseBodyConsumer.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CResponseBodyConsumer::CResponseBodyConsumer(CDavRequest* pReq) +{ + m_pRequest = pReq; +} + +CResponseBodyConsumer::~CResponseBodyConsumer(void) +{ +} + +OI_RESULT +CResponseBodyConsumer::CheckCType(const char *pszCType) +{ + return OI_OK; +} + +void +CResponseBodyConsumer::OnCancel(CDavRequest* pReq) +{ +} Index: onion/src/HandlerConn.cpp =================================================================== --- onion/src/HandlerConn.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerConn.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,57 @@ +/* + Http header handler for "Connection" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerConn.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +CHandlerConn::CHandlerConn(void) +{ +} + +CHandlerConn::~CHandlerConn(void) +{ +} + + +bool +CHandlerConn::Execute(CDavRequest* pReq, const char *pszValue) +{ + char szClose[] = "close"; + char szKeepAlive[] = "Keep-Alive"; + if(strnicmp(pszValue, szClose, sizeof(szClose) - 1) == 0){ + pReq->SetPersistent(false); + } else if(strnicmp(pszValue, szKeepAlive, sizeof(szKeepAlive) - 1) == 0){ + pReq->SetPersistent(true); + } + return true; +} + +const char* +CHandlerConn::GetHeaderName() +{ + return OI_RSPHDR_CONN; +} + Index: onion/src/DavSSLCertificateList.cpp =================================================================== --- onion/src/DavSSLCertificateList.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavSSLCertificateList.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,74 @@ +/* + List of SSL certificates + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSSLCertificateList.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +CDavSSLCertificateList::CDavSSLCertificateList() +{ +} + +CDavSSLCertificateList::~CDavSSLCertificateList() +{ + Clear(); +} + +unsigned int +CDavSSLCertificateList::GetCount() +{ + return m_vecCertificateList.size(); +} + +void +CDavSSLCertificateList::Clear() +{ + SSLCERTITERATOR it; + for(it = m_vecCertificateList.begin(); + it != m_vecCertificateList.end(); + it++){ + delete *it; + } + m_vecCertificateList.clear(); +} + +void +CDavSSLCertificateList::AddCertificate(CDavSSLCertificate* pCert) +{ + m_vecCertificateList.push_back(pCert); +} + +CDavSSLCertificate* +CDavSSLCertificateList::GetCertificate(unsigned int unIndex) +{ + return m_vecCertificateList[unIndex]; +} + +CDavSSLCertificate* +CDavSSLCertificateList::operator [](unsigned int unIndex) +{ + return GetCertificate(unIndex); +} + Index: onion/src/DavXmlInputSource.cpp =================================================================== --- onion/src/DavXmlInputSource.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavXmlInputSource.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,47 @@ +/* + Input source needed by XML parser + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlInputSource.cpp,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +CDavXmlInputSource::CDavXmlInputSource(CDavResponseBody* pBody): + m_pBody(pBody) +{ + OI_ASSERT(m_pBody); + OI_ASSERT(M_RSP_NO_BODY != m_pBody->m_enuMode); +} + +CDavXmlInputSource::~CDavXmlInputSource() +{ +} + +XNS(BinInputStream)* +CDavXmlInputSource::makeStream() const +{ + return new CDavXmlInputStream(m_pBody); +} + Index: onion/src/PBCSMMemBuffer.cpp =================================================================== --- onion/src/PBCSMMemBuffer.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/PBCSMMemBuffer.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,88 @@ +/* + Response body consumer that writes to memory buffer + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMMemBuffer.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include + +CPBCSMMemBuffer::CPBCSMMemBuffer(CDavRequest* pReq): + CResponseBodyConsumer(pReq) +{ +} + +CPBCSMMemBuffer::~CPBCSMMemBuffer() +{ +} + +void +CPBCSMMemBuffer::Close() +{ +} + +OI_RESULT +CPBCSMMemBuffer::Open() +{ + return OI_OK; +} + +OI_PBC_TYPE +CPBCSMMemBuffer::GetType() +{ + return T_PBC_BUFFER; +} + + +OI_RESULT +CPBCSMMemBuffer::PullResponseBody(CDavResponseBody* pBody) +{ + size_t unReadLen, unBufLen = OI_GENBUFSIZE; + OI_RESULT enuRet; + bool bContinue; + + char* pszBuf = m_pRequest->m_szBuffer; //use request's internal buffer + CDavWorkSession* pSession = m_pRequest->m_pSession; + CDavMemBuffer* pMemBuffer = pSession->GetMemBuffer(); + pMemBuffer->m_strContentType = pBody->m_strContentType; + + for(enuRet = OI_RETRY; enuRet == OI_RETRY;){ + enuRet = pBody->Read(pszBuf, unBufLen, &unReadLen); + bContinue = pSession->OnReceiveProgress(m_pRequest, + pBody->m_unReadLen, + pBody->m_unBodyLen, + (pBody->m_enuMode == M_RSP_CLENGTH)); + if(!bContinue){ + //TODO: better cancel handling + pSession->Disconnect(); + return OI_USERCANCELED; + } + pMemBuffer->Write(pszBuf, unReadLen); + } + return enuRet; +} + Index: onion/src/HandlerAuth.cpp =================================================================== --- onion/src/HandlerAuth.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerAuth.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,65 @@ +/* + Http header handler for "Auth" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerAuth.cpp,v 1.1.1.1 2004/07/15 06:58:43 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include + +CHandlerAuth::CHandlerAuth(CDavRequest* pReq, CDavAuthSession* pAuthSession) +{ + OI_ASSERT(pAuthSession); + m_pAuthSession = pAuthSession; + m_pPBConsumer = NULL; +} + +CHandlerAuth::~CHandlerAuth() +{ + if(m_pPBConsumer) delete m_pPBConsumer; +} + +bool +CHandlerAuth::Execute(CDavRequest* pReq, const char *pszValue) +{ + m_pAuthSession->ParseAuthHeader(pszValue); + + if(m_pAuthSession->GetAuthScheme() == H_AUTH_BASIC){ + if(m_pPBConsumer) delete m_pPBConsumer; + m_pPBConsumer = new CPBCSMAuthBasic(pReq); + } else { + if(m_pPBConsumer) delete m_pPBConsumer; + m_pPBConsumer = new CPBCSMAuthDigest(pReq); + } + return true; +} + +const char* +CHandlerAuth::GetHeaderName() +{ + return m_pAuthSession->GetAuthHeaderName(); +} + Index: onion/src/DavSSLCertificate.cpp =================================================================== --- onion/src/DavSSLCertificate.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavSSLCertificate.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,157 @@ +/* + SSL certificate + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSSLCertificate.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CDavSSLCertificate::CDavSSLCertificate() +{ + m_pX509 = NULL; + m_ulFailures = 0L; + m_tmNotBefore = -1; + m_tmNotAfter = -1; +} + +CDavSSLCertificate::CDavSSLCertificate(X509* pX509, unsigned long ulFailures) +{ + OI_ASSERT(pX509); + m_pX509 = X509_dup(pX509); + m_ulFailures = ulFailures; +} + +CDavSSLCertificate::~CDavSSLCertificate() +{ + if(m_pX509) + X509_free(m_pX509); +} + +void +CDavSSLCertificate::Attach(X509* pX509) +{ + if(m_pX509) + X509_free(m_pX509); + m_pX509 = pX509; +} + +X509* +CDavSSLCertificate::Detach() +{ + X509* pX509 = m_pX509; + m_pX509 = NULL; + return pX509; +} + +CDavSSLCertificate& +CDavSSLCertificate::operator =(const CDavSSLCertificate& master) +{ + if(m_pX509){ + X509_free(m_pX509); + m_dnSubject.Clear(); + m_dnIssuer.Clear(); + m_tmNotBefore = -1; + m_tmNotAfter = -1; + m_ulFailures = 0; + } + + if(!master.m_pX509) + return *this; + m_pX509 = X509_dup(master.m_pX509); //X509_dup can't copy the entire cert? + m_tmNotBefore = master.m_tmNotBefore; + m_tmNotAfter = master.m_tmNotAfter; + //m_dnSubject = master.m_dnSubject; + //m_dnIssuer = master.m_dnIssuer; + m_ulFailures = master.m_ulFailures; + return *this; +} + +bool +CDavSSLCertificate::operator ==(const CDavSSLCertificate& other) +{ + if(!m_pX509 || !other.m_pX509) + return false; + else + return (X509_cmp(m_pX509, other.m_pX509) == 0); +} + +bool +CDavSSLCertificate::operator ==(const X509* pOther) +{ + if(!m_pX509 || !pOther) + return false; + else + return (X509_cmp(m_pX509, pOther) == 0); +} + +void +CDavSSLCertificate::ParseDNames() +{ + if(!m_pX509) + return; + + X509_NAME* pSubject = X509_get_subject_name(m_pX509); + X509_NAME* pIssuer = X509_get_issuer_name(m_pX509); + m_dnSubject.parseDName(pSubject); + m_dnIssuer.parseDName(pIssuer); +} + +void +CDavSSLCertificate::ParseTime() +{ + m_tmNotBefore = -1; + m_tmNotAfter = -1; + + if(!m_pX509) + return; + ASN1_TIME *pNotBefore = X509_get_notBefore(m_pX509); + ASN1_TIME *pNotAfter = X509_get_notAfter(m_pX509); + if(!pNotBefore || !pNotAfter) + return; + + OI_STRING_A strNotBefore; + OI_STRING_A strNotAfter; + asn1TimeToString(pNotBefore, strNotBefore); + asn1TimeToString(pNotAfter, strNotAfter); + + m_tmNotBefore = ParseTimeRFC2459(strNotBefore.c_str()); + m_tmNotAfter = ParseTimeRFC2459(strNotAfter.c_str()); +} + +void +CDavSSLCertificate::asn1TimeToString(ASN1_TIME* pTime, OI_STRING_A& strOut) +{ + char chBuf[64]; + BIO *pBIO; + + strncpy(chBuf, "[invalid date]", sizeof chBuf); + pBIO = BIO_new(BIO_s_mem()); + if (pBIO){ + if (ASN1_TIME_print(pBIO, pTime)) + BIO_read(pBIO, chBuf, sizeof chBuf); + BIO_free(pBIO); + } + strOut = chBuf; +} + + Index: onion/src/RBPVDXmlPropfind.cpp =================================================================== --- onion/src/RBPVDXmlPropfind.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDXmlPropfind.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,42 @@ +/* + Request body provider that provides XML for PROPFIND method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlPropfind.cpp,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CRBPVDXmlPropfind::CRBPVDXmlPropfind() +{ + XNS(DOMDocument)* pDoc = m_xbfBody.GetDocument(); + if(!pDoc ) return; + XNS(DOMElement)* pRoot = pDoc->getDocumentElement(); + XNS(DOMElement)* pProp = pDoc->createElementNS(X("DAV:"), + X("D:allprop")); + pRoot->appendChild(pProp); +} + +CRBPVDXmlPropfind::~CRBPVDXmlPropfind() +{ +} Index: onion/src/DavSSLDName.cpp =================================================================== --- onion/src/DavSSLDName.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavSSLDName.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,209 @@ +/* + Distinguish name of SSL certificates + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSSLDName.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + + +CDavSSLDName::CDavSSLDName() +{ + m_pX509Name = NULL; + m_itrCurrent = m_mapFields.begin(); +} + +CDavSSLDName::~CDavSSLDName() +{ +} + +bool +CDavSSLDName::parseDName(X509_NAME* pName) +{ + //OI_ASSERT(pName); + if(!pName) + return false; + m_mapFields.clear(); + m_pX509Name = pName; + + char chBuf[80]; + OI_STRING_A strName; + OI_STRING_A strValue; + X509_NAME_ENTRY* pEntry = NULL; + ASN1_OBJECT* pObject = NULL; + bool bDoIt[4] = {false, false, false, false}; + + int nCount = sk_X509_NAME_ENTRY_num(pName->entries); + + for(int nIndex = 0; nIndex < nCount; nIndex++){ + pEntry = sk_X509_NAME_ENTRY_value(pName->entries, nIndex); + pObject = X509_NAME_ENTRY_get_object(pEntry); + int nID = OBJ_obj2nid(pEntry->object); + + /* + if ((nID == NID_undef) || (OBJ_nid2sn(nID) == NULL)) + { + i2t_ASN1_OBJECT(chBuf, sizeof(chBuf), pEntry->object); + strName = chBuf; + } + */ + //TODO: implement more options. currently we use only the OID, + // Shortname and long name shall also be the choices + + OBJ_obj2txt(chBuf, sizeof chBuf, pObject, 1); + strName = chBuf; + + int nType = pEntry->value->type; + int nLength = pEntry->value->length; + unsigned char* pszData = pEntry->value->data; + + //setting up flags + if ((nType == V_ASN1_GENERALSTRING) && ((nLength%4) == 0)){ + for(int nByteIdx = 0; nByteIdx < nLength; nByteIdx++){ + if(pszData[nByteIdx]) + bDoIt[nByteIdx & 3] = true; + } + + if(bDoIt[0] || bDoIt[1] || bDoIt[2]){ + bDoIt[0] = true; + bDoIt[1] = true; + bDoIt[2] = true; + bDoIt[3] = true; + } else { + bDoIt[0] = false; + bDoIt[1] = false; + bDoIt[2] = false; + bDoIt[3] = true; + } + } else { + bDoIt[0] = true; + bDoIt[1] = true; + bDoIt[2] = true; + bDoIt[3] = true; + } + + strValue.erase(); + for(int nByteIdx = 0; nByteIdx < nLength; nByteIdx++) { + if(!bDoIt[nByteIdx & 3]) + continue; + unsigned char chTmp = pszData[nByteIdx]; + if(chTmp < ' ' || chTmp > '~'){ + char chTmpBuf[4]; + sprintf(chTmpBuf, "\\x%x", chTmp); + strValue += (const char*)chTmpBuf; + } else { + strValue += chTmp; + } + } + + m_mapFields[strName].AddValue(strValue.c_str()); + } + return true; +} + +unsigned int +CDavSSLDName::GetFieldCount() +{ + return m_mapFields.size(); +} + +void +CDavSSLDName::Clear() +{ + m_mapFields.clear(); +} + +const CDavSSLDNameField* +CDavSSLDName::GetField(const char* pszName) +{ + if(!pszName) + return NULL; + DNAMEFIELDITERATOR it = m_mapFields.find(pszName); + if(it != m_mapFields.end()) + return &it->second; + else + return NULL; +} + +const CDavSSLDNameField* +CDavSSLDName::GetFirstField(OI_STRING_A& strName) +{ + m_itrCurrent = m_mapFields.begin(); + if(m_itrCurrent == m_mapFields.end()){ + return NULL; + } else { + strName = m_itrCurrent->first; + return &m_itrCurrent->second; + } +} + +const CDavSSLDNameField* +CDavSSLDName::GetNextField(OI_STRING_A& strName) +{ + if(m_itrCurrent == m_mapFields.end()){ + m_itrCurrent = m_mapFields.begin(); + return NULL; + } else { + m_itrCurrent++; + if(m_itrCurrent == m_mapFields.end()){ + return NULL; + } else { + strName = m_itrCurrent->first; + return &m_itrCurrent->second; + } + } +} + +const CDavSSLDNameField* +CDavSSLDName::operator [](const char* pszName) +{ + return GetField(pszName); +} + +bool +CDavSSLDName::operator ==(const CDavSSLDName& other) +{ + if(!m_pX509Name || !other.m_pX509Name) + return false; + else + return (X509_NAME_cmp(m_pX509Name, other.m_pX509Name) == 0); +} + +bool +CDavSSLDName::operator ==(const X509_NAME* pOther) +{ + if(!m_pX509Name || !pOther) + return false; + else + return (X509_NAME_cmp(m_pX509Name, pOther) == 0); +} + +CDavSSLDName& +CDavSSLDName::operator =(const CDavSSLDName& master) +{ + m_pX509Name = master.m_pX509Name; + m_mapFields = master.m_mapFields; + m_itrCurrent = m_mapFields.begin(); + return *this; +} + Index: onion/src/HandlerServer.cpp =================================================================== --- onion/src/HandlerServer.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerServer.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,53 @@ +/* + Http header handler for "Server" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerServer.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + +CHandlerServer::CHandlerServer(CDavWorkSession* pSession) +{ + OI_ASSERT(pSession); + m_pSession = pSession; +} + +CHandlerServer::~CHandlerServer(void) +{ +} + +bool +CHandlerServer::Execute(CDavRequest* pReq, const char *pszValue) +{ + m_pSession->m_strServerString = pszValue; + return true; +} + +const char* +CHandlerServer::GetHeaderName() +{ + return OI_RSPHDR_SERVER; +} + Index: onion/src/DavSSLDNameField.cpp =================================================================== --- onion/src/DavSSLDNameField.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavSSLDNameField.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,78 @@ +/* + Field of distinguish name + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSSLDNameField.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + + +CDavSSLDNameField::CDavSSLDNameField() +{ +} + +CDavSSLDNameField::~CDavSSLDNameField() +{ +} + +void +CDavSSLDNameField::AddValue(const char* pszValue) +{ + if(pszValue) + m_vecValues.push_back(pszValue); +} + +void +CDavSSLDNameField::Clear() +{ + m_vecValues.clear(); +} + +unsigned int +CDavSSLDNameField::GetCount() +{ + return m_vecValues.size(); +} + +const char* +CDavSSLDNameField::GetValue(unsigned int unIndex) +{ + if(unIndex < m_vecValues.size()) + return m_vecValues[unIndex].c_str(); + else + return NULL; +} + +const char* +CDavSSLDNameField::operator [](unsigned int unIndex) +{ + return GetValue(unIndex); +} + +CDavSSLDNameField& +CDavSSLDNameField::operator=(const CDavSSLDNameField& master) +{ + m_vecValues = master.m_vecValues; + return *this; +} + Index: onion/src/ResponseHeaderHandler.cpp =================================================================== --- onion/src/ResponseHeaderHandler.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/ResponseHeaderHandler.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,42 @@ +/* + Prototype of http response header handler + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: ResponseHeaderHandler.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CResponseHeaderHandler::CResponseHeaderHandler(void) +{ +} + +CResponseHeaderHandler::~CResponseHeaderHandler(void) +{ +} + +bool +CResponseHeaderHandler::Execute(CDavRequest* pReq, const char *pszValue) +{ + return true; +} Index: onion/src/DavResponseBody.cpp =================================================================== --- onion/src/DavResponseBody.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavResponseBody.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,186 @@ +/* + Http response body infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavResponseBody.cpp,v 1.1.1.1 2004/07/15 06:58:47 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include + +CDavResponseBody::CDavResponseBody(CDavRequest* pReq, CDavSocket* pSocket) +{ + OI_ASSERT(pReq); + OI_ASSERT(pSocket); + + m_enuLastErr = OI_OK; + m_enuMode = M_RSP_TILLEOF; + + m_unBodyLeft = 0; + m_unBodyLen = 0; + m_unChunkLeft = 0; + m_unChunkLen = 0; + m_unReadLen = 0; + m_unChunkNo = 0; + + m_pReq = pReq; + m_pSocket = pSocket; + m_pszLocalBuf = new char[OI_LINEBUFSIZE]; + + //TE handler and CLength handler are related to response body + m_pReq->AddHandler(new CHandlerTE(this)); + m_pReq->AddHandler(new CHandlerCLength(this)); +} + +CDavResponseBody::~CDavResponseBody() +{ + delete[] m_pszLocalBuf; +} + +#define OI_TERMINATE_READ(enuRet) {m_enuLastErr = enuRet;return enuRet;} + +OI_RESULT CDavResponseBody::Read(char* pszBuf, + size_t unBufLen, + size_t* punReadLen) +{ + OI_RESULT enuRet; + size_t unReadLen; + size_t unWillRead; + + switch(m_enuMode){ + case M_RSP_CHUNKED: + if(m_unChunkLeft == 0){ + size_t unChunkLen; + char* pchPos = 0; + unReadLen = OI_LINEBUFSIZE; + enuRet = m_pSocket->ReadLine(m_pszLocalBuf, &unReadLen); + if(OI_OK != enuRet){ + OI_TERMINATE_READ(enuRet); + } + if(unReadLen >= 11){ + OI_TERMINATE_READ(OIHECHUNKSIZE); + } + unChunkLen = strtoul(m_pszLocalBuf, &pchPos, 16); + if(pchPos == m_pszLocalBuf || unChunkLen == ULONG_MAX){ + OI_TERMINATE_READ(OIHECHUNKSIZE); + } + if(unChunkLen == 0){ + //end of body reached + if(punReadLen) + *punReadLen = 0; + return OI_OK; + } + m_unChunkLeft = unChunkLen; + } + unWillRead = m_unChunkLeft; + break; + case M_RSP_CLENGTH: + unWillRead = m_unBodyLeft; + break; + case M_RSP_TILLEOF: + unWillRead = unBufLen; + break; + case M_RSP_NO_BODY: + default: + unWillRead = 0; + break; + } + + if(unWillRead > unBufLen){ + unWillRead = unBufLen; + } else if(unWillRead == 0) { + if(punReadLen) + *punReadLen = 0; + return OI_OK; + } + + unReadLen = unWillRead; + enuRet = m_pSocket->Read(pszBuf, &unReadLen); + + if((m_enuMode == M_RSP_TILLEOF) && + ((enuRet == OISECLOSED) || + ((enuRet == OISETRUNC) && (m_unBodyLen == 0)))){ + m_pReq->SetPersistent(false); + unReadLen = 0; + if(punReadLen) + *punReadLen = 0; + return OI_OK; + } else if(OI_OK != enuRet) { + OI_TERMINATE_READ(enuRet); + } else { + //read successful + } + + if(punReadLen) + *punReadLen = unReadLen; + m_unReadLen += unReadLen; + + if(m_enuMode == M_RSP_CHUNKED){ + m_unChunkLeft -= unReadLen; + if(m_unChunkLeft == 0){ + //check if chunk is ended with CRLF + unReadLen = 2; + enuRet = m_pSocket->FullRead(m_pszLocalBuf, &unReadLen); + if(OI_OK != enuRet) + OI_TERMINATE_READ(enuRet); + + if(strncmp(m_pszLocalBuf, "\r\n", 2) != 0) + OI_TERMINATE_READ(OIHEPROTOCOLPANIC); + } + } else if(m_enuMode == M_RSP_CLENGTH) { + m_unBodyLeft -= unReadLen; + } + + return OI_RETRY; +} +#undef OI_TERMINATE_READ + +size_t CDavResponseBody::Read(unsigned char* toFill, size_t maxToRead) +{ + size_t unReadLen; + OI_RESULT enuRet; + + bool bContinue = + m_pReq->m_pSession->OnReceiveProgress(m_pReq, + m_unReadLen, + m_unBodyLen, + (m_enuMode==M_RSP_CLENGTH)); + + if(!bContinue){ + //TODO: better cancel handling + m_enuLastErr = OI_USERCANCELED; + m_pReq->disconnect(); + return 0; + } + + enuRet = this->Read((char*)toFill, maxToRead, &unReadLen); + if(OI_RETRY != enuRet){ + m_enuLastErr = enuRet; + return 0; + } else { + return unReadLen; + } +} Index: onion/src/RBPVDXmlLock.cpp =================================================================== --- onion/src/RBPVDXmlLock.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDXmlLock.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,97 @@ +/* + Request body provider that provides XML for LOCK method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlLock.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +CRBPVDXmlLock::CRBPVDXmlLock(CDavLock* pLock): + CRBPVDXml(OI_XML_LOCKDOCNAME) +{ + OI_ASSERT(pLock); + OI_STRING_A strType; + OI_STRING_A strScope; + + switch(pLock->m_enuType){ + case T_LOCK_WRITE: + default: + strType = "D:write"; + } + + switch(pLock->m_enuScope){ + case SCP_LOCK_SHARED: + strScope = "D:shared"; + break; + case SCP_LOCK_EXCLUSIVE: + default: + strScope = "D:exclusive"; + break; + } + + X strDavNS(OI_XML_DAVNAMESPACE); + const XMLCh* pszDavNS = strDavNS; + + XNS(DOMDocument)* pDoc = m_xbfBody.GetDocument(); + + //TODO: put the hard coded element names into def? + XNS(DOMElement)* pRoot = pDoc->getDocumentElement(); + //DAV:lockscope + XNS(DOMElement)* pScope = pDoc->createElementNS(pszDavNS, + X("D:lockscope")); + pRoot->appendChild(pScope); + XNS(DOMElement)* pScopeVal = pDoc->createElementNS(pszDavNS, + X(strScope.c_str())); + pScope->appendChild(pScopeVal); + //DAV:lockscope + XNS(DOMElement)* pType = pDoc->createElementNS(pszDavNS, + X("D:locktype")); + pRoot->appendChild(pType); + XNS(DOMElement)* pTypeVal = pDoc->createElementNS(pszDavNS, + X(strType.c_str())); + pType->appendChild(pTypeVal); + //DAV:owner + XNS(DOMElement)* pOwner = pDoc->createElementNS(pszDavNS, + X("D:owner")); + pRoot->appendChild(pOwner); + if(pLock->m_pOwner){ + XNS(DOMNode)* pOwnerVal; + OI_ASSERT(pDoc != pLock->m_pOwner->getOwnerDocument()); + //this is not likely to happen + pOwnerVal = pDoc->importNode(pLock->m_pOwner, true); + pOwner->appendChild(pOwnerVal); + } else { + //default owner node + XNS(DOMNode)* pOwnerDefault = pDoc->createElementNS(pszDavNS, + X("D:href")); + pOwner->appendChild(pOwnerDefault); + XNS(DOMNode)* pOwnerTxt = pDoc->createTextNode(X(OI_XML_DEFAULTLOCKOWNER)); + pOwnerDefault->appendChild(pOwnerTxt); + } +} + +CRBPVDXmlLock::~CRBPVDXmlLock() +{ +} Index: onion/src/HandlerDAV.cpp =================================================================== --- onion/src/HandlerDAV.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerDAV.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Http header handler for "DAV" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerDAV.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CHandlerDAV::CHandlerDAV() +{ +} + +CHandlerDAV::~CHandlerDAV() +{ +} + +bool +CHandlerDAV::Execute(CDavRequest* pReq, const char *pszValue) +{ + m_strDAV += pszValue; + m_strDAV += "\n"; + return true; +} + +const char* +CHandlerDAV::GetHeaderName() +{ + return OI_RSPHDR_DAV; +} Index: onion/src/DavXmlParser.cpp =================================================================== --- onion/src/DavXmlParser.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavXmlParser.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,89 @@ +/* + SAX-DOM hybrid mode XML parser + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlParser.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +CDavXmlParser::CDavXmlParser(CPBCSMXml* pConsumer, const char* pszCutElement): + m_pConsumer(pConsumer) +{ + OI_ASSERT(pConsumer); + if(pszCutElement) + m_strCutElement = pszCutElement; +} + +CDavXmlParser::~CDavXmlParser() +{ +} + + +void +CDavXmlParser::endElement(const XNS(XMLElementDecl) &elemDecl, + const unsigned int urlId, + const bool isRoot, + const XMLCh *const elemPrefix) +{ + AbstractDOMParser::endElement(elemDecl, urlId, isRoot,elemPrefix); + if(m_strCutElement.empty()) return; + if(! m_strCutElement.compare(X(elemDecl.getBaseName()))){ + XNS(DOMNode)* pNode = getCurrentNode(); + //TODO: for performance's sake, do a test to see which one is faster + const XMLCh* pszNS =pNode->lookupNamespaceURI(elemPrefix); + //OI_STRING_A strNS = X(pNode->lookupNamespaceURI(elemPrefix)); + //check the namespace uri to make sure it's a dav response + //if(! strNS.compare("DAV:")) + if(XNS(XMLString)::compareString(pszNS, X("DAV:")) == 0){ + m_pConsumer->OnResponseFound(pNode); + pNode->getParentNode()->removeChild(pNode); + pNode->release(); + } + } +} + +void +CDavXmlParser::error(const unsigned int errCode, + const XMLCh *const errDomain, + const ErrTypes type, + const XMLCh *const errorText, + const XMLCh *const systemId, + const XMLCh *const publicId, + const XMLSSize_t lineNum, + const XMLSSize_t colNum) +{ + int nCode = errCode; +} + +void +CDavXmlParser::docCharacters(const XMLCh *const chars, + const unsigned int length, + const bool cdataSection) +{ + if(!XNS(XMLString)::isAllWhiteSpace(chars)){ + AbstractDOMParser::docCharacters(chars, + length, + cdataSection); + } +} Index: onion/src/DavHost.cpp =================================================================== --- onion/src/DavHost.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavHost.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,88 @@ +/* + Host infomation wrapper + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavHost.cpp,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CDavHost::CDavHost() +{ + m_usPort = 0; +} + +CDavHost::CDavHost(const char *pszName, unsigned short usPort) +{ + OI_ASSERT(pszName); + m_strHostName = pszName; + m_usPort = usPort; +} + +CDavHost::CDavHost(const CDavHost& old) +{ + copy(old); +} + +CDavHost::~CDavHost(void) +{ +} + +const char* +CDavHost::GetHostName() +{ + return m_strHostName.c_str(); +} + +unsigned short +CDavHost::GetPort() +{ + return m_usPort; +} + +void +CDavHost::SetHostName(const char *pszName) +{ + OI_ASSERT(pszName); + m_strHostName = pszName; +} + +void +CDavHost::SetPort(unsigned short usPort) +{ + m_usPort = usPort; +} + +void +CDavHost::copy(const CDavHost& old) +{ + m_strHostName = old.m_strHostName; + m_usPort = old.m_usPort; +} + +CDavHost& +CDavHost::operator =(const CDavHost& old) +{ + copy(old); + return *this; +} + Index: onion/src/config_unix.h =================================================================== --- onion/src/config_unix.h (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/config_unix.h (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,163 @@ +/* src/onion/config.h. Generated by configure. */ +/* src/onion/config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `alarm' function. */ +#define HAVE_ALARM 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ +/* #undef HAVE_DOPRNT */ + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `gethostbyname' function. */ +#define HAVE_GETHOSTBYNAME 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ +#define HAVE_MALLOC 1 + +/* Define to 1 if you have the `memchr' function. */ +#define HAVE_MEMCHR 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if your system has a GNU libc compatible `realloc' function, + and to 0 otherwise. */ +#define HAVE_REALLOC 1 + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the `socket' function. */ +#define HAVE_SOCKET 1 + +/* Define to 1 if stdbool.h conforms to C99. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strstr' function. */ +#define HAVE_STRSTR 1 + +/* Define to 1 if you have the `strtol' function. */ +#define HAVE_STRTOL 1 + +/* Define to 1 if you have the `strtoul' function. */ +#define HAVE_STRTOUL 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `vprintf' function. */ +#define HAVE_VPRINTF 1 + +/* Define to 1 if the system has the type `_Bool'. */ +#define HAVE__BOOL 1 + +/* Name of package */ +#define PACKAGE "onion" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "sledge10@hotmail.com" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "onion" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "onion 0.2.0" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "onion" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.2.0" + +/* Define to the type of arg 1 for `select'. */ +#define SELECT_TYPE_ARG1 int + +/* Define to the type of args 2, 3 and 4 for `select'. */ +#define SELECT_TYPE_ARG234 (fd_set *) + +/* Define to the type of arg 5 for `select'. */ +#define SELECT_TYPE_ARG5 (struct timeval *) + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both and . */ +#define TIME_WITH_SYS_TIME 1 + +/* Define to 1 if your declares `struct tm'. */ +/* #undef TM_IN_SYS_TIME */ + +/* Version number of package */ +#define VERSION "0.2.0" + +/* byte order */ +/* #undef WORDS_BIGENDIAN */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to rpl_malloc if the replacement function should be used. */ +/* #undef malloc */ + +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define to rpl_realloc if the replacement function should be used. */ +/* #undef realloc */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ Index: onion/src/DavHttpStatus.cpp =================================================================== --- onion/src/DavHttpStatus.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavHttpStatus.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,105 @@ +/* + Http status line infomation container + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavHttpStatus.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CDavHttpStatus::CDavHttpStatus() +{ + m_nCode = 0; + m_nCodeClass = 0; + m_nMajorVersion = 0; + m_nMinorVersion = 0; + +} + +CDavHttpStatus::~CDavHttpStatus() +{ +} + +OI_RESULT +CDavHttpStatus::Parse(const char* pszBuf) +{ + OI_ASSERT(pszBuf); + + int nMajor, nMinor; + char* pszPart; + pszBuf = strstr(pszBuf, "HTTP/"); + if(0 == pszBuf) + //server is not talking back in HTTP protocol + return OIHEPROTOCOLPANIC; + + //check nMajor and nMinor version of HTTP protocol + nMajor = 0; + nMinor = 0; + + //extract nMajor version number + for(pszPart = (char*)(pszBuf + 5); + *pszPart != '\0' && isdigit(*pszPart); + pszPart++){ + nMajor = nMajor*10 + (*pszPart - '0'); + } + + //now the pszPart pointer should stop exactly at '.' + if(*pszPart != '.') + return OIHEPROTOCOLPANIC; + + //extract monir version number + for(pszPart++; + *pszPart != '\0' && isdigit(*pszPart); + pszPart++){ + nMinor = nMinor*10 + (*pszPart - '0'); + } + + //now the pszPart pointer should stop exactly at ' ' + if(*pszPart != ' ') + return OIHEPROTOCOLPANIC; + + //skip any spaces + for(; *pszPart == ' '; pszPart++); + + //now the pointer should be pointing exactly at the status code + if(strlen(pszPart) < 4) + return OIHEPROTOCOLPANIC; + + if( !isdigit(pszPart[0]) || + !isdigit(pszPart[1]) || + !isdigit(pszPart[2]) || + (pszPart[3] != '\0' && pszPart[3] != ' ')){ + return OIHEPROTOCOLPANIC; + } + + m_nCode = 100*(pszPart[0]-'0') + 10*(pszPart[1]-'0') + (pszPart[2]-'0'); + m_nCodeClass = pszPart[0]-'0'; + m_nMajorVersion = nMajor; + m_nMinorVersion = nMinor; + + //skip white spaces before reason phrases + for (pszPart+=3; *pszPart == ' ' || *pszPart == '\t'; pszPart++); + + m_strReason = pszPart; + return OI_OK; +} + Index: onion/src/PBCSMDummy.cpp =================================================================== --- onion/src/PBCSMDummy.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/PBCSMDummy.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,81 @@ +/* + Response body consumer which bypasses all data + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMDummy.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include + +CPBCSMDummy::CPBCSMDummy(CDavRequest* pReq): + CResponseBodyConsumer(pReq) +{ +} + +CPBCSMDummy::~CPBCSMDummy() +{ +} + +void +CPBCSMDummy::Close() +{ +} + +OI_RESULT +CPBCSMDummy::Open() +{ + return OI_OK; +} + +OI_PBC_TYPE +CPBCSMDummy::GetType() +{ + return T_PBC_DUMMY; +} + +OI_RESULT +CPBCSMDummy::PullResponseBody(CDavResponseBody* pBody) +{ + OI_RESULT enuRet; + size_t unReadLen, unBufLen = OI_GENBUFSIZE; + bool bCLength = (pBody->m_enuMode == M_RSP_CLENGTH); + bool bContinue; + + char* pszBuf = m_pRequest->m_szBuffer; + for(enuRet = OI_RETRY; enuRet == OI_RETRY;){ + enuRet = pBody->Read(pszBuf, unBufLen, &unReadLen); + bContinue = m_pRequest->m_pSession->OnReceiveProgress(m_pRequest, + pBody->m_unReadLen, + pBody->m_unBodyLen, + bCLength); + if(!bContinue){ + m_pRequest->disconnect(); + return OI_USERCANCELED; + } + //unReadLen = OI_GENBUFSIZE; + } + return enuRet; +} Index: onion/src/HandlerDASL.cpp =================================================================== --- onion/src/HandlerDASL.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerDASL.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,49 @@ +/* + Http header handler for "DASL" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerDASL.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CHandlerDASL::CHandlerDASL() +{ +} + +CHandlerDASL::~CHandlerDASL() +{ +} + +bool +CHandlerDASL::Execute(CDavRequest* pReq, const char *pszValue) +{ + m_strDASL += pszValue; + m_strDASL += "\n"; + return true; +} + +const char* +CHandlerDASL::GetHeaderName() +{ + return OI_RSPHDR_DASL; +} Index: onion/src/DavWorkSession.cpp =================================================================== --- onion/src/DavWorkSession.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavWorkSession.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,849 @@ +/* + Dav session handler + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavWorkSession.cpp,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +#include +#elif HAVE_UNISTD_H +#include +#endif /*HAVE_UNISTD_H*/ + +CDavWorkSession::CDavWorkSession(void) +{ + init(); +} + +CDavWorkSession::~CDavWorkSession(void) +{ + delete m_pSocket; + delete m_pAuthManager; + delete m_pXmlBuffer; + delete m_pMemBuffer; + delete m_pServerPolicy; + delete m_pUnauthenticCerts; +} + +bool +CDavWorkSession::IsExpecting100() +{ + return m_bExpect100; +} + +bool +CDavWorkSession::IsPersistent() +{ + return m_bPersistent; +} + +bool +CDavWorkSession::IsHttp11() +{ + return m_bHttp11; +} + +bool +CDavWorkSession::IsUsingSSL() +{ + return m_bUseSSL; +} + +bool +CDavWorkSession::IsUsingProxy() +{ + return m_bUseProxy; +} + +const char* +CDavWorkSession::GetServerString() +{ + return m_strServerString.c_str(); +} + +void +CDavWorkSession::SetExpecting100(bool bValue) +{ + m_bExpect100 = bValue; +} + +void +CDavWorkSession::SetPersistent(bool bValue) +{ + m_bPersistent = bValue; +} + +void +CDavWorkSession::SetHttp11(bool bValue) +{ + m_bHttp11 = bValue; +} + +void +CDavWorkSession::SetUseSSL(bool bValue) +{ + m_bUseSSL = bValue; +} + +void +CDavWorkSession::SetUseProxy(bool bValue) +{ + m_bUseProxy = bValue; +} + +void +CDavWorkSession::Disconnect() +{ + if(m_enuConnState != S_CONN_DISCONNECTED){ + m_pSocket->Disconnect(); + m_enuConnState = S_CONN_DISCONNECTED; + } + m_tmConnectionTTL = -1; + m_nMaxConnections = -1; + OI_DEBUG("Disconnected\n"); +} + +OI_CONN_STATE +CDavWorkSession::GetConnectState() +{ + return m_enuConnState; +} + +bool +CDavWorkSession::OnAuthentication(const char* pszRealm, + OI_STRING_A& strUsername, + OI_STRING_A& strPasswd, + int nRetry, + OI_AUTH_CLASS enuAuthClass) +{ + return true; +} + +void +CDavWorkSession::OnCancelSend(CDavRequest* pReq, + CRequestBodyProvider* pRBProvider) +{ +} + +void +CDavWorkSession::OnCancelReceive(CDavRequest* pReq, + CResponseBodyConsumer* pPBConsumer) +{ +} + +void +CDavWorkSession::OnCreateRequest(CDavRequest* pReq) +{ +} + +void +CDavWorkSession::OnPreSendRequest(CDavRequest* pReq) +{ +} + +void +CDavWorkSession::OnPostSendRequest(CDavRequest* pReq) +{ +} + +void +CDavWorkSession::OnPreRecvResponse(CDavRequest* pReq) +{ +} + +void +CDavWorkSession::OnPostRecvResponse(CDavRequest* pReq) +{ +} + +void +CDavWorkSession::OnDestroyRequest(CDavRequest* pReq) +{ +} + +bool +CDavWorkSession::ProcessExtraHeader(CDavRequest* pReq, + const char* pszName, + const char* pszValue) +{ + return false; +} + +bool +CDavWorkSession::MatchServerString(const char* pszHeaderValue, + const char* pszConfigValue) +{ + return (strcmp(pszHeaderValue, pszConfigValue) == 0); +} + + +bool +CDavWorkSession::OnSendProgress(CDavRequest* pReq, + size_t unProgress, + size_t unTotal) +{ + return true; +} + +bool +CDavWorkSession::OnReceiveProgress(CDavRequest* pReq, + size_t unProgress, + size_t unTotal, + bool bCLength) +{ + return true; +} + +void +CDavWorkSession::OnResourceFound(CDavResourceNode* pNode) +{ +} + +void +CDavWorkSession::OnSearchResponse(XNS(DOMNode)* pNode) +{ +} + +//SSL callbacks +bool +CDavWorkSession::OnVerifyCertificates(CDavSSLCertificateList* pUnauthenticCerts) +{ + return false; +} + +CDavSocket* +CDavWorkSession::getSocket() +{ + return m_pSocket; +} + +OI_RESULT +CDavWorkSession::Connect(CDavRequest* pReq) +{ + OI_RESULT enuRet; + OI_REQ_TYPE enuMethod = pReq->GetMethod(); + + //handle Keep-Alive values + time_t tmExpiresOn = m_tmConnectionTTL; + if(tmExpiresOn != -1){ + time_t tmNow = time(NULL); + //hard coded value + if(tmNow -1 > tmExpiresOn){ + OI_DEBUG("Connection expired, disconnecting...\n"); + Disconnect(); + } + } + int nMaxConn = m_nMaxConnections; + if(nMaxConn == 0){ + OI_DEBUG("Max connect reached, will disconnect after this request\n"); + SetPersistent(false); + } + + //connect + if(m_bUseProxy){ + switch(m_enuConnState){ + case S_CONN_DISCONNECTED: + enuRet = m_pSocket->Connect(m_Proxy.GetHostName(), + m_Proxy.GetPort()); + if(OI_OK != enuRet) return enuRet; + m_enuConnState = S_CONN_CONNECTED; + //falling through + case S_CONN_CONNECTED: + if(m_bUseSSL && (enuMethod != T_REQ_CONNECT)){ + enuRet = proxyTunnel(); + if(OI_OK != enuRet){ + m_pSocket->Disconnect(); + return enuRet; + } + enuRet = negotiateSSL(); + if(OI_OK != enuRet){ + m_pSocket->Disconnect(); + return enuRet; + } + m_enuConnState = S_CONN_TUNNELED; + } + break; + default: + break; + } + } else { + switch(m_enuConnState){ + case S_CONN_DISCONNECTED: + enuRet = m_pSocket->Connect(m_Server.GetHostName(), + m_Server.GetPort()); + if(OI_OK != enuRet) + return enuRet; + if(m_bUseSSL){ + enuRet = negotiateSSL(); + if(OI_OK != enuRet){ + m_pSocket->Disconnect(); + return enuRet; + } + } + m_enuConnState = S_CONN_CONNECTED; + break; + default: + break; + } + } + return OI_OK; +} + +void +CDavWorkSession::init() +{ + m_bExpect100 = false; + m_bHttp11 = true; + m_bPassiveMode = false; + m_bPersistent = true; + m_bUseSSL = false; + m_bUseProxy = false; + m_tmConnectionTTL = -1; + m_nMaxConnections = -1; + m_enuConnState = S_CONN_DISCONNECTED; + m_enuLastOperation = OP_USE_DEFAULT; + + m_pSocket = new CDavSocket(this); + m_pAuthManager = new CDavAuthManager(this); + m_pXmlBuffer = new CDavXmlBuffer; + m_pMemBuffer = new CDavMemBuffer; + m_pServerPolicy = new CDavServerPolicy; + m_pUnauthenticCerts = new CDavSSLCertificateList(); + m_pCurrentLock = NULL; +} + + +OI_RESULT +CDavWorkSession::proxyTunnel() +{ + bool bUseSSL = m_pSocket->UseSSL(false); + OI_RESULT enuRet; + OI_STRSTREAM_A ssURI; + CDavRequest reqConnect(this); + CRBPVDDummy pvdDummy; + CPBCSMDummy csmDummy(&reqConnect); + + ssURI << m_Server.GetHostName() << ":" << m_Server.GetPort(); + reqConnect.Create(T_REQ_CONNECT, OI_METHOD_CONNECT, ssURI.str().c_str()); + + enuRet = reqConnect.Dispatch(&pvdDummy, &csmDummy); + if(OI_OK != enuRet || reqConnect.GetStatusClass() != 2){ + m_pSocket->UseSSL(bUseSSL); + return OIEETUNNELFAILED; + } + m_pSocket->UseSSL(true); + return enuRet; +} + +OI_RESULT +CDavWorkSession::negotiateSSL() +{ + OI_RESULT enuRet = m_pSocket->connectSSL(); + if(OI_OK != enuRet) + return enuRet; + + if(m_pUnauthenticCerts->GetCount() > 0){ + if(!OnVerifyCertificates(m_pUnauthenticCerts)){ + m_pSocket->cleanupSSL(); + m_pSocket->cleanupSSLSession(); + return OIEECERTCHECKFAILED; + } + } + return OI_OK; +} + +size_t +CDavWorkSession::GetReadBytes() +{ + return m_pSocket->GetReadBytes(); +} + +size_t +CDavWorkSession::GetWrittenBytes() +{ + return m_pSocket->GetWrittenBytes(); +} + +CDavXmlBuffer* +CDavWorkSession::GetXmlBuffer() +{ + return m_pXmlBuffer; +} + +CDavMemBuffer* +CDavWorkSession::GetMemBuffer() +{ + return m_pMemBuffer; +} + +CDavSSLCertificateList* +CDavWorkSession::GetUnauthenticCertificates() +{ + return m_pUnauthenticCerts; +} + +void +CDavWorkSession::OnResponseFound(CDavRequest* pReq, XNS(DOMNode) *pNode) +{ + //TODO:Implement this + switch(pReq->GetMethod()){ + case T_REQ_PROPFIND: + { + CDavResourceNode theNode; + theNode.Parse(pNode); + OnResourceFound(&theNode); + break; + } + case T_REQ_LOCK: + { + OI_ASSERT(m_pCurrentLock); + CDavResourceNode::parseLockStatic(pNode, m_pCurrentLock); + break; + } + case T_REQ_SEARCH: + { + OnSearchResponse(pNode); + } + default: + OI_ASSERT(false); + break; + } +} + + +OI_RESULT +CDavWorkSession::DoPropfind(const char* pszURI, OI_PFIND_DEPTH enuDepth) +{ + OI_DEBUG("Starting PROPFIND on <%s>...\n", pszURI); + OI_RESULT enuRet; + const char* pszDepth; + + switch(enuDepth){ + case D_PFIND_ZERO: + pszDepth = "0"; + break; + case D_PFIND_INFINITE: + pszDepth = "infinity"; + break; + case D_PFIND_ONE: + default: + pszDepth = "1"; + break; + } + CDavRequest reqPropfind(this); + CPBCSMXml csmXml(&reqPropfind, OI_XML_CUTELEMENT); + CRBPVDXmlPropfind pvdXmlPropfind; + //TODO: implement more versions of this function + reqPropfind.AddHeader(OI_REQHDR_DEPTH, pszDepth); + reqPropfind.AddHeader(OI_REQHDR_CONTENTTYPE, "text/xml"); + reqPropfind.Create(T_REQ_PROPFIND, OI_METHOD_PROPFIND, pszURI); + enuRet = reqPropfind.Dispatch(&pvdXmlPropfind, &csmXml); + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoCopy(const char* pszSrc, + const char* pszDest, + CRBPVDXmlCopy* pXml, + bool bOverwrite, + const char* pszIfHeader) +{ + OI_DEBUG("Starting COPY from <%s> to <%s>...\n", pszSrc, pszDest); + OI_RESULT enuRet; + CDavRequest reqCopy(this); + CRBPVDDummy pvdDummy; + CRequestBodyProvider* pBodyProvider = &pvdDummy; + CPBCSMDummy csmDummy(&reqCopy); + OI_STRING_A strDest = Escape(AnsiToUtf8(pszDest)); + OI_STRING_A strOverwrite = bOverwrite ? "T" : "F"; + reqCopy.Create(T_REQ_COPY, OI_METHOD_COPY, pszSrc); + reqCopy.AddHeader(OI_REQHDR_DESTINATION, strDest.c_str()); + reqCopy.AddHeader(OI_REQHDR_OVERWRITE, strOverwrite.c_str()); + if(pXml){ + pBodyProvider = pXml; + reqCopy.AddHeader(OI_REQHDR_CONTENTTYPE, "application/xml"); + } + + if(pszIfHeader) + reqCopy.AddHeader(OI_REQHDR_IF, pszIfHeader); + + enuRet = reqCopy.Dispatch(pBodyProvider, &csmDummy); + return enuRet; + +} + +OI_RESULT +CDavWorkSession::DoDelete(const char* pszURI, + const char* pszIfHeader) +{ + OI_DEBUG("Starting DELETE at <%s>...\n", pszURI); + OI_RESULT enuRet; + CDavRequest reqDelete(this); + CRBPVDDummy pvdDummy; + CPBCSMDummy csmDummy(&reqDelete); + reqDelete.Create(T_REQ_DELETE, OI_METHOD_DELETE, pszURI); + + if(pszIfHeader) + reqDelete.AddHeader(OI_REQHDR_IF, pszIfHeader); + + enuRet = reqDelete.Dispatch(&pvdDummy, &csmDummy); + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoGet(const char* pszURI, + const char* pszLocalPath) +{ + OI_DEBUG("Starting GET on <%s>...\n", pszURI); + OI_RESULT enuRet; + int nFlags = O_WRONLY | O_CREAT | O_TRUNC; +#ifdef WIN32 + nFlags |= O_BINARY; +#endif /* WIN32 */ + + CDavRequest reqGet(this); + int nHandle = open(pszLocalPath, nFlags); + CRBPVDDummy pvdDummy; + CPBCSMLocalFile csmFile(&reqGet, nHandle); + //reqGet.AddHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; YComp 5.0.0.0)"); + reqGet.Create(T_REQ_GET, OI_METHOD_GET, pszURI); + enuRet = reqGet.Dispatch(&pvdDummy, &csmFile); + close(nHandle); + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoHead(const char* pszURI) +{ + OI_DEBUG("Starting HEAD on <%s>...\n", pszURI); + OI_RESULT enuRet; + CDavRequest reqHead(this); + CRBPVDDummy pvdDummy; + CPBCSMDummy csmDummy(&reqHead); + reqHead.Create(T_REQ_HEAD, OI_METHOD_HEAD, pszURI); + enuRet = reqHead.Dispatch(&pvdDummy, &csmDummy); + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoLock(const char* pszURI, + CDavLock* pLock, + const char* pszIfHeader) +{ + OI_DEBUG("Starting LOCK on <%s>...\n", pszURI); + OI_ASSERT(!m_pCurrentLock); + OI_RESULT enuRet; + unsigned long unMask; + CDavRequest reqLock(this); + + if(pszIfHeader) + reqLock.AddHeader(OI_REQHDR_IF, pszIfHeader); + + if(pLock){ + m_pCurrentLock = pLock; + } else { + m_pCurrentLock = new CDavLock; + m_pCurrentLock->m_pOwner = NULL; + m_pCurrentLock->m_unMask = 0; + } + + unMask = m_pCurrentLock->m_unMask; + //ensure all fields are present + if(! (unMask & OI_LIVF_TYPE)) + m_pCurrentLock->m_enuType = T_LOCK_WRITE; + if(! (unMask & OI_LIVF_SCOPE)) + m_pCurrentLock->m_enuScope = SCP_LOCK_EXCLUSIVE; + if(! (unMask & OI_LIVF_DEPTH)) + m_pCurrentLock->m_enuDepth = D_LOCK_INFINITE; + if(! (unMask & OI_LIVF_TIMEOUT)) + m_pCurrentLock->m_lTimeout = 0; + if(! (unMask & OI_LIVF_OWNER)) + m_pCurrentLock->m_pOwner = NULL; + + OI_STRING_A strDepth; + OI_STRING_A strTimeout; + + //setting up depth + switch(m_pCurrentLock->m_enuDepth){ + case D_LOCK_ZERO: + strDepth = "0"; + break; + case D_LOCK_INFINITE: + default: + strDepth = "infinity"; + break; + } + reqLock.AddHeader(OI_REQHDR_DEPTH, strDepth.c_str()); + //setting upt timeout + if(m_pCurrentLock->m_lTimeout > 0){ + char chTimeout[30]; + sprintf(chTimeout, "%d", m_pCurrentLock->m_lTimeout); + strTimeout = chTimeout; + } else { + strTimeout = "Infinite"; + } + reqLock.AddHeader(OI_REQHDR_TIMEOUT, strTimeout.c_str()); + reqLock.AddHeader(OI_REQHDR_CONTENTTYPE, "text/xml"); + reqLock.Create(T_REQ_LOCK, OI_METHOD_LOCK, pszURI); + + CRBPVDXmlLock pvdLock(m_pCurrentLock); + //the cut element is "activelock" + CPBCSMXml csmLock(&reqLock, OI_XML_CUTELEMENT_LOCK); + enuRet = reqLock.Dispatch(&pvdLock, &csmLock); + if(!pLock) + delete m_pCurrentLock; + m_pCurrentLock = NULL; + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoMkcol(const char* pszURI, + const char* pszIfHeader) +{ + OI_DEBUG("Starting MKCOL at <%s>...\n", pszURI); + OI_RESULT enuRet; + CDavRequest reqMkcol(this); + CRBPVDDummy pvdDummy; + CPBCSMDummy csmDummy(&reqMkcol); + reqMkcol.Create(T_REQ_MKCOL, OI_METHOD_MKCOL, pszURI); + + if(pszIfHeader) + reqMkcol.AddHeader(OI_REQHDR_IF, pszIfHeader); + + enuRet = reqMkcol.Dispatch(&pvdDummy, &csmDummy); + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoMove(const char* pszSrc, + const char* pszDest, + CRBPVDXmlMove* pXml, + bool bOverwrite, + const char* pszIfHeader) +{ + OI_DEBUG("Starting MOVE from <%s> to <%s>...\n", pszSrc, pszDest); + OI_RESULT enuRet; + CDavRequest reqMove(this); + CRBPVDDummy pvdDummy; + CRequestBodyProvider* pBodyProvider = &pvdDummy; + CPBCSMDummy csmDummy(&reqMove); + OI_STRING_A strDest = Escape(AnsiToUtf8(pszDest)); + OI_STRING_A strOverwrite = bOverwrite ? "T" : "F"; + reqMove.Create(T_REQ_MOVE, OI_METHOD_MOVE, pszSrc); + reqMove.AddHeader(OI_REQHDR_DESTINATION, strDest.c_str()); + reqMove.AddHeader(OI_REQHDR_OVERWRITE, strOverwrite.c_str()); + if(pXml){ + pBodyProvider = pXml; + reqMove.AddHeader(OI_REQHDR_CONTENTTYPE, "application/xml"); + } + + if(pszIfHeader) + reqMove.AddHeader(OI_REQHDR_IF, pszIfHeader); + + enuRet = reqMove.Dispatch(pBodyProvider, &csmDummy); + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoOptions(const char* pszURI, + OI_STRING_A& strAllow, + OI_STRING_A& strDAV, + OI_STRING_A& strDASL, + OI_STRING_A& strMSV) +{ + OI_DEBUG("Starting OPTIONS on <%s>...\n", pszURI); + OI_RESULT enuRet; + CDavRequest reqOptions(this); + CRBPVDDummy pvdDummy; + CPBCSMDummy csmDummy(&reqOptions); + CHandlerAllow* pAllow = new CHandlerAllow; + CHandlerDAV* pDAV = new CHandlerDAV; + CHandlerDASL* pDASL = new CHandlerDASL; + CHandlerMSV* pMSV = new CHandlerMSV; + + reqOptions.AddHandler(pAllow); + reqOptions.AddHandler(pDAV); + reqOptions.AddHandler(pDASL); + reqOptions.AddHandler(pMSV); + reqOptions.Create(T_REQ_OPTIONS, OI_METHOD_OPTIONS, pszURI); + enuRet = reqOptions.Dispatch(&pvdDummy, &csmDummy); + + if(OI_OK == enuRet){ + strAllow = pAllow->m_strAllow.c_str(); + strDAV = pDAV->m_strDAV.c_str(); + strDASL = pDASL->m_strDASL.c_str(); + strMSV = pMSV->m_strMSV.c_str(); + } + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoProppatch(const char* pszURI, + CRBPVDXmlProppatch* pXml, + const char* pszIfHeader) +{ + OI_ASSERT(pXml); + OI_DEBUG("Starting PROPPATCH on <%s>...\n", pszURI); + OI_RESULT enuRet; + CDavRequest reqProppatch(this); + CPBCSMXml csmProppatch(&reqProppatch, NULL); //we don't process in SAX mode + + reqProppatch.Create(T_REQ_PROPPATCH, OI_METHOD_PROPPATCH, pszURI); + reqProppatch.AddHeader(OI_REQHDR_CONTENTTYPE, "application/xml"); + if(pszIfHeader) + reqProppatch.AddHeader(OI_REQHDR_IF, pszIfHeader); + + enuRet = reqProppatch.Dispatch(pXml, &csmProppatch); + if(OI_OK == enuRet) + m_pXmlBuffer->ImportDocument(csmProppatch.GetDocument()); + return enuRet; +} + + +OI_RESULT +CDavWorkSession::DoPut(const char* pszURI, + const char* pszLocalPath, + const char* pszIfHeader, + const char* pszContentType) +{ + OI_DEBUG("Starting PUT on <%s>...\n", pszURI); + OI_RESULT enuRet; + int nFlags = O_RDONLY; +#ifdef WIN32 + nFlags |= O_BINARY; +#endif /* WIN32 */ + + CDavRequest reqPut(this); + int nHandle = open(pszLocalPath, nFlags); + CRBPVDLocalFile pvdFile(nHandle); + CPBCSMDummy pvdDummy(&reqPut); + //reqGet.AddHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; YComp 5.0.0.0)"); + reqPut.Create(T_REQ_PUT, OI_METHOD_PUT, pszURI); + if(pszIfHeader) + reqPut.AddHeader(OI_REQHDR_IF, pszIfHeader); + + if(pszContentType) + reqPut.AddHeader(OI_REQHDR_CONTENTTYPE, pszContentType); + + enuRet = reqPut.Dispatch(&pvdFile, &pvdDummy); + close(nHandle); + return enuRet; +} + +OI_RESULT +CDavWorkSession::DoSearch(const char* pszURI, + CRBPVDXmlSearch* pXml) +{ + OI_ASSERT(pXml); + OI_DEBUG("Starting SEARCH on <%s>...\n", pszURI); + OI_RESULT enuRet; + CDavRequest reqSearch(this); + CPBCSMXml csmSearch(&reqSearch); + + reqSearch.Create(T_REQ_SEARCH, OI_METHOD_SEARCH, pszURI); + reqSearch.AddHeader(OI_REQHDR_CONTENTTYPE, "application/xml"); + + enuRet = reqSearch.Dispatch(pXml, &csmSearch); + return enuRet; + +} + +OI_RESULT +CDavWorkSession::DoUnlock(const char* pszURI, + const char* pszLockToken) +{ + OI_DEBUG("Starting UNLOCK on <%s>...\n", pszURI); + OI_ASSERT(pszLockToken); + OI_RESULT enuRet; + OI_STRING_A strLockToken = "<"; + strLockToken += pszLockToken; + strLockToken += ">"; + CDavRequest reqUnlock(this); + CRBPVDDummy pvdDummy; + CPBCSMDummy csmDummy(&reqUnlock); + + reqUnlock.Create(T_REQ_UNLOCK, OI_METHOD_UNLOCK, pszURI); + reqUnlock.AddHeader(OI_REQHDR_LOCKTOKEN, strLockToken.c_str()); + + enuRet = reqUnlock.Dispatch(&pvdDummy, &csmDummy); + return enuRet; +} + +CDavServerPolicy* +CDavWorkSession::GetServerPolicy() +{ + return m_pServerPolicy; +} + +/* + * Adding an unauthentic cert to the list + * pX509 should not be incremented before calling this function + * if the same cert already exists in the list, the failure flag bits + * will be "OR"ed to the original + */ +void +CDavWorkSession::addUnauthenticCert(X509* pX509, unsigned long ulFailures) +{ + if(!pX509 || !ulFailures) + return; + //first seach through the list, see if there is a match + int nCount = m_pUnauthenticCerts->GetCount(); + for(int nIndex = 0; nIndex < nCount; nIndex++){ + CDavSSLCertificate* pCert = (*m_pUnauthenticCerts)[nIndex]; + if(*pCert == pX509) + pCert->m_ulFailures |= ulFailures; + return; + } + //no match, add the cert to the list + m_pUnauthenticCerts->AddCertificate(new CDavSSLCertificate(pX509, ulFailures)); +} + + Index: onion/src/DavServerPolicy.cpp =================================================================== --- onion/src/DavServerPolicy.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavServerPolicy.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,896 @@ +/* + Configuration to handle different kinds of servers + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavServerPolicy.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include + + +CDavServerPolicy::CDavServerPolicy(void): + m_xbfConfig(OI_XMLPOLICY_DOCNAME) +{ + m_pConfig = NULL; + m_pRoot = NULL; +} + +CDavServerPolicy::~CDavServerPolicy(void) +{ +} + +void +CDavServerPolicy::Reset() +{ + m_pConfig = NULL; + m_pRoot = NULL; + m_pDefaultMethods = NULL; + m_pDefaultStatuses = NULL; + //m_xbfConfig.Clear(); +} + +bool +CDavServerPolicy::Load(const char* pszPath) +{ + m_xbfConfig.Load(pszPath); //TODO: handle failures + m_pConfig = m_xbfConfig.GetDocument(); + if(initConfig()) + return true; + + Reset(); + return false; +} + +bool +CDavServerPolicy::Load(CDavXmlBuffer* pXmlBuffer) +{ + if(!pXmlBuffer) + return false; + m_xbfConfig = *pXmlBuffer; + m_pConfig = m_xbfConfig.GetDocument(); + if(initConfig()) + return true; + + Reset(); + return false; +} + +/* + * try to make sure all key element + * pointers are in place + */ +bool +CDavServerPolicy::secureConfig() +{ + if(m_pConfig) + return true; + + generateDefault(); + + if(initConfig()) + return true; + + Reset(); + return false; +} + +/* + * Initialize cached pointers to each + * key element. Caller should reset + * m_pConfig in case this function fails + */ +bool +CDavServerPolicy::initConfig() +{ + OI_ASSERT(m_pConfig); + m_pDefaultMethods = NULL; + m_pDefaultStatuses = NULL; + m_pRoot = m_pConfig->getDocumentElement(); + + XNS(DOMNodeList) *pNodeList; + XNS(DOMElement) *pDefaultServer; + + //getting the default server element + pNodeList = m_pRoot->getElementsByTagName(X("DefaultServer")); + if(pNodeList->getLength() < 1) { + OI_DEBUG("default server configuration not found!\n"); + return false; + } + + pDefaultServer = (XNS(DOMElement)*)(pNodeList->item(0)); + if(!pDefaultServer){ + OI_DEBUG("href Content not found!\n"); + return false; + } + + //setting pointer for DefaultServer->Methods + pNodeList = pDefaultServer->getElementsByTagName(X("Methods")); + if(pNodeList->getLength() < 1){ + OI_DEBUG("default server configuration not found!\n"); + return false; + } + m_pDefaultMethods = (XNS(DOMElement)*)(pNodeList->item(0)); + if(!m_pDefaultMethods){ + OI_DEBUG("href Content not found!\n"); + return false; + } + + //setting pointer for DefaultServer->Methods + pNodeList = pDefaultServer->getElementsByTagName(X("CommonStatus")); + if(pNodeList->getLength() < 1){ + OI_DEBUG("default server configuration not found!\n"); + return false; + } + m_pDefaultStatuses = (XNS(DOMElement)*)(pNodeList->item(0)); + if(!m_pDefaultStatuses){ + OI_DEBUG("href Content not found!\n"); + return false; + } + + return true; +} + +XNS(DOMElement)* +CDavServerPolicy::appendElement(XNS(DOMElement)* pParent, + const XMLCh* pszName) +{ + if((!pParent) || (!pszName)) + return NULL; + XNS(DOMElement)* pChild = m_pConfig->createElement(pszName); + pParent->appendChild(pChild); + return pChild; +} + +XNS(DOMElement)* +CDavServerPolicy::appendCType(XNS(DOMElement)* pParent, + const XMLCh* pszType, + const XMLCh* pszErrCode, + const XMLCh* pszOpCode) +{ + if((!pParent)||(!pszType)||(!pszErrCode)||(!pszOpCode)) + return NULL; + XNS(DOMElement)* pChild = m_pConfig->createElement(m_pszCType); + pParent->appendChild(pChild); + pChild->setAttribute(m_pszType, pszType); + pChild->setAttribute(m_pszErrCode, pszErrCode); + pChild->setAttribute(m_pszOpCode, pszOpCode); + return pChild; +} + +XNS(DOMElement)* +CDavServerPolicy::appendMethod(XNS(DOMElement)* pParent, + const XMLCh* pszMethod, + const XMLCh* pszDefaultOp, + const XMLCh* pszDefaultErr) +{ + if((!pParent)||(!pszMethod)||(!pszDefaultOp)||(!pszDefaultErr)) + return NULL; + XNS(DOMElement)* pChild = m_pConfig->createElement(pszMethod); + pParent->appendChild(pChild); + pChild->setAttribute(m_pszDefaultOp, pszDefaultOp); + pChild->setAttribute(m_pszDefaultErr, pszDefaultErr); + return pChild; +} + +XNS(DOMElement)* +CDavServerPolicy::appendStatus(XNS(DOMElement)* pParent, + const XMLCh* pszStatus, + const XMLCh* pszChkBody, + const XMLCh* pszDefErr, + const XMLCh* pszDefOp) +{ + if((!pParent)||(!pszStatus)||(!pszChkBody)||(!pszDefErr)||(!pszDefOp)) + return NULL; + XNS(DOMElement)* pChild = m_pConfig->createElement(pszStatus); + pParent->appendChild(pChild); + pChild->setAttribute(m_pszChkBody, pszChkBody); + pChild->setAttribute(m_pszDefErr, pszDefErr); + pChild->setAttribute(m_pszDefOp, pszDefOp); + return pChild; +} + +/* + * the hard-coded policy. + * Fallback to this only when no + * policy is loaded + */ +void +CDavServerPolicy::generateDefault() +{ + OI_ASSERT(!m_pConfig); + + //initializing node names + X strCType("CType"); + X strType("Type"); + X strErrCode("ErrCode"); + X strOpCode("OpCode"); + X strChkBody("ChkBody"); + X strDefErr("DefErr"); + X strDefOp("DefOp"); + X strDefaultErr("DefaultErr"); + X strDefaultOp("DefaultOp"); + + m_pszCType = strCType; + m_pszType = strType; + m_pszErrCode = strErrCode; + m_pszOpCode = strOpCode; + m_pszChkBody = strChkBody; + m_pszDefErr = strDefErr; + m_pszDefOp = strDefOp; + m_pszDefaultErr = strDefaultErr; + m_pszDefaultOp = strDefaultOp; + + //initializing value strings + X strT("T"); + X strF("F"); + X str0("0"); + X str1("1"); + X str2("2"); + X str3("3"); + X str4("4"); + X str5("5"); + X str6("6"); + X str7("7"); + X str901("901"); + X str902("902"); + X str903("903"); + X strTEXT_HTML("text/html"); + X strTEXT_XML("text/xml"); + + const XMLCh* pszT = strT; + const XMLCh* pszF = strF; + const XMLCh* psz0 = str0; + const XMLCh* psz1 = str1; + const XMLCh* psz2 = str2; + const XMLCh* psz3 = str3; + const XMLCh* psz4 = str4; + const XMLCh* psz5 = str5; + const XMLCh* psz6 = str6; + const XMLCh* psz7 = str7; + const XMLCh* psz901 = str901; + const XMLCh* psz902 = str902; + const XMLCh* psz903 = str903; + const XMLCh* pszTEXT_HTML = strTEXT_HTML; + const XMLCh* pszTEXT_XML = strTEXT_XML; + + + m_xbfConfig.Clear(); + m_pConfig = m_xbfConfig.GetDocument(); + OI_ASSERT(m_pConfig); + + //the DefaultServer Element + XNS(DOMElement)* pRoot = m_pConfig->getDocumentElement(); + XNS(DOMElement)* pDefaultServer = appendElement(pRoot, X("DefaultServer")); + pDefaultServer->setAttribute(X("Name"), X("Default Server")); + + //the CommonStatus Element + XNS(DOMElement)* pCommonStatus = appendElement(pDefaultServer, + X("CommonStatus")); + //S206 for CommonStatus + XNS(DOMElement)* pS206 = appendStatus(pCommonStatus, + X("S206"), + pszF, + psz0, + psz0); + //S301 for CommonStatus + XNS(DOMElement)* pS301 = appendStatus(pCommonStatus, + X("S301"), + pszT, + psz903, + psz1); + //CType for S301 + XNS(DOMElement)* pS301CType = appendCType(pS301, + pszTEXT_HTML, + X("819"), + psz4); + //S400 for CommonStatus + XNS(DOMElement)* pS400 = appendStatus(pCommonStatus, + X("S400"), + pszT, + psz903, + psz1); + //CType for S400 + XNS(DOMElement)* pS400CType = appendCType(pS400, + pszTEXT_HTML, + X("803"), + psz4); + //S401 for CommonStatus + XNS(DOMElement)* pS401 = appendStatus(pCommonStatus, + X("S401"), + pszT, + psz903, + psz1); + //CType for S401 + XNS(DOMElement)* pS401CType = appendCType(pS401, + pszTEXT_HTML, + psz0, + psz7); + //S402 for CommonStatus + XNS(DOMElement)* pS402 = appendStatus(pCommonStatus, + X("S402"), + pszT, + psz903, + psz1); + //CType for S402 + XNS(DOMElement)* pS402CType = appendCType(pS402, + pszTEXT_HTML, + X("821"), + psz4); + //S403 for CommonStatus + XNS(DOMElement)* pS403 = appendStatus(pCommonStatus, + X("S403"), + pszT, + psz903, + psz1); + //CType for S403 + XNS(DOMElement)* pS403CType = appendCType(pS403, + pszTEXT_HTML, + X("804"), + psz4); + //S404 for CommonStatus + XNS(DOMElement)* pS404 = appendStatus(pCommonStatus, + X("S404"), + pszT, + psz903, + psz1); + //CType for S404 + XNS(DOMElement)* pS404CType = appendCType(pS404, + pszTEXT_HTML, + X("805"), + psz4); + //S405 for CommonStatus + XNS(DOMElement)* pS405 = appendStatus(pCommonStatus, + X("S405"), + pszT, + psz903, + psz1); + //CType for S405 + XNS(DOMElement)* pS405CType = appendCType(pS405, + pszTEXT_HTML, + X("806"), + psz4); + //S407 for CommonStatus + XNS(DOMElement)* pS407 = appendStatus(pCommonStatus, + X("S407"), + pszT, + psz903, + psz1); + //CType for S407 + XNS(DOMElement)* pS407CType = appendCType(pS407, + pszTEXT_HTML, + psz0, + psz7); + //S409 for CommonStatus + XNS(DOMElement)* pS409 = appendStatus(pCommonStatus, + X("S409"), + pszT, + psz903, + psz1); + //CType for S409 + XNS(DOMElement)* pS409CType = appendCType(pS409, + pszTEXT_HTML, + X("807"), + psz4); + //S500 for CommonStatus + XNS(DOMElement)* pS500 = appendStatus(pCommonStatus, + X("S500"), + pszT, + psz903, + psz1); + //CType for S500 + XNS(DOMElement)* pS500CType = appendCType(pS500, + pszTEXT_HTML, + X("812"), + psz4); + //S502 for CommonStatus + XNS(DOMElement)* pS502 = appendStatus(pCommonStatus, + X("S502"), + pszT, + psz903, + psz1); + //CType for S502 + XNS(DOMElement)* pS502CType = appendCType(pS502, + pszTEXT_HTML, + X("813"), + psz4); + //S503 for CommonStatus + XNS(DOMElement)* pS503 = appendStatus(pCommonStatus, + X("S503"), + pszT, + psz903, + psz1); + //CType for S503 + XNS(DOMElement)* pS503CType = appendCType(pS503, + pszTEXT_HTML, + X("814"), + psz4); + //S507 for CommonStatus + XNS(DOMElement)* pS507 = appendStatus(pCommonStatus, + X("S507"), + pszT, + psz903, + psz1); + //CType for S507 + XNS(DOMElement)* pS507CType = appendCType(pS507, + pszTEXT_HTML, + X("820"), + psz4); + + //the Methods Element + XNS(DOMElement)* pMethods = appendElement(pDefaultServer, + X("Methods")); + pMethods->setAttribute(m_pszDefaultOp, psz1); + pMethods->setAttribute(m_pszDefaultErr, psz901); + + ///////////////////////////////////////////////////////////////// + //the CONNECT method + XNS(DOMElement)* pCONNECT = appendMethod(pMethods, + X("CONNECT"), + psz1, + psz902); + //S200 for CONNECT + XNS(DOMElement)* pS200 = appendStatus(pCONNECT, + X("S200"), + pszF, + psz0, + psz0); + + ///////////////////////////////////////////////////////////////// + //the COPY method + XNS(DOMElement)* pCOPY = appendMethod(pMethods, + X("COPY"), + psz1, + psz902); + //S201 for COPY + XNS(DOMElement)* pS201 = appendStatus(pCOPY, + X("S201"), + pszT, + psz903, + psz1); + //CType for S201 + XNS(DOMElement)* pS201CType = appendCType(pS201, + pszTEXT_HTML, + psz0, + psz4); + //S204 for COPY + XNS(DOMElement)* pS204 = appendStatus(pCOPY, + X("S204"), + pszF, + psz0, + psz0); + //S412 for COPY + XNS(DOMElement)* pS412 = appendStatus(pCOPY, + X("S412"), + pszT, + psz903, + psz1); + //CType for S412 + XNS(DOMElement)* pS412CType = appendCType(pS412, + pszTEXT_HTML, + X("808"), + psz4); + + //S424 for COPY + XNS(DOMElement)* pS424 = appendStatus(pCOPY, + X("S424"), + pszT, + psz903, + psz1); + //CType for S424 + XNS(DOMElement)* pS424CType = appendCType(pS424, + pszTEXT_XML, + X("810"), + psz3); + pS424CType->setAttribute(X("CutElement"), X("response")); + + ///////////////////////////////////////////////////////////////// + //the DELETE method + XNS(DOMElement)* pDELETE = appendMethod(pMethods, + X("DELETE"), + psz1, + psz902); + //S204 for DELETE + pDELETE->appendChild(pS204->cloneNode(true)); + //S423 for DELETE + XNS(DOMElement)* pS423 = appendStatus(pDELETE, + X("S423"), + pszT, + psz903, + psz1); + //CType for S423 + XNS(DOMElement)* pS423CType = appendCType(pS423, + pszTEXT_HTML, + X("809"), + psz4); + + //S424 for DELETE + pDELETE->appendChild(pS424->cloneNode(true)); + + ///////////////////////////////////////////////////////////////// + //the GET method + XNS(DOMElement)* pGET = appendMethod(pMethods, + X("GET"), + psz1, + psz902); + //S200 for GET + pGET->appendChild(pS200->cloneNode(true)); + + + ///////////////////////////////////////////////////////////////// + //the HEAD method + XNS(DOMElement)* pHEAD = appendMethod(pMethods, + X("HEAD"), + psz1, + psz902); + //S200 for HEAD + pHEAD->appendChild(pS200->cloneNode(true)); + + ///////////////////////////////////////////////////////////////// + //the LOCK method + XNS(DOMElement)* pLOCK = appendMethod(pMethods, + X("LOCK"), + psz1, + psz902); + //S200 for LOCK + XNS(DOMElement)* pS200Lock = appendStatus(pLOCK, + X("S200"), + pszT, + psz903, + psz1); + //CType for S200 + XNS(DOMElement)* pS200LockCType = appendCType(pS200Lock, + pszTEXT_XML, + psz0, + psz5); + //S207 for LOCK + XNS(DOMElement)* pS207Lock = appendStatus(pLOCK, + X("S207"), + pszT, + psz903, + psz1); + //CType for S200 + XNS(DOMElement)* pS207LockCType = appendCType(pS207Lock, + pszTEXT_XML, + X("802"), + psz3); + pS207LockCType->setAttribute(X("CutElement"), X("response")); + //lpS207LockCType->setAttribute(L"CutElement", L"multistatus"); + //S423 for LOCK + pLOCK->appendChild(pS423->cloneNode(true)); + + ///////////////////////////////////////////////////////////////// + //the MKCOL method + XNS(DOMElement)* pMKCOL = appendMethod(pMethods, + X("MKCOL"), + psz1, + psz902); + //S201 for MKCOL + pMKCOL->appendChild(pS201->cloneNode(true)); + //S207 for MKCOL(copy from LOCK method) + pMKCOL->appendChild(pS207Lock->cloneNode(true)); + + ///////////////////////////////////////////////////////////////// + //the MOVE method + XNS(DOMElement)* pMOVE = appendMethod(pMethods, + X("MOVE"), + psz1, + psz902); + //S201 for MOVE + pMOVE->appendChild(pS201->cloneNode(true)); + //S204 for MOVE + pMOVE->appendChild(pS204->cloneNode(true)); + //S412 for MOVE + pMOVE->appendChild(pS412->cloneNode(true)); + //S423 for MOVE + pMOVE->appendChild(pS423->cloneNode(true)); + //S424 for MOVE + pMOVE->appendChild(pS424->cloneNode(true)); + + ///////////////////////////////////////////////////////////////// + //the OPTIONS method + XNS(DOMElement)* pOPTIONS = appendMethod(pMethods, + X("OPTIONS"), + psz1, + psz902); + //S200 for OPTIONS + pOPTIONS->appendChild(pS200->cloneNode(true)); + + ///////////////////////////////////////////////////////////////// + //the PROPFIND method + XNS(DOMElement)* pPROPFIND = appendMethod(pMethods, + X("PROPFIND"), + psz1, + psz902); + //S207 for PROPFIND + XNS(DOMElement)* pS207PFind = appendStatus(pPROPFIND, + X("S207"), + pszT, + psz903, + psz1); + //CType for S200 + XNS(DOMElement)* pS207PFindCType = appendCType(pS207PFind, + pszTEXT_XML, + psz0, + psz6); + pS207PFindCType->setAttribute(X("CutElement"), X("response")); + + + ///////////////////////////////////////////////////////////////// + //the PROPPATCH method + XNS(DOMElement)* pPROPPATCH = appendMethod(pMethods, + X("PROPPATCH"), + psz1, + psz902); + //S207 for PROPPATCH + pPROPPATCH->appendChild(pS207PFind->cloneNode(true)); + //S423 for PROPPATCH + pPROPPATCH->appendChild(pS423->cloneNode(true)); + + ///////////////////////////////////////////////////////////////// + //the PUT method + XNS(DOMElement)* pPUT = appendMethod(pMethods, + X("PUT"), + psz1, + psz902); + //S201 for PUT + pPUT->appendChild(pS201->cloneNode(true)); + //S204 for PUT + XNS(DOMElement)* pS204Put = appendStatus(pPUT, + X("S204"), + pszF, + X("801"), + psz0); + //S207 for PUT(copy from LOCK method) + pPUT->appendChild(pS207Lock->cloneNode(true)); + //S423 for PUT(copy from LOCK method) + pPUT->appendChild(pS423->cloneNode(true)); + + + + ///////////////////////////////////////////////////////////////// + //the SEARCH method + XNS(DOMElement)* pSEARCH = appendMethod(pMethods, + X("SEARCH"), + psz1, + psz902); + //S207 for SEARCH + pSEARCH->appendChild(pS207PFind->cloneNode(true)); + + + ///////////////////////////////////////////////////////////////// + //the UNLOCK method + XNS(DOMElement)* pUNLOCK = appendMethod(pMethods, + X("UNLOCK"), + psz1, + psz902); + //S204 for UNLOCK + pUNLOCK->appendChild(pS204Put->cloneNode(true)); + +} + +void +CDavServerPolicy::WriteDefaultConfig(const char* pszPath) +{ + /* + generateDefault(); + XNS(DOMDocument)* pDoc = m_pConfig; + if(!initConfig(pDoc)) + return; + + XNS(DOMWriter)* pWriter; + XNS(LocalFileFormatTarget)* pFormatTarget; + XNS(DOMImplementation) *pImpl = + XNS(DOMImplementationRegistry)::getDOMImplementation(X("LS")); + pWriter = ((XNS(DOMImplementationLS)*)pImpl)->createDOMWriter(); + pFormatTarget = new XNS(LocalFileFormatTarget)(pszPath); + pWriter->setNewLine(X("\r\n")); + pWriter->setFeature(XNS(XMLUni)::fgDOMWRTFormatPrettyPrint, true); + XNS(DOMDocument)* pDoc2 = pDoc->getOwnerDocument(); + pWriter->writeNode(pFormatTarget, *pDoc); + + pWriter->release(); + delete pFormatTarget; + */ +} + +OI_RESULT +CDavServerPolicy::CheckResponse(CDavWorkSession* pSession, + const char* pszServerString, + const char* pszRequest, + int nStatus, + const char* pszContentType, + OIOPERATION *pOperation) +{ + int i; + OI_ASSERT(pOperation); + OI_ASSERT(pSession); + + if(!secureConfig()) + return OIYECONFINITFAILED; + + pOperation->szCutElement[0] = 0; + XNS(DOMElement)* pCommonStatus = NULL; + + //lookup server + bool bServerFound = false; + OI_STRING_A strServer = pszServerString; + XNS(DOMNodeList) *pNodeList; + XNS(DOMElement) *pServer, *pMethods; + + pNodeList = m_pRoot->getElementsByTagName(X("Server")); + + int nServerCount = pNodeList->getLength(); + for(i = 0; i < nServerCount; i++){ + pServer = (XNS(DOMElement)*)(pNodeList->item(i)); + OI_STRING_A strName = (const char*)X(pServer->getAttribute(X("Name"))); + if(pSession->MatchServerString(strServer.c_str(), strName.c_str())){ + OI_DEBUG("Server Config [%s] found\n", strName.c_str()); + bServerFound = true; + break; + } + } + if(bServerFound){ + pNodeList = pServer->getElementsByTagName(X("Methods")); + pMethods = (XNS(DOMElement)*)(pNodeList->item(0)); + if(!pMethods) + return OIYECONFSYNTAX; + pNodeList = pServer->getElementsByTagName(X("CommonStatus")); + pCommonStatus = (XNS(DOMElement)*)(pNodeList->item(0)); + if(!pCommonStatus) + pCommonStatus = m_pDefaultStatuses; + } else { + OI_DEBUG("Server Config not found, use default\n"); + pMethods = m_pDefaultMethods; + pCommonStatus = m_pDefaultStatuses; + } + + OI_STRING_A strDefaultOp = + (const char*)X(pMethods->getAttribute(X("DefaultOp"))); + OI_STRING_A strDefaultErr = + (const char*)X(pMethods->getAttribute(X("DefaultErr"))); + + if(strDefaultOp.empty() || strDefaultErr.empty()){ + return OIYECONFSYNTAX; + } + + long lDefOp = atol(strDefaultOp.c_str()); + long lDefEr = atol(strDefaultErr.c_str()); + + m_enuOpCode = (OI_OPCODE)lDefOp; + m_enuError = (OI_RESULT)lDefEr; + + //lookup method + OI_STRING_A strMethod = pszRequest; + pNodeList = pMethods->getElementsByTagName(X(strMethod.c_str())); + + XNS(DOMElement)* pMethod = (XNS(DOMElement)*)(pNodeList->item(0)); + if(!pMethod){ + pOperation->enuOpCode = m_enuOpCode; + pOperation->enuErrCode = m_enuError; + return OI_OK; + } + + strDefaultOp = X(pMethod->getAttribute(X("DefaultOp"))); + strDefaultErr = X(pMethod->getAttribute(X("DefaultErr"))); + + if(strDefaultOp.empty() || strDefaultErr.empty()){ + return OIYECONFSYNTAX; + } + + lDefOp = atol(strDefaultOp.c_str()); + lDefEr = atol(strDefaultErr.c_str()); + + m_enuOpCode = (OI_OPCODE)lDefOp; + m_enuError = (OI_RESULT)lDefEr; + + + //lookup status + //OI_STRING_A strStatus; + char chStatus[5]; + sprintf(chStatus, "S%03u", nStatus); + /* + OI_STRSTREAM_A ss; + ss << "S" << setfill('0') << setw(3) << nStatus; + strStatus = ss.str(); + */ + + //pNodeList = pCommonStatus->getElementsByTagName(X(strStatus.c_str())); + pNodeList = pCommonStatus->getElementsByTagName(X(chStatus)); + XNS(DOMElement)* pStatus = (XNS(DOMElement)*)(pNodeList->item(0)); + + if(!pStatus){ + //pNodeList = pMethod->getElementsByTagName(X(strStatus.c_str())); + pNodeList = pMethod->getElementsByTagName(X(chStatus)); + pStatus = (XNS(DOMElement)*)(pNodeList->item(0)); + } + if(!pStatus){ + pOperation->enuOpCode = m_enuOpCode; + pOperation->enuErrCode = m_enuError; + return OI_OK; + } + + strDefaultOp = X(pStatus->getAttribute(X("DefOp"))); + strDefaultErr = X(pStatus->getAttribute(X("DefErr"))); + + if(strDefaultOp.empty() || strDefaultErr.empty()){ + return OIYECONFSYNTAX; + } + + lDefOp = atol(strDefaultOp.c_str()); + lDefEr = atol(strDefaultErr.c_str()); + + m_enuOpCode = (OI_OPCODE)lDefOp; + m_enuError = (OI_RESULT)lDefEr; + + bool bChkBody = false; + OI_STRING_A strChkBody = (const char*)X(pStatus->getAttribute(X("ChkBody"))); + + if(!strChkBody.empty()){ + if(stricmp(strChkBody.c_str(), "T") == 0) + bChkBody = true; + } + + //check content type + if(!bChkBody){ + pOperation->enuOpCode = m_enuOpCode; + pOperation->enuErrCode = m_enuError; + return OI_OK; + } + + pNodeList = pStatus->getElementsByTagName(X("CType")); + int nLen = pNodeList->getLength(); + + for(i = 0; i < nLen; i++){ + XNS(DOMElement)* pCType = (XNS(DOMElement)*)(pNodeList->item(i)); + OI_STRING_A strCType = (const char*)X(pCType->getAttribute(X("Type"))); + if(strCType.empty()) + continue; + + if(stricmp(strCType.c_str(), pszContentType) == 0){ + OI_STRING_A strOp = (const char*)X(pCType->getAttribute(X("OpCode"))); + OI_STRING_A strErr = (const char*)X(pCType->getAttribute(X("ErrCode"))); + if(strOp.empty() || strErr.empty()){ + return OIYECONFSYNTAX; + } + lDefOp = atol(strOp.c_str()); + lDefEr = atol(strErr.c_str()); + OI_STRING_A strCutElement = + (const char*)X(pCType->getAttribute(X("CutElement"))); + if(strCutElement.length() > OI_MAX_ELEM_LEN){ + strCutElement.erase(OI_MAX_ELEM_LEN); + } + pOperation->enuOpCode = (OI_OPCODE)lDefOp; + pOperation->enuErrCode = (OI_RESULT)lDefEr; + strncpy(pOperation->szCutElement, + strCutElement.c_str(), + OI_MAX_ELEM_LEN); + return OI_OK; + } + } + //no match, return the default + pOperation->enuOpCode = m_enuOpCode; + pOperation->enuErrCode = m_enuError; + return OI_OK; +} + Index: onion/src/RequestBodyProvider.cpp =================================================================== --- onion/src/RequestBodyProvider.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RequestBodyProvider.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,41 @@ +/* + Prototype of http request body provider + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RequestBodyProvider.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CRequestBodyProvider::CRequestBodyProvider(void) +{ +} + +CRequestBodyProvider::~CRequestBodyProvider(void) +{ +} + +void +CRequestBodyProvider::OnCancel(CDavRequest* pReq) +{ +} Index: onion/src/DavSocket.cpp =================================================================== --- onion/src/DavSocket.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavSocket.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,621 @@ +/* + Socket wrapper for http operations + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSocket.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +#ifdef WIN32 +# include +# include +#else +# include +# include +#endif + +#ifdef HAVE_SYS_SOCKET_H +# include +#endif /* HAVE_SYS_SOCKET_H */ +#ifdef HAVE_UNISTD_H +# include +#endif /* HAVE_UNISTD_H */ +#if HAVE_NETINET_IN_H +# include +#endif /* HAVE_NETINET_IN_H */ +#if HAVE_ARPA_INET_H +# include +#endif /* HAVE_ARPA_INET_H */ + + +#include +#include +#include +#include +#include + +#include +#include +#include /* for PKCS12_PBE_add */ +#include + +#ifndef INADDR_NONE +#define INADDR_NONE ((unsigned long) -1) +#endif /* INADDR_NONE */ + +extern SSL_CTX* g_pSSLCtx; + +int +fnSSLVerifyCallback(int nOK, X509_STORE_CTX *pStoreCtx) +{ + if(nOK == 0){ + unsigned long ulFailures = 0; + X509* pX509 = X509_STORE_CTX_get_current_cert(pStoreCtx); + int nError = X509_STORE_CTX_get_error(pStoreCtx); + SSL* pSSL = + (SSL*)X509_STORE_CTX_get_ex_data(pStoreCtx, + SSL_get_ex_data_X509_STORE_CTX_idx()); + + CDavSocket* pSocket = (CDavSocket*)SSL_get_app_data(pSSL); + OI_DEBUG("SSL certificate problem: %s\n", + X509_verify_cert_error_string(nError)); + + switch(nError){ + case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: + ulFailures = OI_SSL_ERR_UNABLE_TO_GET_ISSUER_CERT; + break; + case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: + ulFailures = OI_SSL_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE; + break; + case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: + ulFailures = OI_SSL_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY; + break; + case X509_V_ERR_CERT_SIGNATURE_FAILURE: + ulFailures = OI_SSL_ERR_CERT_SIGNATURE_FAILURE; + break; + case X509_V_ERR_CERT_NOT_YET_VALID: + ulFailures = OI_SSL_ERR_CERT_NOT_YET_VALID; + break; + case X509_V_ERR_CERT_HAS_EXPIRED: + ulFailures = OI_SSL_ERR_CERT_HAS_EXPIRED; + break; + case X509_V_ERR_OUT_OF_MEM: + ulFailures = OI_SSL_ERR_OUT_OF_MEM; + break; + case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: + ulFailures = OI_SSL_ERR_DEPTH_ZERO_SELF_SIGNED_CERT; + break; + case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: + ulFailures = OI_SSL_ERR_SELF_SIGNED_CERT_IN_CHAIN; + break; + case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: + ulFailures = OI_SSL_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY; + break; + case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: + ulFailures = OI_SSL_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE; + break; + case X509_V_ERR_CERT_CHAIN_TOO_LONG: + ulFailures = OI_SSL_ERR_CERT_CHAIN_TOO_LONG; + break; + case X509_V_ERR_CERT_REVOKED: + ulFailures = OI_SSL_ERR_CERT_REVOKED; + break; + case X509_V_ERR_INVALID_CA: + ulFailures = OI_SSL_ERR_INVALID_CA; + break; + case X509_V_ERR_PATH_LENGTH_EXCEEDED: + ulFailures = OI_SSL_ERR_PATH_LENGTH_EXCEEDED; + break; + case X509_V_ERR_INVALID_PURPOSE: + ulFailures = OI_SSL_ERR_INVALID_PURPOSE; + break; + case X509_V_ERR_CERT_UNTRUSTED: + ulFailures = OI_SSL_ERR_CERT_UNTRUSTED; + break; + case X509_V_ERR_CERT_REJECTED: + ulFailures = OI_SSL_ERR_CERT_REJECTED; + break; + case X509_V_ERR_SUBJECT_ISSUER_MISMATCH: + ulFailures = OI_SSL_ERR_SUBJECT_ISSUER_MISMATCH; + break; + case X509_V_ERR_AKID_SKID_MISMATCH: + ulFailures = OI_SSL_ERR_AKID_SKID_MISMATCH; + break; + case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: + ulFailures = OI_SSL_ERR_AKID_ISSUER_SERIAL_MISMATCH; + break; + case X509_V_ERR_KEYUSAGE_NO_CERTSIGN: + ulFailures = OI_SSL_ERR_KEYUSAGE_NO_CERTSIGN; + break; + } + pSocket->AddUnauthenticCert(pX509, ulFailures); + } + return 1; +} + +CDavSocket::CDavSocket(CDavWorkSession* pSession): + m_pSession(pSession), + m_hSocket(0) +{ + m_bReady = false; + m_bConnected = false; + m_unTimeout = OI_SOCKTIMEOUTSEC; + + m_pIOFuncRaw = new CDavSocketIORaw; + m_pIOFuncSSL = new CDavSocketIOSSL; + m_pszBuffer = new char[OI_SOCKBUFSIZE]; + m_pszBufPos = m_pszBuffer; + m_unContentLen = 0; + + //statistics + m_unReadCounter = 0; + m_unWriteCounter = 0; + //initialize socket and and io settings + init(); + initSSL(); + UseSSL(false); +} + +CDavSocket::~CDavSocket(void) +{ + cleanupSSL(); + cleanupSSLSession(); + Disconnect(); + destroySocket(); + delete m_pIOFuncRaw; + delete m_pIOFuncSSL; + delete[] m_pszBuffer; +} + +OI_RESULT +CDavSocket::init() +{ + //prevent this function from being called for more than once + if(m_bReady) return OISEINITIALIZED; +#ifdef WIN32 + WSADATA wsaData; + WORD wVersionRequested = MAKEWORD(OI_SOCK_VER_MINOR, + OI_SOCK_VER_MAJOR); + int nResult = WSAStartup(wVersionRequested, &wsaData); + if(nResult != 0) + return OISEINITFAILED; + + if(LOBYTE(wsaData.wVersion) != OI_SOCK_VER_MINOR + || HIBYTE(wsaData.wVersion) != OI_SOCK_VER_MAJOR){ + WSACleanup(); + return OISESOCKVER; + } +#endif /* WIN32 */ + m_bReady = true; + return initSSL(); +} + +OI_RESULT +CDavSocket::initSSL() +{ + m_pSSL = NULL; + m_pSSLSession = NULL; + m_pServerCertificate= NULL; + return OI_OK; +} + + +OI_RESULT +CDavSocket::destroySocket() +{ + if(!m_bReady) + return OI_OK; +#ifdef WIN32 + //winsock needs this to clear the TIME_WAIT state + shutdown(m_hSocket, SD_BOTH); + int nResult = WSACleanup(); + if(nResult != 0) + return OISECLEANUPFAILED; +#endif /* WIN32 */ + m_bReady = false; + return OI_OK; +} + +OI_RESULT +CDavSocket::connect(const struct sockaddr* pSockaddr, + int nSockaddrLen) +{ + int nError; + m_hSocket = (int)socket(AF_INET, SOCK_STREAM, 0); + if(m_hSocket == ONION_INVALIDSOCKET) + return OISEINVALIDSOCK; + nError = ::connect(m_hSocket, pSockaddr, nSockaddrLen); + if(nError){ + //TODO: error code processing + /* + int nWSAError = WSAGetLastError(); + switch(nWSAError) + { + case WSAETIMEDOUT: + return OISETIMEOUT; + break; + } + */ + Disconnect(); + return OISECONNFAILED; + } + m_bConnected = true; + return OI_OK; +} + +void +CDavSocket::Disconnect() +{ + if(m_hSocket > 0){ + ResetBuffer(); + ONION_CLOSE(m_hSocket); + m_bConnected = false; + m_hSocket = 0; + } +} + +void +CDavSocket::ResetBuffer() +{ + m_pszBufPos = m_pszBuffer; + m_unContentLen = 0; +} + + +void +CDavSocket::cleanupSSL() +{ + if(m_pSSL){ + SSL_shutdown(m_pSSL); + SSL_free(m_pSSL); + m_pSSL = NULL; + } +} + +/* + * release cached SSL_SESSION and set pointer to null. + * use this function in to reset session and cached + * server certificate whenever hostname/ssl mode changes + * or a connection is terminated + */ +void +CDavSocket::cleanupSSLSession() +{ + if(m_pSSLSession){ + SSL_SESSION_free(m_pSSLSession); + m_pSSLSession = NULL; + } + if(m_pServerCertificate){ + X509_free(m_pServerCertificate); + m_pServerCertificate = NULL; + } +} + +OI_RESULT +CDavSocket::connectSSL() +{ + cleanupSSL(); //free ssl connection and set pointer to NULL + + OI_ASSERT(g_pSSLCtx); + m_pSSL = SSL_new(g_pSSLCtx); + if(!m_pSSL) + return OIEEDATAINITFAILED; + + UseSSL(true); //setting the IO function + + SSL_set_mode(m_pSSL, SSL_MODE_AUTO_RETRY); + SSL_set_fd(m_pSSL, m_hSocket); + SSL_set_app_data(m_pSSL, (char*)this); + SSL_set_verify(m_pSSL, SSL_VERIFY_PEER, fnSSLVerifyCallback); + + //if(m_pSSLSession) + SSL_set_session(m_pSSL, m_pSSLSession); //resume last session. + + int nResult = SSL_connect(m_pSSL); + if(nResult != 1){ + OI_DEBUG("Error connecting via SSL: %s\n", + ERR_reason_error_string(ERR_get_error())); + ERR_clear_error(); + cleanupSSL(); + cleanupSSLSession(); + return OISEGEN; //TODO: better error code + } else { + if(!m_pSSLSession) + //cache the session(session reference is increamented) + m_pSSLSession = SSL_get1_session(m_pSSL); + } + + //check server certificate + X509* pServerCertificate = SSL_get_peer_certificate(m_pSSL); + if(!pServerCertificate){ + cleanupSSL(); + cleanupSSLSession(); + return OIEENOSERVERCERT; + } + + if(m_pServerCertificate){ + int nResult = X509_cmp(pServerCertificate, m_pServerCertificate); + X509_free(pServerCertificate); + if(nResult != 0){ + cleanupSSL(); + cleanupSSLSession(); + return OIEECERTCHANGED; //could be MITM attack + } + } + return OI_OK; +} + +bool +CDavSocket::UseSSL(bool bUse) +{ + bool bRet = IsUsingSSL(); + if(bUse) + m_pIOFunc = m_pIOFuncSSL; + else + m_pIOFunc = m_pIOFuncRaw; + ResetBuffer(); + return bRet; +} + +bool +CDavSocket::IsUsingSSL() +{ + return (m_pIOFunc == m_pIOFuncSSL); +} + +OI_RESULT +CDavSocket::Connect(const char* pszAddr, unsigned short usPort) +{ + sockaddr_in sockAddr; + + OI_ASSERT(pszAddr); + + memset(&sockAddr, 0, sizeof(sockAddr)); + + sockAddr.sin_family = AF_INET; + sockAddr.sin_addr.s_addr = inet_addr(pszAddr); + + if (sockAddr.sin_addr.s_addr == INADDR_NONE){ + hostent* pHost; + pHost = gethostbyname(pszAddr); + if (pHost){ + sockAddr.sin_addr.s_addr = ((in_addr*)pHost->h_addr)->s_addr; + } else { + //WSASetLastError(WSAEINVAL); + return OISEHOSTNOTFOUND; + } + } + sockAddr.sin_port = htons(usPort); + + return connect((sockaddr*)&sockAddr, sizeof(sockAddr)); +} + +int +CDavSocket::GetHandle() +{ + return m_hSocket; +} + +unsigned int +CDavSocket::GetTimeout() +{ + return m_unTimeout; +} + +void +CDavSocket::SetTimeout(unsigned int unTimeout) +{ + if(unTimeout > OI_SOCK_MAXTIMEOUTSEC) + m_unTimeout = OI_SOCK_MAXTIMEOUTSEC; + else + m_unTimeout = unTimeout; +} + +size_t +CDavSocket::GetReadBytes() +{ + return m_unReadCounter; +} + +size_t +CDavSocket::GetWrittenBytes() +{ + return m_unWriteCounter; +} + +CDavWorkSession* +CDavSocket::GetSession() +{ + return m_pSession; +} + +OI_RESULT +CDavSocket::Read(char *pszBuf, size_t *punReadLen) +{ + OI_ASSERT(pszBuf && punReadLen); + + OI_RESULT enuRet; + size_t unBufLen = *punReadLen; + size_t unBytes = unBufLen; + + if (m_unContentLen > 0){ + // Deliver buffered data. + if (unBufLen > m_unContentLen) + unBufLen = m_unContentLen; + memcpy(pszBuf, m_pszBufPos, unBufLen); + m_pszBufPos += unBufLen; + m_unContentLen -= unBufLen; + //save read length into the parameter + *punReadLen = unBufLen; + m_unReadCounter += unBufLen; + return OI_OK; + } else if (unBufLen >= OI_SOCKBUFSIZE){ + /* No need for read buffer. */ + enuRet = m_pIOFunc->Read(this, + pszBuf, + punReadLen, + m_unTimeout); + m_unReadCounter += *punReadLen; + return enuRet; + } else { + // the internal buffer is empty and + // external buffer is smaller + /* Fill read buffer. */ + OI_RESULT enuRet; + unBufLen = OI_SOCKBUFSIZE; + enuRet = m_pIOFunc->Read(this, + m_pszBuffer, + &unBufLen, + m_unTimeout); + + if (OI_OK != enuRet){ + *punReadLen = 0; + return enuRet; + } + if (unBytes > unBufLen) + unBytes = unBufLen; + memcpy(pszBuf, m_pszBuffer, unBytes); + m_pszBufPos = m_pszBuffer + unBytes; + m_unContentLen = unBufLen - unBytes; + //save read length into the parameter + *punReadLen = unBytes; + m_unReadCounter += unBytes; + return OI_OK; + } +} + +OI_RESULT +CDavSocket::ReadLine(char *pszBuf, size_t *punReadLen) +{ + char *pszLF; + size_t unLen; + size_t unBufLen = *punReadLen; + + if ((pszLF = (char*)memchr(m_pszBufPos, '\n', m_unContentLen)) == 0 + && m_unContentLen < OI_SOCKBUFSIZE){ + /* The buffered data does not contain a complete line: move it + * to the beginning of the buffer. */ + if (m_unContentLen > 0) + memmove(m_pszBuffer, m_pszBufPos, m_unContentLen); + m_pszBufPos = m_pszBuffer; + /* Loop filling the buffer whilst no newline is found in the data + * buffered so far, and there is still buffer space available */ + do { + /* Read more data onto end of buffer. */ + size_t unReadLen = OI_SOCKBUFSIZE - m_unContentLen; + OI_RESULT enuResult; + enuResult = m_pIOFunc->Read(this, + m_pszBuffer + m_unContentLen, + &unReadLen, + m_unTimeout); + + if (OI_OK != enuResult) + return enuResult; + m_unContentLen += unReadLen; + } while ((pszLF = (char*)memchr(m_pszBuffer, '\n', m_unContentLen)) == 0 + && m_unContentLen < OI_SOCKBUFSIZE); + } + + if (pszLF) + unLen = (size_t)(pszLF - m_pszBufPos + 1); + else + unLen = unBufLen; /* fall into "line too long" error... */ + + if ((unLen + 1) > unBufLen){ + return OISELINETOOLONG; + } + + memcpy(pszBuf, m_pszBufPos, unLen); + pszBuf[unLen] = '\0'; + /* consume the line from buffer: */ + m_unContentLen -= unLen; + m_pszBufPos += unLen; + *punReadLen = unLen; + m_unReadCounter += unLen; + return OI_OK; +} + +OI_RESULT +CDavSocket::FullRead(char *pszBuf, size_t *punReadLen) +{ + OI_RESULT enuRet; + size_t unBufLen = *punReadLen; + size_t unReadLen = unBufLen; + + while(unBufLen > 0){ + enuRet = Read(pszBuf, &unReadLen); + if(OI_OK != enuRet) + return enuRet; + + unBufLen -= unReadLen; + pszBuf += unReadLen; + } + return OI_OK; +} + +OI_RESULT +CDavSocket::Peek(char *pszBuf, size_t *punReadLen) +{ + size_t unBufLen = *punReadLen; + size_t unBytes; + OI_RESULT enuRet; + if (m_unContentLen){ + /* just return buffered data. */ + unBytes = m_unContentLen; + } else { + /* fill the buffer. */ + unBytes = OI_SOCKBUFSIZE; + enuRet = Read(m_pszBuffer, &unBytes); + if (OI_OK != enuRet) + return enuRet; + m_pszBufPos = m_pszBuffer; + m_unContentLen = unBytes; + } + + if (unBufLen > unBytes) + unBufLen = unBytes; + + memcpy(pszBuf, m_pszBufPos, unBufLen); + *punReadLen = unBufLen; + return OI_OK; +} + +OI_RESULT +CDavSocket::Write(const char *pszBuf, size_t *punWrittenLen) +{ + OI_ASSERT(pszBuf && punWrittenLen); + m_unWriteCounter += *punWrittenLen; + return m_pIOFunc->Write(this, pszBuf, punWrittenLen); +} + +/* + * just pass the parameters to work session, circumvent + * the protected method. pX509 should not be incremented + * before calling this function + */ +void +CDavSocket::AddUnauthenticCert(X509* pX509, unsigned long ulFailures) +{ + m_pSession->addUnauthenticCert(pX509, ulFailures); +} + Index: onion/src/RBPVDXmlSearch.cpp =================================================================== --- onion/src/RBPVDXmlSearch.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDXmlSearch.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for SEARCH method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlSearch.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CRBPVDXmlSearch::CRBPVDXmlSearch(): + CRBPVDXml(OI_XML_SEARCHDOCNAME) +{ +} + +CRBPVDXmlSearch::~CRBPVDXmlSearch() +{ +} Index: onion/src/DavSocketIORaw.cpp =================================================================== --- onion/src/DavSocketIORaw.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavSocketIORaw.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,154 @@ +/* + Raw socket I/O methods + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSocketIORaw.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif /* HAVE_SYS_SOCKET_H */ + +#include +#include +#include +#include + +CDavSocketIORaw::CDavSocketIORaw(void) +{ +} + +CDavSocketIORaw::~CDavSocketIORaw(void) +{ +} + +OI_RESULT +CDavSocketIORaw::Readable(CDavSocket* pSocket, int nSecs) +{ + int nRet; + fd_set rdfds; + int s = pSocket->GetHandle(); + struct timeval timeout, *tvp = (nSecs >= 0 ? &timeout : 0); + + /* Init the fd set */ + FD_ZERO(&rdfds); + do{ + FD_SET(s, &rdfds); + if (tvp){ + tvp->tv_sec = nSecs; + tvp->tv_usec = 0; + } + //the first parameter of "select" is IGNORED on Windows platforms + //it was merely here for compatibility with the past + nRet = ::select(s + 1, &rdfds, 0, 0, tvp); + } while (nRet < 0 && onion_errno == ONION_EINTR); + // MSDN said return value would be SOCKET_ERROR if select failed. + // Anyway, it is a negative value + if (nRet < 0){ + //TODO: better error handling + return OISEGEN; + } + if(nRet == 0){ + return OISETIMEOUT; + } else { + return OI_OK; + } +} + +OI_RESULT +CDavSocketIORaw::Read(CDavSocket* pSocket, + char* pszBuf, + size_t* punReadLen, + int nSecs) +{ + OI_RESULT enuRet; + int nBytes; + size_t unBufLen = *punReadLen; + int s = pSocket->GetHandle(); + enuRet = Readable(pSocket, nSecs); + if(OI_OK != enuRet) + return enuRet; + do{ + nBytes = ONION_READ(s, pszBuf, unBufLen); + } while(nBytes == ONION_SOCKERR + && onion_errno == ONION_EINTR); + + if(nBytes == 0){ + //pSocket->setError(OISECLOSED); + //??? add method to socket to relay? + pSocket->m_pSession->Disconnect(); + return OISECLOSED; + } else if(nBytes < 0) { + int nErrNo = onion_errno; + if(ONION_ISRESET(nErrNo)){ + return OISERESET; + } + return OISEGEN; + } else { + //TRACE("Rawread: %d chars read from raw socket\n", nBytes); + *punReadLen = nBytes; + return OI_OK; + } +} + +OI_RESULT +CDavSocketIORaw::Write(CDavSocket* pSocket, + const char* pszBuf, + size_t* punWrittenLen) +{ + OI_ASSERT(pszBuf && punWrittenLen); + + size_t unBufLen = *punWrittenLen; + int nBytes; + int s = pSocket->GetHandle(); + do{ + nBytes = ONION_WRITE(s, pszBuf, unBufLen); + pszBuf += nBytes; + unBufLen -= nBytes; + } while((nBytes > 0 || onion_errno == ONION_EINTR) && unBufLen > 0); + + if(nBytes < 0){ + int nErrNo = onion_errno; + pSocket->m_pSession->Disconnect(); + if(ONION_ISRESET(nErrNo)){ + return OISERESET; + } + /* + switch(nErrNo){ + case WSAECONNRESET: + return OISERESET; + case WSAECONNABORTED: + pSocket->m_pSession->Disconnect(); + return OISECONNABORTED; + default: + break; + } + */ + return OISEGEN; + } else { + *punWrittenLen = nBytes; + return OI_OK; + } +} + Index: onion/src/PBCSMXml.cpp =================================================================== --- onion/src/PBCSMXml.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/PBCSMXml.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,123 @@ +/* + Response body consumer that parses body as an XML stream + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMXml.cpp,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include +#include +#include + +CPBCSMXml::CPBCSMXml(CDavRequest* pReq, + const char* pszCutElement, + CDavXmlBuffer* pXmlReceiver): + CResponseBodyConsumer(pReq), + m_pXmlReceiver(pXmlReceiver) +{ + m_nResponseCounter = 0; + try{ + m_pErrorHandler = new CDavXmlErrorHandler; + m_pXmlParser = new CDavXmlParser(this, pszCutElement); + m_pXmlParser->setDoNamespaces(true); + m_pXmlParser->setIncludeIgnorableWhitespace(false); // optional + m_pXmlParser->setExitOnFirstFatalError(true); + m_pXmlParser->setErrorHandler(m_pErrorHandler); + } catch(...) { + } +} + +CPBCSMXml::~CPBCSMXml() +{ + try{ + delete m_pXmlParser; + delete m_pErrorHandler; + } catch(...) { + } +} + +void +CPBCSMXml::Close() +{ +} + +OI_RESULT +CPBCSMXml::Open() +{ + return OI_OK; +} + +OI_PBC_TYPE +CPBCSMXml::GetType() +{ + return T_PBC_XML; +} + +XNS(DOMDocument)* +CPBCSMXml::GetDocument() +{ + return m_pXmlParser->getDocument(); +} + +OI_RESULT +CPBCSMXml::CheckCType(const char* pszCType) +{ + OI_ASSERT(pszCType); + if(strncmp(pszCType, "text/xml", 7) == 0){ + return OI_OK; + } else { + return OIDECTYPEMISMATCH; + } +} + +OI_RESULT +CPBCSMXml::PullResponseBody(CDavResponseBody* pBody) +{ + CDavXmlInputSource inputSource(pBody); + try{ + m_pXmlParser->parse(inputSource); + //m_pXmlParser->parse("f:\\resp.xml"); + } catch(...) { + } + + OI_RESULT enuRet = pBody->m_enuLastErr; + OI_DEBUG("[ %d ] response(s) found \n", m_nResponseCounter); + return enuRet; +} + +void +CPBCSMXml::OnResponseFound(XNS(DOMNode)* pNode) +{ + ++ m_nResponseCounter; + if(m_pXmlReceiver){ + m_pXmlReceiver->AppendChild((XNS(DOMElement)*)pNode); + } else { + m_pRequest->m_pSession->OnResponseFound(m_pRequest, pNode); + } +} + Index: onion/src/RBPVDXmlMove.cpp =================================================================== --- onion/src/RBPVDXmlMove.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDXmlMove.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for MOVE method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlMove.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CRBPVDXmlMove::CRBPVDXmlMove(): + CRBPVDXml(OI_XML_MOVEDOCNAME) +{ +} + +CRBPVDXmlMove::~CRBPVDXmlMove(void) +{ +} Index: onion/src/DavXmlInputStream.cpp =================================================================== --- onion/src/DavXmlInputStream.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavXmlInputStream.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,54 @@ +/* + Input stream needed by input source + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavXmlInputStream.cpp,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +CDavXmlInputStream::CDavXmlInputStream(CDavResponseBody* pBody): + m_pBody(pBody), + m_unByteCounter(0) +{ +} + +CDavXmlInputStream::~CDavXmlInputStream() +{ +} + +unsigned int +CDavXmlInputStream::readBytes(XMLByte* const toFill, + const unsigned int maxToRead) +{ + unsigned int unBytes = m_pBody->Read((unsigned char*)toFill, maxToRead); + m_unByteCounter += unBytes; + return unBytes; +} + +unsigned int +CDavXmlInputStream::curPos() const +{ + return m_unByteCounter; +} + Index: onion/src/config_win.h =================================================================== Index: onion/src/PBCSMAuthBasic.cpp =================================================================== --- onion/src/PBCSMAuthBasic.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/PBCSMAuthBasic.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,82 @@ +/* + Response body consumer in case of basic authentication + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: PBCSMAuthBasic.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include + +CPBCSMAuthBasic::CPBCSMAuthBasic(CDavRequest* pReq): + CResponseBodyConsumer(pReq) +{ +} + +CPBCSMAuthBasic::~CPBCSMAuthBasic() +{ +} + +void +CPBCSMAuthBasic::Close() +{ +} + +OI_RESULT +CPBCSMAuthBasic::Open() +{ + return OI_OK; +} + +OI_PBC_TYPE +CPBCSMAuthBasic::GetType() +{ + return T_PBC_DUMMY; +} + +OI_RESULT +CPBCSMAuthBasic::PullResponseBody(CDavResponseBody* pBody) +{ + OI_RESULT enuRet; + size_t unReadLen, unBufLen = OI_GENBUFSIZE; + bool bCLength = (pBody->m_enuMode == M_RSP_CLENGTH); + bool bContinue; + + char* pszBuf = m_pRequest->m_szBuffer; + for(enuRet = OI_RETRY; enuRet == OI_RETRY;){ + enuRet = pBody->Read(pszBuf, unBufLen, &unReadLen); + bContinue = m_pRequest->m_pSession->OnReceiveProgress(m_pRequest, + pBody->m_unReadLen, + pBody->m_unBodyLen, + bCLength); + if(!bContinue){ + m_pRequest->disconnect(); + return OI_USERCANCELED; + } + //unReadLen = OI_GENBUFSIZE; + } + return enuRet; +} + Index: onion/src/RBPVDDummy.cpp =================================================================== --- onion/src/RBPVDDummy.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDDummy.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,77 @@ +/* + Request body provider that provides nothing + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDDummy.cpp,v 1.1.1.1 2004/07/15 06:58:44 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CRBPVDDummy::CRBPVDDummy() +{ +} + +CRBPVDDummy::~CRBPVDDummy() +{ +} + +OI_RBP_TYPE +CRBPVDDummy::GetType() +{ + return T_RBP_DUMMY; +} + +void +CRBPVDDummy::Close() +{ +} + +OI_RESULT +CRBPVDDummy::Open() +{ + return OI_OK; +} + +OI_RESULT +CRBPVDDummy::Rewind() +{ + return OI_OK; +} + +size_t +CRBPVDDummy::GetBodyLength() +{ + return 0; +} + +void +CRBPVDDummy::OnCancel(CDavRequest* pReq) +{ +} + +OI_RESULT +CRBPVDDummy::Read(CDavRequest* pReq, char* pszBuf, size_t* punReadLen) +{ + return OI_OK; +} + Index: onion/src/RBPVDXmlCopy.cpp =================================================================== --- onion/src/RBPVDXmlCopy.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/RBPVDXmlCopy.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,37 @@ +/* + Request body provider that provides XML for COPY method + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: RBPVDXmlCopy.cpp,v 1.1.1.1 2004/07/15 06:58:46 jiang_lei Exp $ +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +CRBPVDXmlCopy::CRBPVDXmlCopy(): + CRBPVDXml(OI_XML_COPYDOCNAME) +{ +} + +CRBPVDXmlCopy::~CRBPVDXmlCopy() +{ +} Index: onion/src/DavSocketIOSSL.cpp =================================================================== --- onion/src/DavSocketIOSSL.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/DavSocketIOSSL.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,159 @@ +/* + SSL socket I/O methods + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: DavSocketIOSSL.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include + +CDavSocketIOSSL::CDavSocketIOSSL(void) +{ +} + +CDavSocketIOSSL::~CDavSocketIOSSL(void) +{ +} + +OI_RESULT +CDavSocketIOSSL::ossl_error(CDavSocket *pSocket, int nErrCode) +{ + int nErr = SSL_get_error(pSocket->m_pSSL, nErrCode); + OI_RESULT enuRet = OISEGEN; + + switch (nErr){ + case SSL_ERROR_ZERO_RETURN: + enuRet = OISECLOSED; + break; + case SSL_ERROR_SYSCALL: + nErr = ERR_get_error(); + if (nErr == 0){ + if (nErrCode == 0){ + /* EOF without close_notify, possible truncation */ + enuRet = OISETRUNC; + } else { + /* Other socket error. */ + //nErr = WSAGetLastError(); + enuRet = OISEGEN; + } + } else { + enuRet = OIEEGENERIC; + } + break; + default: + enuRet = OIEEGENERIC; + break; + } + return enuRet; +} + +OI_RESULT +CDavSocketIOSSL::Readable(CDavSocket* pSocket, int nSecs) +{ + if(pSocket->m_pSSL){ + if(SSL_pending(pSocket->m_pSSL)){ + return OI_OK; + } + } + + ///////////////////////////////////////////////////////////// + // The following part is same as that of readable_raw() + ///////////////////////////////////////////////////////////// + int nRet; + fd_set rdfds; + int s = pSocket->GetHandle(); + struct timeval timeout, *tvp = (nSecs >= 0 ? &timeout : 0); + + /* Init the fd set */ + FD_ZERO(&rdfds); + do{ + FD_SET(s, &rdfds); + if (tvp){ + tvp->tv_sec = nSecs; + tvp->tv_usec = 0; + } + //the first parameter of "select" is IGNORED on Windows platforms + //it was merely here for compatibility with the past + nRet = ::select(s + 1, &rdfds, 0, 0, tvp); + } while (nRet < 0 && onion_errno == ONION_EINTR); + // MSDN said return value would be SOCKET_ERROR if select failed. + // Anyway, it is a negative value + if (nRet < 0){ + //TODO:more error codes + return OISEGEN; + } + if(nRet == 0){ + return OISETIMEOUT; + } else { + return OI_OK; + } +} + +OI_RESULT +CDavSocketIOSSL::Read(CDavSocket* pSocket, + char* pszBuf, + size_t* punReadLen, + int nSecs) +{ + OI_RESULT enuRet; + int nBytes; + int unBufLen = (int)(*punReadLen); + int s = pSocket->GetHandle(); + enuRet = Readable(pSocket, nSecs); + if(OI_OK != enuRet) + return enuRet; + + + nBytes = SSL_read(pSocket->m_pSSL, pszBuf, unBufLen); + if(nBytes <= 0){ + enuRet = ossl_error(pSocket, nBytes); + pSocket->m_pSession->Disconnect(); + } else { + enuRet = OI_OK; + *punReadLen = nBytes; + } + return enuRet; +} + +OI_RESULT +CDavSocketIOSSL::Write(CDavSocket* pSocket, + const char* pszBuf, + size_t* punWrittenLen) +{ + OI_ASSERT(pszBuf && punWrittenLen); + int nBufLen = (int)(*punWrittenLen); + int nBytes = SSL_write(pSocket->m_pSSL, pszBuf, nBufLen); + /* ssl.h says SSL_MODE_ENABLE_PARTIAL_WRITE must be enabled to + * have SSL_write return < length... so, SSL_write should never + * return < length. */ + if (nBytes != nBufLen){ + pSocket->m_pSession->Disconnect(); + return ossl_error(pSocket, nBytes); + } else { + *punWrittenLen = nBytes; + return OI_OK; + } +} + Index: onion/src/HandlerProxyConn.cpp =================================================================== --- onion/src/HandlerProxyConn.cpp (.../vendor/psi/psi-0.10) (revision 0) +++ onion/src/HandlerProxyConn.cpp (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,57 @@ +/* + Http header handler for "Proxy-Connection" + Copyright (C) 2003-2004, Lei Jiang + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + + $Id: HandlerProxyConn.cpp,v 1.1.1.1 2004/07/15 06:58:45 jiang_lei Exp $ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include + +CHandlerProxyConn::CHandlerProxyConn(void) +{ +} + +CHandlerProxyConn::~CHandlerProxyConn(void) +{ +} + + +bool +CHandlerProxyConn::Execute(CDavRequest* pReq, const char *pszValue) +{ + char szClose[] = "close"; + char szKeepAlive[] = "Keep-Alive"; + if(strnicmp(pszValue, szClose, sizeof(szClose) - 1) == 0){ + pReq->SetPersistent(false); + } else if(strnicmp(pszValue, szKeepAlive, sizeof(szKeepAlive) - 1) == 0) { + pReq->SetPersistent(true); + } + return true; +} + +const char* +CHandlerProxyConn::GetHeaderName() +{ + return OI_RSPHDR_PROXYCONN; +} + Index: onion/onion.pri =================================================================== --- onion/onion.pri (.../vendor/psi/psi-0.10) (revision 0) +++ onion/onion.pri (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,125 @@ +DEFINES += HAVE_CONFIG_H + +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/src/config.h \ + $$PWD/onion/IDavSocketIO.h \ + $$PWD/onion/OnionCfg.h \ + $$PWD/onion/OnionDef.h \ + $$PWD/onion/OnionTypes.h \ + $$PWD/onion/DavAuthManager.h \ + $$PWD/onion/DavAuthSession.h \ + $$PWD/onion/DavHost.h \ + $$PWD/onion/DavHttpStatus.h \ + $$PWD/onion/DavLock.h \ + $$PWD/onion/DavMemBuffer.h \ + $$PWD/onion/DavRequest.h \ + $$PWD/onion/DavResourceNode.h \ + $$PWD/onion/DavResponseBody.h \ + $$PWD/onion/DavServerPolicy.h \ + $$PWD/onion/DavSession.h \ + $$PWD/onion/DavSocket.h \ + $$PWD/onion/DavSocketIORaw.h \ + $$PWD/onion/DavSocketIOSSL.h \ + $$PWD/onion/DavSSLCertificate.h \ + $$PWD/onion/DavSSLCertificateList.h \ + $$PWD/onion/DavSSLDNameField.h \ + $$PWD/onion/DavSSLDName.h \ + $$PWD/onion/DavWorkSession.h \ + $$PWD/onion/DavXmlBuffer.h \ + $$PWD/onion/DavXmlErrorHandler.h \ + $$PWD/onion/DavXmlInputSource.h \ + $$PWD/onion/DavXmlInputStream.h \ + $$PWD/onion/DavXmlParser.h \ + $$PWD/onion/HandlerAuth.h \ + $$PWD/onion/HandlerAllow.h \ + $$PWD/onion/HandlerMSV.h \ + $$PWD/onion/HandlerAuthInfo.h \ + $$PWD/onion/HandlerCLength.h \ + $$PWD/onion/HandlerConn.h \ + $$PWD/onion/HandlerCType.h \ + $$PWD/onion/HandlerDASL.h \ + $$PWD/onion/HandlerDAV.h \ + $$PWD/onion/HandlerKeepAlive.h \ + $$PWD/onion/HandlerProxyConn.h \ + $$PWD/onion/HandlerServer.h \ + $$PWD/onion/HandlerTE.h \ + $$PWD/onion/PBCSMAuthBasic.h \ + $$PWD/onion/PBCSMAuthDigest.h \ + $$PWD/onion/PBCSMDummy.h \ + $$PWD/onion/PBCSMLocalFile.h \ + $$PWD/onion/PBCSMMemBuffer.h \ + $$PWD/onion/PBCSMXml.h \ + $$PWD/onion/RBPVDDummy.h \ + $$PWD/onion/RBPVDLocalFile.h \ + $$PWD/onion/RBPVDXmlCopy.h \ + $$PWD/onion/RBPVDXml.h \ + $$PWD/onion/RBPVDXmlLock.h \ + $$PWD/onion/RBPVDXmlMove.h \ + $$PWD/onion/RBPVDXmlPropfind.h \ + $$PWD/onion/RBPVDXmlProppatch.h \ + $$PWD/onion/RBPVDXmlSearch.h \ + $$PWD/onion/RequestBodyProvider.h \ + $$PWD/onion/ResponseBodyConsumer.h \ + $$PWD/onion/ResponseHeaderHandler.h \ + $$PWD/onion/Utils.h + +SOURCES += \ + $$PWD/src/DavAuthManager.cpp \ + $$PWD/src/DavAuthSession.cpp \ + $$PWD/src/DavHost.cpp \ + $$PWD/src/DavHttpStatus.cpp \ + $$PWD/src/DavLock.cpp \ + $$PWD/src/DavMemBuffer.cpp \ + $$PWD/src/DavRequest.cpp \ + $$PWD/src/DavResourceNode.cpp \ + $$PWD/src/DavResponseBody.cpp \ + $$PWD/src/DavServerPolicy.cpp \ + $$PWD/src/DavSession.cpp \ + $$PWD/src/DavSocket.cpp \ + $$PWD/src/DavSocketIORaw.cpp \ + $$PWD/src/DavSocketIOSSL.cpp \ + $$PWD/src/DavSSLCertificate.cpp \ + $$PWD/src/DavSSLCertificateList.cpp \ + $$PWD/src/DavSSLDName.cpp \ + $$PWD/src/DavSSLDNameField.cpp \ + $$PWD/src/DavWorkSession.cpp \ + $$PWD/src/DavXmlBuffer.cpp \ + $$PWD/src/DavXmlErrorHandler.cpp \ + $$PWD/src/DavXmlInputSource.cpp \ + $$PWD/src/DavXmlInputStream.cpp \ + $$PWD/src/DavXmlParser.cpp \ + $$PWD/src/HandlerAuth.cpp \ + $$PWD/src/HandlerAllow.cpp \ + $$PWD/src/HandlerMSV.cpp \ + $$PWD/src/HandlerAuthInfo.cpp \ + $$PWD/src/HandlerCLength.cpp \ + $$PWD/src/HandlerConn.cpp \ + $$PWD/src/HandlerCType.cpp \ + $$PWD/src/HandlerDASL.cpp \ + $$PWD/src/HandlerDAV.cpp \ + $$PWD/src/HandlerKeepAlive.cpp \ + $$PWD/src/HandlerProxyConn.cpp \ + $$PWD/src/HandlerServer.cpp \ + $$PWD/src/HandlerTE.cpp \ + $$PWD/src/PBCSMAuthBasic.cpp \ + $$PWD/src/PBCSMAuthDigest.cpp \ + $$PWD/src/PBCSMDummy.cpp \ + $$PWD/src/PBCSMLocalFile.cpp \ + $$PWD/src/PBCSMMemBuffer.cpp \ + $$PWD/src/PBCSMXml.cpp \ + $$PWD/src/RBPVDDummy.cpp \ + $$PWD/src/RBPVDLocalFile.cpp \ + $$PWD/src/RBPVDXmlCopy.cpp \ + $$PWD/src/RBPVDXml.cpp \ + $$PWD/src/RBPVDXmlLock.cpp \ + $$PWD/src/RBPVDXmlMove.cpp \ + $$PWD/src/RBPVDXmlPropfind.cpp \ + $$PWD/src/RBPVDXmlSearch.cpp \ + $$PWD/src/RBPVDXmlProppatch.cpp \ + $$PWD/src/RequestBodyProvider.cpp \ + $$PWD/src/ResponseBodyConsumer.cpp \ + $$PWD/src/ResponseHeaderHandler.cpp \ + $$PWD/src/Utils.cpp + Index: autopackage/default.apspec =================================================================== --- autopackage/default.apspec (.../vendor/psi/psi-0.10) (revision 0) +++ autopackage/default.apspec (.../trunk/im/psi-0.10) (revision 39233) @@ -0,0 +1,95 @@ +# -*-shell-script-*- + +# +# This is an example specfile. Delete these comments when you're done. +# + +[Meta] +RootName: @barracuda.com/imclient:2.2.5 +DisplayName: Barracuda IM Client +ShortName: barracudaim +Maintainer: Justin Karneges +Packager: Justin Karneg