Permalink
Browse files

add store sample

  • Loading branch information...
1 parent e671f1e commit dbff50902e59176fe57cf5efcd45ab65e19701ea genywind committed Aug 31, 2010
Showing with 3,250 additions and 42 deletions.
  1. +1 −0 .gitignore
  2. +4 −2 platform/shared/SyncClient/SyncClient.cpp
  3. +2 −35 platform/shared/net/HttpServer.cpp
  4. +39 −0 platform/shared/net/URI.cpp
  5. +3 −0 platform/shared/net/URI.h
  6. +11 −5 platform/shared/sync/SyncEngine.cpp
  7. +1 −0 rhosync-client/ObjectiveC/RhoSyncNotify.m
  8. +25 −0 rhosync-client/Samples/ObjectiveC/store/Classes/LoginViewController.h
  9. +98 −0 rhosync-client/Samples/ObjectiveC/store/Classes/LoginViewController.m
  10. +15 −0 rhosync-client/Samples/ObjectiveC/store/Classes/RootViewController.h
  11. +172 −0 rhosync-client/Samples/ObjectiveC/store/Classes/RootViewController.m
  12. +36 −0 rhosync-client/Samples/ObjectiveC/store/Classes/SyncEngine.h
  13. +89 −0 rhosync-client/Samples/ObjectiveC/store/Classes/SyncEngine.m
  14. +25 −0 rhosync-client/Samples/ObjectiveC/store/Classes/WaitLoginController.h
  15. +82 −0 rhosync-client/Samples/ObjectiveC/store/Classes/WaitLoginController.m
  16. +21 −0 rhosync-client/Samples/ObjectiveC/store/Classes/storeAppDelegate.h
  17. +90 −0 rhosync-client/Samples/ObjectiveC/store/Classes/storeAppDelegate.m
  18. +620 −0 rhosync-client/Samples/ObjectiveC/store/LoginViewController.xib
  19. +580 −0 rhosync-client/Samples/ObjectiveC/store/MainWindow.xib
  20. +384 −0 rhosync-client/Samples/ObjectiveC/store/RootViewController.xib
  21. +557 −0 rhosync-client/Samples/ObjectiveC/store/WaitLoginController.xib
  22. +17 −0 rhosync-client/Samples/ObjectiveC/store/main.m
  23. +364 −0 rhosync-client/Samples/ObjectiveC/store/store.xcodeproj/project.pbxproj
  24. +14 −0 rhosync-client/Samples/ObjectiveC/store/store_Prefix.pch
