void hts_settings_save(htsmsg_t *record, const char *pathfmt, ...) { char path[256]; char tmppath[256]; int fd; va_list ap; htsbuf_queue_t hq; htsbuf_data_t *hd; int ok; if(settingspath == NULL) return; /* Clean the path */ va_start(ap, pathfmt); _hts_settings_buildpath(path, sizeof(path), pathfmt, ap, settingspath); va_end(ap); /* Create directories */ if (hts_settings_makedirs(path)) return; tvhdebug("settings", "saving to %s", path); /* Create tmp file */ snprintf(tmppath, sizeof(tmppath), "%s.tmp", path); if((fd = tvh_open(tmppath, O_CREAT | O_TRUNC | O_RDWR, 0700)) < 0) { tvhlog(LOG_ALERT, "settings", "Unable to create \"%s\" - %s", tmppath, strerror(errno)); return; } /* Store data */ ok = 1; htsbuf_queue_init(&hq, 0); htsmsg_json_serialize(record, &hq, 1); TAILQ_FOREACH(hd, &hq.hq_q, hd_link) if(tvh_write(fd, hd->hd_data + hd->hd_data_off, hd->hd_data_len)) { tvhlog(LOG_ALERT, "settings", "Failed to write file \"%s\" - %s", tmppath, strerror(errno)); ok = 0; break; } close(fd); htsbuf_queue_flush(&hq); /* Move */ if(ok) { rename(tmppath, path); /* Delete tmp */ } else unlink(tmppath); }
void hts_settings_save(htsmsg_t *record, const char *pathfmt, ...) { char path[PATH_MAX]; char tmppath[PATH_MAX]; int fd; va_list ap; htsbuf_queue_t hq; htsbuf_data_t *hd; int ok, r, pack; if(settingspath == NULL) return; /* Clean the path */ va_start(ap, pathfmt); _hts_settings_buildpath(path, sizeof(path), pathfmt, ap, settingspath); va_end(ap); /* Create directories */ if (hts_settings_makedirs(path)) return; tvhdebug("settings", "saving to %s", path); /* Create tmp file */ snprintf(tmppath, sizeof(tmppath), "%s.tmp", path); if((fd = tvh_open(tmppath, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR)) < 0) { tvhlog(LOG_ALERT, "settings", "Unable to create \"%s\" - %s", tmppath, strerror(errno)); return; } /* Store data */ #if ENABLE_ZLIB pack = strstr(path, "/muxes/") != NULL && /* ugly, redesign API */ strstr(path, "/networks/") != NULL && strstr(path, "/input/") != NULL; #else pack = 0; #endif ok = 1; if (!pack) { htsbuf_queue_init(&hq, 0); htsmsg_json_serialize(record, &hq, 1); TAILQ_FOREACH(hd, &hq.hq_q, hd_link) if(tvh_write(fd, hd->hd_data + hd->hd_data_off, hd->hd_data_len)) { tvhlog(LOG_ALERT, "settings", "Failed to write file \"%s\" - %s", tmppath, strerror(errno)); ok = 0; break; } htsbuf_queue_flush(&hq); } else {
static void * send_report(void *aux) { htsmsg_t *m = aux; htsbuf_queue_t hq; htsbuf_queue_init(&hq, 0); htsmsg_add_msg(m, "plugins", plugins_get_installed_list()); htsmsg_json_serialize(m, &hq, 0); http_req("https://movian.tv/movian/status/v1/usage", HTTP_POSTDATA(&hq, "application/json"), NULL); htsmsg_release(m); return NULL; }