[haiku-commits] Re: haiku: hrev49418 - in src/apps/haikudepot: model ui

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 19 Jul 2015 16:21:13 +0200

On 07/19/2015 03:58 PM, kallisti5@xxxxxxxxxxx wrote:

Alex, it is nice that you took the time to apply the patch, but it would be even better, if you also checked it at least for coding style issues first.

93407f0c8709: HaikuDepot: desktop app can now have server url specified

* Enables us to test to other HD servers

Completes Task #12216

[ Andrew Lindesay <apl@xxxxxxxxxxxxxx> ]

Missing Signed-off-by.

diff --git a/src/apps/haikudepot/model/WebAppInterface.cpp
b/src/apps/haikudepot/model/WebAppInterface.cpp
index 22a0a43db..e8d5137 100644
--- a/src/apps/haikudepot/model/WebAppInterface.cpp
+++ b/src/apps/haikudepot/model/WebAppInterface.cpp
@@ -21,6 +21,10 @@
#include "PackageInfo.h"


+#define CODE_REPOSITORY_DEFAULT "haikuports"
+#define BASEURL_DEFAULT "https://depot.haiku-os.org";

Should rather be string constants.

class JsonBuilder {
public:
JsonBuilder()
@@ -269,6 +273,9 @@ enum {
};


+BString WebAppInterface::fBaseUrl = BString(BASEURL_DEFAULT);

sBaseUrl

WebAppInterface::WebAppInterface()
:
fLanguage("en")
@@ -313,6 +320,54 @@ WebAppInterface::SetAuthorization(const BString& username,
}


+static bool
+arguments_is_url_valid(const BString& value)
+{
+ if (value.Length() < 8) {
+ fprintf(stderr,"the url is less than 8 characters in length\n");

spacing

+ return false;
+ }
+
+ int32 schemeEnd = value.FindFirst("://");
+
+ if (schemeEnd == B_ERROR) {

< 0

+ fprintf(stderr,"the url does not contain the '://' string\n");

spacing

+ return false;
+ }
+
+ BString scheme;
+ value.CopyInto(scheme, 0, schemeEnd);
+
+ if (scheme != "http" && scheme != "https") {
+ fprintf(stderr,"the url scheme should be 'http' or 'https'\n");

spacing

+ return false;
+ }
+
+ if (value.Length()-1 == value.FindLast("/")) {

spacing

+ fprintf(stderr,"the url should be be terminated with a '/'\n");

spacing

+ return false;
+ }
+
+ return true;
+}
+
+
+/*! This method will set the web app base URL, returning a status to
+ indicate if the URL was acceptable.
+ \return B_OK if the base URL was valid and B_BAD_VALUE if not.
+ */
+

line spacing

+status_t
+WebAppInterface::SetBaseUrl(const BString& url) {

brace placement

[...]
@@ -625,6 +687,18 @@ WebAppInterface::AuthenticateUser(const BString& nickName,
// #pragma mark - private


+BString
+WebAppInterface::_FormFullUrl(const BString& suffix) const
+{
+ if (fBaseUrl.IsEmpty()) {
+ fprintf(stderr,"illegal state - missing web app base url\n");

spacing

[...]
diff --git a/src/apps/haikudepot/ui/App.cpp b/src/apps/haikudepot/ui/App.cpp
index 65b145c..95a1a85 100644
--- a/src/apps/haikudepot/ui/App.cpp
+++ b/src/apps/haikudepot/ui/App.cpp
@@ -118,9 +118,26 @@ App::RefsReceived(BMessage* message)
void
App::ArgvReceived(int32 argc, char* argv[])
{
- for (int i = 1; i < argc; i++) {
- BEntry entry(argv[i], true);
- _Open(entry);
+ for (int i = 1; i < argc;) {
+ if (0 == strcmp("--webappbaseurl", argv[i])) {

== 0

+ if (i == argc-1) {

spacing

+ fprintf(stderr,"unexpected end of arguments; missing
web app base url\n");

spacing

+ Quit();
+ }
+
+ if (B_OK != WebAppInterface::SetBaseUrl(argv[i+1])) {

!= B_OK, spacing

+ fprintf(stderr,"malformed web app base url;
%s\n", argv[i+1]);

spacing

+ Quit();
+ }
+ else
+ fprintf(stderr,"did configure the web base url;
%s\n",argv[i+1]);

spacing

+
+ i += 2;
+ } else {
+ BEntry entry(argv[i], true);
+ _Open(entry);
+ i ++;

spacing

CU, Ingo


Other related posts: