示例#1
0
文件: game.c 项目: luckyluke/rezzlu
word_t* word_alloc(char* w, path_t* p){
  word_t* tmp;
  int wsize=sizeof(char)*(strlen(w)+1);

  if ((tmp = malloc(sizeof(word_t))) == NULL){
    perror("alloc word");
    return NULL;
  }

  if ((tmp->word = malloc(wsize)) == NULL){
    free(tmp);
    perror("alloc word string");
    return NULL;
  }
  strncpy(tmp->word, w, wsize);
  if ((tmp->path = path_copy(p)) == NULL){
    free(tmp->word);
    free(tmp);
    perror("alloc word path");
    return NULL;
  }
  tmp->pathlen = path_len(tmp->path);

  return tmp;
}
OP_STATUS
OpScopeCookieManager::DoGetCookie(const GetCookieArg &in, CookieList &out)
{
	OpString in_domain;
	RETURN_IF_ERROR(in_domain.Set(in.GetDomain()));

	RETURN_IF_ERROR(Cookie_Manager::CheckLocalNetworkAndAppendDomain(in_domain));

	// we need non-const strings for the URL API
	OpAutoArray<uni_char> domain_copy( OP_NEWA(uni_char, in_domain.Length() + 1) );
	RETURN_OOM_IF_NULL(domain_copy.get());
	uni_strcpy(domain_copy.get(), in_domain.CStr());
	uni_char *domain = domain_copy.get();
	uni_char *path = NULL;

	OpAutoArray<uni_char> path_copy( in.HasPath() ? OP_NEWA(uni_char, in.GetPath().Length() + 1) : NULL );
	if (in.HasPath())
	{
		RETURN_OOM_IF_NULL(path_copy.get());
		uni_strcpy(path_copy.get(), in.GetPath().CStr());
		path = path_copy.get();
	}

	OpAutoArray< ::Cookie * > cookies( OP_NEWA(::Cookie *, urlManager->GetMaxCookiesInDomain()) );
	RETURN_OOM_IF_NULL(cookies.get());
	int cookie_size = 0;
	OP_STATUS status = g_url_api->BuildCookieList(cookies.get(), &cookie_size, domain, path, TRUE);
	if (OpStatus::IsError(status))
		return SetCommandError(OpScopeTPHeader::BadRequest, UNI_L("Could not get cookies for specified domain and path"));

	for (int i = 0; i < cookie_size; ++i)
	{
		Cookie *cookie_out = out.AppendNewCookieList();
		RETURN_OOM_IF_NULL(cookie_out);

		::Cookie *cookie = cookies[i];
		if (!cookie || !(cookie->Received_Domain().CStr() || (cookie->GetDomain() && cookie->GetDomain()->GetFullDomain())))
		{
			OP_ASSERT(cookie && cookie->GetDomain() && cookie->GetDomain()->GetFullDomain());
			return OpStatus::ERR_NULL_POINTER;
		}

		RETURN_IF_ERROR(SetCookieValue(*cookie_out, *cookie));
	}
	return OpStatus::OK;
}
示例#3
0
/**
 * Returns all the paths up to certain length. All the paths come from the pathBuffer, you are responsible
 * of freeing them from the buffer with path_array_free_from_buffer after using the buffer. 
 */
