static int o_files(int f, struct path_info *info, struct fuse_file_info *fi) { int i; cmyth_conn_t control; cmyth_proglist_t list; int count; int ret = -ENOENT; pthread_mutex_lock(&mutex); if ((i=lookup_server(info->host)) < 0) { pthread_mutex_unlock(&mutex); return -ENOENT; } control = ref_hold(conn[i].control); if (conn[i].list == NULL) { list = cmyth_proglist_get_all_recorded(control); conn[i].list = list; parse_progs(conn+i); } else { list = conn[i].list; } list = ref_hold(list); pthread_mutex_unlock(&mutex); count = cmyth_proglist_get_count(list); for (i=0; i<count; i++) { cmyth_proginfo_t prog; char *pn; prog = cmyth_proglist_get_item(list, i); pn = cmyth_proginfo_pathname(prog); if (strcmp(pn+1, info->file) == 0) { if (do_open(prog, fi, f) < 0) { ref_release(pn); ref_release(prog); goto out; } ref_release(pn); ref_release(prog); ret = 0; goto out; } ref_release(pn); ref_release(prog); } out: ref_release(control); ref_release(list); return ret; }
static int rd_files(struct path_info *info, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { int i; cmyth_conn_t control; cmyth_proglist_t list; int count; pthread_mutex_lock(&mutex); if ((i=lookup_server(info->host)) < 0) { pthread_mutex_unlock(&mutex); return 0; } control = ref_hold(conn[i].control); if (conn[i].list == NULL) { list = cmyth_proglist_get_all_recorded(control); conn[i].list = list; parse_progs(conn+i); } else { list = conn[i].list; } list = ref_hold(list); pthread_mutex_unlock(&mutex); count = cmyth_proglist_get_count(list); for (i=0; i<count; i++) { cmyth_proginfo_t prog; long long len; char *fn, *pn; prog = cmyth_proglist_get_item(list, i); pn = cmyth_proginfo_pathname(prog); len = cmyth_proginfo_length(prog); fn = pn+1; debug("%s(): file '%s' len %lld\n", __FUNCTION__, fn, len); filler(buf, fn, NULL, 0); ref_release(prog); ref_release(pn); } ref_release(control); ref_release(list); return 0; }
static void* event_loop(void *arg) { intptr_t i = (intptr_t)arg; char buf[128]; cmyth_event_t next; int done = 0; cmyth_conn_t event; cmyth_conn_t control; cmyth_proglist_t list; debug("%s(): event loop started\n", __FUNCTION__); pthread_mutex_lock(&mutex); pthread_detach(pthread_self()); if (!conn[i].used) { pthread_mutex_unlock(&mutex); return NULL; } event = conn[i].event; control = conn[i].control; list = conn[i].list; pthread_mutex_unlock(&mutex); while (!done) { next = cmyth_event_get(event, buf, 128); pthread_mutex_lock(&mutex); switch (next) { case CMYTH_EVENT_CLOSE: ref_release(control); ref_release(list); ref_release(event); done = 1; break; case CMYTH_EVENT_RECORDING_LIST_CHANGE: ref_release(list); list = cmyth_proglist_get_all_recorded(control); conn[i].list = list; parse_progs(conn+i); break; default: break; } pthread_mutex_unlock(&mutex); } return NULL; }
static int motherdisc_parse() { char xml_uri[512]; char sqlite_cmd[1024]; char error_num[32]; int ret = 0; DEBUG("%s, process motherdisc...\n", MOTHERDISC_XML_URI); sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"DELETE FROM Initialize;"); sqlite_execute(sqlite_cmd); // parse Initialize.xml if(0==parse_xml(initialize_uri_get(), INITIALIZE_XML, NULL)){ // parse Service.xml sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT URI FROM Initialize WHERE PushFlag='%d';", SERVICE_XML); memset(xml_uri,0,sizeof(xml_uri)); if(0==str_sqlite_read(xml_uri,sizeof(xml_uri),sqlite_cmd) && 0==parse_xml(xml_uri, SERVICE_XML, NULL)){ } else{ DEBUG("read URI or parse for %d failed\n",SERVICE_XML); // Service.xml是无关紧要的文件,即便失败也继续。 //msg_send2_UI(MOTHER_DISC_INITIALIZE_FAILED, NULL, 0); //ret = -1; } #if 0 // parse GuideList.xml sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT URI FROM Initialize WHERE PushFlag='%d';", GUIDELIST_XML); memset(xml_uri,0,sizeof(xml_uri)); if(0==str_sqlite_read(xml_uri,sizeof(xml_uri),sqlite_cmd) && 0==parse_xml(xml_uri, GUIDELIST_XML, NULL)){ } else{ DEBUG("read URI or parse for %d failed\n",GUIDELIST_XML); snprintf(error_num,sizeof(error_num),"%d",GUIDELIST_XML); msg_send2_UI(MOTHER_DISC_INITIALIZE_FAILED, error_num, strlen(error_num)); ret = -1; } #endif // parse ProductDesc.xml // 解析ProductDesc.xml时判断拒绝的节目也入库 sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"DELETE FROM ProductDesc;"); sqlite_execute(sqlite_cmd); sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT URI FROM Initialize WHERE PushFlag='%d';", PRODUCTDESC_XML); memset(xml_uri,0,sizeof(xml_uri)); if(0==str_sqlite_read(xml_uri,sizeof(xml_uri),sqlite_cmd) && 0==parse_xml(xml_uri, PRODUCTDESC_XML, NULL)){ DEBUG("parse xmls for mother disc initialize finish, waiting for programs parsing...\n"); parse_progs(); msg_send2_UI(MOTHER_DISC_INITIALIZE_SUCCESS, NULL, 0); DEBUG("parse publications for mother disc initialize finished\n"); ret = 0; } else{ DEBUG("read URI or parse for %d failed\n",PRODUCTDESC_XML); snprintf(error_num,sizeof(error_num),"%d",PRODUCTDESC_XML); msg_send2_UI(MOTHER_DISC_INITIALIZE_FAILED, error_num, strlen(error_num)); ret = -1; } // 只要ProductDesc.xml解析过,无论成功与否,都直接返回0。即使在失败情况下,也无需再次尝试,没有意义。 ret = 0; } else{ DEBUG("parse %d for motherdisc init failed\n", INITIALIZE_XML); snprintf(error_num,sizeof(error_num),"%d",INITIALIZE_XML); msg_send2_UI(MOTHER_DISC_INITIALIZE_FAILED, error_num, strlen(error_num)); ret = -1; } return ret; }
static int ga_all(struct path_info *info, struct stat *stbuf) { cmyth_conn_t control; cmyth_proglist_t list; int count; int i; struct myth_conn *mc; pthread_mutex_lock(&mutex); if ((i=lookup_server(info->host)) < 0) { pthread_mutex_unlock(&mutex); return -ENOENT; } control = ref_hold(conn[i].control); if (conn[i].list == NULL) { list = cmyth_proglist_get_all_recorded(control); conn[i].list = list; parse_progs(conn+i); } else { list = conn[i].list; } mc = conn+i; list = ref_hold(list); pthread_mutex_unlock(&mutex); stbuf->st_mode = S_IFLNK | 0444; stbuf->st_nlink = 1; count = cmyth_proglist_get_count(list); debug("%s(): file '%s'\n", __FUNCTION__, info->file); for (i=0; i<count; i++) { cmyth_proginfo_t prog; long long len; char *title, *s; char tmp[512]; prog = cmyth_proglist_get_item(list, i); title = cmyth_proginfo_title(prog); s = cmyth_proginfo_subtitle(prog); if (mc->progs[i].suffix > 0) { snprintf(tmp, sizeof(tmp), "%s - %s (%d).nuv", title, s, mc->progs[i].suffix); } else { snprintf(tmp, sizeof(tmp), "%s - %s.nuv", title, s); } if (strcmp(tmp, info->file) == 0) { cmyth_timestamp_t ts; time_t t; char *pn; len = cmyth_proginfo_length(prog); pn = cmyth_proginfo_pathname(prog); debug("%s(): file '%s' len %lld\n", __FUNCTION__, tmp, len); stbuf->st_size = strlen(pn); ts = cmyth_proginfo_rec_end(prog); t = cmyth_timestamp_to_unixtime(ts); stbuf->st_atime = t; stbuf->st_mtime = t; stbuf->st_ctime = t; ref_release(pn); ref_release(prog); ref_release(ts); ref_release(title); ref_release(s); ref_release(control); ref_release(list); return 0; } ref_release(prog); ref_release(title); ref_release(s); } ref_release(control); ref_release(list); return -ENOENT; }
static int ga_files(struct path_info *info, struct stat *stbuf) { cmyth_conn_t control; cmyth_proglist_t list; int count; int i; pthread_mutex_lock(&mutex); if ((i=lookup_server(info->host)) < 0) { pthread_mutex_unlock(&mutex); return -ENOENT; } control = ref_hold(conn[i].control); if (conn[i].list == NULL) { list = cmyth_proglist_get_all_recorded(control); conn[i].list = list; parse_progs(conn+i); } else { list = conn[i].list; } list = ref_hold(list); pthread_mutex_unlock(&mutex); stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; count = cmyth_proglist_get_count(list); debug("%s(): file '%s'\n", __FUNCTION__, info->file); for (i=0; i<count; i++) { cmyth_proginfo_t prog; long long len; char *pn; prog = cmyth_proglist_get_item(list, i); pn = cmyth_proginfo_pathname(prog); if (strcmp(pn+1, info->file) == 0) { cmyth_timestamp_t ts; time_t t; len = cmyth_proginfo_length(prog); debug("%s(): file '%s' len %lld\n", __FUNCTION__, pn+1, len); stbuf->st_size = len; stbuf->st_blksize = MAX_BSIZE; stbuf->st_blocks = len / MAX_BSIZE; if ((len * MAX_BSIZE) != stbuf->st_blocks) { stbuf->st_blocks++; } ts = cmyth_proginfo_rec_end(prog); t = cmyth_timestamp_to_unixtime(ts); stbuf->st_atime = t; stbuf->st_mtime = t; stbuf->st_ctime = t; ref_release(prog); ref_release(pn); ref_release(ts); ref_release(control); ref_release(list); return 0; } ref_release(prog); ref_release(pn); } ref_release(control); ref_release(list); return -ENOENT; }
static int rd_all(struct path_info *info, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { int i; cmyth_conn_t control; cmyth_proglist_t list; int count; struct myth_conn *mc; pthread_mutex_lock(&mutex); if ((i=lookup_server(info->host)) < 0) { pthread_mutex_unlock(&mutex); return 0; } control = ref_hold(conn[i].control); if (conn[i].list == NULL) { list = cmyth_proglist_get_all_recorded(control); conn[i].list = list; parse_progs(conn+i); } else { list = conn[i].list; } mc = conn+i; list = ref_hold(list); pthread_mutex_unlock(&mutex); count = cmyth_proglist_get_count(list); char *name[count]; for (i=0; i<count; i++) { cmyth_proginfo_t prog; long long len; char *fn, *pn, *t, *s; prog = cmyth_proglist_get_item(list, i); pn = cmyth_proginfo_pathname(prog); t = cmyth_proginfo_title(prog); s = cmyth_proginfo_subtitle(prog); len = cmyth_proginfo_length(prog); if (mc->progs[i].suffix == 0) { name[i] = ref_sprintf("%s - %s.nuv", t, s); } else { name[i] = ref_sprintf("%s - %s (%d).nuv", t, s, mc->progs[i].suffix); } fn = pn+1; debug("%s(): file '%s' len %lld\n", __FUNCTION__, fn, len); filler(buf, name[i], NULL, 0); ref_release(prog); ref_release(pn); ref_release(t); ref_release(s); } for (i=0; i<count; i++) { ref_release(name[i]); } ref_release(control); ref_release(list); return 0; }
static int myth_readlink(const char *path, char *buf, size_t size) { struct path_info info; int n; int i; cmyth_conn_t control; cmyth_proglist_t list; int count; struct myth_conn *mc; debug("%s(): path '%s' size %lld\n", __FUNCTION__, path, (long long)size); memset(&info, 0, sizeof(info)); if (lookup_path(path, &info) < 0) { return -ENOENT; } if (strcmp(info.dir, "all") != 0) { free_info(&info); return -ENOENT; } pthread_mutex_lock(&mutex); if ((i=lookup_server(info.host)) < 0) { free_info(&info); pthread_mutex_unlock(&mutex); return -ENOENT; } control = ref_hold(conn[i].control); if (conn[i].list == NULL) { list = cmyth_proglist_get_all_recorded(control); conn[i].list = list; parse_progs(conn+i); } else { list = conn[i].list; } mc = conn+i; list = ref_hold(list); pthread_mutex_unlock(&mutex); count = cmyth_proglist_get_count(list); for (i=0; i<count; i++) { cmyth_proginfo_t prog; char tmp[512]; char *t, *s, *pn; prog = cmyth_proglist_get_item(list, i); t = cmyth_proginfo_title(prog); s = cmyth_proginfo_subtitle(prog); pn = cmyth_proginfo_pathname(prog); if (mc->progs[i].suffix == 0) { snprintf(tmp, sizeof(tmp), "%s - %s.nuv", t, s); } else { snprintf(tmp, sizeof(tmp), "%s - %s (%d).nuv", t, s, mc->progs[i].suffix); } if (strcmp(tmp, info.file) == 0) { snprintf(tmp, sizeof(tmp), "../files%s", pn); memset(buf, 0, size); n = (strlen(tmp) > size) ? size : strlen(tmp); strncpy(buf, tmp, n); debug("%s(): link '%s' %d bytes\n", __FUNCTION__, tmp, n); ref_release(t); ref_release(s); ref_release(pn); ref_release(prog); ref_release(control); ref_release(list); free_info(&info); return 0; } ref_release(t); ref_release(s); ref_release(pn); ref_release(prog); } ref_release(control); ref_release(list); free_info(&info); return -ENOENT; }