Skip to content

Commit 9800ff8

Browse files
authored
Merge pull request #155 from nghiadhd/master
Fix "Unknown app_id" issue by resend "forwardGetListing"
2 parents cc0cfac + acab1b3 commit 9800ff8

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

include/rpc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ rpc_status rpc_new_uuid(char **to_uuid);
2727
struct rpc_app_struct {
2828
char *app_id;
2929
char *app_name;
30+
char *host_id;
3031
bool is_proxy;
3132
};
3233
typedef struct rpc_app_struct *rpc_app_t;
34+
rpc_app_t rpc_new_app();
35+
void rpc_free_app(rpc_app_t app);
36+
rpc_status rpc_copy_app(rpc_app_t app, rpc_app_t *to_app);
3337

3438
struct rpc_page_struct {
3539
uint32_t page_id;

src/ios_webkit_debug_proxy.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct iwdp_iport_struct {
100100
// null if the device is detached
101101
iwdp_iwi_t iwi;
102102
};
103+
103104
typedef struct iwdp_iport_struct *iwdp_iport_t;
104105
iwdp_iport_t iwdp_iport_new();
105106
void iwdp_iport_free(iwdp_iport_t iport);
@@ -119,12 +120,14 @@ struct iwdp_iwi_struct {
119120
char *connection_id;
120121

121122
rpc_t rpc; // plist parser
123+
rpc_app_t app;
122124

123125
bool connected;
124126
uint32_t max_page_num; // > 0
125127
ht_t app_id_to_true; // set of app_ids
126128
ht_t page_num_to_ipage;
127129
};
130+
128131
iwdp_iwi_t iwdp_iwi_new(bool is_sim, bool *is_debug);
129132
void iwdp_iwi_free(iwdp_iwi_t iwi);
130133

@@ -175,6 +178,7 @@ struct iwdp_ifs_struct {
175178
// static server
176179
int fs_fd;
177180
};
181+
178182
iwdp_ifs_t iwdp_ifs_new();
179183
void iwdp_ifs_free(iwdp_ifs_t ifs);
180184

@@ -196,6 +200,7 @@ struct iwdp_ipage_struct {
196200
// owner is iport->ws_id_to_iws
197201
iwdp_iws_t iws;
198202
};
203+
199204
iwdp_ipage_t iwdp_ipage_new();
200205
void iwdp_ipage_free(iwdp_ipage_t ipage);
201206
int iwdp_ipage_cmp(const void *a, const void *b);
@@ -255,6 +260,8 @@ void iwdp_log_disconnect(iwdp_iport_t iport) {
255260
}
256261
}
257262