PathArray * branches_get_all_paths_from(pathStep * first, int max_length, dBGraph * db_graph){
//    first->label = Cytosine;
    first->flags = 0;
    first->orientation = reverse;
    first->label = Undefined;
    PathArray * pa = path_array_new(4);// where is freeing the path array?
    Path * buff = path_get_buffer_path();
    path_set_limit(max_length, buff);
    
    WalkingFunctions wf;
    branches_get_funtions(&wf);
    
    
    void copy_path(Path * p){
        Path * tmp = path_get_buffer_path();
        path_copy(tmp, p);
        //path_to_fasta(p, stdout);
        path_array_add_path(tmp, pa);
    }
OP_STATUS
OpScopeCookieManager::DoRemoveCookie(const RemoveCookieArg &in)
{
	OpString in_domain;
	RETURN_IF_ERROR(in_domain.Set(in.GetDomain()));
	RETURN_IF_ERROR(Cookie_Manager::CheckLocalNetworkAndAppendDomain(in_domain));

	// we need non-const strings for the URL API
	uni_char *domain = NULL;
	OpAutoArray<uni_char> domain_copy( OP_NEWA(uni_char, in_domain.Length() + 1) );
	{
		RETURN_OOM_IF_NULL(domain_copy.get());
		uni_strcpy(domain_copy.get(), in_domain.CStr());
		domain = domain_copy.get();
	}
	uni_char *path = NULL;
	OpAutoArray<uni_char> path_copy( in.HasPath() ? OP_NEWA(uni_char, in.GetPath().Length() + 1) : NULL );
	if (in.HasPath())
	{
		RETURN_OOM_IF_NULL(path_copy.get());
		uni_strcpy(path_copy.get(), in.GetPath().CStr());
		path = path_copy.get();
	}
	uni_char *name = NULL;
	OpAutoArray<uni_char> name_copy( in.HasName() ? OP_NEWA(uni_char, in.GetName().Length() + 1) : NULL );
	if (in.HasName())
	{
		RETURN_OOM_IF_NULL(name_copy.get());
		uni_strcpy(name_copy.get(), in.GetName().CStr());
		name = name_copy.get();
	}

	OP_STATUS status = g_url_api->RemoveCookieList(domain, path, name);
	if (OpStatus::IsError(status))
		return SetCommandError(OpScopeTPHeader::BadRequest, UNI_L("Failure while removing cookies for specified domain, path and name"));
	return OpStatus::OK;
}
示例#5
0
static void pp_copy_path(Path * p, void * args) {
    Path * path = (Path *) args;    
    path_copy(path, p);
}
示例#6
0
ACE_URL_Addr*
ACE_HTTP_Addr::create_relative_address (const ACE_TCHAR *url) const
{
  if (ACE_URL_Addr::known_scheme (url))
    return ACE_URL_Addr::create_address (url);

  ACE_HTTP_Addr* addr = 0;
  if (url[0] == '/')
    {
      ACE_NEW_RETURN (addr, ACE_HTTP_Addr (this->get_hostname (),
                                           url + 1,
                                           0,
                                           this->get_port_number ()),
                      0);
    }
  else
    {
      const ACE_TCHAR *path = this->get_path ();
      ACE_TCHAR *buf;
      size_t n = ACE_OS::strlen (url)
        + ACE_OS::strlen (path)
        + 2;
      ACE_NEW_RETURN (buf,
                      ACE_TCHAR [n],
                      0);

      // We copy the contens of <path> into <buf>; but simplifying the
      // path, to avoid infinite loop like:
      // "foo/../foo/../foo/../foo/../foo/index.html"
      //
      ACE_TCHAR *target = buf;

      // Copy the path
      path_copy (buf, buf + n, target, path);

      if (url[0] == '#')
        {
          // Remove any # from the path
          ACE_TCHAR *p = target;
          
          while (p != buf && *(--p) != '#')
            {
              // No action.
            }
          
          if (p != buf)
            target = p;
        }
      else
        {
          // Go back to the last / to remove the basename.
          while (target != buf && *(--target) != '/')
            {
              // No action.
            }
            
          // Go back if we begin with '../'
          while ((url[0] == '.' && url[1] == '.' && url[2] == '/')
                 || (url[0] == '.' && url[1] == '/'))
            {
              if (url[1] == '.')
                {
                  // A ../ go back
                  while (target != buf && *(--target) != '/')
                    {
                      // No action.
                    }
                  
                  url += 3;
                }
              else
                {
                  // A ./ remove
                  url += 2;
                }
            }

          *target = '/'; ++target;
        }
      // Copy the url
      path_copy (buf, buf + n, target, url);
      // null terminate.
      *target = 0;
      ACE_NEW_RETURN (addr, ACE_HTTP_Addr (this->get_hostname (),
                                           buf,
                                           0,
                                           this->get_port_number ()),
                      0);
      delete[] buf;
    }
    
  return addr;
}
示例#7
0
文件: file.c 项目: Caleb1994/stewieos
struct file* file_open(struct path* path, int flags)
{
	
	struct file* file = NULL;
	int access_mode = ((flags+1)&_FWRITE ? W_OK : 0) | \
				((flags+1)&_FREAD ? R_OK : 0);
	int result = 0;
	
	result = path_access(path, access_mode);
	if( result != 0 ){
		return ERR_PTR(result);
	}
	
	// Is this not a directory?
	if( !S_ISDIR(path->p_dentry->d_inode->i_mode) )
	{
		// We requested a directory, and this file isn't one.
		/*if( (flags & O_DIRECTORY) ){
			path_put(&file->f_path);
			kfree(file);
			return -ENOTDIR;
		}*/
	// This is a directory, and we want a writeable file
	} else if( (flags+1) & _FWRITE ){
		return ERR_PTR(-EISDIR);
	}
	
	// FIXME I need to add O_CLOEXEC (and some others) to sys/fcntl.h instead of just using _default_fcntl.h from newlib!
	//if( flags & O_CLOEXEC ) file->f_flags |= FD_CLOEXEC;
	
	// No follow was specified, and this is a symlink
/*	if( flags & O_NOFOLLOW ){
		if( S_ISLNK(file->f_path.p_dentry->d_inode->i_mode) )
		{
			path_put(&file->f_path);
			kfree(file);
			return -ELOOP;
		}
	}*/
	
	if( flags & O_TRUNC )
	{
		if( !(access_mode & W_OK) ){
			return ERR_PTR(-EACCES);
		} else {
			result = inode_trunc(path->p_dentry->d_inode);
			if( result != 0 ){
				return ERR_PTR(result);
			}
		}
	}
	
	file = (struct file*)kmalloc(sizeof(struct file));
	if(!file) {
		return ERR_PTR(-ENOMEM);
	}
	
	memset(file, 0, sizeof(struct file));
	
	path_copy(&file->f_path, path);
	
	if( S_ISBLK(path->p_dentry->d_inode->i_mode) )
	{
		file->f_ops = &block_device_fops;
	} else if( S_ISCHR(path->p_dentry->d_inode->i_mode) ){
		file->f_ops = get_chrdev_fops(major(path->p_dentry->d_inode->i_dev));
	} else if( S_ISFIFO(path->p_dentry->d_inode->i_mode) ){
		file->f_ops = &pipe_operations;
	} else {
		file->f_ops = path->p_dentry->d_inode->i_default_fops;
	}
	
	if( file->f_ops == NULL )
	{
		path_put(&file->f_path);
		kfree(file);
		return ERR_PTR(-ENXIO);
	}
	
	if( file->f_ops->open ){
		result = file->f_ops->open(file, file->f_path.p_dentry, flags);
		if( result != 0 ){
			path_put(&file->f_path);
			kfree(file);
			return ERR_PTR(result);
		}
	}
	
	file->f_status = flags;
	file->f_refs = 1;
	
	return file;
}
int main(int argc, char **argv)
{
    graph_t graph;
    path_t best, candidate, best_candidate;
    int rot_size, rot_start;
    int verbose = 0;

    if ((argc == 2) && (strncmp(argv[1], "-v", sizeof("-v")) == 0)) {
        verbose = 1;
    }
    else if (argc > 1) {
        fprintf(stderr, "\n");
        fprintf(stderr, "  Parâmetros inválidos!\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "Uso: %s [-v]\n", argv[0]);
        fprintf(stderr, " -v     Ativa modo verbose (exibe detalhes da "
                        "execução do algoritmo)\n");
        return EXIT_FAILURE;
    }

    process_input(&graph);
    graph_calculate_distances(&graph);

    path_init(&best, &graph);
    path_find_greedy(&best, 1);

    if (verbose) {
        printf("1o. caminho: ");
        print_path(&best);
    }

    for (rot_size = 2; rot_size < graph.node_count; ++rot_size) {
        if (verbose) {
            printf("\n\n===== Trocando caminhos com tamanho %2d =====\n", rot_size);
        }

        path_copy(&best_candidate, &best);

        for (rot_start = 1; rot_start <= graph.node_count - rot_size; ++rot_start) {
            path_copy(&candidate, &best);
            path_rotate(&candidate, rot_size, rot_start);
            if (verbose) {
                printf("Troca # %3d: ", rot_start);
                print_path(&candidate);
            }

            if (candidate.distance < best_candidate.distance) {
                path_copy(&best_candidate, &candidate);
            }

            path_destroy(&candidate);
        }

        if (best_candidate.distance < best.distance) {
            path_copy(&best, &best_candidate);
        }

        if (verbose) {
            printf("\n   MELHOR  : ");
            print_path(&best);
        }
    }

    if (verbose) {
        printf("\n============================================\n");
    }

    printf("Melhor caminho encontrado:\n");
    print_path(&best);

    path_destroy(&best);
    path_destroy(&best_candidate);
    graph_destroy(&graph);

    return EXIT_SUCCESS;
}