示例#1
0
static void
profile_apply(GtkWidget *main_w, GtkTreeView *profile_l, gboolean destroy)
{
  const gchar *err_msg;

  if ((err_msg = apply_profile_changes()) != NULL) {
    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_msg);
    return;
  }

  profile_select(main_w, profile_l, destroy);
}
示例#2
0
int url_check_check_preview(char *preview_data, int preview_data_len,
                            ci_request_t * req)
{
     ci_headers_list_t *req_header;
     struct url_check_data *uc = ci_service_data(req);
     struct http_info httpinf;
     struct profile *profile;
     int pass = DB_PASS;

     if ((req_header = ci_http_request_headers(req)) == NULL) /*It is not possible but who knows ..... */
          return CI_ERROR;

     if (!get_http_info(req, req_header, &httpinf)) /*Unknown method or something else...*/
	 return CI_MOD_ALLOW204;

     ci_debug_printf(9, "URL  to host %s\n", httpinf.site);
     ci_debug_printf(9, "URL  page %s\n", httpinf.url);

     profile = profile_select(req);

     if (!profile) {
          ci_debug_printf(1, "No Profile configured! Allowing the request...\n");
	  return CI_MOD_ALLOW204;
     }

     if ((pass=profile_access(profile, &httpinf)) == DB_ERROR) {
          ci_debug_printf(1,"Error searching in profile! Allow the request\n");
	  return CI_MOD_ALLOW204;;
     }


     if (pass == DB_BLOCK) {
          /*The URL is not a good one so.... */
          ci_debug_printf(9, "Oh!!! we are going to deny this site.....\n");

          uc->denied = 1;
          uc->body = ci_cached_file_new(strlen(error_message) + 10);
          ci_http_response_create(req, 1, 1); /*Build the responce headers */

          ci_http_response_add_header(req, "HTTP/1.0 403 Forbidden"); /*Send an 403 Forbidden http responce to web client */
          ci_http_response_add_header(req, "Server: C-ICAP");
          ci_http_response_add_header(req, "Content-Type: text/html");
          ci_http_response_add_header(req, "Content-Language: en");
          ci_http_response_add_header(req, "Connection: close");

          ci_cached_file_write(uc->body, error_message, strlen(error_message),
                               1);

     }
     else {
          /*if we are inside preview negotiation or client allow204 responces oudsite of preview then */
          if (preview_data || ci_req_allow204(req))
               return CI_MOD_ALLOW204;

          /*
             icap client does not support preview of data in reqmod requests neither 204 responces outside preview
             so we need to read all the body if exists and send it back to client.
             Allocate a new body for it 
           */
          if (ci_req_hasbody(req)) {
               int clen = ci_http_content_length(req) + 100;
               uc->body = ci_cached_file_new(clen);
          }

     }

     unlock_data(req);
     return CI_MOD_CONTINUE;
}
示例#3
0
static void
profile_apply(GtkWidget *main_w, GtkTreeView *profile_l, gboolean destroy)
{
  char        *pf_dir_path, *pf_dir_path2;
  GList       *fl1, *fl2;
  profile_def *profile1, *profile2;
  gboolean     found;

  /* First validate all profile names */
  fl1 = g_list_first(edited_profiles);
  while (fl1) {
    found = FALSE;
    profile1 = (profile_def *) fl1->data;
    g_strstrip(profile1->name);
    if (profile_is_invalid_name(profile1->name)) {
      return;
    }
    fl1 = g_list_next(fl1);
  }

  /* Then create new and rename changed */
  fl1 = g_list_first(edited_profiles);
  while (fl1) {
    found = FALSE;
    profile1 = (profile_def *) fl1->data;
    g_strstrip(profile1->name);
    if (profile1->status == PROF_STAT_NEW) {
      /* We do not create a directory for the default profile */
      if (strcmp(profile1->name, DEFAULT_PROFILE)!=0) {
	if (create_persconffile_profile(profile1->name, &pf_dir_path) == -1) {
	  simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
			"Can't create directory\n\"%s\":\n%s.",
			pf_dir_path, strerror(errno));

	  g_free(pf_dir_path);
	}
	profile1->status = PROF_STAT_EXISTS;

	g_free (profile1->reference);
	profile1->reference = g_strdup(profile1->name);
      }
    } else if (profile1->status == PROF_STAT_CHANGED) {
      if (strcmp(profile1->reference, profile1->name)!=0) {
	/* Rename old profile directory to new */
	if (rename_persconffile_profile(profile1->reference, profile1->name,
					&pf_dir_path, &pf_dir_path2) == -1) {
	  simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
			"Can't rename directory\n\"%s\" to\n\"%s\":\n%s.",
			pf_dir_path, pf_dir_path2, strerror(errno));

	  g_free(pf_dir_path);
	}
	profile1->status = PROF_STAT_EXISTS;
	g_free (profile1->reference);
	profile1->reference = g_strdup(profile1->name);
      }
    }
    fl1 = g_list_next(fl1);
  }

  /* Last remove deleted */
  fl1 = g_list_first(current_profiles);
  while (fl1) {
    found = FALSE;
    profile1 = (profile_def *) fl1->data;
    fl2 = g_list_first(edited_profiles);
    while (fl2) {
      profile2 = (profile_def *) fl2->data;
      if (strcmp(profile1->name, profile2->name)==0) {
	/* Profile exists in both lists */
	found = TRUE;
      } else if (strcmp(profile1->name, profile2->reference)==0) {
	/* Profile has been renamed */
	found = TRUE;
      }
      fl2 = fl2->next;
    }
    if (!found) {
      /* Exists in existing list and not in edited, this is a deleted profile */
      if (delete_persconffile_profile(profile1->name, &pf_dir_path) == -1) {
	simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
		      "Can't delete profile directory\n\"%s\":\n%s.",
		      pf_dir_path, strerror(errno));

	g_free(pf_dir_path);
      }
    }
    fl1 = g_list_next(fl1);
  }

  copy_profile_list();
  profile_select(main_w, profile_l, destroy);
}