Fairport  v1.0.38
fairport/util/primitives.h
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00008 
00009 #ifndef FAIRPORT_UTIL_PRIMITIVES_H
00010 #define FAIRPORT_UTIL_PRIMITIVES_H
00011 
00012 #include <boost/config.hpp>
00013 #include <boost/cstdint.hpp>
00014 
00015 #include <string>
00016 
00017 //
00018 // Global compiler hacks
00019 //
00020 #ifdef BOOST_NO_STATIC_ASSERT
00021 #include <boost/static_assert.hpp>
00022 #define static_assert(x,y) BOOST_STATIC_ASSERT(x)
00023 #endif
00024 
00034 #ifndef FAIRPORT_VALIDATION_LEVEL_NONE
00035 #define FAIRPORT_VALIDATION_LEVEL_WEAK
00036 #endif
00037 
00038 #ifdef FAIRPORT_VALIDATION_LEVEL_FULL
00039 // full validation also implies weak validation
00040 #define FAIRPORT_VALIDATION_LEVEL_WEAK
00041 #endif
00042 
00043 // Many of the low-level data structures in Fairport rely on being laid out
00044 // in the fashion preferred by Visual C++.  For example, these structures
00045 // need to align ulonglong to the nearest 8 bytes.  Under GCC, we can force
00046 // this layout behavior on Mac and Linux systems by appending an
00047 // appropriate attribute declaration to the structure.  We're also tried
00048 // '#pragma ms_struct on', but it fails on at least some Linux systems.
00049 #ifdef __GNUC__
00050 #define FAIRPORT_MS_STRUCT __attribute__((ms_struct))
00051 #define FAIRPORT_PACK_2 __attribute__((packed, aligned(2)))
00052 #else
00053 #define FAIRPORT_MS_STRUCT
00054 #define FAIRPORT_PACK_2
00055 #endif
00056 
00057 namespace fairport
00058 {
00059 
00063 typedef boost::uint32_t uint;
00064 typedef boost::uint32_t ulong;
00065 typedef boost::int32_t slong;
00066 typedef boost::uint64_t ulonglong;
00067 typedef boost::int64_t slonglong;
00068 typedef boost::uint8_t byte;
00069 typedef boost::uint16_t ushort;
00072 
00073 static_assert(sizeof(byte) == 1, "fairport::byte unexpected size");
00074 static_assert(sizeof(ushort) == 2, "fairport::ushort unexpected size");
00075 static_assert(sizeof(uint) == 4, "fairport::uint unexpected size");
00076 static_assert(sizeof(ulonglong) == 8, "fairport::ulonglong unexpected size");
00078 
00082 typedef ulong node_id;
00083 typedef ulonglong block_id;
00084 typedef block_id page_id;
00085 
00086 typedef ulong heap_id;
00087 typedef ulong heapnode_id;
00088 
00089 typedef ushort prop_id;
00090 
00091 typedef ulong row_id;
00094 //
00095 // node id
00096 //
00097 
00101 enum nid_type
00102 {
00103     nid_type_none = 0x00,
00104     nid_type_internal = 0x01,
00105     nid_type_folder = 0x02,
00106     nid_type_search_folder = 0x03,
00107     nid_type_message = 0x04,
00108     nid_type_attachment = 0x05,
00109     nid_type_search_update_queue = 0x06,
00110     nid_type_search_criteria_object = 0x07,
00111     nid_type_associated_message = 0x08,
00112     nid_type_storage = 0x09,
00113     nid_type_contents_table_index = 0x0A,
00114     nid_type_receive_folder_table = 0x0B,
00115     nid_type_outgoing_queue_table = 0x0C,
00116     nid_type_hierarchy_table = 0x0D,
00117     nid_type_contents_table = 0x0E,
00118     nid_type_associated_contents_table = 0x0F,
00119     nid_type_search_contents_table = 0x10,
00120     nid_type_attachment_table = 0x11,
00121     nid_type_recipient_table = 0x12,
00122     nid_type_search_table_index = 0x13,
00123     nid_type_contents_smp = 0x14,
00124     nid_type_associated_contents_smp = 0x15,
00125     nid_type_change_history_table = 0x16,
00126     nid_type_tombstone_table = 0x17,
00127     nid_type_tombstone_date_table = 0x18,
00128     nid_type_lrep_dups_table = 0x19,
00129     nid_type_folder_path_tombstone_table = 0x1A,
00130     nid_type_ltp = 0x1F,
00131     nid_type_max = 0x20
00132 };
00133 
00137 const ulong nid_type_mask = 0x1FL;
00138 
00142 #define make_nid(nid_type,nid_index) (((nid_type)&nid_type_mask)|((nid_index) << 5))
00143 
00146 #define make_prv_pub_nid(nid_index) (make_nid(nid_type_folder, nid_index_prv_pub_base + (nid_index)))
00147 
00151 enum predefined_nid
00152 {
00153     nid_message_store = make_nid(nid_type_internal, 0x1),   
00154     nid_name_id_map = make_nid(nid_type_internal, 0x3),     
00155     nid_normal_folder_template = make_nid(nid_type_folder, 0x6),
00156     nid_search_folder_template = make_nid(nid_type_search_folder, 0x7),
00157     nid_root_folder = make_nid(nid_type_folder, 0x9),       
00158     nid_search_management_queue = make_nid(nid_type_internal, 0xF),
00159     nid_search_activity_list = make_nid(nid_type_internal, 0x10),
00160     nid_search_domain_alternative = make_nid(nid_type_internal, 0x12),
00161     nid_search_domain_object = make_nid(nid_type_internal, 0x13),
00162     nid_search_gatherer_queue = make_nid(nid_type_internal, 0x14),
00163     nid_search_gatherer_descriptor = make_nid(nid_type_internal, 0x15),
00164     nid_table_rebuild_queue = make_nid(nid_type_internal, 0x17),
00165     nid_junk_mail_pihsl = make_nid(nid_type_internal, 0x18),
00166     nid_search_gatherer_folder_queue = make_nid(nid_type_internal, 0x19),
00167     nid_tc_sub_props = make_nid(nid_type_internal, 0x27),
00168     nid_index_template = 0x30,
00169     nid_hierarchy_table_template = make_nid(nid_type_hierarchy_table, nid_index_template),
00170     nid_contents_table_template = make_nid(nid_type_contents_table, nid_index_template),
00171     nid_associated_contents_table_template = make_nid(nid_type_associated_contents_table, nid_index_template),
00172     nid_search_contents_table_template = make_nid(nid_type_search_contents_table, nid_index_template),
00173     nid_smp_template = make_nid(nid_type_contents_smp, nid_index_template),
00174     nid_tombstone_table_template = make_nid(nid_type_tombstone_table, nid_index_template),
00175     nid_lrep_dups_table_template = make_nid(nid_type_lrep_dups_table, nid_index_template),
00176     nid_receive_folders = make_nid(nid_type_receive_folder_table, 0x31),
00177     nid_outgoing_queue = make_nid(nid_type_outgoing_queue_table, 0x32),
00178     nid_attachment_table = make_nid(nid_type_attachment_table, 0x33),
00179     nid_recipient_table = make_nid(nid_type_recipient_table, 0x34),
00180     nid_change_history_table = make_nid(nid_type_change_history_table, 0x35),
00181     nid_tombstone_table = make_nid(nid_type_tombstone_table, 0x36),
00182     nid_tombstone_date_table = make_nid(nid_type_tombstone_date_table, 0x37),
00183     nid_all_message_search_folder = make_nid(nid_type_search_folder, 0x39), 
00184     nid_all_message_search_contents = make_nid(nid_type_search_contents_table, 0x39),
00185     nid_lrep_gmp = make_nid(nid_type_internal, 0x40),
00186     nid_lrep_folders_smp = make_nid(nid_type_internal, 0x41),
00187     nid_lrep_folders_table = make_nid(nid_type_internal, 0x42),
00188     nid_folder_path_tombstone_table = make_nid(nid_type_internal, 0x43),
00189     nid_hst_hmp = make_nid(nid_type_internal, 0x60),
00190     nid_index_prv_pub_base = 0x100,
00191     nid_pub_root_folder = make_prv_pub_nid(0),
00192     nid_prv_root_folder = make_prv_pub_nid(5),
00193     nid_criterr_notification = make_nid(nid_type_internal, 0x3FD),
00194     nid_object_notification = make_nid(nid_type_internal, 0x3FE),
00195     nid_newemail_notification = make_nid(nid_type_internal, 0x3FF),
00196     nid_extended_notification = make_nid(nid_type_internal, 0x400),
00197     nid_indexing_notification = make_nid(nid_type_internal, 0x401)
00198 };
00199 
00205 inline nid_type get_nid_type(node_id id)
00206     { return (nid_type)(id & nid_type_mask); }
00207 
00213 inline ulong get_nid_index(node_id id)
00214     { return id >> 5; }
00215 
00216 //
00217 // heap id
00218 //
00219 
00225 inline ulong get_heap_page(heap_id id)
00226     { return (id >> 16); } 
00227 
00233 inline ulong get_heap_index(heap_id id)
00234     { return (((id >> 5) - 1) & 0x7FF); }
00235 
00241 inline heap_id make_heap_id(ulong page, ulong index)
00242     { return (heap_id)((page << 16) | ((index + 1) << 5)); }
00243 
00244 //
00245 // heapnode id
00246 //
00247 
00254 inline bool is_heap_id(heapnode_id id)
00255     { return (get_nid_type(id) == nid_type_none); }
00256 
00263 inline bool is_subnode_id(heapnode_id id)
00264     { return (get_nid_type(id) != nid_type_none); }
00265 
00266 //
00267 // properties
00268 //
00269 
00273 enum prop_type
00274 {
00275     prop_type_unspecified = 0,
00276     prop_type_null = 1,
00277     prop_type_short = 2,
00278     prop_type_mv_short = 4098,
00279     prop_type_long = 3,
00280     prop_type_mv_long = 4099,
00281     prop_type_float = 4,
00282     prop_type_mv_float = 4100,
00283     prop_type_double = 5,
00284     prop_type_mv_double = 4101,
00285     prop_type_currency = 6,
00286     prop_type_mv_currency = 4102,
00287     prop_type_apptime = 7,          
00288     prop_type_mv_apptime = 4103,
00289     prop_type_error = 10,
00290     prop_type_boolean = 11,
00291     prop_type_object = 13,
00292     prop_type_longlong = 20,
00293     prop_type_mv_longlong = 4116,
00294     prop_type_string = 30,
00295     prop_type_mv_string = 4126,
00296     prop_type_wstring = 31,
00297     prop_type_mv_wstring = 4127,
00298     prop_type_systime = 64,         
00299     prop_type_mv_systime = 4160,
00300     prop_type_guid = 72,
00301     prop_type_mv_guid = 4168,
00302     prop_type_binary = 258,
00303     prop_type_mv_binary = 4354
00304 };
00305 
00306 //
00307 // mapi recipient type
00308 //
00309 
00312 enum recipient_type
00313 {
00314     mapi_to = 1,
00315     mapi_cc = 2,
00316     mapi_bcc = 3
00317 };
00318 
00319 // 
00320 // message specific values
00321 //
00322 
00326 const byte message_subject_prefix_lead_byte = 0x01;
00327 
00328 //
00329 // Win32 GUID
00330 //
00331 
00334 struct guid
00335 {
00336     ulong data1;
00337     ushort data2;
00338     ushort data3;
00339     byte data4[8];
00340 } FAIRPORT_MS_STRUCT;
00342 static_assert(sizeof(guid) == 16, "guid incorrect size");
00344 
00347 const guid ps_none = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
00348 
00352 const guid ps_mapi = { 0x20328, 0, 0, { 0xc0, 0, 0, 0, 0, 0, 0, 0x46 } };
00353 
00357 const guid ps_public_strings = { 0x20329, 0, 0, { 0xc0, 0, 0, 0, 0, 0, 0, 0x46 } };
00358 
00362 const guid ps_task = { 0x62003, 0, 0, { 0xc0, 0, 0, 0, 0, 0, 0, 0x46 } };
00363 
00367 const guid ps_contact = { 0x62004, 0, 0, { 0xc0, 0, 0, 0, 0, 0, 0, 0x46 } };
00368 
00371 const std::wstring task_class = L"IPM.Task";
00372 
00375 const std::wstring contact_class = L"IPM.Contact";
00376 
00377 } // end fairport namespace
00378 #endif