Ejemplo n.º 1
0
static int _http_get_info (const char *filename, struct File_Info *info)
{
	if (!filename || !info)
		return -1;

	if (!strcmp (filename, CDS_LOCATION))
	{
		set_info_file (info, CDS_DESCRIPTION_LEN, SERVICE_CONTENT_TYPE);
		return 0;
	}

	if (!strcmp (filename, CMS_LOCATION))
	{
		set_info_file (info, CMS_DESCRIPTION_LEN, SERVICE_CONTENT_TYPE);
		return 0;
	}
#if 0
	if (!strcmp (filename, MSR_LOCATION))
	{
		set_info_file (info, MSR_DESCRIPTION_LEN, SERVICE_CONTENT_TYPE);
		return 0;
	}
#endif
	int ret;
	Dms_WaitLock();
	ret = _http_get_local_file_info(filename, info);
	Dms_PostLock();
	return ret;
}
Ejemplo n.º 2
0
static int
http_get_info (const char *filename, struct File_Info *info)
{
  extern struct ushare_t *ut;
  struct upnp_entry_t *entry = NULL;
  struct stat st;
  int upnp_id = 0;
  char *content_type = NULL;
  char *protocol = NULL;
  
  if (!filename || !info)
    return -1;

  log_verbose ("http_get_info, filename : %s\n", filename);

  if (!strcmp (filename, CDS_LOCATION))
  {
    set_info_file (info, CDS_DESCRIPTION_LEN, SERVICE_CONTENT_TYPE);
    return 0;
  }

  if (!strcmp (filename, CMS_LOCATION))
  {
    set_info_file (info, CMS_DESCRIPTION_LEN, SERVICE_CONTENT_TYPE);
    return 0;
  }

  if (!strcmp (filename, MSR_LOCATION))
  {
    set_info_file (info, MSR_DESCRIPTION_LEN, SERVICE_CONTENT_TYPE);
    return 0;
  }

  if (ut->use_presentation && !strcmp (filename, USHARE_PRESENTATION_PAGE))
  {
    if (build_presentation_page (ut) < 0)
      return -1;

    set_info_file (info, ut->presentation->len, PRESENTATION_PAGE_CONTENT_TYPE);
    return 0;
  }

  if (ut->use_presentation && !strncmp (filename, USHARE_CGI, strlen (USHARE_CGI)))
  {
    if (process_cgi (ut, (char *) (filename + strlen (USHARE_CGI) + 1)) < 0)
      return -1;

   set_info_file (info, ut->presentation->len, PRESENTATION_PAGE_CONTENT_TYPE);
    return 0;
  }

  upnp_id = atoi (strrchr (filename, '/') + 1);
  entry = upnp_get_entry (ut, upnp_id);
  if (!entry)
    return -1;

  if (!entry->fullpath)
    return -1;

  if (stat (entry->fullpath, &st) < 0)
    return -1;

  if (access (entry->fullpath, R_OK) < 0)
  {
    if (errno != EACCES)
      return -1;
    info->is_readable = 0;
  }
  else
    info->is_readable = 1;

  /* file exist and can be read */
  info->file_length = st.st_size;
  info->last_modified = st.st_mtime;
  info->is_directory = S_ISDIR (st.st_mode);

  protocol = 
#ifdef HAVE_DLNA
    entry->dlna_profile ?
    dlna_write_protocol_info (DLNA_PROTOCOL_INFO_TYPE_HTTP,
                              DLNA_ORG_PLAY_SPEED_NORMAL,
                              DLNA_ORG_CONVERSION_NONE,
                              DLNA_ORG_OPERATION_RANGE,
                              ut->dlna_flags, entry->dlna_profile) :
#endif /* HAVE_DLNA */
    mime_get_protocol (entry->mime_type);

  content_type =
    strndup ((protocol + PROTOCOL_TYPE_PRE_SZ),
             strlen (protocol + PROTOCOL_TYPE_PRE_SZ)
             - PROTOCOL_TYPE_SUFF_SZ);
  free (protocol);

  if (content_type)
  {
    info->content_type = ixmlCloneDOMString (content_type);
    free (content_type);
  }
  else
    info->content_type = ixmlCloneDOMString ("");

  return 0;
}
Ejemplo n.º 3
0
// We should not override the options specified in the command line
int parseInfodConfFile(infod_cmdline_t *opts) {

     conf_file_t cf;


     if(!(cf = cf_new(validVarNames))) {
	  fprintf(stderr, "Error generating conf file object\n");
	  return 0;
     }
     printf("Parsing configuration file [%s]\n", opts->opt_confFile);
     if(access(opts->opt_confFile, R_OK) != 0) {
	  fprintf(stderr, "Error: configuration files [%s] does not exists or is not readable\n",
		  opts->opt_confFile);
	  return 0;
     }
     
     if(!cf_parseFile(cf, opts->opt_confFile)) {
	  fprintf(stderr, "Error parsing configuration file\n");
	  return 0;
     }

     conf_var_t ent;
     int        intVal;
     if(cf_getVar(cf, "provider", &ent)) 
	     set_provider(ent.varValue);
     if(cf_getVar(cf, "myip", &ent)) 
	     set_my_ip(ent.varValue);
     if(cf_getVar(cf, "port", &ent)) {
          if(!getInt(ent.varValue, &intVal)) {
               fprintf(stderr, "Error: parameter port is not an integer\n");
               return 0;
          }
          set_port(&intVal);
     }
     if(cf_getVar(cf, "maptype", &ent)) 
	     set_map_type(ent.varValue);
     if(cf_getVar(cf, "mapfile", &ent)) 
	     set_map_file(ent.varValue);
     if(cf_getVar(cf, "mapcmd", &ent)) 
	     set_map_cmd(ent.varValue);
     if(cf_getVar(cf, "timestep", &ent)) {
          if(!getInt(ent.varValue, &intVal)) {
               fprintf(stderr, "Error: parameter timestep is not an integer\n");
               return 0;
          }
          set_time_step(&intVal);
     }
     if(cf_getVar(cf, "gossip-algo", &ent)) 
	     set_gossip_algo(ent.varValue);
     if(cf_getVar(cf, "wintype", &ent)) 
	     set_win_type(ent.varValue);
     if(cf_getVar(cf, "winparam", &ent)) 
	     set_win_param(ent.varValue);

     if(cf_getVar(cf, "avgage", &ent)) {
          if(!getInt(ent.varValue, &intVal)) {
               fprintf(stderr, "Error: parameter avgage is not an integer\n");
               return 0;
          }
          set_avgage(&intVal);
     }
     
     if(cf_getVar(cf, "avgmax", &ent)) {
          if(!getInt(ent.varValue, &intVal)) {
               fprintf(stderr, "Error: parameter avgmax is not an integer\n");
               return 0;
          }
          set_avgmax(&intVal);
     }
     
     if(cf_getVar(cf, "upto-entries", &ent)) {
          if(!getInt(ent.varValue, &intVal)) {
               fprintf(stderr, "Error: parameter upto-entries is not an integer\n");
               return 0;
          }
          set_uptoentries(&intVal);
     }

     if(cf_getVar(cf, "watch-fs", &ent)) 
	     set_watch_fs(ent.varValue);
     if(cf_getVar(cf, "watch-net", &ent)) 
	     set_watch_net(ent.varValue);
     if(cf_getVar(cf, "info-file", &ent)) 
	     set_info_file(ent.varValue);
     if(cf_getVar(cf, "eco-file", &ent)) 
	     set_eco_file(ent.varValue);
     if(cf_getVar(cf, "proc-file", &ent)) 
	     set_proc_file(ent.varValue);
     if(cf_getVar(cf, "jmig-file", &ent)) 
	  set_jmig_file(ent.varValue);
     

     cf_free(cf);
	
	

     return 1;
}