Some code reordering to placate scan-build's wrath.

This commit is contained in:
default 2022-12-14 04:55:47 +01:00
parent f5086fecd7
commit 645e7ec43e
3 changed files with 25 additions and 14 deletions

View file

@ -264,7 +264,9 @@ void process_tags(const char *content, d_char **n_content, d_char **tag)
char *p, *v; char *p, *v;
int n = 0; int n = 0;
p = split = xs_regex_split(content, "(@[A-Za-z0-9_]+@[A-Za-z0-9\\.-]+|#[^ ,\\.:;]+)"); split = xs_regex_split(content, "(@[A-Za-z0-9_]+@[A-Za-z0-9\\.-]+|#[^ ,\\.:;]+)");
p = split;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
if ((n & 0x1)) { if ((n & 0x1)) {
if (*v == '@') { if (*v == '@') {
@ -320,18 +322,24 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char
xs *published = NULL; xs *published = NULL;
/* generated values */ /* generated values */
if (date && strcmp(date, "@now") == 0) if (date && strcmp(date, "@now") == 0) {
date = published = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ"); published = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ");
date = published;
}
if (id != NULL) { if (id != NULL) {
if (strcmp(id, "@dummy") == 0) { if (strcmp(id, "@dummy") == 0) {
xs *ntid = tid(0); xs *ntid = tid(0);
id = did = xs_fmt("%s/d/%s/%s", snac->actor, ntid, type); did = xs_fmt("%s/d/%s/%s", snac->actor, ntid, type);
id = did;
} }
else else
if (strcmp(id, "@object") == 0) { if (strcmp(id, "@object") == 0) {
if (object != NULL) if (object != NULL) {
id = did = xs_fmt("%s/%s", xs_dict_get(object, "id"), type); did = xs_fmt("%s/%s", xs_dict_get(object, "id"), type);
id = did;
}
else else
id = NULL; id = NULL;
} }

View file

@ -98,8 +98,9 @@ d_char *not_really_markdown(const char *content)
char *p, *v; char *p, *v;
/* work by lines */ /* work by lines */
p = list = xs_split(content, "\n"); list = xs_split(content, "\n");
p = list;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *ss = NULL; xs *ss = NULL;

16
snac.c
View file

@ -74,17 +74,17 @@ int validate_uid(const char *uid)
void srv_debug(int level, d_char *str) void srv_debug(int level, d_char *str)
/* logs a debug message */ /* logs a debug message */
{ {
xs *msg = str; if (xs_str_in(str, srv_basedir) != -1) {
if (xs_str_in(msg, srv_basedir) != -1) {
/* replace basedir with ~ */ /* replace basedir with ~ */
msg = xs_replace_i(msg, srv_basedir, "~"); str = xs_replace_i(str, srv_basedir, "~");
} }
if (dbglevel >= level) { if (dbglevel >= level) {
xs *tm = xs_str_localtime(0, "%H:%M:%S"); xs *tm = xs_str_localtime(0, "%H:%M:%S");
fprintf(stderr, "%s %s\n", tm, msg); fprintf(stderr, "%s %s\n", tm, str);
} }
xs_free(str);
} }
@ -110,8 +110,10 @@ d_char *hash_password(const char *uid, const char *passwd, const char *nonce)
xs *combi; xs *combi;
xs *hash; xs *hash;
if (nonce == NULL) if (nonce == NULL) {
nonce = d_nonce = xs_fmt("%08x", random()); d_nonce = xs_fmt("%08x", random());
nonce = d_nonce;
}
combi = xs_fmt("%s:%s:%s", nonce, uid, passwd); combi = xs_fmt("%s:%s:%s", nonce, uid, passwd);
hash = xs_sha1_hex(combi, strlen(combi)); hash = xs_sha1_hex(combi, strlen(combi));