main() { content_add("c"); content_print(); content_add("a"); content_print(); Content *f= content_add("b"); map_add(&(f->bhead),2,4); map_add(&(f->bhead),7,5); map_add(&(f->bhead),3,2); content_print(); content_add("d"); content_print(); }
/* remember a file block using next available cache block */ int remember_fblock(const char *name, int fblock, const char *block) { Content *f; Map *b; int cblock; if (strlen(name)>255) { flog("name %s too long",name); return FALSE; } if (!block) { flog("can't read from NULL pointer"); return FALSE; } f = content_add(name); if ((b=content_fblock_stored(f,fblock))) { cblock=b->cblock; flog("reused old cache block %d",cblock); } else { cblock=next_cblock(); flog("chose new cache block %d",cblock); } storage_put(cblock, (const char *)block); map_add(&(f->bhead),fblock,cblock); flog("stored block %d of %s (cblock %d)",fblock,name,cblock); return TRUE; }
/* map a file block to a specific cache block */ int remember_fblock_at_cblock(const char *name, int fblock, int cblock, const char *block) { Content *f, *g; if (strlen(name)>255) { flog("name %s too long",name); return FALSE; } if (cblock<0 || cblock>=storage_blocks) { flog("cache block %d does not exist",cblock); return FALSE; } f = content_add(name); if ((g=clist_cblock_used(cblock))) { Map *b=content_cblock_used(g,cblock); flog("cache block %d in use for (%s %d) (removing)",cblock,g->name,b->fblock); content_forget_cblock(g,cblock); } Map *b; if ((b=content_fblock_stored(f,fblock))) { flog("file block %d already stored for file %s (local %d) (removing)",fblock,f->name,b->cblock); storage_forget(b->cblock); content_forget_fblock(f,fblock); } storage_put(cblock, (const char *)block); map_add(&(f->bhead),fblock,cblock); flog("stored block %d of %s (cblock %d)",fblock,name,cblock); return TRUE; }
static int tmpl_select(struct _select_def *conf) { int i; POINT *pts; struct _select_def grouplist_conf; clear(); t_now = conf->pos - 1; if (ptemplate[t_now].tmpl->content_num == 0) { char ans[3]; clear(); getdata(t_lines - 1, 0, "本模板现在没有内容,需要现在增加吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true); if (ans[0] != 'Y' && ans[0] != 'y') { return SHOW_REFRESH; } if (content_add() < 0) { return SHOW_REFRESH; } } pts = (POINT *) malloc(sizeof(POINT) * BBS_PAGESIZE); for (i = 0; i < BBS_PAGESIZE; i++) { pts[i].x = 2; pts[i].y = i + 3; } bzero(&grouplist_conf, sizeof(struct _select_def)); grouplist_conf.item_count = ptemplate[t_now].tmpl->content_num; grouplist_conf.item_per_page = BBS_PAGESIZE; /* * 加上 LF_VSCROLL 才能用 LEFT 键退出 */ grouplist_conf.flag = LF_VSCROLL | LF_BELL | LF_LOOP | LF_MULTIPAGE; grouplist_conf.prompt = "◆"; grouplist_conf.item_pos = pts; grouplist_conf.title_pos.x = 0; grouplist_conf.title_pos.y = 0; grouplist_conf.pos = 1; /* initialize cursor on the first mailgroup */ grouplist_conf.page_pos = 1; /* initialize page to the first one */ grouplist_conf.show_data = content_show; grouplist_conf.pre_key_command = tmpl_prekey; grouplist_conf.key_command = content_key; grouplist_conf.show_title = content_refresh; grouplist_conf.get_data = content_getdata; list_select_loop(&grouplist_conf); free(pts); t_now = 0; return SHOW_REFRESH; }
int process_cgi (struct ushare_t *ut, char *cgiargs) { char *action = NULL; int refresh = 0; if (!ut || !cgiargs) return -1; if (strncmp (cgiargs, CGI_ACTION, strlen (CGI_ACTION))) return -1; action = cgiargs + strlen (CGI_ACTION); if (!strncmp (action, CGI_ACTION_ADD, strlen (CGI_ACTION_ADD))) { char *path = NULL; path = action + strlen (CGI_ACTION_ADD) + 1; if (path && !strncmp (path, CGI_PATH"=", strlen (CGI_PATH) + 1)) { ut->contentlist = content_add (ut->contentlist, path + strlen (CGI_PATH) + 1); refresh = 1; } } else if (!strncmp (action, CGI_ACTION_DEL, strlen (CGI_ACTION_DEL))) { char *shares,*share; char *m_buffer = NULL, *buffer; int num, shift=0; shares = strdup (action + strlen (CGI_ACTION_DEL) + 1); m_buffer = (char*) malloc (strlen (shares) * sizeof (char)); if (m_buffer) { buffer = m_buffer; for (share = strtok_r (shares, "&", &buffer) ; share ; share = strtok_r (NULL, "&", &buffer)) { if (sscanf (share, CGI_SHARE"[%d]=on", &num) < 0) continue; ut->contentlist = content_del (ut->contentlist, num - shift++); } free (m_buffer); } refresh = 1; free (shares); } else if (!strncmp (action, CGI_ACTION_REFRESH, strlen (CGI_ACTION_REFRESH))) refresh = 1; if (refresh && ut->contentlist) { free_metadata_list (ut); build_metadata_list (ut); } if (ut->presentation) buffer_free (ut->presentation); ut->presentation = buffer_new (); buffer_append (ut->presentation, "<html>"); buffer_append (ut->presentation, "<head>"); buffer_appendf (ut->presentation, "<title>%s</title>", _("uShare Information Page")); buffer_append (ut->presentation, "<meta http-equiv=\"pragma\" content=\"no-cache\"/>"); buffer_append (ut->presentation, "<meta http-equiv=\"expires\" content=\"1970-01-01\"/>"); buffer_append (ut->presentation, "<meta http-equiv=\"refresh\" content=\"0; URL=/web/ushare.html\"/>"); buffer_append (ut->presentation, "</head>"); buffer_append (ut->presentation, "</html>"); return 0; }
static int content_key(struct _select_def *conf, int key) { int oldmode; switch (key) { case 'm': { char ans[5]; int newm; getdata(t_lines-1, 0, "移动到新次序:", ans, 4, DOECHO, NULL, true); if (ans[0]=='\0' || ans[0]=='\n' || ans[0]=='\r') return SHOW_REFRESH; newm=atoi(ans); if (newm <= 0 || newm > ptemplate[t_now].tmpl->content_num) return SHOW_REFRESH; if (newm > conf->pos) { int i; struct s_content sc; memcpy(&sc, &ptemplate[t_now].cont[conf->pos-1], sizeof(struct s_content)); for (i=conf->pos; i<newm; i++) memcpy(& ptemplate[t_now].cont[i-1], & ptemplate[t_now].cont[i], sizeof(struct s_content)); memcpy(&ptemplate[t_now].cont[newm-1], &sc, sizeof(struct s_content)); tmpl_save(); return SHOW_REFRESH; } else if (newm < conf->pos) { int i; struct s_content sc; memcpy(&sc, &ptemplate[t_now].cont[conf->pos-1], sizeof(struct s_content)); for (i=conf->pos; i>newm; i--) memcpy(& ptemplate[t_now].cont[i-1], & ptemplate[t_now].cont[i-2], sizeof(struct s_content)); memcpy(&ptemplate[t_now].cont[newm-1], &sc, sizeof(struct s_content)); tmpl_save(); return SHOW_REFRESH; } else return SHOW_REFRESH; } case 'a': if (ptemplate[t_now].tmpl->content_num >= MAX_CONTENT) { char ans[STRLEN]; move(t_lines - 1, 0); clrtoeol(); a_prompt(-1, "选项已满,按回车继续 << ", ans); move(t_lines - 1, 0); clrtoeol(); return SHOW_CONTINUE; } content_add(); return SHOW_DIRCHANGE; break; case 'd': { char ans[3]; getdata(t_lines - 1, 0, "确实要删除吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true); if (ans[0] == 'Y' || ans[0] == 'y') { int i=0; struct s_content *ct; if (ptemplate[t_now].tmpl->content_num == 1) { ptemplate[t_now].tmpl->content_num = 0; free(ptemplate[t_now].cont); tmpl_save(); return SHOW_QUIT; } ct = (struct s_content *) malloc(sizeof(struct s_content) * (ptemplate[t_now].tmpl->content_num-1)); memcpy(ct+i,&(ptemplate[t_now].cont[i]),sizeof(struct s_content) *(conf->pos-1)); for (i=conf->pos-1; i<ptemplate[t_now].tmpl->content_num-1; i++) memcpy(ct+i, &(ptemplate[t_now].cont[i+1]), sizeof(struct s_content)); free(ptemplate[t_now].cont); ptemplate[t_now].cont = ct; ptemplate[t_now].tmpl->content_num --; tmpl_save(); return SHOW_DIRCHANGE; } return SHOW_REFRESH; } case 't' : { char newtitle[60]; strcpy(newtitle, ptemplate[t_now].cont[conf->pos-1].text); getdata(t_lines - 1, 0, "新标题: ", newtitle, 50, DOECHO, NULL, false); if (newtitle[0] == '\0' || newtitle[0]=='\n' || ! strcmp(newtitle,ptemplate[t_now].cont[conf->pos-1].text)) return SHOW_REFRESH; strncpy(ptemplate[t_now].cont[conf->pos-1].text, newtitle, 50); ptemplate[t_now].cont[conf->pos-1].text[49]='\0'; tmpl_save(); return SHOW_REFRESH; } break; case 'l' : { char newlen[10]; int nl; sprintf(newlen,"%-3d",ptemplate[t_now].cont[conf->pos-1].length); getdata(t_lines-1, 0, "新长度: ", newlen, 5, DOECHO, NULL, false); nl = atoi(newlen); if (nl <= 0 || nl > MAX_CONTENT_LENGTH || nl == ptemplate[t_now].cont[conf->pos-1].length) return SHOW_REFRESH; ptemplate[t_now].cont[conf->pos-1].length = nl; tmpl_save(); return SHOW_REFRESH; } break; case 'w': /* by pig2532 on 2005-12-1 */ oldmode = uinfo.mode; if (!HAS_PERM(getCurrentUser(), PERM_PAGE)) break; s_msg(); modify_user_mode(oldmode); return SHOW_REFRESH; case 'u': /* by pig2532 on 2005-12-1 */ clear(); oldmode = uinfo.mode; modify_user_mode(QUERY); t_query(NULL); modify_user_mode(oldmode); return SHOW_REFRESH; case 'U': /* pig2532 2005.12.10 */ board_query(); return SHOW_REFRESH; default: break; } return SHOW_CONTINUE; }
int process_cgi (struct ushare_t *ut, char *cgiargs) { char *action = NULL; int refresh = 0; if (!ut || !cgiargs) return -1; if (strncmp (cgiargs, CGI_ACTION, strlen (CGI_ACTION))) return -1; action = cgiargs + strlen (CGI_ACTION); if (!strncmp (action, CGI_ACTION_ADD, strlen (CGI_ACTION_ADD))) { char *path = NULL; path = action + strlen (CGI_ACTION_ADD) + 1; if (path && !strncmp (path, CGI_PATH"=", strlen (CGI_PATH) + 1)) { ut->contentlist = content_add (ut->contentlist, path + strlen (CGI_PATH) + 1); refresh = 1; } } else if (!strncmp (action, CGI_ACTION_DEL, strlen (CGI_ACTION_DEL))) { char *shares,*share; char *m_buffer = NULL, *buffer; int num, shift=0; shares = strdup (action + strlen (CGI_ACTION_DEL) + 1); m_buffer = (char*) malloc (strlen (shares) * sizeof (char)); if (m_buffer) { buffer = m_buffer; for (share = strtok_r (shares, "&", &buffer) ; share ; share = strtok_r (NULL, "&", &buffer)) { if (sscanf (share, CGI_SHARE"[%d]=on", &num) < 0) continue; ut->contentlist = content_del (ut->contentlist, num - shift++); } free (m_buffer); } refresh = 1; free (shares); } else if (!strncmp (action, CGI_ACTION_REFRESH, strlen (CGI_ACTION_REFRESH))) refresh = 1; else if (!strncmp (action, CGI_WebCam_Start, strlen (CGI_WebCam_Start))) { extern pthread_mutex_t grab_ctrl_mutex; extern pthread_cond_t grab_ctrl_cond; if( videoIn.cameraname == NULL ) { if( init_dev(WebCam_DEV, 0)== 0) { pthread_mutex_lock (&grab_ctrl_mutex); pthread_cond_signal (&grab_ctrl_cond); pthread_mutex_unlock (&grab_ctrl_mutex); capFlag = 1;capOK = 0; } else { close_v4l(&videoIn); memset (&videoIn, 0, sizeof (struct vdIn)); capFlag = 0;capOK = 1; } } else { pthread_mutex_lock (&grab_ctrl_mutex); pthread_cond_signal (&grab_ctrl_cond); pthread_mutex_unlock (&grab_ctrl_mutex); capFlag = 1;capOK = 0; } } else if (!strncmp (action, CGI_WebCam_Stop, strlen (CGI_WebCam_Stop))) { extern int webcam_exit_flag,Pic_exit_flag, Mov_exit_flag; extern pthread_mutex_t Pic_mutex,Mov_mutex; extern pthread_cond_t Mov_cond,Pic_cond; capFlag = 0; if( videoIn.cameraname != NULL ) { webcam_exit_flag = 1; if( Pic_exit_flag == 1 ) { pthread_mutex_lock (&Pic_mutex); pthread_cond_signal (&Pic_cond); pthread_mutex_unlock (&Pic_mutex); } else Pic_exit_flag = 1; if( Mov_exit_flag == 1 ) { pthread_mutex_lock (&Mov_mutex); pthread_cond_signal (&Mov_cond); pthread_mutex_unlock (&Mov_mutex); } else Mov_exit_flag = 1; } } extern int scanDir_flag; if (refresh && ut->contentlist && !scanDir_flag) { scanDir_flag = 1; free_metadata_list (ut); build_metadata_list (ut); scanDir_flag = 0; } if (ut->presentation) buffer_free (ut->presentation); ut->presentation = buffer_new (); buffer_append (ut->presentation, "<html>"); buffer_append (ut->presentation, "<head>"); buffer_appendf (ut->presentation, "<title>%s</title>", _("uShare Information Page")); buffer_append (ut->presentation, "<meta http-equiv=\"pragma\" content=\"no-cache\"/>"); buffer_append (ut->presentation, "<meta http-equiv=\"expires\" content=\"1970-01-01\"/>"); buffer_append (ut->presentation, "<meta http-equiv=\"refresh\" content=\"0; URL=/web/ushare.html\"/>"); buffer_append (ut->presentation, "</head>"); buffer_append (ut->presentation, "</html>"); return 0; }