Exemplo n.º 1
0
Arquivo: lrw_dict.c Projeto: fizx/sit
static void 
_truncate(LRWDict *d) {
  Term *key = d->oldest;
  if (key) {
    _extract(d, key);
    dictDelete(d->dict, key);
  }
}
Exemplo n.º 2
0
double WayFeatureExtractor::extract(const OsmMap& map,
  const shared_ptr<const Element>& target, const shared_ptr<const Element>& candidate) const
{
  vector<double> scores;

  if (target->getElementType() == ElementType::Way &&
      candidate->getElementType() == ElementType::Way)
  {
    scores.push_back(_extract(map, dynamic_pointer_cast<const Way>(target),
                              dynamic_pointer_cast<const Way>(candidate)));
  }
  else if (target->getElementType() == ElementType::Relation &&
           candidate->getElementType() == ElementType::Relation)
  {
    ConstRelationPtr r1 = dynamic_pointer_cast<const Relation>(target);
    ConstRelationPtr r2 = dynamic_pointer_cast<const Relation>(candidate);

    if (r1->getType() == Relation::MULTILINESTRING &&
        r2->getType() == Relation::MULTILINESTRING &&
        r1->getMembers().size() == r2->getMembers().size())
    {
      for (size_t i = 0; i < r1->getMembers().size(); i++)
      {
        ElementId eid1 = r1->getMembers()[i].getElementId();
        ElementId eid2 = r2->getMembers()[i].getElementId();

        if (eid1.getType() != ElementType::Way || eid2.getType() != ElementType::Way)
        {
          return nullValue();
        }
        scores.push_back(_extract(map, map.getWay(eid1), map.getWay(eid2)));
      }
    }
    else
    {
      return nullValue();
    }
  }
  else
  {
    return nullValue();
  }
  return _agg->aggregate(scores);
}
Exemplo n.º 3
0
Arquivo: lrw_dict.c Projeto: fizx/sit
static void
_bump(LRWDict *d, Term *term) {
  _extract(d, term);
  
  if(!d->oldest) {
    d->oldest = term;
  }
  
  // insert
  Term *old = d->newest;
  if(old) {
    old->next = term;
  }
  term->prev = old;
  term->next = NULL;
  d->newest = term;
}
Exemplo n.º 4
0
Arquivo: undbx.c Projeto: dabble/undbx
static int _undbx(char *dbx_dir, char *out_dir, char *dbx_file, dbx_options_t *options)
{
  int deleted = 0; 
  int saved = 0;
  int errors = 0;
  
  dbx_t *dbx = NULL;
  char *eml_dir = NULL;
  char *cwd = NULL;
  int rc = -1;

  cwd = sys_getcwd();
  if (cwd == NULL) {
    dbx_progress_message(NULL, DBX_STATUS_ERROR, "can't get current working directory");
    goto UNDBX_DONE;
  }

  rc = sys_chdir(dbx_dir);
  if (rc != 0) {
    dbx_progress_message(NULL, DBX_STATUS_ERROR, "can't chdir to %s", dbx_dir);
    goto UNDBX_DONE;
  }
  
  dbx = dbx_open(dbx_file, options);
  
  sys_chdir(cwd);

  if (dbx == NULL) {
    dbx_progress_message(NULL, DBX_STATUS_WARNING, "can't open DBX file %s", dbx_file);
    rc = -1;
    goto UNDBX_DONE;
  }

  if (!options->recover && dbx->type != DBX_TYPE_EMAIL) {
    dbx_progress_message(dbx->progress_handle, DBX_STATUS_WARNING, "DBX file %s does not contain messages", dbx_file);
    rc = -1;
    goto UNDBX_DONE;
  }

  if (!options->recover && dbx->file_size >= 0x80000000) {
    dbx_progress_message(dbx->progress_handle, DBX_STATUS_WARNING,"DBX file %s is corrupted (larger than 2GB)", dbx_file);
  }

  eml_dir = strdup(dbx_file);
  eml_dir[strlen(eml_dir) - 4] = '\0';
  rc = sys_mkdir(out_dir, eml_dir);
  if (rc != 0) {
    dbx_progress_message(dbx->progress_handle, DBX_STATUS_ERROR, "can't create directory %s/%s", out_dir, eml_dir);
    goto UNDBX_DONE;
  }

  rc = sys_chdir(out_dir);
  if (rc != 0) {
    dbx_progress_message(dbx->progress_handle, DBX_STATUS_ERROR, "can't chdir to %s", out_dir);
    goto UNDBX_DONE;
  }

  if (options->recover)
    _recover(dbx, out_dir, eml_dir, &saved, &errors);
  else
    _extract(dbx, out_dir, eml_dir, &saved, &deleted, &errors);

 UNDBX_DONE:  
  free(eml_dir);
  eml_dir = NULL;
  dbx_close(dbx);
  sys_chdir(cwd);
  free(cwd);
  cwd = NULL;

  return rc;
}
Exemplo n.º 5
0
int main(int argc, char **argv){
   int i, n, nexthost, port=0, method=M_DEFAULT, addr_len;
   char *p, *pl, *pl2, *listen_addr=LISTEN_ADDR, tmpbuf[TMPLEN];
   unsigned char packet[PACKETLEN];
   unsigned long listenhost;
   struct sockaddr_in my_addr, send_addr, client_addr;

   while((i = getopt(argc, argv, "x:l:m:p:v")) > 0){

      switch(i){
         case 'x' :
                    pl = optarg;

                    do{
                       memset((char *)&hosts[hostnum], 0, sizeof(struct onehost));

                       p = _extract(pl, ',', &tmpbuf[0], TMPLEN-1);

                       if(p){
                          p++;
                          pl = p;
                       }
                       else {
                          strncpy(&tmpbuf[0], pl, TMPLEN-1);
                       }

                       pl2 = strchr(tmpbuf, ':');
                       if(pl2){
                          *pl2 = '\0';
                          pl2++;
                          bogomips[hostnum] = atoi(pl2);
                          if(bogomips[hostnum] == 0)
                             fatal(FORMAT2, "bogomips value must be >= 1", bogomips[hostnum]);
                       }
                       else {
                          bogomips[hostnum] = 0;
                       }

                       strncpy((char *)&hosts[hostnum].host[0], &tmpbuf[0], IPADDRLEN-1);

                       hosts[hostnum].s_addr = resolve_host(hosts[hostnum].host);
                       if(hosts[hostnum].s_addr == 0)
                          fatal(FORMAT3, "invalid host", hosts[hostnum].host);

                       hostnum++;

                       if(hostnum > MAXHOSTS)
                          fatal(FORMAT2, "too many host. max:", MAXHOSTS);

                    } while(p);

                    break;

         case 'l' :
                    listen_addr = optarg;
                    break;

         case 'm' :
                    if(!strcmp(optarg, "roundrobin"))
                       method = M_ROUNDROBIN;

                    if(!strcmp(optarg, "loadbalance"))
                       method = M_LOADBALANCE;

                    if(!strcmp(optarg, "volumebalance"))
                       method = M_VOLUMEBALANCE;

                    break;

         case 'p' :
                    port = atoi(optarg);
                    if(port == 0 || port > 65535)
                       fatal(FORMAT2, "invalid port", port);

                    break;

         case 'v' :
                    v++;
                    break;

         default : 
                    fatal(FORMAT1, USAGE);
                    break;
      }
   }

   if(port == 0)
      fatal(FORMAT2, "invalid port", port);

   listenhost = resolve_host(listen_addr);

   #ifdef USESYSLOG
      (void) openlog(PROGNAME, LOG_PID, LOG_FACILITY);
      syslog(LOG_OPTION, "%s %s is starting on %s:%d", PROGNAME, VERSION, listen_addr, port);
   #endif

   signal(SIGINT, clean_exit);
   signal(SIGQUIT, clean_exit);
   signal(SIGKILL, clean_exit);
   signal(SIGTERM, clean_exit);
   signal(SIGALRM, refresh);

   /* create listener socket */

   if((lsd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
      fatal(FORMAT1, "cannot open listener socket");

   my_addr.sin_family = AF_INET;
   my_addr.sin_port = htons(port);
   my_addr.sin_addr.s_addr = listenhost;
   bzero(&(my_addr.sin_zero), 8);

   if(bind(lsd, (struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == -1)
      fatal(FORMAT2, "cannot bind to port:", port);

   /* drop root privs if we have */

   if(getuid() == 0 || geteuid() == 0){
      fprintf(stderr, "dropped\n");
      drop_root();
   }

   /* create sender socket */

   if((sd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
      fatal(FORMAT1, "cannot open socket");

   bzero((char *)&send_addr, sizeof(struct sockaddr));
   send_addr.sin_family = AF_INET;
   send_addr.sin_port = htons(port);


   nexthost = -1;
   addr_len = sizeof(struct sockaddr);

   srand(getpid());

   refresh();

   for(;;){

      /* read request from clients */

      if((n = recvfrom(lsd,  &packet[0], PACKETLEN, 0, (struct sockaddr*)&client_addr, &addr_len)) > 0){
         //fprintf(stderr, "%d %s\n", n, inet_ntoa(client_addr.sin_addr));

         /* determine next host to forward request */

         switch(method){
            case M_ROUNDROBIN:
                               nexthost++;
                               nexthost = choose_round_robin_host(nexthost);
                               break;

            case M_VOLUMEBALANCE:
                               nexthost = choose_volume_host();
                               break;

            case M_LOADBALANCE:
                               nexthost = choose_balance_host();
                               break;
         }

         if(nexthost < 0){
            #ifdef USESYSLOG
               syslog(LOG_OPTION, "no available hosts! Refreshing.");
            #endif

            fprintf(stderr, "no available hosts! Refreshing.\n");
            refresh();

            continue;
         }

         /* send request to selected host */

         send_addr.sin_addr.s_addr = hosts[nexthost].s_addr;

         gettimeofday(&senttime, &tz);

         sendto(sd, (char *)&packet, n, 0, (struct sockaddr *)&send_addr, sizeof(struct sockaddr));

         /*
          * read answer 
          * we do not retry instead let the client repeat the request
          */

         n = readudppacket(sd, &packet[0], PACKETLEN, timeout, (struct sockaddr*)&client_addr);

         gettimeofday(&now, &tz);

         if(n > 0){
            hosts[nexthost].counter++;
            hosts[nexthost].rtt += tvdiff(now, senttime);

            if(hosts[nexthost].rtt < 0)
               hosts[nexthost].rtt = INT_MAX - 100;

            // print debug info
            if(v > 2)
               fprintf(stderr, "%s => %s:%d - %d bytes in %ld [usec]\n", inet_ntoa(client_addr.sin_addr), hosts[nexthost].host, port, n, tvdiff(now, senttime));
         }
         else {
            /* one lost packet should not discard our next node */

            hosts[nexthost].lost++;
            if(hosts[nexthost].lost > MAX_LOST_PACKET){
               hosts[nexthost].avail = 0;

               #ifdef USESYSLOG
                  syslog(LOG_OPTION, "%s-(%d) been discarded", hosts[nexthost].host, port);
               #endif

               if(v >= 1)
                  fprintf(stderr, "%s-(%d) been discarded\n", hosts[nexthost].host, port);
            }
         }

         /* send response back to your client */

         sendto(lsd, (char *)&packet, n, 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
      }
   }

   return 0;
}
Exemplo n.º 6
0
void _extract_from_timer (ft_scheduler_t sched,item_cell_t cell)
{
   _extract (sched->timer,cell);
}