Skip to content

Commit e19e5ee

Browse files
committed
update
1 parent db5dc14 commit e19e5ee

File tree

2 files changed

+195
-85
lines changed

2 files changed

+195
-85
lines changed

src/applet/notification/process.c

Lines changed: 108 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "process.h"
22
#include <stdio.h>
33
#include <stdlib.h>
4-
#include <stdbool.h>
54
#include <unistd.h>
65
#include <string.h>
76
#include <errno.h>
@@ -10,89 +9,142 @@
109
#include <euicc/es10b.h>
1110
#include <euicc/es9p.h>
1211

13-
static const char *opt_string = "rh?";
14-
15-
static int applet_main(int argc, char **argv)
12+
static int _process_single(uint32_t seqNumber, uint8_t autoremove)
1613
{
17-
bool auto_remove = false;
18-
int opt = getopt(argc, argv, opt_string);
19-
while (opt != -1)
14+
int ret;
15+
char str_seqNumber[11];
16+
struct es10b_pending_notification notification;
17+
18+
snprintf(str_seqNumber, sizeof(str_seqNumber), "%u", seqNumber);
19+
20+
jprint_progress("es10b_retrieve_notifications_list", str_seqNumber);
21+
if (es10b_retrieve_notifications_list(&euicc_ctx, &notification, seqNumber))
2022
{
21-
switch (opt)
22-
{
23-
case 'r':
24-
auto_remove = true;
25-
break;
26-
case 'h':
27-
case '?':
28-
printf("Usage: %s [seqNumber] etc [OPTIONS]\r\n", argv[0]);
29-
printf("\t -r Automatically remove processed notifications\r\n");
30-
return -1;
31-
default:
32-
break;
33-
}
34-
opt = getopt(argc, argv, opt_string);
23+
jprint_error("es10b_retrieve_notifications_list", NULL);
24+
return -1;
3525
}
3626

37-
int seqNumber;
38-
char *str_seqNumber = NULL;
39-
struct es10b_pending_notification notification;
40-
int ret;
27+
euicc_ctx.http.server_address = notification.notificationAddress;
28+
29+
jprint_progress("es9p_handle_notification", str_seqNumber);
30+
if (es9p_handle_notification(&euicc_ctx, notification.b64_PendingNotification))
31+
{
32+
jprint_error("es9p_handle_notification", NULL);
33+
return -1;
34+
}
35+
36+
es10b_pending_notification_free(&notification);
4137

42-
for (int i = 1; i < argc; i++)
38+
if (!autoremove)
4339
{
44-
errno = 0;
45-
seqNumber = (int) strtol(argv[i], NULL, 10);
46-
if (errno != 0)
40+
return 0;
41+
}
42+
43+
jprint_progress("es10b_remove_notification_from_list", str_seqNumber);
44+
if ((ret = es10b_remove_notification_from_list(&euicc_ctx, seqNumber)))
45+
{
46+
const char *reason;
47+
switch (ret)
4748
{
48-
continue;
49+
case 1:
50+
reason = "seqNumber not found";
51+
break;
52+
default:
53+
reason = "unknown";
54+
break;
4955
}
50-
str_seqNumber = argv[i];
56+
jprint_error("es10b_remove_notification_from_list", reason);
57+
return -1;
58+
}
59+
60+
return 0;
61+
}
62+
63+
static int applet_main(int argc, char **argv)
64+
{
65+
static const char *opt_string = "arh?";
5166

52-
jprint_progress("es10b_retrieve_notifications_list", str_seqNumber);
53-
if (es10b_retrieve_notifications_list(&euicc_ctx, &notification, seqNumber))
67+
int fret = 0;
68+
int all = 0;
69+
int autoremove = 0;
70+
int argc_seq_offset = 1;
71+
72+
int opt = getopt(argc, argv, opt_string);
73+
for (int i = 0; opt != -1; i++)
74+
{
75+
switch (opt)
5476
{
55-
jprint_error("es10b_retrieve_notifications_list", NULL);
77+
case 'a':
78+
all = 1;
79+
break;
80+
case 'r':
81+
autoremove = 1;
82+
break;
83+
case 'h':
84+
case '?':
85+
printf("Usage: %s [OPTIONS] [seqNumber_0] [seqNumber_1]...\r\n", argv[0]);
86+
printf("\t -a All notifications\r\n");
87+
printf("\t -r Automatically remove processed notifications\r\n");
5688
return -1;
89+
default:
90+
goto run;
91+
break;
5792
}
93+
argc_seq_offset++;
94+
opt = getopt(argc, argv, opt_string);
95+
}
5896

59-
euicc_ctx.http.server_address = notification.notificationAddress;
97+
run:
98+
if (all)
99+
{
100+
struct es10b_notification_metadata_list *notifications, *rptr;
60101

61-
jprint_progress("es9p_handle_notification", str_seqNumber);
62-
if (es9p_handle_notification(&euicc_ctx, notification.b64_PendingNotification))
102+
jprint_progress("es10b_list_notification", NULL);
103+
if (es10b_list_notification(&euicc_ctx, &notifications))
63104
{
64-
jprint_error("es9p_handle_notification", NULL);
105+
jprint_error("es10b_list_notification", NULL);
65106
return -1;
66107
}
67108

68-
es10b_pending_notification_free(&notification);
69-
70-
if (!auto_remove)
109+
rptr = notifications;
110+
while (rptr)
71111
{
72-
continue;
112+
if (_process_single(rptr->seqNumber, autoremove))
113+
{
114+
fret = -1;
115+
break;
116+
}
117+
rptr = rptr->next;
73118
}
74119

75-
jprint_progress("es10b_remove_notification_from_list", str_seqNumber);
76-
if ((ret = es10b_remove_notification_from_list(&euicc_ctx, seqNumber)))
120+
es10b_notification_metadata_list_free_all(notifications);
121+
}
122+
else
123+
{
124+
for (int i = argc_seq_offset; i < argc; i++)
77125
{
78-
const char *reason;
79-
switch (ret)
126+
unsigned long seqNumber;
127+
128+
errno = 0;
129+
seqNumber = strtoul(argv[i], NULL, 10);
130+
if (errno != 0)
80131
{
81-
case 1:
82-
reason = "seqNumber not found";
83-
break;
84-
default:
85-
reason = "unknown";
86-
break;
132+
continue;
133+
}
134+
if (_process_single(seqNumber, autoremove))
135+
{
136+
fret = -1;
137+
break;
87138
}
88-
jprint_error("es10b_remove_notification_from_list", reason);
89-
return -1;
90139
}
91140
}
92141

93-
jprint_success(NULL);
142+
if (fret == 0)
143+
{
144+
jprint_success(NULL);
145+
}
94146

95-
return 0;
147+
return fret;
96148
}
97149

