struct list_elem
*list_next(struct list_elem *e)
{
    assert(e);
    assert(is_head(e) || is_interior(e));
    return e->next;
}
Example #2
0
struct list_elem *
list_next (struct list_elem *elem)
{
  ASSERT (is_head (elem) == true || is_interior (elem) == true);
  
  return elem->next;
}
Example #3
0
/* Returns the element after ELEM in its list.  If ELEM is the
   last element in its list, returns the list tail.  Results are
   undefined if ELEM is itself a list tail. */
struct list_elem *
list_next (struct list_elem *elem)
{
  ASSERT (is_head (elem) || list_is_interior (elem));
  // ASSERT (is_list_elem (elem->next));
  return elem->next;
}
Example #4
0
//URL Encoding not emplemented RFC1738
int connection::check_method_uri_protocol()
{
	if (m_method.empty() || m_uri.empty() || m_protocol.empty())
	{
		return httpcodes::forbidden;
	}
	char const bad_sym[] = "<>\"%{}|^~[]`\\;:/?@#=&";
	std::string::iterator it = std::search(m_uri.begin(), m_uri.end(), bad_sym, bad_sym+sizeof(bad_sym)-1);
	if (it != m_uri.end())
	{
		return httpcodes::forbidden;
	}
	if (m_uri.find("..") != std::string::npos)
	{
		//URI contains ..
		return httpcodes::forbidden;
	}
	if (!is_get() && !is_head())
	{
		//Unsupported method
		return httpcodes::not_implemented;
	}
	if (m_uri.size() > MAX_PATH)
	{
		return httpcodes::uri_to_long;
	}
	if ('/' == *m_uri.begin())
	{
		m_full_file_name.assign(m_uri.begin()+1, m_uri.end());
	}
	if (m_full_file_name.empty())
	{
		m_full_file_name = DEFAULT_FILE_NAME;
	}
	int res = ::stat(m_full_file_name.c_str(), &m_file_stat);
	if (res < 0)
	{
		int last_errno = errno;
		return get_last_http_error(last_errno);
	}
	m_file.open(m_full_file_name.c_str(), std::ifstream::in);
	if (!m_file)
	{
		return httpcodes::not_found;
	}
	if (m_file.fail())
	{
		return httpcodes::forbidden;
	}
	if (m_file.bad())
	{
		return httpcodes::service_unavailable;
	}
	return httpcodes::ok;
}
Example #5
0
static void reflog_expiry_prepare(const char *refname,
				  const struct object_id *oid,
				  void *cb_data)
{
	struct expire_reflog_policy_cb *cb = cb_data;

	if (!cb->cmd.expire_unreachable || is_head(refname)) {
		cb->tip_commit = NULL;
		cb->unreachable_expire_kind = UE_HEAD;
	} else {
		cb->tip_commit = lookup_commit_reference_gently(the_repository,
								oid, 1);
		if (!cb->tip_commit)
			cb->unreachable_expire_kind = UE_ALWAYS;
		else
			cb->unreachable_expire_kind = UE_NORMAL;
	}

	if (cb->cmd.expire_unreachable <= cb->cmd.expire_total)
		cb->unreachable_expire_kind = UE_ALWAYS;

	cb->mark_list = NULL;
	cb->tips = NULL;
	if (cb->unreachable_expire_kind != UE_ALWAYS) {
		if (cb->unreachable_expire_kind == UE_HEAD) {
			struct commit_list *elem;

			for_each_ref(push_tip_to_list, &cb->tips);
			for (elem = cb->tips; elem; elem = elem->next)
				commit_list_insert(elem->item, &cb->mark_list);
		} else {
			commit_list_insert(cb->tip_commit, &cb->mark_list);
		}
		cb->mark_limit = cb->cmd.expire_total;
		mark_reachable(cb);
	}
}
Example #6
0
File: list.c Project: spolu/ur
/* Returns the element after ELEM in its list.  If ELEM is the
   last element in its list, returns the list tail.  Results are
   undefined if ELEM is itself a list tail. */
