Skip to content

Commit

Permalink
Removed the LARGE_ID_TEST code. Updated the YAJL parser so that it ca…
Browse files Browse the repository at this point in the history
…n handle integers larger than 2^32 - 1 (0x7fffffff).
  • Loading branch information
Craig Hockenberry committed Jun 15, 2009
1 parent f32f7ae commit 32d439b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 112 deletions.
49 changes: 0 additions & 49 deletions MGTwitterEngine.m
Expand Up @@ -936,11 +936,6 @@ - (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID startingAtPage:(

- (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
{
#if LARGE_ID_TEST
if (sinceID > 0) sinceID -= 0x7fffffff;
if (maxID > 0) maxID -= 0x7fffffff;
#endif

NSString *path = [NSString stringWithFormat:@"statuses/friends_timeline.%@", API_FORMAT];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
Expand Down Expand Up @@ -973,11 +968,6 @@ - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sin

- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
{
#if LARGE_ID_TEST
if (sinceID > 0) sinceID -= 0x7fffffff;
if (maxID > 0) maxID -= 0x7fffffff;
#endif

NSString *path = [NSString stringWithFormat:@"statuses/user_timeline.%@", API_FORMAT];
MGTwitterRequestType requestType = MGTwitterUserTimelineRequest;

Expand Down Expand Up @@ -1010,10 +1000,6 @@ - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sin

- (NSString *)getUpdate:(unsigned long)updateID
{
#if LARGE_ID_TEST
if (updateID > 0) updateID -= 0x7fffffff;
#endif

NSString *path = [NSString stringWithFormat:@"statuses/show/%u.%@", updateID, API_FORMAT];

return [self _sendRequestWithMethod:nil path:path queryParameters:nil body:nil
Expand All @@ -1030,10 +1016,6 @@ - (NSString *)sendUpdate:(NSString *)status

- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
{
#if LARGE_ID_TEST
if (updateID > 0) updateID -= 0x7fffffff;
#endif

if (!status) {
return nil;
}
Expand Down Expand Up @@ -1074,11 +1056,6 @@ - (NSString *)getRepliesSinceID:(unsigned long)sinceID startingAtPage:(int)page

- (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
{
#if LARGE_ID_TEST
if (sinceID > 0) sinceID -= 0x7fffffff;
if (maxID > 0) maxID -= 0x7fffffff;
#endif

// NOTE: identi.ca can't handle mentions URL yet...
// NSString *path = [NSString stringWithFormat:@"statuses/mentions.%@", API_FORMAT];
NSString *path = [NSString stringWithFormat:@"statuses/replies.%@", API_FORMAT];
Expand Down Expand Up @@ -1108,10 +1085,6 @@ - (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned l

- (NSString *)deleteUpdate:(unsigned long)updateID
{
#if LARGE_ID_TEST
if (updateID > 0) updateID -= 0x7fffffff;
#endif

NSString *path = [NSString stringWithFormat:@"statuses/destroy/%u.%@", updateID, API_FORMAT];

return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path queryParameters:nil body:nil
Expand Down Expand Up @@ -1216,11 +1189,6 @@ - (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID startingAtPage:(in

- (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
{
#if LARGE_ID_TEST
if (sinceID > 0) sinceID -= 0x7fffffff;
if (maxID > 0) maxID -= 0x7fffffff;
#endif

NSString *path = [NSString stringWithFormat:@"direct_messages.%@", API_FORMAT];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
Expand Down Expand Up @@ -1252,11 +1220,6 @@ - (NSString *)getSentDirectMessagesSinceID:(unsigned long)sinceID startingAtPage

- (NSString *)getSentDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
{
#if LARGE_ID_TEST
if (sinceID > 0) sinceID -= 0x7fffffff;
if (maxID > 0) maxID -= 0x7fffffff;
#endif

NSString *path = [NSString stringWithFormat:@"direct_messages/sent.%@", API_FORMAT];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
Expand Down Expand Up @@ -1309,10 +1272,6 @@ - (NSString *)sendDirectMessage:(NSString *)message to:(NSString *)username

- (NSString *)deleteDirectMessage:(unsigned long)updateID
{
#if LARGE_ID_TEST
if (updateID > 0) updateID -= 0x7fffffff;
#endif

NSString *path = [NSString stringWithFormat:@"direct_messages/destroy/%u.%@", updateID, API_FORMAT];

return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path queryParameters:nil body:nil
Expand Down Expand Up @@ -1484,10 +1443,6 @@ - (NSString *)getFavoriteUpdatesFor:(NSString *)username startingAtPage:(int)pag

- (NSString *)markUpdate:(unsigned long)updateID asFavorite:(BOOL)flag
{
#if LARGE_ID_TEST
if (updateID > 0) updateID -= 0x7fffffff;
#endif

NSString *path = nil;
MGTwitterRequestType requestType;
if (flag)
Expand Down Expand Up @@ -1611,10 +1566,6 @@ - (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)

- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)sinceID startingAtPage:(int)page count:(int)count geocode:(NSString *)geocode
{
#if LARGE_ID_TEST
if (sinceID > 0) sinceID -= 0x7fffffff;
#endif

NSString *path = [NSString stringWithFormat:@"search.%@", API_FORMAT];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
Expand Down
20 changes: 0 additions & 20 deletions MGTwitterEngineGlobalHeader.h
Expand Up @@ -49,23 +49,3 @@
*/

#define YAJL_AVAILABLE 0

#if YAJL_AVAILABLE
/*
When enabled, this definition artificially adds 0x7ffffff to each tweet ID that is read from the API. It
also subtracts 0x7fffffff from anything it sends back to the API. This allows you to test your application
code and make sure it works well with large unsigned longs. This is important because tweet IDs that are
treated as signed integers will become negative after 2^32 - 1 (0x7fffffff). This will happen sometime
around the end of May 2009.
A future release of MGTwitterEngine will use 64-bit integers for the tweet IDs. The current change is
meant as a stopgap measure that will affect existing applications as little as possible.
*/

#define LARGE_ID_TEST 0
#else
/*
This option is only available when you are using the YAJL parser. Do not change the following definition.
*/
#define LARGE_ID_TEST 0
#endif
63 changes: 20 additions & 43 deletions MGTwitterYAJLParser.m
Expand Up @@ -41,47 +41,24 @@ int process_yajl_boolean(void * ctx, int boolVal)
return 1;
}

int process_yajl_integer(void *ctx, long integerVal)
int process_yajl_number(void *ctx, const char *numberVal, unsigned int numberLen)
{
id self = ctx;
if (currentKey)
if (currentKey)
{
#if LARGE_ID_TEST
if ([currentKey isEqualToString:@"id"] || [currentKey isEqualToString:@"in_reply_to_status_id"])
{
unsigned long adjustedIntegerVal = (unsigned long)integerVal + 0x7fffffff;
[self addValue:[NSNumber numberWithUnsignedLong:adjustedIntegerVal] forKey:currentKey];
}
else
{
unsigned long coercedLongVal = (unsigned long)integerVal;
[self addValue:[NSNumber numberWithUnsignedLong:coercedLongVal] forKey:currentKey];
}
#else
unsigned long coercedLongVal = (unsigned long)integerVal;
[self addValue:[NSNumber numberWithUnsignedLong:coercedLongVal] forKey:currentKey];
#endif
[currentKey release];
currentKey = nil;
}
NSString *stringValue = [[NSString alloc] initWithBytesNoCopy:(void *)numberVal length:numberLen encoding:NSUTF8StringEncoding freeWhenDone:NO];

return 1;
}
NSNumber *longLongValue = [NSNumber numberWithLongLong:[stringValue longLongValue]];
[self addValue:longLongValue forKey:currentKey];

int process_yajl_double(void *ctx, double doubleVal)
{
id self = ctx;

if (currentKey)
{
[self addValue:[NSNumber numberWithDouble:doubleVal] forKey:currentKey];
[stringValue release];

[currentKey release];
currentKey = nil;
currentKey = nil;
}

return 1;
return 1;
}

int process_yajl_string(void *ctx, const unsigned char * stringVal, unsigned int stringLen)
Expand Down Expand Up @@ -179,17 +156,17 @@ int process_yajl_end_array(void *ctx)
}

static yajl_callbacks callbacks = {
process_yajl_null,
process_yajl_boolean,
process_yajl_integer,
process_yajl_double,
NULL,
process_yajl_string,
process_yajl_start_map,
process_yajl_map_key,
process_yajl_end_map,
process_yajl_start_array,
process_yajl_end_array
process_yajl_null,
process_yajl_boolean,
NULL,
NULL,
process_yajl_number,
process_yajl_string,
process_yajl_start_map,
process_yajl_map_key,
process_yajl_end_map,
process_yajl_start_array,
process_yajl_end_array
};

#pragma mark Creation and Destruction
Expand Down

0 comments on commit 32d439b

Please sign in to comment.