passwordmaker-cli-1.5.orig/0000755000000000000000000000000011552315352014445 5ustar rootrootpasswordmaker-cli-1.5.orig/tinystr.cpp0000755000000000000000000000505411545725573016710 0ustar rootroot/* www.sourceforge.net/projects/tinyxml Original file by Yves Berquin. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* * THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005. */ #include "stdafx.h" #ifndef TIXML_USE_STL #include "tinystr.h" // Error value for find primitive const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1); // Null rep. TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, '\0' }; void TiXmlString::reserve (size_type cap) { if (cap > capacity()) { TiXmlString tmp; tmp.init(length(), cap); memcpy(tmp.start(), data(), length()); swap(tmp); } } TiXmlString& TiXmlString::assign(const char* str, size_type len) { size_type cap = capacity(); if (len > cap || cap > 3*(len + 8)) { TiXmlString tmp; tmp.init(len); memcpy(tmp.start(), str, len); swap(tmp); } else { memmove(start(), str, len); set_size(len); } return *this; } TiXmlString& TiXmlString::append(const char* str, size_type len) { size_type newsize = length() + len; if (newsize > capacity()) { reserve (newsize + capacity()); } memmove(finish(), str, len); set_size(newsize); return *this; } TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) { TiXmlString tmp; tmp.reserve(a.length() + b.length()); tmp += a; tmp += b; return tmp; } TiXmlString operator + (const TiXmlString & a, const char* b) { TiXmlString tmp; TiXmlString::size_type b_len = static_cast( strlen(b) ); tmp.reserve(a.length() + b_len); tmp += a; tmp.append(b, b_len); return tmp; } TiXmlString operator + (const char* a, const TiXmlString & b) { TiXmlString tmp; TiXmlString::size_type a_len = static_cast( strlen(a) ); tmp.reserve(a_len + b.length()); tmp.append(a, a_len); tmp += b; return tmp; } #endif // TIXML_USE_STL passwordmaker-cli-1.5.orig/mingw/0000755000000000000000000000000011552315352015566 5ustar rootrootpasswordmaker-cli-1.5.orig/mingw/depends0000755000000000000000000000000011545725573017140 0ustar rootrootpasswordmaker-cli-1.5.orig/tinyxml.h0000755000000000000000000014716011545725573016352 0ustar rootroot/* www.sourceforge.net/projects/tinyxml Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef TINYXML_INCLUDED #define TINYXML_INCLUDED #ifdef _MSC_VER #pragma warning( push ) #pragma warning( disable : 4530 ) #pragma warning( disable : 4786 ) #endif #include #include #include #include #include // Help out windows: #if defined( _DEBUG ) && !defined( DEBUG ) #define DEBUG #endif #if defined( DEBUG ) && defined( _MSC_VER ) #include #define TIXML_LOG OutputDebugString #else #define TIXML_LOG printf #endif #ifdef TIXML_USE_STL #include #include #define TIXML_STRING std::string #define TIXML_ISTREAM std::istream #define TIXML_OSTREAM std::ostream #else #include "tinystr.h" #define TIXML_STRING TiXmlString #define TIXML_OSTREAM TiXmlOutStream #endif // Deprecated library function hell. Compilers want to use the // new safe versions. This probably doesn't fully address the problem, // but it gets closer. There are too many compilers for me to fully // test. If you get compilation troubles, undefine TIXML_SAFE #define TIXML_SAFE // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress. #ifdef TIXML_SAFE #if defined(_MSC_VER) && (_MSC_VER >= 1200 ) // Microsoft visual studio, version 6 and higher. //#pragma message( "Using _sn* functions." ) #define TIXML_SNPRINTF _snprintf #define TIXML_SNSCANF _snscanf #elif defined(__GNUC__) && (__GNUC__ >= 3 ) // GCC version 3 and higher.s //#warning( "Using sn* functions." ) #define TIXML_SNPRINTF snprintf #define TIXML_SNSCANF snscanf #endif #endif class TiXmlDocument; class TiXmlElement; class TiXmlComment; class TiXmlUnknown; class TiXmlAttribute; class TiXmlText; class TiXmlDeclaration; class TiXmlParsingData; const int TIXML_MAJOR_VERSION = 2; const int TIXML_MINOR_VERSION = 4; const int TIXML_PATCH_VERSION = 2; /* Internal structure for tracking location of items in the XML file. */ struct TiXmlCursor { TiXmlCursor() { Clear(); } void Clear() { row = col = -1; } int row; // 0 based. int col; // 0 based. }; // Only used by Attribute::Query functions enum { TIXML_SUCCESS, TIXML_NO_ATTRIBUTE, TIXML_WRONG_TYPE }; // Used by the parsing routines. enum TiXmlEncoding { TIXML_ENCODING_UNKNOWN, TIXML_ENCODING_UTF8, TIXML_ENCODING_LEGACY }; const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; /** TiXmlBase is a base class for every class in TinyXml. It does little except to establish that TinyXml classes can be printed and provide some utility functions. In XML, the document and elements can contain other elements and other types of nodes. @verbatim A Document can contain: Element (container or leaf) Comment (leaf) Unknown (leaf) Declaration( leaf ) An Element can contain: Element (container or leaf) Text (leaf) Attributes (not on tree) Comment (leaf) Unknown (leaf) A Decleration contains: Attributes (not on tree) @endverbatim */ class TiXmlBase { friend class TiXmlNode; friend class TiXmlElement; friend class TiXmlDocument; public: TiXmlBase() : userData(0) {} virtual ~TiXmlBase() {} /** All TinyXml classes can print themselves to a filestream. This is a formatted print, and will insert tabs and newlines. (For an unformatted stream, use the << operator.) */ virtual void Print( FILE* cfile, int depth ) const = 0; /** The world does not agree on whether white space should be kept or not. In order to make everyone happy, these global, static functions are provided to set whether or not TinyXml will condense all white space into a single space or not. The default is to condense. Note changing this values is not thread safe. */ static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } /// Return the current white space setting. static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } /** Return the position, in the original source file, of this node or attribute. The row and column are 1-based. (That is the first row and first column is 1,1). If the returns values are 0 or less, then the parser does not have a row and column value. Generally, the row and column value will be set when the TiXmlDocument::Load(), TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set when the DOM was created from operator>>. The values reflect the initial load. Once the DOM is modified programmatically (by adding or changing nodes and attributes) the new values will NOT update to reflect changes in the document. There is a minor performance cost to computing the row and column. Computation can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. @sa TiXmlDocument::SetTabSize() */ int Row() const { return location.row + 1; } int Column() const { return location.col + 1; } ///< See Row() void SetUserData( void* user ) { userData = user; } void* GetUserData() { return userData; } // Table that returs, for a given lead byte, the total number of bytes // in the UTF-8 sequence. static const int utf8ByteTable[256]; virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; enum { TIXML_NO_ERROR = 0, TIXML_ERROR, TIXML_ERROR_OPENING_FILE, TIXML_ERROR_OUT_OF_MEMORY, TIXML_ERROR_PARSING_ELEMENT, TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, TIXML_ERROR_READING_ELEMENT_VALUE, TIXML_ERROR_READING_ATTRIBUTES, TIXML_ERROR_PARSING_EMPTY, TIXML_ERROR_READING_END_TAG, TIXML_ERROR_PARSING_UNKNOWN, TIXML_ERROR_PARSING_COMMENT, TIXML_ERROR_PARSING_DECLARATION, TIXML_ERROR_DOCUMENT_EMPTY, TIXML_ERROR_EMBEDDED_NULL, TIXML_ERROR_PARSING_CDATA, TIXML_ERROR_STRING_COUNT }; protected: // See STL_STRING_BUG // Utility class to overcome a bug. class StringToBuffer { public: StringToBuffer( const TIXML_STRING& str ); ~StringToBuffer(); char* buffer; }; static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); inline static bool IsWhiteSpace( char c ) { return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); } virtual void StreamOut (TIXML_OSTREAM *) const = 0; #ifdef TIXML_USE_STL static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag ); static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag ); #endif /* Reads an XML name into the string provided. Returns a pointer just past the last character of the name, or 0 if the function has an error. */ static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding ); /* Reads text. Returns a pointer past the given end tag. Wickedly complex options, but it keeps the (sensitive) code in one place. */ static const char* ReadText( const char* in, // where to start TIXML_STRING* text, // the string read bool ignoreWhiteSpace, // whether to keep the white space const char* endTag, // what ends this text bool ignoreCase, // whether to ignore case in the end tag TiXmlEncoding encoding ); // the current encoding // If an entity has been found, transform it into a character. static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding ); // Get a character, while interpreting entities. // The length can be from 0 to 4 bytes. inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) { assert( p ); if ( encoding == TIXML_ENCODING_UTF8 ) { *length = utf8ByteTable[ *((unsigned char*)p) ]; assert( *length >= 0 && *length < 5 ); } else { *length = 1; } if ( *length == 1 ) { if ( *p == '&' ) return GetEntity( p, _value, length, encoding ); *_value = *p; return p+1; } else if ( *length ) { //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), // and the null terminator isn't needed for( int i=0; p[i] && i<*length; ++i ) { _value[i] = p[i]; } return p + (*length); } else { // Not valid text. return 0; } } // Puts a string to a stream, expanding entities as it goes. // Note this should not contian the '<', '>', etc, or they will be transformed into entities! static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out ); static void PutString( const TIXML_STRING& str, TIXML_STRING* out ); // Return true if the next characters in the stream are any of the endTag sequences. // Ignore case only works for english, and should only be relied on when comparing // to English words: StringEqual( p, "version", true ) is fine. static bool StringEqual( const char* p, const char* endTag, bool ignoreCase, TiXmlEncoding encoding ); static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; TiXmlCursor location; /// Field containing a generic user pointer void* userData; // None of these methods are reliable for any language except English. // Good for approximation, not great for accuracy. static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ); static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding ); inline static int ToLower( int v, TiXmlEncoding encoding ) { if ( encoding == TIXML_ENCODING_UTF8 ) { if ( v < 128 ) return tolower( v ); return v; } else { return tolower( v ); } } static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); private: TiXmlBase( const TiXmlBase& ); // not implemented. void operator=( const TiXmlBase& base ); // not allowed. struct Entity { const char* str; unsigned int strLength; char chr; }; enum { NUM_ENTITY = 5, MAX_ENTITY_LENGTH = 6 }; static Entity entity[ NUM_ENTITY ]; static bool condenseWhiteSpace; }; /** The parent class for everything in the Document Object Model. (Except for attributes). Nodes have siblings, a parent, and children. A node can be in a document, or stand on its own. The type of a TiXmlNode can be queried, and it can be cast to its more defined type. */ class TiXmlNode : public TiXmlBase { friend class TiXmlDocument; friend class TiXmlElement; public: #ifdef TIXML_USE_STL /** An input stream operator, for every class. Tolerant of newlines and formatting, but doesn't expect them. */ friend std::istream& operator >> (std::istream& in, TiXmlNode& base); /** An output stream operator, for every class. Note that this outputs without any newlines or formatting, as opposed to Print(), which includes tabs and new lines. The operator<< and operator>> are not completely symmetric. Writing a node to a stream is very well defined. You'll get a nice stream of output, without any extra whitespace or newlines. But reading is not as well defined. (As it always is.) If you create a TiXmlElement (for example) and read that from an input stream, the text needs to define an element or junk will result. This is true of all input streams, but it's worth keeping in mind. A TiXmlDocument will read nodes until it reads a root element, and all the children of that root element. */ friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); /// Appends the XML node or attribute to a std::string. friend std::string& operator<< (std::string& out, const TiXmlNode& base ); #else // Used internally, not part of the public API. friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base); #endif /** The types of XML nodes supported by TinyXml. (All the unsupported types are picked up by UNKNOWN.) */ enum NodeType { DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, DECLARATION, TYPECOUNT }; virtual ~TiXmlNode(); /** The meaning of 'value' changes for the specific type of TiXmlNode. @verbatim Document: filename of the xml file Element: name of the element Comment: the comment text Unknown: the tag contents Text: the text string @endverbatim The subclasses will wrap this function. */ const char *Value() const { return value.c_str (); } #ifdef TIXML_USE_STL /** Return Value() as a std::string. If you only use STL, this is more efficient than calling Value(). Only available in STL mode. */ const std::string& ValueStr() const { return value; } #endif /** Changes the value of the node. Defined as: @verbatim Document: filename of the xml file Element: name of the element Comment: the comment text Unknown: the tag contents Text: the text string @endverbatim */ void SetValue(const char * _value) { value = _value;} #ifdef TIXML_USE_STL /// STL std::string form. void SetValue( const std::string& _value ) { StringToBuffer buf( _value ); SetValue( buf.buffer ? buf.buffer : "" ); } #endif /// Delete all the children of this node. Does not affect 'this'. void Clear(); /// One step up the DOM. TiXmlNode* Parent() { return parent; } const TiXmlNode* Parent() const { return parent; } const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. TiXmlNode* FirstChild() { return firstChild; } const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. TiXmlNode* FirstChild( const char * value ); ///< The first child of this node with the matching 'value'. Will be null if none found. const TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. TiXmlNode* LastChild() { return lastChild; } const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. TiXmlNode* LastChild( const char * value ); #ifdef TIXML_USE_STL const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); } ///< STL std::string form. const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); } ///< STL std::string form. #endif /** An alternate way to walk the children of a node. One way to iterate over nodes is: @verbatim for( child = parent->FirstChild(); child; child = child->NextSibling() ) @endverbatim IterateChildren does the same thing with the syntax: @verbatim child = 0; while( child = parent->IterateChildren( child ) ) @endverbatim IterateChildren takes the previous child as input and finds the next one. If the previous child is null, it returns the first. IterateChildren will return null when done. */ const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const; TiXmlNode* IterateChildren( TiXmlNode* previous ); /// This flavor of IterateChildren searches for children with a particular 'value' const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const; TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ); #ifdef TIXML_USE_STL const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. #endif /** Add a new node related to this. Adds a child past the LastChild. Returns a pointer to the new object or NULL if an error occured. */ TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); /** Add a new node related to this. Adds a child past the LastChild. NOTE: the node to be added is passed by pointer, and will be henceforth owned (and deleted) by tinyXml. This method is efficient and avoids an extra copy, but should be used with care as it uses a different memory model than the other insert functions. @sa InsertEndChild */ TiXmlNode* LinkEndChild( TiXmlNode* addThis ); /** Add a new node related to this. Adds a child before the specified child. Returns a pointer to the new object or NULL if an error occured. */ TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ); /** Add a new node related to this. Adds a child after the specified child. Returns a pointer to the new object or NULL if an error occured. */ TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ); /** Replace a child of this node. Returns a pointer to the new object or NULL if an error occured. */ TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ); /// Delete a child of this node. bool RemoveChild( TiXmlNode* removeThis ); /// Navigate to a sibling node. const TiXmlNode* PreviousSibling() const { return prev; } TiXmlNode* PreviousSibling() { return prev; } /// Navigate to a sibling node. const TiXmlNode* PreviousSibling( const char * ) const; TiXmlNode* PreviousSibling( const char * ); #ifdef TIXML_USE_STL const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form. #endif /// Navigate to a sibling node. const TiXmlNode* NextSibling() const { return next; } TiXmlNode* NextSibling() { return next; } /// Navigate to a sibling node with the given 'value'. const TiXmlNode* NextSibling( const char * ) const; TiXmlNode* NextSibling( const char * ); /** Convenience function to get through elements. Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns 0 if there is not another element. */ const TiXmlElement* NextSiblingElement() const; TiXmlElement* NextSiblingElement(); /** Convenience function to get through elements. Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns 0 if there is not another element. */ const TiXmlElement* NextSiblingElement( const char * ) const; TiXmlElement* NextSiblingElement( const char * ); #ifdef TIXML_USE_STL const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. #endif /// Convenience function to get through elements. const TiXmlElement* FirstChildElement() const; TiXmlElement* FirstChildElement(); /// Convenience function to get through elements. const TiXmlElement* FirstChildElement( const char * value ) const; TiXmlElement* FirstChildElement( const char * value ); #ifdef TIXML_USE_STL const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. #endif /** Query the type (as an enumerated value, above) of this node. The possible types are: DOCUMENT, ELEMENT, COMMENT, UNKNOWN, TEXT, and DECLARATION. */ int Type() const { return type; } /** Return a pointer to the Document this node lives in. Returns null if not in a document. */ const TiXmlDocument* GetDocument() const; TiXmlDocument* GetDocument(); /// Returns true if this node has no children. bool NoChildren() const { return !firstChild; } const TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (const TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. const TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (const TiXmlElement*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. const TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (const TiXmlComment*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. const TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (const TiXmlUnknown*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. const TiXmlText* ToText() const { return ( this && type == TEXT ) ? (const TiXmlText*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. const TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (const TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. TiXmlDocument* ToDocument() { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. TiXmlElement* ToElement() { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. TiXmlComment* ToComment() { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. TiXmlUnknown* ToUnknown() { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. TiXmlText* ToText() { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. TiXmlDeclaration* ToDeclaration() { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. /** Create an exact duplicate of this node and return it. The memory must be deleted by the caller. */ virtual TiXmlNode* Clone() const = 0; protected: TiXmlNode( NodeType _type ); // Copy to the allocated object. Shared functionality between Clone, Copy constructor, // and the assignment operator. void CopyTo( TiXmlNode* target ) const; #ifdef TIXML_USE_STL // The real work of the input operator. virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0; #endif // Figure out what is at *p, and parse it. Returns null if it is not an xml node. TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); TiXmlNode* parent; NodeType type; TiXmlNode* firstChild; TiXmlNode* lastChild; TIXML_STRING value; TiXmlNode* prev; TiXmlNode* next; private: TiXmlNode( const TiXmlNode& ); // not implemented. void operator=( const TiXmlNode& base ); // not allowed. }; /** An attribute is a name-value pair. Elements have an arbitrary number of attributes, each with a unique name. @note The attributes are not TiXmlNodes, since they are not part of the tinyXML document object model. There are other suggested ways to look at this problem. */ class TiXmlAttribute : public TiXmlBase { friend class TiXmlAttributeSet; public: /// Construct an empty attribute. TiXmlAttribute() : TiXmlBase() { document = 0; prev = next = 0; } #ifdef TIXML_USE_STL /// std::string constructor. TiXmlAttribute( const std::string& _name, const std::string& _value ) { name = _name; value = _value; document = 0; prev = next = 0; } #endif /// Construct an attribute with a name and value. TiXmlAttribute( const char * _name, const char * _value ) { name = _name; value = _value; document = 0; prev = next = 0; } const char* Name() const { return name.c_str (); } ///< Return the name of this attribute. const char* Value() const { return value.c_str (); } ///< Return the value of this attribute. int IntValue() const; ///< Return the value of this attribute, converted to an integer. double DoubleValue() const; ///< Return the value of this attribute, converted to a double. /** QueryIntValue examines the value string. It is an alternative to the IntValue() method with richer error checking. If the value is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. A specialized but useful call. Note that for success it returns 0, which is the opposite of almost all other TinyXml calls. */ int QueryIntValue( int* _value ) const; /// QueryDoubleValue examines the value string. See QueryIntValue(). int QueryDoubleValue( double* _value ) const; void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. void SetValue( const char* _value ) { value = _value; } ///< Set the value. void SetIntValue( int _value ); ///< Set the value from an integer. void SetDoubleValue( double _value ); ///< Set the value from a double. #ifdef TIXML_USE_STL /// STL std::string form. void SetName( const std::string& _name ) { StringToBuffer buf( _name ); SetName ( buf.buffer ? buf.buffer : "error" ); } /// STL std::string form. void SetValue( const std::string& _value ) { StringToBuffer buf( _value ); SetValue( buf.buffer ? buf.buffer : "error" ); } #endif /// Get the next sibling attribute in the DOM. Returns null at end. const TiXmlAttribute* Next() const; TiXmlAttribute* Next(); /// Get the previous sibling attribute in the DOM. Returns null at beginning. const TiXmlAttribute* Previous() const; TiXmlAttribute* Previous(); bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; } /* Attribute parsing starts: first letter of the name returns: the next char after the value end quote */ virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); // Prints this Attribute to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; virtual void StreamOut( TIXML_OSTREAM * out ) const; // [internal use] // Set the document pointer so the attribute can report errors. void SetDocument( TiXmlDocument* doc ) { document = doc; } private: TiXmlAttribute( const TiXmlAttribute& ); // not implemented. void operator=( const TiXmlAttribute& base ); // not allowed. TiXmlDocument* document; // A pointer back to a document, for error reporting. TIXML_STRING name; TIXML_STRING value; TiXmlAttribute* prev; TiXmlAttribute* next; }; /* A class used to manage a group of attributes. It is only used internally, both by the ELEMENT and the DECLARATION. The set can be changed transparent to the Element and Declaration classes that use it, but NOT transparent to the Attribute which has to implement a next() and previous() method. Which makes it a bit problematic and prevents the use of STL. This version is implemented with circular lists because: - I like circular lists - it demonstrates some independence from the (typical) doubly linked list. */ class TiXmlAttributeSet { public: TiXmlAttributeSet(); ~TiXmlAttributeSet(); void Add( TiXmlAttribute* attribute ); void Remove( TiXmlAttribute* attribute ); const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } const TiXmlAttribute* Find( const char * name ) const; TiXmlAttribute* Find( const char * name ); private: //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element), //*ME: this class must be also use a hidden/disabled copy-constructor !!! TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute) TiXmlAttribute sentinel; }; /** The element is a container class. It has a value, the element name, and can contain other elements, text, comments, and unknowns. Elements also contain an arbitrary number of attributes. */ class TiXmlElement : public TiXmlNode { public: /// Construct an element. TiXmlElement (const char * in_value); #ifdef TIXML_USE_STL /// std::string constructor. TiXmlElement( const std::string& _value ); #endif TiXmlElement( const TiXmlElement& ); void operator=( const TiXmlElement& base ); virtual ~TiXmlElement(); /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. */ const char* Attribute( const char* name ) const; /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. If the attribute exists and can be converted to an integer, the integer value will be put in the return 'i', if 'i' is non-null. */ const char* Attribute( const char* name, int* i ) const; /** Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists. If the attribute exists and can be converted to an double, the double value will be put in the return 'd', if 'd' is non-null. */ const char* Attribute( const char* name, double* d ) const; /** QueryIntAttribute examines the attribute - it is an alternative to the Attribute() method with richer error checking. If the attribute is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE. If the attribute does not exist, then TIXML_NO_ATTRIBUTE is returned. */ int QueryIntAttribute( const char* name, int* _value ) const; /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). int QueryDoubleAttribute( const char* name, double* _value ) const; /// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). int QueryFloatAttribute( const char* name, float* _value ) const { double d; int result = QueryDoubleAttribute( name, &d ); if ( result == TIXML_SUCCESS ) { *_value = (float)d; } return result; } /** Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does. */ void SetAttribute( const char* name, const char * _value ); #ifdef TIXML_USE_STL const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); } const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); } const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); } int QueryIntAttribute( const std::string& name, int* _value ) const { return QueryIntAttribute( name.c_str(), _value ); } int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); } /// STL std::string form. void SetAttribute( const std::string& name, const std::string& _value ) { StringToBuffer n( name ); StringToBuffer v( _value ); if ( n.buffer && v.buffer ) SetAttribute (n.buffer, v.buffer ); } ///< STL std::string form. void SetAttribute( const std::string& name, int _value ) { StringToBuffer n( name ); if ( n.buffer ) SetAttribute (n.buffer, _value); } #endif /** Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does. */ void SetAttribute( const char * name, int value ); /** Sets an attribute of name to a given value. The attribute will be created if it does not exist, or changed if it does. */ void SetDoubleAttribute( const char * name, double value ); /** Deletes an attribute with the given name. */ void RemoveAttribute( const char * name ); #ifdef TIXML_USE_STL void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. #endif const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. TiXmlAttribute* FirstAttribute() { return attributeSet.First(); } const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. TiXmlAttribute* LastAttribute() { return attributeSet.Last(); } /** Convenience function for easy access to the text inside an element. Although easy and concise, GetText() is limited compared to getting the TiXmlText child and accessing it directly. If the first child of 'this' is a TiXmlText, the GetText() returns the character string of the Text node, else null is returned. This is a convenient method for getting the text of simple contained text: @verbatim This is text const char* str = fooElement->GetText(); @endverbatim 'str' will be a pointer to "This is text". Note that this function can be misleading. If the element foo was created from this XML: @verbatim This is text @endverbatim then the value of str would be null. The first child node isn't a text node, it is another element. From this XML: @verbatim This is text @endverbatim GetText() will return "This is ". WARNING: GetText() accesses a child node - don't become confused with the similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are safe type casts on the referenced node. */ const char* GetText() const; /// Creates a new Element and returns it - the returned element is a copy. virtual TiXmlNode* Clone() const; // Print the Element to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; /* Attribtue parsing starts: next char past '<' returns: next char past '>' */ virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); protected: void CopyTo( TiXmlElement* target ) const; void ClearThis(); // like clear, but initializes 'this' object as well // Used to be public [internal use] #ifdef TIXML_USE_STL virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); #endif virtual void StreamOut( TIXML_OSTREAM * out ) const; /* [internal use] Reads the "value" of the element -- another element, or text. This should terminate with the current end tag. */ const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding ); private: TiXmlAttributeSet attributeSet; }; /** An XML comment. */ class TiXmlComment : public TiXmlNode { public: /// Constructs an empty comment. TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {} TiXmlComment( const TiXmlComment& ); void operator=( const TiXmlComment& base ); virtual ~TiXmlComment() {} /// Returns a copy of this Comment. virtual TiXmlNode* Clone() const; /// Write this Comment to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; /* Attribtue parsing starts: at the ! of the !-- returns: next char past '>' */ virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); protected: void CopyTo( TiXmlComment* target ) const; // used to be public #ifdef TIXML_USE_STL virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); #endif virtual void StreamOut( TIXML_OSTREAM * out ) const; private: }; /** XML text. A text node can have 2 ways to output the next. "normal" output and CDATA. It will default to the mode it was parsed from the XML file and you generally want to leave it alone, but you can change the output mode with SetCDATA() and query it with CDATA(). */ class TiXmlText : public TiXmlNode { friend class TiXmlElement; public: /** Constructor for text element. By default, it is treated as normal, encoded text. If you want it be output as a CDATA text element, set the parameter _cdata to 'true' */ TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT) { SetValue( initValue ); cdata = false; } virtual ~TiXmlText() {} #ifdef TIXML_USE_STL /// Constructor. TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT) { SetValue( initValue ); cdata = false; } #endif TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); } void operator=( const TiXmlText& base ) { base.CopyTo( this ); } /// Write this text object to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; /// Queries whether this represents text using a CDATA section. bool CDATA() { return cdata; } /// Turns on or off a CDATA representation of text. void SetCDATA( bool _cdata ) { cdata = _cdata; } virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); protected : /// [internal use] Creates a new Element and returns it. virtual TiXmlNode* Clone() const; void CopyTo( TiXmlText* target ) const; virtual void StreamOut ( TIXML_OSTREAM * out ) const; bool Blank() const; // returns true if all white space and new lines // [internal use] #ifdef TIXML_USE_STL virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); #endif private: bool cdata; // true if this should be input and output as a CDATA style text element }; /** In correct XML the declaration is the first entry in the file. @verbatim @endverbatim TinyXml will happily read or write files without a declaration, however. There are 3 possible attributes to the declaration: version, encoding, and standalone. Note: In this version of the code, the attributes are handled as special cases, not generic attributes, simply because there can only be at most 3 and they are always the same. */ class TiXmlDeclaration : public TiXmlNode { public: /// Construct an empty declaration. TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {} #ifdef TIXML_USE_STL /// Constructor. TiXmlDeclaration( const std::string& _version, const std::string& _encoding, const std::string& _standalone ); #endif /// Construct. TiXmlDeclaration( const char* _version, const char* _encoding, const char* _standalone ); TiXmlDeclaration( const TiXmlDeclaration& copy ); void operator=( const TiXmlDeclaration& copy ); virtual ~TiXmlDeclaration() {} /// Version. Will return an empty string if none was found. const char *Version() const { return version.c_str (); } /// Encoding. Will return an empty string if none was found. const char *Encoding() const { return encoding.c_str (); } /// Is this a standalone document? const char *Standalone() const { return standalone.c_str (); } /// Creates a copy of this Declaration and returns it. virtual TiXmlNode* Clone() const; /// Print this declaration to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); protected: void CopyTo( TiXmlDeclaration* target ) const; // used to be public #ifdef TIXML_USE_STL virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); #endif virtual void StreamOut ( TIXML_OSTREAM * out) const; private: TIXML_STRING version; TIXML_STRING encoding; TIXML_STRING standalone; }; /** Any tag that tinyXml doesn't recognize is saved as an unknown. It is a tag of text, but should not be modified. It will be written back to the XML, unchanged, when the file is saved. DTD tags get thrown into TiXmlUnknowns. */ class TiXmlUnknown : public TiXmlNode { public: TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {} virtual ~TiXmlUnknown() {} TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); } void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); } /// Creates a copy of this Unknown and returns it. virtual TiXmlNode* Clone() const; /// Print this Unknown to a FILE stream. virtual void Print( FILE* cfile, int depth ) const; virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); protected: void CopyTo( TiXmlUnknown* target ) const; #ifdef TIXML_USE_STL virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); #endif virtual void StreamOut ( TIXML_OSTREAM * out ) const; private: }; /** Always the top level node. A document binds together all the XML pieces. It can be saved, loaded, and printed to the screen. The 'value' of a document node is the xml file name. */ class TiXmlDocument : public TiXmlNode { public: /// Create an empty document, that has no name. TiXmlDocument(); /// Create a document with a name. The name of the document is also the filename of the xml. TiXmlDocument( const char * documentName ); #ifdef TIXML_USE_STL /// Constructor. TiXmlDocument( const std::string& documentName ); #endif TiXmlDocument( const TiXmlDocument& copy ); void operator=( const TiXmlDocument& copy ); virtual ~TiXmlDocument() {} /** Load a file using the current document value. Returns true if successful. Will delete any existing document data before loading. */ bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); /// Save a file using the current document value. Returns true if successful. bool SaveFile() const; /// Load a file using the given filename. Returns true if successful. bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); /// Save a file using the given filename. Returns true if successful. bool SaveFile( const char * filename ) const; #ifdef TIXML_USE_STL bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. { StringToBuffer f( filename ); return ( f.buffer && LoadFile( f.buffer, encoding )); } bool SaveFile( const std::string& filename ) const ///< STL std::string version. { StringToBuffer f( filename ); return ( f.buffer && SaveFile( f.buffer )); } #endif /** Parse the given null terminated block of xml data. Passing in an encoding to this method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml to use that encoding, regardless of what TinyXml might otherwise try to detect. */ virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); /** Get the root element -- the only top level element -- of the document. In well formed XML, there should only be one. TinyXml is tolerant of multiple elements at the document level. */ const TiXmlElement* RootElement() const { return FirstChildElement(); } TiXmlElement* RootElement() { return FirstChildElement(); } /** If an error occurs, Error will be set to true. Also, - The ErrorId() will contain the integer identifier of the error (not generally useful) - The ErrorDesc() method will return the name of the error. (very useful) - The ErrorRow() and ErrorCol() will return the location of the error (if known) */ bool Error() const { return error; } /// Contains a textual (english) description of the error if one occurs. const char * ErrorDesc() const { return errorDesc.c_str (); } /** Generally, you probably want the error string ( ErrorDesc() ). But if you prefer the ErrorId, this function will fetch it. */ int ErrorId() const { return errorId; } /** Returns the location (if known) of the error. The first column is column 1, and the first row is row 1. A value of 0 means the row and column wasn't applicable (memory errors, for example, have no row/column) or the parser lost the error. (An error in the error reporting, in that case.) @sa SetTabSize, Row, Column */ int ErrorRow() { return errorLocation.row+1; } int ErrorCol() { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct values for row and column. It does not change the output or input in any way. By calling this method, with a tab size greater than 0, the row and column of each node and attribute is stored when the file is loaded. Very useful for tracking the DOM back in to the source file. The tab size is required for calculating the location of nodes. If not set, the default of 4 is used. The tabsize is set per document. Setting the tabsize to 0 disables row/column tracking. Note that row and column tracking is not supported when using operator>>. The tab size needs to be enabled before the parse or load. Correct usage: @verbatim TiXmlDocument doc; doc.SetTabSize( 8 ); doc.Load( "myfile.xml" ); @endverbatim @sa Row, Column */ void SetTabSize( int _tabsize ) { tabsize = _tabsize; } int TabSize() const { return tabsize; } /** If you have handled the error, it can be reset with this call. The error state is automatically cleared if you Parse a new XML block. */ void ClearError() { error = false; errorId = 0; errorDesc = ""; errorLocation.row = errorLocation.col = 0; //errorLocation.last = 0; } /** Dump the document to standard out. */ void Print() const { Print( stdout, 0 ); } /// Print this Document to a FILE stream. virtual void Print( FILE* cfile, int depth = 0 ) const; // [internal use] void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding ); protected : virtual void StreamOut ( TIXML_OSTREAM * out) const; // [internal use] virtual TiXmlNode* Clone() const; #ifdef TIXML_USE_STL virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); #endif private: void CopyTo( TiXmlDocument* target ) const; bool error; int errorId; TIXML_STRING errorDesc; int tabsize; TiXmlCursor errorLocation; bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. }; /** A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml DOM structure. It is a separate utility class. Take an example: @verbatim @endverbatim Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very easy to write a *lot* of code that looks like: @verbatim TiXmlElement* root = document.FirstChildElement( "Document" ); if ( root ) { TiXmlElement* element = root->FirstChildElement( "Element" ); if ( element ) { TiXmlElement* child = element->FirstChildElement( "Child" ); if ( child ) { TiXmlElement* child2 = child->NextSiblingElement( "Child" ); if ( child2 ) { // Finally do something useful. @endverbatim And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity of such code. A TiXmlHandle checks for null pointers so it is perfectly safe and correct to use: @verbatim TiXmlHandle docHandle( &document ); TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).Element(); if ( child2 ) { // do something useful @endverbatim Which is MUCH more concise and useful. It is also safe to copy handles - internally they are nothing more than node pointers. @verbatim TiXmlHandle handleCopy = handle; @endverbatim What they should not be used for is iteration: @verbatim int i=0; while ( true ) { TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).Element(); if ( !child ) break; // do something ++i; } @endverbatim It seems reasonable, but it is in fact two embedded while loops. The Child method is a linear walk to find the element, so this code would iterate much more than it needs to. Instead, prefer: @verbatim TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).Element(); for( child; child; child=child->NextSiblingElement() ) { // do something } @endverbatim */ class TiXmlHandle { public: /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. TiXmlHandle( TiXmlNode* _node ) { this->node = _node; } /// Copy constructor TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; } /// Return a handle to the first child node. TiXmlHandle FirstChild() const; /// Return a handle to the first child node with the given name. TiXmlHandle FirstChild( const char * value ) const; /// Return a handle to the first child element. TiXmlHandle FirstChildElement() const; /// Return a handle to the first child element with the given name. TiXmlHandle FirstChildElement( const char * value ) const; /** Return a handle to the "index" child with the given name. The first child is 0, the second 1, etc. */ TiXmlHandle Child( const char* value, int index ) const; /** Return a handle to the "index" child. The first child is 0, the second 1, etc. */ TiXmlHandle Child( int index ) const; /** Return a handle to the "index" child element with the given name. The first child element is 0, the second 1, etc. Note that only TiXmlElements are indexed: other types are not counted. */ TiXmlHandle ChildElement( const char* value, int index ) const; /** Return a handle to the "index" child element. The first child element is 0, the second 1, etc. Note that only TiXmlElements are indexed: other types are not counted. */ TiXmlHandle ChildElement( int index ) const; #ifdef TIXML_USE_STL TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } #endif /// Return the handle as a TiXmlNode. This may return null. TiXmlNode* Node() const { return node; } /// Return the handle as a TiXmlElement. This may return null. TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } /// Return the handle as a TiXmlText. This may return null. TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } /// Return the handle as a TiXmlUnknown. This may return null; TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } private: TiXmlNode* node; }; #ifdef _MSC_VER #pragma warning( pop ) #endif #endif passwordmaker-cli-1.5.orig/stdafx.cpp0000755000000000000000000000240411545725573016461 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ // stdafx.cpp : source file that includes just the standard includes // test.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file passwordmaker-cli-1.5.orig/listaccounts.h0000755000000000000000000000224511545725573017353 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung * listaccounts.h by Dave Marotti */ #ifndef LISTACCOUNTS_H #define LISTACCOUNTS_H #include #include void listAccounts(std::string filepath, std::string about, int indent); #endif passwordmaker-cli-1.5.orig/cli.sln0000755000000000000000000000276411545725573015762 0ustar rootrootMicrosoft Visual Studio Solution File, Format Version 9.00 # Visual C++ Express 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cli", "cli.vcproj", "{AB79B5EF-637B-496A-BC52-F17C23FE8B94}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug - mhash|Win32 = Debug - mhash|Win32 Debug - SpiderMonkey|Win32 = Debug - SpiderMonkey|Win32 Release - mhash|Win32 = Release - mhash|Win32 Release - SpiderMonkey|Win32 = Release - SpiderMonkey|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {AB79B5EF-637B-496A-BC52-F17C23FE8B94}.Debug - mhash|Win32.ActiveCfg = Debug - mhash|Win32 {AB79B5EF-637B-496A-BC52-F17C23FE8B94}.Debug - mhash|Win32.Build.0 = Debug - mhash|Win32 {AB79B5EF-637B-496A-BC52-F17C23FE8B94}.Debug - SpiderMonkey|Win32.ActiveCfg = Debug - SpiderMonkey|Win32 {AB79B5EF-637B-496A-BC52-F17C23FE8B94}.Debug - SpiderMonkey|Win32.Build.0 = Debug - SpiderMonkey|Win32 {AB79B5EF-637B-496A-BC52-F17C23FE8B94}.Release - mhash|Win32.ActiveCfg = Release - mhash|Win32 {AB79B5EF-637B-496A-BC52-F17C23FE8B94}.Release - mhash|Win32.Build.0 = Release - mhash|Win32 {AB79B5EF-637B-496A-BC52-F17C23FE8B94}.Release - SpiderMonkey|Win32.ActiveCfg = Release - SpiderMonkey|Win32 {AB79B5EF-637B-496A-BC52-F17C23FE8B94}.Release - SpiderMonkey|Win32.Build.0 = Release - SpiderMonkey|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal passwordmaker-cli-1.5.orig/tinystr.h0000755000000000000000000002007111545725573016351 0ustar rootroot/* www.sourceforge.net/projects/tinyxml Original file by Yves Berquin. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ /* * THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005. * * - completely rewritten. compact, clean, and fast implementation. * - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems) * - fixed reserve() to work as per specification. * - fixed buggy compares operator==(), operator<(), and operator>() * - fixed operator+=() to take a const ref argument, following spec. * - added "copy" constructor with length, and most compare operators. * - added swap(), clear(), size(), capacity(), operator+(). */ #ifndef TIXML_USE_STL #ifndef TIXML_STRING_INCLUDED #define TIXML_STRING_INCLUDED #include #include /* TiXmlString is an emulation of a subset of the std::string template. Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. Only the member functions relevant to the TinyXML project have been implemented. The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase a string and there's no more room, we allocate a buffer twice as big as we need. */ class TiXmlString { public : // The size type used typedef unsigned int size_type; // Error value for find primitive static const size_type npos; // = -1; // TiXmlString empty constructor TiXmlString () : rep_(&nullrep_) { } // TiXmlString copy constructor TiXmlString (const TiXmlString & copy) { init(copy.length()); memcpy(start(), copy.data(), length()); } // TiXmlString constructor, based on a string TiXmlString (const char * copy) { init( static_cast( strlen(copy) )); memcpy(start(), copy, length()); } // TiXmlString constructor, based on a string TiXmlString (const char * str, size_type len) { init(len); memcpy(start(), str, len); } // TiXmlString destructor ~TiXmlString () { quit(); } // = operator TiXmlString& operator = (const char * copy) { return assign( copy, (size_type)strlen(copy)); } // = operator TiXmlString& operator = (const TiXmlString & copy) { return assign(copy.start(), copy.length()); } // += operator. Maps to append TiXmlString& operator += (const char * suffix) { return append(suffix, static_cast( strlen(suffix) )); } // += operator. Maps to append TiXmlString& operator += (char single) { return append(&single, 1); } // += operator. Maps to append TiXmlString& operator += (const TiXmlString & suffix) { return append(suffix.data(), suffix.length()); } // Convert a TiXmlString into a null-terminated char * const char * c_str () const { return rep_->str; } // Convert a TiXmlString into a char * (need not be null terminated). const char * data () const { return rep_->str; } // Return the length of a TiXmlString size_type length () const { return rep_->size; } // Alias for length() size_type size () const { return rep_->size; } // Checks if a TiXmlString is empty bool empty () const { return rep_->size == 0; } // Return capacity of string size_type capacity () const { return rep_->capacity; } // single char extraction const char& at (size_type index) const { assert( index < length() ); return rep_->str[ index ]; } // [] operator char& operator [] (size_type index) const { assert( index < length() ); return rep_->str[ index ]; } // find a char in a string. Return TiXmlString::npos if not found size_type find (char lookup) const { return find(lookup, 0); } // find a char in a string from an offset. Return TiXmlString::npos if not found size_type find (char tofind, size_type offset) const { if (offset >= length()) return npos; for (const char* p = c_str() + offset; *p != '\0'; ++p) { if (*p == tofind) return static_cast< size_type >( p - c_str() ); } return npos; } void clear () { //Lee: //The original was just too strange, though correct: // TiXmlString().swap(*this); //Instead use the quit & re-init: quit(); init(0,0); } /* Function to reserve a big amount of data when we know we'll need it. Be aware that this function DOES NOT clear the content of the TiXmlString if any exists. */ void reserve (size_type cap); TiXmlString& assign (const char* str, size_type len); TiXmlString& append (const char* str, size_type len); void swap (TiXmlString& other) { Rep* r = rep_; rep_ = other.rep_; other.rep_ = r; } private: void init(size_type sz) { init(sz, sz); } void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } char* start() const { return rep_->str; } char* finish() const { return rep_->str + rep_->size; } struct Rep { size_type size, capacity; char str[1]; }; void init(size_type sz, size_type cap) { if (cap) { // Lee: the original form: // rep_ = static_cast(operator new(sizeof(Rep) + cap)); // doesn't work in some cases of new being overloaded. Switching // to the normal allocation, although use an 'int' for systems // that are overly picky about structure alignment. const size_type bytesNeeded = sizeof(Rep) + cap; const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); rep_ = reinterpret_cast( new int[ intsNeeded ] ); rep_->str[ rep_->size = sz ] = '\0'; rep_->capacity = cap; } else { rep_ = &nullrep_; } } void quit() { if (rep_ != &nullrep_) { // The rep_ is really an array of ints. (see the allocator, above). // Cast it back before delete, so the compiler won't incorrectly call destructors. delete [] ( reinterpret_cast( rep_ ) ); } } Rep * rep_; static Rep nullrep_; } ; inline bool operator == (const TiXmlString & a, const TiXmlString & b) { return ( a.length() == b.length() ) // optimization on some platforms && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare } inline bool operator < (const TiXmlString & a, const TiXmlString & b) { return strcmp(a.c_str(), b.c_str()) < 0; } inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); } inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; } inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); } inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); } inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } inline bool operator == (const char* a, const TiXmlString & b) { return b == a; } inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); } inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); } TiXmlString operator + (const TiXmlString & a, const TiXmlString & b); TiXmlString operator + (const TiXmlString & a, const char* b); TiXmlString operator + (const char* a, const TiXmlString & b); /* TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. Only the operators that we need for TinyXML have been developped. */ class TiXmlOutStream : public TiXmlString { public : // TiXmlOutStream << operator. TiXmlOutStream & operator << (const TiXmlString & in) { *this += in; return *this; } // TiXmlOutStream << operator. TiXmlOutStream & operator << (const char * in) { *this += in; return *this; } } ; #endif // TIXML_STRING_INCLUDED #endif // TIXML_USE_STL passwordmaker-cli-1.5.orig/urlsearch.cpp0000755000000000000000000001042111545725573017156 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung * urlsearch.cpp by Dave Marotti */ #include #include #include #include #include "stdafx.h" #include "tinyxml.h" #include "urlsearch.h" using namespace std; int UrlSearch::regexCmp(const char *regexp, const char *string) { pcrecpp::RE re(regexp); if(re.FullMatch(string)) { return 1; } else { return 0; } } int UrlSearch::wildcardCmp(const char *wild, const char *string) { // Written by Jack Handy - jakkhandy@hotmail.com // Found at: http://www.codeproject.com/KB/string/wildcmp.aspx const char *cp = NULL, *mp = NULL; while ((*string) && (*wild != '*')) { if ((*wild != *string) && (*wild != '?')) { return 0; } wild++; string++; } while (*string) { if (*wild == '*') { if (!*++wild) { return 1; } mp = wild; cp = string+1; } else if ((*wild == *string) || (*wild == '?')) { wild++; string++; } else { wild = mp; string = cp++; } } while (*wild == '*') { wild++; } return !*wild; } bool UrlSearch::search(string url, string filepath) { TiXmlDocument document(filepath); document.LoadFile(); string ns; int attrnum; if (!document.Error()) { TiXmlHandle docHandle(&document); TiXmlElement *defaultNode = docHandle.FirstChildElement("RDF:RDF").Element(); if (defaultNode) { TiXmlAttribute *attrib = defaultNode->FirstAttribute(); // Find the namespace while (attrib) { if (!strcmp(attrib->Value(), "http://passwordmaker.mozdev.org/rdf#")) { ns = attrib->Name(); ns.erase(ns.begin(), ns.begin() + (ns.find(':') + 1)); break; } attrib = attrib->Next(); } if (ns.empty()) { // Namespace was not found. Not a valid file? } else { defaultNode = docHandle.FirstChildElement("RDF:RDF").FirstChildElement("RDF:Description").Element(); while (defaultNode) { if(defaultNode->Attribute(ns+":name")) { // iterate through all possible patterns attrnum = 0; while(1) { ostringstream attrname, attrtype, attrenabled; attrname << ns << ":pattern" << attrnum; attrtype << ns << ":patterntype" << attrnum; attrenabled << ns << ":patternenabled" << attrnum; // Does this node have a pattern attribute? if(defaultNode->Attribute(attrname.str())) { string pattern = string(defaultNode->Attribute(attrname.str())); string type = string(defaultNode->Attribute(attrtype.str())); string enabled = string(defaultNode->Attribute(attrenabled.str())); // Locate it based on regexp/wildcard patterns bool found = false; if(type=="wildcard") found = wildcardCmp(pattern.c_str(), url.c_str()); else if(type=="regex") found = regexCmp(pattern.c_str(), url.c_str()); if(found) { name = defaultNode->Attribute(ns+":name"); description = defaultNode->Attribute(ns+":description"); username = defaultNode->Attribute(ns+":usernameTB"); return true; } attrnum++; } else { break; } } } // end has ns1:name defaultNode = defaultNode->NextSiblingElement("RDF:Description"); } } } // end if(defaultNode) } // end if(!document.Error()) return false; } UrlSearch::UrlSearch() { name = ""; description = ""; username = ""; } UrlSearch::~UrlSearch() { } passwordmaker-cli-1.5.orig/leet.cpp0000755000000000000000000000716011545725573016125 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ #include #include "stdafx.h" #include "leet.h" using namespace std; // Unless we make an Array class, we can only do this with static const char *levels[][26] = { {"4", "b", "c", "d", "3", "f", "g", "h", "i", "j", "k", "1", "m", "n", "0", "p", "9", "r", "s", "7", "u", "v", "w", "x", "y", "z"}, {"4", "b", "c", "d", "3", "f", "g", "h", "1", "j", "k", "1", "m", "n", "0", "p", "9", "r", "5", "7", "u", "v", "w", "x", "y", "2"}, {"4", "8", "c", "d", "3", "f", "6", "h", "'", "j", "k", "1", "m", "n", "0", "p", "9", "r", "5", "7", "u", "v", "w", "x", "'/", "2"}, {"@", "8", "c", "d", "3", "f", "6", "h", "'", "j", "k", "1", "m", "n", "0", "p", "9", "r", "5", "7", "u", "v", "w", "x", "'/", "2"}, {"@", "|3", "c", "d", "3", "f", "6", "#", "!", "7", "|<", "1", "m", "n", "0", "|>", "9", "|2", "$", "7", "u", "\\/", "w", "x", "'/", "2"}, {"@", "|3", "c", "|)", "&", "|=", "6", "#", "!", ",|", "|<", "1", "m", "n", "0", "|>", "9", "|2", "$", "7", "u", "\\/", "w", "x", "'/", "2"}, {"@", "|3", "[", "|)", "&", "|=", "6", "#", "!", ",|", "|<", "1", "^^", "^/", "0", "|*", "9", "|2", "5", "7", "(_)", "\\/", "\\/\\/", "><", "'/", "2"}, {"@", "8", "(", "|)", "&", "|=", "6", "|-|", "!", "_|", "|(", "1", "|\\/|", "|\\|", "()", "|>", "(,)", "|2", "$", "|", "|_|", "\\/", "\\^/", ")(", "'/", "\"/_"}, {"@", "8", "(", "|)", "&", "|=", "6", "|-|", "!", "_|", "|{", "|_", "/\\/\\", "|\\|", "()", "|>", "(,)", "|2", "$", "|", "|_|", "\\/", "\\^/", ")(", "'/", "\"/_"} }; /** * Convert the string in _message_ to l33t-speak * using the l33t level specified by _leetLevel_. * l33t levels are 0-8 with 0 being the simplest * form of l33t-speak and 8 being the most complex. * * Note that _message_ is converted to lower-case if * the l33t conversion is performed. To maintain * backwards compatibility, do not change this function * so it uses mixed-case. * * Using a _leetLevel_ <= 0 results in the original message * being returned. * */ string leetConvert(int level, string message) { string ret; char *string; int item; if (level > -1 && level < 9) { // ret = tolower(message); ret = ""; string = (char *)message.c_str(); // Unless a better to lower is known to me, use this for now for (item = 0; item < (int)strlen(string); item++) { string[item] = tolower(string[item]); } for (item = 0; item < (int)strlen(string); item++) { if (string[item] >= 'a' && string[item] <= 'z') { ret += levels[level][string[item] - 'a']; } else { ret += string[item]; } //ret = replace(alphabet[item], levels[level][item]); } return ret; } return message; } passwordmaker-cli-1.5.orig/leet.h0000755000000000000000000000221311545725573015564 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ #ifndef LEET_H #define LEET_H #include "shared/pwm_common.h" // convert message to l33t-speak std::string leetConvert(int level, std::string message); #endif passwordmaker-cli-1.5.orig/pwmdoc.h0000755000000000000000000000352511545725573016133 0ustar rootroot#ifndef PWMDOC_H #define PWMDOC_H #include #include #include #include #include #include "tinyxml.h" struct PWMNode { public: enum { ntUnknown, ntSeq, ntLi, ntDescription } nodeType; std::map attrs; std::vector children; public: PWMNode() { nodeType = ntUnknown; } }; struct PWMDoc { public: PWMNode mainNode; std::string ns; public: std::string findNamespace(TiXmlHandle *docHandle) { std::string ns = ""; TiXmlElement *defaultNode = docHandle->FirstChildElement("RDF:RDF").Element(); if(defaultNode) { TiXmlAttribute *attrib = defaultNode->FirstAttribute(); while(attrib) { if(!strcmp(attrib->Value(), "http://passwordmaker.mozdev.org/rdf#")) { ns = attrib->Name(); ns.erase(ns.begin(), ns.begin() + (ns.find(':')+1)); break; } } } return ns; } PWMDoc() { } TiXmlElement *findSeq(TiXmlHandle *docHandle, std::string about) { TiXmlElement *defaultNode = docHandle->FirstChildElement("RDF:RDF").FirstChildElement("RDF:Seq").Element(); while(defaultNode) { if(about.compare(defaultNode->Attribute("RDF:about"))==0) break; defaultNode = defaultNode->NextSiblingElement("RDF:Seq"); } return defaultNode; } bool load(std::string filepath) { TiXmlDocument document(filepath); document.LoadFile(); if(document.Error()) { return false; } TiXmlHandle docHandle(&document); ns = findNamespace(&docHandle); if(ns.size()==0) return false; } PWMNode loadSeq(TiXmlHandle *docHandle, TiXmlElement *seqNode) { PWMNode node; node.nodeType = ntSeq; TiXmlAttribute *attrib = seqNode->FirstAttribute(); while(attrib) { node.attrs[std::string(attrib->Name())] = std::string(attrib->Value()); attrib = attrib->Next(); } } }; #endif passwordmaker-cli-1.5.orig/passwordmaker.h0000755000000000000000000000375111545725573017525 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ #ifndef PASSWORDMAKER_H #define PASSWORDMAKER_H #include "shared/pwm_common.h" extern char base93Set[]; class Hasher; // So that main.cpp doesn't need to see this class class PasswordMaker { public: PasswordMaker(void); ~PasswordMaker(void); // The mack daddy function of the the class. Actually, the only exposed function that's needed. // leetLevel = 1 - 9 std::string generatePassword(std::string masterPassword = "", hashType algorithm = PWM_MD5, bool hmac = false, bool trim = true, std::string url = "", int length = 12, std::string characters = base93Set, leetType useLeet = LEET_NONE, int leetLevel = 0, std::string username = "", std::string modifier = "", std::string prefix = "", std::string suffix = "", bool sha256_bug = true); bool initialized(); // Allows us to set where to look for the gethash.js, if it's needed // Must end with '/' or '\' (blackslash on Windows only) void setPath(std::string path); private: Hasher *hasher; }; #endif //PASSWORDMAKER_H passwordmaker-cli-1.5.orig/mingw32.mak0000755000000000000000000000501511545725573016445 0ustar rootroot# PasswordMaker - Creates and manages passwords # Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. # http://passwordmaker.org/ # grimholtz@yahoo.com # # This library is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 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 # FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # # You should have received a copy of the GNU Lesser 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 # # Written by Miquel Burns and Eric H. Jung LINK = $(CXX) DEFINES = -DXP_WIN -DUSE_SPIDERMONKEY -DTIXML_USE_STL # Thanks to MinGW for including windows.h in STD headers, we don't want it included that way, so let us include it outselves thank you very much. DEFINES += -D__GTHREAD_HIDE_WIN32API -DPCRE_STATIC CFLAGS = -O2 -Wall $(DEFINES) CXXFLAGS = -O2 -frtti -fexceptions -Wall $(DEFINES) # Current directory is needed for TCLAP INCPATH = -Ishared/3rdparty/spidermonkey/include -Ishared/3rdparty/pcre/include -Ishared/3rdparty/pcre/mingw/include -I. LFLAGS = -Wl,-s -Wl,-subsystem,console -s LIBS = shared/3rdparty/spidermonkey/mingw/lib/libjs.a shared\3rdparty\pcre\mingw\lib\libpcrecpp.a shared/3rdparty/pcre/mingw/lib/libpcre.a shared/3rdparty/pcre/mingw/lib/libpcreposix.a SOURCE = shared\hasher.cpp leet.cpp main.cpp passwordmaker.cpp pwmdefaults.cpp tinystr.cpp tinyxml.cpp tinyxmlerror.cpp tinyxmlparser.cpp listaccounts.cpp urlsearch.cpp OBJECTS = $(SOURCE:.cpp=.o) TARGET = passwordmaker SUFFIX = .exe $(TARGET)$(SUFFIX): $(OBJECTS) $(LINK) $(LFLAGS) -o "$(TARGET)$(SUFFIX)" $(OBJECTS) $(LIBS) upx --no-env -q --best --crp-ms=999999 --nrv2d $(TARGET)$(SUFFIX) .SUFFIXES: .c .cpp .cc .cxx .cpp.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .cc.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .cxx.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .c.o: $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< include mingw/depends .PHONY: depend clean depend: $(CXX) -MM $(CXXFLAGS) $(INCPATH) $(SOURCE) > mingw/depends clean: del $(OBJECTS) $(TARGET)$(SUFFIX) $(TARGET)a$(SUFFIX) $(TARGET)b$(SUFFIX) passwordmaker-cli-1.5.orig/stdafx.h0000755000000000000000000000257311545725573016135 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #ifndef STDAFX_H #define STDAFX_H #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #ifdef USE_MHASH #include #endif #include #include #include #endif //STDAFX_H passwordmaker-cli-1.5.orig/ReadMe.txt0000755000000000000000000001666611545725573016401 0ustar rootrootPasswordMaker - Creates and manages passwords. Command-Line Edition http://passwordmaker.org/ Copyright 2005, 2006 LeahScape, Inc. All Rights Reserved. grimholtz@yahoo.com LICENSE ======= This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser 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 AUTHORS ======= Miquel Burns - http://www.miquelfire.com/ Eric H. Jung - grimholtz@yahoo.com ABOUT ===== The purpose of PASSWORDMAKER is to enable you to securely and easily log in to Internet applications, such as websites, instant messaging, ftp, and others. With the proliferation of online resouces, you probably have usernames and passwords for banks, bill pay systems, email accounts, credit card websites, instant messenger, investment accounts, photo sites, blogging tools, and countless others. Most people have a few passwords they use for all of these accounts because it's easier to remember just a few. But this is incredibly risky. What if you could use passwords unique as fingerprints for each and every one of your accounts, yet not have to remember those fingerprints? PASSWORDMAKER does just that. By using complex mathematical formulae, PASSWORDMAKER outputs the same unique passwords for you each and every time you provide it with the same input. And these passwords are unique across the globe (providing they are of sufficient length). But only a genius could memorize so many unique passwords. Don't write them down on sticky notes for others to find; no, PASSWORDMAKER calculates them for you over and over again -- as needed -- without storing them so nothing be hacked, lost or stolen. INSTRUCTIONS ============ Handle with care. Dry clean only. PasswordMaker searches for and reads a file named passwordmaker.rdf in the current directory. If found, the password is generated using the "Defaults" settings as specified in this file. Command-line arguments override (take precedence over) passwordmaker.rdf settings. Command-line arguments, in turn, override (take precendence over) built-in default settings. If a command-line argument is missing or not specified in the "Defaults" of passwordmaker.rdf or the file pointed to by -f/--file, these built-in defaults are used in its place: masterPassword : none url : none algorithm : MD5 hmac : no trim : yes length : 8 characters : ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\:";'<>?,./ useLeet : none leetLevel : 0 username : none modifier : none prefix : none suffix : none USAGE ===== ./passwordmaker [-f ] [--search ] [-L] [-b] [-0] [-x] [-r ] [-a ] [--account_skip ] [--account ] [-c ] [-g ] [-d ] [-s ] [-p ] [-u ] [-l ] [-e <1|2|3|4|5|6|7|8|9>] [-m ] [--] [-v] [-h] Where: -f , --file (value required) Path/filename to a settings file --search (value required) Search config file for an account matching the supplied URL. If found, that account's settings will be used to generate the password. Example: passwordmaker --search https://yoursite.com/login.phtml -L, --list List all accounts and groups in the config file. -b, --verbose Echo command-line arguments -0, --trimzeros Trim leading zeros from the generated password -x, --HMAC Use the HMAC version of the specified hash algorithm -r , --url (value required) URL (equivalent to "Use This URL" in the Firefox/Mozilla extension) -a , --alg (value required) Hash Algorithm --account_skip (value required) Account skip --account (value required) Account -c , --chars (value required) Characters -g , --length (value required) Password Length -d , --modifier (value required) Password Modifier -s , --suffix (value required) Password Suffix -p , --prefix (value required) Password Prefix -u , --username (value required) Username -l , --l33t (value required) Where to use l33t -e <1|2|3|4|5|6|7|8|9>, --level <1|2|3|4|5|6|7|8|9> (value required) l33t level -m , --mpw (value required) Master Password --, --ignore_rest Ignores the rest of the labeled arguments following this flag. -v, --version Displays version information and exits. -h, --help Displays usage information and exits. Example: passwordmaker.exe -m foobar -r google.com -u ericjung -g 12 -a SHA1 -x Assuming passwordmaker.rdf is not found, this example generates a password with the following settings: masterPassword : foobar url : google.com algorithm : HMAC-SHA1 trim : yes length : 12 characters : ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\:";'<>?,./ useLeet : none leetLevel : 0 username : ericjung modifier : none prefix : none suffix : none The generated password is BBg*6R#y7}c3 RELEASE HISTORY =============== 1.5 - 15 January 2011 - Added account related features for using the RDF files 1.4.2 - 14 January 2008 - Changed defaults to match Firefox extension of PasswordMaker 1.4.1 - 22 May 2007 - The master password does not echo the characters typed Unix method was provided here (at the same time as this request was made): http://forums.passwordmaker.org/index.php/topic,1294.0.html 1.4 - 23 July 2006 - Master password is prompted for if it's not present on command-line options. Fixed leet levels 8 and 9. 1.3 - 26 April 2006 - Added account support and building instructions. Slight tweaks to unix makefile to make it compatible with OS X. 1.2 - 06 Feburary 2006 - Added mhash support. A *n?x makefile is included as well. 1.1 - 30 January 2006 - Added "-f" option to specify the path & filename to a passwordmaker settings file. Expanded ReadMe.txt documentation. Support for unlimited password length. 1.0 - 10 January 2006 - Initial release. passwordmaker-cli-1.5.orig/tinyxml.cpp0000755000000000000000000010200011545725573016665 0ustar rootroot/* www.sourceforge.net/projects/tinyxml Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "stdafx.h" #include #include "tinyxml.h" #ifdef TIXML_USE_STL #include #endif bool TiXmlBase::condenseWhiteSpace = true; void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_OSTREAM* stream ) { TIXML_STRING buffer; PutString( str, &buffer ); (*stream) << buffer; } void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_STRING* outString ) { int i=0; while( i<(int)str.length() ) { unsigned char c = (unsigned char) str[i]; if ( c == '&' && i < ( (int)str.length() - 2 ) && str[i+1] == '#' && str[i+2] == 'x' ) { // Hexadecimal character reference. // Pass through unchanged. // © -- copyright symbol, for example. // // The -1 is a bug fix from Rob Laveaux. It keeps // an overflow from happening if there is no ';'. // There are actually 2 ways to exit this loop - // while fails (error case) and break (semicolon found). // However, there is no mechanism (currently) for // this function to return an error. while ( i<(int)str.length()-1 ) { outString->append( str.c_str() + i, 1 ); ++i; if ( str[i] == ';' ) break; } } else if ( c == '&' ) { outString->append( entity[0].str, entity[0].strLength ); ++i; } else if ( c == '<' ) { outString->append( entity[1].str, entity[1].strLength ); ++i; } else if ( c == '>' ) { outString->append( entity[2].str, entity[2].strLength ); ++i; } else if ( c == '\"' ) { outString->append( entity[3].str, entity[3].strLength ); ++i; } else if ( c == '\'' ) { outString->append( entity[4].str, entity[4].strLength ); ++i; } else if ( c < 32 ) { // Easy pass at non-alpha/numeric/symbol // Below 32 is symbolic. char buf[ 32 ]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); #else sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); #endif //*ME: warning C4267: convert 'size_t' to 'int' //*ME: Int-Cast to make compiler happy ... outString->append( buf, (int)strlen( buf ) ); ++i; } else { //char realc = (char) c; //outString->append( &realc, 1 ); *outString += (char) c; // somewhat more efficient function call. ++i; } } } // <-- Strange class for a bug fix. Search for STL_STRING_BUG TiXmlBase::StringToBuffer::StringToBuffer( const TIXML_STRING& str ) { buffer = new char[ str.length()+1 ]; if ( buffer ) { strcpy( buffer, str.c_str() ); } } TiXmlBase::StringToBuffer::~StringToBuffer() { delete [] buffer; } // End strange bug fix. --> TiXmlNode::TiXmlNode( NodeType _type ) : TiXmlBase() { parent = 0; type = _type; firstChild = 0; lastChild = 0; prev = 0; next = 0; } TiXmlNode::~TiXmlNode() { TiXmlNode* node = firstChild; TiXmlNode* temp = 0; while ( node ) { temp = node; node = node->next; delete temp; } } void TiXmlNode::CopyTo( TiXmlNode* target ) const { target->SetValue (value.c_str() ); target->userData = userData; } void TiXmlNode::Clear() { TiXmlNode* node = firstChild; TiXmlNode* temp = 0; while ( node ) { temp = node; node = node->next; delete temp; } firstChild = 0; lastChild = 0; } TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) { node->parent = this; node->prev = lastChild; node->next = 0; if ( lastChild ) lastChild->next = node; else firstChild = node; // it was an empty list. lastChild = node; return node; } TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) { TiXmlNode* node = addThis.Clone(); if ( !node ) return 0; return LinkEndChild( node ); } TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) { if ( !beforeThis || beforeThis->parent != this ) return 0; TiXmlNode* node = addThis.Clone(); if ( !node ) return 0; node->parent = this; node->next = beforeThis; node->prev = beforeThis->prev; if ( beforeThis->prev ) { beforeThis->prev->next = node; } else { assert( firstChild == beforeThis ); firstChild = node; } beforeThis->prev = node; return node; } TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) { if ( !afterThis || afterThis->parent != this ) return 0; TiXmlNode* node = addThis.Clone(); if ( !node ) return 0; node->parent = this; node->prev = afterThis; node->next = afterThis->next; if ( afterThis->next ) { afterThis->next->prev = node; } else { assert( lastChild == afterThis ); lastChild = node; } afterThis->next = node; return node; } TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) { if ( replaceThis->parent != this ) return 0; TiXmlNode* node = withThis.Clone(); if ( !node ) return 0; node->next = replaceThis->next; node->prev = replaceThis->prev; if ( replaceThis->next ) replaceThis->next->prev = node; else lastChild = node; if ( replaceThis->prev ) replaceThis->prev->next = node; else firstChild = node; delete replaceThis; node->parent = this; return node; } bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) { if ( removeThis->parent != this ) { assert( 0 ); return false; } if ( removeThis->next ) removeThis->next->prev = removeThis->prev; else lastChild = removeThis->prev; if ( removeThis->prev ) removeThis->prev->next = removeThis->next; else firstChild = removeThis->next; delete removeThis; return true; } const TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const { const TiXmlNode* node; for ( node = firstChild; node; node = node->next ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } TiXmlNode* TiXmlNode::FirstChild( const char * _value ) { TiXmlNode* node; for ( node = firstChild; node; node = node->next ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } const TiXmlNode* TiXmlNode::LastChild( const char * _value ) const { const TiXmlNode* node; for ( node = lastChild; node; node = node->prev ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } TiXmlNode* TiXmlNode::LastChild( const char * _value ) { TiXmlNode* node; for ( node = lastChild; node; node = node->prev ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } const TiXmlNode* TiXmlNode::IterateChildren( const TiXmlNode* previous ) const { if ( !previous ) { return FirstChild(); } else { assert( previous->parent == this ); return previous->NextSibling(); } } TiXmlNode* TiXmlNode::IterateChildren( TiXmlNode* previous ) { if ( !previous ) { return FirstChild(); } else { assert( previous->parent == this ); return previous->NextSibling(); } } const TiXmlNode* TiXmlNode::IterateChildren( const char * val, const TiXmlNode* previous ) const { if ( !previous ) { return FirstChild( val ); } else { assert( previous->parent == this ); return previous->NextSibling( val ); } } TiXmlNode* TiXmlNode::IterateChildren( const char * val, TiXmlNode* previous ) { if ( !previous ) { return FirstChild( val ); } else { assert( previous->parent == this ); return previous->NextSibling( val ); } } const TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const { const TiXmlNode* node; for ( node = next; node; node = node->next ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } TiXmlNode* TiXmlNode::NextSibling( const char * _value ) { TiXmlNode* node; for ( node = next; node; node = node->next ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } const TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const { const TiXmlNode* node; for ( node = prev; node; node = node->prev ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) { TiXmlNode* node; for ( node = prev; node; node = node->prev ) { if ( strcmp( node->Value(), _value ) == 0 ) return node; } return 0; } void TiXmlElement::RemoveAttribute( const char * name ) { TiXmlAttribute* node = attributeSet.Find( name ); if ( node ) { attributeSet.Remove( node ); delete node; } } const TiXmlElement* TiXmlNode::FirstChildElement() const { const TiXmlNode* node; for ( node = FirstChild(); node; node = node->NextSibling() ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } TiXmlElement* TiXmlNode::FirstChildElement() { TiXmlNode* node; for ( node = FirstChild(); node; node = node->NextSibling() ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } const TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const { const TiXmlNode* node; for ( node = FirstChild( _value ); node; node = node->NextSibling( _value ) ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) { TiXmlNode* node; for ( node = FirstChild( _value ); node; node = node->NextSibling( _value ) ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } const TiXmlElement* TiXmlNode::NextSiblingElement() const { const TiXmlNode* node; for ( node = NextSibling(); node; node = node->NextSibling() ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } TiXmlElement* TiXmlNode::NextSiblingElement() { TiXmlNode* node; for ( node = NextSibling(); node; node = node->NextSibling() ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } const TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const { const TiXmlNode* node; for ( node = NextSibling( _value ); node; node = node->NextSibling( _value ) ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) { TiXmlNode* node; for ( node = NextSibling( _value ); node; node = node->NextSibling( _value ) ) { if ( node->ToElement() ) return node->ToElement(); } return 0; } const TiXmlDocument* TiXmlNode::GetDocument() const { const TiXmlNode* node; for( node = this; node; node = node->parent ) { if ( node->ToDocument() ) return node->ToDocument(); } return 0; } TiXmlDocument* TiXmlNode::GetDocument() { TiXmlNode* node; for( node = this; node; node = node->parent ) { if ( node->ToDocument() ) return node->ToDocument(); } return 0; } TiXmlElement::TiXmlElement (const char * _value) : TiXmlNode( TiXmlNode::ELEMENT ) { firstChild = lastChild = 0; value = _value; } #ifdef TIXML_USE_STL TiXmlElement::TiXmlElement( const std::string& _value ) : TiXmlNode( TiXmlNode::ELEMENT ) { firstChild = lastChild = 0; value = _value; } #endif TiXmlElement::TiXmlElement( const TiXmlElement& copy) : TiXmlNode( TiXmlNode::ELEMENT ) { firstChild = lastChild = 0; copy.CopyTo( this ); } void TiXmlElement::operator=( const TiXmlElement& base ) { ClearThis(); base.CopyTo( this ); } TiXmlElement::~TiXmlElement() { ClearThis(); } void TiXmlElement::ClearThis() { Clear(); while( attributeSet.First() ) { TiXmlAttribute* node = attributeSet.First(); attributeSet.Remove( node ); delete node; } } const char * TiXmlElement::Attribute( const char * name ) const { const TiXmlAttribute* node = attributeSet.Find( name ); if ( node ) return node->Value(); return 0; } const char * TiXmlElement::Attribute( const char * name, int* i ) const { const char * s = Attribute( name ); if ( i ) { if ( s ) *i = atoi( s ); else *i = 0; } return s; } const char * TiXmlElement::Attribute( const char * name, double* d ) const { const char * s = Attribute( name ); if ( d ) { if ( s ) *d = atof( s ); else *d = 0; } return s; } int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const { const TiXmlAttribute* node = attributeSet.Find( name ); if ( !node ) return TIXML_NO_ATTRIBUTE; return node->QueryIntValue( ival ); } int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const { const TiXmlAttribute* node = attributeSet.Find( name ); if ( !node ) return TIXML_NO_ATTRIBUTE; return node->QueryDoubleValue( dval ); } void TiXmlElement::SetAttribute( const char * name, int val ) { char buf[64]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF( buf, sizeof(buf), "%d", val ); #else sprintf( buf, "%d", val ); #endif SetAttribute( name, buf ); } void TiXmlElement::SetDoubleAttribute( const char * name, double val ) { char buf[256]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF( buf, sizeof(buf), "%f", val ); #else sprintf( buf, "%f", val ); #endif SetAttribute( name, buf ); } void TiXmlElement::SetAttribute( const char * name, const char * _value ) { TiXmlAttribute* node = attributeSet.Find( name ); if ( node ) { node->SetValue( _value ); return; } TiXmlAttribute* attrib = new TiXmlAttribute( name, _value ); if ( attrib ) { attributeSet.Add( attrib ); } else { TiXmlDocument* document = GetDocument(); if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN ); } } void TiXmlElement::Print( FILE* cfile, int depth ) const { int i; for ( i=0; iNext() ) { fprintf( cfile, " " ); attrib->Print( cfile, depth ); } // There are 3 different formatting approaches: // 1) An element without children is printed as a node // 2) An element with only a text child is printed as text // 3) An element with children is printed on multiple lines. TiXmlNode* node; if ( !firstChild ) { fprintf( cfile, " />" ); } else if ( firstChild == lastChild && firstChild->ToText() ) { fprintf( cfile, ">" ); firstChild->Print( cfile, depth + 1 ); fprintf( cfile, "", value.c_str() ); } else { fprintf( cfile, ">" ); for ( node = firstChild; node; node=node->NextSibling() ) { if ( !node->ToText() ) { fprintf( cfile, "\n" ); } node->Print( cfile, depth+1 ); } fprintf( cfile, "\n" ); for( i=0; i", value.c_str() ); } } void TiXmlElement::StreamOut( TIXML_OSTREAM * stream ) const { (*stream) << "<" << value; const TiXmlAttribute* attrib; for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) { (*stream) << " "; attrib->StreamOut( stream ); } // If this node has children, give it a closing tag. Else // make it an empty tag. TiXmlNode* node; if ( firstChild ) { (*stream) << ">"; for ( node = firstChild; node; node=node->NextSibling() ) { node->StreamOut( stream ); } (*stream) << ""; } else { (*stream) << " />"; } } void TiXmlElement::CopyTo( TiXmlElement* target ) const { // superclass: TiXmlNode::CopyTo( target ); // Element class: // Clone the attributes, then clone the children. const TiXmlAttribute* attribute = 0; for( attribute = attributeSet.First(); attribute; attribute = attribute->Next() ) { target->SetAttribute( attribute->Name(), attribute->Value() ); } TiXmlNode* node = 0; for ( node = firstChild; node; node = node->NextSibling() ) { target->LinkEndChild( node->Clone() ); } } TiXmlNode* TiXmlElement::Clone() const { TiXmlElement* clone = new TiXmlElement( Value() ); if ( !clone ) return 0; CopyTo( clone ); return clone; } const char* TiXmlElement::GetText() const { const TiXmlNode* child = this->FirstChild(); if ( child ) { const TiXmlText* childText = child->ToText(); if ( childText ) { return childText->Value(); } } return 0; } TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT ) { tabsize = 4; useMicrosoftBOM = false; ClearError(); } TiXmlDocument::TiXmlDocument( const char * documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) { tabsize = 4; useMicrosoftBOM = false; value = documentName; ClearError(); } #ifdef TIXML_USE_STL TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) { tabsize = 4; useMicrosoftBOM = false; value = documentName; ClearError(); } #endif TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode::DOCUMENT ) { copy.CopyTo( this ); } void TiXmlDocument::operator=( const TiXmlDocument& copy ) { Clear(); copy.CopyTo( this ); } bool TiXmlDocument::LoadFile( TiXmlEncoding encoding ) { // See STL_STRING_BUG below. StringToBuffer buf( value ); if ( buf.buffer && LoadFile( buf.buffer, encoding ) ) return true; return false; } bool TiXmlDocument::SaveFile() const { // See STL_STRING_BUG below. StringToBuffer buf( value ); if ( buf.buffer && SaveFile( buf.buffer ) ) return true; return false; } bool TiXmlDocument::LoadFile( const char* filename, TiXmlEncoding encoding ) { // Delete the existing data: Clear(); location.Clear(); // There was a really terrifying little bug here. The code: // value = filename // in the STL case, cause the assignment method of the std::string to // be called. What is strange, is that the std::string had the same // address as it's c_str() method, and so bad things happen. Looks // like a bug in the Microsoft STL implementation. // See STL_STRING_BUG above. // Fixed with the StringToBuffer class. value = filename; // reading in binary mode so that tinyxml can normalize the EOL FILE* file = fopen( value.c_str (), "rb" ); if ( file ) { // Get the file size, so we can pre-allocate the string. HUGE speed impact. long length = 0; fseek( file, 0, SEEK_END ); length = ftell( file ); fseek( file, 0, SEEK_SET ); // Strange case, but good to handle up front. if ( length == 0 ) { fclose( file ); return false; } // If we have a file, assume it is all one big XML file, and read it in. // The document parser may decide the document ends sooner than the entire file, however. TIXML_STRING data; data.reserve( length ); // Subtle bug here. TinyXml did use fgets. But from the XML spec: // 2.11 End-of-Line Handling // // // ...the XML processor MUST behave as if it normalized all line breaks in external // parsed entities (including the document entity) on input, before parsing, by translating // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to // a single #xA character. // // // It is not clear fgets does that, and certainly isn't clear it works cross platform. // Generally, you expect fgets to translate from the convention of the OS to the c/unix // convention, and not work generally. /* while( fgets( buf, sizeof(buf), file ) ) { data += buf; } */ char* buf = new char[ length+1 ]; buf[0] = 0; if ( fread( buf, length, 1, file ) != 1 ) { //if ( fread( buf, 1, length, file ) != (size_t)length ) { SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); fclose( file ); return false; } fclose( file ); const char* lastPos = buf; const char* p = buf; buf[length] = 0; while( *p ) { assert( p < (buf+length) ); if ( *p == 0xa ) { // Newline character. No special rules for this. Append all the characters // since the last string, and include the newline. data.append( lastPos, p-lastPos+1 ); // append, include the newline ++p; // move past the newline lastPos = p; // and point to the new buffer (may be 0) assert( p <= (buf+length) ); } else if ( *p == 0xd ) { // Carriage return. Append what we have so far, then // handle moving forward in the buffer. if ( (p-lastPos) > 0 ) { data.append( lastPos, p-lastPos ); // do not add the CR } data += (char)0xa; // a proper newline if ( *(p+1) == 0xa ) { // Carriage return - new line sequence p += 2; lastPos = p; assert( p <= (buf+length) ); } else { // it was followed by something else...that is presumably characters again. ++p; lastPos = p; assert( p <= (buf+length) ); } } else { ++p; } } // Handle any left over characters. if ( p-lastPos ) { data.append( lastPos, p-lastPos ); } delete [] buf; buf = 0; Parse( data.c_str(), 0, encoding ); if ( Error() ) return false; else return true; } SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } bool TiXmlDocument::SaveFile( const char * filename ) const { // The old c stuff lives on... FILE* fp = fopen( filename, "w" ); if ( fp ) { if ( useMicrosoftBOM ) { const unsigned char TIXML_UTF_LEAD_0 = 0xefU; const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; fputc( TIXML_UTF_LEAD_0, fp ); fputc( TIXML_UTF_LEAD_1, fp ); fputc( TIXML_UTF_LEAD_2, fp ); } Print( fp, 0 ); fclose( fp ); return true; } return false; } void TiXmlDocument::CopyTo( TiXmlDocument* target ) const { TiXmlNode::CopyTo( target ); target->error = error; target->errorDesc = errorDesc.c_str (); TiXmlNode* node = 0; for ( node = firstChild; node; node = node->NextSibling() ) { target->LinkEndChild( node->Clone() ); } } TiXmlNode* TiXmlDocument::Clone() const { TiXmlDocument* clone = new TiXmlDocument(); if ( !clone ) return 0; CopyTo( clone ); return clone; } void TiXmlDocument::Print( FILE* cfile, int depth ) const { const TiXmlNode* node; for ( node=FirstChild(); node; node=node->NextSibling() ) { node->Print( cfile, depth ); fprintf( cfile, "\n" ); } } void TiXmlDocument::StreamOut( TIXML_OSTREAM * out ) const { const TiXmlNode* node; for ( node=FirstChild(); node; node=node->NextSibling() ) { node->StreamOut( out ); // Special rule for streams: stop after the root element. // The stream in code will only read one element, so don't // write more than one. if ( node->ToElement() ) break; } } const TiXmlAttribute* TiXmlAttribute::Next() const { // We are using knowledge of the sentinel. The sentinel // have a value or name. if ( next->value.empty() && next->name.empty() ) return 0; return next; } TiXmlAttribute* TiXmlAttribute::Next() { // We are using knowledge of the sentinel. The sentinel // have a value or name. if ( next->value.empty() && next->name.empty() ) return 0; return next; } const TiXmlAttribute* TiXmlAttribute::Previous() const { // We are using knowledge of the sentinel. The sentinel // have a value or name. if ( prev->value.empty() && prev->name.empty() ) return 0; return prev; } TiXmlAttribute* TiXmlAttribute::Previous() { // We are using knowledge of the sentinel. The sentinel // have a value or name. if ( prev->value.empty() && prev->name.empty() ) return 0; return prev; } void TiXmlAttribute::Print( FILE* cfile, int /*depth*/ ) const { TIXML_STRING n, v; PutString( name, &n ); PutString( value, &v ); if (value.find ('\"') == TIXML_STRING::npos) fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); else fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); } void TiXmlAttribute::StreamOut( TIXML_OSTREAM * stream ) const { if (value.find( '\"' ) != TIXML_STRING::npos) { PutString( name, stream ); (*stream) << "=" << "'"; PutString( value, stream ); (*stream) << "'"; } else { PutString( name, stream ); (*stream) << "=" << "\""; PutString( value, stream ); (*stream) << "\""; } } int TiXmlAttribute::QueryIntValue( int* ival ) const { if ( sscanf( value.c_str(), "%d", ival ) == 1 ) return TIXML_SUCCESS; return TIXML_WRONG_TYPE; } int TiXmlAttribute::QueryDoubleValue( double* dval ) const { if ( sscanf( value.c_str(), "%lf", dval ) == 1 ) return TIXML_SUCCESS; return TIXML_WRONG_TYPE; } void TiXmlAttribute::SetIntValue( int _value ) { char buf [64]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value); #else sprintf (buf, "%d", _value); #endif SetValue (buf); } void TiXmlAttribute::SetDoubleValue( double _value ) { char buf [256]; #if defined(TIXML_SNPRINTF) TIXML_SNPRINTF( buf, sizeof(buf), "%lf", _value); #else sprintf (buf, "%lf", _value); #endif SetValue (buf); } int TiXmlAttribute::IntValue() const { return atoi (value.c_str ()); } double TiXmlAttribute::DoubleValue() const { return atof (value.c_str ()); } TiXmlComment::TiXmlComment( const TiXmlComment& copy ) : TiXmlNode( TiXmlNode::COMMENT ) { copy.CopyTo( this ); } void TiXmlComment::operator=( const TiXmlComment& base ) { Clear(); base.CopyTo( this ); } void TiXmlComment::Print( FILE* cfile, int depth ) const { for ( int i=0; i", value.c_str() ); } void TiXmlComment::StreamOut( TIXML_OSTREAM * stream ) const { (*stream) << ""; } void TiXmlComment::CopyTo( TiXmlComment* target ) const { TiXmlNode::CopyTo( target ); } TiXmlNode* TiXmlComment::Clone() const { TiXmlComment* clone = new TiXmlComment(); if ( !clone ) return 0; CopyTo( clone ); return clone; } void TiXmlText::Print( FILE* cfile, int depth ) const { if ( cdata ) { int i; fprintf( cfile, "\n" ); for ( i=0; i\n" ); } else { TIXML_STRING buffer; PutString( value, &buffer ); fprintf( cfile, "%s", buffer.c_str() ); } } void TiXmlText::StreamOut( TIXML_OSTREAM * stream ) const { if ( cdata ) { (*stream) << ""; } else { PutString( value, stream ); } } void TiXmlText::CopyTo( TiXmlText* target ) const { TiXmlNode::CopyTo( target ); target->cdata = cdata; } TiXmlNode* TiXmlText::Clone() const { TiXmlText* clone = 0; clone = new TiXmlText( "" ); if ( !clone ) return 0; CopyTo( clone ); return clone; } TiXmlDeclaration::TiXmlDeclaration( const char * _version, const char * _encoding, const char * _standalone ) : TiXmlNode( TiXmlNode::DECLARATION ) { version = _version; encoding = _encoding; standalone = _standalone; } #ifdef TIXML_USE_STL TiXmlDeclaration::TiXmlDeclaration( const std::string& _version, const std::string& _encoding, const std::string& _standalone ) : TiXmlNode( TiXmlNode::DECLARATION ) { version = _version; encoding = _encoding; standalone = _standalone; } #endif TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy ) : TiXmlNode( TiXmlNode::DECLARATION ) { copy.CopyTo( this ); } void TiXmlDeclaration::operator=( const TiXmlDeclaration& copy ) { Clear(); copy.CopyTo( this ); } void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/ ) const { fprintf (cfile, ""); } void TiXmlDeclaration::StreamOut( TIXML_OSTREAM * stream ) const { (*stream) << ""; } void TiXmlDeclaration::CopyTo( TiXmlDeclaration* target ) const { TiXmlNode::CopyTo( target ); target->version = version; target->encoding = encoding; target->standalone = standalone; } TiXmlNode* TiXmlDeclaration::Clone() const { TiXmlDeclaration* clone = new TiXmlDeclaration(); if ( !clone ) return 0; CopyTo( clone ); return clone; } void TiXmlUnknown::Print( FILE* cfile, int depth ) const { for ( int i=0; i", value.c_str() ); } void TiXmlUnknown::StreamOut( TIXML_OSTREAM * stream ) const { (*stream) << "<" << value << ">"; // Don't use entities here! It is unknown. } void TiXmlUnknown::CopyTo( TiXmlUnknown* target ) const { TiXmlNode::CopyTo( target ); } TiXmlNode* TiXmlUnknown::Clone() const { TiXmlUnknown* clone = new TiXmlUnknown(); if ( !clone ) return 0; CopyTo( clone ); return clone; } TiXmlAttributeSet::TiXmlAttributeSet() { sentinel.next = &sentinel; sentinel.prev = &sentinel; } TiXmlAttributeSet::~TiXmlAttributeSet() { assert( sentinel.next == &sentinel ); assert( sentinel.prev == &sentinel ); } void TiXmlAttributeSet::Add( TiXmlAttribute* addMe ) { assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. addMe->next = &sentinel; addMe->prev = sentinel.prev; sentinel.prev->next = addMe; sentinel.prev = addMe; } void TiXmlAttributeSet::Remove( TiXmlAttribute* removeMe ) { TiXmlAttribute* node; for( node = sentinel.next; node != &sentinel; node = node->next ) { if ( node == removeMe ) { node->prev->next = node->next; node->next->prev = node->prev; node->next = 0; node->prev = 0; return; } } assert( 0 ); // we tried to remove a non-linked attribute. } const TiXmlAttribute* TiXmlAttributeSet::Find( const char * name ) const { const TiXmlAttribute* node; for( node = sentinel.next; node != &sentinel; node = node->next ) { if ( node->name == name ) return node; } return 0; } TiXmlAttribute* TiXmlAttributeSet::Find( const char * name ) { TiXmlAttribute* node; for( node = sentinel.next; node != &sentinel; node = node->next ) { if ( node->name == name ) return node; } return 0; } #ifdef TIXML_USE_STL TIXML_ISTREAM & operator >> (TIXML_ISTREAM & in, TiXmlNode & base) { TIXML_STRING tag; tag.reserve( 8 * 1000 ); base.StreamIn( &in, &tag ); base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING ); return in; } #endif TIXML_OSTREAM & operator<< (TIXML_OSTREAM & out, const TiXmlNode & base) { base.StreamOut (& out); return out; } #ifdef TIXML_USE_STL std::string & operator<< (std::string& out, const TiXmlNode& base ) { std::ostringstream os_stream( std::ostringstream::out ); base.StreamOut( &os_stream ); out.append( os_stream.str() ); return out; } #endif TiXmlHandle TiXmlHandle::FirstChild() const { if ( node ) { TiXmlNode* child = node->FirstChild(); if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::FirstChild( const char * value ) const { if ( node ) { TiXmlNode* child = node->FirstChild( value ); if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::FirstChildElement() const { if ( node ) { TiXmlElement* child = node->FirstChildElement(); if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::FirstChildElement( const char * value ) const { if ( node ) { TiXmlElement* child = node->FirstChildElement( value ); if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::Child( int count ) const { if ( node ) { int i; TiXmlNode* child = node->FirstChild(); for ( i=0; child && iNextSibling(), ++i ) { // nothing } if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::Child( const char* value, int count ) const { if ( node ) { int i; TiXmlNode* child = node->FirstChild( value ); for ( i=0; child && iNextSibling( value ), ++i ) { // nothing } if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::ChildElement( int count ) const { if ( node ) { int i; TiXmlElement* child = node->FirstChildElement(); for ( i=0; child && iNextSiblingElement(), ++i ) { // nothing } if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const { if ( node ) { int i; TiXmlElement* child = node->FirstChildElement( value ); for ( i=0; child && iNextSiblingElement( value ), ++i ) { // nothing } if ( child ) return TiXmlHandle( child ); } return TiXmlHandle( 0 ); } passwordmaker-cli-1.5.orig/tclap/0000755000000000000000000000000011545725711015556 5ustar rootrootpasswordmaker-cli-1.5.orig/tclap/Visitor.h0000755000000000000000000000232511545725573017401 0ustar rootroot /****************************************************************************** * * file: Visitor.h * * Copyright (c) 2003, Michael E. Smoot . * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_VISITOR_H #define TCLAP_VISITOR_H namespace TCLAP { /** * A base class that defines the interface for visitors. */ class Visitor { public: /** * Constructor. Does nothing. */ Visitor() { } /** * Does nothing. Should be overridden by child. */ virtual void visit() { } }; } #endif passwordmaker-cli-1.5.orig/tclap/CmdLine.h0000755000000000000000000002671211545725573017263 0ustar rootroot /****************************************************************************** * * file: CmdLine.h * * Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_CMDLINE_H #define TCLAP_CMDLINE_H #include "tclap/SwitchArg.h" #include "tclap/UnlabeledValueArg.h" #include "tclap/UnlabeledMultiArg.h" #include "tclap/XorHandler.h" #include "tclap/HelpVisitor.h" #include "tclap/VersionVisitor.h" #include "tclap/IgnoreRestVisitor.h" #include "tclap/CmdLineOutput.h" #include "tclap/StdOutput.h" #include #include #include #include #include #include namespace TCLAP { /** * The base class that manages the command line definition and passes * along the parsing to the appropriate Arg classes. */ class CmdLine : public CmdLineInterface { protected: /** * The list of arguments that will be tested against the * command line. */ std::list _argList; /** * The name of the program. Set to argv[0]. */ std::string _progName; /** * A message used to describe the program. Used in the usage output. */ std::string _message; /** * The version to be displayed with the --version switch. */ std::string _version; /** * The number of arguments that are required to be present on * the command line. This is set dynamically, based on the * Args added to the CmdLine object. */ int _numRequired; /** * The character that is used to separate the argument flag/name * from the value. Defaults to ' ' (space). */ char _delimiter; /** * The handler that manages xoring lists of args. */ XorHandler _xorHandler; /** * A list of Args to be explicitly deleted when the destructor * is called. At the moment, this only includes the three default * Args. */ std::list _argDeleteOnExitList; /** * A list of Visitors to be explicitly deleted when the destructor * is called. At the moment, these are the Vistors created for the * default Args. */ std::list _visitorDeleteOnExitList; /** * Object that handles all output for the CmdLine. */ CmdLineOutput* _output; /** * Checks whether a name/flag string matches entirely matches * the Arg::blankChar. Used when multiple switches are combined * into a single argument. * \param s - The message to be used in the usage. */ bool _emptyCombined(const std::string& s); private: /** * Encapsulates the code common to the constructors (which is all * of it). */ void _constructor(); /** * Perform a delete ptr; operation on ptr when this object is deleted. */ void deleteOnExit(Arg* ptr); /** * Perform a delete ptr; operation on ptr when this object is deleted. */ void deleteOnExit(Visitor* ptr); /** * Is set to true when a user sets the output object. We use this so * that we don't delete objects that are created outside of this lib. */ bool _userSetOutput; public: /** * Command line constructor. DEPRECATED!!! This is here to maintain * backwards compatibility with earlier releases. Note that the * program name will be overwritten with argv[0]. The delimiter * used is ' ' (as before). * \param name - The program name - will be overwritten with argv[0]. * \param message - The message to be used in the usage output. * \param version - The version number to be used in the * --version switch. */ CmdLine(const std::string& name, const std::string& message, const std::string& version = "none" ); /** * Command line constructor. Defines how the arguments will be * parsed. * \param message - The message to be used in the usage * output. * \param delimiter - The character that is used to separate * the argument flag/name from the value. Defaults to ' ' (space). * \param version - The version number to be used in the * --version switch. */ CmdLine(const std::string& message, const char delimiter = ' ', const std::string& version = "none" ); /** * Deletes any resources allocated by a CmdLine object. */ virtual ~CmdLine(); /** * Adds an argument to the list of arguments to be parsed. * \param a - Argument to be added. */ void add( Arg& a ); /** * An alternative add. Functionally identical. * \param a - Argument to be added. */ void add( Arg* a ); /** * Add two Args that will be xor'd. If this method is used, add does * not need to be called. * \param a - Argument to be added and xor'd. * \param b - Argument to be added and xor'd. */ void xorAdd( Arg& a, Arg& b ); /** * Add a list of Args that will be xor'd. If this method is used, * add does not need to be called. * \param xors - List of Args to be added and xor'd. */ void xorAdd( std::vector& xors ); /** * Parses the command line. * \param argc - Number of arguments. * \param argv - Array of arguments. */ void parse(int argc, char** argv); /** * */ CmdLineOutput* getOutput(); /** * */ void setOutput(CmdLineOutput* co); /** * */ std::string& getVersion(); /** * */ std::string& getProgramName(); /** * */ std::list& getArgList(); /** * */ XorHandler& getXorHandler(); /** * */ char getDelimiter(); /** * */ std::string& getMessage(); }; /////////////////////////////////////////////////////////////////////////////// //Begin CmdLine.cpp /////////////////////////////////////////////////////////////////////////////// inline CmdLine::CmdLine(const std::string& n, const std::string& m, const std::string& v ) : _progName(n), _message(m), _version(v), _numRequired(0), _delimiter(' '), _userSetOutput(false) { _constructor(); } inline CmdLine::CmdLine(const std::string& m, char delim, const std::string& v ) : _progName("not_set_yet"), _message(m), _version(v), _numRequired(0), _delimiter(delim), _userSetOutput(false) { _constructor(); } inline CmdLine::~CmdLine() { ArgListIterator argIter; VisitorListIterator visIter; for( argIter = _argDeleteOnExitList.begin(); argIter != _argDeleteOnExitList.end(); ++argIter) delete *argIter; for( visIter = _visitorDeleteOnExitList.begin(); visIter != _visitorDeleteOnExitList.end(); ++visIter) delete *visIter; if ( !_userSetOutput ) delete _output; } inline void CmdLine::_constructor() { _output = new StdOutput; Visitor *v; Arg::setDelimiter( _delimiter ); v = new HelpVisitor( this, &_output ); SwitchArg* help = new SwitchArg("h","help", "Displays usage information and exits.", false, v); add( help ); deleteOnExit(help); deleteOnExit(v); v = new VersionVisitor( this, &_output ); SwitchArg* vers = new SwitchArg("v","version", "Displays version information and exits.", false, v); add( vers ); deleteOnExit(vers); deleteOnExit(v); v = new IgnoreRestVisitor(); SwitchArg* ignore = new SwitchArg(Arg::flagStartString(), Arg::ignoreNameString(), "Ignores the rest of the labeled arguments following this flag.", false, v); add( ignore ); deleteOnExit(ignore); deleteOnExit(v); } inline void CmdLine::xorAdd( std::vector& ors ) { _xorHandler.add( ors ); for (ArgVectorIterator it = ors.begin(); it != ors.end(); it++) { (*it)->forceRequired(); (*it)->setRequireLabel( "OR required" ); add( *it ); } } inline void CmdLine::xorAdd( Arg& a, Arg& b ) { std::vector ors; ors.push_back( &a ); ors.push_back( &b ); xorAdd( ors ); } inline void CmdLine::add( Arg& a ) { add( &a ); } inline void CmdLine::add( Arg* a ) { for( ArgListIterator it = _argList.begin(); it != _argList.end(); it++ ) if ( *a == *(*it) ) throw( SpecificationException( "Argument with same flag/name already exists!", a->longID() ) ); a->addToList( _argList ); if ( a->isRequired() ) _numRequired++; } inline void CmdLine::parse(int argc, char** argv) { try { _progName = argv[0]; // this step is necessary so that we have easy access to mutable strings. std::vector args; for (int i = 1; i < argc; i++) args.push_back(argv[i]); int requiredCount = 0; for (int i = 0; (unsigned int)i < args.size(); i++) { bool matched = false; for (ArgListIterator it = _argList.begin(); it != _argList.end(); it++) { if ( (*it)->processArg( &i, args ) ) { requiredCount += _xorHandler.check( *it ); matched = true; break; } } // checks to see if the argument is an empty combined switch ... // and if so, then we've actually matched it if ( !matched && _emptyCombined( args[i] ) ) matched = true; if ( !matched && !Arg::ignoreRest() ) throw(CmdLineParseException("Couldn't find match for argument", args[i])); } if ( requiredCount < _numRequired ) throw(CmdLineParseException("One or more required arguments missing!")); if ( requiredCount > _numRequired ) throw(CmdLineParseException("Too many arguments!")); } catch ( ArgException e ) { _output->failure(*this,e); exit(1); } } inline bool CmdLine::_emptyCombined(const std::string& s) { if ( s[0] != Arg::flagStartChar() ) return false; for ( int i = 1; (unsigned int)i < s.length(); i++ ) if ( s[i] != Arg::blankChar() ) return false; return true; } inline void CmdLine::deleteOnExit(Arg* ptr) { _argDeleteOnExitList.push_back(ptr); } inline void CmdLine::deleteOnExit(Visitor* ptr) { _visitorDeleteOnExitList.push_back(ptr); } inline CmdLineOutput* CmdLine::getOutput() { return _output; } inline void CmdLine::setOutput(CmdLineOutput* co) { _userSetOutput = true; _output = co; } inline std::string& CmdLine::getVersion() { return _version; } inline std::string& CmdLine::getProgramName() { return _progName; } inline std::list& CmdLine::getArgList() { return _argList; } inline XorHandler& CmdLine::getXorHandler() { return _xorHandler; } inline char CmdLine::getDelimiter() { return _delimiter; } inline std::string& CmdLine::getMessage() { return _message; } /////////////////////////////////////////////////////////////////////////////// //End CmdLine.cpp /////////////////////////////////////////////////////////////////////////////// } //namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/VersionVisitor.h0000755000000000000000000000347611545725573020757 0ustar rootroot /****************************************************************************** * * file: VersionVisitor.h * * Copyright (c) 2003, Michael E. Smoot . * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_VERSION_VISITOR_H #define TCLAP_VERSION_VISITOR_H #include "tclap/CmdLineInterface.h" #include "tclap/CmdLineOutput.h" #include "tclap/Visitor.h" namespace TCLAP { /** * A Vistor that will call the version method of the given CmdLineOutput * for the specified CmdLine object and then exit. */ class VersionVisitor: public Visitor { protected: /** * The CmdLine of interest. */ CmdLineInterface* _cmd; /** * The output object. */ CmdLineOutput** _out; public: /** * Constructor. * \param cmd - The CmdLine the output is generated for. * \param out - The type of output. */ VersionVisitor( CmdLineInterface* cmd, CmdLineOutput** out ) : Visitor(), _cmd( cmd ), _out( out ) { } /** * Calls the version method of the output object using the * specified CmdLine. */ void visit() { (*_out)->version(*_cmd); exit(0); } }; } #endif passwordmaker-cli-1.5.orig/tclap/MultiArg.h0000755000000000000000000003550511545725573017474 0ustar rootroot/****************************************************************************** * * file: MultiArg.h * * Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_MULTIPLE_ARGUMENT_H #define TCLAP_MULTIPLE_ARGUMENT_H #include #include #include "tclap/Arg.h" #ifdef HAVE_CONFIG_H #include #else #define HAVE_SSTREAM #endif #if defined(HAVE_SSTREAM) #include #elif defined(HAVE_STRSTREAM) #include #else #error "Need a stringstream (sstream or strstream) to compile!" #endif namespace TCLAP { template class MultiArg; namespace MULTI_ARG_HELPER { enum Error_e { EXTRACT_FAILURE = 1000, EXTRACT_TOO_MANY }; /** * This class is used to extract a value from an argument. * It is used because we need a special implementation to * deal with std::string and making a specialiced function * puts it in the T segment, thus generating link errors. * Having a specialiced class makes the symbols weak. * This is not pretty but I don't know how to make it * work any other way. */ template class ValueExtractor { friend class MultiArg; private: /** * Reference to the vector of values where the result of the * extraction will be put. */ std::vector &_values; /** * Constructor. * \param values - Where the values extracted will be put. */ ValueExtractor(std::vector &values) : _values(values) {} /** * Method that will attempt to parse the input stream for values * of type T. * \param val - Where the values parsed will be put. */ int extractValue( const std::string& val ) { T temp; #if defined(HAVE_SSTREAM) std::istringstream is(val); #elif defined(HAVE_STRSTREAM) std::istrstream is(val.c_str()); #else #error "Need a stringstream (sstream or strstream) to compile!" #endif int valuesRead = 0; while ( is.good() ) { if ( is.peek() != EOF ) is >> temp; else break; valuesRead++; } if ( is.fail() ) return EXTRACT_FAILURE; if ( valuesRead > 1 ) return EXTRACT_TOO_MANY; _values.push_back(temp); return 0; } }; /** * Specialization for string. This is necessary because istringstream * operator>> is not able to ignore spaces... meaning -x "X Y" will only * read 'X'... and thus the specialization. */ template<> class ValueExtractor { friend class MultiArg; private: /** * Reference to the vector of strings where the result of the * extraction will be put. */ std::vector &_values; /** * Constructor. * \param values - Where the strings extracted will be put. */ ValueExtractor(std::vector &values) : _values(values) {} /** * Method that will attempt to parse the input stream for values * of type std::string. * \param val - Where the values parsed will be put. */ int extractValue( const std::string& val ) { _values.push_back( val ); return 0; } }; } //namespace MULTI_ARG_HELPER /** * An argument that allows multiple values of type T to be specified. Very * similar to a ValueArg, except a vector of values will be returned * instead of just one. */ template class MultiArg : public Arg { protected: /** * The list of values parsed from the CmdLine. */ std::vector _values; /** * A list of allowed values. * A list of values allowed for this argument. If the value parsed * for this arg is not found in this list, then an exception is * thrown. If the list is empty, then any value is allowed. */ std::vector _allowed; /** * The description of type T to be used in the usage. */ std::string _typeDesc; /** * Extracts the value from the string. * Attempts to parse string as type T, if this fails an exception * is thrown. * \param val - The string to be read. */ void _extractValue( const std::string& val ); /** * Checks to see if parsed value is in allowed list. * \param val - value parsed (only used in output). */ void _checkAllowed( const std::string& val ); public: /** * Constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param req - Whether the argument is required on the command * line. * \param typeDesc - A short, human readable description of the * type that this object expects. This is used in the generation * of the USAGE statement. The goal is to be helpful to the end user * of the program. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ MultiArg( const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, Visitor* v = NULL); /** * Constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param req - Whether the argument is required on the command * line. * \param typeDesc - A short, human readable description of the * type that this object expects. This is used in the generation * of the USAGE statement. The goal is to be helpful to the end user * of the program. * \param parser - A CmdLine parser object to add this Arg to * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ MultiArg( const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, CmdLineInterface& parser, Visitor* v = NULL ); /** * Constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param req - Whether the argument is required on the command * line. * \param allowed - A vector of type T that where the values in the * vector are the only values allowed for the arg. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ MultiArg( const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::vector& allowed, Visitor* v = NULL ); /** * Constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param req - Whether the argument is required on the command * line. * \param allowed - A vector of type T that where the values in the * vector are the only values allowed for the arg. * \param parser - A CmdLine parser object to add this Arg to * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ MultiArg( const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::vector& allowed, CmdLineInterface& parser, Visitor* v = NULL ); /** * Handles the processing of the argument. * This re-implements the Arg version of this method to set the * _value of the argument appropriately. It knows the difference * between labeled and unlabeled. * \param i - Pointer the the current argument in the list. * \param args - Mutable list of strings. Passed from main(). */ virtual bool processArg(int* i, std::vector& args); /** * Returns a vector of type T containing the values parsed from * the command line. */ const std::vector& getValue(); /** * Returns the a short id string. Used in the usage. * \param val - value to be used. */ virtual std::string shortID(const std::string& val="val") const; /** * Returns the a long id string. Used in the usage. * \param val - value to be used. */ virtual std::string longID(const std::string& val="val") const; /** * Once we've matched the first value, then the arg is no longer * required. */ virtual bool isRequired() const; private: /** * Common initialization code for constructors with allowed vectors. */ void allowedInit(); }; /** * */ template void MultiArg::allowedInit() { for ( unsigned int i = 0; i < _allowed.size(); i++ ) { #if defined(HAVE_SSTREAM) std::ostringstream os; #elif defined(HAVE_STRSTREAM) std::ostrstream os; #else #error "Need a stringstream (sstream or strstream) to compile!" #endif os << _allowed[i]; std::string temp( os.str() ); if ( i > 0 ) _typeDesc += "|"; _typeDesc += temp; } } /** * */ template MultiArg::MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, Visitor* v) : Arg( flag, name, desc, req, true, v ), _typeDesc( typeDesc ) { } template MultiArg::MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::string& typeDesc, CmdLineInterface& parser, Visitor* v) : Arg( flag, name, desc, req, true, v ), _typeDesc( typeDesc ) { parser.add( this ); } /** * */ template MultiArg::MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::vector& allowed, Visitor* v) : Arg( flag, name, desc, req, true, v ), _allowed( allowed ) { allowedInit(); } template MultiArg::MultiArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, const std::vector& allowed, CmdLineInterface& parser, Visitor* v) : Arg( flag, name, desc, req, true, v ), _allowed( allowed ) { allowedInit(); parser.add( this ); } /** * */ template const std::vector& MultiArg::getValue() { return _values; } /** * */ template bool MultiArg::processArg(int *i, std::vector& args) { if ( _ignoreable && Arg::ignoreRest() ) return false; if ( _hasBlanks( args[*i] ) ) return false; std::string flag = args[*i]; std::string value = ""; trimFlag( flag, value ); if ( argMatches( flag ) ) { if ( Arg::delimiter() != ' ' && value == "" ) throw( ArgParseException( "Couldn't find delimiter for this argument!", toString() ) ); if ( value == "" ) { (*i)++; if ( (unsigned int)*i < args.size() ) _extractValue( args[*i] ); else throw( ArgParseException("Missing a value for this argument!", toString() ) ); } else _extractValue( value ); _checkWithVisitor(); return true; } else return false; } /** * Checks to see if the value parsed is in the allowed list. */ template void MultiArg::_checkAllowed( const std::string& val ) { if ( _allowed.size() > 0 ) if ( find(_allowed.begin(),_allowed.end(),_values.back()) == _allowed.end() ) throw( CmdLineParseException( "Couldn't find '" + val + "' in allowed list.", toString() ) ); } /** * */ template std::string MultiArg::shortID(const std::string& val) const { std::string id = Arg::shortID(_typeDesc) + " ... "; return id; } /** * */ template std::string MultiArg::longID(const std::string& val) const { std::string id = Arg::longID(_typeDesc) + " (accepted multiple times)"; return id; } /** * Once we've matched the first value, then the arg is no longer * required. */ template bool MultiArg::isRequired() const { if ( _required ) { if ( _values.size() > 1 ) return false; else return true; } else return false; } template void MultiArg::_extractValue( const std::string& val ) { MULTI_ARG_HELPER::ValueExtractor ve(_values); int err = ve.extractValue(val); if ( err == MULTI_ARG_HELPER::EXTRACT_FAILURE ) throw( ArgParseException("Couldn't read argument value " "from string '" + val + "'", toString() ) ); if(err == MULTI_ARG_HELPER::EXTRACT_TOO_MANY) throw( ArgParseException("More than one valid value " "parsed from string '" + val + "'", toString() ) ); _checkAllowed( val ); } } // namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/IgnoreRestVisitor.h0000755000000000000000000000255311545725573021406 0ustar rootroot /****************************************************************************** * * file: IgnoreRestVisitor.h * * Copyright (c) 2003, Michael E. Smoot . * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_IGNORE_REST_VISITOR_H #define TCLAP_IGNORE_REST_VISITOR_H #include "tclap/Visitor.h" #include "tclap/Arg.h" namespace TCLAP { /** * A Vistor that tells the CmdLine to begin ignoring arguments after * this one is parsed. */ class IgnoreRestVisitor: public Visitor { public: /** * Constructor. */ IgnoreRestVisitor() : Visitor() {} /** * Sets Arg::_ignoreRest. */ void visit() { Arg::beginIgnoring(); } }; } #endif passwordmaker-cli-1.5.orig/tclap/CmdLineOutput.h0000755000000000000000000000360411545725573020477 0ustar rootroot /****************************************************************************** * * file: CmdLineOutput.h * * Copyright (c) 2004, Michael E. Smoot * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_CMDLINEOUTPUT_H #define TCLAP_CMDLINEOUTPUT_H #include #include #include #include #include #include namespace TCLAP { class CmdLineInterface; class ArgException; /** * The interface that any output object must implement. */ class CmdLineOutput { public: /** * Generates some sort of output for the USAGE. * \param c - The CmdLine object the output is generated for. */ virtual void usage(CmdLineInterface& c)=0; /** * Generates some sort of output for the version. * \param c - The CmdLine object the output is generated for. */ virtual void version(CmdLineInterface& c)=0; /** * Generates some sort of output for a failure. * \param c - The CmdLine object the output is generated for. * \param e - The ArgException that caused the failure. */ virtual void failure( CmdLineInterface& c, ArgException& e )=0; }; } //namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/UnlabeledValueArg.h0000755000000000000000000002656611545725573021301 0ustar rootroot /****************************************************************************** * * file: UnlabeledValueArg.h * * Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H #define TCLAP_UNLABELED_VALUE_ARGUMENT_H #include #include #include "tclap/ValueArg.h" namespace TCLAP { /** * The basic unlabeled argument that parses a value. * This is a template class, which means the type T defines the type * that a given object will attempt to parse when an UnlabeledValueArg * is reached in the list of args that the CmdLine iterates over. */ template class UnlabeledValueArg : public ValueArg { // If compiler has two stage name lookup (as gcc >= 3.4 does) // this is requried to prevent undef. symbols using ValueArg::_ignoreable; using ValueArg::_hasBlanks; using ValueArg::_extractValue; using ValueArg::_typeDesc; using ValueArg::_name; using ValueArg::_description; using ValueArg::_alreadySet; public: /** * UnlabeledValueArg constructor. * Note that this constructor does not have a required flag. Any * unlabeled argument added to the CmdLine is by default required. * If you want optional, unlabeled arguments then use an * UnlabeledMultiArg. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param value - The default value assigned to this argument if it * is not present on the command line. * \param typeDesc - A short, human readable description of the * type that this object expects. This is used in the generation * of the USAGE statement. The goal is to be helpful to the end user * of the program. * \param ignoreable - Allows you to specify that this argument can be * ignored if the '--' flag is set. This defaults to false (cannot * be ignored) and should generally stay that way unless you have * some special need for certain arguments to be ignored. * \param v - Optional Vistor. You should leave this blank unless * you have a very good reason. */ UnlabeledValueArg( const std::string& name, const std::string& desc, T value, const std::string& typeDesc, bool ignoreable = false, Visitor* v = NULL); /** * UnlabeledValueArg constructor. * Note that this constructor does not have a required flag. Any * unlabeled argument added to the CmdLine is by default required. * If you want optional, unlabeled arguments then use an * UnlabeledMultiArg. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param value - The default value assigned to this argument if it * is not present on the command line. * \param typeDesc - A short, human readable description of the * type that this object expects. This is used in the generation * of the USAGE statement. The goal is to be helpful to the end user * of the program. * \param parser - A CmdLine parser object to add this Arg to * \param ignoreable - Allows you to specify that this argument can be * ignored if the '--' flag is set. This defaults to false (cannot * be ignored) and should generally stay that way unless you have * some special need for certain arguments to be ignored. * \param v - Optional Vistor. You should leave this blank unless * you have a very good reason. */ UnlabeledValueArg( const std::string& name, const std::string& desc, T value, const std::string& typeDesc, CmdLineInterface& parser, bool ignoreable = false, Visitor* v = NULL ); /** * UnlabeledValueArg constructor. * Note that this constructor does not have a required flag. Any * unlabeled argument added to the CmdLine is by default required. * If you want optional, unlabeled arguments then use an * UnlabeledMultiArg. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param value - The default value assigned to this argument if it * is not present on the command line. * \param allowed - A vector of type T that where the values in the * vector are the only values allowed for the arg. * \param ignoreable - Allows you to specify that this argument can be * ignored if the '--' flag is set. This defaults to false (cannot * be ignored) and should generally stay that way unless you have * some special need for certain arguments to be ignored. * \param v - Optional Vistor. You should leave this blank unless * you have a very good reason. */ UnlabeledValueArg( const std::string& name, const std::string& desc, T value, const std::vector& allowed, bool ignoreable = false, Visitor* v = NULL ); /** * UnlabeledValueArg constructor. * Note that this constructor does not have a required flag. Any * unlabeled argument added to the CmdLine is by default required. * If you want optional, unlabeled arguments then use an * UnlabeledMultiArg. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param value - The default value assigned to this argument if it * is not present on the command line. * \param allowed - A vector of type T that where the values in the * vector are the only values allowed for the arg. * \param parser - A CmdLine parser object to add this Arg to * \param ignoreable - Allows you to specify that this argument can be * ignored if the '--' flag is set. This defaults to false (cannot * be ignored) and should generally stay that way unless you have * some special need for certain arguments to be ignored. * \param v - Optional Vistor. You should leave this blank unless * you have a very good reason. */ UnlabeledValueArg( const std::string& name, const std::string& desc, T value, const std::vector& allowed, CmdLineInterface& parser, bool ignoreable = false, Visitor* v = NULL); /** * Handles the processing of the argument. * This re-implements the Arg version of this method to set the * _value of the argument appropriately. Handling specific to * unlabled arguments. * \param i - Pointer the the current argument in the list. * \param args - Mutable list of strings. */ virtual bool processArg(int* i, std::vector& args); /** * Overrides shortID for specific behavior. */ virtual std::string shortID(const std::string& val="val") const; /** * Overrides longID for specific behavior. */ virtual std::string longID(const std::string& val="val") const; /** * Overrides operator== for specific behavior. */ virtual bool operator==(const Arg& a ) const; /** * Instead of pushing to the front of list, push to the back. * \param argList - The list to add this to. */ virtual void addToList( std::list& argList ) const; }; /** * Constructor implemenation. */ template UnlabeledValueArg::UnlabeledValueArg(const std::string& name, const std::string& desc, T val, const std::string& typeDesc, bool ignoreable, Visitor* v) : ValueArg("", name, desc, true, val, typeDesc, v) { _ignoreable = ignoreable; } template UnlabeledValueArg::UnlabeledValueArg(const std::string& name, const std::string& desc, T val, const std::string& typeDesc, CmdLineInterface& parser, bool ignoreable, Visitor* v) : ValueArg("", name, desc, true, val, typeDesc, v) { _ignoreable = ignoreable; parser.add( this ); } /** * Constructor implemenation. */ template UnlabeledValueArg::UnlabeledValueArg(const std::string& name, const std::string& desc, T val, const std::vector& allowed, bool ignoreable, Visitor* v) : ValueArg("", name, desc, true, val, allowed, v) { _ignoreable = ignoreable; } template UnlabeledValueArg::UnlabeledValueArg(const std::string& name, const std::string& desc, T val, const std::vector& allowed, CmdLineInterface& parser, bool ignoreable, Visitor* v) : ValueArg("", name, desc, true, val, allowed, v) { _ignoreable = ignoreable; parser.add( this ); } /** * Implementation of processArg(). */ template bool UnlabeledValueArg::processArg(int *i, std::vector& args) { if ( _alreadySet ) return false; if ( _hasBlanks( args[*i] ) ) return false; // never ignore an unlabeled arg _extractValue( args[*i] ); _alreadySet = true; return true; } /** * Overriding shortID for specific output. */ template std::string UnlabeledValueArg::shortID(const std::string& val) const { std::string id = "<" + _typeDesc + ">"; return id; } /** * Overriding longID for specific output. */ template std::string UnlabeledValueArg::longID(const std::string& val) const { // Ideally we would like to be able to use RTTI to return the name // of the type required for this argument. However, g++ at least, // doesn't appear to return terribly useful "names" of the types. std::string id = "<" + _typeDesc + ">"; return id; } /** * Overriding operator== for specific behavior. */ template bool UnlabeledValueArg::operator==(const Arg& a ) const { if ( _name == a.getName() || _description == a.getDescription() ) return true; else return false; } template void UnlabeledValueArg::addToList( std::list& argList ) const { argList.push_back( (Arg*)this ); } } #endif passwordmaker-cli-1.5.orig/tclap/ArgException.h0000755000000000000000000001162511545725573020335 0ustar rootroot /****************************************************************************** * * file: ArgException.h * * Copyright (c) 2003, Michael E. Smoot . * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_ARG_EXCEPTION_H #define TCLAP_ARG_EXCEPTION_H #include #include namespace TCLAP { /** * A simple class that defines and argument exception. Should be caught * whenever a CmdLine is created and parsed. */ class ArgException : public std::exception { public: /** * Constructor. * \param text - The text of the exception. * \param id - The text identifying the argument source. * \param td - Text describing the type of ArgException it is. * of the exception. */ ArgException( const std::string& text = "undefined exception", const std::string& id = "undefined", const std::string& td = "Generic ArgException") : std::exception(), _errorText(text), _argId( id ), _typeDescription(td) { } /** * Destructor. */ virtual ~ArgException() throw() { } /** * Returns the error text. */ std::string error() const { return ( _errorText ); } /** * Returns the argument id. */ std::string argId() const { if ( _argId == "undefined" ) return " "; else return ( "Argument: " + _argId ); } /** * Returns the arg id and error text. */ const char* what() const throw() { std::string ex = _argId + " -- " + _errorText; return ex.c_str(); } /** * Returns the type of the exception. Used to explain and distinguish * between different child exceptions. */ std::string typeDescription() const { return _typeDescription; } private: /** * The text of the exception message. */ std::string _errorText; /** * The argument related to this exception. */ std::string _argId; /** * Describes the type of the exception. Used to distinguish * between different child exceptions. */ std::string _typeDescription; }; /** * Thrown from within the child Arg classes when it fails to properly * parse the argument it has been passed. */ class ArgParseException : public ArgException { public: /** * Constructor. * \param text - The text of the exception. * \param id - The text identifying the argument source * of the exception. */ ArgParseException( const std::string& text = "undefined exception", const std::string& id = "undefined" ) : ArgException( text, id, std::string( "Exception found while parsing " ) + std::string( "the value the Arg has been passed." )) { } }; /** * Thrown from CmdLine when the arguments on the command line are not * properly specified, e.g. too many arguments, required argument missing, etc. */ class CmdLineParseException : public ArgException { public: /** * Constructor. * \param text - The text of the exception. * \param id - The text identifying the argument source * of the exception. */ CmdLineParseException( const std::string& text = "undefined exception", const std::string& id = "undefined" ) : ArgException( text, id, std::string( "Exception found when the values ") + std::string( "on the command line do not meet ") + std::string( "the requirements of the defined ") + std::string( "Args." )) { } }; /** * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g. * same flag as another Arg, same name, etc. */ class SpecificationException : public ArgException { public: /** * Constructor. * \param text - The text of the exception. * \param id - The text identifying the argument source * of the exception. */ SpecificationException( const std::string& text = "undefined exception", const std::string& id = "undefined" ) : ArgException( text, id, std::string("Exception found when an Arg object ")+ std::string("is improperly defined by the ") + std::string("developer." )) { } }; } // namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/ValueArg.h0000755000000000000000000004344211545725573017455 0ustar rootroot/****************************************************************************** * * file: ValueArg.h * * Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_VALUE_ARGUMENT_H #define TCLAP_VALUE_ARGUMENT_H #include #include #include "tclap/Arg.h" #ifdef HAVE_CONFIG_H #include #else #define HAVE_SSTREAM #endif #if defined(HAVE_SSTREAM) #include #elif defined(HAVE_STRSTREAM) #include #else #error "Need a stringstream (sstream or strstream) to compile!" #endif namespace TCLAP { template class ValueArg; namespace VALUE_ARG_HELPER { enum Error_e { EXTRACT_FAILURE = 1000, EXTRACT_TOO_MANY }; /** * This class is used to extract a value from an argument. * It is used because we need a special implementation to * deal with std::string and making a specialiced function * puts it in the T segment, thus generating link errors. * Having a specialiced class makes the symbols weak. * This is not pretty but I don't know how to make it * work any other way. */ template class ValueExtractor { /** * */ friend class ValueArg; private: /** * Reference to the value where the result of the extraction will * be put. */ T &_value; /** * Constructor. * \param value - Where the value extracted will be put. */ ValueExtractor(T &value) : _value(value) { } /** * Method that will attempt to parse the input stream for a value * of type T. * \param val - Where the value parsed will be put. */ int extractValue( const std::string& val ) { #if defined(HAVE_SSTREAM) std::istringstream is(val); #elif defined(HAVE_STRSTREAM) std::istrstream is(val.c_str()); #else #error "Need a stringstream (sstream or strstream) to compile!" #endif int valuesRead = 0; while ( is.good() ) { if ( is.peek() != EOF ) is >> _value; else break; valuesRead++; } if ( is.fail() ) return EXTRACT_FAILURE; if ( valuesRead > 1 ) return EXTRACT_TOO_MANY; return 0; } }; /** * Specialization for string. This is necessary because istringstream * operator>> is not able to ignore spaces... meaning -x "X Y" will only * read 'X'... and thus the specialization. */ template<> class ValueExtractor { /** * */ friend class ValueArg; private: /** * Reference to the value where the result of the extraction will * be put. */ std::string &_value; /** * Constructor. * \param value - Where the value extracted will be put. */ ValueExtractor(std::string &value) : _value(value) {} /** * Method that will attempt to parse the input stream for a value * of type std::string. * \param val - Where the string parsed will be put. */ int extractValue( const std::string& val ) { _value = val; return 0; } }; } //namespace VALUE_ARG_HELPER /** * The basic labeled argument that parses a value. * This is a template class, which means the type T defines the type * that a given object will attempt to parse when the flag/name is matched * on the command line. While there is nothing stopping you from creating * an unflagged ValueArg, it is unwise and would cause significant problems. * Instead use an UnlabeledValueArg. */ template class ValueArg : public Arg { protected: /** * The value parsed from the command line. * Can be of any type, as long as the >> operator for the type * is defined. */ T _value; /** * A list of allowed values. * A list of values allowed for this argument. If the value parsed * for this arg is not found in this list, then an exception is * thrown. If the list is empty, then any value is allowed. */ std::vector _allowed; /** * A human readable description of the type to be parsed. * This is a hack, plain and simple. Ideally we would use RTTI to * return the name of type T, but until there is some sort of * consistent support for human readable names, we are left to our * own devices. */ std::string _typeDesc; /** * Extracts the value from the string. * Attempts to parse string as type T, if this fails an exception * is thrown. * \param val - value to be parsed. */ void _extractValue( const std::string& val ); /** * Checks to see if parsed value is in allowed list. * \param val - value parsed (only used in output). */ void _checkAllowed( const std::string& val ); public: /** * Labeled ValueArg constructor. * You could conceivably call this constructor with a blank flag, * but that would make you a bad person. It would also cause * an exception to be thrown. If you want an unlabeled argument, * use the other constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param req - Whether the argument is required on the command * line. * \param value - The default value assigned to this argument if it * is not present on the command line. * \param typeDesc - A short, human readable description of the * type that this object expects. This is used in the generation * of the USAGE statement. The goal is to be helpful to the end user * of the program. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ ValueArg( const std::string& flag, const std::string& name, const std::string& desc, bool req, T value, const std::string& typeDesc, Visitor* v = NULL); /** * Labeled ValueArg constructor. * You could conceivably call this constructor with a blank flag, * but that would make you a bad person. It would also cause * an exception to be thrown. If you want an unlabeled argument, * use the other constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param req - Whether the argument is required on the command * line. * \param value - The default value assigned to this argument if it * is not present on the command line. * \param typeDesc - A short, human readable description of the * type that this object expects. This is used in the generation * of the USAGE statement. The goal is to be helpful to the end user * of the program. * \param parser - A CmdLine parser object to add this Arg to * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ ValueArg( const std::string& flag, const std::string& name, const std::string& desc, bool req, T value, const std::string& typeDesc, CmdLineInterface& parser, Visitor* v = NULL ); /** * Labeled ValueArg constructor. * You could conceivably call this constructor with a blank flag, * but that would make you a bad person. It would also cause * an exception to be thrown. If you want an unlabeled argument, * use the other constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param req - Whether the argument is required on the command * line. * \param value - The default value assigned to this argument if it * is not present on the command line. * \param allowed - A vector of type T that where the values in the * vector are the only values allowed for the arg. * \param parser - A CmdLine parser object to add this Arg to. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ ValueArg( const std::string& flag, const std::string& name, const std::string& desc, bool req, T value, const std::vector& allowed, CmdLineInterface& parser, Visitor* v = NULL ); /** * Labeled ValueArg constructor. * You could conceivably call this constructor with a blank flag, * but that would make you a bad person. It would also cause * an exception to be thrown. If you want an unlabeled argument, * use the other constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param req - Whether the argument is required on the command * line. * \param value - The default value assigned to this argument if it * is not present on the command line. * \param allowed - A vector of type T that where the values in the * vector are the only values allowed for the arg. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ ValueArg( const std::string& flag, const std::string& name, const std::string& desc, bool req, T value, const std::vector& allowed, Visitor* v = NULL ); /** * Handles the processing of the argument. * This re-implements the Arg version of this method to set the * _value of the argument appropriately. It knows the difference * between labeled and unlabeled. * \param i - Pointer the the current argument in the list. * \param args - Mutable list of strings. Passed * in from main(). */ virtual bool processArg(int* i, std::vector& args); /** * Returns the value of the argument. */ T& getValue() ; /** * Specialization of shortID. * \param val - value to be used. */ virtual std::string shortID(const std::string& val = "val") const; /** * Specialization of longID. * \param val - value to be used. */ virtual std::string longID(const std::string& val = "val") const; private: /** * Common initialization code for constructors with allowed vectors. */ void allowedInit(); }; template void ValueArg::allowedInit() { for ( unsigned int i = 0; i < _allowed.size(); i++ ) { #if defined(HAVE_SSTREAM) std::ostringstream os; #elif defined(HAVE_STRSTREAM) std::ostrstream os; #else #error "Need a stringstream (sstream or strstream) to compile!" #endif os << _allowed[i]; std::string temp( os.str() ); if ( i > 0 ) _typeDesc += "|"; _typeDesc += temp; } } /** * Constructor implementation. */ template ValueArg::ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T val, const std::string& typeDesc, Visitor* v) : Arg(flag, name, desc, req, true, v), _value( val ), _typeDesc( typeDesc ) { } template ValueArg::ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T val, const std::string& typeDesc, CmdLineInterface& parser, Visitor* v) : Arg(flag, name, desc, req, true, v), _value( val ), _typeDesc( typeDesc ) { parser.add( this ); } /** * Constructor with allowed list. */ template ValueArg::ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T val, const std::vector& allowed, Visitor* v) : Arg(flag, name, desc, req, true, v), _value( val ), _allowed( allowed ) { allowedInit(); } template ValueArg::ValueArg(const std::string& flag, const std::string& name, const std::string& desc, bool req, T val, const std::vector& allowed, CmdLineInterface& parser, Visitor* v) : Arg(flag, name, desc, req, true, v), _value( val ), _allowed( allowed ) { allowedInit(); parser.add( this ); } /** * Implementation of getValue(). */ template T& ValueArg::getValue() { return _value; } /** * Implementation of processArg(). */ template bool ValueArg::processArg(int *i, std::vector& args) { if ( _ignoreable && Arg::ignoreRest() ) return false; if ( _hasBlanks( args[*i] ) ) return false; std::string flag = args[*i]; std::string value = ""; trimFlag( flag, value ); if ( argMatches( flag ) ) { if ( _alreadySet ) throw( CmdLineParseException("Argument already set!", toString()) ); if ( Arg::delimiter() != ' ' && value == "" ) throw( ArgParseException( "Couldn't find delimiter for this argument!", toString() ) ); if ( value == "" ) { (*i)++; if ( (unsigned int)*i < args.size() ) _extractValue( args[*i] ); else throw( ArgParseException("Missing a value for this argument!", toString() ) ); } else _extractValue( value ); _alreadySet = true; _checkWithVisitor(); return true; } else return false; } /** * Checks to see if the value parsed is in the allowed list. */ template void ValueArg::_checkAllowed( const std::string& val ) { if ( _allowed.size() > 0 ) if ( find(_allowed.begin(),_allowed.end(),_value) == _allowed.end() ) throw( CmdLineParseException( "Couldn't find '" + val + "' in allowed list.", toString() ) ); } /** * Implementation of shortID. */ template std::string ValueArg::shortID(const std::string& val) const { return Arg::shortID( _typeDesc ); } /** * Implementation of longID. */ template std::string ValueArg::longID(const std::string& val) const { return Arg::longID( _typeDesc ); } template void ValueArg::_extractValue( const std::string& val ) { VALUE_ARG_HELPER::ValueExtractor ve(_value); int err = ve.extractValue(val); if ( err == VALUE_ARG_HELPER::EXTRACT_FAILURE ) throw( ArgParseException("Couldn't read argument value from string '" + val + "'", toString() ) ); if ( err == VALUE_ARG_HELPER::EXTRACT_TOO_MANY ) throw( ArgParseException( "More than one valid value parsed from string '" + val + "'", toString() ) ); _checkAllowed( val ); } } // namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/XorHandler.h0000755000000000000000000001123711545725573020012 0ustar rootroot /****************************************************************************** * * file: XorHandler.h * * Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_XORHANDLER_H #define TCLAP_XORHANDLER_H #include "tclap/Arg.h" #include #include #include #include namespace TCLAP { /** * This class handles lists of Arg's that are to be XOR'd on the command * line. This is used by CmdLine and you shouldn't ever use it. */ class XorHandler { protected: /** * The list of of lists of Arg's to be or'd together. */ std::vector< std::vector > _orList; public: /** * Constructor. Does nothing. */ XorHandler( ) {} /** * Add a list of Arg*'s that will be orred together. * \param ors - list of Arg* that will be xor'd. */ void add( std::vector& ors ); /** * Checks whether the specified Arg is in one of the xor lists and * if it does match one, returns the size of the xor list that the * Arg matched. If the Arg matches, then it also sets the rest of * the Arg's in the list. You shouldn't use this. * \param a - The Arg to be checked. */ int check( const Arg* a ); /** * Returns the XOR specific short usage. */ std::string shortUsage(); /** * Prints the XOR specific long usage. * \param os - Stream to print to. */ void printLongUsage(std::ostream& os); /** * Simply checks whether the Arg is contained in one of the arg * lists. * \param a - The Arg to be checked. */ bool contains( const Arg* a ); std::vector< std::vector >& getXorList(); }; ////////////////////////////////////////////////////////////////////// //BEGIN XOR.cpp ////////////////////////////////////////////////////////////////////// inline void XorHandler::add( std::vector& ors ) { _orList.push_back( ors ); } /* inline std::string XorHandler::shortUsage() { std::string out = ""; for ( int i = 0; (unsigned int)i < _orList.size(); i++ ) { out += " {"; for ( ArgVectorIterator it = _orList[i].begin(); it != _orList[i].end(); it++ ) out += (*it)->shortID() + "|"; out[out.length()-1] = '}'; } return out; } inline void XorHandler::printLongUsage( std::ostream& os ) { for ( int i = 0; (unsigned int)i < _orList.size(); i++ ) { for ( ArgVectorIterator it = _orList[i].begin(); it != _orList[i].end(); it++ ) { spacePrint( os, (*it)->longID(), 75, 3, 3 ); spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); if ( it+1 != _orList[i].end() ) spacePrint(os, "-- OR --", 75, 9); } os << std::endl << std::endl; } } */ inline int XorHandler::check( const Arg* a ) { // iterate over each XOR list for ( int i = 0; (unsigned int)i < _orList.size(); i++ ) { // if the XOR list contains the arg.. if ( find( _orList[i].begin(), _orList[i].end(), a ) != _orList[i].end() ) { // go through and set each arg that is not a for ( ArgVectorIterator it = _orList[i].begin(); it != _orList[i].end(); it++ ) if ( a != (*it) ) (*it)->xorSet(); // return the number of required args that have now been set return (int)_orList[i].size(); } } if ( a->isRequired() ) return 1; else return 0; } inline bool XorHandler::contains( const Arg* a ) { for ( int i = 0; (unsigned int)i < _orList.size(); i++ ) for ( ArgVectorIterator it = _orList[i].begin(); it != _orList[i].end(); it++ ) if ( a == (*it) ) return true; return false; } inline std::vector< std::vector >& XorHandler::getXorList() { return _orList; } ////////////////////////////////////////////////////////////////////// //END XOR.cpp ////////////////////////////////////////////////////////////////////// } //namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/StdOutput.h0000755000000000000000000002023211545725573017712 0ustar rootroot /****************************************************************************** * * file: StdOutput.h * * Copyright (c) 2004, Michael E. Smoot * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_STDCMDLINEOUTPUT_H #define TCLAP_STDCMDLINEOUTPUT_H #include #include #include #include #include #include "tclap/CmdLineInterface.h" #include "tclap/CmdLineOutput.h" #include "tclap/XorHandler.h" #include "tclap/Arg.h" namespace TCLAP { /** * A class that isolates any output from the CmdLine object so that it * may be easily modified. */ class StdOutput : public CmdLineOutput { public: /** * Prints the usage to stdout. Can be overridden to * produce alternative behavior. * \param c - The CmdLine object the output is generated for. */ virtual void usage(CmdLineInterface& c); /** * Prints the version to stdout. Can be overridden * to produce alternative behavior. * \param c - The CmdLine object the output is generated for. */ virtual void version(CmdLineInterface& c); /** * Prints (to stderr) an error message, short usage * Can be overridden to produce alternative behavior. * \param c - The CmdLine object the output is generated for. * \param e - The ArgException that caused the failure. */ virtual void failure(CmdLineInterface& c, ArgException& e ); protected: /** * Writes a brief usage message with short args. * \param c - The CmdLine object the output is generated for. * \param os - The stream to write the message to. */ void _shortUsage( CmdLineInterface& c, std::ostream& os ) const; /** * Writes a longer usage message with long and short args, * provides descriptions and prints message. * \param c - The CmdLine object the output is generated for. * \param os - The stream to write the message to. */ void _longUsage( CmdLineInterface& c, std::ostream& os ) const; /** * This function inserts line breaks and indents long strings * according the params input. It will only break lines at spaces, * commas and pipes. * \param os - The stream to be printed to. * \param s - The string to be printed. * \param maxWidth - The maxWidth allowed for the output line. * \param indentSpaces - The number of spaces to indent the first line. * \param secondLineOffset - The number of spaces to indent the second * and all subsequent lines in addition to indentSpaces. */ void spacePrint( std::ostream& os, const std::string& s, int maxWidth, int indentSpaces, int secondLineOffset ) const; }; inline void StdOutput::version(CmdLineInterface& _cmd) { std::string progName = _cmd.getProgramName(); std::string version = _cmd.getVersion(); std::cout << std::endl << progName << " version: " << version << std::endl << std::endl; } inline void StdOutput::usage(CmdLineInterface& _cmd ) { std::cout << std::endl << "USAGE: " << std::endl << std::endl; _shortUsage( _cmd, std::cout ); std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl; _longUsage( _cmd, std::cout ); std::cout << std::endl; } inline void StdOutput::failure( CmdLineInterface& _cmd, ArgException& e ) { std::string progName = _cmd.getProgramName(); std::cerr << "PARSE ERROR: " << e.argId() << std::endl << " " << e.error() << std::endl << std::endl; std::cerr << "Brief USAGE: " << std::endl; _shortUsage( _cmd, std::cerr ); std::cerr << std::endl << "For complete USAGE and HELP type: " << std::endl << " " << progName << " --help" << std::endl << std::endl; } inline void StdOutput::_shortUsage( CmdLineInterface& _cmd, std::ostream& os ) const { std::list argList = _cmd.getArgList(); std::string progName = _cmd.getProgramName(); XorHandler xorHandler = _cmd.getXorHandler(); std::vector< std::vector > xorList = xorHandler.getXorList(); std::string s = progName + " "; // first the xor for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) { s += " {"; for ( ArgVectorIterator it = xorList[i].begin(); it != xorList[i].end(); it++ ) s += (*it)->shortID() + "|"; s[s.length()-1] = '}'; } // then the rest for (ArgListIterator it = argList.begin(); it != argList.end(); it++) if ( !xorHandler.contains( (*it) ) ) s += " " + (*it)->shortID(); // if the program name is too long, then adjust the second line offset int secondLineOffset = (int)(progName.length()) + 2; if ( secondLineOffset > 75/2 ) secondLineOffset = (int)(75/2); spacePrint( std::cout, s, 75, 3, secondLineOffset ); } inline void StdOutput::_longUsage( CmdLineInterface& _cmd, std::ostream& os ) const { std::list argList = _cmd.getArgList(); std::string message = _cmd.getMessage(); XorHandler xorHandler = _cmd.getXorHandler(); std::vector< std::vector > xorList = xorHandler.getXorList(); // first the xor for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) { for ( ArgVectorIterator it = xorList[i].begin(); it != xorList[i].end(); it++ ) { spacePrint( os, (*it)->longID(), 75, 3, 3 ); spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); if ( it+1 != xorList[i].end() ) spacePrint(os, "-- OR --", 75, 9, 0); } os << std::endl << std::endl; } // then the rest for (ArgListIterator it = argList.begin(); it != argList.end(); it++) if ( !xorHandler.contains( (*it) ) ) { spacePrint( os, (*it)->longID(), 75, 3, 3 ); spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); os << std::endl; } os << std::endl; spacePrint( os, message, 75, 3, 0 ); } inline void StdOutput::spacePrint( std::ostream& os, const std::string& s, int maxWidth, int indentSpaces, int secondLineOffset ) const { int len = (int)(s.length()); if ( (len + indentSpaces > maxWidth) && maxWidth > 0 ) { int allowedLen = maxWidth - indentSpaces; int start = 0; while ( start < len ) { // find the substring length int stringLen = std::min( len - start, allowedLen ); // trim the length so it doesn't end in middle of a word if ( stringLen == allowedLen ) while ( s[stringLen+start] != ' ' && s[stringLen+start] != ',' && s[stringLen+start] != '|' && stringLen >= 0 ) stringLen--; // ok, the word is longer than the line, so just split in the // wherever the line ends if ( stringLen <= 0 ) stringLen = allowedLen; // check for newlines for ( int i = 0; i < stringLen; i++ ) if ( s[start+i] == '\n' ) stringLen = i+1; // print the indent for ( int i = 0; i < indentSpaces; i++ ) os << " "; if ( start == 0 ) { // handle second line offsets indentSpaces += secondLineOffset; // adjust allowed len allowedLen -= secondLineOffset; } os << s.substr(start,stringLen) << std::endl; // so we don't start a line with a space while ( s[stringLen+start] == ' ' && start < len ) start++; start += stringLen; } } else { for ( int i = 0; i < indentSpaces; i++ ) os << " "; os << s << std::endl; } } } //namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/HelpVisitor.h0000755000000000000000000000347511545725573020221 0ustar rootroot /****************************************************************************** * * file: HelpVisitor.h * * Copyright (c) 2003, Michael E. Smoot . * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_HELP_VISITOR_H #define TCLAP_HELP_VISITOR_H #include "tclap/CmdLineInterface.h" #include "tclap/CmdLineOutput.h" #include "tclap/Visitor.h" namespace TCLAP { /** * A Visitor object that calls the usage method of the given CmdLineOutput * object for the specified CmdLine object. */ class HelpVisitor: public Visitor { protected: /** * The CmdLine the output will be generated for. */ CmdLineInterface* _cmd; /** * The output object. */ CmdLineOutput** _out; public: /** * Constructor. * \param cmd - The CmdLine the output will be generated for. * \param out - The type of output. */ HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out) : Visitor(), _cmd( cmd ), _out( out ) { } /** * Calls the usage method of the CmdLineOutput for the * specified CmdLine. */ void visit() { (*_out)->usage(*_cmd); exit(0); } }; } #endif passwordmaker-cli-1.5.orig/tclap/UnlabeledMultiArg.h0000755000000000000000000002074211545725573021305 0ustar rootroot /****************************************************************************** * * file: UnlabeledMultiArg.h * * Copyright (c) 2003, Michael E. Smoot. * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H #define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H #include #include #include "tclap/MultiArg.h" namespace TCLAP { /** * Just like a MultiArg, except that the arguments are unlabeled. Basically, * this Arg will slurp up everything that hasn't been matched to another * Arg. */ template class UnlabeledMultiArg : public MultiArg { // If compiler has two stage name lookup (as gcc >= 3.4 does) // this is requried to prevent undef. symbols using MultiArg::_ignoreable; using MultiArg::_hasBlanks; using MultiArg::_extractValue; using MultiArg::_typeDesc; using MultiArg::_name; using MultiArg::_description; public: /** * Constructor. * \param name - The name of the Arg. Note that this is used for * identification, not as a long flag. * \param desc - A description of what the argument is for or * does. * \param typeDesc - A short, human readable description of the * type that this object expects. This is used in the generation * of the USAGE statement. The goal is to be helpful to the end user * of the program. * \param ignoreable - Whether or not this argument can be ignored * using the "--" flag. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ UnlabeledMultiArg( const std::string& name, const std::string& desc, const std::string& typeDesc, bool ignoreable = false, Visitor* v = NULL ); /** * Constructor. * \param name - The name of the Arg. Note that this is used for * identification, not as a long flag. * \param desc - A description of what the argument is for or * does. * \param typeDesc - A short, human readable description of the * type that this object expects. This is used in the generation * of the USAGE statement. The goal is to be helpful to the end user * of the program. * \param parser - A CmdLine parser object to add this Arg to * \param ignoreable - Whether or not this argument can be ignored * using the "--" flag. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ UnlabeledMultiArg( const std::string& name, const std::string& desc, const std::string& typeDesc, CmdLineInterface& parser, bool ignoreable = false, Visitor* v = NULL ); /** * Constructor. * \param name - The name of the Arg. Note that this is used for * identification, not as a long flag. * \param desc - A description of what the argument is for or * does. * \param allowed - A vector of type T that where the values in the * vector are the only values allowed for the arg. * \param ignoreable - Whether or not this argument can be ignored * using the "--" flag. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ UnlabeledMultiArg( const std::string& name, const std::string& desc, const std::vector& allowed, bool ignoreable = false, Visitor* v = NULL ); /** * Constructor. * \param name - The name of the Arg. Note that this is used for * identification, not as a long flag. * \param desc - A description of what the argument is for or * does. * \param allowed - A vector of type T that where the values in the * vector are the only values allowed for the arg. * \param parser - A CmdLine parser object to add this Arg to * \param ignoreable - Whether or not this argument can be ignored * using the "--" flag. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ UnlabeledMultiArg( const std::string& name, const std::string& desc, const std::vector& allowed, CmdLineInterface& parser, bool ignoreable = false, Visitor* v = NULL ); /** * Handles the processing of the argument. * This re-implements the Arg version of this method to set the * _value of the argument appropriately. It knows the difference * between labeled and unlabeled. * \param i - Pointer the the current argument in the list. * \param args - Mutable list of strings. Passed from main(). */ virtual bool processArg(int* i, std::vector& args); /** * Returns the a short id string. Used in the usage. * \param val - value to be used. */ virtual std::string shortID(const std::string& val="val") const; /** * Returns the a long id string. Used in the usage. * \param val - value to be used. */ virtual std::string longID(const std::string& val="val") const; /** * Opertor ==. * \param a - The Arg to be compared to this. */ virtual bool operator==(const Arg& a) const; /** * Pushes this to back of list rather than front. * \param argList - The list this should be added to. */ virtual void addToList( std::list& argList ) const; }; template UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, const std::string& desc, const std::string& typeDesc, bool ignoreable, Visitor* v) : MultiArg("", name, desc, false, typeDesc, v) { _ignoreable = ignoreable; } template UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, const std::string& desc, const std::string& typeDesc, CmdLineInterface& parser, bool ignoreable, Visitor* v) : MultiArg("", name, desc, false, typeDesc, v) { _ignoreable = ignoreable; parser.add( this ); } template UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, const std::string& desc, const std::vector& allowed, bool ignoreable, Visitor* v) : MultiArg("", name, desc, false, allowed, v) { _ignoreable = ignoreable; } template UnlabeledMultiArg::UnlabeledMultiArg(const std::string& name, const std::string& desc, const std::vector& allowed, CmdLineInterface& parser, bool ignoreable, Visitor* v) : MultiArg("", name, desc, false, allowed, v) { _ignoreable = ignoreable; parser.add( this ); } template bool UnlabeledMultiArg::processArg(int *i, std::vector& args) { if ( _hasBlanks( args[*i] ) ) return false; // never ignore an unlabeled multi arg _extractValue( args[*i] ); return true; } template std::string UnlabeledMultiArg::shortID(const std::string& val) const { std::string id = "<" + _typeDesc + "> ..."; return id; } template std::string UnlabeledMultiArg::longID(const std::string& val) const { std::string id = "<" + _typeDesc + "> (accepted multiple times)"; return id; } template bool UnlabeledMultiArg::operator==(const Arg& a) const { if ( _name == a.getName() || _description == a.getDescription() ) return true; else return false; } template void UnlabeledMultiArg::addToList( std::list& argList ) const { argList.push_back( (Arg*)this ); } } #endif passwordmaker-cli-1.5.orig/tclap/DocBookOutput.h0000755000000000000000000001075411545725573020510 0ustar rootroot /****************************************************************************** * * file: DocBookOutput.h * * Copyright (c) 2004, Michael E. Smoot * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_DOCBOOKOUTPUT_H #define TCLAP_DOCBOOKOUTPUT_H #include #include #include #include #include #include #include #include #include namespace TCLAP { /** * A class that generates DocBook output for usage() method for the * given CmdLine and its Args. */ class DocBookOutput : public CmdLineOutput { public: /** * Prints the usage to stdout. Can be overridden to * produce alternative behavior. * \param c - The CmdLine object the output is generated for. */ virtual void usage(CmdLineInterface& c); /** * Prints the version to stdout. Can be overridden * to produce alternative behavior. * \param c - The CmdLine object the output is generated for. */ virtual void version(CmdLineInterface& c); /** * Prints (to stderr) an error message, short usage * Can be overridden to produce alternative behavior. * \param c - The CmdLine object the output is generated for. * \param e - The ArgException that caused the failure. */ virtual void failure(CmdLineInterface& c, ArgException& e ); protected: /** * Substitutes the char r for string x in string s. * \param s - The string to operate on. * \param r - The char to replace. * \param x - What to replace r with. */ void substituteSpecialChars( std::string& s, char r, std::string& x ); }; inline void DocBookOutput::version(CmdLineInterface& _cmd) { std::cout << _cmd.getVersion() << std::endl; } inline void DocBookOutput::usage(CmdLineInterface& _cmd ) { std::list argList = _cmd.getArgList(); std::string progName = _cmd.getProgramName(); XorHandler xorHandler = _cmd.getXorHandler(); std::vector< std::vector > xorList = xorHandler.getXorList(); std::cout << "" << std::endl; std::cout << "" << std::endl << std::endl; std::cout << "" << std::endl; std::cout << "" << std::endl; std::cout << "" << progName << "" << std::endl; std::string lt = "<"; std::string gt = ">"; // xor for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) { std::cout << "" << std::endl; for ( ArgVectorIterator it = xorList[i].begin(); it != xorList[i].end(); it++ ) { std::string id = (*it)->shortID(); substituteSpecialChars(id,'<',lt); substituteSpecialChars(id,'>',gt); std::cout << "" << id << "" << std::endl; } std::cout << "" << std::endl; } for (ArgListIterator it = argList.begin(); it != argList.end(); it++) if ( !xorHandler.contains( (*it) ) ) { std::string id = (*it)->shortID(); substituteSpecialChars(id,'<',lt); substituteSpecialChars(id,'>',gt); std::cout << "" << id << "" << std::endl; } std::cout << "" << std::endl; std::cout << "" << std::endl; } inline void DocBookOutput::failure( CmdLineInterface& _cmd, ArgException& e ) { std::cout << e.what() << std::endl; } inline void DocBookOutput::substituteSpecialChars( std::string& s, char r, std::string& x ) { size_t p; while ( (p = s.find_first_of(r)) != std::string::npos ) { s.erase(p,1); s.insert(p,x); } } } //namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/SwitchArg.h0000755000000000000000000001370511545725573017641 0ustar rootroot /****************************************************************************** * * file: SwitchArg.h * * Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_SWITCH_ARG_H #define TCLAP_SWITCH_ARG_H #include #include #include "tclap/Arg.h" namespace TCLAP { /** * A simple switch argument. If the switch is set on the command line, then * the getValue method will return the opposite of the default value for the * switch. */ class SwitchArg : public Arg { protected: /** * The value of the switch. */ bool _value; public: /** * SwitchArg constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param def - The default value for this Switch. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ SwitchArg(const std::string& flag, const std::string& name, const std::string& desc, bool def, Visitor* v = NULL); /** * SwitchArg constructor. * \param flag - The one character flag that identifies this * argument on the command line. * \param name - A one word name for the argument. Can be * used as a long flag on the command line. * \param desc - A description of what the argument is for or * does. * \param parser - A CmdLine parser object to add this Arg to * \param def - The default value for this Switch. * \param v - An optional visitor. You probably should not * use this unless you have a very good reason. */ SwitchArg(const std::string& flag, const std::string& name, const std::string& desc, bool def, CmdLineInterface& parser, Visitor* v = NULL); /** * Handles the processing of the argument. * This re-implements the Arg version of this method to set the * _value of the argument appropriately. * \param i - Pointer the the current argument in the list. * \param args - Mutable list of strings. Passed * in from main(). */ virtual bool processArg(int* i, std::vector& args); /** * Checks a string to see if any of the chars in the string * match the flag for this Switch. */ bool combinedSwitchesMatch(std::string& combined); /** * Returns bool, whether or not the switch has been set. */ bool getValue(); }; ////////////////////////////////////////////////////////////////////// //BEGIN SwitchArg.cpp ////////////////////////////////////////////////////////////////////// inline SwitchArg::SwitchArg(const std::string& flag, const std::string& name, const std::string& desc, bool _default, Visitor* v ) : Arg(flag, name, desc, false, false, v), _value( _default ) { } inline SwitchArg::SwitchArg(const std::string& flag, const std::string& name, const std::string& desc, bool _default, CmdLineInterface& parser, Visitor* v ) : Arg(flag, name, desc, false, false, v), _value( _default ) { parser.add( this ); } inline bool SwitchArg::getValue() { return _value; } inline bool SwitchArg::combinedSwitchesMatch(std::string& combinedSwitches ) { // make sure this is actually a combined switch if ( combinedSwitches[0] != Arg::flagStartString()[0] ) return false; // make sure it isn't a long name if ( combinedSwitches.substr( 0, Arg::nameStartString().length() ) == Arg::nameStartString() ) return false; // ok, we're not specifying a ValueArg, so we know that we have // a combined switch list. for ( unsigned int i = 1; i < combinedSwitches.length(); i++ ) if ( combinedSwitches[i] == _flag[0] ) { // update the combined switches so this one is no longer present // this is necessary so that no unlabeled args are matched // later in the processing. //combinedSwitches.erase(i,1); combinedSwitches[i] = Arg::blankChar(); return true; } // none of the switches passed in the list match. return false; } inline bool SwitchArg::processArg(int *i, std::vector& args) { if ( _ignoreable && Arg::ignoreRest() ) return false; if ( argMatches( args[*i] ) || combinedSwitchesMatch( args[*i] ) ) { // If we match on a combined switch, then we want to return false // so that other switches in the combination will also have a // chance to match. bool ret = false; if ( argMatches( args[*i] ) ) ret = true; if ( _alreadySet ) throw(CmdLineParseException("Argument already set!", toString())); _alreadySet = true; if ( _value == true ) _value = false; else _value = true; _checkWithVisitor(); return ret; } else return false; } ////////////////////////////////////////////////////////////////////// //End SwitchArg.cpp ////////////////////////////////////////////////////////////////////// } //namespace TCLAP #endif passwordmaker-cli-1.5.orig/tclap/CmdLineInterface.h0000755000000000000000000000623611545725573021103 0ustar rootroot /****************************************************************************** * * file: CmdLineInterface.h * * Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_COMMANDLINE_INTERFACE_H #define TCLAP_COMMANDLINE_INTERFACE_H #include #include #include #include #include namespace TCLAP { class Arg; class CmdLineOutput; class XorHandler; /** * The base class that manages the command line definition and passes * along the parsing to the appropriate Arg classes. */ class CmdLineInterface { public: /** * Destructor */ virtual ~CmdLineInterface() {} /** * Adds an argument to the list of arguments to be parsed. * \param a - Argument to be added. */ virtual void add( Arg& a )=0; /** * An alternative add. Functionally identical. * \param a - Argument to be added. */ virtual void add( Arg* a )=0; /** * Add two Args that will be xor'd. * If this method is used, add does * not need to be called. * \param a - Argument to be added and xor'd. * \param b - Argument to be added and xor'd. */ virtual void xorAdd( Arg& a, Arg& b )=0; /** * Add a list of Args that will be xor'd. If this method is used, * add does not need to be called. * \param xors - List of Args to be added and xor'd. */ virtual void xorAdd( std::vector& xors )=0; /** * Parses the command line. * \param argc - Number of arguments. * \param argv - Array of arguments. */ virtual void parse(int argc, char** argv)=0; /** * Returns the CmdLineOutput object. */ virtual CmdLineOutput* getOutput()=0; /** * \param co - CmdLineOutput object that we want to use instead. */ virtual void setOutput(CmdLineOutput* co)=0; /** * Returns the version string. */ virtual std::string& getVersion()=0; /** * Returns the program name string. */ virtual std::string& getProgramName()=0; /** * Returns the argList. */ virtual std::list& getArgList()=0; /** * Returns the XorHandler. */ virtual XorHandler& getXorHandler()=0; /** * Returns the delimiter string. */ virtual char getDelimiter()=0; /** * Returns the message string. */ virtual std::string& getMessage()=0; }; } //namespace #endif passwordmaker-cli-1.5.orig/tclap/Arg.h0000755000000000000000000003523711545725573016463 0ustar rootroot /****************************************************************************** * * file: Arg.h * * Copyright (c) 2003, Michael E. Smoot . * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno . * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef TCLAP_ARGUMENT_H #define TCLAP_ARGUMENT_H #include #include #include #include #include "tclap/ArgException.h" #include "tclap/Visitor.h" #include "tclap/CmdLineInterface.h" namespace TCLAP { /** * A virtual base class that defines the essential data for all arguments. * This class, or one of its existing children, must be subclassed to do * anything. */ class Arg { private: /** * Indicates whether the rest of the arguments should be ignored. */ static bool& ignoreRestRef() { static bool ign = false; return ign; } /** * The delimiter that separates an argument flag/name from the * value. */ static char& delimiterRef() { static char delim = ' '; return delim; } protected: /** * The single char flag used to identify the argument. * This value (preceded by a dash {-}), can be used to identify * an argument on the command line. The _flag can be blank, * in fact this is how unlabeled args work. Unlabeled args must * override appropriate functions to get correct handling. Note * that the _flag does NOT include the dash as part of the flag. */ std::string _flag; /** * A single work namd indentifying the argument. * This value (preceded by two dashed {--}) can also be used * to identify an argument on the command line. Note that the * _name does NOT include the two dashes as part of the _name. The * _name cannot be blank. */ std::string _name; /** * Description of the argument. */ std::string _description; /** * Indicating whether the argument is required. */ bool _required; /** * Label to be used in usage description. Normally set to * "required", but can be changed when necessary. */ std::string _requireLabel; /** * Indicates whether a value is required for the argument. * Note that the value may be required but the argument/value * combination may not be, as specified by _required. */ bool _valueRequired; /** * Indicates whether the argument has been set. * Indicates that a value on the command line has matched the * name/flag of this argument and the values have been set accordingly. */ bool _alreadySet; /** * A pointer to a vistitor object. * The visitor allows special handling to occur as soon as the * argument is matched. This defaults to NULL and should not * be used unless absolutely necessary. */ Visitor* _visitor; /** * Whether this argument can be ignored, if desired. */ bool _ignoreable; /** * Indicates that the arg was set as part of an XOR and not on the * command line. */ bool _xorSet; /** * Performs the special handling described by the Vistitor. */ void _checkWithVisitor() const; /** * Primary constructor. YOU (yes you) should NEVER construct an Arg * directly, this is a base class that is extended by various children * that are meant to be used. Use SwitchArg, ValueArg, MultiArg, * UnlabeledValueArg, or UnlabeledMultiArg instead. * * \param flag - The flag identifying the argument. * \param name - The name identifying the argument. * \param desc - The description of the argument, used in the usage. * \param req - Whether the argument is required. * \param valreq - Whether the a value is required for the argument. * \param v - The visitor checked by the argument. Defaults to NULL. */ Arg( const std::string& flag, const std::string& name, const std::string& desc, bool req, bool valreq, Visitor* v = NULL ); public: /** * Destructor. */ virtual ~Arg(); /** * Adds this to the specified list of Args. * \param argList - The list to add this to. */ virtual void addToList( std::list& argList ) const; /** * Begin ignoring arguments since the "--" argument was specified. */ static void beginIgnoring() { ignoreRestRef() = true; } /** * Whether to ignore the rest. */ static bool ignoreRest() { return ignoreRestRef(); } /** * The delimiter that separates an argument flag/name from the * value. */ static char delimiter() { return delimiterRef(); } /** * The char used as a place holder when SwitchArgs are combined. * Currently set to '*', which shouldn't cause many problems since * *'s are expanded by most shells on the command line. */ static const char blankChar() { return '*'; } /** * The char that indicates the beginning of a flag. Currently '-'. */ static const char flagStartChar() { return '-'; } /** * The sting that indicates the beginning of a flag. Currently "-". * Should be identical to flagStartChar. */ static const std::string flagStartString() { return "-"; } /** * The sting that indicates the beginning of a name. Currently "--". * Should be flagStartChar twice. */ static const std::string nameStartString() { return "--"; } /** * The name used to identify the ignore rest argument. */ static const std::string ignoreNameString() { return "ignore_rest"; } /** * Sets the delimiter for all arguments. * \param c - The character that delimits flags/names from values. */ static void setDelimiter( char c ) { delimiterRef() = c; } /** * Pure virtual method meant to handle the parsing and value assignment * of the string on the command line. * \param i - Pointer the the current argument in the list. * \param args - Mutable list of strings. What is * passed in from main. */ virtual bool processArg(int *i, std::vector& args) = 0; /** * Operator ==. * Equality operator. Must be virtual to handle unlabeled args. * \param a - The Arg to be compared to this. */ virtual bool operator==(const Arg& a); /** * Returns the argument flag. */ const std::string& getFlag() const; /** * Returns the argument name. */ const std::string& getName() const; /** * Returns the argument description. */ std::string getDescription() const; /** * Indicates whether the argument is required. */ virtual bool isRequired() const; /** * Sets _required to true. This is used by the XorHandler. * You really have no reason to ever use it. */ void forceRequired(); /** * Sets the _alreadySet value to true. This is used by the XorHandler. * You really have no reason to ever use it. */ void xorSet(); /** * Indicates whether a value must be specified for argument. */ bool isValueRequired() const; /** * Indicates whether the argument has already been set. Only true * if the arg has been matched on the command line. */ bool isSet() const; /** * Indicates whether the argument can be ignored, if desired. */ bool isIgnoreable() const; /** * A method that tests whether a string matches this argument. * This is generally called by the processArg() method. This * method could be re-implemented by a child to change how * arguments are specified on the command line. * \param s - The string to be compared to the flag/name to determine * whether the arg matches. */ virtual bool argMatches( const std::string& s ) const; /** * Returns a simple string representation of the argument. * Primarily for debugging. */ virtual std::string toString() const; /** * Returns a short ID for the usage. * \param valueId - The value used in the id. */ virtual std::string shortID( const std::string& valueId = "val" ) const; /** * Returns a long ID for the usage. * \param valueId - The value used in the id. */ virtual std::string longID( const std::string& valueId = "val" ) const; /** * Trims a value off of the flag. * \param flag - The string from which the flag and value will be * trimmed. Contains the flag once the value has been trimmed. * \param value - Where the value trimmed from the string will * be stored. */ virtual void trimFlag( std::string& flag, std::string& value ) const; /** * Checks whether a given string has blank chars, indicating that * it is a combined SwitchArg. If so, return true, otherwise return * false. * \param s - string to be checked. */ bool _hasBlanks( const std::string& s ) const; /** * Sets the requireLabel. Used by XorHandler. You shouldn't ever * use this. * \param s - Set the requireLabel to this value. */ void setRequireLabel( const std::string& s ); }; /** * Typedef of an Arg list iterator. */ typedef std::list::iterator ArgListIterator; /** * Typedef of an Arg vector iterator. */ typedef std::vector::iterator ArgVectorIterator; /** * Typedef of a Visitor list iterator. */ typedef std::list::iterator VisitorListIterator; ////////////////////////////////////////////////////////////////////// //BEGIN Arg.cpp ////////////////////////////////////////////////////////////////////// inline Arg::Arg(const std::string& flag, const std::string& name, const std::string& desc, bool req, bool valreq, Visitor* v) : _flag(flag), _name(name), _description(desc), _required(req), _requireLabel("required"), _valueRequired(valreq), _alreadySet(false), _visitor( v ), _ignoreable(true), _xorSet(false) { if ( _flag.length() > 1 ) throw(SpecificationException( "Argument flag can only be one character long", toString() ) ); if ( _name != ignoreNameString() && ( _flag == Arg::flagStartString() || _flag == Arg::nameStartString() || _flag == " " ) ) throw(SpecificationException("Argument flag cannot be either '" + Arg::flagStartString() + "' or '" + Arg::nameStartString() + "' or a space.", toString() ) ); if ( ( _name.find( Arg::flagStartString(), 0 ) != std::string::npos ) || ( _name.find( Arg::nameStartString(), 0 ) != std::string::npos ) || ( _name.find( " ", 0 ) != std::string::npos ) ) throw(SpecificationException("Argument name cannot contain either '" + Arg::flagStartString() + "' or '" + Arg::nameStartString() + "' or space.", toString() ) ); } inline Arg::~Arg() { } inline std::string Arg::shortID( const std::string& valueId ) const { std::string id = ""; if ( _flag != "" ) id = Arg::flagStartString() + _flag; else id = Arg::nameStartString() + _name; std::string delim = " "; delim[0] = Arg::delimiter(); // ugly!!! if ( _valueRequired ) id += delim + "<" + valueId + ">"; if ( !_required ) id = "[" + id + "]"; return id; } inline std::string Arg::longID( const std::string& valueId ) const { std::string id = ""; if ( _flag != "" ) { id += Arg::flagStartString() + _flag; if ( _valueRequired ) id += " <" + valueId + ">"; id += ", "; } id += Arg::nameStartString() + _name; if ( _valueRequired ) id += " <" + valueId + ">"; return id; } inline bool Arg::operator==(const Arg& a) { if ( ( _flag != "" && _flag == a._flag ) || _name == a._name || _description == a._description ) return true; else return false; } inline std::string Arg::getDescription() const { std::string desc = ""; if ( _required ) desc = "(" + _requireLabel + ") "; if ( _valueRequired ) desc += "(value required) "; desc += _description; return desc; } inline const std::string& Arg::getFlag() const { return _flag; } inline const std::string& Arg::getName() const { return _name; } inline bool Arg::isRequired() const { return _required; } inline bool Arg::isValueRequired() const { return _valueRequired; } inline bool Arg::isSet() const { if ( _alreadySet && !_xorSet ) return true; else return false; } inline bool Arg::isIgnoreable() const { return _ignoreable; } inline void Arg::setRequireLabel( const std::string& s) { _requireLabel = s; } inline bool Arg::argMatches( const std::string& argFlag ) const { if ( ( argFlag == Arg::flagStartString() + _flag && _flag != "" ) || argFlag == Arg::nameStartString() + _name ) return true; else return false; } inline std::string Arg::toString() const { std::string s = ""; if ( _flag != "" ) s += Arg::flagStartString() + _flag + " "; s += "(" + Arg::nameStartString() + _name + ")"; return s; } inline void Arg::_checkWithVisitor() const { if ( _visitor != NULL ) _visitor->visit(); } /** * Implementation of trimFlag. */ inline void Arg::trimFlag(std::string& flag, std::string& value) const { int stop = 0; for ( int i = 0; (unsigned int)i < flag.length(); i++ ) if ( flag[i] == Arg::delimiter() ) { stop = i; break; } if ( stop > 1 ) { value = flag.substr(stop+1); flag = flag.substr(0,stop); } } /** * Implementation of _hasBlanks. */ inline bool Arg::_hasBlanks( const std::string& s ) const { for ( int i = 1; (unsigned int)i < s.length(); i++ ) if ( s[i] == Arg::blankChar() ) return true; return false; } inline void Arg::forceRequired() { _required = true; } inline void Arg::xorSet() { _alreadySet = true; _xorSet = true; } /** * Overridden by Args that need to added to the end of the list. */ inline void Arg::addToList( std::list& argList ) const { argList.push_front( (Arg*)this ); } ////////////////////////////////////////////////////////////////////// //END Arg.cpp ////////////////////////////////////////////////////////////////////// } //namespace TCLAP #endif passwordmaker-cli-1.5.orig/unix/0000755000000000000000000000000011552315352015430 5ustar rootrootpasswordmaker-cli-1.5.orig/unix/depends0000755000000000000000000000204611545725573017016 0ustar rootroothasher.o: shared/hasher.cpp shared/hasher.h shared/pwm_common.h leet.o: leet.cpp stdafx.h leet.h shared/pwm_common.h main.o: main.cpp stdafx.h passwordmaker.h shared/pwm_common.h \ tclap/CmdLine.h tclap/SwitchArg.h tclap/Arg.h tclap/ArgException.h \ tclap/Visitor.h tclap/CmdLineInterface.h tclap/UnlabeledValueArg.h \ tclap/ValueArg.h tclap/UnlabeledMultiArg.h tclap/MultiArg.h \ tclap/XorHandler.h tclap/HelpVisitor.h tclap/CmdLineOutput.h \ tclap/VersionVisitor.h tclap/IgnoreRestVisitor.h tclap/StdOutput.h \ pwmdefaults.h listaccounts.h urlsearch.h passwordmaker.o: passwordmaker.cpp stdafx.h passwordmaker.h \ shared/pwm_common.h shared/hasher.h shared/pwm_common.h leet.h pwmdefaults.o: pwmdefaults.cpp stdafx.h pwmdefaults.h tinyxml.h tinystr.o: tinystr.cpp stdafx.h tinyxml.o: tinyxml.cpp stdafx.h tinyxml.h tinyxmlerror.o: tinyxmlerror.cpp stdafx.h tinyxml.h tinyxmlparser.o: tinyxmlparser.cpp stdafx.h tinyxml.h listaccounts.o: listaccounts.cpp stdafx.h tinyxml.h listaccounts.h urlsearch.o: urlsearch.cpp stdafx.h tinyxml.h urlsearch.h passwordmaker-cli-1.5.orig/unix.mak0000755000000000000000000000422411545725573016143 0ustar rootroot# PasswordMaker - Creates and manages passwords # Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. # http://passwordmaker.org/ # grimholtz@yahoo.com # # This library is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 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 # FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # # You should have received a copy of the GNU Lesser 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 # # Written by Miquel Burns and Eric H. Jung # USE_MAC - 1 = compile on a MAC, 0 = compile elsewhere # FINK_REPO - Location of your MAC FINK software repository, you must have # libmhash and libpcre installed. USE_MAC = 0 FINK_REPO = /sw LINK = $(CXX) DEFINES = -DUSE_MHASH -DTIXML_USE_STL CFLAGS = -O2 -Wall $(DEFINES) CXXFLAGS = -O2 -frtti -fexceptions -Wall $(DEFINES) INCPATH = -I. LIBS = -lmhash -lpcre -lpcrecpp ifeq ($(USE_MAC), 1) CFLAGS := $(CFLAGS) -m32 CXXFLAGS := $(CXXFLAGS) -m32 INCPATH := -I$(FINK_REPO)/include $(INCPATH) LIBS := -m32 -L$(FINK_REPO)/lib $(LIBS) endif SOURCE = shared/hasher.cpp leet.cpp main.cpp passwordmaker.cpp pwmdefaults.cpp tinystr.cpp tinyxml.cpp tinyxmlerror.cpp tinyxmlparser.cpp listaccounts.cpp urlsearch.cpp OBJECTS = $(SOURCE:.cpp=.o) TARGET = passwordmaker $(TARGET): $(OBJECTS) $(LINK) -o "$(TARGET)" $(OBJECTS) $(LIBS) .SUFFIXES: .c .cpp .cc .cxx .cpp.o: $(CXX) -g -c $(CXXFLAGS) $(INCPATH) -o $@ $< .cc.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .cxx.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .c.o: $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< include unix/depends .PHONY: depend clean depend: $(CXX) -MM $(CXXFLAGS) $(INCPATH) $(SOURCE) > unix/depends clean: rm -f $(OBJECTS) $(TARGET) 2>/dev/null passwordmaker-cli-1.5.orig/passwordmaker.cpp0000755000000000000000000000567711545725573020071 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ #include "stdafx.h" #include "passwordmaker.h" #include "shared/hasher.h" #include "leet.h" using namespace std; char base93Set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./"; PasswordMaker::PasswordMaker(void) { hasher = new Hasher; } PasswordMaker::~PasswordMaker(void) { delete hasher; // Don't what a memory leak } bool PasswordMaker::initialized() { return hasher->initialized(); } void PasswordMaker::setPath(string path) { if (!hasher->initialized()) { delete hasher; hasher = new Hasher(path); } } string PasswordMaker::generatePassword(std::string masterPassword, hashType algorithm, bool hmac, bool trim, std::string url, int length, std::string characters, leetType useLeet, int leetLevel, std::string username, std::string modifier, std::string prefix, std::string suffix, bool sha256_bug) { string data, password = ""; int count = 0; leetLevel--; data = url + username + modifier; // Never *ever, ever* allow the character set length < 2 else // the hash algorithms will run indefinitely if (characters.length() < 2) return "Invalid arguments: the minimum number of characters is two."; if (useLeet == LEET_BEFORE || useLeet == LEET_BOTH) { masterPassword = leetConvert(leetLevel, masterPassword); data = leetConvert(leetLevel, data); } while ((int)password.length() < length) { char tempvalue[12]; sprintf(tempvalue, "%i", count); if (count == 0) { password = hasher->hash(algorithm, hmac, trim, characters, data, masterPassword, sha256_bug); } else { password += hasher->hash(algorithm, hmac, trim, characters, data, masterPassword+"\n"+tempvalue, sha256_bug); } count++; } if (useLeet == LEET_AFTER || useLeet == LEET_BOTH) password = leetConvert(leetLevel, password); password = prefix + password; password = password.substr(0, length-suffix.length()) + suffix; return password.substr(0, length); } passwordmaker-cli-1.5.orig/pwmdefaults.h0000755000000000000000000000426511545725573017177 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ #ifndef PWMDEFAULTS_H #define PWMDEFAULTS_H #include /** This class reads "passwordmaker.rdf" and sets defaults based on that. Then you can use the get functions to get defaults for use with command line options. */ class pwmDefaults { public: pwmDefaults(std::string filepath = "", std::string account = "", int account_count = 0); ~pwmDefaults(void); std::string getMasterPassword() { return masterPassword; }; std::string getCharset() { return characters; }; std::string getUserName() { return username; }; std::string getModifier() { return modifier; }; std::string getUseLeet() { return useLeet; }; std::string getAlgorithm() { return algorithm; }; std::string getPrefix() { return prefix; }; std::string getSuffix() { return suffix; }; std::string getURL() { return url; }; int getPasswordLength() { return length; }; int getLeetLevel() { return leetLevel; }; bool getHmac() { return hmac; }; bool getTrim() { return trim; }; bool usedFile() { return used_file; }; private: std::string masterPassword, useLeet, algorithm, characters, username, modifier, prefix, suffix, url; int length, leetLevel; bool hmac, trim, used_file; }; #endif // PWMDEFAULTS_H passwordmaker-cli-1.5.orig/listaccounts.cpp0000755000000000000000000001104511545725573017704 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung * listaccounts.cpp by Dave Marotti */ #include #include #include #include "stdafx.h" #include "tinyxml.h" #include "listaccounts.h" using namespace std; static set findSeq(string filepath, string about); static string findDesc(string filepath, string about); // Not the fastest nor most elegant method of parsing this thing, but it // works. Well, it works for my password file. -dave void listAccounts(string filepath, string about, int indent) { set list; set::iterator iter; list = findSeq(filepath, about); if(list.size()>0) { for(iter = list.begin(); iter!=list.end(); iter++) { set sublist = findSeq(filepath, *iter); cout << string(indent, ' ') << findDesc(filepath, *iter) << endl; for(set::iterator i2=sublist.begin(); i2!=sublist.end(); i2++) { listAccounts(filepath, *i2, indent+4); } } } else { cout << string(indent, ' ') << findDesc(filepath, about) << endl; } } // Gets the set of subnodes for a given RDF:Seq node set findSeq(string filepath, string about) { TiXmlDocument document(filepath); document.LoadFile(); string ns; set list; if (!document.Error()) { TiXmlHandle docHandle(&document); TiXmlElement *defaultNode = docHandle.FirstChildElement("RDF:RDF").Element(); if (defaultNode) { TiXmlAttribute *attrib = defaultNode->FirstAttribute(); // Find the namespace while (attrib) { if (!strcmp(attrib->Value(), "http://passwordmaker.mozdev.org/rdf#")) { ns = attrib->Name(); ns.erase(ns.begin(), ns.begin() + (ns.find(':') + 1)); break; } attrib = attrib->Next(); } if (ns.empty()) { // Namespace was not found. Not a valid file? defaultNode = NULL; } else { defaultNode = docHandle.FirstChildElement("RDF:RDF").FirstChildElement("RDF:Seq").Element(); while (defaultNode) { if(!strcmp(defaultNode->Attribute("RDF:about"), about.c_str())) { // dump all children TiXmlElement *liNode = defaultNode->FirstChildElement("RDF:li"); while(liNode) { const char *res = liNode->Attribute("RDF:resource"); if(res) { list.insert(string(res)); } liNode = liNode->NextSiblingElement("RDF:li"); } return list; } defaultNode = defaultNode->NextSiblingElement("RDF:Seq"); } } } // end if(defaultNode) } // end if(!document.Error()) return list; } // Returns the account name for a description node string findDesc(string filepath, string about) { TiXmlDocument document(filepath); document.LoadFile(); string ns; if (!document.Error()) { TiXmlHandle docHandle(&document); TiXmlElement *defaultNode = docHandle.FirstChildElement("RDF:RDF").Element(); if (defaultNode) { TiXmlAttribute *attrib = defaultNode->FirstAttribute(); // Find the namespace while (attrib) { if (!strcmp(attrib->Value(), "http://passwordmaker.mozdev.org/rdf#")) { ns = attrib->Name(); ns.erase(ns.begin(), ns.begin() + (ns.find(':') + 1)); break; } attrib = attrib->Next(); } if (ns.empty()) { // Namespace was not found. Not a valid file? defaultNode = NULL; } else { defaultNode = docHandle.FirstChildElement("RDF:RDF").FirstChildElement("RDF:Description").Element(); while (defaultNode) { if(!strcmp(defaultNode->Attribute("RDF:about"), about.c_str())) { return string(defaultNode->Attribute(ns+":name")); } defaultNode = defaultNode->NextSiblingElement("RDF:Description"); } } } // end if(defaultNode) } // end if(!document.Error()) return string("UNKNOWN"); } passwordmaker-cli-1.5.orig/tinyxmlparser.cpp0000755000000000000000000010372211545725573020116 0ustar rootroot/* www.sourceforge.net/projects/tinyxml Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "stdafx.h" #include "tinyxml.h" #include #include //#define DEBUG_PARSER // Note tha "PutString" hardcodes the same list. This // is less flexible than it appears. Changing the entries // or order will break putstring. TiXmlBase::Entity TiXmlBase::entity[ NUM_ENTITY ] = { { "&", 5, '&' }, { "<", 4, '<' }, { ">", 4, '>' }, { """, 6, '\"' }, { "'", 6, '\'' } }; // Bunch of unicode info at: // http://www.unicode.org/faq/utf_bom.html // Including the basic of this table, which determines the #bytes in the // sequence from the lead byte. 1 placed for invalid sequences -- // although the result will be junk, pass it through as much as possible. // Beware of the non-characters in UTF-8: // ef bb bf (Microsoft "lead bytes") // ef bf be // ef bf bf const unsigned char TIXML_UTF_LEAD_0 = 0xefU; const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; const int TiXmlBase::utf8ByteTable[256] = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid }; void TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) { const unsigned long BYTE_MASK = 0xBF; const unsigned long BYTE_MARK = 0x80; const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; if (input < 0x80) *length = 1; else if ( input < 0x800 ) *length = 2; else if ( input < 0x10000 ) *length = 3; else if ( input < 0x200000 ) *length = 4; else { *length = 0; return; } // This code won't covert this correctly anyway. output += *length; // Scary scary fall throughs. switch (*length) { case 4: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 3: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 2: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; case 1: --output; *output = (char)(input | FIRST_BYTE_MARK[*length]); } } /*static*/ int TiXmlBase::IsAlpha( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) { // This will only work for low-ascii, everything else is assumed to be a valid // letter. I'm not sure this is the best approach, but it is quite tricky trying // to figure out alhabetical vs. not across encoding. So take a very // conservative approach. // if ( encoding == TIXML_ENCODING_UTF8 ) // { if ( anyByte < 127 ) return isalpha( anyByte ); else return 1; // What else to do? The unicode set is huge...get the english ones right. // } // else // { // return isalpha( anyByte ); // } } /*static*/ int TiXmlBase::IsAlphaNum( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) { // This will only work for low-ascii, everything else is assumed to be a valid // letter. I'm not sure this is the best approach, but it is quite tricky trying // to figure out alhabetical vs. not across encoding. So take a very // conservative approach. // if ( encoding == TIXML_ENCODING_UTF8 ) // { if ( anyByte < 127 ) return isalnum( anyByte ); else return 1; // What else to do? The unicode set is huge...get the english ones right. // } // else // { // return isalnum( anyByte ); // } } class TiXmlParsingData { friend class TiXmlDocument; public: void Stamp( const char* now, TiXmlEncoding encoding ); const TiXmlCursor& Cursor() { return cursor; } private: // Only used by the document! TiXmlParsingData( const char* start, int _tabsize, int row, int col ) { assert( start ); stamp = start; tabsize = _tabsize; cursor.row = row; cursor.col = col; } TiXmlCursor cursor; const char* stamp; int tabsize; }; void TiXmlParsingData::Stamp( const char* now, TiXmlEncoding encoding ) { assert( now ); // Do nothing if the tabsize is 0. if ( tabsize < 1 ) { return; } // Get the current row, column. int row = cursor.row; int col = cursor.col; const char* p = stamp; assert( p ); while ( p < now ) { // Treat p as unsigned, so we have a happy compiler. const unsigned char* pU = (const unsigned char*)p; // Code contributed by Fletcher Dunn: (modified by lee) switch (*pU) { case 0: // We *should* never get here, but in case we do, don't // advance past the terminating null character, ever return; case '\r': // bump down to the next line ++row; col = 0; // Eat the character ++p; // Check for \r\n sequence, and treat this as a single character if (*p == '\n') { ++p; } break; case '\n': // bump down to the next line ++row; col = 0; // Eat the character ++p; // Check for \n\r sequence, and treat this as a single // character. (Yes, this bizarre thing does occur still // on some arcane platforms...) if (*p == '\r') { ++p; } break; case '\t': // Eat the character ++p; // Skip to next tab stop col = (col / tabsize + 1) * tabsize; break; case TIXML_UTF_LEAD_0: if ( encoding == TIXML_ENCODING_UTF8 ) { if ( *(p+1) && *(p+2) ) { // In these cases, don't advance the column. These are // 0-width spaces. if ( *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) p += 3; else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU ) p += 3; else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU ) p += 3; else { p +=3; ++col; } // A normal character. } } else { ++p; ++col; } break; default: if ( encoding == TIXML_ENCODING_UTF8 ) { // Eat the 1 to 4 byte utf8 character. int step = TiXmlBase::utf8ByteTable[*((unsigned char*)p)]; if ( step == 0 ) step = 1; // Error case from bad encoding, but handle gracefully. p += step; // Just advance one column, of course. ++col; } else { ++p; ++col; } break; } } cursor.row = row; cursor.col = col; assert( cursor.row >= -1 ); assert( cursor.col >= -1 ); stamp = p; assert( stamp ); } const char* TiXmlBase::SkipWhiteSpace( const char* p, TiXmlEncoding encoding ) { if ( !p || !*p ) { return 0; } if ( encoding == TIXML_ENCODING_UTF8 ) { while ( *p ) { const unsigned char* pU = (const unsigned char*)p; // Skip the stupid Microsoft UTF-8 Byte order marks if ( *(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) { p += 3; continue; } else if(*(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==0xbfU && *(pU+2)==0xbeU ) { p += 3; continue; } else if(*(pU+0)==TIXML_UTF_LEAD_0 && *(pU+1)==0xbfU && *(pU+2)==0xbfU ) { p += 3; continue; } if ( IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space. ++p; else break; } } else { while ( *p && IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ) ++p; } return p; } #ifdef TIXML_USE_STL /*static*/ bool TiXmlBase::StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag ) { for( ;; ) { if ( !in->good() ) return false; int c = in->peek(); // At this scope, we can't get to a document. So fail silently. if ( !IsWhiteSpace( c ) || c <= 0 ) return true; *tag += (char) in->get(); } } /*static*/ bool TiXmlBase::StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag ) { //assert( character > 0 && character < 128 ); // else it won't work in utf-8 while ( in->good() ) { int c = in->peek(); if ( c == character ) return true; if ( c <= 0 ) // Silent failure: can't get document at this scope return false; in->get(); *tag += (char) c; } return false; } #endif const char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding ) { *name = ""; assert( p ); // Names start with letters or underscores. // Of course, in unicode, tinyxml has no idea what a letter *is*. The // algorithm is generous. // // After that, they can be letters, underscores, numbers, // hyphens, or colons. (Colons are valid ony for namespaces, // but tinyxml can't tell namespaces from names.) if ( p && *p && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) { while( p && *p && ( IsAlphaNum( (unsigned char ) *p, encoding ) || *p == '_' || *p == '-' || *p == '.' || *p == ':' ) ) { (*name) += *p; ++p; } return p; } return 0; } const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding ) { // Presume an entity, and pull it out. TIXML_STRING ent; int i; *length = 0; if ( *(p+1) && *(p+1) == '#' && *(p+2) ) { unsigned long ucs = 0; ptrdiff_t delta = 0; unsigned mult = 1; if ( *(p+2) == 'x' ) { // Hexadecimal. if ( !*(p+3) ) return 0; const char* q = p+3; q = strchr( q, ';' ); if ( !q || !*q ) return 0; delta = q-p; --q; while ( *q != 'x' ) { if ( *q >= '0' && *q <= '9' ) ucs += mult * (*q - '0'); else if ( *q >= 'a' && *q <= 'f' ) ucs += mult * (*q - 'a' + 10); else if ( *q >= 'A' && *q <= 'F' ) ucs += mult * (*q - 'A' + 10 ); else return 0; mult *= 16; --q; } } else { // Decimal. if ( !*(p+2) ) return 0; const char* q = p+2; q = strchr( q, ';' ); if ( !q || !*q ) return 0; delta = q-p; --q; while ( *q != '#' ) { if ( *q >= '0' && *q <= '9' ) ucs += mult * (*q - '0'); else return 0; mult *= 10; --q; } } if ( encoding == TIXML_ENCODING_UTF8 ) { // convert the UCS to UTF-8 ConvertUTF32ToUTF8( ucs, value, length ); } else { *value = (char)ucs; *length = 1; } return p + delta + 1; } // Now try to match it. for( i=0; iappend( cArr, len ); } } else { bool whitespace = false; // Remove leading white space: p = SkipWhiteSpace( p, encoding ); while ( p && *p && !StringEqual( p, endTag, caseInsensitive, encoding ) ) { if ( *p == '\r' || *p == '\n' ) { whitespace = true; ++p; } else if ( IsWhiteSpace( *p ) ) { whitespace = true; ++p; } else { // If we've found whitespace, add it before the // new character. Any whitespace just becomes a space. if ( whitespace ) { (*text) += ' '; whitespace = false; } int len; char cArr[4] = { 0, 0, 0, 0 }; p = GetChar( p, cArr, &len, encoding ); if ( len == 1 ) (*text) += cArr[0]; // more efficient else text->append( cArr, len ); } } } return p + strlen( endTag ); } #ifdef TIXML_USE_STL void TiXmlDocument::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) { // The basic issue with a document is that we don't know what we're // streaming. Read something presumed to be a tag (and hope), then // identify it, and call the appropriate stream method on the tag. // // This "pre-streaming" will never read the closing ">" so the // sub-tag can orient itself. if ( !StreamTo( in, '<', tag ) ) { SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } while ( in->good() ) { int tagIndex = (int) tag->length(); while ( in->good() && in->peek() != '>' ) { int c = in->get(); if ( c <= 0 ) { SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); break; } (*tag) += (char) c; } if ( in->good() ) { // We now have something we presume to be a node of // some sort. Identify it, and call the node to // continue streaming. TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); if ( node ) { node->StreamIn( in, tag ); bool isElement = node->ToElement() != 0; delete node; node = 0; // If this is the root element, we're done. Parsing will be // done by the >> operator. if ( isElement ) { return; } } else { SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } } } // We should have returned sooner. SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); } #endif const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) { ClearError(); // Parse away, at the document level. Since a document // contains nothing but other tags, most of what happens // here is skipping white space. if ( !p || !*p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } // Note that, for a document, this needs to come // before the while space skip, so that parsing // starts from the pointer we are given. location.Clear(); if ( prevData ) { location.row = prevData->cursor.row; location.col = prevData->cursor.col; } else { location.row = 0; location.col = 0; } TiXmlParsingData data( p, TabSize(), location.row, location.col ); location = data.Cursor(); if ( encoding == TIXML_ENCODING_UNKNOWN ) { // Check for the Microsoft UTF-8 lead bytes. const unsigned char* pU = (const unsigned char*)p; if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) { encoding = TIXML_ENCODING_UTF8; useMicrosoftBOM = true; } } p = SkipWhiteSpace( p, encoding ); if ( !p ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return 0; } while ( p && *p ) { TiXmlNode* node = Identify( p, encoding ); if ( node ) { p = node->Parse( p, &data, encoding ); LinkEndChild( node ); } else { break; } // Did we get encoding info? if ( encoding == TIXML_ENCODING_UNKNOWN && node->ToDeclaration() ) { TiXmlDeclaration* dec = node->ToDeclaration(); const char* enc = dec->Encoding(); assert( enc ); if ( *enc == 0 ) encoding = TIXML_ENCODING_UTF8; else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) encoding = TIXML_ENCODING_UTF8; else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice else encoding = TIXML_ENCODING_LEGACY; } p = SkipWhiteSpace( p, encoding ); } // Was this empty? if ( !firstChild ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); return 0; } // All is well. return p; } void TiXmlDocument::SetError( int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding ) { // The first error in a chain is more accurate - don't set again! if ( error ) return; assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); error = true; errorId = err; errorDesc = errorString[ errorId ]; errorLocation.Clear(); if ( pError && data ) { data->Stamp( pError, encoding ); errorLocation = data->Cursor(); } } TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) { TiXmlNode* returnNode = 0; p = SkipWhiteSpace( p, encoding ); if( !p || !*p || *p != '<' ) { return 0; } TiXmlDocument* doc = GetDocument(); p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { return 0; } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: "; if ( !StringEqual( p, startTag, false, encoding ) ) { document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); return 0; } p += strlen( startTag ); p = ReadText( p, &value, false, endTag, false, encoding ); return p; } const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) { p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) return 0; int tabsize = 4; if ( document ) tabsize = document->TabSize(); if ( data ) { data->Stamp( p, encoding ); location = data->Cursor(); } // Read the name, the '=' and the value. const char* pErr = p; p = ReadName( p, &name, encoding ); if ( !p || !*p ) { if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); return 0; } p = SkipWhiteSpace( p, encoding ); if ( !p || !*p || *p != '=' ) { if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); return 0; } ++p; // skip '=' p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); return 0; } const char* end; if ( *p == '\'' ) { ++p; end = "\'"; p = ReadText( p, &value, false, end, false, encoding ); } else if ( *p == '"' ) { ++p; end = "\""; p = ReadText( p, &value, false, end, false, encoding ); } else { // All attribute values should be in single or double quotes. // But this is such a common error that the parser will try // its best, even without them. value = ""; while ( p && *p // existence && !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r' // whitespace && *p != '/' && *p != '>' ) // tag end { value += *p; ++p; } } return p; } #ifdef TIXML_USE_STL void TiXmlText::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) { if ( cdata ) { int c = in->get(); if ( c <= 0 ) { TiXmlDocument* document = GetDocument(); if ( document ) document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } (*tag) += (char) c; if ( c == '>' && tag->at( tag->length() - 2 ) == ']' && tag->at( tag->length() - 3 ) == ']' ) { // All is well. return; } } else { while ( in->good() ) { int c = in->peek(); if ( c == '<' ) return; if ( c <= 0 ) { TiXmlDocument* document = GetDocument(); if ( document ) document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } (*tag) += (char) c; in->get(); } } } #endif const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) { value = ""; TiXmlDocument* document = GetDocument(); if ( data ) { data->Stamp( p, encoding ); location = data->Cursor(); } const char* const startTag = ""; if ( cdata || StringEqual( p, startTag, false, encoding ) ) { cdata = true; if ( !StringEqual( p, startTag, false, encoding ) ) { document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); return 0; } p += strlen( startTag ); // Keep all the white space, ignore the encoding, etc. while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) { value += *p; ++p; } TIXML_STRING dummy; p = ReadText( p, &dummy, false, endTag, false, encoding ); return p; } else { bool ignoreWhite = true; const char* end = "<"; p = ReadText( p, &value, ignoreWhite, end, false, encoding ); if ( p ) return p-1; // don't truncate the '<' return 0; } } #ifdef TIXML_USE_STL void TiXmlDeclaration::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) { while ( in->good() ) { int c = in->get(); if ( c <= 0 ) { TiXmlDocument* document = GetDocument(); if ( document ) document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); return; } (*tag) += (char) c; if ( c == '>' ) { // All is well. return; } } } #endif const char* TiXmlDeclaration::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding ) { p = SkipWhiteSpace( p, _encoding ); // Find the beginning, find the end, and look for // the stuff in-between. TiXmlDocument* document = GetDocument(); if ( !p || !*p || !StringEqual( p, "SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding ); return 0; } if ( data ) { data->Stamp( p, _encoding ); location = data->Cursor(); } p += 5; version = ""; encoding = ""; standalone = ""; while ( p && *p ) { if ( *p == '>' ) { ++p; return p; } p = SkipWhiteSpace( p, _encoding ); if ( StringEqual( p, "version", true, _encoding ) ) { TiXmlAttribute attrib; p = attrib.Parse( p, data, _encoding ); version = attrib.Value(); } else if ( StringEqual( p, "encoding", true, _encoding ) ) { TiXmlAttribute attrib; p = attrib.Parse( p, data, _encoding ); encoding = attrib.Value(); } else if ( StringEqual( p, "standalone", true, _encoding ) ) { TiXmlAttribute attrib; p = attrib.Parse( p, data, _encoding ); standalone = attrib.Value(); } else { // Read over whatever it is. while( p && *p && *p != '>' && !IsWhiteSpace( *p ) ) ++p; } } return 0; } bool TiXmlText::Blank() const { for ( unsigned i=0; i and Eric H. Jung */ #ifndef HASHER_H #define HASHER_H #ifdef USE_QSA #error QSA is no longer supported #endif // USE_QSA #include "pwm_common.h" #ifdef USE_QT #include #include #ifdef USE_QTSCRIPT #include #include #endif // USE_QTSCRIPT #else #ifdef USE_QTSCRIPT #error WHOOPS! QtScript can only be used with QT. #error Check the build system for the correct defines #endif #ifdef USE_SPIDERMONKEY #include #endif #endif #include class Hasher #ifdef USE_QT : public QObject #endif { public: Hasher( #ifdef USE_QT QObject *parent #else std::string path = "" #endif ); ~Hasher(void); #ifdef USE_QT QString hash(hashType algo, bool usingHMAC, bool trim, QString encoding, QString data, QString key, bool hmac_sha256_bug = true); #endif std::string hash(hashType algo, bool usingHMAC, bool trim, std::string encoding, std::string data, std::string key, bool hmac_sha256_bug = true); bool initialized() { return aOK; }; private: bool aOK; #ifdef USE_SPIDERMONKEY JSRuntime *rt; JSContext *cx; JSObject *globalObj; #endif // USE_SPIDERMONKEY #ifdef USE_QTSCRIPT QScriptEngine script; QScriptValue getHashFunc; QScriptValue getHashScope; void loadScript(); #endif // USE_QTSCRIPT #ifdef USE_MHASH #ifdef USE_QT QString rstr2any(unsigned char *input, int length, QString encoding, bool trim = true); #endif std::string rstr2any(unsigned char *input, int length, std::string encoding, bool trim = true); #endif // USE_MHASH }; #endif //HASHER_H passwordmaker-cli-1.5.orig/shared/pwm_common.h0000755000000000000000000000273311545725573020263 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005-2006 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Written by Miquel Burns and Eric H. Jung */ /* * This file contains definition that are used in all files. */ #ifndef PWM_COMMON_H #define PWM_COMMON_H enum hashType { PWM_MD4 = 1, PWM_MD5, PWM_SHA1, PWM_RIPEMD160, PWM_SHA256, // Following are bitmasks that can be applied PWM_HMAC = 0x0100, PWM_V6 = 0x0200, /* Sets trim to false and charset set to hexstring*/ PWM_HMAC_BUG = 0x0400 /* Use the buggy version of HMAC-SHA-256 */ }; enum leetType { LEET_NONE, LEET_BEFORE, LEET_AFTER, LEET_BOTH }; #endif // PWM_COMMON_H passwordmaker-cli-1.5.orig/shared/hasher.cpp0000755000000000000000000003674011545725573017722 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005-2006 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Written by Miquel Burns and Eric H. Jung */ #ifdef USE_QT #include #include #ifdef USE_QSA #error QSA is no longer supported #endif // USE_QSA #else #ifdef USE_QTSCRIPT #error Config error! USE_QTSCRIPT can only be used with USE_QT #endif // USE_QTSCRIPT #endif // USE_QT #ifdef USE_MHASH #include #include #ifndef mutils_word8 #define mutils_word8 unsigned char #define mutils_word8_cast (void*) #else #define mutils_word8_cast #endif #endif // USE_MHASH #ifdef USE_SPIDERMONKEY #include #include #include #endif // USE_SPIDERMONKEY #include #include "hasher.h" using namespace std; #ifdef USE_SPIDERMONKEY // Emulate PHP's add_slashes to exscape JavaScript control characters static string add_slashes(string str); // This allow us to do a debugging message in Javascript static JSBool dump(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); // Javascript error reporting static void printError(JSContext *cx, const char *message, JSErrorReport *report); static JSFunctionSpec m_functions[] = { { "dump",dump, 1, 0, 0 }, { 0, 0, 0, 0, 0 } }; static JSClass globalClass = { "Global", 0, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; #endif // USE_SPIDERMONKEY Hasher::Hasher( #ifdef USE_QT QObject *parent #else string path #endif ) #ifdef USE_QT : QObject(parent), script(this) #endif { #ifdef USE_QTSCRIPT aOK = false; loadScript(); #endif // USE_QTSCRIPT #ifdef USE_MHASH hashid tests[] = {MHASH_MD5, MHASH_SHA1, MHASH_RIPEMD160, MHASH_MD4, MHASH_SHA256}; unsigned char hash[32]; MHASH td; aOK = true; for (int i = 0; (i < (int)(sizeof(tests)/sizeof(hashid))) && aOK; i++) { td = mhash_init(tests[i]); if (td == MHASH_FAILED) { // MHASH Failed. aOK = false; } mhash_deinit(td, hash); } #endif // USE_MHASH #ifdef USE_SPIDERMONKEY cx = NULL; // in case the runtime doesn't load aOK = false; rt = JS_NewRuntime(1000000L); if (rt) { cx = JS_NewContext(rt, 8192); if (cx) { globalObj = JS_NewObject(cx, &globalClass, 0, 0); JS_InitStandardClasses(cx, globalObj); JS_SetErrorReporter(cx, printError); string script, buffer; path.append("getHash.js"); ifstream istr(path.c_str()); if (istr.is_open()) { while (!istr.fail()) { std::getline(istr, buffer); script += buffer + "\n"; // Line break to allow comments } } else { return; } JSBool ok = JS_DefineFunctions(cx, globalObj, m_functions); if (ok == JS_TRUE) { jsval rval; uintN lineno = 0; ok = JS_EvaluateScript(cx, globalObj, script.c_str(), (uintN)script.length(), "getHash.js", lineno, &rval); if (ok == JS_TRUE) aOK = true; } } } #endif } Hasher::~Hasher(void) { #ifdef USE_SPIDERMONKEY if (cx) JS_DestroyContext(cx); if (rt) JS_DestroyRuntime(rt); #endif } #ifdef USE_QTSCRIPT void Hasher::loadScript() { QFile file(":/getHash.qs"); QString qs; if (aOK) return; aOK = false; if (file.exists()) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { qs = file.readAll(); script.evaluate(qs, "getHash.qs"); if (script.hasUncaughtException()) { // For debugging reasons qDebug() << script.uncaughtException().toString() << script.uncaughtExceptionLineNumber(); } // Note: Currently, this is sure to work. Not sure what will be needed to combine with the evaluate line above getHashFunc = script.evaluate("function(algo, data, encoding, key, trim, sha256_bug) { return getHash(algo, data, encoding, key, trim, sha256_bug); }"); getHashScope = script.globalObject(); aOK = true; } } } #endif // USE_QTSCRIPT #ifdef USE_QT QString Hasher::hash(hashType algo, bool usingHMAC, bool trim, QString encoding, QString data, QString key, bool hmac_sha256_bug) { if (!aOK) return "ERROR!"; // Just in case // data changes to key + data if the hashType is not a HMAC algorithm if (!usingHMAC) { data = key+data; key = ""; } QString ret = "ERROR!"; #ifdef USE_QTSCRIPT // TODO: Redo this part QString algorithm; switch(algo) { case PWM_MD4: algorithm = "md4"; break; case PWM_MD5: algorithm = "md5"; break; case PWM_SHA1: algorithm = "sha1"; break; case PWM_SHA256: algorithm = "sha256"; break; case PWM_RIPEMD160: algorithm = "ripemd160"; break; default: return "ERROR!"; // Otherwise, an infinite loop may occur } if (usingHMAC) { algorithm = "hmac-" + algorithm; } QScriptValueList args; args.append(QScriptValue(&script, algorithm)); args.append(QScriptValue(&script, data)); args.append(QScriptValue(&script, encoding)); args.append(QScriptValue(&script, key)); args.append(QScriptValue(&script, trim)); args.append(QScriptValue(&script, hmac_sha256_bug)); //function getHash(algo, data, encoding, key, trim) { ret = getHashFunc.call(getHashScope, args).toString(); if (ret.isEmpty()) { if (script.hasUncaughtException()) { // For debugging reasons qDebug() << script.uncaughtException().toString(); } ret = "ERROR!"; } #elif USE_MHASH MHASH td; hashid algorithm; mutils_word8 hash[32]; switch (algo) { case PWM_MD4: algorithm = MHASH_MD4; break; case PWM_MD5: algorithm = MHASH_MD5; break; case PWM_SHA1: algorithm = MHASH_SHA1; break; case PWM_SHA256: algorithm = MHASH_SHA256; break; case PWM_RIPEMD160: algorithm = MHASH_RIPEMD160; break; default: return "ERROR!"; } if (usingHMAC) { td = mhash_hmac_init(algorithm, (void*)key.toAscii().data(), key.size(), mhash_get_hash_pblock(algorithm)); mhash(td, data.toAscii().data(), data.size()); mhash_hmac_deinit(td, mutils_word8_cast hash); } else { td = mhash_init(algorithm); mhash(td, (void*)data.toAscii().data(), data.size()); mhash_deinit(td, mutils_word8_cast hash); } ret = rstr2any(hash, mhash_get_block_size(algorithm), encoding, trim); #endif // USE_MHASH return ret; } #endif // USE_QT string Hasher::hash(hashType algo, bool usingHMAC, bool trim, std::string encoding, std::string data, std::string key, bool hmac_sha256_bug) { // data changes to key + data if the hashType is not a HMAC algorithm if (!usingHMAC) { data = key+data; key = ""; } string ret = "ERROR!"; #ifdef USE_SPIDERMONKEY string algorithm; switch(algo) { case PWM_MD4: algorithm = "md4"; break; case PWM_MD5: algorithm = "md5"; break; case PWM_SHA1: algorithm = "sha1"; break; case PWM_SHA256: algorithm = "sha256"; break; case PWM_RIPEMD160: algorithm = "ripemd160"; break; default: algorithm = ""; } if (!aOK) return ""; jsval rval; uintN lineno = 0; string script = "getHash('"; script += ((usingHMAC)?"hmac-":""); script += algorithm; script += "', '"; script += add_slashes(data); script += "', '"; script += add_slashes(encoding); script += "', '"; script += add_slashes(key); script += "', "; script += ((trim) ? "true" : "false"); script += ", "; script += ((hmac_sha256_bug) ? "true" : "false"); script += ");"; JSBool ok = JS_EvaluateScript(cx, globalObj, script.c_str(), (uintN)script.length(), "cFunc_hash()", lineno, &rval); if (ok == JS_FALSE) return ""; JSString *str = JS_ValueToString(cx, rval); ret = JS_GetStringBytes(str); #elif USE_MHASH MHASH td; unsigned char *hash; hashid malgo; switch(algo) { case PWM_MD4: malgo = MHASH_MD4; break; case PWM_SHA1: malgo = MHASH_SHA1; break; case PWM_SHA256: malgo = MHASH_SHA256; break; case PWM_RIPEMD160: malgo = MHASH_RIPEMD160; break; case PWM_MD5: default: malgo = MHASH_MD5; break; } if (usingHMAC) { // Might offer a custom SHA256 version of these functions at some point // Depends on how easy that would be to do td = mhash_hmac_init(malgo, (void*)key.c_str(), (int)key.length(), mhash_get_hash_pblock(malgo)); mhash(td, data.c_str(), (int)data.length()); if (algo == PWM_SHA256) { cout << "WARNING: Due to a bug in Javascript based versions, this is wrong;" << endl; } hash = (unsigned char*)mhash_hmac_end(td); } else { td = mhash_init(malgo); mhash(td, (void*)data.c_str(), (int)data.length()); hash = (unsigned char*)mhash_end(td); } ret = rstr2any(hash, mhash_get_block_size(malgo), encoding, trim); #endif return ret; } #ifdef USE_MHASH #ifdef USE_QT QString Hasher::rstr2any(unsigned char *input, int length, QString encoding, bool trim) { int divisor; int full_length; int *dividend; int *remainders; int remainders_count = 0; // for use with trimming zeros method int dividend_length; // Counter int i, j; QString output = ""; // Can't handle odd lengths for input correctly with this function if (length % 2) return ""; divisor = (int)encoding.length(); dividend_length = (int)ceil((double)length/2); dividend = new int[dividend_length]; for (i = 0; i < dividend_length; i++) { dividend[i] = (((int) input[i*2]) << 8) | ((int) input[i*2+1]); } full_length = (int)ceil((double)length * 8 / (log((double)encoding.length()) / log((double)2))); remainders = new int[full_length]; if (trim) { while(dividend_length > 0) { int *quotient; int quotient_length = 0; int qCounter = 0; int x = 0; quotient = new int[dividend_length]; for(i = 0; i < dividend_length; i++) { int q; x = (x << 16) + dividend[i]; q = (int)floor((double)x / divisor); x -= q * divisor; if (quotient_length > 0 || q > 0) { quotient[qCounter++] = q; quotient_length++; } } remainders[remainders_count++] = x; delete[] dividend; dividend_length = quotient_length; dividend = quotient; } full_length = remainders_count; } else { for (j = 0; j < full_length; j++) { int *quotient; int quotient_length = 0; int qCounter = 0; int x = 0; quotient = new int[dividend_length]; for(i = 0; i < dividend_length; i++) { int q; x = (x << 16) + dividend[i]; q = (int)floor((double)x / divisor); x -= q * divisor; if (quotient_length > 0 || q > 0) { quotient[qCounter++] = q; quotient_length++; } } remainders[j] = x; delete[] dividend; dividend_length = quotient_length; dividend = quotient; } } for (i = full_length - 1; i>=0; i--) output.append(encoding[remainders[i]]); delete[] dividend; delete[] remainders; return output; } #endif // USE_QT // TODO: Test trimming leading 'zeros' string Hasher::rstr2any(unsigned char *input, int length, string encoding, bool trim) { int divisor; int full_length; int *dividend; int *remainders; int remainders_count = 0; // for use with trimming zeros method int dividend_length; // Counter int i, j; string output; // Can't handle odd lengths for input correctly with this function if (length % 2) return ""; output = ""; divisor = (int)encoding.length(); dividend_length = (int)ceil((double)length/2); dividend = new int[dividend_length]; for (i = 0; i < dividend_length; i++) { dividend[i] = (((int) input[i*2]) << 8) | ((int) input[i*2+1]); } full_length = (int)ceil((double)length * 8 / (log((double)encoding.length()) / log((double)2))); remainders = new int[full_length]; if (trim) { while(dividend_length > 0) { int *quotient; int quotient_length = 0; int qCounter = 0; int x = 0; quotient = new int[dividend_length]; for(i = 0; i < dividend_length; i++) { int q; x = (x << 16) + dividend[i]; q = (int)floor((double)x / divisor); x -= q * divisor; if (quotient_length > 0 || q > 0) { quotient[qCounter++] = q; quotient_length++; } } remainders[remainders_count++] = x; delete[] dividend; dividend_length = quotient_length; dividend = quotient; } full_length = remainders_count; } else { for (j = 0; j < full_length; j++) { int *quotient; int quotient_length = 0; int qCounter = 0; int x = 0; quotient = new int[dividend_length]; for(i = 0; i < dividend_length; i++) { int q; x = (x << 16) + dividend[i]; q = (int)floor((double)x / divisor); x -= q * divisor; if (quotient_length > 0 || q > 0) { quotient[qCounter++] = q; quotient_length++; } } remainders[j] = x; delete[] dividend; dividend_length = quotient_length; dividend = quotient; } } for (i = full_length - 1; i>=0; i--) output.append(1, encoding[remainders[i]]); delete[] dividend; delete[] remainders; return output; } #endif // USE_MHASH #ifdef USE_SPIDERMONKEY // Prevent certain characters from messing up a call static string add_slashes(string str) { string ret = ""; char c; for (int i = 0; i < (int)str.length(); i++) { c = str[i]; switch (c) { case '\n': ret += "\\n"; break; case '\r': ret += "\\r"; break; case '\'': case '\"': case '\\': ret += "\\"; default: ret.append(1, c); } } return ret; } // JavaScript Core does not provide a function for debugging reason, here's my dump static JSBool dump(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { uintN i; rval = JSVAL_NULL; for (i = 0; i < argc; i++) { if (JSVAL_IS_VOID(argv[i])) { std::cout << "Void" << std::endl; } if (JSVAL_IS_STRING(argv[i])) { JSString *str = JS_ValueToString(cx, argv[i]); std::cout << "String: " << JS_GetStringBytes(str) << std::endl; } if (JSVAL_IS_NULL(argv[i])) { std::cout << "Null" << std::endl; } if (JSVAL_IS_INT(argv[i])) { int value = JSVAL_TO_INT(argv[i]); std::cout << "Int: " << value << std::endl; } if (JSVAL_IS_DOUBLE(argv[i])) { double value; JS_ValueToNumber(cx, argv[i], &value); std::cout << "Double: " << value << std::endl; } if (JSVAL_IS_BOOLEAN(argv[i])) { int value = JSVAL_TO_BOOLEAN(argv[i]); std::cout << "Bool: " << ((value) ? "true" : "false") << std::endl; } } return JS_TRUE; } // Print out errors static void printError(JSContext *cx, const char *message, JSErrorReport *report) { cout << "Error in Javascript: " << ((report->filename) ? report->filename : "NULL") << "(" << report->lineno << "): " << message << endl; if (report->linebuf) { cout << "\t" << report->linebuf << endl; } } #endif // USE_SPIDERMONKEY passwordmaker-cli-1.5.orig/cli.vcproj0000755000000000000000000002732511545725573016471 0ustar rootroot passwordmaker-cli-1.5.orig/tinyxmlerror.cpp0000755000000000000000000000330711545725573017751 0ustar rootroot/* www.sourceforge.net/projects/tinyxml Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "stdafx.h" #include "tinyxml.h" // The goal of the seperate error file is to make the first // step towards localization. tinyxml (currently) only supports // english error messages, but the could now be translated. // // It also cleans up the code a bit. // const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] = { "No error", "Error", "Failed to open file", "Memory allocation failed.", "Error parsing Element.", "Failed to read Element name", "Error reading Element value.", "Error reading Attributes.", "Error: empty tag.", "Error reading end tag.", "Error parsing Unknown.", "Error parsing Comment.", "Error parsing Declaration.", "Error document empty.", "Error null (0) or unexpected EOF found in input stream.", "Error parsing CDATA.", }; passwordmaker-cli-1.5.orig/building.txt0000755000000000000000000000352111545725573017023 0ustar rootrootRequirements ============ For Windows, you will need either MSVC 2005 or MinGW (http://www.mingw.org). If you want a native 64-bit build, you will need to compile SpiderMonkey or mHash (mHash is only supported with MSVC right now) yourself. Normally, you don't need to worry as a prebuilt 32 bit binary is provided from the site. Also for the MinGW build, have UPX (http://upx.sourceforge.net) somewhere in your path. For Unix based OSes (including OS X), you need to have mHash installed. Windows with MSVC 2005 ====================== Just open the cli.sln solution file, select the configuration you want, and build the solution. There are both Debug and Release versions for the two main configurations: SpiderMonkey - Use this if you must have HMAC-SHA256 compatiblity with the other Javascript compiled extensions. This requires the getHash.js to be in the same directory at the exe (or in the working directory) mHash - Use this if you don't use HMAC-SHA256 and do not want to rely on the getHash.js file. If you need to compile for a platform other than 32-bit, you must have a compiled version of either SpiderMonkey or mHash as well (just replace the lib files in the msvc/lib directory) MinGW ===== Just compile with the command "make -f mingw32.mak". Unless you're missing UPX, you will actually build the same exe that is provided at the site. If you want 64-bit, edit the makefile to add the apporterate switches (and have a 64-bit version of SpiderMonkey in mingw/lib) Unix based ========== Make sure to install mHash first if it's not already installed. To compile, just type "make -f unix.mak" and everything should go just fine. You can move the resulting passwordmaker executible to your path if you so desire. HMAC-SHA256 is broken if you're going to compare it to other Javascript based editions however. passwordmaker-cli-1.5.orig/main.cpp0000755000000000000000000002517311545725573016124 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ // main.cpp : Defines the entry point for the console application. // #include #include "stdafx.h" #include "passwordmaker.h" #include "tclap/CmdLine.h" #include "pwmdefaults.h" #include "listaccounts.h" #include "urlsearch.h" #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include #endif using namespace std; using namespace TCLAP; struct SettingsStruct { string mpw, useLeet, algorithm, charset, username, modifier, prefix, suffix, url, filepath, account, search; int length, leetLevel, account_skip; bool hmac, trim, verbose, list; }; SettingsStruct getSettings(int argc, char* argv[], pwmDefaults defaults) { // Define the command line object. See TCLAP docs at http://tclap.sourceforge.net/ CmdLine cmd("PasswordMaker", ' ', "1.5"); ValueArg mpw("m", "mpw", "Master Password", false, defaults.getMasterPassword(), "string", cmd); vector allowedLeetLevel; allowedLeetLevel.push_back(1); allowedLeetLevel.push_back(2); allowedLeetLevel.push_back(3); allowedLeetLevel.push_back(4); allowedLeetLevel.push_back(5); allowedLeetLevel.push_back(6); allowedLeetLevel.push_back(7); allowedLeetLevel.push_back(8); allowedLeetLevel.push_back(9); ValueArg leetLevel("e", "level", "l33t level", false, defaults.getLeetLevel(), allowedLeetLevel, cmd); // TODO: Find a way to converting to upper/lower case or making these args case insen vector allowedLeet; allowedLeet.push_back("none"); allowedLeet.push_back("before"); allowedLeet.push_back("after"); allowedLeet.push_back("both"); ValueArg whereLeet("l", "l33t", "Where to use l33t", false, defaults.getUseLeet(), allowedLeet, cmd); ValueArg username("u", "username", "Username", false, defaults.getUserName(), "string", cmd); ValueArg prefix("p", "prefix", "Password Prefix", false, defaults.getPrefix(), "string", cmd); ValueArg suffix("s", "suffix", "Password Suffix", false, defaults.getSuffix(), "string", cmd); ValueArg modifier("d", "modifier", "Password Modifier", false, defaults.getModifier(), "string", cmd); ValueArg length("g", "length", "Password Length", false, defaults.getPasswordLength(), "integer", cmd); ValueArg charset("c", "chars", "Characters", false, defaults.getCharset(), "string", cmd); // Short flag needed ValueArg account("", "account", "Account", false, "", "string", cmd); // Short flag needed ValueArg account_skip("", "account_skip", "Account skip", false, 0, "interger", cmd); vector allowedAlgorithms; allowedAlgorithms.push_back("MD4"); allowedAlgorithms.push_back("MD5"); allowedAlgorithms.push_back("SHA1"); allowedAlgorithms.push_back("SHA256"); allowedAlgorithms.push_back("RIPEMD160"); ValueArg algorithm("a", "alg", "Hash Algorithm", false, defaults.getAlgorithm(), allowedAlgorithms, cmd); ValueArg url("r", "url", "URL (equivalent to \"Use This URL\" in the Firefox/Mozilla extension)", false, defaults.getURL(), "string", cmd); // RDF, doesn't export a default URL // Define the switches SwitchArg hmac("x", "HMAC", "Use the HMAC version of the specified hash algorithm", defaults.getHmac(), cmd); SwitchArg trimLeading0("0", "trimzeros", "Trim leading zeros from the generated password", defaults.getTrim(), cmd); SwitchArg verbose("b", "verbose", "Echo command-line arguments", false, cmd); SwitchArg list("L", "list", "List all accounts and groups in the config file.", false, cmd); ValueArg search("", "search", "Search config file for an account matching the supplied URL. If found, that account's settings will be used to generate the password. Example: passwordmaker --search https://yoursite.com/login.phtml", false, "", "string", cmd); #if defined(__unix) || defined(__linux) || defined(__linux__) || defined(__APPLE__) string defaultPath = string(getenv("HOME")) + string("/.passwordmaker.rdf"); ValueArg filepath("f", "file", "Path/filename to a settings file", false, defaultPath.c_str(), "string", cmd); #else ValueArg filepath("f", "file", "Path/filename to a settings file", false, "passwordmaker.rdf", "string", cmd); #endif try { // Parse the args cmd.parse(argc, argv); } catch (ArgException &e) { cerr << "error: " << e.error() << " for arg " << e.argId() << endl; exit(1); } SettingsStruct settings; settings.mpw = mpw.getValue(); settings.useLeet = whereLeet.getValue(); settings.algorithm = algorithm.getValue(); settings.charset = charset.getValue(); settings.username = username.getValue(); settings.modifier = modifier.getValue(); settings.prefix = prefix.getValue(); settings.suffix = suffix.getValue(); settings.url = url.getValue(); settings.length = length.getValue(); settings.leetLevel = leetLevel.getValue(); settings.hmac = hmac.getValue(); settings.trim = trimLeading0.getValue(); settings.verbose = verbose.getValue(); settings.filepath = filepath.getValue(); settings.account = account.getValue(); settings.account_skip = account_skip.getValue(); settings.list = list.getValue(); settings.search = search.getValue(); return settings; } SettingsStruct getDefaults(int argc, char* argv[]) { // Define the command line object. See TCLAP docs at http://tclap.sourceforge.net/ pwmDefaults defaults; return getSettings(argc, argv, defaults); } void setOutputVisible(bool visible) { #ifdef WIN32 DWORD cm = NULL; HANDLE hin = GetStdHandle(STD_INPUT_HANDLE); if (!GetConsoleMode(hin, &cm)) { cout << "Doh!" << endl; return; } switch (visible) { case true: cm |= ENABLE_ECHO_INPUT; break; case false: cm = cm & ~(ENABLE_ECHO_INPUT); break; } SetConsoleMode(hin, cm); #else switch(visible) { case true: system("stty echo"); break; case false: system("stty -echo"); break; } #endif } int main(int argc, char* argv[]) { SettingsStruct temp_default = getDefaults(argc, argv); UrlSearch search; // hack // // If --search was passed in, use the URL passed in to locate the // relevant account and re-write that into the temp_default variable // so the defaults below read that account if(temp_default.search.size()>0) { if(search.search(temp_default.search, temp_default.filepath)) { temp_default.account = search.getName(); cout << "Name: " << search.getName() << endl; cout << "Description: " << search.getDescription() << endl; cout << "Username: " << search.getUsername() << endl; } else { cout << "Unable to locate matching account." << endl; exit(1); } } pwmDefaults defaults(temp_default.filepath, temp_default.account, temp_default.account_skip); SettingsStruct settings = getSettings(argc, argv, defaults); // If just asked to list the settings, do that and exit if (settings.list) { listAccounts(temp_default.filepath, "http://passwordmaker.mozdev.org/accounts", 0); exit(0); } if (settings.mpw == "\x01") { char tmpw[255]; // Hope this is enough for a master password cout << "Master Password: "; setOutputVisible(false); cin.getline(tmpw, 254); setOutputVisible(true); cout << endl; settings.mpw = tmpw; // reset memory used by master password memset(tmpw, 0, sizeof(tmpw)); } // Generate PasswordMaker pwm; // Setting the path for the hasher to find getHash.js on SpiderMonkey builds string path = argv[0]; string::size_type index; static const string::size_type npos = (string::size_type)-1; index = path.find_last_of("/"); if (index == npos) { index = path.find_last_of("\\"); } if (index != npos) { path.erase(path.begin() + index + 1, path.end()); pwm.setPath(path); } if (!pwm.initialized()) { #ifdef USE_SPIDERMONKEY // Note: If js.dll can't be found, main() is not even called cerr << "PasswordMaker could not initialize. Cannot find 'getHash.js'." << endl; #elif USE_MHASH cerr << "PasswordMaker could not initialize. mHash appears to be broken somehow on this system." << endl; #endif return 1; } if (settings.verbose) { // Output the command-line args cout << "Master Password: " << settings.mpw << endl; cout << "Use l33t: " << settings.useLeet << endl; cout << "l33t level: " << settings.leetLevel << endl; cout << "Hash Algorithm: " << (settings.hmac ? "HMAC-" : "") << settings.algorithm << endl; cout << "URL: " << settings.url << endl; cout << "Generated Password Length: " << settings.length << endl; cout << "Username: " << settings.username << endl; cout << "Modifier: " << settings.modifier << endl; cout << "Characters: " << settings.charset << endl; cout << "Generated Password Prefix: " << settings.prefix << endl; cout << "Generated Password Suffix: " << settings.suffix << endl; } hashType algo = PWM_SHA256; if (!settings.algorithm.compare("MD4")) algo = PWM_MD4; if (!settings.algorithm.compare("MD5")) algo = PWM_MD5; if (!settings.algorithm.compare("SHA1")) algo = PWM_SHA1; if (!settings.algorithm.compare("SHA256")) algo = PWM_SHA256; if (!settings.algorithm.compare("RIPEMD160")) algo = PWM_RIPEMD160; leetType useLeet = LEET_NONE; if (!settings.useLeet.compare("none")) useLeet = LEET_NONE; if (!settings.useLeet.compare("before")) useLeet = LEET_BEFORE; if (!settings.useLeet.compare("after")) useLeet = LEET_AFTER; if (!settings.useLeet.compare("both")) useLeet = LEET_BOTH; cout << pwm.generatePassword(settings.mpw, algo, settings.hmac, settings.trim, settings.url, settings.length, settings.charset, useLeet, settings.leetLevel, settings.username, settings.modifier, settings.prefix, settings.suffix) << endl; // reset memory associated with the master password settings.mpw = string(256, 0); return 0; } passwordmaker-cli-1.5.orig/pwmdefaults.cpp0000755000000000000000000001203111545725573017520 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ #include "stdafx.h" #include "pwmdefaults.h" #include "tinyxml.h" using namespace std; extern char base93Set[]; // This is defined in passwordmaker.cpp pwmDefaults::pwmDefaults(string filepath, string account, int account_count) { masterPassword = "\x01"; algorithm = "MD5"; hmac = false; trim = true; length = 8; characters = base93Set; useLeet = "none"; leetLevel = 0; username = ""; modifier = ""; prefix = ""; suffix = ""; used_file = false; // Try to open the rdf with tinyxml TiXmlDocument document(filepath); document.LoadFile(); string ns; if (!document.Error()) { TiXmlHandle docHandle(&document); TiXmlElement *defaultNode = docHandle.FirstChildElement("RDF:RDF").Element(); int acc_cnt = 0; if (defaultNode) { TiXmlAttribute *attrib = defaultNode->FirstAttribute(); // Find the namespace while (attrib) { if (!strcmp(attrib->Value(), "http://passwordmaker.mozdev.org/rdf#")) { ns = attrib->Name(); ns.erase(ns.begin(), ns.begin() + (ns.find(':') + 1)); break; } attrib = attrib->Next(); } if (ns.empty()) { // Namespace was not found. Not a valid file? defaultNode = NULL; } else { defaultNode = docHandle.FirstChildElement("RDF:RDF").FirstChildElement("RDF:Description").Element(); while (defaultNode) { if (account.empty()) { // Now get the node that contains the default settings if (!strcmp(defaultNode->Attribute("RDF:about"), "http://passwordmaker.mozdev.org/defaults")) { break; } } else { // Now to find the node with the account name we're using if (defaultNode->Attribute(ns+":autoPopulate") && !strcmp(defaultNode->Attribute(ns+":name"), account.c_str()) && acc_cnt++ == account_count) { break; } } defaultNode = defaultNode->NextSiblingElement("RDF:Description"); } } } if (defaultNode) { used_file = true; char *tmpStr; masterPassword = "\x01"; // Doesn't support stored passwords, yet // Grab the characterset tmpStr = (char*)defaultNode->Attribute(ns+":charset"); characters = (tmpStr) ? tmpStr : base93Set; // Grab the username tmpStr = (char*)defaultNode->Attribute(ns+":usernameTB"); username = (tmpStr) ? tmpStr : ""; // Grab the modifier, which was called counter in an earlier version of the Firefox extension tmpStr = (char*)defaultNode->Attribute(ns+":counter"); modifier = (tmpStr) ? tmpStr : ""; // Grab the prefix tmpStr = (char*)defaultNode->Attribute(ns+":prefix"); prefix = (tmpStr) ? tmpStr : ""; // Grab the suffix tmpStr = (char*)defaultNode->Attribute(ns+":suffix"); suffix = (tmpStr) ? tmpStr : ""; // Grab the url tmpStr = (char*)defaultNode->Attribute(ns+":urlToUse"); url = (tmpStr) ? tmpStr : ""; // Get the password length tmpStr = (char*)defaultNode->Attribute(ns+":passwordLength", &length); if (!tmpStr) length = 8; // Get the leet level tmpStr = (char*)defaultNode->Attribute(ns+":leetLevelLB", &leetLevel); if (!tmpStr) leetLevel = 1; // Find hash algorithm to use, and if it's HMAC tmpStr = (char*)defaultNode->Attribute(ns+":hashAlgorithmLB"); if (!tmpStr) tmpStr = "md5"; if (strstr(tmpStr, "hmac")) { hmac = true; } else { hmac = false; } if (strstr(tmpStr, "md4")) algorithm = "MD4"; if (strstr(tmpStr, "md5")) algorithm = "MD5"; if (strstr(tmpStr, "sha1")) algorithm = "SHA1"; if (strstr(tmpStr, "sha256")) algorithm = "SHA256"; if (strstr(tmpStr, "rmd160")) algorithm = "RIPEMD160"; // Get where to apply leet (and convert to commandline value tmpStr = (char*)defaultNode->Attribute(ns+":whereLeetLB"); if (!tmpStr) tmpStr = "off"; if (strstr(tmpStr, "off")) useLeet = "none"; if (strstr(tmpStr, "before-hashing")) useLeet = "before"; if (strstr(tmpStr, "after-hashing")) useLeet = "after"; if (strstr(tmpStr, "both")) useLeet = "both"; } } } pwmDefaults::~pwmDefaults(void) { } passwordmaker-cli-1.5.orig/urlsearch.h0000755000000000000000000000306611545725573016632 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung * urlsearch.h by Dave Marotti */ #ifndef URLSEARCH_H #define URLSEARCH_H #include class UrlSearch { private: std::string name; std::string description; std::string username; public: UrlSearch(); virtual ~UrlSearch(); bool search(std::string url, std::string filepath); inline std::string getName() { return name; } inline std::string getDescription() { return description; } inline std::string getUsername() { return username; } private: int regexCmp(const char *regexp, const char *string); int wildcardCmp(const char *wild, const char *string); }; #endif passwordmaker-cli-1.5.orig/getHash.js0000755000000000000000000010146711545725573016416 0ustar rootroot/** * PasswordMaker - Creates and manages passwords * Copyright (C) 2005 Eric H. Jung and LeahScape, Inc. * http://passwordmaker.org/ * grimholtz@yahoo.com * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 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 * FITNESSFOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser 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 * * Written by Miquel Burns and Eric H. Jung */ /* This is a bandaid solution until someone can give decent support for mhash on Windows. Plus side is that HMAC-SHA256 will be correct with the Javascript version ;) */ /* * The main function the c code will call. * -string: algo - algorithm to use to hash the data and key. * -string: data - data to hash, always passed to the hash function * -string: encoding - encoding to convert the hash to * -string: key - key to use when using HMAC * -bool: trim - If rstr2any trims the leading 'zeros' */ function getHash(algo, data, encoding, key, trim) { switch (algo) { case "md4": return PasswordMaker_MD4.any_md4(data, encoding, trim); case "hmac-md4": return PasswordMaker_MD4.any_hmac_md4(key, data, encoding, trim); case "md5": return PasswordMaker_MD5.any_md5(data, encoding, trim); case "hmac-md5": return PasswordMaker_MD5.any_hmac_md5(key, data, encoding, trim); case "ripemd160": return PasswordMaker_RIPEMD160.any_rmd160(data, encoding, trim); case "hmac-ripemd160": return PasswordMaker_RIPEMD160.any_hmac_rmd160(key, data, encoding, trim); case "sha1": return PasswordMaker_SHA1.any_sha1(data, encoding, trim); case "hmac-sha1": return PasswordMaker_SHA1.any_hmac_sha1(key, data, encoding, trim); case "sha256": return PasswordMaker_SHA256.any_sha256(data, encoding, trim); case "hmac-sha256": return PasswordMaker_SHA256.any_hmac_sha256(key, data, encoding, trim); default: return ''; } } if (typeof(PasswordMaker_HashUtils) != "object") { var PasswordMaker_HashUtils = { chrsz : 8, /* bits per input character. 8 - ASCII; 16 - Unicode */ /* * Encode a string as utf-8. * For efficiency, this assumes the input is valid utf-16. */ str2rstr_utf8 : function(input) { var output = ""; var i = -1; var x, y; while(++i < input.length) { /* Decode utf-16 surrogate pairs */ x = input.charCodeAt(i); y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) { x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); i++; } /* Encode output as utf-8 */ if(x <= 0x7F) output += String.fromCharCode(x); else if(x <= 0x7FF) output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), 0x80 | ( x & 0x3F)); else if(x <= 0xFFFF) output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 0x80 | ((x >>> 6 ) & 0x3F), 0x80 | ( x & 0x3F)); else if(x <= 0x1FFFFF) output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 0x80 | ((x >>> 12) & 0x3F), 0x80 | ((x >>> 6 ) & 0x3F), 0x80 | ( x & 0x3F)); } return output; }, /* * Convert a raw string to an array of little-endian words * Characters >255 have their high-byte silently ignored. */ rstr2binl : function(input) { var output = Array(input.length >> 2); for(var i = 0; i < output.length; i++) output[i] = 0; for(var i = 0; i < input.length * 8; i += 8) output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32); return output; }, /* * Convert an array of little-endian words to a string */ binl2rstr : function(input) { var output = ""; for(var i = 0; i < input.length * 32; i += 8) output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF); return output; }, /* * Convert a raw string to an arbitrary string encoding */ rstr2any : function(input, encoding, trim) { var divisor = encoding.length; var remainders = Array(); var j, i, q, x, quotient, full_length; /* Convert to an array of 16-bit big-endian values, forming the dividend */ var dividend = Array(input.length / 2); var inp = new String(input); // EHJ: added for(i = 0; i < dividend.length; i++) { dividend[i] = (inp.charCodeAt(i * 2) << 8) | inp.charCodeAt(i * 2 + 1); } /* * Repeatedly perform a long division. The binary array forms the dividend, * the length of the encoding is the divisor. Once computed, the quotient * forms the dividend for the next step. We stop when the dividend is zero. * All remainders are stored for later use. */ full_length = Math.ceil(inp.length * 8 / (Math.log(encoding.length) / Math.log(2))); var count = 0; if (trim) { while(dividend.length > 0) { quotient = Array(); x = 0; for(i = 0; i < dividend.length; i++) { x = (x << 16) + dividend[i]; q = Math.floor(x / divisor); x -= q * divisor; if(quotient.length > 0 || q > 0) quotient[quotient.length] = q; } remainders[remainders.length] = x; dividend = quotient; count++; } full_length = remainders.length; } else { remainders = Array(full_length); for (j = 0; j < full_length; j++) { quotient = Array(); x = 0; for(i = 0; i < dividend.length; i++) { x = (x << 16) + dividend[i]; q = Math.floor(x / divisor); x -= q * divisor; if(quotient.length > 0 || q > 0) quotient[quotient.length] = q; } remainders[j] = x; dividend = quotient; } } /* Convert the remainders to the output string */ var output = ""; for(i = remainders.length - 1; i >= 0; i--) { output += encoding.charAt(remainders[i]); } return output; }, ///===== big endian =====\\\ /* * Convert a raw string to an array of big-endian words * Characters >255 have their high-byte silently ignored. */ rstr2binb : function(input) { var output = Array(input.length >> 2); for(var i = 0; i < output.length; i++) output[i] = 0; for(var i = 0; i < input.length * 8; i += 8) output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32); return output; }, /* * Convert an array of big-endian words to a string */ binb2rstr : function(input) { var output = ""; for(var i = 0; i < input.length * 32; i += 8) output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF); return output; }, /* * Bitwise rotate a 32-bit number to the left. */ bit_rol : function(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); }, /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ safe_add : function(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } } } if (typeof(PasswordMaker_MD4) != "object") { var PasswordMaker_MD4 = { any_md4 : function(s, e, t) { return PasswordMaker_HashUtils.rstr2any(this.rstr_md4(PasswordMaker_HashUtils.str2rstr_utf8(s)), e, t); }, any_hmac_md4 : function(k, d, e, t) { return PasswordMaker_HashUtils.rstr2any(this.rstr_hmac_md4(PasswordMaker_HashUtils.str2rstr_utf8(k), PasswordMaker_HashUtils.str2rstr_utf8(d)), e, t); }, /* * Calculate the MD4 of a raw string */ rstr_md4 : function(s) { return PasswordMaker_HashUtils.binl2rstr(this.binl_md4(PasswordMaker_HashUtils.rstr2binl(s), s.length * PasswordMaker_HashUtils.chrsz)); }, /* * Calculate the MD4 of an array of little-endian words, and a bit length */ binl_md4 : function(x, len) { /* append padding */ x[len >> 5] |= 0x80 << (len % 32); x[(((len + 64) >>> 9) << 4) + 14] = len; var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for(var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = this.md4_ff(a, b, c, d, x[i+ 0], 3 ); d = this.md4_ff(d, a, b, c, x[i+ 1], 7 ); c = this.md4_ff(c, d, a, b, x[i+ 2], 11); b = this.md4_ff(b, c, d, a, x[i+ 3], 19); a = this.md4_ff(a, b, c, d, x[i+ 4], 3 ); d = this.md4_ff(d, a, b, c, x[i+ 5], 7 ); c = this.md4_ff(c, d, a, b, x[i+ 6], 11); b = this.md4_ff(b, c, d, a, x[i+ 7], 19); a = this.md4_ff(a, b, c, d, x[i+ 8], 3 ); d = this.md4_ff(d, a, b, c, x[i+ 9], 7 ); c = this.md4_ff(c, d, a, b, x[i+10], 11); b = this.md4_ff(b, c, d, a, x[i+11], 19); a = this.md4_ff(a, b, c, d, x[i+12], 3 ); d = this.md4_ff(d, a, b, c, x[i+13], 7 ); c = this.md4_ff(c, d, a, b, x[i+14], 11); b = this.md4_ff(b, c, d, a, x[i+15], 19); a = this.md4_gg(a, b, c, d, x[i+ 0], 3 ); d = this.md4_gg(d, a, b, c, x[i+ 4], 5 ); c = this.md4_gg(c, d, a, b, x[i+ 8], 9 ); b = this.md4_gg(b, c, d, a, x[i+12], 13); a = this.md4_gg(a, b, c, d, x[i+ 1], 3 ); d = this.md4_gg(d, a, b, c, x[i+ 5], 5 ); c = this.md4_gg(c, d, a, b, x[i+ 9], 9 ); b = this.md4_gg(b, c, d, a, x[i+13], 13); a = this.md4_gg(a, b, c, d, x[i+ 2], 3 ); d = this.md4_gg(d, a, b, c, x[i+ 6], 5 ); c = this.md4_gg(c, d, a, b, x[i+10], 9 ); b = this.md4_gg(b, c, d, a, x[i+14], 13); a = this.md4_gg(a, b, c, d, x[i+ 3], 3 ); d = this.md4_gg(d, a, b, c, x[i+ 7], 5 ); c = this.md4_gg(c, d, a, b, x[i+11], 9 ); b = this.md4_gg(b, c, d, a, x[i+15], 13); a = this.md4_hh(a, b, c, d, x[i+ 0], 3 ); d = this.md4_hh(d, a, b, c, x[i+ 8], 9 ); c = this.md4_hh(c, d, a, b, x[i+ 4], 11); b = this.md4_hh(b, c, d, a, x[i+12], 15); a = this.md4_hh(a, b, c, d, x[i+ 2], 3 ); d = this.md4_hh(d, a, b, c, x[i+10], 9 ); c = this.md4_hh(c, d, a, b, x[i+ 6], 11); b = this.md4_hh(b, c, d, a, x[i+14], 15); a = this.md4_hh(a, b, c, d, x[i+ 1], 3 ); d = this.md4_hh(d, a, b, c, x[i+ 9], 9 ); c = this.md4_hh(c, d, a, b, x[i+ 5], 11); b = this.md4_hh(b, c, d, a, x[i+13], 15); a = this.md4_hh(a, b, c, d, x[i+ 3], 3 ); d = this.md4_hh(d, a, b, c, x[i+11], 9 ); c = this.md4_hh(c, d, a, b, x[i+ 7], 11); b = this.md4_hh(b, c, d, a, x[i+15], 15); a = PasswordMaker_HashUtils.safe_add(a, olda); b = PasswordMaker_HashUtils.safe_add(b, oldb); c = PasswordMaker_HashUtils.safe_add(c, oldc); d = PasswordMaker_HashUtils.safe_add(d, oldd); } return Array(a, b, c, d); }, /* * These functions implement the basic operation for each round of the * algorithm. */ md4_cmn : function(q, a, b, x, s, t) { return PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.bit_rol(PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(a, q), PasswordMaker_HashUtils.safe_add(x, t)), s), b); }, md4_ff : function(a, b, c, d, x, s) { return this.md4_cmn((b & c) | ((~b) & d), a, 0, x, s, 0); }, md4_gg : function(a, b, c, d, x, s) { return this.md4_cmn((b & c) | (b & d) | (c & d), a, 0, x, s, 1518500249); }, md4_hh : function(a, b, c, d, x, s) { return this.md4_cmn(b ^ c ^ d, a, 0, x, s, 1859775393); }, /* * Calculate the HMAC-MD4 of a key and some data */ rstr_hmac_md4 : function(key, data) { var bkey = PasswordMaker_HashUtils.rstr2binl(key); if(bkey.length > 16) bkey = this.binl_md4(bkey, key.length * PasswordMaker_HashUtils.chrsz); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = this.binl_md4(ipad.concat(PasswordMaker_HashUtils.rstr2binl(data)), 512 + data.length * PasswordMaker_HashUtils.chrsz); //return this.binl_md4(opad.concat(hash), 512 + 128); return PasswordMaker_HashUtils.binl2rstr(this.binl_md4(opad.concat(hash), 512 + 128)); } } } if (typeof(PasswordMaker_MD5) != "object") { var PasswordMaker_MD5 = { any_md5 : function(s, e, t) { return PasswordMaker_HashUtils.rstr2any(this.rstr_md5(PasswordMaker_HashUtils.str2rstr_utf8(s)), e, t); }, any_hmac_md5 : function(k, d, e, t) { return PasswordMaker_HashUtils.rstr2any(this.rstr_hmac_md5(PasswordMaker_HashUtils.str2rstr_utf8(k), PasswordMaker_HashUtils.str2rstr_utf8(d)), e, t); }, /* * Calculate the MD5 of a raw string */ rstr_md5 : function(s) { return PasswordMaker_HashUtils.binl2rstr(this.binl_md5(PasswordMaker_HashUtils.rstr2binl(s), s.length * PasswordMaker_HashUtils.chrsz)); }, /* * Calculate the MD5 of an array of little-endian words, and a bit length. */ binl_md5 : function(x, len) { /* append padding */ x[len >> 5] |= 0x80 << ((len) % 32); x[(((len + 64) >>> 9) << 4) + 14] = len; var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for(var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = this.md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); d = this.md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); c = this.md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); b = this.md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); a = this.md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); d = this.md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); c = this.md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); b = this.md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); a = this.md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); d = this.md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); c = this.md5_ff(c, d, a, b, x[i+10], 17, -42063); b = this.md5_ff(b, c, d, a, x[i+11], 22, -1990404162); a = this.md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); d = this.md5_ff(d, a, b, c, x[i+13], 12, -40341101); c = this.md5_ff(c, d, a, b, x[i+14], 17, -1502002290); b = this.md5_ff(b, c, d, a, x[i+15], 22, 1236535329); a = this.md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); d = this.md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); c = this.md5_gg(c, d, a, b, x[i+11], 14, 643717713); b = this.md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); a = this.md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); d = this.md5_gg(d, a, b, c, x[i+10], 9 , 38016083); c = this.md5_gg(c, d, a, b, x[i+15], 14, -660478335); b = this.md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); a = this.md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); d = this.md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); c = this.md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); b = this.md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); a = this.md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); d = this.md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); c = this.md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); b = this.md5_gg(b, c, d, a, x[i+12], 20, -1926607734); a = this.md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); d = this.md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); c = this.md5_hh(c, d, a, b, x[i+11], 16, 1839030562); b = this.md5_hh(b, c, d, a, x[i+14], 23, -35309556); a = this.md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); d = this.md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); c = this.md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); b = this.md5_hh(b, c, d, a, x[i+10], 23, -1094730640); a = this.md5_hh(a, b, c, d, x[i+13], 4 , 681279174); d = this.md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); c = this.md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); b = this.md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); a = this.md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); d = this.md5_hh(d, a, b, c, x[i+12], 11, -421815835); c = this.md5_hh(c, d, a, b, x[i+15], 16, 530742520); b = this.md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); a = this.md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); d = this.md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); c = this.md5_ii(c, d, a, b, x[i+14], 15, -1416354905); b = this.md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); a = this.md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); d = this.md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); c = this.md5_ii(c, d, a, b, x[i+10], 15, -1051523); b = this.md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); a = this.md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); d = this.md5_ii(d, a, b, c, x[i+15], 10, -30611744); c = this.md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); b = this.md5_ii(b, c, d, a, x[i+13], 21, 1309151649); a = this.md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); d = this.md5_ii(d, a, b, c, x[i+11], 10, -1120210379); c = this.md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); b = this.md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); a = PasswordMaker_HashUtils.safe_add(a, olda); b = PasswordMaker_HashUtils.safe_add(b, oldb); c = PasswordMaker_HashUtils.safe_add(c, oldc); d = PasswordMaker_HashUtils.safe_add(d, oldd); } return Array(a, b, c, d); }, /* * These functions implement the four basic operations the algorithm uses. */ md5_cmn : function(q, a, b, x, s, t) { return PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.bit_rol(PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(a, q), PasswordMaker_HashUtils.safe_add(x, t)), s),b); }, md5_ff : function(a, b, c, d, x, s, t) { return this.md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); }, md5_gg : function(a, b, c, d, x, s, t) { return this.md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); }, md5_hh : function(a, b, c, d, x, s, t) { return this.md5_cmn(b ^ c ^ d, a, b, x, s, t); }, md5_ii : function(a, b, c, d, x, s, t) { return this.md5_cmn(c ^ (b | (~d)), a, b, x, s, t); }, /* * Calculate the HMAC-MD5 of a key and some data (raw strings) */ rstr_hmac_md5 : function(key, data) { var bkey = PasswordMaker_HashUtils.rstr2binl(key); if(bkey.length > 16) bkey = this.binl_md5(bkey, key.length * PasswordMaker_HashUtils.chrsz); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = this.binl_md5(ipad.concat(PasswordMaker_HashUtils.rstr2binl(data)), 512 + data.length * PasswordMaker_HashUtils.chrsz); return PasswordMaker_HashUtils.binl2rstr(this.binl_md5(opad.concat(hash), 512 + 128)); } } } if (typeof(PasswordMaker_RIPEMD160) != "object") { var PasswordMaker_RIPEMD160 = { any_rmd160 : function(s, e, t){ return PasswordMaker_HashUtils.rstr2any(this.rstr_rmd160(PasswordMaker_HashUtils.str2rstr_utf8(s)), e, t); }, any_hmac_rmd160 : function(k, d, e, t){ return PasswordMaker_HashUtils.rstr2any(this.rstr_hmac_rmd160(PasswordMaker_HashUtils.str2rstr_utf8(k), PasswordMaker_HashUtils.str2rstr_utf8(d)), e, t); }, /* * Calculate the rmd160 of a raw string */ rstr_rmd160 : function(s) { return PasswordMaker_HashUtils.binl2rstr(this.binl_rmd160(PasswordMaker_HashUtils.rstr2binl(s), s.length * PasswordMaker_HashUtils.chrsz)); }, /* * Calculate the HMAC-rmd160 of a key and some data (raw strings) */ rstr_hmac_rmd160 : function(key, data) { var bkey = PasswordMaker_HashUtils.rstr2binl(key); if(bkey.length > 16) bkey = this.binl_rmd160(bkey, key.length * 8); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = this.binl_rmd160(ipad.concat(PasswordMaker_HashUtils.rstr2binl(data)), 512 + data.length * 8); return PasswordMaker_HashUtils.binl2rstr(this.binl_rmd160(opad.concat(hash), 512 + 160)); }, /* * Calculate the RIPE-MD160 of an array of little-endian words, and a bit length. */ binl_rmd160 : function(x, len) { /* append padding */ x[len >> 5] |= 0x80 << (len % 32); x[(((len + 64) >>> 9) << 4) + 14] = len; var h0 = 0x67452301; var h1 = 0xefcdab89; var h2 = 0x98badcfe; var h3 = 0x10325476; var h4 = 0xc3d2e1f0; for (var i = 0; i < x.length; i += 16) { var T; var A1 = h0, B1 = h1, C1 = h2, D1 = h3, E1 = h4; var A2 = h0, B2 = h1, C2 = h2, D2 = h3, E2 = h4; for (var j = 0; j <= 79; ++j) { T = PasswordMaker_HashUtils.safe_add(A1, this.rmd160_f(j, B1, C1, D1)); T = PasswordMaker_HashUtils.safe_add(T, x[i + this.rmd160_r1[j]]); T = PasswordMaker_HashUtils.safe_add(T, this.rmd160_K1(j)); T = PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.bit_rol(T, this.rmd160_s1[j]), E1); A1 = E1; E1 = D1; D1 = PasswordMaker_HashUtils.bit_rol(C1, 10); C1 = B1; B1 = T; T = PasswordMaker_HashUtils.safe_add(A2, this.rmd160_f(79-j, B2, C2, D2)); T = PasswordMaker_HashUtils.safe_add(T, x[i + this.rmd160_r2[j]]); T = PasswordMaker_HashUtils.safe_add(T, this.rmd160_K2(j)); T = PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.bit_rol(T, this.rmd160_s2[j]), E2); A2 = E2; E2 = D2; D2 = PasswordMaker_HashUtils.bit_rol(C2, 10); C2 = B2; B2 = T; } T = PasswordMaker_HashUtils.safe_add(h1, PasswordMaker_HashUtils.safe_add(C1, D2)); h1 = PasswordMaker_HashUtils.safe_add(h2, PasswordMaker_HashUtils.safe_add(D1, E2)); h2 = PasswordMaker_HashUtils.safe_add(h3, PasswordMaker_HashUtils.safe_add(E1, A2)); h3 = PasswordMaker_HashUtils.safe_add(h4, PasswordMaker_HashUtils.safe_add(A1, B2)); h4 = PasswordMaker_HashUtils.safe_add(h0, PasswordMaker_HashUtils.safe_add(B1, C2)); h0 = T; } return [h0, h1, h2, h3, h4]; }, /* * Encode a string as utf-16 */ str2rstr_utf16le : function(input) { var output = ""; for(var i = 0; i < input.length; i++) output += String.fromCharCode( input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF); return output; }, str2rstr_utf16be : function(input) { var output = ""; for(var i = 0; i < input.length; i++) output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF); return output; }, rmd160_f : function(j, x, y, z) { return ( 0 <= j && j <= 15) ? (x ^ y ^ z) : (16 <= j && j <= 31) ? (x & y) | (~x & z) : (32 <= j && j <= 47) ? (x | ~y) ^ z : (48 <= j && j <= 63) ? (x & z) | (y & ~z) : (64 <= j && j <= 79) ? x ^ (y | ~z) : "rmd160_f: j out of range"; }, rmd160_K1 : function(j) { return ( 0 <= j && j <= 15) ? 0x00000000 : (16 <= j && j <= 31) ? 0x5a827999 : (32 <= j && j <= 47) ? 0x6ed9eba1 : (48 <= j && j <= 63) ? 0x8f1bbcdc : (64 <= j && j <= 79) ? 0xa953fd4e : "rmd160_K1: j out of range"; }, rmd160_K2 : function(j) { return ( 0 <= j && j <= 15) ? 0x50a28be6 : (16 <= j && j <= 31) ? 0x5c4dd124 : (32 <= j && j <= 47) ? 0x6d703ef3 : (48 <= j && j <= 63) ? 0x7a6d76e9 : (64 <= j && j <= 79) ? 0x00000000 : "rmd160_K2: j out of range"; }, rmd160_r1 : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 ], rmd160_r2 : [ 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 ], rmd160_s1 : [ 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ], rmd160_s2 : [ 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ] } } if (typeof(PasswordMaker_SHA1) != "object") { var PasswordMaker_SHA1 = { any_sha1 : function(s, e, t){ return PasswordMaker_HashUtils.rstr2any(this.rstr_sha1(PasswordMaker_HashUtils.str2rstr_utf8(s)), e, t); }, any_hmac_sha1 : function(k, d, e, t){ return PasswordMaker_HashUtils.rstr2any(this.rstr_hmac_sha1(PasswordMaker_HashUtils.str2rstr_utf8(k), PasswordMaker_HashUtils.str2rstr_utf8(d)), e, t); }, /* * Calculate the SHA1 of a raw string */ rstr_sha1 : function(s) { return PasswordMaker_HashUtils.binb2rstr(this.binb_sha1(PasswordMaker_HashUtils.rstr2binb(s), s.length * PasswordMaker_HashUtils.chrsz)); }, /* * Calculate the SHA-1 of an array of big-endian words and a bit length */ binb_sha1 : function(x, len) { /* append padding */ x[len >> 5] |= 0x80 << (24 - len % 32); x[((len + 64 >> 9) << 4) + 15] = len; var w = Array(80); var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; var e = -1009589776; for(var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; var olde = e; for(var j = 0; j < 80; j++) { if(j < 16) w[j] = x[i + j]; else w[j] = PasswordMaker_HashUtils.bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); var t = PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.bit_rol(a, 5), this.sha1_ft(j, b, c, d)), PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(e, w[j]), this.sha1_kt(j))); e = d; d = c; c = PasswordMaker_HashUtils.bit_rol(b, 30); b = a; a = t; } a = PasswordMaker_HashUtils.safe_add(a, olda); b = PasswordMaker_HashUtils.safe_add(b, oldb); c = PasswordMaker_HashUtils.safe_add(c, oldc); d = PasswordMaker_HashUtils.safe_add(d, oldd); e = PasswordMaker_HashUtils.safe_add(e, olde); } return Array(a, b, c, d, e); }, /* * Perform the appropriate triplet combination function for the current * iteration */ sha1_ft : function(t, b, c, d) { if(t < 20) return (b & c) | ((~b) & d); if(t < 40) return b ^ c ^ d; if(t < 60) return (b & c) | (b & d) | (c & d); return b ^ c ^ d; }, /* * Determine the appropriate additive constant for the current iteration */ sha1_kt : function(t) { return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : (t < 60) ? -1894007588 : -899497514; }, /* * Calculate the HMAC-SHA1 of a key and some data (raw strings) */ rstr_hmac_sha1 : function(key, data) { var bkey = PasswordMaker_HashUtils.rstr2binb(key); if(bkey.length > 16) bkey = this.binb_sha1(bkey, key.length * 8); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = this.binb_sha1(ipad.concat(PasswordMaker_HashUtils.rstr2binb(data)), 512 + data.length * 8); return PasswordMaker_HashUtils.binb2rstr(this.binb_sha1(opad.concat(hash), 512 + 160)); } } } if (typeof(PasswordMaker_SHA256) != "object") { var PasswordMaker_SHA256 = { any_sha256 : function(s, e, t){ return PasswordMaker_HashUtils.rstr2any(this.rstr_sha256(PasswordMaker_HashUtils.str2rstr_utf8(s)), e, t); }, any_hmac_sha256: function(k, d, e, t){ return PasswordMaker_HashUtils.rstr2any(this.rstr_hmac_sha256(PasswordMaker_HashUtils.str2rstr_utf8(k), PasswordMaker_HashUtils.str2rstr_utf8(d)), e, t); }, /* * Calculate the sha256 of a raw string */ rstr_sha256 : function(s) { return PasswordMaker_HashUtils.binb2rstr(this.binb_sha256(PasswordMaker_HashUtils.rstr2binb(s), s.length * 8)); }, /* * Calculate the HMAC-sha256 of a key and some data (raw strings) */ rstr_hmac_sha256 : function(key, data) { var bkey = PasswordMaker_HashUtils.rstr2binb(key); if(bkey.length > 16) bkey = this.binb_sha256(bkey, key.length * 8); var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = this.binb_sha256(ipad.concat(PasswordMaker_HashUtils.rstr2binb(data)), 512 + data.length * 8); return PasswordMaker_HashUtils.binb2rstr(this.binb_sha256(opad.concat(hash), 512 + 160)); }, /* * Main sha256 function, with its support functions */ S:function(X, n) {return ( X >>> n ) | (X << (32 - n));}, R:function (X, n) {return ( X >>> n );}, Ch:function(x, y, z) {return ((x & y) ^ ((~x) & z));}, Maj:function(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}, Sigma0256:function(x) {return (this.S(x, 2) ^ this.S(x, 13) ^ this.S(x, 22));}, Sigma1256:function(x) {return (this.S(x, 6) ^ this.S(x, 11) ^ this.S(x, 25));}, Gamma0256:function(x) {return (this.S(x, 7) ^ this.S(x, 18) ^ this.R(x, 3));}, Gamma1256:function(x) {return (this.S(x, 17) ^ this.S(x, 19) ^ this.R(x, 10));}, Sigma0512:function(x) {return (this.S(x, 28) ^ this.S(x, 34) ^ this.S(x, 39));}, Sigma1512:function(x) {return (this.S(x, 14) ^ this.S(x, 18) ^ this.S(x, 41));}, Gamma0512:function(x) {return (this.S(x, 1) ^ this.S(x, 8) ^ this.R(x, 7));}, Gamma1512:function(x) {return (this.S(x, 19) ^ this.S(x, 61) ^ this.R(x, 6));}, sha256_K : new Array( 1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987, 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998 ), binb_sha256 : function(m, l) { var HASH = new Array(1779033703, -1150833019, 1013904242, -1521486534, 1359893119, -1694144372, 528734635, 1541459225); var W = new Array(64); var a, b, c, d, e, f, g, h; var i, j, T1, T2; /* append padding */ m[l >> 5] |= 0x80 << (24 - l % 32); m[((l + 64 >> 9) << 4) + 15] = l; for(i = 0; i < m.length; i += 16) { a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7]; for(j = 0; j < 64; j++) { if (j < 16) W[j] = m[j + i]; else W[j] = PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(this.Gamma1256(W[j - 2]), W[j - 7]), this.Gamma0256(W[j - 15])), W[j - 16]); T1 = PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(PasswordMaker_HashUtils.safe_add(h, this.Sigma1256(e)), this.Ch(e, f, g)), this.sha256_K[j]), W[j]); T2 = PasswordMaker_HashUtils.safe_add(this.Sigma0256(a), this.Maj(a, b, c)); h = g; g = f; f = e; e = PasswordMaker_HashUtils.safe_add(d, T1); d = c; c = b; b = a; a = PasswordMaker_HashUtils.safe_add(T1, T2); } HASH[0] = PasswordMaker_HashUtils.safe_add(a, HASH[0]); HASH[1] = PasswordMaker_HashUtils.safe_add(b, HASH[1]); HASH[2] = PasswordMaker_HashUtils.safe_add(c, HASH[2]); HASH[3] = PasswordMaker_HashUtils.safe_add(d, HASH[3]); HASH[4] = PasswordMaker_HashUtils.safe_add(e, HASH[4]); HASH[5] = PasswordMaker_HashUtils.safe_add(f, HASH[5]); HASH[6] = PasswordMaker_HashUtils.safe_add(g, HASH[6]); HASH[7] = PasswordMaker_HashUtils.safe_add(h, HASH[7]); } return HASH; } } }