Merge pull request #54 from lambmj/master

Guard against failed read in TDSocketChangeTracker.
Suppress logging of 404 status reading remote checkpoint doc during replication

This status is expected if it's the first time replicating this pair of databases, so having it show up in the log output makes it look as though there's a problem when there isn't.
Added TDJSON, to abstract our use of NSJSONSerialization and make it easier to replace

While I was at it, I added the ability to write fragments, and to encode directly to an NSString.
Async parsing of continuous _changes feed

TDSocketChangeTracker parses batches of lines on a background thread.
It doesn't read more data from the stream until parsing has finished.
This adds parallelism, and also makes the stream buffering work a lot better because data isn't read until it's ready to be parsed.
Optimization to -forceInsert:revisionHistory:source:

Don't waste time looking for previous revisions of a document, if the document's ID wasn't even in the database already.
This makes a difference during pull replications.
implemented TDNoBody content option and use it for GET attachment

When getting an attachment via the REST API, avoid loading the document JSON data.

Based on Marty's commit to TouchDB-Android:
https://github.com/couchbaselabs/TouchDB-Android/commit/6cc2407daca03529118a393c4902789e95512500
Add GET handler for _session

Send back an "Admin Party"-like response on a GET
request to /_session. This makes CouchApps work
that rely on _session (like Mobile Futon).

Based on vmx's commit to the Android repo:
https://github.com/vmx/TouchDB-Android/commit/7509e3e8b5f0c520d32711a80e02fc16eb55f542
Added +[TDJSON appendDictionary:toJSONDictionaryData:].

Replaces the static function appendDictToJSON in TDDatabase.m.

Also, unrelatedly, added _local_seq to the list sSpecialKeysToRemove in encodeDocumentJSON:.
Fixed some issues with EOF handling in the updated TDSocketChangeTracker.

The recent changes to do async parsing didn't handle EOF correctly — the tracker shouldn't stop until *after* any pending parse finishes.
Add router support for PUT of document in MIME multipart format

This is necessary for allowing TouchDB to be pushed to by another server.
Fixed a race condition in the HTTP listener

Sometimes it would never send the body of a response or close the socket.
I saw this happen with error responses like 404s; not sure it it would happen otherwise.
Support multipart GETs of documents

Another missing router feature that broke replication.
Also made TDMultipartDocumentReader not fail if the document contains no attachments.
Also added some more warnings/logging.
Allow TDURLProtocol and CouchCocoa to access multiple TDServers

This allows TouchDB databases in arbitrary locations in the filesystem to be accessed using CouchCocoa. Each TDServer is associated with a different hostname, which allows them to have distinct URLs.

Conflicts:

	TouchDB.xcodeproj/project.pbxproj
	TouchDB.xcodeproj/xcshareddata/xcschemes/iOS Demo.xcscheme
Speculative fix for a crash in -[TDSocketChangeTracker start]

Make sure that calling -stop always cancels a pending delayed connection retry.
(Crash was reported via email, by Nicolas Lapomarda.)
Revision IDs should be deterministic

Make revision ID a digest of the document & attachments. Fixes #56.
This means that if the same change is made to a document in two databases, it will not cause a conflict when they sync with each other (because the rev IDs will be the same.)
It also means that if some conflict occurs, and two peers fix it in the same way, the fixes will not conflict with each other.
Added unit tests for TDCanonicalJSON

These caught an edge case, where ASCII 31 (\037) wasn't being escaped in strings.