home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kabc / ldif.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  6.0 KB  |  183 lines

  1. /*
  2.     This file is part of libkabc.
  3.     Copyright (c) 2004 Szombathelyi Gyorgy <gyurco@freemail.hu>
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General  Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef _K_LDIF_H_
  22. #define _K_LDIF_H_
  23.  
  24. #include <qstring.h>
  25. #include <qcstring.h>
  26. #include <qmemarray.h>
  27.  
  28. #include <kdelibs_export.h>
  29.  
  30. namespace KABC {
  31.  
  32.   /**
  33.    * LDIF
  34.  
  35.    * LDIF implements an RFC 2849 compliant LDIF parser. LDIF files are used to
  36.    * represent directory information on LDAP-based servers, or to describe a set
  37.    * of changes which are to be applied to a directory. 
  38.    */
  39.  
  40.   class KABC_EXPORT LDIF 
  41.   {
  42.   public:
  43.  
  44.     enum ParseVal{ None, NewEntry, EndEntry, Item, Control, Err, MoreData };
  45.     enum EntryType{ Entry_None, Entry_Add, Entry_Del, Entry_Mod, Entry_Modrdn };
  46.     enum ModType{ Mod_None, Mod_Add, Mod_Replace, Mod_Del };
  47.     LDIF();
  48.     virtual ~LDIF();
  49.     
  50.     /**
  51.      * Assembles fieldname and value into a valid LDIF line, BASE64 encodes the 
  52.      * value if neccessary and optionally splits into more lines.
  53.      * @param fieldname The name of the entry.
  54.      * @param value The value of the entry.
  55.      * @param linelen Maximum length of the lines in the result.
  56.      * @param url If true, encode value as url ( use :< ).
  57.      */
  58.     static QCString assembleLine( const QString &fieldname, 
  59.       const QByteArray &value, uint linelen=0, bool url=false );
  60.     /**
  61.      * This is the same as the above function, the only difference that 
  62.      * this accepts QCString as the value.
  63.      */
  64.     static QCString assembleLine( const QString &fieldname, 
  65.       const QCString &value, uint linelen=0, bool url=false );
  66.     /**
  67.      * This is the same as the above function, the only difference that 
  68.      * this accepts QString as the value.
  69.      */
  70.     static QCString assembleLine( const QString &fieldname, 
  71.       const QString &value, uint linelen=0, bool url=false );
  72.       
  73.     /**
  74.      * Splits one line from an LDIF file to attribute and value components.
  75.      * @returns true if value is an URL, false otherwise
  76.      */
  77.     static bool splitLine( const QCString &line, QString &fieldname, QByteArray &value );
  78.     /**
  79.      * Splits a control specification (without the "control:" directive)
  80.      * @param line is the control directive
  81.      * @param oid will contain the OID
  82.      * @param critical will contain the criticality of control
  83.      * @param value is the control value
  84.      */
  85.     static bool splitControl( const QCString &line, QString &oid, bool &critical,
  86.       QByteArray &value );
  87.     /**
  88.      * Starts the parsing of a new LDIF
  89.      */
  90.     void startParsing();
  91.     /**
  92.      * Process one LDIF line
  93.      */
  94.     ParseVal processLine();
  95.     /**
  96.      * Process the LDIF until a complete item can be returned
  97.      * @returns NewEntry if a new DN encountered, 
  98.      * Item if a new item returned, 
  99.      * Err if the LDIF contains error,
  100.      * EndEntry if the parser reached the end of the current entry
  101.      * and MoreData if the parser encountered the end of the current chunk of 
  102.      * the LDIF. If you want to finish the parsing after receiving 
  103.      * MoreData, then call endLDIF(), so the parser can safely flush 
  104.      * the current entry.
  105.      */
  106.     ParseVal nextItem();
  107.     /**
  108.      * Sets a chunk of LDIF. Call before startParsing(), or if nextItem() returned
  109.      * MoreData.
  110.      */
  111.     void setLDIF( const QByteArray &ldif ) { mLdif = ldif; mPos = 0; }
  112.     /**
  113.       * Indicates the end of the LDIF file/stream. Call if nextItem() returned
  114.       * MoreData, but actually you don't have more data.
  115.       */
  116.     void endLDIF();
  117.     /**
  118.      * Returns the requested LDAP operation extracted from the current entry.
  119.      */
  120.     EntryType entryType() const { return mEntryType; }
  121.     /**
  122.      * Returns the LDAP modify request type if entryType() returned Entry_Mod.
  123.      */
  124.     int modType() const { return mModType; }
  125.     /**
  126.      * Returns the Distinguished Name of the current entry.
  127.      */
  128.     const QString& dn() const { return mDn; }
  129.     /**
  130.      * Returns the new Relative Distinguished Name if modType() returned Entry_Modrdn.
  131.      */
  132.     const QString& newRdn() const { return mNewRdn; }
  133.     /**
  134.      * Returns the new parent of the entry if modType() returned Entry_Modrdn.
  135.      */
  136.     const QString& newSuperior() const { return mNewSuperior; }
  137.     /**
  138.      * Returns if the delete of the old RDN is required.
  139.      */
  140.     bool delOldRdn() const { return mDelOldRdn; }
  141.     /**
  142.      * Returns the attribute name.
  143.      */
  144.     const QString& attr() const { return mAttr; }
  145.     /**
  146.      * Returns the attribute value.
  147.      */
  148.     const QByteArray& val() const { return mVal; }
  149.     /**
  150.      * Returns if val() is an url
  151.      */
  152.     bool isUrl() const { return mUrl; }
  153.     /**
  154.      * Returns the criticality level when modType() returned Control.
  155.      */
  156.     bool critical() const { return mCritical; }
  157.     /**
  158.      * Returns the OID when modType() returned Control.
  159.      */
  160.     const QString& oid() const { return mOid; }
  161.     /**
  162.      * Returns the line number which the parser processes.
  163.      */
  164.     uint lineNo() const { return mLineNo; }
  165.   private:
  166.     int mModType;
  167.     bool mDelOldRdn, mUrl;
  168.     QString mDn,mAttr,mNewRdn,mNewSuperior, mOid;
  169.     QByteArray mLdif, mVal;
  170.     EntryType mEntryType;
  171.     
  172.     bool mIsNewLine, mIsComment,mCritical;
  173.     ParseVal mLastParseVal;
  174.     uint mPos,mLineNo;  
  175.     QCString line;
  176.         
  177.     class LDIFPrivate;
  178.     LDIFPrivate *d;
  179.   };
  180. }
  181.  
  182. #endif
  183.