icqdb.h
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. #ifndef _ICQ_DB_H
  12. #define _ICQ_DB_H
  13. #include "icqtypes.h"
  14. #include <db.h>
  15. #define MAX_BLOCK_SIZE 4096
  16. class DBOutStream {
  17. public:
  18. DBOutStream() {
  19. cursor = data;
  20. }
  21. char *getData() {
  22. return data;
  23. }
  24. int getSize() {
  25. return (cursor - data);
  26. }
  27. DBOutStream &operator <<(uint8 b);
  28. DBOutStream &operator <<(uint16 w);
  29. DBOutStream &operator <<(uint32 dw);
  30. DBOutStream &operator <<(const char *str);
  31. DBOutStream &operator <<(const string &str) {
  32. return operator <<(str.c_str());
  33. }
  34. DBOutStream &operator <<(StrList &strList);
  35. private:
  36. char data[MAX_BLOCK_SIZE];
  37. char *cursor;
  38. };
  39. class DBInStream {
  40. public:
  41. DBInStream(void *d, int n) {
  42. cursor = data = (char *) d;
  43. datalen = n;
  44. }
  45. DBInStream &operator >>(uint8 &b);
  46. DBInStream &operator >>(uint16 &w);
  47. DBInStream &operator >>(uint32 &dw);
  48. DBInStream &operator >>(string &str);
  49. DBInStream &operator >>(StrList &strList);
  50. private:
  51. char *data;
  52. char *cursor;
  53. int datalen;
  54. };
  55. class DBSerialize {
  56. public:
  57. virtual void save(DBOutStream &out) = 0;
  58. virtual void load(DBInStream &in) = 0;
  59. };
  60. class IcqMsg;
  61. class IcqContact;
  62. class IcqUser;
  63. class IcqOption;
  64. class IcqDB {
  65. public:
  66. static void setDir(const char *dir) {
  67. dbDir = dir;
  68. }
  69. static bool saveMsg(IcqMsg &msg);
  70. static bool loadMsg(uint32 uin, PtrList &msgList);
  71. static bool delMsg(uint32 uin);
  72. static bool delMsg(uint32 uin, int item);
  73. static bool saveContact(IcqContact &c);
  74. static bool loadContact(IcqContact &c);
  75. static bool loadContact(PtrList &contactList);
  76. static bool delContact(uint32 uin);
  77. static bool saveUser(IcqUser &user);
  78. static bool loadUser(IcqUser &user);
  79. static bool saveOptions(IcqOption &options);
  80. static bool loadOptions(IcqOption &options);
  81. static bool saveGroupInfo(DBSerialize &obj);
  82. static bool loadGroupInfo(DBSerialize &obj);
  83. static bool exportMsg(const char *pathName, uint32 uin);
  84. static bool importRecord(const char *pathName);
  85. static bool saveConfig(const char *fileName, DBSerialize &obj);
  86. static bool loadConfig(const char *fileName, DBSerialize &obj);
  87. static bool getMsgUinList(UinList &uinList);
  88. static void loadQuickReply(StrList &l);
  89. static void saveQuickReply(StrList &l);
  90. static void loadAutoReply(StrList &l);
  91. static void saveAutoReply(StrList &l);
  92. private:
  93. static DB *getDBFullPath(const char *pathName, bool dup = false);
  94. static DB *getDB(const char *fileName, bool dup = false) {
  95. return getDBFullPath((dbDir + fileName).c_str(), dup);
  96. }
  97. static bool saveBlock(const char *fileName, uint32 index, DBSerialize &obj, bool dup);
  98. static bool saveBlock(DB *db, uint32 index, DBSerialize &obj);
  99. static bool loadBlock(const char *fileName, uint32 index, DBSerialize &obj);
  100. static bool delIndex(const char *fileName, uint32 index);
  101. static void loadStrList(const char *file, StrList &l);
  102. static void saveStrList(const char *file, StrList &l);
  103. static string dbDir;
  104. };
  105. #endif