void shlog_write(shbuf_t *buff, int level, int err_code, char *log_str) { static char log_path[PATH_MAX+1]; char line[640]; char *beg_line; size_t mem_size; if (!buff) return; if (!*log_path) { char *label; shpeer_t peer; memcpy(&peer, ashpeer(), sizeof(peer)); label = (!*peer.label ? PACKAGE_NAME : peer.label); sprintf(log_path, "%s%s.log", shlog_path(label), label); } if (*log_path && !_shlog_file) { _shlog_file = fopen(log_path, "ab"); } beg_line = shbuf_data(buff) + shbuf_size(buff); sprintf(line, "%s", shstrtime(shtime(), "[%x %T] ")); shbuf_catstr(buff, line); if (level == SHLOG_ERROR) { shbuf_catstr(buff, "error"); } else if (level == SHLOG_WARNING) { shbuf_catstr(buff, "warning"); } else { shbuf_catstr(buff, "info"); } if (err_code) { memset(line, 0, sizeof(line)); snprintf(line, sizeof(line) - 1, ": %s [code %d]", strerror(-(err_code)), (err_code)); shbuf_catstr(buff, line); } if (log_str) { shbuf_catstr(buff, ": "); shbuf_catstr(buff, log_str); } mem_size = shlog_mem_size(); if (mem_size > 100000) { sprintf(line, " (mem:%dm)", (mem_size / 1000)); shbuf_catstr(buff, line); } shbuf_catstr(buff, "\n"); }
int shcert_init_default(shcert_t *cert) { int i; /* certificate version */ cert->cert_ver = 3; /* certificate's issuer peer entity */ memcpy(&cert->cert_sub.ent_peer, ashpeer(), sizeof(cert->cert_sub.ent_peer)); /* set birth and expiration time-stamps */ cert->cert_sub.ent_sig.sig_stamp = shtime_adj(shtime(), -1); cert->cert_sub.ent_sig.sig_expire = shtime_adj(shtime(), SHARE_DEFAULT_EXPIRE_TIME); /* fill with random serial number */ shcert_init_serial(shcert_sub_ser(cert)); }