int def_set(struct userrec *u, struct user_entry *e, void *buf) { char *string = (char *) buf; if (string && !string[0]) string = NULL; if (!string && !e->u.string) return 1; if (string) { int l = strlen(string); char *i; e->u.string = user_realloc(e->u.string, l + 1); strncpyz(e->u.string, string, l + 1); for (i = e->u.string; *i; i++) /* Allow bold, inverse, underline, color text here... * But never add cr or lf!! --rtc */ if ((unsigned int) *i < 32 && !strchr("\002\003\026\037", *i)) *i = '?'; } else { nfree(e->u.string); e->u.string = NULL; } if (!noshare && !(u->flags & (USER_BOT | USER_UNSHARED))) { if (e->type != &USERENTRY_INFO || share_greet) shareout(NULL, "c %s %s %s\n", e->type->name, u->handle, e->u.string ? e->u.string : ""); } return 1; }
int del_note_ignore(struct userrec *u, char *mask) { struct user_entry *ue; struct xtra_key *xk; char **ignores, *buf = NULL; int ignoresn, i, size = 0, foundit = 0; ignoresn = get_note_ignores(u, &ignores); if (!ignoresn) return 0; buf = user_malloc(1); buf[0] = 0; for (i = 0; i < ignoresn; i++) { if (strcmp(ignores[i], mask)) { size += strlen(ignores[i]); if (buf[0]) size++; buf = user_realloc(buf, size + 1); if (buf[0]) strcat(buf, " "); strcat(buf, ignores[i]); } else foundit = 1; } nfree(ignores[0]); /* Free the string buffer */ nfree(ignores); /* Free the ptr array */ /* Entry not found */ if (!foundit) { nfree(buf); return 0; } ue = find_user_entry(&USERENTRY_XTRA, u); /* Delete the entry if the buffer is empty */ xk = user_malloc(sizeof(struct xtra_key)); xk->key = user_malloc(strlen(NOTES_IGNKEY) + 1); xk->next = 0; if (!buf[0]) { nfree(buf); /* The allocated byte needs to be free'd too */ strcpy(xk->key, NOTES_IGNKEY); xk->data = 0; } else { xk->data = buf; strcpy(xk->key, NOTES_IGNKEY); } xtra_set(u, ue, xk); return 1; }
int add_note_ignore(struct userrec *u, char *mask) { struct xtra_key *xk; char **ignores; int ignoresn, i; ignoresn = get_note_ignores(u, &ignores); if (ignoresn > 0) { /* Search for existing mask */ for (i = 0; i < ignoresn; i++) if (!strcmp(ignores[i], mask)) { nfree(ignores[0]); /* Free the string buffer */ nfree(ignores); /* Free the ptr array */ /* The mask already exists, exit. */ return 0; } nfree(ignores[0]); /* Free the string buffer */ nfree(ignores); /* Free the ptr array */ } xk = getnotesentry(u); /* First entry? */ if (!xk) { struct xtra_key *mxk = user_malloc(sizeof(struct xtra_key)); struct user_entry *ue = find_user_entry(&USERENTRY_XTRA, u); if (!ue) return 0; mxk->next = 0; mxk->data = user_malloc(strlen(mask) + 1); strcpy(mxk->data, mask); mxk->key = user_malloc(strlen(NOTES_IGNKEY) + 1); strcpy(mxk->key, NOTES_IGNKEY); xtra_set(u, ue, mxk); } else { /* ... else, we already have other entries. */ xk->data = user_realloc(xk->data, strlen(xk->data) + strlen(mask) + 2); strcat(xk->data, " "); strcat(xk->data, mask); } return 1; }
char *ssl_fpconv(char *in, char *out) { long len; char *fp; unsigned char *md5; if (!in) return NULL; if ((md5 = string_to_hex(in, &len))) { fp = hex_to_string(md5, len); if (fp) { out = user_realloc(out, strlen(fp) + 1); strcpy(out, fp); OPENSSL_free(md5); OPENSSL_free(fp); return out; } OPENSSL_free(md5); } return NULL; }