ProtocolDefines.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #ifndef Threema_ProtocolDefines_h
  21. #define Threema_ProtocolDefines_h
  22. #define kCookieLen 16
  23. #define kIdentityLen 8
  24. #define kLoginAckReservedLen 16
  25. #define kMessageIdLen 8
  26. #define kNonceLen 24
  27. #define kClientVersionLen 32
  28. #define kPushFromNameLen 32
  29. #define kBlobIdLen 16
  30. #define kBlobKeyLen 32
  31. #define kGroupIdLen 8
  32. #define kBallotIdLen 8
  33. #define kConnectTimeout 15
  34. #define kReadTimeout 20
  35. #define kWriteTimeout 20
  36. #define kDisconnectTimeout 3
  37. #define kReconnectBaseInterval 2
  38. #define kReconnectMaxInterval 10
  39. #define kKeepAliveInterval 180
  40. #define kErrorDisplayInterval 30
  41. #define kBlobLoadTimeout 30
  42. #define kBlobUploadTimeout 120
  43. #define kMaxMessageLen 3500 // text message size limit (bytes, not characters!); must comfortably fit in maximum packet length (including 360 bytes overhead and padding)
  44. #define kMaxPktLen 8192
  45. #define kMinMessagePaddedLen 32
  46. //#define kMaxFileSize 50*1024*1024
  47. static NSInteger const kMaxFileSize = 50*1024*1024;
  48. static NSInteger const kWebClientAvatarSize = 48;
  49. static Float32 const kWebClientAvatarQuality = 0.6;
  50. static NSInteger const kWebClientAvatarHiResSize = 512;
  51. static Float32 const kWebClientAvatarHiResQuality = 0.75;
  52. static NSInteger const kWebClientMediaPreviewSize = 50;
  53. static NSInteger const kWebClientMediaThumbnailSize = 350;
  54. static Float32 const kWebClientMediaQuality = 0.6;
  55. #define kMaxVideoDurationLowMinutes 15
  56. #define kMaxVideoDurationHighMinutes 3
  57. #define kMaxVideoSizeLow 480
  58. #define kMaxVideoSizeHigh 848
  59. #define kVideoBitrateLow 384000
  60. #define kVideoBitrateMedium 1500000
  61. #define kVideoBitrateHigh 2000000
  62. #define kAudioBitrateLow 32000
  63. #define kAudioBitrateMedium 64000
  64. #define kAudioBitrateHigh 128000
  65. #define kAudioChannelsLow 1
  66. #define kAudioChannelsHigh 2
  67. #define kClientTempKeyMaxAge 7*86400
  68. #define kGroupSyncRequestInterval 1*86400
  69. #define MSGTYPE_TEXT 0x01
  70. #define MSGTYPE_IMAGE 0x02
  71. #define MSGTYPE_LOCATION 0x10
  72. #define MSGTYPE_VIDEO 0x13
  73. #define MSGTYPE_AUDIO 0x14
  74. #define MSGTYPE_BALLOT_CREATE 0x15
  75. #define MSGTYPE_BALLOT_VOTE 0x16
  76. #define MSGTYPE_FILE 0x17
  77. #define MSGTYPE_CONTACT_SET_PHOTO 0x18
  78. #define MSGTYPE_CONTACT_DELETE_PHOTO 0x19
  79. #define MSGTYPE_CONTACT_REQUEST_PHOTO 0x1a
  80. #define MSGTYPE_GROUP_TEXT 0x41
  81. #define MSGTYPE_GROUP_LOCATION 0x42
  82. #define MSGTYPE_GROUP_IMAGE 0x43
  83. #define MSGTYPE_GROUP_VIDEO 0x44
  84. #define MSGTYPE_GROUP_AUDIO 0x45
  85. #define MSGTYPE_GROUP_FILE 0x46
  86. #define MSGTYPE_GROUP_CREATE 0x4a
  87. #define MSGTYPE_GROUP_RENAME 0x4b
  88. #define MSGTYPE_GROUP_LEAVE 0x4c
  89. #define MSGTYPE_GROUP_SET_PHOTO 0x50
  90. #define MSGTYPE_GROUP_REQUEST_SYNC 0x51
  91. #define MSGTYPE_GROUP_BALLOT_CREATE 0x52
  92. #define MSGTYPE_GROUP_BALLOT_VOTE 0x53
  93. #define MSGTYPE_GROUP_DELETE_PHOTO 0x54
  94. #define MSGTYPE_VOIP_CALL_OFFER 0x60
  95. #define MSGTYPE_VOIP_CALL_ANSWER 0x61
  96. #define MSGTYPE_VOIP_CALL_ICECANDIDATE 0x62
  97. #define MSGTYPE_VOIP_CALL_HANGUP 0x63
  98. #define MSGTYPE_VOIP_CALL_RINGING 0x64
  99. #define MSGTYPE_DELIVERY_RECEIPT 0x80
  100. #define MSGTYPE_TYPING_INDICATOR 0x90
  101. #define MESSAGE_FLAG_PUSH 0x01
  102. #define MESSAGE_FLAG_IMMEDIATE 0x02
  103. #define MESSAGE_FLAG_NOACK 0x04
  104. #define MESSAGE_FLAG_GROUP 0x10
  105. #define MESSAGE_FLAG_VOIP 0x20
  106. #define MESSAGE_FLAG_NO_DELIVERY_RECEIPT 0x80
  107. #define DELIVERYRECEIPT_MSGRECEIVED 0x01
  108. #define DELIVERYRECEIPT_MSGREAD 0x02
  109. #define DELIVERYRECEIPT_MSGUSERACK 0x03
  110. #define DELIVERYRECEIPT_MSGUSERDECLINE 0x04
  111. #define PLTYPE_ECHO_REQUEST 0x00
  112. #define PLTYPE_ECHO_REPLY 0x80
  113. #define PLTYPE_OUTGOING_MESSAGE 0x01
  114. #define PLTYPE_OUTGOING_MESSAGE_ACK 0x81
  115. #define PLTYPE_INCOMING_MESSAGE 0x02
  116. #define PLTYPE_INCOMING_MESSAGE_ACK 0x82
  117. #define PLTYPE_PUSH_NOTIFICATION_TOKEN 0x20
  118. #define PLTYPE_PUSH_ALLOWED_IDENTITIES 0x21
  119. #define PLTYPE_PUSH_SOUND 0x22
  120. #define PLTYPE_PUSH_GROUP_SOUND 0x23
  121. #define PLTYPE_VOIP_PUSH_NOTIFICATION_TOKEN 0x24
  122. #define PLTYPE_PUSH_OVERRIDE_TIMEOUT 0x31
  123. #define PLTYPE_QUEUE_SEND_COMPLETE 0xd0
  124. #define PLTYPE_ERROR 0xe0
  125. #define PLTYPE_ALERT 0xe1
  126. #define PUSHTOKEN_TYPE_NONE 0x00
  127. #define PUSHTOKEN_TYPE_APPLE_PROD 0x01
  128. #define PUSHTOKEN_TYPE_APPLE_SANDBOX 0x02
  129. #define PUSHTOKEN_TYPE_APPLE_PROD_MC 0x05
  130. #define PUSHTOKEN_TYPE_APPLE_SANDBOX_MC 0x06
  131. #define kWithoutVoIPFeatureMask 0x0f
  132. #define kCurrentFeatureMask 0x3f
  133. #define FEATURE_MASK_AUDIO_MSG 0x01
  134. #define FEATURE_MASK_GROUP_CHAT 0x02
  135. #define FEATURE_MASK_BALLOT 0x04
  136. #define FEATURE_MASK_FILE_TRANSFER 0x08
  137. #define FEATURE_MASK_VOIP 0x10
  138. #define FEATURE_MASK_VOIP_VIDEO 0x20
  139. #define PUSHFILTER_TYPE_NONE 0
  140. #define PUSHFILTER_TYPE_ALLOW_LISTED 1
  141. #define PUSHFILTER_TYPE_BLOCK_LISTED 2
  142. #define kGeneralErrorCode 100
  143. #define kErrorCodeUserCancelled 300
  144. #define kBlockUnknownContactErrorCode 666
  145. #define kBadMessageErrorCode 667
  146. #define kUnknownMessageTypeErrorCode 668
  147. #define kMessageProcessingErrorCode 669
  148. #define kJPEGCompressionQuality 1.0
  149. static unsigned char kNonce_1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01};
  150. static unsigned char kNonce_2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02};
  151. #pragma pack(push, 1)
  152. #pragma pack(1)
  153. struct plError {
  154. uint8_t reconnect_allowed;
  155. char err_message[];
  156. };
  157. struct plMessage {
  158. char from_identity[kIdentityLen];
  159. char to_identity[kIdentityLen];
  160. char message_id[kMessageIdLen];
  161. uint32_t date;
  162. uint8_t flags;
  163. uint8_t reserved[3];
  164. char push_from_name[kPushFromNameLen];
  165. char nonce[kNonceLen];
  166. char box[]; /* Box */
  167. };
  168. struct plMessageAck {
  169. char from_identity[kIdentityLen];
  170. char message_id[kMessageIdLen];
  171. };
  172. #pragma pack(pop)
  173. #endif