static void socket_open_client(struct diag_socket_info *info) { int ret = 0; if (!info || info->port_type != PORT_TYPE_CLIENT) return; ret = sock_create(AF_MSM_IPC, SOCK_DGRAM, 0, &info->hdl); if (ret < 0 || !info->hdl) { pr_err("diag: In %s, socket not initialized for %s\n", __func__, info->name); return; } write_lock_bh(&info->hdl->sk->sk_callback_lock); info->hdl->sk->sk_user_data = (void *)(info); info->hdl->sk->sk_data_ready = socket_data_ready; info->hdl->sk->sk_write_space = socket_flow_cntl; write_unlock_bh(&info->hdl->sk->sk_callback_lock); ret = lookup_server(info); if (ret) { pr_err("diag: In %s, failed to lookup server, ret: %d\n", __func__, ret); return; } __socket_open_channel(info); DIAG_LOG(DIAG_DEBUG_PERIPHERALS, "%s exiting\n", info->name); }
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; } 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; struct stat st; prog = cmyth_proglist_get_item(list, i); pn = cmyth_proginfo_pathname(prog); len = cmyth_proginfo_length(prog); fn = pn+1; memset(&st, 0, sizeof(st)); st.st_mode = S_IFREG | 0444; st.st_size = len; debug("%s(): file '%s' len %lld\n", __FUNCTION__, fn, len); filler(buf, fn, &st, 0); ref_release(prog); ref_release(pn); } ref_release(control); ref_release(list); return 0; }
int main (int argc, char *argv[]) { struct sockaddr_in addr; if (argc < 2) { printf ("usage: %s server_host server_port\n", argv[0]); exit (1); } lookup_server (argv [1], atoi (argv[2]), &addr); run_test (&addr); exit (0); }
static int ga_all(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; } else { list = conn[i].list; } 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); 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) + 8; 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 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; 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) { return -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; } 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 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); snprintf(tmp, sizeof(tmp), "%s - %s.nuv", t, s); if (strcmp(tmp, info.file) == 0) { snprintf(tmp, sizeof(tmp), "../files%s", pn); 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); return 0; } ref_release(t); ref_release(s); ref_release(pn); ref_release(prog); } 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 rd_shows(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; } else { list = conn[i].list; } list = ref_hold(list); pthread_mutex_unlock(&mutex); count = cmyth_proglist_get_count(list); if(info->subdir) { for (i=0; i<count; i++) { cmyth_proginfo_t prog; long long len; char *fn, *pn, *t, *s; struct stat st; char tmp[512]; prog = cmyth_proglist_get_item(list, i); t = cmyth_proginfo_title(prog); if(strcmp(t, info->subdir) == 0) { pn = cmyth_proginfo_pathname(prog); s = cmyth_proginfo_subtitle(prog); len = cmyth_proginfo_length(prog); fn = pn+1; snprintf(tmp, sizeof(tmp), "%s.nuv", s); memset(&st, 0, sizeof(st)); st.st_mode = S_IFLNK | 0444; st.st_size = strlen(pn) + 8; debug("%s(): file '%s' len %lld\n", __FUNCTION__, fn, len); filler(buf, tmp, &st, 0); snprintf(tmp, sizeof(tmp), "%s.nuv.png", s); memset(&st, 0, sizeof(st)); st.st_mode = S_IFLNK | 0444; st.st_size = strlen(pn) + 8; debug("%s(): file '%s' len %lld\n", __FUNCTION__, fn, len); filler(buf, tmp, &st, 0); ref_release(pn); ref_release(s); } ref_release(prog); ref_release(t); } } else { char** seen = malloc(sizeof(char*) * count); int seen_counter, k; seen_counter = 0; memset(seen, count, sizeof(char*)); for (i=0; i<count; i++) { cmyth_proginfo_t prog; char *t; struct stat st; char found; prog = cmyth_proglist_get_item(list, i); t = cmyth_proginfo_title(prog); found = 0; for(k=0; k<seen_counter; k++) { if(strcmp(seen[k], t) == 0) { found = 1; break; } } if(!found) { seen[seen_counter] = strdup(t); seen_counter++; st.st_mode = S_IFDIR | 0555; st.st_nlink = 2; debug("%s(): dir '%s'\n", __FUNCTION__, t); filler(buf, t, &st, 0); } ref_release(prog); ref_release(t); } for(i=0; i<seen_counter; i++) { free(seen[i]); } free(seen); } ref_release(control); ref_release(list); return 0; }