Picture of iqbal
Registered 5 years 221 days
iqbal Wednesday, 2 February 2022, 04:52 PM
Add Custom Parameters to AppUrl in PBX
Hi
I have a question regarding adding GET Parameters to URL of App.
Like:
https://APP_Manager/byon-dev.de/test_app/test_app_admin?user=test&command=testCommand
I Tried it but it doesnt work well. app worked before adding these Parameters.
After adding these Parameters app worked but without websocket comunication.
see Attached Image:
can you please explain how it is done correct way.
BR
Iqbal
2022-02-02_16_45_59-innovaphone_myApps.png

Andreas Fink
Moderator Registered 13 years 52 days
Andreas Fink (innovaphone) Wednesday, 2 February 2022, 06:24 PM
Re: Add Custom Parameters to AppUrl in PBX
Hello Iqbal,

it seems to be, your App Service ignores the JSON messages on the WS connection, if the value of the "app" element is not equals 'byon_line_selector_admin'. Somewhere in the App Service implementation you have something like this:

if (conn.app == "byon_line_selector_admin") {


The WS URI with query strings is handled by the webserver of the AP as one part and forwarded it completely to the app service. You have to strip it from the app name manually in your service.

Best Regards
Andreas Fink
Picture of iqbal
Registered 5 years 221 days
iqbal Thursday, 3 February 2022, 11:34 AM
Re: Add Custom Parameters to AppUrl in PBX
Hi
I am trying to use SDK internal parser for query string and i am not getting Parameters.
works HttpQueryArgs only on urls or i can pass any string to it?

Code looks like this:

if (strstr(app, "?")) {
char* tok = strtok(app, "?");
app = tok;
LOG_INSTANCE("QueryParams After: %s \t TOK: %s", app,tok);
for (class HttpQueryArgs args(app); args.Current(); args.Next()) {
class HttpQueryArg* arg = args.Current();
LOG_INSTANCE("QueryParams Detail arg->name: %s \t arg->value: %s", arg->name, arg->value);
}

}

Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Thursday, 3 February 2022, 11:42 AM
Re: Add Custom Parameters to AppUrl in PBX
Hi Igbal,

just posting my working code. HttpQueryArgs constructor searches for ? itself already:

void YourApp::WebserverPluginHttpListenResultHistory(IWebserverPlugin * plugin, char * resourceName, bool api)
{
size_t len = strlen(resourceName) + 1;
char * tmp = (char *)alloca(len);
memcpy(tmp, resourceName, len);

for (HttpQueryArgs args(tmp); args.Current(); args.Next()) {
HttpQueryArg * arg = args.Current();
}
}

Greetings,
Daniel
Picture of iqbal
Registered 5 years 221 days
iqbal Thursday, 3 February 2022, 12:04 PM
Re: Add Custom Parameters to AppUrl in PBX
Hi Daniel
i tryed your Code:

void LineSelector::WebserverPluginHttpListenResultHistory(IWebserverPlugin* plugin, char* resourceName, bool api)
{
size_t len = strlen(resourceName) + 1;
char* tmp = (char*)alloca(len);
memcpy(tmp, resourceName, len);

for (HttpQueryArgs args(tmp); args.Current(); args.Next()) {
HttpQueryArg* arg = args.Current();
this->Log("QueryParams Detail arg->name: %s \t arg->value: %s", arg->name, arg->value);
}
}

but it doesnt worked and i didnt got any Logs.
Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Thursday, 3 February 2022, 12:08 PM
Re: Add Custom Parameters to AppUrl in PBX
Can you log resourceName at the beginning of the function.

Greetings,
Daniel
Picture of iqbal
Registered 5 years 221 days
iqbal Thursday, 3 February 2022, 12:19 PM
Re: Add Custom Parameters to AppUrl in PBX
Hi Daniel
i Logged it at beginning of function and there was no log.
as said query string should come from pbx.
i dont have rest api funtionality in app. app works only via websockets.

this is my App Class Declaration:


#pragma once

class LineSelector : public AppInstance, public AppUpdates, public UDatabase, public UWebserverPlugin, public JsonApiContext, public ConfigContext, public UBadgeCountSignaling, public UReplicator
{
protected:
void DatabaseConnectComplete(IDatabase* const database) override;
void DatabaseShutdown(IDatabase* const database, db_error_t reason) override;
void DatabaseError(IDatabase* const database, db_error_t error) override;

void WebserverPluginClose(IWebserverPlugin* plugin, wsp_close_reason_t reason, bool lastUser) override;
void WebserverPluginWebsocketListenResult(IWebserverPlugin* plugin, const char* path, const char* registeredPathForRequest, const char* host) override;
void WebserverPluginHttpListenResult(IWebserverPlugin* plugin, ws_request_type_t requestType, char* resourceName, const char* registeredPathForRequest, ulong64 dataSize) override;
void WebserverPluginHttpListenResultHistory(IWebserverPlugin* plugin, char* resourceName, bool api);

void ServerCertificateUpdate(const byte* cert, size_t certLen) override;
void Stop() override;

void CreateBadgeCountPresenceMonitor(class BadgeCountSignaling* signaling, int call, const char* user, const char* topic) override;

void TryStop();
void InitReplicator();

bool stopping;
class ITask* currentTask;
std::list<class LineSelectorSession*> sessionList;

public:
LineSelector(IIoMux* const iomux, class LineSelectorService* service, AppInstanceArgs* args);
~LineSelector();

void DatabaseInitComplete();
void ConfigInitComplete();
void LineSelectorSessionClosed(class LineSelectorSession* session);

void StartUpdate(const char* domain, const char* instance);
void ReStartUpdate();

// UReplicator
virtual void ReplicatorInitialized() override;
virtual void ReplicatorAdded(ulong64 id) override;
virtual void ReplicatorDeleted(ulong64 id) override;
virtual void ReplicatorDeletedConfirm(ulong64 id) override;
virtual void ReplicatorDeletedConfirmComplete(ulong64 id) override;
virtual void ReplicatorUpdated(ulong64 id, ulong64 mask) override;
virtual void ReplicatorStopped() override;

void ReplicatorStart(class json_io& msg, word base, char*& tmp) override;

const char* appPwd() { return args.appPassword; };

class IIoMux* iomux;
class LineSelectorService* service;
class IWebserverPlugin* webserverPlugin;
class IDatabase* database;
long64 count;

class AppUpdatesFilters countFilters;
class AppUpdatesFilters badgeCountFilters;

class IReplicator* replicator;
std::string appDomain;
std::string appInstance;

std::string appName;
std::string appPassword;

ulong64 currentId;
};


Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Thursday, 3 February 2022, 01:19 PM
1 of 1 users consider this post helpful
Re: Add Custom Parameters to AppUrl in PBX
Ah, you are just receiving websocket connections ... I missed this part.
Websocket connections from the PBX are received inside your WebserverPluginWebsocketListenResult function, but the path and registeredPathForRequest there won't contain the query arguments if the connection has been established by the PBX!

Instead you create your LineSelectorSession object as usual and implement the AppWebsocketAppInfo callback there.
The app parameter there will contain the query arguments.

void LineSelectorSession::AppWebsocketAppInfo(const char * app, class json_io & msg, word base)
{
}

Greetings,
Daniel
← You can define your color theme preference here