Ejemplo n.º 1
0
static void
prefs_dialog_revert(GtkWidget* dialog)
{
    GConfChangeSet* cs;
    GConfChangeSet* revert_cs;
    GConfClient* client;

    revert_cs = g_object_get_data(dialog, "revert_changeset");

    if (revert_cs == NULL)
        return; /* happens on cancel, if no apply has been done */

    client = g_object_get_data(dialog, "client");

    cs = g_object_get_data(dialog, "changeset");

    /* When reverting, you want to discard any pending changes so
       "apply" won't do anything */
    gconf_change_set_clear(cs);

    /* FALSE so we don't remove committed stuff from the revert set */
    gconf_client_commit_change_set(client, revert_cs, FALSE, NULL);

    /* Set the prefs dialog contents back to the
       new values */
    update_entry(dialog, revert_cs, "/apps/basic-gconf-app/foo");
    update_entry(dialog, revert_cs, "/apps/basic-gconf-app/bar");
    update_entry(dialog, revert_cs, "/apps/basic-gconf-app/baz");
    update_entry(dialog, revert_cs, "/apps/basic-gconf-app/blah");

    /* Update sensitivity of the dialog buttons */
    prefs_dialog_update_sensitivity(dialog);
}
Ejemplo n.º 2
0
static GtkWidget*
get_entry_box (TTXWindow *self)
{
	GtkWidget *entry_box, *entry_main, *entry_sub;

	entry_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);

	entry_main = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY(entry_main), 3);
	gtk_entry_set_width_chars (GTK_ENTRY(entry_main), 3);

	entry_sub = gtk_entry_new ();
	gtk_entry_set_max_length (GTK_ENTRY(entry_sub), 2);
	gtk_entry_set_width_chars (GTK_ENTRY(entry_sub), 2);

	gtk_box_pack_start (GTK_BOX(entry_box), entry_main,
			    FALSE, FALSE, 2);
	gtk_box_pack_start (GTK_BOX(entry_box), entry_sub,
			    FALSE, FALSE, 2);

	self->priv->page_entry    = entry_main;
	self->priv->subpage_entry = entry_sub;

	g_signal_connect (entry_main, "activate",
			  G_CALLBACK(on_entry_activate),
			  self);
	g_signal_connect (entry_sub, "activate",
			  G_CALLBACK(on_entry_activate),
			  self);

	update_entry (self);

	return entry_box;
}
Ejemplo n.º 3
0
static int
do_update_entry(
        struct rldb_mysql_cnts *cs,
        int run_id,
        const struct run_entry *re,
        int flags)
{
  struct rldb_mysql_state *state = cs->plugin_state;
  struct runlog_state *rls = cs->rl_state;
  struct run_entry *de;
  char *cmd_t = 0;
  size_t cmd_z = 0;
  FILE *cmd_f = 0;

  ASSERT(run_id >= 0 && run_id < rls->run_u);
  de = &rls->runs[run_id];

  cmd_f = open_memstream(&cmd_t, &cmd_z);
  fprintf(cmd_f, "UPDATE %sruns SET ", state->md->table_prefix);
  generate_update_entry_clause(state, cmd_f, re, flags);
  fprintf(cmd_f, " WHERE contest_id = %d AND run_id = %d ;",
          cs->contest_id, run_id);
  close_memstream(cmd_f); cmd_f = 0;
  if (state->mi->simple_query(state->md, cmd_t, cmd_z) < 0) goto fail;
  xfree(cmd_t); cmd_t = 0; cmd_z = 0;
  update_entry(de, re, flags);
  return run_id;

 fail:
  if (cmd_f) fclose(cmd_f);
  xfree(cmd_t);
  return -1;
}
Ejemplo n.º 4
0
static int find_transport_entry(TRANSPORT_INFO *tp, const char *key,
				        const char *rcpt_domain, int flags,
				        VSTRING *channel, VSTRING *nexthop)
{
    char   *saved_value;
    const char *host;
    const char *value;

#define FOUND		1
#define NOTFOUND	0

    /*
     * Look up an entry with extreme prejudice.
     * 
     * XXX Should report lookup failure status to caller instead of aborting.
     */
    if ((value = maps_find(tp->transport_path, key, flags)) == 0)
	return (NOTFOUND);

    /*
     * It would be great if we could specify a recipient address in the
     * lookup result. Unfortunately, we cannot simply run the result through
     * a parser that recognizes "transport:user@domain" because the lookup
     * result can have arbitrary content (especially in the case of the error
     * mailer).
     */
    else {
	saved_value = mystrdup(value);
	host = split_at(saved_value, ':');
	update_entry(saved_value, host ? host : "", rcpt_domain,
		     channel, nexthop);
	myfree(saved_value);
	return (FOUND);
    }
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: tm512/ispolin
void seenPrivmsg (ircclient_t *cl, char *nick, char *host, char *source, char *message)
{
	char *buf, *tokbuf, *tnick;
	seen_entry_t *entry;
	update_entry (nick, time (NULL));

	if (message [0] == globalcfg.prefix)
	{
		buf = alloca (strlen (message));
		tokbuf = alloca (strlen (message));
		strncpy (buf, message + 1, strlen (message));

		if (strstr (buf, "seen ") == buf)
		{
			strtok_r (buf, " ", &tokbuf);
			tnick = strtok_r (NULL, " ", &tokbuf);

			if (!strlen (tnick))
				return;

			entry = get_entry (tnick);

			if (entry)
			{
				char timestring [32];
				time_t t = (time_t) entry->seen_date;
				strftime (timestring, 32, "%b %d, %Y, at %T %Z", localtime (&t));
				irc_privmsg (cl, source, "%s: The last time I saw activity from %s was on %s.", nick, entry->nick, timestring);
			}
			else
				irc_privmsg (cl, source, "%s: I have never seen %s before.", nick, tnick);
		}
	}
	return;
}
Ejemplo n.º 6
0
static int
resolve_entry(struct adapter *sc, struct l2t_entry *e)
{
	struct tom_data *td = sc->tom_softc;
	struct toedev *tod = &td->tod;
	struct sockaddr_in sin = {0};
	struct sockaddr_in6 sin6 = {0};
	struct sockaddr *sa;
	uint8_t dmac[ETHER_ADDR_LEN];
	uint16_t vtag = VLAN_NONE;
	int rc;

	if (e->ipv6 == 0) {
		sin.sin_family = AF_INET;
		sin.sin_len = sizeof(struct sockaddr_in);
		sin.sin_addr.s_addr = e->addr[0];
		sa = (void *)&sin;
	} else {
		sin6.sin6_family = AF_INET6;
		sin6.sin6_len = sizeof(struct sockaddr_in6);
		memcpy(&sin6.sin6_addr, &e->addr[0], sizeof(e->addr));
		sa = (void *)&sin6;
	}

	rc = toe_l2_resolve(tod, e->ifp, sa, dmac, &vtag);
	if (rc == EWOULDBLOCK)
		return (rc);

	mtx_lock(&e->lock);
	update_entry(sc, e, rc == 0 ? dmac : NULL, vtag);
	mtx_unlock(&e->lock);

	return (rc);
}
Ejemplo n.º 7
0
/*
 * flood - General purpose flooding method.
 *
 * @param lsa_type      type of LSA to be flooded
 * @param sockfd        routing daemon socket identifier
 * @param dl            pointer to direct neighbors table
 * @param rt            pointer to routing table
 * @param node_id       routing daemon node id
 * @param sequence_num  incremental sequence number
 * @return              1
 */
int flood(int lsa_type,int sockfd, direct_links *dl, local_objects *ol, routing_table *rt, int node_id, int sequence_num)
{
    int i, num_links;
    int port;
    char *host;
    int size;
    ack_checkers *curr_checkers;
    routing_entry *entry;
    LSA *lsa;
    lsa = create_packet(&size, lsa_type, node_id, sequence_num, dl, ol);

    entry = get_routing_entry(rt,node_id);
    update_entry(entry,rt, dl,lsa, size, node_id);

    curr_checkers = entry->checkers_list;

    num_links = dl->num_links;
    for (i = 1; i < num_links; i++)
    {
        if (get_routing_entry(rt, ((dl->links)[i]).id)->node_status != STATUS_DOWN)
        {
            port = ((dl->links)[i]).route_p;
            host = ((dl->links)[i]).host;
            rt_sendto(sockfd, lsa, host, port, size);

            curr_checkers->checkers[i].ack_received = ACK_NOT_RECEIVED;
        }
    }

    return 1;
}
Ejemplo n.º 8
0
/*
  If a label is encountered in parse_record, this function gets called to deal
  with the remaining record. The following tokens in the record can be either
  an instruction, a directive or a comment/null. Anything else is an error
*/
void analyzelabel(char* line, char* token){
  char* nexttoken;
  char* string;
  char* strptr;
  struct firsttoken result;

  #ifdef debug
  printf("FOUND LABEL >>%s<<\n", token);
  #endif /* debug */

  global = token;                       // Global string saving the label token
  string = storeline(line);
  nexttoken = strtok(line, " \t\r\n");

  if(nexttoken != NULL && *nexttoken != ';' && nexttoken[0] != '\r'){

    while(!isalnum(*string)){       // Go to first legible char
      *string++;
    }

    //Points to the start of the next token for the analysis functions

    strptr = storeline(string + strlen(nexttoken));

    #ifdef debug
    printf("TOKEN AFTER LABEL IS >>%s<<\n", nexttoken);
    printf("SENDING TO ANALYZERS: >>%s<<\n", strptr);
    #endif /* debug */

    result = sort(nexttoken);
    flag_first_token_label = TRUE; // indicator used for storing in symtbl
    switch (result.type) {
      case INST:
      analyzeinstruction(strptr, result);
      break;
      case DIR:
      analyzedirective(strptr, result);
      break;
      default:
      error_count("ERROR: Invalid token after label:", nexttoken);
      break;
    }
    flag_first_token_label = FALSE;
  }
  else{                                      // Nothing follows the label
    #ifdef debug
    printf("SOLO LABEL >>%s<<\n", token);
    #endif
    if(!get_entry(token)){            // If label unique, add it with LC
      add_entry(token, LC, LBLTYPE);
    }
    else{
      update_entry(token, LC, LBLTYPE);
    }
  }

  global = NULL; //Reset the global label for further usage
}
Ejemplo n.º 9
0
void *safe_realloc_internal(void *ptr, size_t size, char *file, int line)
{
  void *ret = realloc(ptr, size);
  if(!ret)
    DIE_MEM();

  update_entry(ptr, ret, size);
  return ret;
}
Ejemplo n.º 10
0
// Create rule entry object for given destination key and fill it with matching rule value from rule table.
// Parameters: 
//		key		: key object that contain information about destination.
//		obs		: object that contain observer for specific rule entry.
//	Returns created rule entry object.
rule_entry* rule_table_mgr::create_new_entry(route_rule_table_key key, const observer *obs)
{
	rr_mgr_logdbg("");
	NOT_IN_USE(obs);
	rule_entry* p_ent = new rule_entry(key);
	update_entry(p_ent);
	rr_mgr_logdbg("new entry %p created successfully", p_ent);
	return p_ent;
}
Ejemplo n.º 11
0
config_t copy_sequences(const config_t conf, config_t com){
    
    int i = CONFIG_PROGRAM;
    for(; i < N_CONFIG_VARIABLES; i++){
        com = update_entry(i,
            copy_entry(get_entry(i, conf)),
            com);
    }
    return com;
}
Ejemplo n.º 12
0
void route_table_mgr::update_invalid_entries()
{
	route_entry *p_rte;
	std::tr1::unordered_map<ip_address, cache_entry_subject<ip_address, route_val*> *>::iterator cache_itr;
	for (cache_itr = m_cache_tbl.begin(); cache_itr != m_cache_tbl.end(); cache_itr++) {
		p_rte = (route_entry *)cache_itr->second;
		if(!p_rte->is_valid()) {
			update_entry(p_rte);
		}
	}
}
Ejemplo n.º 13
0
route_entry* route_table_mgr::create_new_entry(ip_address p_ip, const observer *obs)
{
	// no need for lock - lock is activated in cache_collection_mgr::register_observer

	rt_mgr_logdbg("");
	NOT_IN_USE(obs);
	route_entry* p_rte = new route_entry(p_ip);
	update_entry(p_rte, true);
	rt_mgr_logdbg("new entry %p created successfully", p_rte);
	return p_rte;
}
Ejemplo n.º 14
0
route_entry* route_table_mgr::create_new_entry(route_rule_table_key key, const observer *obs)
{
	// no need for lock - lock is activated in cache_collection_mgr::register_observer

	rt_mgr_logdbg("");
	NOT_IN_USE(obs);
	route_entry* p_ent = new route_entry(key);
	update_entry(p_ent, true);
	rt_mgr_logdbg("new entry %p created successfully", p_ent);
	return p_ent;
}
Ejemplo n.º 15
0
void route_table_mgr::update_invalid_entries()
{
	route_entry *p_ent;
	std::tr1::unordered_map<route_rule_table_key, cache_entry_subject<route_rule_table_key, route_val*> *>::iterator cache_itr;
	for (cache_itr = m_cache_tbl.begin(); cache_itr != m_cache_tbl.end(); cache_itr++) {
		p_ent = (route_entry *)cache_itr->second;
		if(!p_ent->is_valid()) {
			update_entry(p_ent);
		}
	}
}
Ejemplo n.º 16
0
void
ttx_window_request_page (TTXWindow *self,
			 TTXProviderID prov_id, unsigned page,
			 unsigned subpage)
{
	const char		*combo_id;
	GtkComboBox		*combo;
	const TTXProvider	*prov;

	g_return_if_fail (TTX_IS_WINDOW(self));
	g_return_if_fail (page >= 100 && page <= 999);
	g_return_if_fail (subpage > 0);

	if (page > 999 || subpage < 1) {
		g_warning ("invalid page %u/%u", page, subpage);
		update_entry (self);
	}

	/* if not provided, get the last one (or the default) */
	if (!prov_id)
		prov_id = get_provider_id (self);

	if (prov_id) {
		prov = ttx_provider_mgr_get_provider (
			self->priv->prov_mgr, prov_id);
		if (!prov) {
			g_printerr (_("unknown teletext provider %s\n"),
				    prov_id);
			prov_id = "nos"; /* default */
		}
		
	}
	
	combo	 = GTK_COMBO_BOX(self->priv->combo);
	combo_id = gtk_combo_box_get_active_id (combo);

	self->priv->retrieving = TRUE;

	if (g_strcmp0 (prov_id, combo_id) != 0)
		if (!gtk_combo_box_set_active_id (combo, prov_id))
			g_warning ("failed to set active id to %s",
				   prov_id);

	ttx_provider_mgr_retrieve
		(self->priv->prov_mgr,
		 prov_id,
		 page, subpage,
		 (TTXProviderResultFunc)on_completed,
		 self);
}
Ejemplo n.º 17
0
/*
 * lsa_handler - Handler for any incoming LSA from other nodes.
 *
 * @param sockfd    routing daemon socket identifier
 * @param dl        pointer to direct neighbors table
 * @param rt        pointer to routing table
 * @param ht        pointer to objects hash table
 * @return          1 when successful, othersize -1
 */
int lsa_handler(int sockfd, direct_links *dl, routing_table *rt, liso_hash *ht)
{
    int forwarder_id;
    int type;
    int lsa_size;
    LSA *lsa;
    int i;
    int tmp_type, new_ttl;
    routing_entry * entry;
    link_entry *src_link;
    lsa = rt_recvfrom(sockfd, &forwarder_id, dl, &lsa_size);

    type = GET_TYPE(lsa->version_ttl_type);
    entry = get_routing_entry(rt, lsa->sender_node_id);


    if(entry != NULL && entry->lsa!= NULL && ((type == TYPE_LSA && lsa->sequence_num <= entry->lsa->sequence_num) || (type == TYPE_ACK && lsa->sequence_num != entry->lsa->sequence_num))){
        return -1;
    }

    if (type == TYPE_LSA)
    {
        tmp_type = lsa->version_ttl_type;
        lsa->version_ttl_type = SET_TYPE(lsa->version_ttl_type,TYPE_ACK);
        src_link = lookup_link_entry_node_id(dl,forwarder_id);

        rt_sendto(sockfd, lsa, src_link->host, src_link->route_p, lsa_size);
        lsa->version_ttl_type = SET_TYPE(lsa->version_ttl_type, tmp_type);	 
        
        new_ttl = GET_TTL(lsa->version_ttl_type) - 1;
        lsa->version_ttl_type = SET_TTL(lsa->version_ttl_type, new_ttl);
        update_entry(entry, rt, dl, lsa, lsa_size, forwarder_id);
        
        store_node_objects(ht,lsa);        
    }
    else if (type == TYPE_ACK)
    {
        for (i = 0; i <  entry->checkers_list->num_links; i++)
        {
            if (entry->checkers_list->checkers[i].id == forwarder_id)
            {
                rt->table[0].checkers_list->checkers[i].ack_received = ACK_RECEIVED;
                rt->table[0].checkers_list->checkers[i].retransmit = 0;

            }
        }
    }

    return 1;
}
Ejemplo n.º 18
0
static void
nmt_device_entry_set_property (GObject      *object,
                               guint         prop_id,
                               const GValue *value,
                               GParamSpec   *pspec)
{
    NmtDeviceEntry *deventry = NMT_DEVICE_ENTRY (object);
    NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
    const char *interface_name;
    const char *mac_address;

    switch (prop_id) {
    case PROP_LABEL:
        priv->label = g_value_dup_string (value);
        break;
    case PROP_WIDTH:
        nmt_newt_entry_set_width (priv->entry, g_value_get_int (value));
        break;
    case PROP_HARDWARE_TYPE:
        priv->hardware_type = g_value_get_gtype (value);
        priv->arptype = (priv->hardware_type == NM_TYPE_DEVICE_INFINIBAND) ? ARPHRD_INFINIBAND : ARPHRD_ETHER;
        break;
    case PROP_INTERFACE_NAME:
        interface_name = g_value_get_string (value);
        if (nmt_device_entry_set_interface_name (deventry, interface_name))
            update_entry (deventry);
        break;
    case PROP_MAC_ADDRESS:
        mac_address = g_value_get_string (value);
        if (nmt_device_entry_set_mac_address (deventry, mac_address))
            update_entry (deventry);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
    }
}
Ejemplo n.º 19
0
static void
on_completed (TTXRetrievalStatus status,
	      unsigned page, unsigned subpage, const char *path,
	      GSList *links, TTXWindow *self)
{
	GdkPixbuf *pixbuf;
	int h, w;

	self->priv->retrieving = FALSE;
	
	if (status != TTX_RETRIEVAL_OK) {
		g_warning ("an error occured retrieving %u/%u",
			   page, subpage);
		update_entry (self);
		return;
	}

	gtk_image_set_from_file (GTK_IMAGE(self->priv->image), path);

	/* resize the window */
	pixbuf = gtk_image_get_pixbuf (GTK_IMAGE(self->priv->image));
	if (pixbuf) {
		h = gdk_pixbuf_get_height (pixbuf);
		w = gdk_pixbuf_get_width (pixbuf);
		gtk_widget_set_size_request (self->priv->image, w, h);
	}

	reset_img_file (self, path);

	add_links (self, links);

	self->priv->page = page;
	self->priv->subpage = subpage;

	update_entry (self);
}
Ejemplo n.º 20
0
/*
 * Called when the host's ARP layer makes a change to some entry that is loaded
 * into the HW L2 table.
 */
void
t4_l2_update(struct toedev *tod, struct ifnet *ifp, struct sockaddr *sa,
    uint8_t *lladdr, uint16_t vtag)
{
	struct adapter *sc = tod->tod_softc;
	struct l2t_entry *e;
	struct l2t_data *d = sc->l2t;
	u_int hash;

	KASSERT(d != NULL, ("%s: no L2 table", __func__));

	hash = l2_hash(d, sa, ifp->if_index);
	rw_rlock(&d->lock);
	for (e = d->l2tab[hash].first; e; e = e->next) {
		if (l2_cmp(sa, e) == 0 && e->ifp == ifp) {
			mtx_lock(&e->lock);
			if (atomic_load_acq_int(&e->refcnt))
				goto found;
			e->state = L2T_STATE_STALE;
			mtx_unlock(&e->lock);
			break;
		}
	}
	rw_runlock(&d->lock);

	/*
	 * This is of no interest to us.  We've never had an offloaded
	 * connection to this destination, and we aren't attempting one right
	 * now.
	 */
	return;

found:
	rw_runlock(&d->lock);

	KASSERT(e->state != L2T_STATE_UNUSED,
	    ("%s: unused entry in the hash.", __func__));

	update_entry(sc, e, lladdr, vtag);
	mtx_unlock(&e->lock);
}
Ejemplo n.º 21
0
/*  Somewhat arbitrarily, we attempt to apply all the relocations we can
    and still notify the caller of at least one error if we found
    any errors.  */
static int
apply_rela_entries(Dwarf_Debug dbg,
    Dwarf_Bool is_64bit,
    Dwarf_Endianness endianess,
    Dwarf_Half machine,
    Dwarf_Small *target_section,
    Dwarf_Small *symtab_section,
    Dwarf_Unsigned symtab_section_size,
    Dwarf_Unsigned symtab_section_entrysize,
    struct Dwarf_Elf_Rela *relas, unsigned int nrelas,
    int *error)
{
    int return_res = DW_DLV_OK;
    if ((target_section != NULL)  && (relas != NULL)) {
        unsigned int i;
        if (symtab_section_entrysize == 0) {
            *error = DW_DLE_SYMTAB_SECTION_ENTRYSIZE_ZERO;
            return DW_DLV_ERROR;
        }
        if (symtab_section_size%symtab_section_entrysize) {
            *error = DW_DLE_SYMTAB_SECTION_LENGTH_ODD;
            return DW_DLV_ERROR;
        }
        for (i = 0; i < nrelas; i++) {
            int res = update_entry(dbg, is_64bit,
                endianess,
                machine,
                &(relas)[i],
                target_section,
                symtab_section,
                symtab_section_size,
                symtab_section_entrysize,
                error);
            if (res != DW_DLV_OK) {
                return_res = res;
            }
        }
    }
    return return_res;
}
Ejemplo n.º 22
0
void
grg_prefs_update (void)
{
	update_buttons ();
	update_entry ();
}
Ejemplo n.º 23
0
Archivo: main.c Proyecto: tm512/ispolin
void seenQuit (ircclient_t *cl, char *nick, char *host, char *reason)
{
	update_entry (nick, time (NULL));
	return;
}
Ejemplo n.º 24
0
int put_hnode( char     *str,   /* Hostname  */
               int       type,  /* obj type  */
               u_long    count, /* hit count */
               u_long    file,  /* File flag */
               double    xfer,  /* xfer size */
               u_long   *ctr,   /* counter   */
               u_long    visit, /* visits    */
               u_long    tstamp,/* timestamp */
               char     *lasturl, /* lasturl */
               HNODEPTR *htab)  /* ptr>next  */
{
   HNODEPTR cptr,nptr;

   /* check if hashed */
   if ( (cptr = htab[hash(str)]) == NULL)
   {
      /* not hashed */
      if ( (nptr=new_hnode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->files = file;
         nptr->xfer  = xfer;
         nptr->next  = NULL;
         htab[hash(str)] = nptr;
         if (type!=OBJ_GRP) (*ctr)++;

         if (visit)
         {
            nptr->visit=(visit-1);
            nptr->lasturl=find_url(lasturl);
            nptr->tstamp=tstamp;
            return 0;
         }
         else
         {
            if (ispage(log_rec.url))
            {
               if (htab==sm_htab) update_entry(log_rec.url);
               nptr->lasturl=find_url(log_rec.url);
               nptr->tstamp=tstamp;
               nptr->visit=1;
            }
         }
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
         {
            if ((type==cptr->flag)||((type!=OBJ_GRP)&&(cptr->flag!=OBJ_GRP)))
            {
               /* found... bump counter */
               cptr->count+=count;
               cptr->files+=file;
               cptr->xfer +=xfer;

               if (ispage(log_rec.url))
               {
                  if ((tstamp-cptr->tstamp)>=visit_timeout)
                  {
                     cptr->visit++;
                     if (htab==sm_htab)
                     {
                        update_exit(cptr->lasturl);
                        update_entry(log_rec.url);
                     }
                  }
                  cptr->lasturl=find_url(log_rec.url);
                  cptr->tstamp=tstamp;
               }
               return 0;
            }
         }
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_hnode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->files = file;
         nptr->xfer  = xfer;
         nptr->next  = htab[hash(str)];
         htab[hash(str)]=nptr;
         if (type!=OBJ_GRP) (*ctr)++;

         if (visit)
         {
            nptr->visit = (visit-1);
            nptr->lasturl=find_url(lasturl);
            nptr->tstamp= tstamp;
            return 0;
         }
         else
         {
            if (ispage(log_rec.url))
            {
               if (htab==sm_htab) update_entry(log_rec.url);
               nptr->lasturl=find_url(log_rec.url);
               nptr->tstamp= tstamp;
               nptr->visit=1;
            }
         }
      }
   }

   if (nptr!=NULL)
   {
      /* set object type */
      if (type==OBJ_GRP) nptr->flag=OBJ_GRP;            /* is it a grouping? */
      else
      {
         /* check if it's a hidden object */
         if ((hide_sites)||(isinlist(hidden_sites,nptr->string)!=NULL))
           nptr->flag=OBJ_HIDE;
      }
   }
   return nptr==NULL;
}
Ejemplo n.º 25
0
config_t init_config(){
 //TODO: in a c++ implementation this all can be done automatically 
 //using a hashmap
    config_t conf = new_config(N_CONFIG_VARIABLES);
   
    config_t uspace = new_config(N_USPACE_VARS);
            
    uspace = update_entry(
        USPACE_BASE,
	    new_entry_int(50176, "BASE"),
	    uspace);
	
	uspace = update_entry(
	    USPACE_WR, 
	    new_entry_int(0, "WR"),
	    uspace);
	    
	uspace = update_entry(
	    USPACE_RD, 
	    new_entry_int(8, "RD"),
	    uspace);
	
	config_t subdev = new_config(N_SUBDEV_VARS);
	
    subdev = update_entry(
        SUBDEV_IN,
	    new_entry_int(0, "IN"),
	    subdev);
	    
	subdev = update_entry(
	    SUBDEV_OUT,
	    new_entry_int(1, "OUT"),
	    subdev);
	    
    subdev = update_entry(
        SUBDEV_ADC, 
	    new_entry_int(2, "ADC"),
	    subdev);
	    
	subdev = update_entry(
	    SUBDEV_DAC, 
	    new_entry_int(3, "DAC"),
	    subdev);
	
	config_t comedi = new_config(N_COMEDI_VARS);
	
	comedi = update_entry(
	    COMEDI_FILE,
	    new_entry_int(0, "FILE"),
	    comedi);
	    
	comedi = update_entry(
	    COMEDI_SUBDEV, 
	    new_entry_map(subdev, "SUBDEV"),
	    comedi);
    
    config_t sim = new_config(N_SIM_VARS);
    
    sim = update_entry(
        SIM_INPUT,
        new_entry_str("sim.in", "INPUT"), 
        sim);
        
    sim = update_entry(
        SIM_OUTPUT,
        new_entry_str("sim.out", "OUTPUT"),
        sim);    

    conf = update_entry(
        CONFIG_STEP,
        new_entry_int(1, "STEP"),
        conf);
    
    conf = update_entry(
        CONFIG_PIPE,
        new_entry_str("plcpipe", "PIPE"),
        conf);
    
    conf = update_entry(
        CONFIG_HW,
        new_entry_str("STDI/O", "HW"),
        conf);
        
    conf = update_entry(
        CONFIG_USPACE,
        new_entry_map(uspace, "USPACE"),
        conf);
    
    conf = update_entry(
        CONFIG_COMEDI,
        new_entry_map(comedi, "COMEDI"),
        conf);
    
    conf = update_entry(
        CONFIG_SIM,
        new_entry_map(sim, "SIM"),
        conf);

   /*******************************************/
    conf = update_entry(
        CONFIG_TIMER,
        new_entry_seq(new_sequence(4), "TIMERS"),
        conf);
    
    conf = update_entry(
        CONFIG_PULSE,
        new_entry_seq(new_sequence(4), "PULSES"),
        conf);
        
    conf = update_entry(
        CONFIG_MREG,
        new_entry_seq(new_sequence(4), "MREG"),
        conf);
        
    conf = update_entry(
        CONFIG_MVAR,
        new_entry_seq(new_sequence(4), "MVAR"),
        conf);
    
    conf = update_entry(
        CONFIG_DI,
        new_entry_seq(new_sequence(8), "DI"),
        conf);
 
    conf = update_entry(
        CONFIG_DQ,
        new_entry_seq(new_sequence(8), "DQ"),
        conf);
    
    conf = update_entry(
        CONFIG_AI,
        new_entry_seq(new_sequence(8), "AI"),
        conf);
    
    conf = update_entry(
        CONFIG_AQ,
        new_entry_seq(new_sequence(8), "AQ"),
        conf);

    conf = update_entry(
        CONFIG_PROGRAM,
        new_entry_seq(new_sequence(2), "PROGRAM"),
        conf);

    return conf;
}
Ejemplo n.º 26
0
int     transport_lookup(TRANSPORT_INFO *tp, const char *addr,
			         const char *rcpt_domain,
			         VSTRING *channel, VSTRING *nexthop)
{
    char   *stripped_addr;
    char   *ratsign = 0;
    const char *name;
    const char *next;
    int     found;

#define STREQ(x,y)	(strcmp((x), (y)) == 0)
#define DISCARD_EXTENSION ((char **) 0)

    /*
     * The null recipient is rewritten to the local mailer daemon address.
     */
    if (*addr == 0) {
	msg_warn("transport_lookup: null address - skipping table lookup");
	return (NOTFOUND);
    }

    /*
     * Look up the full address with the FULL flag to include regexp maps in
     * the query.
     */
    if ((ratsign = strrchr(addr, '@')) == 0 || ratsign[1] == 0)
	msg_panic("transport_lookup: bad address: \"%s\"", addr);

    if (find_transport_entry(tp, addr, rcpt_domain, FULL, channel, nexthop))
	return (FOUND);
    if (tp->transport_path->error != 0)
	return (NOTFOUND);

    /*
     * If the full address did not match, and there is an address extension,
     * look up the stripped address with the PARTIAL flag to avoid matching
     * partial lookup keys with regular expressions.
     */
    if ((stripped_addr = strip_addr(addr, DISCARD_EXTENSION,
				    var_rcpt_delim)) != 0) {
	found = find_transport_entry(tp, stripped_addr, rcpt_domain, PARTIAL,
				     channel, nexthop);

	myfree(stripped_addr);
	if (found)
	    return (FOUND);
	if (tp->transport_path->error != 0)
	    return (NOTFOUND);
    }

    /*
     * If the full and stripped address lookup fails, try domain name lookup.
     * 
     * Keep stripping domain components until nothing is left or until a
     * matching entry is found.
     * 
     * After checking the full domain name, check for .upper.domain, to
     * distinguish between the parent domain and it's decendants, a la
     * sendmail and tcp wrappers.
     * 
     * Before changing the DB lookup result, make a copy first, in order to
     * avoid DB cache corruption.
     * 
     * Specify that the lookup key is partial, to avoid matching partial keys
     * with regular expressions.
     */
    for (name = ratsign + 1; *name != 0; name = next) {
	if (find_transport_entry(tp, name, rcpt_domain, PARTIAL, channel, nexthop))
	    return (FOUND);
	if (tp->transport_path->error != 0)
	    return (NOTFOUND);
	if ((next = strchr(name + 1, '.')) == 0)
	    break;
	if (transport_match_parent_style == MATCH_FLAG_PARENT)
	    next++;
    }

    /*
     * Fall back to the wild-card entry.
     */
    if (tp->wildcard_errno || event_time() > tp->expire)
	transport_wildcard_init(tp);
    if (tp->wildcard_errno) {
	tp->transport_path->error = tp->wildcard_errno;
	return (NOTFOUND);
    } else if (tp->wildcard_channel) {
	update_entry(STR(tp->wildcard_channel), STR(tp->wildcard_nexthop),
		     rcpt_domain, channel, nexthop);
	return (FOUND);
    }

    /*
     * We really did not find it.
     */
    return (NOTFOUND);
}
Ejemplo n.º 27
0
HYPRE_Int hypre_AMGeAgglomerate(HYPRE_Int *i_AE_element, HYPRE_Int *j_AE_element,

                                HYPRE_Int *i_face_face, HYPRE_Int *j_face_face, HYPRE_Int *w_face_face,

                                HYPRE_Int *i_face_element, HYPRE_Int *j_face_element,
                                HYPRE_Int *i_element_face, HYPRE_Int *j_element_face,

                                HYPRE_Int *i_face_to_prefer_weight,
                                HYPRE_Int *i_face_weight,

                                HYPRE_Int num_faces, HYPRE_Int num_elements,
                                HYPRE_Int *num_AEs_pointer)
{

    HYPRE_Int ierr = 0;
    HYPRE_Int i, j, k, l;

    HYPRE_Int face_to_eliminate;
    HYPRE_Int max_weight_old, max_weight;

    HYPRE_Int AE_counter=0, AE_element_counter=0;

    /* HYPRE_Int i_element_face_counter; */

    HYPRE_Int *i_element_to_AE;

    HYPRE_Int *previous, *next, *first;
    HYPRE_Int head, tail, last;

    HYPRE_Int face_max_weight, face_local_max_weight, preferred_weight;

    HYPRE_Int weight, weight_max;

    max_weight = 1;
    for (i=0; i < num_faces; i++)
    {
        weight = 1;
        for (j=i_face_face[i]; j < i_face_face[i+1]; j++)
            weight+= w_face_face[j];
        if (max_weight < weight) max_weight = weight;
    }

    first = hypre_CTAlloc(HYPRE_Int, max_weight+1);



    next = hypre_CTAlloc(HYPRE_Int, num_faces);


    previous = hypre_CTAlloc(HYPRE_Int, num_faces+1);


    tail = num_faces;
    head = -1;

    for (i=0; i < num_faces; i++)
    {
        next[i] = i+1;
        previous[i] = i-1;
    }

    last = num_faces-1;
    previous[tail] = last;

    for (weight=1; weight <= max_weight; weight++)
        first[weight] = tail;

    i_element_to_AE = hypre_CTAlloc(HYPRE_Int, num_elements);

    /*=======================================================================
                       AGGLOMERATION PROCEDURE:
      ======================================================================= */

    for (k=0; k < num_elements; k++)
        i_element_to_AE[k] = -1;

    for (k=0; k < num_faces; k++)
        i_face_weight[k] = 1;


    first[0] = 0;
    first[1] = 0;

    last = previous[tail];
    weight_max = i_face_weight[last];


    k = last;
    face_max_weight = -1;
    while (k!= head)
    {
        if (i_face_to_prefer_weight[k] > -1)
            face_max_weight = k;

        if (face_max_weight > -1) break;

        k=previous[k];
    }


    /* this will be used if the faces have been sorted: *****************
    k = last;
    face_max_weight = -1;
    while (k != head)
      {
        if (i_face_to_prefer_weight[k] > -1)
    face_max_weight = k;


        if (face_max_weight > -1)
    {
      max_weight = i_face_weight[face_max_weight];
      l = face_max_weight;

      while (previous[l] != head)
        {

          if (i_face_weight[previous[l]] < max_weight)
    	break;
          else
    	if (i_face_to_prefer_weight[previous[l]] >
    	    i_face_to_prefer_weight[face_max_weight])
    	  {
    	    l = previous[l];
    	    face_max_weight = l;
    	  }
    	else
    	  l = previous[l];
        }

      break;
    }


        l =previous[k];



        weight = i_face_weight[k];
        last = previous[tail];
        if (last == head)
    weight_max = 0;
        else
    weight_max = i_face_weight[last];


        ierr = remove_entry(weight, &weight_max,
    		  previous, next, first, &last,
    		  head, tail,
    		  k);





        k=l;
      }
      */

    if (face_max_weight == -1)
    {
        hypre_printf("all faces are unacceptable, i.e., no faces to eliminate !\n");

        *num_AEs_pointer = 1;

        i_AE_element[0] = 0;
        for (i=0; i < num_elements; i++)
        {
            i_element_to_AE[i] = 0;
            j_AE_element[i] = i;
        }

        i_AE_element[1] = num_elements;

        return ierr;
    }

    for (k=0; k < num_faces; k++)
        if (i_face_to_prefer_weight[k] > i_face_to_prefer_weight[face_max_weight])
            face_max_weight = k;

    max_weight = i_face_weight[face_max_weight];

    AE_counter=0;
    AE_element_counter=0;


    i_AE_element[AE_counter] = AE_element_counter;

    max_weight_old = -1;

    face_local_max_weight = face_max_weight;

eliminate_face:

    face_to_eliminate = face_local_max_weight;

    max_weight = i_face_weight[face_to_eliminate];

    last = previous[tail];
    if (last == head)
        weight_max = 0;
    else
        weight_max = i_face_weight[last];


    ierr = remove_entry(max_weight, &weight_max,
                        previous, next, first, &last,
                        head, tail,
                        face_to_eliminate);

    i_face_weight[face_to_eliminate] = 0;

    /*----------------------------------------------------------
     *  agglomeration step:
     *
     *  put on AE_element -- list all elements
     *  that share face "face_to_eliminate";
     *----------------------------------------------------------*/

    for (k = i_face_element[face_to_eliminate];
            k < i_face_element[face_to_eliminate+1]; k++)
    {
        /* check if element j_face_element[k] is already on the list: */

        if (j_face_element[k] < num_elements)
        {
            if (i_element_to_AE[j_face_element[k]] == -1)
            {
                j_AE_element[AE_element_counter] = j_face_element[k];
                i_element_to_AE[j_face_element[k]] = AE_counter;
                AE_element_counter++;
            }
        }
    }


    /* local update & search:==================================== */

    for (j=i_face_face[face_to_eliminate];
            j<i_face_face[face_to_eliminate+1]; j++)
        if (i_face_weight[j_face_face[j]] > 0)
        {
            weight = i_face_weight[j_face_face[j]];


            last = previous[tail];
            if (last == head)
                weight_max = 0;
            else
                weight_max = i_face_weight[last];

            ierr = move_entry(weight, &weight_max,
                              previous, next, first, &last,
                              head, tail,
                              j_face_face[j]);

            i_face_weight[j_face_face[j]]+=w_face_face[j];

            weight = i_face_weight[j_face_face[j]];

            /* hypre_printf("update entry: %d\n", j_face_face[j]);  */

            last = previous[tail];
            if (last == head)
                weight_max = 0;
            else
                weight_max = i_face_weight[last];

            ierr = update_entry(weight, &weight_max,
                                previous, next, first, &last,
                                head, tail,
                                j_face_face[j]);

            last = previous[tail];
            if (last == head)
                weight_max = 0;
            else
                weight_max = i_face_weight[last];

        }

    /* find a face of the elements that have already been agglomerated
       with a maximal weight: ====================================== */

    max_weight_old = max_weight;

    face_local_max_weight = -1;
    preferred_weight = -1;

    for (l = i_AE_element[AE_counter];
            l < AE_element_counter; l++)
    {
        for (j=i_element_face[j_AE_element[l]];
                j<i_element_face[j_AE_element[l]+1]; j++)
        {
            i = j_element_face[j];

            if (max_weight_old > 1 && i_face_weight[i] > 0 &&
                    i_face_to_prefer_weight[i] > -1)
            {
                if ( max_weight < i_face_weight[i])
                {
                    face_local_max_weight = i;
                    max_weight = i_face_weight[i];
                    preferred_weight = i_face_to_prefer_weight[i];
                }

                if ( max_weight == i_face_weight[i]
                        && i_face_to_prefer_weight[i] > preferred_weight)
                {
                    face_local_max_weight = i;
                    preferred_weight = i_face_to_prefer_weight[i];
                }

            }
        }
    }

    if (face_local_max_weight > -1) goto eliminate_face;

    /* ----------------------------------------------------------------
     * eliminate and label with i_face_weight[ ] = -1
     * "boundary faces of agglomerated elements";
     * those faces will be preferred for the next coarse spaces
     * in case multiple coarse spaces are to be built;
     * ---------------------------------------------------------------*/

    for (k = i_AE_element[AE_counter]; k < AE_element_counter; k++)
    {
        for (j = i_element_face[j_AE_element[k]];
                j < i_element_face[j_AE_element[k]+1]; j++)
        {
            if (i_face_weight[j_element_face[j]] > 0)
            {
                weight = i_face_weight[j_element_face[j]];
                last = previous[tail];
                if (last == head)
                    weight_max = 0;
                else
                    weight_max = i_face_weight[last];


                ierr = remove_entry(weight, &weight_max,
                                    previous, next, first, &last,
                                    head, tail,
                                    j_element_face[j]);

                i_face_weight[j_element_face[j]] = -1;

            }
        }
    }

    if (AE_element_counter > i_AE_element[AE_counter])
    {
        /* hypre_printf("completing agglomerated element: %d\n",
          AE_counter);   */
        AE_counter++;
    }

    i_AE_element[AE_counter] = AE_element_counter;


    /* find a face with maximal weight: ---------------------------*/


    last = previous[tail];
    if (last == head) goto end_agglomerate;

    weight_max = i_face_weight[last];


    /* hypre_printf("global search: ======================================\n"); */

    face_max_weight = -1;

    k = last;
    while (k != head)
    {
        if (i_face_to_prefer_weight[k] > -1)
            face_max_weight = k;


        if (face_max_weight > -1)
        {
            max_weight = i_face_weight[face_max_weight];
            l = face_max_weight;

            while (previous[l] != head)
            {

                if (i_face_weight[previous[l]] < max_weight)
                    break;
                else if (i_face_to_prefer_weight[previous[l]] >
                         i_face_to_prefer_weight[face_max_weight])
                {
                    l = previous[l];
                    face_max_weight = l;
                }
                else
                    l = previous[l];
            }

            break;
        }


        l =previous[k];
        /* remove face k: ---------------------------------------*/


        weight = i_face_weight[k];
        last = previous[tail];
        if (last == head)
            weight_max = 0;
        else
            weight_max = i_face_weight[last];


        ierr = remove_entry(weight, &weight_max,
                            previous, next, first, &last,
                            head, tail,
                            k);


        /* i_face_weight[k] = -1; */


        k=l;
    }

    if (face_max_weight == -1) goto end_agglomerate;

    max_weight = i_face_weight[face_max_weight];

    face_local_max_weight = face_max_weight;

    goto eliminate_face;

end_agglomerate:


    /* eliminate isolated elements: ----------------------------------*/

    for (i=0; i<num_elements; i++)
    {

        if (i_element_to_AE[i] == -1)
        {
            for (j=i_element_face[i]; j < i_element_face[i+1]
                    && i_element_to_AE[i] == -1; j++)
                if (i_face_to_prefer_weight[j_element_face[j]] > -1)
                    for (k=i_face_element[j_element_face[j]];
                            k<i_face_element[j_element_face[j]+1]
                            && i_element_to_AE[i] == -1; k++)
                        if (i_element_to_AE[j_face_element[k]] != -1)
                            i_element_to_AE[i] = i_element_to_AE[j_face_element[k]];
        }

        /*
        if (i_element_to_AE[i] == -1)
        {
          i_element_face_counter = 0;
          for (j=i_element_face[i]; j < i_element_face[i+1]; j++)
            if (i_face_to_prefer_weight[j_element_face[j]] > -1)
              i_element_face_counter++;

          if (i_element_face_counter == 1)
            {
              for (j=i_element_face[i]; j < i_element_face[i+1]; j++)
        	if (i_face_to_prefer_weight[j_element_face[j]] > -1)
        	  for (k=i_face_element[j_element_face[j]];
        	       k<i_face_element[j_element_face[j]+1]; k++)
        	    if (i_element_to_AE[j_face_element[k]] != -1)
        	      i_element_to_AE[i] = i_element_to_AE[j_face_element[k]];
            }
        }
        */

        if (i_element_to_AE[i] == -1)
        {
            i_element_to_AE[i] = AE_counter;
            AE_counter++;
        }
    }

    num_AEs_pointer[0] = AE_counter;


    /* compute adjoint graph: -------------------------------------------*/

    for (i=0; i < AE_counter; i++)
        i_AE_element[i] = 0;

    for (i=0; i < num_elements; i++)
        i_AE_element[i_element_to_AE[i]]++;

    i_AE_element[AE_counter] = num_elements;

    for (i=AE_counter-1; i > -1; i--)
        i_AE_element[i] = i_AE_element[i+1] - i_AE_element[i];

    for (i=0; i < num_elements; i++)
    {
        j_AE_element[i_AE_element[i_element_to_AE[i]]] = i;
        i_AE_element[i_element_to_AE[i]]++;
    }

    for (i=AE_counter-1; i > -1; i--)
        i_AE_element[i+1] = i_AE_element[i];

    i_AE_element[0] = 0;

    /*--------------------------------------------------------------------*/
    for (i=0; i < num_faces; i++)
        if (i_face_to_prefer_weight[i] == -1) i_face_weight[i] = -1;


    hypre_TFree(i_element_to_AE);

    hypre_TFree(previous);
    hypre_TFree(next);
    hypre_TFree(first);

    return ierr;
}
Ejemplo n.º 28
0
int main() {
    while (FCGI_Accept() >= 0) {
        char type[80] = "html";
        char entry[10] = "0";
        char comments[6] = "false";
        char *req_method;
        char gets[1000];

        req_method = getenv("REQUEST_METHOD");

        if (strcmp(req_method, "PUT") == 0) {
            char id[10];

            strcpy(gets, getenv("QUERY_STRING"));

            if (getenv("QUERY_STRING") == NULL) {
                printf("Status: 400 Bad Request\r\n\r\n");
            } else {
                get_param(gets, "id", id, 10);

                int entry_id = strtol(id, NULL, 10);

                // grab the post data
                int len = strtol(getenv("CONTENT_LENGTH"), NULL, 10);
                char *content = (char *)malloc(sizeof(char) * len);
                fread(content, sizeof(char), len, stdin);

                LIBXML_TEST_VERSION

                char *t;
                char *c;
                const int TS = 256;
                int code;

                t = (char *)malloc(sizeof(char) * TS);
                c = (char *)malloc(sizeof(char) * len);

                if (parse_post(content, t, TS, c, len) == 0) {

                    code = update_entry(entry_id, t, c);
                    if (code == 0) {
                        printf("Status: 200 OK\r\n");
                        printf("Content-type: text/xml; charset=UTF-8\r\n"
                            "\r\n");

                        generate_entries(1, entry_id, "atom_single.ct");

                    } else {
                        printf("Status: 500 Internal Server Error\r\n\r\nDB Error Code: %d - %d \n\n", code, entry_id);
                    }

                } else {
                    printf("Status: 400 Bad Request\r\n\r\n");
                }

                free(t);
                free(c);
                free(content);
            }
        } else 
        if (strcmp(req_method, "DELETE") == 0) {
            char id[10];

            strcpy(gets, getenv("QUERY_STRING"));

            if (getenv("QUERY_STRING") == NULL) {
                printf("Status: 400 Bad Request\r\n\r\n");
            } else {
                get_param(gets, "id", id, 10);

                if (remove_entry(strtol(id, NULL, 10)) == 0) {
                    printf("Status: 204 No Content\r\n\r\n");
                } else {
                    printf("Status: 400 Bad Request\r\n\r\n");
                }
            }

        } else
        if (strcmp(req_method, "POST") == 0) {
            if (getenv("QUERY_STRING") == NULL) {
                printf("Status: 400 Bad Request\r\n\r\n");
            }

            // parse the post function
            char function[20];
            strcpy(gets, getenv("QUERY_STRING"));
            get_param(gets, "function", function, 20);
            get_param(gets, "format", type, 20);

            // grab the post data
            int len = strtol(getenv("CONTENT_LENGTH"), NULL, 10);
            char *content = (char *)malloc(sizeof(char) * len);
            fread(content, sizeof(char), len, stdin);

            //atom post!
            if (strcmp(type, "atom") == 0) {
                LIBXML_TEST_VERSION

                char *t;
                char *c;
                const int TS = 256;
                int id;

                t = (char *)malloc(sizeof(char) * TS);
                c = (char *)malloc(sizeof(char) * len);

                if (parse_post(content, t, TS, c, len) == 0) {
                    id = add_entry(t, c);

                    if (id > 0) {
                        printf("Status: 201 Created\r\n\r\n");
                        printf("Content-type: text/xml; charset=UTF-8\r\n"
                            "\r\n");
                        generate_entries(1, id, "atom_single.ct");
                    } else {
                        printf("Status: 500 Internal Server Error\r\n\r\nDB Error Code: %d", id);
                    }
                } else {
                    printf("Status: 400 Bad Request\r\n\r\n");
                }

                free(t);
                free(c);
                free(content);
            } else 
            if (strcmp(function, "comment") == 0) {
                char entry_id[10];
                char comment[len];
                int ac;

                get_param(content, "entry_id", entry_id, 10);
                get_param(content, "content", comment, len);

                ac = add_comment(strtol(entry_id, NULL, 10), comment);

                fprintf(stderr, "Does it get here?");

                if (ac > 0) {
                    printf("Content-type: application/json; charset=UTF-8\r\n");
                    printf("\r\n");
                    printf("{'success': true}");
                } else {
                    printf("Status: 500 Internal Server Error\r\n\r\n");
                    printf("{'success': false, 'error_code': %d}", ac);
                }
            } else {
                printf("Status: 400 Bad Request\r\n\r\n");
            }

            free(content);

            /*
            int len = strtol(getenv("CONTENT_LENGTH"), NULL, 10);
            char *content = (char *)malloc(sizeof(char) * len);
            fread(content, sizeof(char), len, stdin);


            */
        } else // end if( type == "POST")

        if (strcmp(req_method, "GET") == 0) {

            if (getenv("QUERY_STRING") != NULL) {
                char gets[1000];

                strcpy(gets, getenv("QUERY_STRING"));
                get_param(gets, "entry", entry, 10);

                strcpy(gets, getenv("QUERY_STRING"));
                get_param(gets, "format", type, 20);

                strcpy(gets, getenv("QUERY_STRING"));
                get_param(gets, "get_comments", comments, 6);
            }


            if (strcmp(type, "html") == 0) {
                // application/xhtml+xml doesn't work with IE -_-;;
                //printf("Content-type: application/xhtml+xml; charset=UTF-8\r\n"
                // have to serve xhtml as html... IE sucks
                printf("Content-type: text/html; charset=UTF-8\r\n"
                        "\r\n");
            } else
            if (strcmp(type, "json") == 0) {
                printf("Content-type: application/json; charset=UTF-8\r\n"
                        "\r\n");
            } else
            if (strcmp(type, "rss") == 0) {
                printf("Content-type: application/rss+xml; charset=UTF-8\r\n"
                        "\r\n");
            } else 
            if (strcmp(type, "atom") == 0) {
                printf("Content-type: application/atom+xml; charset=UTF-8\r\n"
                        "\r\n");
            } else {
                printf("Status: 400 Bad Request\r\n\r\n");
                break;
            }

            if (strcmp(comments, "true") == 0) {
                strcat(type, "_comments.ct");
                generate_comments(strtol(entry, NULL, 10), type);
            } else {
                /* defaults to creating the main blog */
                strcat(type, ".ct");
                if(strcmp(entry,"0") == 0) {
                    generate_entries(10, 1, type);
                } else { 
                    generate_entries(1, strtol(entry, NULL, 10), type);
                }
            }

        } // end if( type == "GET")
    }
    return 0;
}
Ejemplo n.º 29
0
void  QP_basis_inverse<ET_,Is_LP_>::
z_update_inplace( ForIt psi1_l_it, ForIt psi1_x_it,
                  ForIt psi2_l_it, ForIt psi2_x_it,
	             const ET& omega0, const ET& omega1,
		         const ET& omega2, const ET& omega3)
{
    typename Matrix::      iterator  matrix_it;
    typename Row   ::      iterator     row_it;
    typename Row   ::const_iterator      y_it1_r, y_it1_c, y_it2_r, y_it2_c;
	
    unsigned int  row, col, k = l+b;
    ET           u_elem;

    // rows: 0..s-1  ( P )
    for (  row = 0, matrix_it = M.begin(),
           y_it1_r = psi1_l_it,  y_it2_r = psi2_l_it;
	   row < s;
         ++row, ++matrix_it, ++y_it1_r, ++y_it2_r  ) {
	      
        // columns: 0..row  ( P )
        for (   row_it =  matrix_it->begin(),
	        y_it1_c = psi1_l_it,  y_it2_c = psi2_l_it;
                row_it != matrix_it->end();
              ++row_it,  ++y_it1_c,  ++y_it2_c            ) {
                
            u_elem = (*y_it1_r * *y_it2_c) + (*y_it2_r * *y_it1_c);
	    u_elem *= omega2;
	    u_elem += omega1 * *y_it1_r * *y_it1_c;
            update_entry( *row_it, omega0, u_elem, omega3);
        } 
    }
	
    // rows: l..k-1  ( Q R )
    for (  row = l, matrix_it = M.begin()+l,
	   y_it1_r = psi1_x_it,  y_it2_r = psi2_x_it;
	   row != k;
	 ++row,  ++matrix_it,  ++y_it1_r,  ++y_it2_r ) {
	    
        // columns: 0..s-1  ( Q )
        for (   col = 0,   row_it =  matrix_it->begin(),
	        y_it1_c = psi1_l_it,  y_it2_c = psi2_l_it;
                col < s;
              ++col, ++row_it,  ++y_it1_c,  ++y_it2_c     ){
    
            u_elem = (*y_it1_r * *y_it2_c) + (*y_it2_r * *y_it1_c);
	       u_elem *= omega2;
	       u_elem += omega1 * *y_it1_r * *y_it1_c; 
	       update_entry( *row_it, omega0, u_elem, omega3);
        }
    
        // columns: l..k-1  ( R )
        for (  row_it = matrix_it->begin()+l,
	       y_it1_c = psi1_x_it,  y_it2_c = psi2_x_it;
               row_it != matrix_it->end();
             ++row_it,  ++y_it1_c,  ++y_it2_c            ){
		 
            u_elem = (*y_it1_r * *y_it2_c) + (*y_it2_r * *y_it1_c);
            u_elem *= omega2;
	        u_elem += omega1 * *y_it1_r * *y_it1_c;     
            update_entry( *row_it, omega0, u_elem, omega3);
        }
	    
    } 
	
} 
Ejemplo n.º 30
0
Archivo: main.c Proyecto: tm512/ispolin
void seenNick (ircclient_t *cl, char *nick, char *host, char *newnick)
{
	update_entry (nick, time (NULL));
	update_entry (newnick, time (NULL));
	return;
}