struct list_elem *
list_next (struct list_elem *elem)
{
  assert (is_head (elem) || is_interior (elem));
  return elem->next;
}
Example #7
0
int main ( int argc, char *argv[] )
{
    size_t nb = 0, nc, nx = 0, nbuf = 0, nsel = 0, nerr = 0, i, nh = 0, nw;
    FILE* ficin;
    FILE* ficout = NULL;
    FILE* ficol = NULL;
    unsigned char b[4], header[256];
    unsigned int expected = 0;
    char name[256], namex[256], namec[256];
    double tx;
    struct timeval tini, tfin, tt;

    // Initial time
    gettimeofday ( &tini, NULL );

    // read args from stdio
    if ( read_args ( argc, argv ) < 0 )
    {
        exit ( EXIT_FAILURE );
    }

    // Check input
    if ( stat ( ENTRADA, &INSTAT ) )
    {
        printf ( "%s: Cannot stat  %s\n", OWN, ENTRADA );
        exit ( EXIT_FAILURE );
    }

    // Open output file
    if ( ( ficin = fopen ( ENTRADA,"r" ) ) == NULL )
    {
        printf ( "%s: Cannot open %s\n", OWN, ENTRADA );
        exit ( EXIT_FAILURE );
    }

    if ( COLECT )
    {
        // To make an archive

        // build a name
        strcpy ( namec, PREFIX );
        strcat ( namec, ENTRADA );

        // open the file
        if ( ( ficol = fopen ( namec, "w" ) ) == NULL )
        {
            printf ( "%s: Cannot open %s\n", OWN, namec );
            exit ( EXIT_FAILURE );
        }
    }


    STAGE = 0;

    memset ( &b, 0, 4 * sizeof ( unsigned char ) );

    while ( ( nc = fread ( &BUF[0], sizeof ( unsigned char ), BLEN, ficin ) ) > 0 )
    {
        for ( i = 0; i < nc ; i++ )
        {
            // ingest a byte
            b[3] = b[2];
            b[2] = b[1];
            b[1] = b[0];
            b[0] = BUF[i];

            switch ( STAGE )
            {
            case 0: // begining, searching header init
                if ( is_head ( &b[0] ) )
                {
                    memset ( &header[0], 0, 64 * sizeof ( unsigned char ) );
                    header[0] = '*';
                    header[1] = '*';
                    header[2] = '*';
                    header[3] = '*';
                    nh = 4;
                    STAGE = 1;
                }
                break;
            case 1: // header found, filling
                if ( nh < 255 )
                    header[nh++] = b[0];
                else
                {
                    STAGE = 0;
                    nerr++;
                    break;
                }
                if ( is_head ( &b[0] ) )
                {
                    STAGE = 2;
                    //header[nh++] = '\0';
                    //printf("Header: '%s'\n",header);
                }
                break;
            case 2: // header already finished
                if ( nh < 255 )
                    header[nh++] = b[0];
                else
                {
                    STAGE = 0;
                    nerr++;
                    break;
                }
                if ( b[0] != 0x0a && b[0] != 0x0d )
                {
                    STAGE = 3;
                    memset ( &name[0], 0, 128 * sizeof ( unsigned char ) );
                    name[0] = b[0];
                    nx = 1;
                }
                break;
            case 3: // name already inited
                if ( nh < 255 )
                    header[nh++] = b[0];
                else
                {
                    STAGE = 0;
                    nerr++;
                    break;
                }
                if ( nx >= 255 )
                {
                    STAGE = 0;
                    break;
                }
                if ( b[0] == 0x01a || b[0] == 0x0d )
                {
                    STAGE = 4;
                    name[nx++] = '\0';
                    //printf("Name: '%s'\n",name);
                }
                else if ( b[0] == ' ' )
                    name[nx++] = '_'; // substitute a space by '_'
                else
                    name[nx++] = b[0];
                break;
            case 4: // Waiting BUFR message begin
                if ( nh < 255 )
                    header[nh++] = b[0];
                else
                {
                    STAGE = 0;
                    nerr++;
                    break;
                }
                if ( is_bufr ( &b[0] ) )
                {
                    STAGE = 5;
                    expected = 0;
                    // printf("Leyendo BUFR\n");
                    memset ( &BUFR[0], 0, BUFRLEN );
                    nb = 4;
                    BUFR[0]='B';
                    BUFR[1]='U';
                    BUFR[2]='F';
                    BUFR[3]='R';
                    nh -= 4;
                    header[nh] = '\0';
                }
                break;
            case 5: // Filling BUFR message till final '7777'
                if ( nb < ( BUFRLEN - 1 ) )
                    BUFR[nb++] = b[0];
                else
                {
                    printf ( "Error: Bufr message length > %d", BUFRLEN );
                    fclose ( ficin );
                    exit ( EXIT_FAILURE );
                }
                // check expected length
                if (nb == 7)
                {
                    expected = (unsigned int)b[0] + (unsigned int)b[1] * 256 + (unsigned int)b[2] * 65536;
                }

                // Has been detected some void and fakes bufr
                if ( b[0] == '*' &&
                        b[1] == '*' &&
                        b[2] == '*'
                   )
                {
                    // Ooops. a fake bufr
                    // it seems a new header has been found before '7777'
                    STAGE = 0;
                    nerr++;
                    break;
                }
                if ( nb == expected)
                {
                    if ( is_endb ( &b[0] ) )
                    {
                        STAGE = 0;
                        nbuf++;
                        if ( LISTF )
                            printf ( "%s\n", name );
                        if ( bufr_is_selected ( name ) )
                        {
                            nsel++;
                            if ( INDIVIDUAL )
                            {
                                // prefix with input file timestamp
                                date_mtime_from_stat ( namex, &INSTAT );
                                strcat ( namex,"_" );
                                strcat ( namex, name );
                                strcat ( namex, ".bufr" );
                                if ( ( ficout = fopen ( namex, "w" ) ) == NULL )
                                {
                                    printf ( "Error: cannot open %s\n", name );
                                    fclose ( ficin );
                                    exit ( EXIT_FAILURE );
                                }
                                if ( ( nw = fwrite ( &BUFR[0], sizeof ( unsigned char ), nb, ficout ) ) != nb )
                                {
                                    printf ( "Error: Writen %lu bytes instead of %lu in %s file\n", nw, nb, namex );
                                    fclose ( ficin );
                                    fclose ( ficout );
                                    exit ( EXIT_FAILURE );
                                }
                                // close an individual fileq
                                fclose ( ficout );
                                // change individual file timestamp
                                mtime_from_stat ( namex, &INSTAT );
                            }
                            if ( COLECT )
                            {
                                // first write header
                                if ( ( nw = fwrite ( &header[0], sizeof ( char ), nh, ficol ) ) != nh )
                                {
                                    printf ( "%s: Error: Writen %lu bytes instead of %lu in %s file\n", OWN, nw, nh, namec );
                                    fclose ( ficin );
                                    fclose ( ficol );
                                    exit ( EXIT_FAILURE );
                                }

                                // then bufr message
                                if ( ( nw = fwrite ( &BUFR[0], sizeof ( unsigned char ), nb, ficol ) ) != nb )
                                {
                                    printf ( "%s: Error: Writen %lu bytes instead of %lu in %s file\n", OWN, nw, nb, namex );
                                    fclose ( ficin );
                                    fclose ( ficout );
                                    exit ( EXIT_FAILURE );
                                }
                                // finally \r\r\n
                                if ( ( nw = fwrite ( &SEP[0], sizeof ( char ), 3, ficol ) ) != 3 )
                                {
                                    printf ( "%s: Error: Writen %lu bytes instead of 3 chars separing messages in %s\n", OWN, nw, namex );
                                    fclose ( ficin );
                                    fclose ( ficout );
                                    exit ( EXIT_FAILURE );
                                }
                            }
                        }
                    }
                    else
                    {   // reached the expected end of BUFR without a '7777'
                        STAGE = 0;
                        nerr++;
                        break;
                    }
                }
            }
        }
    }

    if ( COLECT )
    {
        fclose ( ficol );
        // change archive file timestamp
        mtime_from_stat ( namec, &INSTAT );
    }

    // Final time
    gettimeofday ( &tfin, NULL );
    fclose ( ficin );

    // A brief stat output
    if ( VERBOSE )
    {
        printf ( "Found %lu bufr reports. Selected: %lu. Wrong: %lu\n", nbuf, nsel, nerr );
        timeval_substract ( &tt, &tfin, &tini );
        tx = ( double ) tt.tv_sec + ( double ) tt.tv_usec *1e-6;
        printf ( "%lf seg.  ", tx );
        if ( nbuf && tx != 0.0 )
            printf ( "%lf reports/sec.\n", ( double ) nbuf / tx );
        else
            printf ( "\n" );
    }
    exit ( EXIT_SUCCESS );
}
Example #8
0
void C_leer_ficha(void *environment, DATA_OBJECT_PTR returnValuePtr)
{
  SDL_Event evento;
  int x, y, pos, head=1;
  void *retorno;
  char fin=0, fin2=0;
  if (n == 0) {
    x=-1;
    y=-1;
    fin = 1;
  }
  leyendo=1;
  while (!fin) {
    while (SDL_PollEvent(&evento)) {
      switch (evento.type) {
      case SDL_QUIT:
	SDL_Quit();
	fin = 1;
	break;
      case SDL_MOUSEBUTTONDOWN:
	if (evento.button.button == SDL_BUTTON_RIGHT) {
	  x=-1; y=-1;
	  fin = 1;
	  break;
	}
	if (evento.button.y >= FICHAS_Y &&
	    evento.button.y <= FICHAS_Y + fichaH) {
	  for (pos=0; pos<n; ++pos) {
	    if (evento.button.y >= FICHAS_Y &&
		evento.button.y <= FICHAS_Y + fichaH) {
	      if (evento.button.x >= (30 + pos*(fichaW + 10)) &&
		  evento.button.x <= (30 + pos*(fichaW + 10) + fichaW)) {
		if (evento.button.y > FICHAS_Y + fichaH/2) {
		  x = fichas[jugador[pos]].y;
		  y = fichas[jugador[pos]].x;
		}
		else {
		  x = fichas[jugador[pos]].x;
		  y = fichas[jugador[pos]].y;
		}
		fin2=0;
		while (!fin2) {
		  SDL_PollEvent(&evento);
		  switch (evento.type) {
		  case SDL_MOUSEBUTTONDOWN:
		    if (evento.button.button == SDL_BUTTON_RIGHT) fin2=1;
		    else {
		      if (is_head (evento.button.x, evento.button.y))
			fin=1, fin2=1;
		      else if (is_tail (evento.button.x, evento.button.y)) {
			fin = x;
			x = y;
			y = fin;
			fin = 1;
			head = 0;
			fin2=1;
		      }
		    }
		    break;
		  }
		}
	      }
	    }
	  }
	}
	break;
      }
    }
    C_flip(environment);
  }
  
  retorno = EnvCreateMultifield(environment,3);
  SetMFType(retorno, 1, INTEGER);
  SetMFValue(retorno, 1, EnvAddLong(environment,x));
  SetMFType(retorno, 2, INTEGER);
  SetMFValue(retorno, 2, EnvAddLong(environment,y));
  SetMFType(retorno, 3, INTEGER);
  SetMFValue(retorno, 3, EnvAddLong(environment,head));
  SetpType(returnValuePtr, MULTIFIELD);
  SetpValue(returnValuePtr, retorno);
  SetpDOBegin(returnValuePtr, 1);
  SetpDOEnd(returnValuePtr, 3);
  n=0;
  
  while (SDL_PollEvent(&evento));
}