static int mailmap_name(char *email, int email_len, char *name, int name_len) { static struct string_list *mail_map; if (!mail_map) { mail_map = xcalloc(1, sizeof(*mail_map)); read_mailmap(mail_map, NULL); } return mail_map->nr && map_user(mail_map, email, email_len, name, name_len); }
/* * Parse author/committer line in the commit object buffer */ static void get_ac_line(const char *inbuf, const char *what, struct strbuf *name, struct strbuf *mail, timestamp_t *time, struct strbuf *tz) { struct ident_split ident; size_t len, maillen, namelen; char *tmp, *endp; const char *namebuf, *mailbuf; tmp = strstr(inbuf, what); if (!tmp) goto error_out; tmp += strlen(what); endp = strchr(tmp, '\n'); if (!endp) len = strlen(tmp); else len = endp - tmp; if (split_ident_line(&ident, tmp, len)) { error_out: /* Ugh */ tmp = "(unknown)"; strbuf_addstr(name, tmp); strbuf_addstr(mail, tmp); strbuf_addstr(tz, tmp); *time = 0; return; } namelen = ident.name_end - ident.name_begin; namebuf = ident.name_begin; maillen = ident.mail_end - ident.mail_begin; mailbuf = ident.mail_begin; if (ident.date_begin && ident.date_end) *time = strtoul(ident.date_begin, NULL, 10); else *time = 0; if (ident.tz_begin && ident.tz_end) strbuf_add(tz, ident.tz_begin, ident.tz_end - ident.tz_begin); else strbuf_addstr(tz, "(unknown)"); /* * Now, convert both name and e-mail using mailmap */ map_user(&mailmap, &mailbuf, &maillen, &namebuf, &namelen); strbuf_addf(mail, "<%.*s>", (int)maillen, mailbuf); strbuf_add(name, namebuf, namelen); }
static void check_mailmap(struct string_list *mailmap, const char *contact) { const char *name, *mail; size_t namelen, maillen; struct ident_split ident; if (split_ident_line(&ident, contact, strlen(contact))) die(_("unable to parse contact: %s"), contact); name = ident.name_begin; namelen = ident.name_end - ident.name_begin; mail = ident.mail_begin; maillen = ident.mail_end - ident.mail_begin; map_user(mailmap, &mail, &maillen, &name, &namelen); if (namelen) printf("%.*s ", (int)namelen, name); printf("<%.*s>\n", (int)maillen, mail); }
static int parse_stdin_author(struct shortlog *log, struct strbuf *out, const char *in) { const char *mailbuf, *namebuf; size_t namelen, maillen; struct ident_split ident; if (split_ident_line(&ident, in, strlen(in))) return -1; namebuf = ident.name_begin; mailbuf = ident.mail_begin; namelen = ident.name_end - ident.name_begin; maillen = ident.mail_end - ident.mail_begin; map_user(&log->mailmap, &mailbuf, &maillen, &namebuf, &namelen); strbuf_add(out, namebuf, namelen); if (log->email) strbuf_addf(out, " <%.*s>", (int)maillen, mailbuf); return 0; }
uint32_t load_user(const uint8_t *elf) { Elf32_Ehdr *ehdr = (void*)elf; uint32_t res = ehdr->e_entry; Elf32_Phdr *phdr = (void *)(elf + ehdr->e_phoff); int i; for (i = 0; i < ehdr->e_phnum; i++, phdr++) { if (phdr->p_type != PT_LOAD) continue; uint32_t start = phdr->p_paddr; uint32_t fend = start + phdr->p_filesz; uint32_t mend = start + phdr->p_memsz; start &= ~0xfff; uint32_t addr; for (addr = start; addr < mend; addr += 0x1000) { map_user(addr, palloc(), !!(phdr->p_flags & PF_W)); } int j; memcpy((void*)phdr->p_paddr, elf + phdr->p_offset, phdr->p_filesz); memset((void*)fend, 0, mend-fend); } return res; }
void pp_user_info(struct pretty_print_context *pp, const char *what, struct strbuf *sb, const char *line, const char *encoding) { struct ident_split ident; char *line_end; const char *mailbuf, *namebuf; size_t namelen, maillen; int max_length = 78; /* per rfc2822 */ if (pp->fmt == CMIT_FMT_ONELINE) return; line_end = strchrnul(line, '\n'); if (split_ident_line(&ident, line, line_end - line)) return; mailbuf = ident.mail_begin; maillen = ident.mail_end - ident.mail_begin; namebuf = ident.name_begin; namelen = ident.name_end - ident.name_begin; if (pp->mailmap) map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen); if (pp->fmt == CMIT_FMT_EMAIL) { if (pp->from_ident && ident_cmp(pp->from_ident, &ident)) { struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, "From: "); strbuf_add(&buf, namebuf, namelen); strbuf_addstr(&buf, " <"); strbuf_add(&buf, mailbuf, maillen); strbuf_addstr(&buf, ">\n"); string_list_append(&pp->in_body_headers, strbuf_detach(&buf, NULL)); mailbuf = pp->from_ident->mail_begin; maillen = pp->from_ident->mail_end - mailbuf; namebuf = pp->from_ident->name_begin; namelen = pp->from_ident->name_end - namebuf; } strbuf_addstr(sb, "From: "); if (needs_rfc2047_encoding(namebuf, namelen, RFC2047_ADDRESS)) { add_rfc2047(sb, namebuf, namelen, encoding, RFC2047_ADDRESS); max_length = 76; /* per rfc2047 */ } else if (needs_rfc822_quoting(namebuf, namelen)) { struct strbuf quoted = STRBUF_INIT; add_rfc822_quoted("ed, namebuf, namelen); strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len, -6, 1, max_length); strbuf_release("ed); } else { strbuf_add_wrapped_bytes(sb, namebuf, namelen, -6, 1, max_length); } if (max_length < last_line_length(sb) + strlen(" <") + maillen + strlen(">")) strbuf_addch(sb, '\n'); strbuf_addf(sb, " <%.*s>\n", (int)maillen, mailbuf); } else { strbuf_addf(sb, "%s: %.*s%.*s <%.*s>\n", what, (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0, " ", (int)namelen, namebuf, (int)maillen, mailbuf); } switch (pp->fmt) { case CMIT_FMT_MEDIUM: strbuf_addf(sb, "Date: %s\n", show_ident_date(&ident, pp->date_mode)); break; case CMIT_FMT_EMAIL: strbuf_addf(sb, "Date: %s\n", show_ident_date(&ident, DATE_RFC2822)); break; case CMIT_FMT_FULLER: strbuf_addf(sb, "%sDate: %s\n", what, show_ident_date(&ident, pp->date_mode)); break; default: /* notin' */ break; } }
static void insert_one_record(struct shortlog *log, const char *author, const char *oneline) { const char *dot3 = log->common_repo_prefix; char *buffer, *p; struct string_list_item *item; char namebuf[1024]; char emailbuf[1024]; size_t len; const char *eol; const char *boemail, *eoemail; struct strbuf subject = STRBUF_INIT; boemail = strchr(author, '<'); if (!boemail) return; eoemail = strchr(boemail, '>'); if (!eoemail) return; /* copy author name to namebuf, to support matching on both name and email */ memcpy(namebuf, author, boemail - author); len = boemail - author; while(len > 0 && isspace(namebuf[len-1])) len--; namebuf[len] = 0; /* copy email name to emailbuf, to allow email replacement as well */ memcpy(emailbuf, boemail+1, eoemail - boemail); emailbuf[eoemail - boemail - 1] = 0; if (!map_user(&log->mailmap, emailbuf, sizeof(emailbuf), namebuf, sizeof(namebuf))) { while (author < boemail && isspace(*author)) author++; for (len = 0; len < sizeof(namebuf) - 1 && author + len < boemail; len++) namebuf[len] = author[len]; while (0 < len && isspace(namebuf[len-1])) len--; namebuf[len] = '\0'; } else len = strlen(namebuf); if (log->email) { size_t room = sizeof(namebuf) - len - 1; int maillen = strlen(emailbuf); snprintf(namebuf + len, room, " <%.*s>", maillen, emailbuf); } item = string_list_insert(namebuf, &log->list); if (item->util == NULL) item->util = xcalloc(1, sizeof(struct string_list)); /* Skip any leading whitespace, including any blank lines. */ while (*oneline && isspace(*oneline)) oneline++; eol = strchr(oneline, '\n'); if (!eol) eol = oneline + strlen(oneline); if (!prefixcmp(oneline, "[PATCH")) { char *eob = strchr(oneline, ']'); if (eob && (!eol || eob < eol)) oneline = eob + 1; } while (*oneline && isspace(*oneline) && *oneline != '\n') oneline++; format_subject(&subject, oneline, " "); buffer = strbuf_detach(&subject, NULL); if (dot3) { int dot3len = strlen(dot3); if (dot3len > 5) { while ((p = strstr(buffer, dot3)) != NULL) { int taillen = strlen(p) - dot3len; memcpy(p, "/.../", 5); memmove(p + 5, p + dot3len, taillen + 1); } } } string_list_append(buffer, item->util); }
void shortlog_insert_one_record(struct shortlog *log, const char *author, const char *oneline) { const char *dot3 = log->common_repo_prefix; char *buffer, *p; struct string_list_item *item; const char *mailbuf, *namebuf; size_t namelen, maillen; const char *eol; struct strbuf subject = STRBUF_INIT; struct strbuf namemailbuf = STRBUF_INIT; struct ident_split ident; if (split_ident_line(&ident, author, strlen(author))) return; namebuf = ident.name_begin; mailbuf = ident.mail_begin; namelen = ident.name_end - ident.name_begin; maillen = ident.mail_end - ident.mail_begin; map_user(&log->mailmap, &mailbuf, &maillen, &namebuf, &namelen); strbuf_add(&namemailbuf, namebuf, namelen); if (log->email) strbuf_addf(&namemailbuf, " <%.*s>", (int)maillen, mailbuf); item = string_list_insert(&log->list, namemailbuf.buf); if (item->util == NULL) item->util = xcalloc(1, sizeof(struct string_list)); /* Skip any leading whitespace, including any blank lines. */ while (*oneline && isspace(*oneline)) oneline++; eol = strchr(oneline, '\n'); if (!eol) eol = oneline + strlen(oneline); if (starts_with(oneline, "[PATCH")) { char *eob = strchr(oneline, ']'); if (eob && (!eol || eob < eol)) oneline = eob + 1; } while (*oneline && isspace(*oneline) && *oneline != '\n') oneline++; format_subject(&subject, oneline, " "); buffer = strbuf_detach(&subject, NULL); if (dot3) { int dot3len = strlen(dot3); if (dot3len > 5) { while ((p = strstr(buffer, dot3)) != NULL) { int taillen = strlen(p) - dot3len; memcpy(p, "/.../", 5); memmove(p + 5, p + dot3len, taillen + 1); } } } string_list_append(item->util, buffer); }
void pp_user_info(const struct pretty_print_context *pp, const char *what, struct strbuf *sb, const char *line, const char *encoding) { struct strbuf name; struct strbuf mail; struct ident_split ident; int linelen; char *line_end, *date; const char *mailbuf, *namebuf; size_t namelen, maillen; int max_length = 78; /* per rfc2822 */ unsigned long time; int tz; if (pp->fmt == CMIT_FMT_ONELINE) return; line_end = strchr(line, '\n'); if (!line_end) { line_end = strchr(line, '\0'); if (!line_end) return; } linelen = ++line_end - line; if (split_ident_line(&ident, line, linelen)) return; mailbuf = ident.mail_begin; maillen = ident.mail_end - ident.mail_begin; namebuf = ident.name_begin; namelen = ident.name_end - ident.name_begin; if (pp->mailmap) map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen); strbuf_init(&mail, 0); strbuf_init(&name, 0); strbuf_add(&mail, mailbuf, maillen); strbuf_add(&name, namebuf, namelen); namelen = name.len + mail.len + 3; /* ' ' + '<' + '>' */ time = strtoul(ident.date_begin, &date, 10); tz = strtol(date, NULL, 10); if (pp->fmt == CMIT_FMT_EMAIL) { strbuf_addstr(sb, "From: "); if (needs_rfc2047_encoding(name.buf, name.len, RFC2047_ADDRESS)) { add_rfc2047(sb, name.buf, name.len, encoding, RFC2047_ADDRESS); max_length = 76; /* per rfc2047 */ } else if (needs_rfc822_quoting(name.buf, name.len)) { struct strbuf quoted = STRBUF_INIT; add_rfc822_quoted("ed, name.buf, name.len); strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len, -6, 1, max_length); strbuf_release("ed); } else { strbuf_add_wrapped_bytes(sb, name.buf, name.len, -6, 1, max_length); } if (namelen - name.len + last_line_length(sb) > max_length) strbuf_addch(sb, '\n'); strbuf_addf(sb, " <%s>\n", mail.buf); } else { strbuf_addf(sb, "%s: %.*s%s <%s>\n", what, (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0, " ", name.buf, mail.buf); } strbuf_release(&mail); strbuf_release(&name); switch (pp->fmt) { case CMIT_FMT_MEDIUM: strbuf_addf(sb, "Date: %s\n", show_date(time, tz, pp->date_mode)); break; case CMIT_FMT_EMAIL: strbuf_addf(sb, "Date: %s\n", show_date(time, tz, DATE_RFC2822)); break; case CMIT_FMT_FULLER: strbuf_addf(sb, "%sDate: %s\n", what, show_date(time, tz, pp->date_mode)); break; default: /* notin' */ break; } }
// USER FUNCTIONS // Manages the user interaction void manage_user(int fd, int registration) { User user = None; char buffer[MAXBUF+1]; if (registration == 1) { _info("Serving the registration form."); User new_user = (struct UserType*)malloc(sizeof(struct UserType)); new_user->fd = fd; new_user->notifications = None; new_user->noti_count = 0; new_user->private_messages = None; do { _send(fd, " > Username: "******":q") == 0) { _error("Registration task was interrupted by user.."); return; } } while (find_username(Users, buffer) is_not None); new_user->username = (char*)malloc(sizeof(MAXBUF)); strcpy(new_user->username, buffer); _send(fd, " > Nome: "); _recv(fd, buffer, 1); if (strcmp(buffer, ":q") == 0) { _error("Registration task was interrupted by user.."); return; } new_user->name = (char*)malloc(sizeof(MAXBUF)); strcpy(new_user->name, buffer); _send(fd, " > Cognome: "); _recv(fd, buffer, 1); if (strcmp(buffer, ":q") == 0) { _error("Registration task was interrupted by user.."); return; } new_user->surname = (char*)malloc(sizeof(MAXBUF)); strcpy(new_user->surname, buffer); _send(fd, " > Posizione X (int): "); _recv(fd, buffer, 1); if (strcmp(buffer, ":q") == 0) { _error("Registration task was interrupted by user.."); return; } new_user->x = atoi(buffer) % 256; _send(fd, " > Posizione Y (int): "); _recv(fd, buffer, 1); if (strcmp(buffer, ":q") == 0) { _error("Registration task was interrupted by user.."); return; } new_user->y = atoi(buffer) % 256; _send(fd, " > Raggio d'Azione (int): "); _recv(fd, buffer, 1); if (strcmp(buffer, ":q") == 0) { _error("Registration task was interrupted by user.."); return; } new_user->rad = atoi(buffer) % 256; user = new_user; pthread_mutex_lock(&users_mutex); if (Users is None) { Users = (UserList)malloc(sizeof(struct UserListType)); Users->info = user; Users->next = NULL; } else { UserList N = (UserList)malloc(sizeof(struct UserListType)); N->info = user; N->next = Users; Users = N; } pthread_mutex_unlock(&users_mutex); pthread_mutex_lock(&map_mutex); map_user(user); pthread_mutex_unlock(&map_mutex); _infoUser("New user created.", user->username); } assert(user is_not None); _infoUser("User logged in.", user->username); int choice; do { memset(buffer, 0, MAXBUF); char notif[MAXBUF]; if (user->noti_count > 0) { sprintf(notif, "\n## MESSAGE SYSTEM MENU ## [Notifiche: %d]", user->noti_count); } else { sprintf(notif, "\n## MESSAGE SYSTEM MENU ##"); } strcat(notif, menu); _send(user->fd, notif); _recv(user->fd, buffer, 1); while (atoi(buffer) <= 0 or atoi(buffer) > 8) { _send(user->fd, " > "); _recv(user->fd, buffer, 1); } choice = atoi(buffer); switch (choice) { case 1: { show_users_available(user); } break; case 2: { send_public_message(user); } break; case 3: { send_private_message(user); } break; case 4: { read_public_messages(user); break; } break; case 5: { read_private_messages(user); break; } case 6: { move_user(user); } break; case 7: { read_notifications(user); } break; case 8: { return; } default: break; } } while (choice > 0 && choice < 8); }