pastehub 0.2.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,122 @@
1
+ #
2
+ # syncentry.rb - PasteHub's data handing of single clipboard entry.
3
+ #
4
+ # Copyright (c) 2014-2014 Kiyoka Nishiyama <kiyoka@sumibi.org>
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions
8
+ # are met:
9
+ #
10
+ # 1. Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ #
13
+ # 2. Redistributions in binary form must reproduce the above copyright
14
+ # notice, this list of conditions and the following disclaimer in the
15
+ # documentation and/or other materials provided with the distribution.
16
+ #
17
+ # 3. Neither the name of the authors nor the names of its contributors
18
+ # may be used to endorse or promote products derived from this
19
+ # software without specific prior written permission.
20
+ #
21
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27
+ # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ #
33
+ #
34
+ require 'base64'
35
+ require 'json'
36
+
37
+ module PasteHub
38
+
39
+ class EntryBase
40
+ def initialize( hostname )
41
+ config = PasteHub::Config.instance
42
+ @hostname = hostname
43
+ @filepath = config.localSyncPath + @hostname + ".dat"
44
+ end
45
+
46
+ def encode_body( bin )
47
+ return Base64.strict_encode64( bin ).chomp
48
+ end
49
+
50
+ def decode_body( str )
51
+ return Base64.decode64( str )
52
+ end
53
+
54
+ def gen_header( create_date, bin, encoded )
55
+ h = Hash.new
56
+ h[ :create_date ] = create_date
57
+ h[ :create_unixtime ] = create_date.to_i
58
+ h[ :hostname ] = @hostname
59
+ h[ :bodySize ] = bin.size()
60
+ h[ :encodedBodySize ] = encoded.size()
61
+ return JSON.dump( h )
62
+ end
63
+
64
+ end
65
+
66
+ class Entry < EntryBase
67
+ def initialize( hostname )
68
+ super( hostname )
69
+ end
70
+
71
+ # save as file
72
+ def save( bin )
73
+ create_date = Time.now()
74
+ encoded = encode_body( bin )
75
+ json_str = gen_header( create_date, bin, encoded )
76
+ open( @filepath, "w" ) { |f|
77
+ f.puts json_str
78
+ f.puts encoded
79
+ }
80
+ true
81
+ end
82
+
83
+ # check the file saved completely
84
+ def can_load?()
85
+ if not File.exist?( @filepath )
86
+ false
87
+ else
88
+ json = nil
89
+ open( @filepath, "r" ) {|f|
90
+ firstline = f.readline.chomp
91
+ begin
92
+ json = JSON.parse( firstline )
93
+ rescue JSON::JSONError
94
+ return false
95
+ end
96
+ # p "json[encodedBodySize]", json[ 'encodedBodySize' ]
97
+ if not json[ 'encodedBodySize' ]
98
+ return false
99
+ end
100
+
101
+ secondline = f.readline.chomp
102
+ # p "secondline", secondline
103
+ # p "secondline.size()", secondline.size()
104
+ if json[ 'encodedBodySize' ] != secondline.size()
105
+ return false # body is incomplete
106
+ end
107
+ }
108
+ return true
109
+ end
110
+ end
111
+
112
+ # load from file
113
+ def load
114
+ open( @filepath, "r" ) { |f|
115
+ firstline = f.readline.chomp
116
+ h = JSON.parse( firstline )
117
+ secondline = f.readline.chomp
118
+ return [h, decode_body( secondline ) ]
119
+ }
120
+ end
121
+ end
122
+ end
metadata CHANGED
@@ -1,155 +1,155 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pastehub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kiyoka Nishiyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-12 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
19
+ version: 1.8.1
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.8.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: clipboard
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
33
+ version: 1.0.5
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.0.5
41
41
  - !ruby/object:Gem::Dependency
42
- name: json
42
+ name: ffi
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.9.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.9.3
55
55
  - !ruby/object:Gem::Dependency
56
- name: highline
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: clipboard
70
+ name: jeweler2
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.0.5
75
+ version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 1.0.5
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: ffi
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rspec
98
+ name: json
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
103
+ version: 1.8.1
104
+ type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 1.8.1
111
111
  - !ruby/object:Gem::Dependency
112
- name: rake
112
+ name: clipboard
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
117
+ version: 1.0.5
118
+ type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 1.0.5
125
125
  - !ruby/object:Gem::Dependency
126
- name: json
126
+ name: ffi
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ! '>='
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: 1.9.3
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ! '>='
136
+ - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: 1.9.3
139
139
  - !ruby/object:Gem::Dependency
140
- name: highline
140
+ name: json
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ! '>='
143
+ - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: 1.8.1
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ! '>='
150
+ - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: 1.8.1
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: clipboard
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -168,21 +168,21 @@ dependencies:
168
168
  name: ffi
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ! '>='
171
+ - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
173
+ version: 1.9.3
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ! '>='
178
+ - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: 1.9.3
181
181
  description: PasteHub is cloud-based cross-platform clipboard sync.
182
182
  email: kiyoka@sumibi.org
183
183
  executables:
184
184
  - PastehubSync
185
- - pastehubDump
185
+ - pastehubGet
186
186
  - pastehubPost
187
187
  extensions: []
188
188
  extra_rdoc_files:
