r_sms.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_sms.h
00003 ///             Record parsing class for SMS messages.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008     Copyright (C) 2009, Ryan Li(ryan@ryanium.com)
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 #ifndef __BARRY_RECORD_SMS_H__
00024 #define __BARRY_RECORD_SMS_H__
00025 
00026 #include "dll.h"
00027 #include "record.h"
00028 #include <vector>
00029 #include <string>
00030 #include <stdint.h>
00031 
00032 namespace Barry {
00033 
00034 // forward declarations
00035 class IConverter;
00036 
00037 class BXEXPORT Sms
00038 {
00039 public:
00040         typedef Barry::UnknownsType                     UnknownsType;
00041 
00042         uint8_t RecType;
00043         uint32_t RecordId;
00044 
00045         enum MessageType
00046         {
00047                 Unknown = 0,
00048                 Received,
00049                 Sent,
00050                 Draft
00051         };
00052         MessageType MessageStatus;
00053 
00054         enum DeliveryType
00055         {
00056                 NoReport = 0,
00057                 Failed,
00058                 Succeeded
00059         };
00060         DeliveryType DeliveryStatus; // not implemented yet
00061 
00062         bool IsNew;
00063         bool NewConversation;
00064         bool Saved;
00065         bool Deleted;
00066         bool Opened;
00067 
00068         uint64_t Timestamp; // milliseconds from Jan 1, 1970
00069         uint64_t ServiceCenterTimestamp; // not applicable for non-incoming messages
00070 
00071         enum DataCodingSchemeType
00072         {
00073                 SevenBit = 0,
00074                 EightBit,
00075                 UCS2
00076         };
00077         DataCodingSchemeType DataCodingScheme;
00078 
00079         uint32_t ErrorId;
00080 
00081         EmailList Addresses;            //< not strictly email, but just a list
00082                                         //< strings, used for phone numbers
00083         std::string Body;
00084 
00085         UnknownsType Unknowns;
00086 
00087 public:
00088         Sms();
00089         ~Sms();
00090 
00091         time_t GetTime() const;
00092         time_t GetServiceCenterTime() const;
00093         void SetTime(const time_t timestamp, unsigned int milliseconds = 0);
00094         void SetServiceCenterTime(const time_t timestamp, unsigned int milliseconds = 0);
00095 
00096         // Parser / Builder API (see parser.h / builder.h)
00097         void Validate() const;
00098         const unsigned char* ParseField(const unsigned char *begin, const unsigned char *end, const IConverter *ic = 0);
00099         uint8_t GetRecType() const { return RecType; }
00100         uint32_t GetUniqueId() const { return RecordId; }
00101         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00102         void ParseHeader(const Data &data, size_t &offset);
00103         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00104         void BuildHeader(Data &data, size_t &offset) const;
00105         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00106 
00107         // operations (common among record classes)
00108         void Clear();
00109         void Dump(std::ostream &os) const;
00110         std::string GetDescription() const;
00111 
00112         static std::string ConvertGsmToUtf8(const std::string &);
00113 
00114         // sorting
00115         bool operator<(const Sms &other) const {
00116                 return Timestamp < other.Timestamp;
00117         }
00118 
00119         // database name
00120         static const char * GetDBName() { return "SMS Messages"; }
00121         static uint8_t GetDefaultRecType() { return 5; }
00122 
00123         // Generic Field Handle support
00124         static const FieldHandle<Sms>::ListT& GetFieldHandles();
00125 };
00126 
00127 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const Sms &msg) {
00128         msg.Dump(os);
00129         return os;
00130 }
00131 
00132 } // namespace Barry
00133 
00134 #endif
00135