| 1 |
/*************************************************************************** |
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
| 2 |
menu.c - description |
/* |
| 3 |
------------------- |
* menu |
| 4 |
Copyright : (C) 2004-2025 by Leaflet |
* - configurable user interactive menu feature |
| 5 |
Email : leaflet@leafok.com |
* |
| 6 |
***************************************************************************/ |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
|
*/ |
| 8 |
/*************************************************************************** |
|
| 9 |
* * |
#ifdef HAVE_CONFIG_H |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
#include "config.h" |
| 11 |
* it under the terms of the GNU General Public License as published by * |
#endif |
|
* the Free Software Foundation; either version 3 of the License, or * |
|
|
* (at your option) any later version. * |
|
|
* * |
|
|
***************************************************************************/ |
|
| 12 |
|
|
| 13 |
#include "bbs.h" |
#include "bbs.h" |
| 14 |
#include "bbs_cmd.h" |
#include "bbs_cmd.h" |
| 28 |
#include <sys/ipc.h> |
#include <sys/ipc.h> |
| 29 |
#include <sys/shm.h> |
#include <sys/shm.h> |
| 30 |
|
|
| 31 |
#define MENU_SCREEN_PATH_PREFIX "var/MENU_SCR_" |
enum _menu_constant_t |
| 32 |
#define MENU_CONF_DELIM_WITH_SPACE " ,\t\r\n" |
{ |
| 33 |
#define MENU_CONF_DELIM_WITHOUT_SPACE "\r\n" |
MENU_SET_RESERVED_LENGTH = sizeof(int16_t) * 4, |
| 34 |
|
MENU_SHMGET_RETRY_LIMIT = 10, |
| 35 |
#define MENU_SET_RESERVED_LENGTH (sizeof(int16_t) * 4) |
}; |
| 36 |
|
|
| 37 |
#define MENU_SHMGET_RETRY_LIMIT 3 |
static const char MENU_CONF_DELIM_WITH_SPACE[] = " ,\t\r\n"; |
| 38 |
|
static const char MENU_CONF_DELIM_WITHOUT_SPACE[] = "\r\n"; |
| 39 |
|
|
| 40 |
MENU_SET bbs_menu; |
MENU_SET bbs_menu; |
| 41 |
MENU_SET top10_menu; |
MENU_SET top10_menu; |
| 101 |
key = ftok(conf_file, proj_id + retry_cnt); |
key = ftok(conf_file, proj_id + retry_cnt); |
| 102 |
if (key == -1) |
if (key == -1) |
| 103 |
{ |
{ |
| 104 |
log_error("ftok(%s %d) error (%d)\n", conf_file, proj_id, errno); |
log_error("ftok(%s %d) error (%d)\n", conf_file, proj_id + retry_cnt, errno); |
| 105 |
return -2; |
return -3; |
| 106 |
} |
} |
| 107 |
|
|
| 108 |
p_menu_set->shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600); |
p_menu_set->shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600); |
|
|
|
| 109 |
if (p_menu_set->shmid == -1) |
if (p_menu_set->shmid == -1) |
| 110 |
{ |
{ |
| 111 |
if (errno != EEXIST || retry_cnt + 1 >= MENU_SHMGET_RETRY_LIMIT) |
if (errno != EEXIST || retry_cnt + 1 >= MENU_SHMGET_RETRY_LIMIT) |
| 112 |
{ |
{ |
| 113 |
log_error("shmget(conf_file=%s, size=%d) error (%d) %d times\n", |
log_error("shmget(conf_file=%s, size=%d) error (%d) %d times\n", |
| 114 |
conf_file, size, errno, retry_cnt + 1); |
conf_file, size, errno, retry_cnt + 1); |
| 115 |
break; |
return -3; |
| 116 |
} |
} |
| 117 |
log_error("shmget(conf_file=%s, proj_id=%d, key=0x%x, size=%d) error (%d), retry ...\n", |
log_error("shmget(conf_file=%s, proj_id=%d, key=0x%x, size=%d) error (%d), retry ...\n", |
| 118 |
conf_file, proj_id + retry_cnt, key, size, errno); |
conf_file, proj_id + retry_cnt, key, size, errno); |
| 192 |
return -1; |
return -1; |
| 193 |
} |
} |
| 194 |
p = q; |
p = q; |
| 195 |
while (isalnum(*q) || *q == '_' || *q == '-') |
while (isalnum((int)*q) || *q == '_' || *q == '-') |
| 196 |
{ |
{ |
| 197 |
q++; |
q++; |
| 198 |
} |
} |
| 275 |
else |
else |
| 276 |
{ |
{ |
| 277 |
q = p; |
q = p; |
| 278 |
while (isalnum(*q) || *q == '_' || *q == '-') |
while (isalnum((int)*q) || *q == '_' || *q == '-') |
| 279 |
{ |
{ |
| 280 |
q++; |
q++; |
| 281 |
} |
} |
| 302 |
return -1; |
return -1; |
| 303 |
} |
} |
| 304 |
p = q; |
p = q; |
| 305 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 306 |
{ |
{ |
| 307 |
q++; |
q++; |
| 308 |
} |
} |
| 321 |
return -1; |
return -1; |
| 322 |
} |
} |
| 323 |
p = q; |
p = q; |
| 324 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 325 |
{ |
{ |
| 326 |
q++; |
q++; |
| 327 |
} |
} |
| 340 |
return -1; |
return -1; |
| 341 |
} |
} |
| 342 |
p = q; |
p = q; |
| 343 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 344 |
{ |
{ |
| 345 |
q++; |
q++; |
| 346 |
} |
} |
| 359 |
return -1; |
return -1; |
| 360 |
} |
} |
| 361 |
p = q; |
p = q; |
| 362 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 363 |
{ |
{ |
| 364 |
q++; |
q++; |
| 365 |
} |
} |
| 464 |
return -1; |
return -1; |
| 465 |
} |
} |
| 466 |
p = q; |
p = q; |
| 467 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 468 |
{ |
{ |
| 469 |
q++; |
q++; |
| 470 |
} |
} |
| 483 |
return -1; |
return -1; |
| 484 |
} |
} |
| 485 |
p = q; |
p = q; |
| 486 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 487 |
{ |
{ |
| 488 |
q++; |
q++; |
| 489 |
} |
} |
| 551 |
return -1; |
return -1; |
| 552 |
} |
} |
| 553 |
p = q; |
p = q; |
| 554 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 555 |
{ |
{ |
| 556 |
q++; |
q++; |
| 557 |
} |
} |
| 570 |
return -1; |
return -1; |
| 571 |
} |
} |
| 572 |
p = q; |
p = q; |
| 573 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 574 |
{ |
{ |
| 575 |
q++; |
q++; |
| 576 |
} |
} |
| 589 |
return -1; |
return -1; |
| 590 |
} |
} |
| 591 |
p = q; |
p = q; |
| 592 |
while (isalnum(*q) || *q == '_' || *q == '-') |
while (isalnum((int)*q) || *q == '_' || *q == '-') |
| 593 |
{ |
{ |
| 594 |
q++; |
q++; |
| 595 |
} |
} |
| 619 |
return -1; |
return -1; |
| 620 |
} |
} |
| 621 |
p = q; |
p = q; |
| 622 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 623 |
{ |
{ |
| 624 |
q++; |
q++; |
| 625 |
} |
} |
| 638 |
return -1; |
return -1; |
| 639 |
} |
} |
| 640 |
p = q; |
p = q; |
| 641 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 642 |
{ |
{ |
| 643 |
q++; |
q++; |
| 644 |
} |
} |
| 657 |
return -1; |
return -1; |
| 658 |
} |
} |
| 659 |
p = q; |
p = q; |
| 660 |
while (isdigit(*q)) |
while (isdigit((int)*q)) |
| 661 |
{ |
{ |
| 662 |
q++; |
q++; |
| 663 |
} |
} |
| 703 |
p_screen = get_menu_screen_by_id(p_menu_set, screen_id); |
p_screen = get_menu_screen_by_id(p_menu_set, screen_id); |
| 704 |
|
|
| 705 |
q = p; |
q = p; |
| 706 |
while (isalnum(*q) || *q == '_' || *q == '-') |
while (isalnum((int)*q) || *q == '_' || *q == '-') |
| 707 |
{ |
{ |
| 708 |
q++; |
q++; |
| 709 |
} |
} |
| 1389 |
|
|
| 1390 |
detach_menu_shm(p_menu_set); |
detach_menu_shm(p_menu_set); |
| 1391 |
|
|
| 1392 |
if (shmctl(shmid, IPC_RMID, NULL) == -1) |
if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1) |
| 1393 |
{ |
{ |
| 1394 |
log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno); |
log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno); |
| 1395 |
return -1; |
return -1; |
| 1428 |
void *p_shm; |
void *p_shm; |
| 1429 |
|
|
| 1430 |
// Remap shared memory in read-only mode |
// Remap shared memory in read-only mode |
| 1431 |
|
#if defined(__CYGWIN__) |
| 1432 |
|
if (shmdt(p_menu_set->p_reserved) == -1) |
| 1433 |
|
{ |
| 1434 |
|
log_error("shmdt() error (%d)\n", errno); |
| 1435 |
|
return -1; |
| 1436 |
|
} |
| 1437 |
|
p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY); |
| 1438 |
|
#else |
| 1439 |
p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY | SHM_REMAP); |
p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY | SHM_REMAP); |
| 1440 |
|
#endif |
| 1441 |
if (p_shm == (void *)-1) |
if (p_shm == (void *)-1) |
| 1442 |
{ |
{ |
| 1443 |
log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno); |
log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno); |