int EFSSyncCreate(EFSSessionRef const session, strarg_t const syncID, EFSSyncRef *const out) { assert(out); if(!syncID) return UV_EINVAL; EFSSyncRef sync = calloc(1, sizeof(struct EFSSync)); if(!sync) return UV_ENOMEM; sync->session = session; syncID = strdup(syncID); if(!syncID) { EFSSyncFree(&sync); return UV_ENOMEM; } async_mutex_init(sync->mutex, 0); async_cond_init(sync->cond, ASYNC_CANCELABLE); sync->cur = &sync->queues[0]; int rc = async_spawn(STACK_DEFAULT, db_thread, sync); if(rc < 0) { EFSSyncFree(&sync); return rc; } *out = sync; return 0; }
SLNPullRef SLNRepoCreatePull(SLNRepoRef const repo, uint64_t const pullID, uint64_t const userID, strarg_t const host, strarg_t const sessionid, strarg_t const query) { SLNPullRef pull = calloc(1, sizeof(struct SLNPull)); if(!pull) return NULL; SLNSessionCacheRef const cache = SLNRepoGetSessionCache(repo); pull->pullID = pullID; pull->session = SLNSessionCreateInternal(cache, 0, NULL, NULL, userID, SLN_RDWR, NULL); // TODO: How to create this properly? pull->host = strdup(host); pull->cookie = aasprintf("s=%s", sessionid ? sessionid : ""); // pull->query = strdup(query); assert(!query || '\0' == query[0]); // TODO if(!pull->session || !pull->host || !pull->cookie) { SLNPullFree(&pull); return NULL; } async_mutex_init(pull->connlock, 0); async_mutex_init(pull->mutex, 0); async_cond_init(pull->cond, 0); pull->stop = true; return pull; }
BlogRef BlogCreate(SLNRepoRef const repo) { assertf(repo, "Blog requires valid repo"); BlogRef blog = calloc(1, sizeof(struct Blog)); if(!blog) return NULL; blog->repo = repo; blog->dir = aasprintf("%s/blog", SLNRepoGetDir(repo)); blog->cacheDir = aasprintf("%s/blog", SLNRepoGetCacheDir(repo)); if(!blog->dir || !blog->cacheDir) { BlogFree(&blog); return NULL; } // Automatically attempt to create a default blog resource directory. // If it fails, it's probably because it already exists. // If not, we'll find out when we try to load a template. (void)async_fs_symlink(INSTALL_PREFIX "/share/stronglink/blog", blog->dir, 0); if( !load_template(blog, "header.html", &blog->header) || !load_template(blog, "footer.html", &blog->footer) || !load_template(blog, "backlinks.html", &blog->backlinks) || !load_template(blog, "entry-start.html", &blog->entry_start) || !load_template(blog, "entry-end.html", &blog->entry_end) || !load_template(blog, "preview.html", &blog->preview) || !load_template(blog, "empty.html", &blog->empty) || !load_template(blog, "compose.html", &blog->compose) || !load_template(blog, "upload.html", &blog->upload) || !load_template(blog, "login.html", &blog->login) || !load_template(blog, "notfound.html", &blog->notfound) || !load_template(blog, "noresults.html", &blog->noresults) ) { BlogFree(&blog); return NULL; } async_mutex_init(blog->pending_mutex, 0); async_cond_init(blog->pending_cond, 0); return blog; }