static void http_player_state_txt(struct shttpd_arg* arg) { HTTPAccess* access = (HTTPAccess*)arg->user_data; int i; shttpd_printf(arg, "HTTP/1.1 200 OK\r\n"); shttpd_printf(arg, "Content-type: text/plain\r\n\r\n"); PTHREAD_MUTEX_LOCK(&access->playerStateMutex); shttpd_printf(arg, "length=%"PRId64"\n", access->currentFrameInfo.sourceLength); shttpd_printf(arg, "availableLength=%"PRId64"\n", access->currentFrameInfo.availableSourceLength); shttpd_printf(arg, "position=%"PRId64"\n", access->currentFrameInfo.position); shttpd_printf(arg, "startOffset=%"PRId64"\n", access->currentFrameInfo.startOffset); shttpd_printf(arg, "vtrErrorLevel=%u\n", access->currentFrameInfo.vtrErrorLevel); shttpd_printf(arg, "numMarkSelections=%d\n", access->currentFrameInfo.numMarkSelections); for (i = 0; i < access->currentFrameInfo.numMarkSelections; i++) { shttpd_printf(arg, "markFilter_%d=%u\n", i, access->currentFrameInfo.markTypeMasks[i]); } PTHREAD_MUTEX_UNLOCK(&access->playerStateMutex); arg->flags |= SHTTPD_END_OF_OUTPUT; }
void show_geolocation(struct shttpd_arg *arg) { char location[256]; CGPSController* gps = CGPSController::Instance(); gps->TurnGpsOn(); gps->UpdateTimeout(); if (gps->IsKnownPosition()) { double latitude = gps->GetLatitude(); double longitude = gps->GetLongitude(); sprintf(location,"%.4f° %s, %.4f° %s;%f;%f", fabs(latitude),latitude < 0 ? "South" : "North", fabs(longitude),longitude < 0 ? "West" : "East", latitude,longitude); } else { strcpy(location,"reading...;reading...;reading..."); } printf("Location: %s\n",location); shttpd_printf(arg, "%s", "HTTP/1.1 200 OK\r\n"); shttpd_printf(arg, "Content-Length: %lu\r\n", strlen(location)); shttpd_printf(arg, "%s", "Connection: close\r\n"); shttpd_printf(arg, "%s", "Pragma: no-cache\r\n" ); shttpd_printf(arg, "%s", "Cache-Control: no-cache\r\n" ); shttpd_printf(arg, "%s", "Expires: 0\r\n" ); shttpd_printf(arg, "%s", "Content-Type: text/html; charset=ISO-8859-4\r\n\r\n"); shttpd_printf(arg, "%s", location); arg->flags |= SHTTPD_END_OF_OUTPUT; }
static void http_player_page(struct shttpd_arg* arg) { HTTPAccess* access = (HTTPAccess*)arg->user_data; const HTTPAccessResource* playerPage = har_get_resource(access->resources, "player_page"); if (playerPage != NULL) { shttpd_printf(arg, "HTTP/1.1 200 OK\r\n"); shttpd_printf(arg, "Content-Type: %s\r\n\r\n", playerPage->contentType); shttpd_printf(arg, "%s", (const char*)playerPage->data); } /* else TODO return error */ arg->flags |= SHTTPD_END_OF_OUTPUT; }
static void http_static_content(struct shttpd_arg* arg) { HTTPAccess* access = (HTTPAccess*)arg->user_data; const char* requestURI; requestURI = shttpd_get_env(arg, "REQUEST_URI"); const HTTPAccessResource* content = har_get_resource(access->resources, requestURI); if (content != NULL) { shttpd_printf(arg, "HTTP/1.1 200 OK\r\n"); shttpd_printf(arg, "Content-Type: %s\r\n\r\n", content->contentType); /* TODO: don't assume content size < buffer size */ memcpy(&arg->out.buf[arg->out.num_bytes], content->data, content->dataSize); arg->out.num_bytes += content->dataSize; } /* else TODO return error */ arg->flags |= SHTTPD_END_OF_OUTPUT; }
static void http_player_state_txt(struct shttpd_arg* arg) { HTTPAccess* access = (HTTPAccess*)arg->user_data; shttpd_printf(arg, "HTTP/1.1 200 OK\r\n"); shttpd_printf(arg, "Content-type: text/plain\r\n\r\n"); PTHREAD_MUTEX_LOCK(&access->playerStateMutex); shttpd_printf(arg, "length=%"PRId64"\n", access->currentFrameInfo.sourceLength); shttpd_printf(arg, "availableLength=%"PRId64"\n", access->currentFrameInfo.availableSourceLength); shttpd_printf(arg, "position=%"PRId64"\n", access->currentFrameInfo.position); shttpd_printf(arg, "startOffset=%"PRId64"\n", access->currentFrameInfo.startOffset); shttpd_printf(arg, "vtrErrorLevel=%u\n", access->currentFrameInfo.vtrErrorLevel); PTHREAD_MUTEX_UNLOCK(&access->playerStateMutex); arg->flags |= SHTTPD_END_OF_OUTPUT; }
void example_shttpd_callback(struct shttpd_arg *arg) { const char *query; query = shttpd_get_env(arg, "QUERY_STRING" ); if ( !query ) query = ""; /* fprintf( stderr, "RTEMS Request -%s-\n", query ); */ if ( !strcmp( query, "cpuuse_report" ) ) { shttpd_printf( arg, "<pre>" ); rtems_cpu_usage_report_with_plugin( arg, (rtems_printk_plugin_t) shttpd_printf ); shttpd_printf( arg, "</pre>" ); } else if ( !strcmp( query, "cpuuse_reset" ) ) { rtems_cpu_usage_reset(); shttpd_printf( arg, START_HTML_BODY " <p><big>CPU Usage data reset -- return to the previous page</big></p>" END_HTML_BODY ); } else if ( !strcmp( query, "stackuse_report" ) ) { shttpd_printf( arg, "<pre>" ); rtems_stack_checker_report_usage_with_plugin( arg, (rtems_printk_plugin_t) shttpd_printf ); shttpd_printf( arg, "</pre>" ); } else { shttpd_printf( arg, START_HTML_BODY " <h2>Unknown Request</h2>" " <h3>URI: %s</br>" " Arguments: %s</h3>" END_HTML_BODY, shttpd_get_env(arg, "REQUEST_URI"), query ); } arg->flags |= SHTTPD_END_OF_OUTPUT; }
static void http_player_state_xml(struct shttpd_arg* arg) { HTTPAccess* access = (HTTPAccess*)arg->user_data; shttpd_printf(arg, "HTTP/1.1 200 OK\r\n"); shttpd_printf(arg, "Content-type: application/xml\r\n\r\n"); PTHREAD_MUTEX_LOCK(&access->playerStateMutex); shttpd_printf(arg, "<?xml version='1.0'?>\n"); shttpd_printf(arg, "<player_state>\n"); shttpd_printf(arg, " <timecode>%02d:%02d:%02d:%02d</timecode>\n", access->currentFrameInfo.timecodes[0].timecode.hour, access->currentFrameInfo.timecodes[0].timecode.min, access->currentFrameInfo.timecodes[0].timecode.sec, access->currentFrameInfo.timecodes[0].timecode.frame); shttpd_printf(arg, "</player_state>\n"); PTHREAD_MUTEX_UNLOCK(&access->playerStateMutex); arg->flags |= SHTTPD_END_OF_OUTPUT; }
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; }
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(strstr(arg -> in.buf, "sysUserName") != 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; } char compare[strlen(ADMIN) + 2]; sprintf(compare, "%s:", ADMIN); while(fgets(line, LINE_LEN, fp) != NULL) { 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; } 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; } char compare[strlen(ADMIN) + 2]; sprintf(compare, "%s:", USER); while(fgets(line, LINE_LEN, fp) != NULL) { 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; }