@@ -191,26 +191,19 @@ files:
191
191
  - Rakefile
192
192
  - VERSION.yml
193
193
  - bin/PastehubSync
194
- - bin/pastehubDump
194
+ - bin/pastehubGet
195
195
  - bin/pastehubPost
196
196
  - lib/pastehub.rb
197
- - lib/pastehub/auth.rb
198
197
  - lib/pastehub/client.rb
199
198
  - lib/pastehub/clientsync.rb
200
199
  - lib/pastehub/clipboard.rb
201
200
  - lib/pastehub/config.rb
202
- - lib/pastehub/crypt.rb
203
- - lib/pastehub/localdb.rb
204
- - lib/pastehub/log.rb
205
- - lib/pastehub/macosx.rb
206
- - lib/pastehub/masterdb.rb
207
- - lib/pastehub/store.rb
201
+ - lib/pastehub/syncentry.rb
208
202
  - lib/pastehub/util.rb
209
- - server/masterdb.rb
210
- - server/notifier.rb
211
203
  - README.md
212
204
  homepage: http://github.com/kiyoka/pastehub
213
- licenses: []
205
+ licenses:
206
+ - New BSD
214
207
  metadata: {}
215
208
  post_install_message:
216
209
  rdoc_options: []
@@ -218,17 +211,17 @@ require_paths:
218
211
  - lib
219
212
  required_ruby_version: !ruby/object:Gem::Requirement
220
213
  requirements:
221
- - - ! '>='
214
+ - - ">="
222
215
  - !ruby/object:Gem::Version
223
216
  version: '0'
224
217
  required_rubygems_version: !ruby/object:Gem::Requirement
225
218
  requirements:
226
- - - ! '>='
219
+ - - ">="
227
220
  - !ruby/object:Gem::Version
228
221
  version: '0'
229
222
  requirements: []
230
223
  rubyforge_project:
231
- rubygems_version: 2.0.3
224
+ rubygems_version: 2.0.14
232
225
  signing_key:
233
226
  specification_version: 4
234
227
  summary: PasteHub is cloud-based cross-platform clipboard sync.
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- #
4
- # pastehubDump - PasteHub's dump utility for UNIX client.
5
- #
6
- # Copyright (c) 2009-2011 Kiyoka Nishiyama <kiyoka@sumibi.org>
7
- #
8
- # Redistribution and use in source and binary forms, with or without
9
- # modification, are permitted provided that the following conditions
10
- # are met:
11
- #
12
- # 1. Redistributions of source code must retain the above copyright
13
- # notice, this list of conditions and the following disclaimer.
14
- #
15
- # 2. Redistributions in binary form must reproduce the above copyright
16
- # notice, this list of conditions and the following disclaimer in the
17
- # documentation and/or other materials provided with the distribution.
18
- #
19
- # 3. Neither the name of the authors nor the names of its contributors
20
- # may be used to endorse or promote products derived from this
21
- # software without specific prior written permission.
22
- #
23
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29
- # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
- # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
- # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
- # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- #
35
- #
36
- require 'pastehub'
37
-
38
- def dumpDb( username, command, key )
39
- config = PasteHub::Config.instance
40
- config.loadClient
41
-
42
- # open local store
43
- store = PasteHub::LocalStore.new( username, true )
44
- case command
45
- when "list"
46
- localList = store.getList()
47
- if key and key.match( /^[0-9]+$/ )
48
- localList = localList.take( key.to_i )
49
- end
50
- localList.each { |x|
51
- puts x
52
- }
53
-
54
- when "slist"
55
- serverList = store.getServerList()
56
- serverList.each { |x|
57
- puts x
58
- }
59
-
60
- when "top"
61
- pair = store.top()
62
- print pair[1] if pair[1]
63
-
64
- when "latest"
65
- arr = store.latest()
66
- puts 'server=' + arr[0]
67
- puts 'local =' + arr[1]
68
-
69
- when "get"
70
- print store.getValue( key )
71
- end
72
-
73
- store.close()
74
- end
75
-
76
- def main
77
- username = PasteHub.loadUsername
78
- if not username
79
- STDERR.puts "clientDump: setup problem. Please setup pastehub application."
80
- exit 1
81
- end
82
-
83
- if 0 == ARGV.length
84
- STDERR.puts "clientDump [command] [arg]"
85
- STDERR.puts " 1) clientDump list"
86
- STDERR.puts " 2) clientDump slist"
87
- STDERR.puts " 3) clientDump get key"
88
- STDERR.puts " 4) clientDump top"
89
- STDERR.puts " 5) clientDump latest"
90
- exit 1
91
- end
92
-
93
- command = ARGV[0].downcase
94
- case command
95
- when "list"
96
- dumpDb( username, command, ARGV[1] )
97
- when "slist"
98
- dumpDb( username, command, "" )
99
- when "top"
100
- dumpDb( username, command, "" )
101
- when "latest"
102
- dumpDb( username, command, "" )
103
- when "get"
104
- if 2 > ARGV.length
105
- STDERR.puts "Error: please spacify key."
106
- exit 1
107
- end
108
- dumpDb( username, command, ARGV[1] )
109
- else
110
- STDERR.puts "unknown command [#{command}]"
111
- end
112
- end
113
-
114
- main