Skip to content

Commit f0d0d57

Browse files
committed
Use const for the logsrv message handling functions where possible.
1 parent 1f3a4c8 commit f0d0d57

File tree

9 files changed

+112
-106
lines changed

9 files changed

+112
-106
lines changed

logsrvd/iolog_writer.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#include <logsrvd.h>
5656

5757
static bool
58-
type_matches(InfoMessage *info, const char *source,
58+
type_matches(const InfoMessage *info, const char *source,
5959
InfoMessage__ValueCase value_case)
6060
{
6161
const void *val = info->u.strval; /* same for strlistval */
@@ -84,7 +84,7 @@ type_matches(InfoMessage *info, const char *source,
8484
* Returns a NULL-terminated string vector.
8585
*/
8686
static char **
87-
strlist_copy(InfoMessage__StringList *strlist)
87+
strlist_copy(const InfoMessage__StringList *strlist)
8888
{
8989
char **dst, **src = strlist->strings;
9090
size_t i, len = strlist->n_strings;
@@ -133,8 +133,8 @@ strvec_free(char *vec[])
133133
* Returns true on success and false on failure.
134134
*/
135135
struct eventlog *
136-
evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
137-
struct connection_closure *closure)
136+
evlog_new(const TimeSpec *submit_time, InfoMessage * const *info_msgs,
137+
size_t infolen, struct connection_closure *closure)
138138
{
139139
const char *source = closure->journal_path ? closure->journal_path :
140140
closure->ipaddr;
@@ -177,7 +177,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
177177

178178
/* Pull out values by key from info array. */
179179
for (idx = 0; idx < infolen; idx++) {
180-
InfoMessage *info = info_msgs[idx];
180+
const InfoMessage *info = info_msgs[idx];
181181
const char *key = info->key;
182182
switch (key[0]) {
183183
case 'c':
@@ -689,7 +689,7 @@ iolog_flush_all(struct connection_closure *closure)
689689
}
690690

691691
bool
692-
iolog_init(AcceptMessage *msg, struct connection_closure *closure)
692+
iolog_init(const AcceptMessage *msg, struct connection_closure *closure)
693693
{
694694
struct eventlog *evlog = closure->evlog;
695695
debug_decl(iolog_init, SUDO_DEBUG_UTIL);
@@ -922,7 +922,7 @@ iolog_rewrite(const struct timespec *target, struct connection_closure *closure)
922922
* We cannot use timespecadd here since delta is not struct timespec.
923923
*/
924924
void
925-
update_elapsed_time(TimeSpec *delta, struct timespec *elapsed)
925+
update_elapsed_time(const TimeSpec *delta, struct timespec *elapsed)
926926
{
927927
debug_decl(update_elapsed_time, SUDO_DEBUG_UTIL);
928928

logsrvd/logsrvd.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ schedule_error_message(const char *errstr, struct connection_closure *closure)
442442
* AcceptMessage handler.
443443
*/
444444
static bool
445-
handle_accept(AcceptMessage *msg, uint8_t *buf, size_t len,
445+
handle_accept(const AcceptMessage *msg, const uint8_t *buf, size_t len,
446446
struct connection_closure *closure)
447447
{
448448
const char *source = closure->journal_path ? closure->journal_path :
@@ -479,7 +479,7 @@ handle_accept(AcceptMessage *msg, uint8_t *buf, size_t len,
479479
* RejectMessage handler.
480480
*/
481481
static bool
482-
handle_reject(RejectMessage *msg, uint8_t *buf, size_t len,
482+
handle_reject(const RejectMessage *msg, const uint8_t *buf, size_t len,
483483
struct connection_closure *closure)
484484
{
485485
const char *source = closure->journal_path ? closure->journal_path :
@@ -512,7 +512,7 @@ handle_reject(RejectMessage *msg, uint8_t *buf, size_t len,
512512
}
513513

514514
static bool
515-
handle_exit(ExitMessage *msg, uint8_t *buf, size_t len,
515+
handle_exit(const ExitMessage *msg, const uint8_t *buf, size_t len,
516516
struct connection_closure *closure)
517517
{
518518
const char *source = closure->journal_path ? closure->journal_path :
@@ -566,7 +566,7 @@ handle_exit(ExitMessage *msg, uint8_t *buf, size_t len,
566566
}
567567

568568
static bool
569-
handle_restart(RestartMessage *msg, uint8_t *buf, size_t len,
569+
handle_restart(const RestartMessage *msg, const uint8_t *buf, size_t len,
570570
struct connection_closure *closure)
571571
{
572572
const char *source = closure->journal_path ? closure->journal_path :
@@ -608,7 +608,7 @@ handle_restart(RestartMessage *msg, uint8_t *buf, size_t len,
608608
}
609609

610610
static bool
611-
handle_alert(AlertMessage *msg, uint8_t *buf, size_t len,
611+
handle_alert(const AlertMessage *msg, const uint8_t *buf, size_t len,
612612
struct connection_closure *closure)
613613
{
614614
const char *source = closure->journal_path ? closure->journal_path :
@@ -646,7 +646,7 @@ enable_commit(struct connection_closure *closure)
646646
}
647647

648648
static bool
649-
handle_iobuf(int iofd, IoBuffer *iobuf, uint8_t *buf, size_t len,
649+
handle_iobuf(int iofd, const IoBuffer *iobuf, const uint8_t *buf, size_t len,
650650
struct connection_closure *closure)
651651
{
652652
const char *source = closure->journal_path ? closure->journal_path :
@@ -682,7 +682,7 @@ handle_iobuf(int iofd, IoBuffer *iobuf, uint8_t *buf, size_t len,
682682
}
683683

684684
static bool
685-
handle_winsize(ChangeWindowSize *msg, uint8_t *buf, size_t len,
685+
handle_winsize(const ChangeWindowSize *msg, const uint8_t *buf, size_t len,
686686
struct connection_closure *closure)
687687
{
688688
const char *source = closure->journal_path ? closure->journal_path :
@@ -718,7 +718,7 @@ handle_winsize(ChangeWindowSize *msg, uint8_t *buf, size_t len,
718718
}
719719

720720
static bool
721-
handle_suspend(CommandSuspend *msg, uint8_t *buf, size_t len,
721+
handle_suspend(const CommandSuspend *msg, const uint8_t *buf, size_t len,
722722
struct connection_closure *closure)
723723
{
724724
const char *source = closure->journal_path ? closure->journal_path :
@@ -754,7 +754,7 @@ handle_suspend(CommandSuspend *msg, uint8_t *buf, size_t len,
754754
}
755755

756756
static bool
757-
handle_client_hello(ClientHello *msg, uint8_t *buf, size_t len,
757+
handle_client_hello(const ClientHello *msg, const uint8_t *buf, size_t len,
758758
struct connection_closure *closure)
759759
{
760760
const char *source = closure->journal_path ? closure->journal_path :
@@ -776,7 +776,7 @@ handle_client_hello(ClientHello *msg, uint8_t *buf, size_t len,
776776
}
777777

778778
static bool
779-
handle_client_message(uint8_t *buf, size_t len,
779+
handle_client_message(const uint8_t *buf, size_t len,
780780
struct connection_closure *closure)
781781
{
782782
const char *source = closure->journal_path ? closure->journal_path :
@@ -1167,15 +1167,15 @@ client_msg_cb(int fd, int what, void *v)
11671167
* Format and schedule a commit_point message.
11681168
*/
11691169
bool
1170-
schedule_commit_point(TimeSpec *commit_point,
1170+
schedule_commit_point(const TimeSpec *commit_point,
11711171
struct connection_closure *closure)
11721172
{
11731173
debug_decl(schedule_commit_point, SUDO_DEBUG_UTIL);
11741174

11751175
if (closure->write_ev != NULL) {
11761176
/* Send an acknowledgement of what we've committed to disk. */
11771177
ServerMessage msg = SERVER_MESSAGE__INIT;
1178-
msg.u.commit_point = commit_point;
1178+
msg.u.commit_point = (TimeSpec *)commit_point;
11791179
msg.type_case = SERVER_MESSAGE__TYPE_COMMIT_POINT;
11801180

11811181
sudo_debug_printf(SUDO_DEBUG_INFO,

logsrvd/logsrvd.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,21 @@ struct connection_closure {
126126

127127
/* Client message switch. */
128128
struct client_message_switch {
129-
bool (*accept)(AcceptMessage *msg, uint8_t *buf, size_t len,
129+
bool (*accept)(const AcceptMessage *msg, const uint8_t *buf, size_t len,
130130
struct connection_closure *closure);
131-
bool (*reject)(RejectMessage *msg, uint8_t *buf, size_t len,
131+
bool (*reject)(const RejectMessage *msg, const uint8_t *buf, size_t len,
132132
struct connection_closure *closure);
133-
bool (*exit)(ExitMessage *msg, uint8_t *buf, size_t len,
133+
bool (*exit)(const ExitMessage *msg, const uint8_t *buf, size_t len,
134134
struct connection_closure *closure);
135-
bool (*restart)(RestartMessage *msg, uint8_t *buf, size_t len,
135+
bool (*restart)(const RestartMessage *msg, const uint8_t *buf, size_t len,
136136
struct connection_closure *closure);
137-
bool (*alert)(AlertMessage *msg, uint8_t *buf, size_t len,
137+
bool (*alert)(const AlertMessage *msg, const uint8_t *buf, size_t len,
138138
struct connection_closure *closure);
139-
bool (*iobuf)(int iofd, IoBuffer *iobuf, uint8_t *buf, size_t len,
139+
bool (*iobuf)(int iofd, const IoBuffer *iobuf, const uint8_t *buf,
140+
size_t len, struct connection_closure *closure);
141+
bool (*suspend)(const CommandSuspend *msg, const uint8_t *buf, size_t len,
140142
struct connection_closure *closure);
141-
bool (*suspend)(CommandSuspend *msg, uint8_t *buf, size_t len,
142-
struct connection_closure *closure);
143-
bool (*winsize)(ChangeWindowSize *msg, uint8_t *buf, size_t len,
143+
bool (*winsize)(const ChangeWindowSize *msg, const uint8_t *buf, size_t len,
144144
struct connection_closure *closure);
145145
};
146146

@@ -186,19 +186,19 @@ struct outgoing_journal {
186186
TAILQ_HEAD(outgoing_journal_queue, outgoing_journal);
187187

188188
/* iolog_writer.c */
189-
struct eventlog *evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen, struct connection_closure *closure);
190-
bool iolog_init(AcceptMessage *msg, struct connection_closure *closure);
189+
struct eventlog *evlog_new(const TimeSpec *submit_time, InfoMessage * const *info_msgs, size_t infolen, struct connection_closure *closure);
190+
bool iolog_init(const AcceptMessage *msg, struct connection_closure *closure);
191191
bool iolog_create(int iofd, struct connection_closure *closure);
192192
void iolog_close_all(struct connection_closure *closure);
193193
bool iolog_flush_all(struct connection_closure *closure);
194194
bool iolog_rewrite(const struct timespec *target, struct connection_closure *closure);
195-
void update_elapsed_time(TimeSpec *delta, struct timespec *elapsed);
195+
void update_elapsed_time(const TimeSpec *delta, struct timespec *elapsed);
196196

197197
/* logsrvd.c */
198198
extern struct client_message_switch cms_local;
199199
bool start_protocol(struct connection_closure *closure);
200200
void connection_close(struct connection_closure *closure);
201-
bool schedule_commit_point(TimeSpec *commit_point, struct connection_closure *closure);
201+
bool schedule_commit_point(const TimeSpec *commit_point, struct connection_closure *closure);
202202
bool fmt_log_id_message(const char *id, struct connection_closure *closure);
203203
bool schedule_error_message(const char *errstr, struct connection_closure *closure);
204204
struct connection_buffer *get_free_buf(size_t, struct connection_closure *closure);
@@ -242,14 +242,14 @@ extern struct client_message_switch cms_journal;
242242
/* logsrvd_local.c */
243243
extern struct client_message_switch cms_local;
244244
bool set_random_drop(const char *dropstr);
245-
bool store_accept_local(AcceptMessage *msg, uint8_t *buf, size_t len, struct connection_closure *closure);
246-
bool store_reject_local(RejectMessage *msg, uint8_t *buf, size_t len, struct connection_closure *closure);
247-
bool store_exit_local(ExitMessage *msg, uint8_t *buf, size_t len, struct connection_closure *closure);
248-
bool store_restart_local(RestartMessage *msg, uint8_t *buf, size_t len, struct connection_closure *closure);
249-
bool store_alert_local(AlertMessage *msg, uint8_t *buf, size_t len, struct connection_closure *closure);
250-
bool store_iobuf_local(int iofd, IoBuffer *iobuf, uint8_t *buf, size_t len, struct connection_closure *closure);
251-
bool store_winsize_local(ChangeWindowSize *msg, uint8_t *buf, size_t len, struct connection_closure *closure);
252-
bool store_suspend_local(CommandSuspend *msg, uint8_t *buf, size_t len, struct connection_closure *closure);
245+
bool store_accept_local(const AcceptMessage *msg, const uint8_t *buf, size_t len, struct connection_closure *closure);
246+
bool store_reject_local(const RejectMessage *msg, const uint8_t *buf, size_t len, struct connection_closure *closure);
247+
bool store_exit_local(const ExitMessage *msg, const uint8_t *buf, size_t len, struct connection_closure *closure);
248+
bool store_restart_local(const RestartMessage *msg, const uint8_t *buf, size_t len, struct connection_closure *closure);
249+
bool store_alert_local(const AlertMessage *msg, const uint8_t *buf, size_t len, struct connection_closure *closure);
250+
bool store_iobuf_local(int iofd, const IoBuffer *iobuf, const uint8_t *buf, size_t len, struct connection_closure *closure);
251+
bool store_winsize_local(const ChangeWindowSize *msg, const uint8_t *buf, size_t len, struct connection_closure *closure);
252+
bool store_suspend_local(const CommandSuspend *msg, const uint8_t *buf, size_t len, struct connection_closure *closure);
253253

254254
/* logsrvd_queue.c */
255255
bool logsrvd_queue_enable(time_t timeout, struct sudo_event_base *evbase);

logsrvd/logsrvd_journal.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ journal_finish(struct connection_closure *closure)
227227
* Returns true if we reached the target time exactly, else false.
228228
*/
229229
static bool
230-
journal_seek(struct timespec *target, struct connection_closure *closure)
230+
journal_seek(const struct timespec *target, struct connection_closure *closure)
231231
{
232232
ClientMessage *msg = NULL;
233233
size_t nread, bufsize = 0;
@@ -407,7 +407,7 @@ journal_seek(struct timespec *target, struct connection_closure *closure)
407407
* Returns true if we reached the target time exactly, else false.
408408
*/
409409
static bool
410-
journal_restart(RestartMessage *msg, uint8_t *buf, size_t buflen,
410+
journal_restart(const RestartMessage *msg, const uint8_t *buf, size_t buflen,
411411
struct connection_closure *closure)
412412
{
413413
struct timespec target;
@@ -455,7 +455,8 @@ journal_restart(RestartMessage *msg, uint8_t *buf, size_t buflen,
455455
}
456456

457457
static bool
458-
journal_write(uint8_t * restrict buf, size_t len, struct connection_closure * restrict closure)
458+
journal_write(const uint8_t * restrict buf, size_t len,
459+
struct connection_closure * restrict closure)
459460
{
460461
uint32_t msg_len;
461462
debug_decl(journal_write, SUDO_DEBUG_UTIL);
@@ -478,7 +479,7 @@ journal_write(uint8_t * restrict buf, size_t len, struct connection_closure * re
478479
* Store an AcceptMessage from the client in the journal.
479480
*/
480481
static bool
481-
journal_accept(AcceptMessage *msg, uint8_t *buf, size_t len,
482+
journal_accept(const AcceptMessage *msg, const uint8_t *buf, size_t len,
482483
struct connection_closure *closure)
483484
{
484485
debug_decl(journal_accept, SUDO_DEBUG_UTIL);
@@ -512,8 +513,8 @@ journal_accept(AcceptMessage *msg, uint8_t *buf, size_t len,
512513
* Store a RejectMessage from the client in the journal.
513514
*/
514515
static bool
515-
journal_reject(RejectMessage *msg, uint8_t * restrict buf, size_t len,
516-
struct connection_closure * restrict closure)
516+
journal_reject(const RejectMessage *msg, const uint8_t * restrict buf,
517+
size_t len, struct connection_closure * restrict closure)
517518
{
518519
debug_decl(journal_reject, SUDO_DEBUG_UTIL);
519520

@@ -532,7 +533,7 @@ journal_reject(RejectMessage *msg, uint8_t * restrict buf, size_t len,
532533
* Store an ExitMessage from the client in the journal.
533534
*/
534535
static bool
535-
journal_exit(ExitMessage *msg, uint8_t * restrict buf, size_t len,
536+
journal_exit(const ExitMessage *msg, const uint8_t * restrict buf, size_t len,
536537
struct connection_closure * restrict closure)
537538
{
538539
debug_decl(journal_exit, SUDO_DEBUG_UTIL);
@@ -550,7 +551,7 @@ journal_exit(ExitMessage *msg, uint8_t * restrict buf, size_t len,
550551
* Store an AlertMessage from the client in the journal.
551552
*/
552553
static bool
553-
journal_alert(AlertMessage *msg, uint8_t * restrict buf, size_t len,
554+
journal_alert(const AlertMessage *msg, const uint8_t * restrict buf, size_t len,
554555
struct connection_closure * restrict closure)
555556
{
556557
debug_decl(journal_alert, SUDO_DEBUG_UTIL);
@@ -570,8 +571,8 @@ journal_alert(AlertMessage *msg, uint8_t * restrict buf, size_t len,
570571
* Store an IoBuffer from the client in the journal.
571572
*/
572573
static bool
573-
journal_iobuf(int iofd, IoBuffer *iobuf, uint8_t * restrict buf, size_t len,
574-
struct connection_closure * restrict closure)
574+
journal_iobuf(int iofd, const IoBuffer *iobuf, const uint8_t * restrict buf,
575+
size_t len, struct connection_closure * restrict closure)
575576
{
576577
debug_decl(journal_iobuf, SUDO_DEBUG_UTIL);
577578

@@ -586,8 +587,8 @@ journal_iobuf(int iofd, IoBuffer *iobuf, uint8_t * restrict buf, size_t len,
586587
* Store a CommandSuspend message from the client in the journal.
587588
*/
588589
static bool
589-
journal_suspend(CommandSuspend *msg, uint8_t * restrict buf, size_t len,
590-
struct connection_closure * restrict closure)
590+
journal_suspend(const CommandSuspend *msg, const uint8_t * restrict buf,
591+
size_t len, struct connection_closure * restrict closure)
591592
{
592593
debug_decl(journal_suspend, SUDO_DEBUG_UTIL);
593594

@@ -600,8 +601,8 @@ journal_suspend(CommandSuspend *msg, uint8_t * restrict buf, size_t len,
600601
* Store a ChangeWindowSize message from the client in the journal.
601602
*/
602603
static bool
603-
journal_winsize(ChangeWindowSize *msg, uint8_t * restrict buf, size_t len,
604-
struct connection_closure * restrict closure)
604+
journal_winsize(const ChangeWindowSize *msg, const uint8_t * restrict buf,
605+
size_t len, struct connection_closure * restrict closure)
605606
{
606607
debug_decl(journal_winsize, SUDO_DEBUG_UTIL);
607608

0 commit comments

Comments
 (0)