263+
#define SAFARI_NAME "Safari"
264+
258265
//
259266
// device_listener
260267
//
@@ -473,6 +480,7 @@ iwdp_status iwdp_iport_accept(iwdp_t self, iwdp_iport_t iport, int ws_fd,
473480
*to_iws = iws;
474481
return IWDP_SUCCESS;
475482
}
483+
476484
iwdp_status iwdp_on_accept(iwdp_t self, int s_fd, void *value,
477485
int fd, void **to_value) {
478486
int type = ((iwdp_type_t)value)->type;
@@ -1165,6 +1173,12 @@ rpc_status iwdp_add_app_id(rpc_t rpc, const char *app_id) {
11651173
}
11661174

11671175
rpc_status iwdp_on_applicationConnected(rpc_t rpc, const rpc_app_t app) {
1176+
if (!strcmp(app->app_name, SAFARI_NAME)) {
1177+
iwdp_iwi_t iwi = (iwdp_iwi_t)rpc->state;
1178+
rpc_app_t to_app = NULL;
1179+
rpc_copy_app(app, &to_app);
1180+
iwi->app = to_app;
1181+
}
11681182
return iwdp_add_app_id(rpc, app->app_id);
11691183
}
11701184

@@ -1264,6 +1278,7 @@ rpc_status iwdp_remove_app_id(rpc_t rpc, const char *app_id) {
12641278
free(old_app_id);
12651279
return RPC_SUCCESS;
12661280
}
1281+
12671282
rpc_status iwdp_on_applicationDisconnected(rpc_t rpc, const rpc_app_t app) {
12681283
return iwdp_remove_app_id(rpc, app->app_id);
12691284
}
@@ -1305,6 +1320,11 @@ rpc_status iwdp_on_applicationSentListing(rpc_t rpc,
13051320
return RPC_ERROR; // Inspector closed?
13061321
}
13071322
if (!ht_get_value(iwi->app_id_to_true, app_id)) {
1323+
iwdp_iwi_t iwi = (iwdp_iwi_t)rpc->state;
1324+
rpc_app_t app = iwi->app;
1325+
if (app && !strcmp(app->app_name, SAFARI_NAME)) {
1326+
return rpc->send_forwardGetListing(rpc, iwi->connection_id, app->app_id);
1327+
}
13081328
return self->on_error(self, "Unknown app_id %s", app_id);
13091329
}
13101330
ht_t ipage_ht = iwi->page_num_to_ipage;
@@ -1411,6 +1431,7 @@ void iwdp_free(iwdp_t self) {
14111431
free(self);
14121432
}
14131433
}
1434+
14141435
iwdp_t iwdp_new(const char *frontend) {
14151436
iwdp_t self = (iwdp_t)malloc(sizeof(struct iwdp_struct));
14161437
iwdp_private_t my = (iwdp_private_t)malloc(sizeof(struct iwdp_private));
@@ -1442,6 +1463,7 @@ void iwdp_idl_free(iwdp_idl_t idl) {
14421463
free(idl);
14431464
}
14441465
}
1466+
14451467
iwdp_idl_t iwdp_idl_new() {
14461468
iwdp_idl_t idl = (iwdp_idl_t)malloc(sizeof(struct iwdp_idl_struct));
14471469
dl_t dl = dl_new();
@@ -1468,6 +1490,7 @@ void iwdp_iport_free(iwdp_iport_t iport) {
14681490
free(iport);
14691491
}
14701492
}
1493+
14711494
iwdp_iport_t iwdp_iport_new() {
14721495
iwdp_iport_t iport = (iwdp_iport_t)malloc(sizeof(struct iwdp_iport_struct));
14731496
if (!iport) {
@@ -1493,6 +1516,7 @@ int iwdp_iport_cmp(const void *a, const void *b) {
14931516
uint32_t pb = ipb->port;
14941517
return (pa == pb ? 0 : pa < pb ? -1 : 1);
14951518
}
1519+
14961520
char *iwdp_iports_to_text(iwdp_iport_t *iports, bool want_json,
14971521
const char *host) {
14981522
// count ports
@@ -1583,6 +1607,7 @@ void iwdp_iwi_free(iwdp_iwi_t iwi) {
15831607
if (iwi) {
15841608
wi_free(iwi->wi);
15851609
rpc_free(iwi->rpc);
1610+
rpc_free_app(iwi->app);
15861611
// TODO free ht_values?
15871612
free(iwi->connection_id);
15881613
ht_free(iwi->app_id_to_true);
@@ -1591,6 +1616,7 @@ void iwdp_iwi_free(iwdp_iwi_t iwi) {
15911616
free(iwi);
15921617
}
15931618
}
1619+
15941620
iwdp_iwi_t iwdp_iwi_new(bool is_sim, bool *is_debug) {
15951621
iwdp_iwi_t iwi = (iwdp_iwi_t)malloc(sizeof(struct iwdp_iwi_struct));
15961622
if (!iwi) {
@@ -1633,6 +1659,7 @@ void iwdp_iws_free(iwdp_iws_t iws) {
16331659
free(iws);
16341660
}
16351661
}
1662+
16361663
iwdp_iws_t iwdp_iws_new(bool *is_debug) {
16371664
iwdp_iws_t iws = (iwdp_iws_t)malloc(sizeof(struct iwdp_iws_struct));
16381665
if (!iws) {
@@ -1664,6 +1691,7 @@ void iwdp_ifs_free(iwdp_ifs_t ifs) {
16641691
free(ifs);
16651692
}
16661693
}
1694+
16671695
iwdp_ifs_t iwdp_ifs_new() {
16681696
iwdp_ifs_t ifs = (iwdp_ifs_t)malloc(sizeof(struct iwdp_ifs_struct));
16691697
if (ifs) {
@@ -1684,6 +1712,7 @@ void iwdp_ipage_free(iwdp_ipage_t ipage) {
16841712
free(ipage);
16851713
}
16861714
}
1715+
16871716
iwdp_ipage_t iwdp_ipage_new() {
16881717
iwdp_ipage_t ipage = (iwdp_ipage_t)malloc(sizeof(struct iwdp_ipage_struct));
16891718
if (ipage) {

src/rpc.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ void rpc_free(rpc_t self) {
538538
free(self);
539539
}
540540
}
541+
541542
rpc_t rpc_new() {
542543
rpc_t self = (rpc_t)malloc(sizeof(struct rpc_struct));
543544
if (!self) {
@@ -563,6 +564,7 @@ rpc_app_t rpc_new_app() {
563564
}
564565
return app;
565566
}
567+
566568
void rpc_free_app(rpc_app_t app) {
567569
if (app) {
568570
free(app->app_id);
@@ -571,6 +573,20 @@ void rpc_free_app(rpc_app_t app) {
571573
free(app);
572574
}
573575
}
576+
577+
rpc_status rpc_copy_app(rpc_app_t app, rpc_app_t *to_app) {
578+
rpc_app_t new_app = (to_app ? rpc_new_app() : NULL);
579+
if (!new_app) {
580+
return RPC_ERROR;
581+
}
582+
583+
new_app->app_id = strdup(app->app_id);
584+
new_app->app_name = strdup(app->app_name);
585+
new_app->is_proxy = app->is_proxy;
586+
*to_app = new_app;
587+
return RPC_SUCCESS;
588+
}
589+
574590
rpc_status rpc_parse_app(const plist_t node, rpc_app_t *to_app) {
575591
rpc_app_t app = (to_app ? rpc_new_app() : NULL);
576592
if (!app ||
@@ -590,7 +606,6 @@ rpc_status rpc_parse_app(const plist_t node, rpc_app_t *to_app) {
590606
return RPC_SUCCESS;
591607
}
592608

593-
594609
void rpc_free_apps(rpc_app_t *apps) {
595610
if (apps) {
596611
rpc_app_t *a = apps;
@@ -600,6 +615,7 @@ void rpc_free_apps(rpc_app_t *apps) {
600615
free(apps);
601616
}
602617
}
618+
603619
rpc_status rpc_parse_apps(const plist_t node, rpc_app_t **to_apps) {
604620
if (!to_apps) {
605621
return RPC_ERROR;

0 commit comments

Comments
 (0)