View
@@ -39,6 +39,7 @@ rhosync-client/ObjectiveC/Tests/SyncClientTest/build/*
rhosync-client/ObjectiveC/Tests/build/*
rhosync-client/ObjectiveC/build/*
rhosync-client/build/*
+rhosync-client/Samples/ObjectiveC/store/build/*
spec/bin/*
spec/**/bin/*
@@ -9,6 +9,7 @@
#include "common/RhoConf.h"
#include "common/RhoTime.h"
#include "common/RhoAppAdapter.h"
+#include "net/URI.h"
using namespace rho;
using namespace rho::common;
@@ -89,6 +90,7 @@ void rho_syncclient_init(RHOM_MODEL* pModels, int nModels)
//create db and db-files folder
CRhoFile::createFolder( (strDbPath + "db/db-files").c_str());
+ CRhoFile::createFolder( (strDbPath + "apps").c_str());
for( int i = 0; i < nModels; i++ )
{
@@ -640,8 +642,8 @@ void rho_syncclient_parsenotify(const char* msg, RHO_SYNC_NOTIFY* pNotify)
continue;
CTokenizer oValueTok( tok, "=" );
- String name = oValueTok.nextToken();
- String value = oValueTok.nextToken();
+ String name = net::URI::urlDecode(oValueTok.nextToken());
+ String value = net::URI::urlDecode(oValueTok.nextToken());
if ( name.compare("total_count") == 0)
convertFromStringA( value.c_str(), pNotify->total_count );
@@ -1,6 +1,7 @@
#include "net/HttpServer.h"
#include "common/RhodesApp.h"
#include "common/RhoFilePath.h"
+#include "net/URI.h"
#include "ruby/ext/rho/rhoruby.h"
#include <algorithm>
@@ -66,40 +67,6 @@ static bool isfile(String const &path)
return stat(path.c_str(), &st) == 0 && S_ISREG(st.st_mode);
}
-static String decode(String const &url)
-{
- String ret;
- for (const char *s = url.c_str(); *s != '\0'; ++s) {
- if (*s != '%') {
- ret.push_back(*s);
- continue;
- }
-
- unsigned int c1 = (unsigned char)*++s;
- if (c1 >= (unsigned char)'0' && c1 <= (unsigned char)'9')
- c1 = c1 - (unsigned char)'0';
- else if (c1 >= (unsigned char)'a' && c1 <= (unsigned char)'f')
- c1 = c1 - (unsigned char)'a' + 10;
- else if (c1 >= (unsigned char)'A' && c1 <= (unsigned char)'F')
- c1 = c1 - (unsigned char)'A' + 10;
- else
- break;
- unsigned int c2 = (unsigned char)*++s;
- if (c2 >= (unsigned char)'0' && c2 <= (unsigned char)'9')
- c2 = c2 - (unsigned char)'0';
- else if (c2 >= (unsigned char)'a' && c2 <= (unsigned char)'f')
- c2 = c2 - (unsigned char)'a' + 10;
- else if (c2 >= (unsigned char)'A' && c2 <= (unsigned char)'F')
- c2 = c2 - (unsigned char)'A' + 10;
- else
- break;
-
- char c = (char)((c1 << 4) | c2);
- ret.push_back(c);
- }
- return ret;
-}
-
static bool isindex(String const &uri)
{
static struct {
@@ -702,7 +669,7 @@ bool CHttpServer::parse_startline(String const &line, String &method, String &ur
}
uri.assign(s, e);
- uri = decode(uri);
+ uri = URI::urlDecode(uri);
query.clear();
if (*e == '?') {
@@ -141,6 +141,45 @@ String URI::urlEncode(const String& fullPath)
strRes += fullPath;
}
+/*static*/String URI::urlDecode(const String& fullPath)
+{
+ String res;
+ urlDecode(fullPath, res);
+ return res;
+}
+
+/*static*/ void URI::urlDecode(const String &url, String& ret )
+{
+ for (const char *s = url.c_str(); *s != '\0'; ++s) {
+ if (*s != '%') {
+ ret.push_back(*s);
+ continue;
+ }
+
+ unsigned int c1 = (unsigned char)*++s;
+ if (c1 >= (unsigned char)'0' && c1 <= (unsigned char)'9')
+ c1 = c1 - (unsigned char)'0';
+ else if (c1 >= (unsigned char)'a' && c1 <= (unsigned char)'f')
+ c1 = c1 - (unsigned char)'a' + 10;
+ else if (c1 >= (unsigned char)'A' && c1 <= (unsigned char)'F')
+ c1 = c1 - (unsigned char)'A' + 10;
+ else
+ break;
+ unsigned int c2 = (unsigned char)*++s;
+ if (c2 >= (unsigned char)'0' && c2 <= (unsigned char)'9')
+ c2 = c2 - (unsigned char)'0';
+ else if (c2 >= (unsigned char)'a' && c2 <= (unsigned char)'f')
+ c2 = c2 - (unsigned char)'a' + 10;
+ else if (c2 >= (unsigned char)'A' && c2 <= (unsigned char)'F')
+ c2 = c2 - (unsigned char)'A' + 10;
+ else
+ break;
+
+ char c = (char)((c1 << 4) | c2);
+ ret.push_back(c);
+ }
+}
+
//"auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT, auth_token=887b2ffd30a7b97be9a0986d7746a934421eec7d; path=/; expires=Sat, 24 Oct 2009 20:56:55 GMT, rhosync_session=BAh7BzoMdXNlcl9pZGkIIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--f9b67d99397fc534107fb3b7483ccdae23b4a761; path=/; expires=Sun, 10 Oct 2010 19:10:58 GMT; HttpOnly");
//"auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT");
//"rhosync_session=BAh7CToNcGFzc3dvcmQiFTiMYru1W11zuoAlN%2FPtgjc6CmxvZ2luIhU4jGK7tVtdc7qAJTfz7YI3Ogx1c2VyX2lkaQYiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA%3D--a7829a70171203d72cd4e83d07b18e8fcf5e2f78; path=/; expires=Thu, 02 Sep 2010 23:51:31 GMT; HttpOnly");
@@ -14,6 +14,9 @@ class URI
static void urlEncode(const String& fullPath, String& strRes);
static String urlEncode(const String& fullPath);
+ static String urlDecode(const String& url);
+ static void urlDecode(const String &url, String& ret );
+
String getPath();
String getQueryString();
String getScheme();
@@ -786,12 +786,18 @@ void CSyncEngine::logout()
void CSyncEngine::setSyncServer(const char* syncserver)
{
- rho_conf_setString("syncserver", syncserver);
- rho_conf_save();
-
- getUserDB().executeSQL("DELETE FROM client_info");
+ String strOldSrv = RHOCONF().getString("syncserver");
+ String strNewSrv = syncserver ? syncserver : "";
+
+ if ( strOldSrv.compare(strNewSrv) != 0)
+ {
+ rho_conf_setString("syncserver", syncserver);
+ rho_conf_save();
+
+ getUserDB().executeSQL("DELETE FROM client_info");
- logout();
+ logout();
+ }
}
static String getHostFromUrl( const String& strUrl )
@@ -42,6 +42,7 @@ - (id) init: (RHO_SYNC_NOTIFY*) data
if ( data->callback_params )
callback_params = [NSString stringWithUTF8String: data->callback_params];
+ rho_syncclient_free_syncnotify(data);
return self;
}
@@ -0,0 +1,25 @@
+//
+// LoginViewController.h
+// store
+//
+// Created by Vlad on 8/30/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "WaitLoginController.h"
+
+
+@interface LoginViewController : UIViewController {
+ IBOutlet UITextField* txtLogin;
+ IBOutlet UITextField* txtPassword;
+ IBOutlet WaitLoginController *waitPage;
+}
+
+@property (retain, nonatomic) IBOutlet UITextField* txtLogin;
+@property (retain, nonatomic) IBOutlet UITextField* txtPassword;
+@property (nonatomic, retain) IBOutlet WaitLoginController* waitPage;
+
+- (IBAction)doLogin:(id)sender;
+
+@end
@@ -0,0 +1,98 @@
+//
+// LoginViewController.m
+// store
+//
+// Created by Vlad on 8/30/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "SyncEngine.h"
+#import "LoginViewController.h"
+
+
+@implementation LoginViewController
+
+@synthesize txtLogin, txtPassword, waitPage;
+
+- (void)loginThreadMainRoutine:(WaitLoginController*) waitView {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool
+
+ if ( [[SyncEngine sharedInstance].syncClient is_logged_in] )
+ {
+ sleep(1);
+ [SyncEngine sharedInstance].loginState = logged_in;
+ [waitView performSelectorOnMainThread:@selector(loginComplete:) withObject:@"no errors" waitUntilDone:false];
+ [pool release]; // Release the objects in the pool.
+ return;
+ }
+
+ NSLog(@"login: %@, password: %@", txtLogin.text, txtPassword.text);
+
+ RhoSyncNotify* res = [ [SyncEngine sharedInstance].syncClient loginWithUser:txtLogin.text pwd:txtPassword.text];
+ if ( res.error_code != RHO_ERR_NONE || ![[SyncEngine sharedInstance].syncClient is_logged_in])
+ [SyncEngine sharedInstance].loginState = failed;
+ else
+ {
+ [SyncEngine sharedInstance].loginState = logged_in;
+ [res release];
+
+ res = [[SyncEngine sharedInstance].syncClient syncAll];
+ }
+
+ [waitView performSelectorOnMainThread:@selector(loginComplete:) withObject:[res error_message] waitUntilDone:false];
+
+ [pool release]; // Release the objects in the pool.
+}
+
+- (IBAction)doLogin:(id)sender
+{
+ [SyncEngine sharedInstance].loginState = in_progress;
+ [[self navigationController] pushViewController:waitPage animated:YES];
+ [NSThread detachNewThreadSelector:@selector(loginThreadMainRoutine:) toTarget:self withObject:waitPage];
+}
+
+/*
+ // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
+ if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
+ // Custom initialization
+ }
+ return self;
+}
+*/
+
+/*
+// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
+- (void)viewDidLoad {
+ [super viewDidLoad];
+}
+*/
+
+/*
+// Override to allow orientations other than the default portrait orientation.
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
+ // Return YES for supported orientations
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+*/
+
+- (void)didReceiveMemoryWarning {
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+
+ // Release any cached data, images, etc that aren't in use.
+}
+
+- (void)viewDidUnload {
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+
+@end
@@ -0,0 +1,15 @@
+//
+// RootViewController.h
+// store
+//
+// Created by Vlad on 8/30/10.
+// Copyright __MyCompanyName__ 2010. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface RootViewController : UITableViewController {
+ NSMutableArray* arItems;
+}
+
+@end
Oops, something went wrong.

0 comments on commit dbff509

Please sign in to comment.