Example #1
0
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;
}
Example #2
0
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;
}