Show More
@@ -336,6 +336,24 def _handlehttperror(e, req, cmd): | |||
|
336 | 336 | |
|
337 | 337 | return '' |
|
338 | 338 | |
|
339 | def _sshv1respondbytes(fout, value): | |
|
340 | """Send a bytes response for protocol version 1.""" | |
|
341 | fout.write('%d\n' % len(value)) | |
|
342 | fout.write(value) | |
|
343 | fout.flush() | |
|
344 | ||
|
345 | def _sshv1respondstream(fout, source): | |
|
346 | write = fout.write | |
|
347 | for chunk in source.gen: | |
|
348 | write(chunk) | |
|
349 | fout.flush() | |
|
350 | ||
|
351 | def _sshv1respondooberror(fout, ferr, rsp): | |
|
352 | ferr.write(b'%s\n-\n' % rsp) | |
|
353 | ferr.flush() | |
|
354 | fout.write(b'\n') | |
|
355 | fout.flush() | |
|
356 | ||
|
339 | 357 | class sshserver(baseprotocolhandler): |
|
340 | 358 | def __init__(self, ui, repo): |
|
341 | 359 | self._ui = ui |
@@ -376,7 +394,7 class sshserver(baseprotocolhandler): | |||
|
376 | 394 | return [data[k] for k in keys] |
|
377 | 395 | |
|
378 | 396 | def getfile(self, fpout): |
|
379 | self._sendresponse('') | |
|
397 | _sshv1respondbytes(self._fout, b'') | |
|
380 | 398 | count = int(self._fin.readline()) |
|
381 | 399 | while count: |
|
382 | 400 | fpout.write(self._fin.read(count)) |
@@ -385,51 +403,34 class sshserver(baseprotocolhandler): | |||
|
385 | 403 | def redirect(self): |
|
386 | 404 | pass |
|
387 | 405 | |
|
388 | def _sendresponse(self, v): | |
|
389 | self._fout.write("%d\n" % len(v)) | |
|
390 | self._fout.write(v) | |
|
391 | self._fout.flush() | |
|
392 | ||
|
393 | def _sendstream(self, source): | |
|
394 | write = self._fout.write | |
|
395 | for chunk in source.gen: | |
|
396 | write(chunk) | |
|
397 | self._fout.flush() | |
|
398 | ||
|
399 | def _sendpushresponse(self, rsp): | |
|
400 | self._sendresponse('') | |
|
401 | self._sendresponse(str(rsp.res)) | |
|
402 | ||
|
403 | def _sendpusherror(self, rsp): | |
|
404 | self._sendresponse(rsp.res) | |
|
405 | ||
|
406 | def _sendooberror(self, rsp): | |
|
407 | self._ui.ferr.write('%s\n-\n' % rsp.message) | |
|
408 | self._ui.ferr.flush() | |
|
409 | self._fout.write('\n') | |
|
410 | self._fout.flush() | |
|
411 | ||
|
412 | 406 | def serve_forever(self): |
|
413 | 407 | while self.serve_one(): |
|
414 | 408 | pass |
|
415 | 409 | sys.exit(0) |
|
416 | 410 | |
|
417 | _handlers = { | |
|
418 | str: _sendresponse, | |
|
419 | wireproto.streamres: _sendstream, | |
|
420 | wireproto.streamres_legacy: _sendstream, | |
|
421 | wireproto.pushres: _sendpushresponse, | |
|
422 | wireproto.pusherr: _sendpusherror, | |
|
423 | wireproto.ooberror: _sendooberror, | |
|
424 | } | |
|
425 | ||
|
426 | 411 | def serve_one(self): |
|
427 | 412 | cmd = self._fin.readline()[:-1] |
|
428 | 413 | if cmd and wireproto.commands.commandavailable(cmd, self): |
|
429 | 414 | rsp = wireproto.dispatch(self._repo, self, cmd) |
|
430 | self._handlers[rsp.__class__](self, rsp) | |
|
415 | ||
|
416 | if isinstance(rsp, bytes): | |
|
417 | _sshv1respondbytes(self._fout, rsp) | |
|
418 | elif isinstance(rsp, wireproto.streamres): | |
|
419 | _sshv1respondstream(self._fout, rsp) | |
|
420 | elif isinstance(rsp, wireproto.streamres_legacy): | |
|
421 | _sshv1respondstream(self._fout, rsp) | |
|
422 | elif isinstance(rsp, wireproto.pushres): | |
|
423 | _sshv1respondbytes(self._fout, b'') | |
|
424 | _sshv1respondbytes(self._fout, bytes(rsp.res)) | |
|
425 | elif isinstance(rsp, wireproto.pusherr): | |
|
426 | _sshv1respondbytes(self._fout, rsp.res) | |
|
427 | elif isinstance(rsp, wireproto.ooberror): | |
|
428 | _sshv1respondooberror(self._fout, self._ui.ferr, rsp.message) | |
|
429 | else: | |
|
430 | raise error.ProgrammingError('unhandled response type from ' | |
|
431 | 'wire protocol command: %s' % rsp) | |
|
431 | 432 | elif cmd: |
|
432 | self._sendresponse("") | |
|
433 | _sshv1respondbytes(self._fout, b'') | |
|
433 | 434 | return cmd != '' |
|
434 | 435 | |
|
435 | 436 | def _client(self): |
@@ -45,11 +45,11 class prehelloserver(wireprotoserver.ssh | |||
|
45 | 45 | l = self._fin.readline() |
|
46 | 46 | assert l == b'hello\n' |
|
47 | 47 | # Respond to unknown commands with an empty reply. |
|
48 | self._sendresponse(b'') | |
|
48 | wireprotoserver._sshv1respondbytes(self._fout, b'') | |
|
49 | 49 | l = self._fin.readline() |
|
50 | 50 | assert l == b'between\n' |
|
51 | 51 | rsp = wireproto.dispatch(self._repo, self, b'between') |
|
52 | self._handlers[rsp.__class__](self, rsp) | |
|
52 | wireprotoserver._sshv1respondbytes(self._fout, rsp) | |
|
53 | 53 | |
|
54 | 54 | super(prehelloserver, self).serve_forever() |
|
55 | 55 |
General Comments 0
You need to be logged in to leave comments.
Login now