dlserver.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. {$MACRO ON}
  2. (******************************************************************************
  3. *
  4. * Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
  5. * All rights reserved.
  6. *
  7. * File: DLServer.h
  8. *
  9. * Release: Palm OS SDK 4.0 (63220)
  10. *
  11. * Description:
  12. * Desktop Link Protocol(DLP) Server implementation definitions.
  13. *
  14. * History:
  15. * vmk 7/12/95 Created by Vitaly Marty Kruglikov
  16. * vmk 7/12/96 Converted to HTAL architecture
  17. * jmp 12/23/99 Fix <> vs. "" problem.
  18. *
  19. *****************************************************************************)
  20. unit dlserver;
  21. interface
  22. uses palmos, coretraps, errorbase, datamgr;
  23. (************************************************************
  24. * DLK result codes
  25. * (dlkErrorClass is defined in SystemMgr.h)
  26. *************************************************************)
  27. const
  28. dlkErrParam = dlkErrorClass or 1; // invalid parameter
  29. dlkErrMemory = dlkErrorClass or 2; // memory allocation error
  30. dlkErrNoSession = dlkErrorClass or 3; // could not establish a session
  31. dlkErrSizeErr = dlkErrorClass or 4; // reply length was too big
  32. dlkErrLostConnection = dlkErrorClass or 5; // lost connection
  33. dlkErrInterrupted = dlkErrorClass or 6; // sync was interrupted (see sync state)
  34. dlkErrUserCan = dlkErrorClass or 7; // cancelled by user
  35. dlkErrIncompatibleProducts = dlkErrorClass or 8; // incompatible desktop version
  36. dlkErrNPOD = dlkErrorClass or 9; // New Password, Old Desktop
  37. (********************************************************************
  38. * Desktop Link system preferences resource for user info
  39. * id = sysResIDDlkUserInfo, defined in SystemResources.h
  40. ********************************************************************)
  41. const
  42. dlkMaxUserNameLength = 40;
  43. dlkUserNameBufSize = dlkMaxUserNameLength + 1;
  44. const
  45. dlkMaxLogSize = 20 * 1024;
  46. // dlkMaxLogSize = 2 * 1024;
  47. type
  48. DlkSyncStateType = Enum;
  49. const
  50. dlkSyncStateNeverSynced = 0; // never synced
  51. dlkSyncStateInProgress = Succ(dlkSyncStateNeverSynced); // sync is in progress
  52. dlkSyncStateLostConnection = Succ(dlkSyncStateInProgress); // connection lost during sync
  53. dlkSyncStateLocalCan = Succ(dlkSyncStateLostConnection); // cancelled by local user on handheld
  54. dlkSyncStateRemoteCan = Succ(dlkSyncStateLocalCan); // cancelled by user from desktop
  55. dlkSyncStateLowMemoryOnTD = Succ(dlkSyncStateRemoteCan); // sync ended due to low memory on handheld
  56. dlkSyncStateAborted = Succ(dlkSyncStateLowMemoryOnTD); // sync was aborted for some other reason
  57. dlkSyncStateCompleted = Succ(dlkSyncStateAborted); // sync completed normally
  58. // Added in PalmOS v3.0:
  59. dlkSyncStateIncompatibleProducts = Succ(dlkSyncStateCompleted); // sync ended because desktop HotSync product
  60. // is incompatible with this version
  61. // of the handheld HotSync
  62. dlkSyncStateNPOD = Succ(dlkSyncStateIncompatibleProducts); // New Password, Old Desktop
  63. const
  64. dlkUserInfoPrefVersion = $0102; // current user info pref version: 1.2
  65. type
  66. DlkUserInfoHdrType = record
  67. version: UInt16; // pref version number
  68. userID: UInt32; // user id
  69. viewerID: UInt32; // id assigned to viewer by the desktop
  70. lastSyncPC: UInt32; // last sync PC id
  71. succSyncDate: UInt32; // last successful sync date
  72. lastSyncDate: UInt32; // last sync date
  73. lastSyncState: DlkSyncStateType; // last sync status
  74. reserved1: UInt8; // Explicitly account for 16-bit alignment padding
  75. lanSyncEnabled: UInt16; // if non-zero, LAN Sync is enabled
  76. hsTcpPortNum: UInt32; // TCP/IP port number of Desktop HotSync
  77. dwReserved1: UInt32; // RESERVED -- set to NULL!
  78. dwReserved2: UInt32; // RESERVED -- set to NULL!
  79. userNameLen: UInt8; // length of name field(including null)
  80. reserved2: UInt8; // Explicitly account for 16-bit alignment padding
  81. syncLogLen: UInt16; // length of sync log(including null)
  82. end;
  83. DlkUserInfoType = record
  84. header: DlkUserInfoHdrType; // fixed size header
  85. nameAndLog: array [0..1] of Char; // user name, followed by sync log;
  86. // both null-terminated(for debugging)
  87. end;
  88. DlkUserInfoPtr = ^DlkUserInfoType; // user info pointer
  89. (********************************************************************
  90. * Desktop Link system preferences resource for the Conduit Filter Table
  91. * id = sysResIDDlkCondFilterTab, defined in SystemResources.h
  92. ********************************************************************)
  93. //
  94. // Table for specifying conduits to "filter out" during HotSync
  95. //
  96. // This table consists of DlkCondFilterTableHdrType header followed by a
  97. // variable number of DlkCondFilterEntryType entries
  98. type
  99. DlkCondFilterTableHdrType = record
  100. entryCount: UInt16;
  101. end;
  102. DlkCondFilterTableHdrPtr = ^DlkCondFilterTableHdrType;
  103. DlkCondFilterEntryType = record
  104. creator: UInt32;
  105. type_: UInt32;
  106. end;
  107. DlkCondFilterEntryPtr = ^DlkCondFilterEntryType;
  108. DlkCondFilterTableType = record
  109. hdr: DlkCondFilterTableHdrType; // table header
  110. entry: array [0..0] of DlkCondFilterEntryType; // variable number of entries
  111. end;
  112. DlkCondFilterTablePtr = ^DlkCondFilterTableType;
  113. (********************************************************************
  114. * DLK Session Structures
  115. ********************************************************************)
  116. // DesktopLink event notification callback. If non-zero is returned,
  117. // sync will be cancelled as soon as a safe point is reached.
  118. type
  119. DlkEventType = Enum;
  120. const
  121. dlkEventOpeningConduit = 1; // conduit is being opened -- paramP
  122. // is null;
  123. dlkEventDatabaseOpened = Succ(dlkEventOpeningConduit); // client has opened a database -- paramP
  124. // points to DlkEventDatabaseOpenedType;
  125. dlkEventCleaningUp = Succ(dlkEventDatabaseOpened); // last stage of sync -- cleaning up (notifying apps, etc) --
  126. // paramP is null
  127. dlkEventSystemResetRequested = Succ(dlkEventCleaningUp); // system reset was requested by the desktop client
  128. // (the normal action is to delay the reset until
  129. // end of sync) -- paramP is null
  130. // Prototype for the event notification callback
  131. type
  132. DlkEventProc = function(eventRef: UInt32; dlkEvent: DlkEventType; paramP: Pointer): Int16;
  133. // Parameter structure for dlkEventDatabaseOpened
  134. // Added new fields for Pilot v2.0 vmk 12/24/96
  135. type
  136. DlkEventDatabaseOpenedType = record
  137. dbR: DmOpenRef; // open database ref (v2.0)
  138. dbNameP: PChar; // database name
  139. dbType: UInt32; // databse type (v2.0)
  140. dbCreator: UInt32; // database creator
  141. end;
  142. // Prototype for the "user cancel" check callback function
  143. type
  144. DlkUserCanProc = function(canRef: UInt32): Int16;
  145. //
  146. // List of modified database creators maintained by DLP Server
  147. //
  148. DlkDBCreatorList = record
  149. count: UInt16; // number of entries in the list
  150. listH: MemHandle; // chunk MemHandle of the creators list
  151. end;
  152. //
  153. // Desktop Link Server state flags
  154. //
  155. const
  156. dlkStateFlagVerExchanged = $8000;
  157. dlkStateFlagSyncDateSet = $4000;
  158. //
  159. // DLP Server session information
  160. //
  161. type
  162. DlkServerSessionType = record
  163. htalLibRefNum: UInt16; // HTAL library reference number - the library has a live connection
  164. maxHtalXferSize: UInt32; // Maximum transfer block size
  165. // Information supplied by user
  166. eventProcP: DlkEventProc; // ptr to DesktopLink event notification proc
  167. eventRef: UInt32; // user reference value for event proc
  168. canProcP: DlkUserCanProc; // ptr to user-cancel function
  169. canRef: UInt32; // parameter for canProcP()
  170. condFilterH: MemHandle; // MemHandle of conduit filter table(DlkCondFilterTableHdrPtr) or 0 for none
  171. // Current database information
  172. dlkDBID: UInt8; // Desktop Link database MemHandle of the open database
  173. reserved1: UInt8;
  174. dbR: DmOpenRef; // TouchDown database access pointer -- if null, no current db
  175. cardNo: UInt16; // memory module number
  176. dbCreator: UInt32; // creator id
  177. dbName: array [0..dmDBNameLength-1] of Char; // DB name
  178. dbOpenMode: UInt16; // database open mode
  179. created: Boolean; // true if the current db was created
  180. isResDB: Boolean; // set to true if resource database
  181. ramBased: Boolean; // true if the db is in RAM storage
  182. readOnly: Boolean; // true if the db is read-only
  183. dbLocalID: LocalID; // TouchDown LocalID of the database
  184. initialModNum: UInt32; // initial DB modification number
  185. curRecIndex: UInt32; // current record index for enumeration functions
  186. // (0=beginning)
  187. // List of modified database creators maintained by DLP Server
  188. creatorList: DlkDBCreatorList;
  189. // Session status information
  190. syncState: DlkSyncStateType; // current sync state;
  191. complete: Boolean; // set to true when completion request
  192. // has been received
  193. conduitOpened: Boolean; // set to true after the first coduit
  194. // is opened by remote
  195. logCleared: Boolean; // set to true after sync log has been
  196. // cleared during the current session;
  197. // The log will be cleared before any new entries are added or at
  198. // the end of sync in case no new entries were added.
  199. // (we do not clear the log at the beginning of sync in case the
  200. // user cancels during the "identifying user" phase; in this
  201. // event, the spec calls for preserving the original log)
  202. resetPending: Boolean; // set to true if system reset is pending;
  203. // the reset will be carried out at end
  204. // of sync
  205. // Current request information
  206. gotCommand: Boolean; // set to true when got a request
  207. cmdTID: UInt8; // current transaction ID
  208. reserved2: UInt8;
  209. cmdLen: UInt16; // size of data in request buffer
  210. cmdP: Pointer; // pointer to command
  211. cmdH: MemHandle; // MemHandle of command buffer
  212. // Fields added in PalmOS v3.0
  213. wStateFlags: UInt16; // bitfield of dlkStateFlag... bits
  214. dbSearchState: DmSearchStateType; // database search state for iterative
  215. // searches using DmGetNextDatabaseByTypeCreator
  216. // Fields added in PalmOS v4.0
  217. openFileRefsH: MemHandle ; // Table of open file refs
  218. numOpenFileRefs: Int16; // Current size of the file ref table.
  219. pre40Desktop: Boolean; // are we using a pre-4.0 desktop (DLP v1.2)
  220. passwordSet: Boolean; // is a password set?
  221. end;
  222. DlkServerSessionPtr = ^DlkServerSessionType;
  223. (********************************************************************
  224. * DLK Function Parameter Structures
  225. ********************************************************************)
  226. //
  227. // Parameter passed to DlkControl()
  228. //
  229. type
  230. DlkCtlEnum = Enum;
  231. const
  232. dlkCtlFirst = 0; // reserve 0
  233. //
  234. // Pilot v2.0 control codes:
  235. //
  236. dlkCtlGetPCHostName = Succ(dlkCtlFirst); // param1P = ptr to text buffer; (can be null if *(UInt16 *)param2P is 0)
  237. // param2P = ptr to buffer size(UInt16);
  238. // returns actual length, including null, in *(UInt16 *)param2P which may be bigger than # of bytes copied.
  239. dlkCtlSetPCHostName = Succ(dlkCtlGetPCHostName); // param1P = ptr to host name(zero-terminated) or NULL if *param2 is 0
  240. // param2P = ptr to length(UInt16), including NULL (if length is 0, the current name is deleted)
  241. dlkCtlGetCondFilterTable = Succ(dlkCtlSetPCHostName); // param1P = ptr to destination buffer for filter table, or NULL if *param2 is 0
  242. // param2P = on entry, ptr to size of buffer(UInt16) (the size may be 0)
  243. // on return, size, in bytes, of the actual filter table
  244. dlkCtlSetCondFilterTable = Succ(dlkCtlGetCondFilterTable); // param1P = ptr to to conduit filter table, or NULL if *param2 is 0
  245. // param2P = ptr to size of filter table(UInt16) (if size is 0, the current table will be deleted)
  246. dlkCtlGetLANSync = Succ(dlkCtlSetCondFilterTable); // param1P = ptr to store for the LANSync setting(UInt16): 0 = off, otherwise on
  247. // param2P = not used, set to NULL
  248. dlkCtlSetLANSync = Succ(dlkCtlGetLANSync); // param1P = ptr to the LANSync setting(UInt16): 0 = off, otherwise on
  249. // param2P = not used, set to NULL
  250. dlkCtlGetHSTCPPort = Succ(dlkCtlSetLANSync); // param1P = ptr to store for the Desktop HotSync TCP/IP port number(UInt32) -- zero if not set
  251. // param2P = not used, set to NULL
  252. dlkCtlSetHSTCPPort = Succ(dlkCtlGetHSTCPPort); // param1P = ptr to the Desktop HotSync TCP/IP port number(UInt32)
  253. // param2P = not used, set to NULL
  254. dlkCtlSendCallAppReply = Succ(dlkCtlSetHSTCPPort); // param1P = ptr to DlkCallAppReplyParamType structure
  255. // param2P = not used, set to NULL
  256. //
  257. // RETURNS: send error code; use this error code
  258. // as return value from the action code handler
  259. dlkCtlGetPCHostAddr = Succ(dlkCtlSendCallAppReply); // param1P = ptr to text buffer; (can be null if *(UInt16 *)param2P is 0)
  260. // param2P = ptr to buffer size(UInt16);
  261. // returns actual length, including null, in *(UInt16 *)param2P which may be bigger than # of bytes copied.
  262. dlkCtlSetPCHostAddr = Succ(dlkCtlGetPCHostAddr); // param1P = ptr to host address string(zero-terminated) or NULL if *param2 is 0
  263. // param2P = ptr to length(UInt16), including NULL (if length is 0, the current name is deleted)
  264. dlkCtlGetPCHostMask = Succ(dlkCtlSetPCHostAddr); // param1P = ptr to text buffer; (can be null if *(UInt16 *)param2P is 0)
  265. // param2P = ptr to buffer size(UInt16);
  266. // returns actual length, including null, in *(UInt16 *)param2P which may be bigger than # of bytes copied.
  267. dlkCtlSetPCHostMask = Succ(dlkCtlGetPCHostMask); // param1P = ptr to subnet mask string(zero-terminated) or NULL if *param2 is 0
  268. // param2P = ptr to length(UInt16), including NULL (if length is 0, the current name is deleted)
  269. dlkCtlLAST = Succ(dlkCtlSetPCHostMask); // *KEEP THIS ENTRY LAST*
  270. //
  271. // Parameter passed to DlkStartServer()
  272. //
  273. type
  274. DlkServerParamType = record
  275. htalLibRefNum: UInt16; // HTAL library reference number - the library has a live connection
  276. eventProcP: DlkEventProc; // ptr to DesktopLink event notification proc
  277. eventRef: UInt32; // user reference value for event proc
  278. reserved1: UInt32; // reserved - set to NULL
  279. reserved2: UInt32; // reserved - set to NULL
  280. condFilterH: MemHandle; // MemHandle of conduit filter table(DlkCondFilterTableHdrPtr) or 0 for none
  281. end;
  282. DlkServerParamPtr = ^DlkServerParamType;
  283. //
  284. // Parameter passed with DlkControl()'s dlkCtlSendCallAppReply code
  285. //
  286. type
  287. DlkCallAppReplyParamType = record
  288. pbSize: UInt16; // size of this parameter block (set to sizeof(DlkCallAppReplyParamType))
  289. dwResultCode: UInt32; // result code to be returned to remote caller
  290. {const} resultP: Pointer; // ptr to result data
  291. dwResultSize: UInt32; // size of reply data in number of bytes
  292. dlRefP: Pointer; // DesktopLink reference pointer from
  293. // SysAppLaunchCmdHandleSyncCallAppType
  294. dwReserved1: UInt32; // RESERVED -- set to null!!!
  295. end;
  296. (********************************************************************
  297. * DesktopLink Server Routines
  298. ********************************************************************)
  299. //
  300. // SERVER API
  301. //
  302. // * RETURNED: 0 if session ended successfully; otherwise: dlkErrParam,
  303. // * dlkErrNoSession, dlkErrLostConnection, dlkErrMemory,
  304. // * dlkErrUserCan
  305. function DlkStartServer(paramP: DlkServerParamPtr): Err; syscall sysTrapDlkStartServer;
  306. function DlkGetSyncInfo(var succSyncDateP, lastSyncDateP: UInt32;
  307. var syncStateP: DlkSyncStateType; nameBufP, logBufP: PChar;
  308. var logLenP: Int32): Err; syscall sysTrapDlkGetSyncInfo;
  309. procedure DlkSetLogEntry(const textP: PChar; textLen: Int16; append: Boolean); syscall sysTrapDlkSetLogEntry;
  310. // Dispatch a DesktopLink request (exposed for patching)
  311. function DlkDispatchRequest(sessP: DlkServerSessionPtr): Err; syscall sysTrapDlkDispatchRequest;
  312. function DlkControl(op: DlkCtlEnum; param1P, param2P: Pointer): Err; syscall sysTrapDlkControl;
  313. (********************************************************************
  314. * DLK Macros
  315. ********************************************************************)
  316. implementation
  317. end.