98150
struct applet_entry applet_notification_process = {

src/applet/notification/remove.c

Lines changed: 87 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,114 @@
88

99
#include <euicc/es10b.h>
1010

11-
static const char *opt_string = "h?";
11+
static int _delete_single(uint32_t seqNumber)
12+
{
13+
char str_seqNumber[11];
14+
int ret;
15+
16+
snprintf(str_seqNumber, sizeof(str_seqNumber), "%u", seqNumber);
17+
18+
jprint_progress("es10b_remove_notification_from_list", str_seqNumber);
19+
if ((ret = es10b_remove_notification_from_list(&euicc_ctx, seqNumber)))
20+
{
21+
const char *reason;
22+
switch (ret)
23+
{
24+
case 1:
25+
reason = "seqNumber not found";
26+
break;
27+
default:
28+
reason = "unknown";
29+
break;
30+
}
31+
jprint_error("es10b_remove_notification_from_list", reason);
32+
return -1;
33+
}
34+
35+
return 0;
36+
}
1237

1338
static int applet_main(int argc, char **argv)
1439
{
40+
static const char *opt_string = "ah?";
41+
42+
int fret = 0;
43+
int all = 0;
44+
int argc_seq_offset = 1;
45+
1546
int opt = getopt(argc, argv, opt_string);
16-
while (opt != -1)
47+
for (int i = 0; opt != -1; i++)
1748
{
1849
switch (opt)
1950
{
20-
case 'h':
21-
case '?':
22-
printf("Usage: %s [seqNumber] etc\r\n", argv[0]);
23-
return -1;
24-
default:
25-
break;
51+
case 'a':
52+
all = 1;
53+
break;
54+
case 'h':
55+
case '?':
56+
printf("Usage: %s [OPTIONS] [seqNumber_0] [seqNumber_1]...\r\n", argv[0]);
57+
printf("\t -a All notifications\r\n");
58+
return -1;
59+
default:
60+
goto run;
61+
break;
2662
}
63+
argc_seq_offset++;
2764
opt = getopt(argc, argv, opt_string);
2865
}
2966

30-
int seqNumber;
31-
int ret;
32-
33-
for (int i = 1; i < argc; i++)
67+
run:
68+
if (all)
3469
{
35-
errno = 0;
36-
seqNumber = (int) strtol(argv[i], NULL, 10);
37-
if (errno != 0)
70+
struct es10b_notification_metadata_list *notifications, *rptr;
71+
72+
jprint_progress("es10b_list_notification", NULL);
73+
if (es10b_list_notification(&euicc_ctx, &notifications))
3874
{
39-
continue;
75+
jprint_error("es10b_list_notification", NULL);
76+
return -1;
4077
}
41-
if ((ret = es10b_remove_notification_from_list(&euicc_ctx, seqNumber)))
78+
79+
rptr = notifications;
80+
while (rptr)
4281
{
43-
const char *reason;
44-
switch (ret)
82+
if (_delete_single(rptr->seqNumber))
4583
{
46-
case 1:
47-
reason = "seqNumber not found";
48-
break;
49-
default:
50-
reason = "unknown";
51-
break;
84+
fret = -1;
85+
break;
5286
}
53-
jprint_error("es10b_remove_notification_from_list", reason);
54-
return -1;
87+
rptr = rptr->next;
5588
}
89+
90+
es10b_notification_metadata_list_free_all(notifications);
5691
}
92+
else
93+
{
94+
for (int i = argc_seq_offset; i < argc; i++)
95+
{
96+
unsigned long seqNumber;
5797

58-
jprint_success(NULL);
98+
errno = 0;
99+
seqNumber = strtoul(argv[i], NULL, 10);
100+
if (errno != 0)
101+
{
102+
continue;
103+
}
59104

60-
return 0;
105+
if (_delete_single(seqNumber))
106+
{
107+
fret = -1;
108+
break;
109+
}
110+
}
111+
}
112+
113+
if (fret == 0)
114+
{
115+
jprint_success(NULL);
116+
}
117+
118+
return fret;
61119
}
62120

63121
struct applet_entry applet_notification_remove = {

0 commit comments

Comments
 (0)