void ssi_get_userinfo(struct shttpd_arg *arg) { FILE *fp = NULL; if(strstr(arg -> in.buf, "curUserName") != NULL) { int fd; char buffer[4096]; if((fd = open(SESSIONFILE, O_RDONLY)) < 0) goto err; memset(buffer, 0, sizeof buffer); if(read(fd, buffer, sizeof buffer) < 0) goto err; struct loginInfo *LoginInfo = (struct loginInfo *)buffer; struct loginOneItem *FirstItem = (struct loginOneItem *)LoginInfo->data; struct loginOneItem *Item = NULL; if(LoginInfo->ItemCount <= 0) goto err; Item = FirstItem + LoginInfo->ItemCount - 1; shttpd_printf(arg, "%s", Item->UserName); close(fd); goto out; err: close(fd); shttpd_printf(arg, "%s", NULL); goto out; #if 0 #define CGI_VERIFY #if defined(DIGEST_VERIFY) const char * const cur_user = shttpd_get_env(arg, "REMOTE_USER"); DBG((stderr, "===> cur_user_digest = %s\n", cur_user)); shttpd_printf(arg, "%s", cur_user == NULL ? "NULL" : cur_user); goto out; #elif defined(CGI_VERIFY) DBG((stderr, "===> Enter %s", __FUNCTION__)); fp = fopen(SESSIONFILE, "r"); if(fp == NULL) { DBG((stderr, "===> Open file %s error: %s", SESSIONFILE, strerror(errno))); shttpd_printf(arg, "%s", NULL); goto out; } char line[LINE_LEN]; char value[LINE_LEN]; char tmp[FILENAME_MAX]; while(fgets(line, LINE_LEN, fp) != NULL) { if(strstr(line, "#"))/* remark line */ continue; if(strstr(line, shttpd_get_env(arg, "REMOTE_ADDR")) != NULL) { strsplit(line, value, LINE_LEN, ':', 1); DBG((stderr, "===> cur_user_cgi = %s\n", value)); shttpd_printf(arg, "%s", value); goto out; } } shttpd_printf(arg, "%s", NULL); goto out; #endif #endif } if(strstr(arg -> in.buf, "sysUserName") != NULL) { shttpd_printf(arg, "%s", ADMIN); goto out; } if(strstr(arg -> in.buf, "usrUserName") != NULL) { char line[LINE_LEN]; const char * prev; const char * next; if((fp = fopen(HTPASSWDPATH, "r")) == NULL) { DBG((stderr, "===> File open error: %s", strerror(errno))); shttpd_printf(arg, "get user name error"); goto out; } while(fgets(line, LINE_LEN, fp) != NULL) { char compare[strlen(ADMIN) + 2]; sprintf(compare, "%s:", ADMIN); if(strstr(line, compare) != NULL) /* admin user */ continue; else { prev = line; next = strchr(line, TOKEN); if(next != prev) { char tmp[next - prev + 1]; memset(tmp, '\0', next -prev + 1); memcpy(tmp, prev, next - prev); DBG((stderr, "===> User name = %s", tmp)); shttpd_printf(arg, "%s", tmp); goto out; } shttpd_printf(arg, "Password file format error"); goto out; } } shttpd_printf(arg, "NULL"); /* Not enough user */ goto out; } shttpd_printf(arg, "Unknow Command\n"); out: arg->flags |= SHTTPD_END_OF_OUTPUT; if(fp != NULL) fclose(fp); return; }
static void http_player_control(struct shttpd_arg* arg) { HTTPAccess* access = (HTTPAccess*)arg->user_data; const char* requestURI; char queryValue[64]; int64_t offset = 0; int whence = SEEK_SET; int speed = 1; PlayUnit unit = FRAME_PLAY_UNIT; int forward = 1; int queryOk; int queryValueCount; int pause = 0; float factor; int64_t duration; int toggle = 1; int markType = 0; int64_t position = 0; unsigned int markTypeMask = 0; int vtrErrorLevel = 0; int selection = 0; requestURI = shttpd_get_env(arg, "REQUEST_URI"); if (strcmp("/player/control/play", requestURI) == 0) { mc_play(access->control); } else if (strcmp("/player/control/stop", requestURI) == 0) { mc_stop(access->control); } else if (strcmp("/player/control/pause", requestURI) == 0) { mc_pause(access->control); } else if (strcmp("/player/control/toggle-play-pause", requestURI) == 0) { mc_toggle_play_pause(access->control); } else if (strcmp("/player/control/seek", requestURI) == 0) { queryOk = 1; queryValueCount = 0; if (get_query_value(arg, "offset", queryValue, sizeof(queryValue))) { if (!parse_int64(queryValue, &offset)) { queryOk = 0; } else { queryValueCount++; } } if (get_query_value(arg, "whence", queryValue, sizeof(queryValue))) { queryValueCount++; if (strcmp("SEEK_SET", queryValue) == 0) { whence = SEEK_SET; } else if (strcmp("SEEK_CUR", queryValue) == 0) { whence = SEEK_CUR; } else if (strcmp("SEEK_END", queryValue) == 0) { whence = SEEK_END; } else { queryOk = 0; } } if (get_query_value(arg, "unit", queryValue, sizeof(queryValue))) { queryValueCount++; if (strcmp("FRAME_PLAY_UNIT", queryValue) == 0) { unit = FRAME_PLAY_UNIT; } else if (strcmp("PERCENTAGE_PLAY_UNIT", queryValue) == 0) { unit = PERCENTAGE_PLAY_UNIT; } else { queryOk = 0; } } if (get_query_value(arg, "pause", queryValue, sizeof(queryValue))) { if (strcmp("true", queryValue) == 0) { pause = 1; } } if (queryOk && queryValueCount == 3) { if (pause) { mc_pause(access->control); } mc_seek(access->control, offset, whence, unit); } } else if (strcmp("/player/control/play-speed", requestURI) == 0) { queryOk = 1; queryValueCount = 0; if (get_query_value(arg, "speed", queryValue, sizeof(queryValue))) { queryValueCount++; if ((speed = atoi(queryValue)) == 0) { queryOk = 0; } } if (get_query_value(arg, "unit", queryValue, sizeof(queryValue))) { queryValueCount++; if (strcmp("FRAME_PLAY_UNIT", queryValue) == 0) { unit = FRAME_PLAY_UNIT; } else if (strcmp("PERCENTAGE_PLAY_UNIT", queryValue) == 0) { unit = PERCENTAGE_PLAY_UNIT; } else { queryOk = 0; } } if (queryOk && queryValueCount == 2) { mc_play_speed(access->control, speed, unit); } } else if (strcmp("/player/control/play-speed-factor", requestURI) == 0) { queryOk = 1; queryValueCount = 0; factor = 0.0; if (get_query_value(arg, "factor", queryValue, sizeof(queryValue))) { queryValueCount++; factor = (float)(atof(queryValue)); if (factor == 0.0) { queryOk = 0; } } if (queryOk && queryValueCount == 1) { mc_play_speed_factor(access->control, factor); } } else if (strcmp("/player/control/step", requestURI) == 0) { queryOk = 1; queryValueCount = 0; if (get_query_value(arg, "forward", queryValue, sizeof(queryValue))) { queryValueCount++; if (strcmp("true", queryValue) == 0) { forward = 1; } else if (strcmp("false", queryValue) == 0) { forward = 0; } else { queryOk = 0; } } if (get_query_value(arg, "unit", queryValue, sizeof(queryValue))) { queryValueCount++; if (strcmp("FRAME_PLAY_UNIT", queryValue) == 0) { unit = FRAME_PLAY_UNIT; } else if (strcmp("PERCENTAGE_PLAY_UNIT", queryValue) == 0) { unit = PERCENTAGE_PLAY_UNIT; } else { queryOk = 0; } } if (queryOk && queryValueCount == 2) { mc_step(access->control, forward, unit); } } else if (strcmp("/player/control/home", requestURI) == 0) { if (get_query_value(arg, "pause", queryValue, sizeof(queryValue))) { if (strcmp("true", queryValue) == 0) { mc_pause(access->control); } } mc_seek(access->control, 0, SEEK_SET, FRAME_PLAY_UNIT); } else if (strcmp("/player/control/end", requestURI) == 0) { if (get_query_value(arg, "pause", queryValue, sizeof(queryValue))) { if (strcmp("true", queryValue) == 0) { mc_pause(access->control); } } mc_seek(access->control, 0, SEEK_END, FRAME_PLAY_UNIT); } else if (strcmp("/player/control/prev-mark", requestURI) == 0) { mc_seek_prev_mark(access->control); } else if (strcmp("/player/control/next-mark", requestURI) == 0) { mc_seek_next_mark(access->control); } else if (strcmp("/player/control/clip-mark", requestURI) == 0) { mc_seek_clip_mark(access->control); } else if (strcmp("/player/control/mark-position", requestURI) == 0) { queryOk = 1; queryValueCount = 0; if (get_query_value(arg, "position", queryValue, sizeof(queryValue))) { if (!parse_int64(queryValue, &position) || position < 0) { queryOk = 0; } else { queryValueCount++; } } if (get_query_value(arg, "type", queryValue, sizeof(queryValue))) { queryValueCount++; markType = atoi(queryValue); } if (get_query_value(arg, "toggle", queryValue, sizeof(queryValue))) { queryValueCount++; if (strcmp("true", queryValue) == 0) { toggle = 1; } else if (strcmp("false", queryValue) == 0) { toggle = 0; } else { queryOk = 0; } } if (queryOk && queryValueCount == 3) { mc_mark_position(access->control, position, markType, toggle); } } else if (strcmp("/player/control/clear-mark-position", requestURI) == 0) { queryOk = 1; queryValueCount = 0; if (get_query_value(arg, "position", queryValue, sizeof(queryValue))) { if (!parse_int64(queryValue, &position) || position < 0) { queryOk = 0; } else { queryValueCount++; } } if (get_query_value(arg, "type", queryValue, sizeof(queryValue))) { queryValueCount++; markTypeMask = atoi(queryValue); } if (queryOk && queryValueCount == 2) { mc_clear_mark_position(access->control, position, markTypeMask); } } else if (strcmp("/player/control/next-show-marks", requestURI) == 0) { queryOk = 1; selection = 0; if (get_query_value(arg, "sel", queryValue, sizeof(queryValue))) { if (!parse_int(queryValue, &selection)) { queryOk = 0; } } if (queryOk) { mc_next_show_marks(access->control, selection); } } else if (strcmp("/player/control/set-vtr-error-level", requestURI) == 0) { queryOk = 1; queryValueCount = 0; if (get_query_value(arg, "level", queryValue, sizeof(queryValue))) { if (!parse_int(queryValue, &vtrErrorLevel) || vtrErrorLevel < VTR_NO_ERROR_LEVEL || vtrErrorLevel > VTR_NO_GOOD_LEVEL) { queryOk = 0; } else { queryValueCount++; } } if (queryOk && queryValueCount == 1) { mc_set_vtr_error_level(access->control, (VTRErrorLevel)vtrErrorLevel); } } else if (strcmp("/player/control/next-vtr-error-level", requestURI) == 0) { mc_next_vtr_error_level(access->control); } else if (strcmp("/player/control/next-osd-screen", requestURI) == 0) { mc_next_osd_screen(access->control); } else if (strcmp("/player/control/next-osd-timecode", requestURI) == 0) { mc_next_osd_timecode(access->control); } else if (strcmp("/player/control/review", requestURI) == 0) { queryOk = 1; queryValueCount = 0; if (get_query_value(arg, "duration", queryValue, sizeof(queryValue))) { if (!parse_int64(queryValue, &duration) || duration <= 0) { queryOk = 0; } else { queryValueCount++; } } if (queryOk && queryValueCount == 1) { mc_review(access->control, duration); } } else if (strcmp("/player/control/next-marks-selection", requestURI) == 0) { mc_next_active_mark_selection(access->control); } shttpd_printf(arg, "HTTP/1.1 200 OK\r\n\r\n"); arg->flags |= SHTTPD_END_OF_OUTPUT; }