コード例 #1
0
ファイル: set.c プロジェクト: jianingy/bitlbee-clone
int set_getbool( set_t **head, char *key )
{
	char *s = set_getstr( head, key );
	
	if( !s )
		return 0;
	
	return bool2int( s );
}
コード例 #2
0
ファイル: irc_im.c プロジェクト: wingo/bitlbee
static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, guint32 flags, time_t sent_at)
{
	irc_t *irc = bee->ui_data;
	irc_user_t *iu = (irc_user_t *) bu->ui_data;
	irc_user_t *src_iu = iu;
	irc_user_t *dst_iu = irc->user;
	const char *dst;
	char *prefix = NULL;
	char *wrapped, *ts = NULL;
	char *msg = g_strdup(msg_);
	char *message_type = "PRIVMSG";
	GSList *l;

	if (sent_at > 0 && set_getbool(&irc->b->set, "display_timestamps")) {
		ts = irc_format_timestamp(irc, sent_at);
	}

	dst = irc_user_msgdest(iu);

	if (flags & OPT_SELFMESSAGE) {
		char *setting = set_getstr(&irc->b->set, "self_messages");

		if (is_bool(setting)) {
			if (bool2int(setting)) {
				/* set to true, send it with src/dst flipped */
				
				dst_iu = iu;
				src_iu = irc->user;

				if (dst == irc->user->nick) {
					dst = dst_iu->nick;
				}
			} else {
				/* set to false, skip the message completely */
				goto cleanup;
			}
		} else if (g_strncasecmp(setting, "prefix", 6) == 0) {
			/* third state, prefix, loosely imitates the znc privmsg_prefix module */

			g_free(msg);
			if (g_strncasecmp(msg_, "/me ", 4) == 0) {
				msg = g_strdup_printf("/me -> %s", msg_ + 4);
			} else {
				msg = g_strdup_printf("-> %s", msg_);
			}

			if (g_strcasecmp(setting, "prefix_notice") == 0) {
				message_type = "NOTICE";
			}
		}

	}

	if (dst != dst_iu->nick) {
		/* if not messaging directly (control channel), call user by name */
		prefix = g_strdup_printf("%s%s%s", dst_iu->nick, set_getstr(&bee->set, "to_char"), ts ? : "");
	} else {
コード例 #3
0
ファイル: set.c プロジェクト: MrSam/bitlbee
char *set_eval_oauth( set_t *set, char *value )
{
	account_t *acc = set->data;
	
	if( bool2int( value ) && strcmp( acc->pass, PASSWORD_PENDING ) == 0 )
		*acc->pass = '******';
	
	return set_eval_bool( set, value );
}
コード例 #4
0
ファイル: account.c プロジェクト: jianingy/bitlbee-clone
char *set_eval_account( set_t *set, char *value )
{
	account_t *acc = set->data;
	
	/* Double-check: We refuse to edit on-line accounts. */
	if( set->flags & ACC_SET_OFFLINE_ONLY && acc->ic )
		return SET_INVALID;
	
	if( strcmp( set->key, "server" ) == 0 )
	{
		g_free( acc->server );
		if( value && *value )
		{
			acc->server = g_strdup( value );
			return value;
		}
		else
		{
			acc->server = g_strdup( set->def );
			return g_strdup( set->def );
		}
	}
	else if( strcmp( set->key, "username" ) == 0 )
	{
		g_free( acc->user );
		acc->user = g_strdup( value );
		return value;
	}
	else if( strcmp( set->key, "password" ) == 0 )
	{
		if( value )
		{
			g_free( acc->pass );
			acc->pass = g_strdup( value );
			return NULL;	/* password shouldn't be visible in plaintext! */
		}
		else
		{
			/* NULL can (should) be stored in the set_t
			   variable, but is otherwise not correct. */
			return SET_INVALID;
		}
	}
	else if( strcmp( set->key, "auto_connect" ) == 0 )
	{
		if( !is_bool( value ) )
			return SET_INVALID;
		
		acc->auto_connect = bool2int( value );
		return value;
	}
	
	return SET_INVALID;
}
コード例 #5
0
ファイル: steam.c プロジェクト: dequis/bitlbee-steam
/**
 * Implemented #set_eval for the set of game_status.
 *
 * @param set   The #set_t.
 * @param value The set value.
 *
 * @return The resulting set value.
 **/
static char *steam_eval_game_status(set_t *set, char *value)
{
    account_t *acc = set->data;
    SteamData *sata;

    if (!is_bool(value))
        return SET_INVALID;

    if (acc->ic == NULL)
        return value;

    sata = acc->ic->proto_data;
    sata->game_status = bool2int(value);

    return value;
}
コード例 #6
0
ファイル: root_commands.c プロジェクト: EionRobb/bitlbee
static void cmd_account(irc_t *irc, char **cmd)
{
	account_t *a;
	int len;

	if (global.conf->authmode == AUTHMODE_REGISTERED && !(irc->status & USTATUS_IDENTIFIED)) {
		irc_rootmsg(irc, "This server only accepts registered users");
		return;
	}

	len = strlen(cmd[1]);

	if (len >= 1 && g_strncasecmp(cmd[1], "add", len) == 0) {
		struct prpl *prpl;

		MIN_ARGS(3);

		if (!global.conf->allow_account_add) {
			irc_rootmsg(irc, "This server does not allow adding new accounts");
			return;
		}

		if (cmd[4] == NULL) {
			for (a = irc->b->accounts; a; a = a->next) {
				if (strcmp(a->pass, PASSWORD_PENDING) == 0) {
					irc_rootmsg(irc, "Enter password for account %s "
					            "first (use /OPER)", a->tag);
					return;
				}
			}

			irc->status |= OPER_HACK_ACCOUNT_PASSWORD;
		}

		prpl = find_protocol(cmd[2]);

		if (prpl == NULL) {
			if (is_protocol_disabled(cmd[2])) {
				irc_rootmsg(irc, "Protocol disabled in global config");
			} else {
				irc_rootmsg(irc, "Unknown protocol");
			}
			return;
		}

		for (a = irc->b->accounts; a; a = a->next) {
			if (a->prpl == prpl && prpl->handle_cmp(a->user, cmd[3]) == 0) {
				irc_rootmsg(irc, "Warning: You already have an account with "
				            "protocol `%s' and username `%s'. Are you accidentally "
				            "trying to add it twice?", prpl->name, cmd[3]);
			}
		}

		a = account_add(irc->b, prpl, cmd[3], cmd[4] ? cmd[4] : PASSWORD_PENDING);
		if (cmd[5]) {
			irc_rootmsg(irc, "Warning: Passing a servername/other flags to `account add' "
			            "is now deprecated. Use `account set' instead.");
			set_setstr(&a->set, "server", cmd[5]);
		}

		irc_rootmsg(irc, "Account successfully added with tag %s", a->tag);

		if (cmd[4] == NULL) {
			set_t *oauth = set_find(&a->set, "oauth");
			if (oauth && bool2int(set_value(oauth))) {
				*a->pass = '******';
				irc_rootmsg(irc, "No need to enter a password for this "
				            "account since it's using OAuth");
			} else {
				irc_rootmsg(irc, "You can now use the /OPER command to "
				            "enter the password");
				if (oauth) {
					irc_rootmsg(irc, "Alternatively, enable OAuth if "
					            "the account supports it: account %s "
					            "set oauth on", a->tag);
				}
			}
		}

		return;
	} else if (len >= 1 && g_strncasecmp(cmd[1], "list", len) == 0) {
		int i = 0;

		if (strchr(irc->umode, 'b')) {
			irc_rootmsg(irc, "Account list:");
		}

		for (a = irc->b->accounts; a; a = a->next) {
			char *con;

			if (a->ic && (a->ic->flags & OPT_LOGGED_IN)) {
				con = " (connected)";
			} else if (a->ic) {
				con = " (connecting)";
			} else if (a->reconnect) {
				con = " (awaiting reconnect)";
			} else {
				con = "";
			}

			irc_rootmsg(irc, "%2d (%s): %s, %s%s", i, a->tag, a->prpl->name, a->user, con);

			i++;
		}
		irc_rootmsg(irc, "End of account list");

		return;
	} else if (cmd[2]) {
		/* Try the following two only if cmd[2] == NULL */
	} else if (len >= 2 && g_strncasecmp(cmd[1], "on", len) == 0) {
		if (irc->b->accounts) {
			irc_rootmsg(irc, "Trying to get all accounts connected...");

			for (a = irc->b->accounts; a; a = a->next) {
				if (!a->ic && a->auto_connect) {
					if (strcmp(a->pass, PASSWORD_PENDING) == 0) {
						irc_rootmsg(irc, "Enter password for account %s "
						            "first (use /OPER)", a->tag);
					} else {
						account_on(irc->b, a);
					}
				}
			}
		} else {
			irc_rootmsg(irc, "No accounts known. Use `account add' to add one.");
		}

		return;
	} else if (len >= 2 && g_strncasecmp(cmd[1], "off", len) == 0) {
		irc_rootmsg(irc, "Deactivating all active (re)connections...");

		for (a = irc->b->accounts; a; a = a->next) {
			if (a->ic) {
				account_off(irc->b, a);
			} else if (a->reconnect) {
				cancel_auto_reconnect(a);
			}
		}

		return;
	}

	MIN_ARGS(2);
	len = strlen(cmd[2]);

	/* At least right now, don't accept on/off/set/del as account IDs even
	   if they're a proper match, since people not familiar with the new
	   syntax yet may get a confusing/nasty surprise. */
	if (g_strcasecmp(cmd[1], "on") == 0 ||
	    g_strcasecmp(cmd[1], "off") == 0 ||
	    g_strcasecmp(cmd[1], "set") == 0 ||
	    g_strcasecmp(cmd[1], "del") == 0 ||
	    (a = account_get(irc->b, cmd[1])) == NULL) {
		irc_rootmsg(irc, "Could not find account `%s'.", cmd[1]);

		return;
	}

	if (len >= 1 && g_strncasecmp(cmd[2], "del", len) == 0) {
		if (a->flags & ACC_FLAG_LOCKED) {
			irc_rootmsg(irc, "Account is locked, can't delete");
		}
		else if (a->ic) {
			irc_rootmsg(irc, "Account is still logged in, can't delete");
		} else {
			account_del(irc->b, a);
			irc_rootmsg(irc, "Account deleted");
		}
	} else if (len >= 2 && g_strncasecmp(cmd[2], "on", len) == 0) {
		if (a->ic) {
			irc_rootmsg(irc, "Account already online");
		} else if (strcmp(a->pass, PASSWORD_PENDING) == 0) {
			irc_rootmsg(irc, "Enter password for account %s "
			            "first (use /OPER)", a->tag);
		} else {
			account_on(irc->b, a);
		}
	} else if (len >= 2 && g_strncasecmp(cmd[2], "off", len) == 0) {
		if (a->ic) {
			account_off(irc->b, a);
		} else if (a->reconnect) {
			cancel_auto_reconnect(a);
			irc_rootmsg(irc, "Reconnect cancelled");
		} else {
			irc_rootmsg(irc, "Account already offline");
		}
	} else if (len >= 1 && g_strncasecmp(cmd[2], "set", len) == 0) {
		cmd_set_real(irc, cmd + 2, &a->set, cmd_account_set_checkflags);
	} else {
		irc_rootmsg(irc,
		            "Unknown command: %s [...] %s. Please use \x02help commands\x02 to get a list of available commands.", "account",
		            cmd[2]);
	}
}
コード例 #7
0
 Bits::operator unsigned int(){     // 2 marks{
   return bool2int();
 }                                 // }
コード例 #8
0
ファイル: account.c プロジェクト: vmiklos/bitlbee
char *set_eval_account( set_t *set, char *value )
{
    account_t *acc = set->data;

    /* Double-check: We refuse to edit on-line accounts. */
    if( set->flags & ACC_SET_OFFLINE_ONLY && acc->ic )
        return SET_INVALID;

    if( strcmp( set->key, "server" ) == 0 )
    {
        g_free( acc->server );
        if( value && *value )
        {
            acc->server = g_strdup( value );
            return value;
        }
        else
        {
            acc->server = g_strdup( set->def );
            return g_strdup( set->def );
        }
    }
    else if( strcmp( set->key, "username" ) == 0 )
    {
        g_free( acc->user );
        acc->user = g_strdup( value );
        return value;
    }
    else if( strcmp( set->key, "password" ) == 0 )
    {
        /* set -del should be allowed now, but I don't want to have any
           NULL pointers to have to deal with. */
        if( !value )
            value = "";

        g_free( acc->pass );
        acc->pass = g_strdup( value );
        return NULL;	/* password shouldn't be visible in plaintext! */
    }
    else if( strcmp( set->key, "tag" ) == 0 )
    {
        account_t *oa;

        /* Enforce uniqueness. */
        if( ( oa = account_by_tag( acc->bee, value ) ) && oa != acc )
            return SET_INVALID;

        g_free( acc->tag );
        acc->tag = g_strdup( value );
        return value;
    }
    else if( strcmp( set->key, "auto_connect" ) == 0 )
    {
        if( !is_bool( value ) )
            return SET_INVALID;

        acc->auto_connect = bool2int( value );
        return value;
    }
    else if( strcmp( set->key, "away" ) == 0 ||
             strcmp( set->key, "status" ) == 0 )
    {
        if( acc->ic && acc->ic->flags & OPT_LOGGED_IN )
        {
            /* If we're currently on-line, set the var now already
               (bit of a hack) and send an update. */
            g_free( set->value );
            set->value = g_strdup( value );

            imc_away_send_update( acc->ic );
        }

        return value;
    }

    return SET_INVALID;
}
コード例 #9
0
ファイル: account.c プロジェクト: andrewalker/bitlbee
char *set_eval_account(set_t *set, char *value)
{
	account_t *acc = set->data;

	/* Double-check: We refuse to edit on-line accounts. */
	if (set->flags & ACC_SET_OFFLINE_ONLY && acc->ic) {
		return SET_INVALID;
	}

	if (strcmp(set->key, "server") == 0) {
		g_free(acc->server);
		if (value && *value) {
			acc->server = g_strdup(value);
			return value;
		} else {
			acc->server = g_strdup(set->def);
			return g_strdup(set->def);
		}
	} else if (strcmp(set->key, "username") == 0) {
		g_free(acc->user);
		acc->user = g_strdup(value);
		return value;
	} else if (strcmp(set->key, "password") == 0) {
		/* set -del allows /oper to be used to change the password or,
		   iff oauth is enabled, reset the oauth credential magic.
		*/
		if (!value) {
			if (set_getbool(&(acc->set), "oauth")) {
				value = "";
			} else {
				value = PASSWORD_PENDING;
				((irc_t *) acc->bee->ui_data)->status |= OPER_HACK_ACCOUNT_PASSWORD;
				irc_rootmsg((irc_t *) acc->bee->ui_data, "You may now use /OPER to set the password");
			}
		}

		g_free(acc->pass);
		acc->pass = g_strdup(value);
		return NULL;    /* password shouldn't be visible in plaintext! */
	} else if (strcmp(set->key, "tag") == 0) {
		account_t *oa;

		/* Enforce uniqueness. */
		if ((oa = account_by_tag(acc->bee, value)) && oa != acc) {
			return SET_INVALID;
		}

		g_free(acc->tag);
		acc->tag = g_strdup(value);
		return value;
	} else if (strcmp(set->key, "auto_connect") == 0) {
		if (!is_bool(value)) {
			return SET_INVALID;
		}

		acc->auto_connect = bool2int(value);
		return value;
	} else if (strcmp(set->key, "away") == 0 ||
	           strcmp(set->key, "status") == 0) {
		if (acc->ic && acc->ic->flags & OPT_LOGGED_IN) {
			/* If we're currently on-line, set the var now already
			   (bit of a hack) and send an update. */
			g_free(set->value);
			set->value = g_strdup(value);

			imc_away_send_update(acc->ic);
		}

		return value;
	}

	return SET_INVALID;
}
コード例 #10
0
ファイル: wreg_shift.c プロジェクト: geoffchu/chuffed
  ShiftSched(int _staff, int _shifts, int _acts, vec< vec<int> >& _demand, int mode)
      : staff(_staff), shifts(_shifts), acts(_acts), dom(acts+maxG), demand(_demand)
  {
    for(int ww = 0; ww < staff; ww++)
    {
      xv.push();
      for( int ss = 0; ss < shifts; ss++ )
      {
          xv[ww].push(newIntVar(0,dom-1));
          xv[ww][ss]->specialiseToEL();
      }
    }
    
    // Build the grammar 
    int first = 0;
    while(first < shifts)
    {
      for(int ii = 0; ii < acts; ii++)
      {
        if(demand[first][ii])
          goto found_first;
      }
      first++;
    }
found_first:

    int last = first;
    for(int ss = first; ss < shifts; ss++)
    {
      for(int ii = 0; ii < acts; ii++)
      {
        if(demand[ss][ii])
        {
          last = ss;
          break;
        }
      }
    }
    CFG::CFG g( buildSchedG(acts, first, last) ); 
    
    // Construct variables for the circuit
    MDDTable mdd_tab(shifts);
    std::vector< std::vector<MDD> > seq;
    for(int ii = 0; ii < shifts; ii++)
    {
      seq.push_back( std::vector<MDD>() );
      for(int kk = 0; kk < dom; kk++)
      {
        seq[ii].push_back(mdd_tab.vareq(ii, kk));
      }
    }
    MDD gcirc(parseCYK(mdd_tab.fff(), seq, g));
    
    // Convert the MDD into an edge-valued graph.
    vec<int> slot_cost;
    for(int si = 0; si < acts; si++)
      slot_cost.push(1);
    for(int si = acts; si < dom; si++)
      slot_cost.push(0);

    EVLayerGraph graph;
    EVLayerGraph::NodeID gcirc_evgraph(mdd_to_layergraph(graph, gcirc, slot_cost));
    
    // Enforce the schedule for each worker.
    MDDOpts mopts;
    mopts.expl_strat = MDDOpts::E_KEEP;
    mopts.expl_alg = MDDOpts::E_MINIMAL;
    for(int ww = 0; ww < staff; ww++)
    {
      staff_cost.push(newIntVar(0, shifts));
      evgraph_to_wmdd(xv[ww], staff_cost[ww], graph, gcirc_evgraph, mopts);
    }

    for(int ww = 1; ww < staff; ww++)
      lex(xv[ww-1],xv[ww],false);

    // Enforce coverage constraints.
    for(int ss = 0; ss < shifts; ss++)
    {
      for(int act = 0; act < acts; act++)
      {
        vec<BoolView> bv;
        for(int ww = 0; ww < staff; ww++)
        {
          bv.push(xv[ww][ss]->getLit(act,1));
        }
        
          bool_linear_decomp(bv, IRT_GE, demand[ss][act]);
//          IntVar* d_const = newIntVar(demand[ss][act], demand[ss][act]);
//          bool_linear(bv, IRT_GE, d_const);
      }
    }
  
    unsigned int cMin(0); 
    for(int ss = 0; ss < shifts; ss++)
    {
      for(int aa = 0; aa < acts; aa++)
      {
        cMin += demand[ss][aa];
      }
    }

    cost = newIntVar(cMin, (last - first + 1)*staff);
    int_linear(staff_cost, IRT_LE, cost);

#if 0
    vec<IntVar*> rostered_int;
    for(int ss = 0; ss < shifts; ss++)
    {
      if(ss < first || ss > last)
        continue;

      for(int ww = 0; ww < staff; ww++)
      {
        IntVar* sv = newIntVar(0,1);
        bool2int(xv[ww][ss]->getLit(acts-1,3),sv);
        rostered_int.push(sv);
      }
    }
    int_linear(rostered_int, IRT_GE, cost);
#endif

    vec<IntVar*> vs;
    for(int ss = 0; ss < shifts; ss++)
    {
      for(int ww = 0; ww < staff; ww++)
      {
        vs.push(xv[ww][ss]);
      }
    }

    branch(vs, VAR_INORDER, VAL_MAX);
		optimize(cost, OPT_MIN);
    
//    vs.push(cost);
    output_vars(vs);
  }