Ejemplo n.º 1
0
Archivo: user.c Proyecto: 6wei/jabberd2
/** initialise a user */
int user_create(sm_t sm, jid_t jid) {
    user_t user;

    log_debug(ZONE, "create user request for %s", jid_user(jid));

    /* check whether it is to serviced domain */
    if(xhash_get(sm->hosts, jid->domain) == NULL) {
        log_write(sm->log, LOG_ERR, "request to create user for non-serviced domain: jid=%s", jid_user(jid));
        log_debug(ZONE, "no such domain, not creating");
        return 1;
    }

    user = user_load(sm, jid);
    if(user != NULL) {
        log_write(sm->log, LOG_ERR, "request to create already-active user: jid=%s", jid_user(jid));
        log_debug(ZONE, "user already active, not creating");
        return 1;
    }

    /* modules create */
    if(mm_user_create(sm->mm, jid) != 0) {
        log_write(sm->log, LOG_ERR, "user creation failed: jid=%s", jid_user(jid));
        log_debug(ZONE, "user create failed, forcing deletion for cleanup");
        mm_user_delete(sm->mm, jid);
        return 1;
    }

    log_write(sm->log, LOG_NOTICE, "created user: jid=%s", jid_user(jid));

    return 0;
}
Ejemplo n.º 2
0
Archivo: user.c Proyecto: 6wei/jabberd2
/** trash a user */
void user_delete(sm_t sm, jid_t jid) {
    user_t user;
    sess_t scan, next;

    log_debug(ZONE, "delete user request for %s", jid_user(jid));

    user = user_load(sm, jid);
    if(user == NULL) {
        log_debug(ZONE, "user doesn't exist, can't delete");
        return;
    }

    /* close their sessions first (this will free user, after the last session ends) */
    scan = user->sessions;
    while(scan != NULL) {
        next = scan->next;
        sm_c2s_action(scan, "ended", NULL);
        sess_end(scan);
        scan = next;
    }

    mm_user_delete(sm->mm, jid);

    log_write(sm->log, LOG_NOTICE, "deleted user: jid=%s", jid_user(jid));
}
Ejemplo n.º 3
0
/*
 * Devuelve el usuario de la sesion
 * */
User*     session_user( Session* s ){
    if( s->user ) return s->user;
    if( s->user_id ){
        s->user = user_load( s->user_id );
        s->flags |= SESSION_FLAGUSERID;
        return s->user;
    }
    return NULL;
}
Ejemplo n.º 4
0
User *user_get_by_jid(const char *jid){
User *u;
char *njid;

	njid=jid_normalized(jid,0);
	if (njid==NULL) return NULL;
	u=(User *)g_hash_table_lookup(users_jid,(gpointer)njid);
	g_free(njid);
	if (u==NULL) u=user_load(jid);
	return u;
}
Ejemplo n.º 5
0
Archivo: conf.c Proyecto: baruch/nut
/* called after SIGHUP */
void conf_reload(void)
{
    upstype_t	*upstmp, *upsnext;

    upslogx(LOG_INFO, "SIGHUP: reloading configuration");

    /* see if we can access upsd.conf before blowing away the config */
    if (!check_file("upsd.conf"))
        return;

    /* reset retain flags on all known UPS entries */
    upstmp = firstups;
    while (upstmp) {
        upstmp->retain = 0;
        upstmp = upstmp->next;
    }

    /* reload from ups.conf */
    read_upsconf();
    upsconf_add(1);			/* 1 = reloading */

    /* now reread upsd.conf */
    load_upsdconf(1);		/* 1 = reloading */

    /* now delete all UPS entries that didn't get reloaded */

    upstmp = firstups;

    while (upstmp) {
        /* upstmp may be deleted during this pass */
        upsnext = upstmp->next;

        if (upstmp->retain == 0)
            delete_ups(upstmp);

        upstmp = upsnext;
    }

    /* did they actually delete the last UPS? */
    if (firstups == NULL)
        upslogx(LOG_WARNING, "Warning: no UPSes currently defined!");

    /* and also make sure upsd.users can be read... */
    if (!check_file("upsd.users"))
        return;

    /* delete all users */
    user_flush();

    /* and finally reread from upsd.users */
    user_load();
}
Ejemplo n.º 6
0
void draw_style()
{
	
	switch(cur_tool)
	{
		case 1:
			user_new();
			break;
		case 2:user_save();
				break;
		case 3:user_load();
			break;
			
		case 10:
		case 17:
			cur_panel=1;
			top_panel_background();
			top_panel_buttons(buttons_data[cur_tool-1],0,1);
			style_icon();
			break;
	}
}
Ejemplo n.º 7
0
/** main packet dispatcher */
void dispatch(sm_t sm, pkt_t pkt) {
    user_t user;
    mod_ret_t ret;

    /* handle broadcasts */
    if(pkt->rtype == route_BROADCAST) {
        log_debug(ZONE, "can't handle broadcast routes (yet), dropping");
        pkt_free(pkt);
        return;
    }

    /* routing errors, add a im error */
    if(pkt->rtype & route_ERROR) {
        int i, aerror, stanza_err;
        aerror = nad_find_attr(pkt->nad, 0, -1, "error", NULL);
        stanza_err = stanza_err_REMOTE_SERVER_NOT_FOUND;
        if(aerror >= 0) {
            for(i=0; _stanza_errors[i].code != NULL; i++)
                if(strncmp(_stanza_errors[i].code, NAD_AVAL(pkt->nad, aerror), NAD_AVAL_L(pkt->nad, aerror)) == 0) {
                    stanza_err = stanza_err_BAD_REQUEST + i;
                    break;
                }
        }
        if(pkt_error(pkt, stanza_err) == NULL)
            return;
    }

    /*
     * - if its from the router (non-route) it goes straight to pkt_router
     * - hand it to in_router chain
     * - if its for the sm itself (no user), hand it to the pkt_sm chain
     * - find the user
     * - hand to pkt_user
     */

    /* non route packets are special-purpose things from the router */
    if(!(pkt->rtype & route_UNICAST)) {
        ret = mm_pkt_router(pkt->sm->mm, pkt);
        switch(ret) {
            case mod_HANDLED:
                break;

            case mod_PASS:
            default:
                /* don't ever bounce these */
                pkt_free(pkt);

                break;
        }

        return;
    }

    /* preprocessing */
    if (pkt != NULL && pkt->sm != NULL) {
        ret = mm_in_router(pkt->sm->mm, pkt);
        switch(ret) {
            case mod_HANDLED:
                return;
 
            case mod_PASS:
                break;

            default:
                pkt_router(pkt_error(pkt, -ret));
                return;
        }
    }

    /* has to come from someone and be directed to someone */
    if(pkt->from == NULL || pkt->to == NULL) {
        pkt_router(pkt_error(pkt, stanza_err_BAD_REQUEST));
        return;
    }

    /* packet is for the sm itself */
    if(*pkt->to->node == '\0') {
        ret = mm_pkt_sm(pkt->sm->mm, pkt);
        switch(ret) {
            case mod_HANDLED:
                break;

            case mod_PASS:
                /* ignore IQ result packets that haven't been handled - XMPP 9.2.3.4 */
                if(pkt->type == pkt_IQ_RESULT) {
                    pkt_free(pkt);
                    break;
                } else
                    ret = -stanza_err_FEATURE_NOT_IMPLEMENTED;

            default:
                pkt_router(pkt_error(pkt, -ret));

                break;
        }

        return;
    }

    /* get the user */
    user = user_load(sm, pkt->to);
    if(user == NULL) {
        if(pkt->type & pkt_PRESENCE && pkt->type != pkt_PRESENCE_PROBE) {
            pkt_free(pkt);
            return;
        }

        if(pkt->type == pkt_PRESENCE_PROBE) {
            pkt_router(pkt_create(pkt->sm, "presence", "unsubscribed", jid_full(pkt->from), jid_full(pkt->to)));
            pkt_free(pkt);
            return;
        }

        pkt_router(pkt_error(pkt, stanza_err_SERVICE_UNAVAILABLE));
        return;
    }

    if (pkt->sm != NULL) {
        ret = mm_pkt_user(pkt->sm->mm, user, pkt);
        switch(ret) {
            case mod_HANDLED:
                break;
    
            case mod_PASS:
                /* ignore IQ result packets that haven't been handled - XMPP 9.2.3.4 */
                if(pkt->type == pkt_IQ_RESULT) {
                    pkt_free(pkt);
                    break;
                } else
                    ret = -stanza_err_FEATURE_NOT_IMPLEMENTED;

            default:
                pkt_router(pkt_error(pkt, -ret));

                break;
        }
    }

    /* if they have no sessions, they were only loaded to do delivery, so free them */
    if(user->sessions == NULL)
        user_free(user);
}
Ejemplo n.º 8
0
user_parameters *uplink_parameters(parameter_model *pmodel) {
  int nmbUsers = 0;
  int nmbRB = MAX_RB;
  int startPos = 0;
  float distribution = 0;
  float p;
  int newRB;
  userS *users = NULL;
  user_parameters *parameters = (user_parameters *)malloc(sizeof(user_parameters));
  int load = 0;

  while (nmbUsers < MAX_USERS && (rand()/(float)RAND_MAX) < PROB_NEW_USER && nmbRB > 0) {
    /* New user so we need to allocate memory to store its information */
    if (users == NULL) {
      users = (userS *)malloc(sizeof(userS));
      users->next = NULL;
      parameters->first = users;
    } else {
      users->next = (userS *)malloc(sizeof(userS));
      users = users->next;
      users->next = NULL;
    }
    parameters->last = users;

    /* Lets determine the number of layers (max 4) */
    users->nmbLayer = 1;
    if ( PROB_EXTRA_LAYER > (rand()/(float)RAND_MAX) ) users->nmbLayer++;
    if ( PROB_EXTRA_LAYER > (rand()/(float)RAND_MAX) ) users->nmbLayer++;
    if ( PROB_EXTRA_LAYER > (rand()/(float)RAND_MAX) ) users->nmbLayer++;

    users->startRB = startPos;
    
    newRB = (int)(MAX_RB*(rand()/(float)RAND_MAX));

    distribution = rand()/(float)RAND_MAX;

    /* Create a nonlinear distribution of the RBs between users */
    if (distribution < 0.4)
      newRB = newRB/8;
    else if (distribution < 0.6)
      newRB = newRB/4;
    else if (distribution < 0.9)
      newRB = newRB/2;

    /* A user has at leas one RB */
    if (!newRB)
      newRB = 1;

    if ( newRB > nmbRB ) {
      newRB = nmbRB;
    }
    users->nmbRB = newRB;
    
    nmbRB = nmbRB - users->nmbRB;
    startPos = startPos + users->nmbRB;
    
    users->mod = MOD_QPSK;
    p = (rand()/(float)RAND_MAX);
    if (p > 0.3 ) users->mod = MOD_16QAM;
    if (p > 0.7 ) users->mod = MOD_64QAM;
    
    users->data = &data[subframe_data()];

    nmbUsers++;
    load += user_load(users->nmbRB, users->nmbLayer, users->mod);
  }

  //printf("Load: %3i, Users: %2i\n", load, nmbUsers);

  if (nmbUsers)
    return parameters;
  
  free(parameters);
  return NULL;
}
Ejemplo n.º 9
0
user_parameters *uplink_parameters(parameter_model *pmodel) {
  int active = 0;
  int nmbUsers = 0;
  int nmbRB = MAX_RB;
  int startPos = 0;
  float distribution = 0;
  int newRB;
  userS *users = NULL;
  user_parameters *parameters = NULL;
  int load_QPSK = 0;
  int load_16QAM = 0;
  int load_64QAM = 0;
  float load_perc = 0.0;
  int minLayer = 4;
  int maxLayer = 1;
  int minMod = MOD_64QAM;
  int maxMod = MOD_QPSK;
  int maxRB = 0;
  int minRB = 100;

  if (new_second()) {
    pmodel->countdown--;
    pmodel->active_min = 100;
    pmodel->active_max = 0;
    pmodel->active_sum = 0;
    pmodel->active_frames = 0;
    if (pmodel->countdown <= 0) {
      if (pmodel->inc)
	pmodel->count++;
      else
	pmodel->count--;
      pmodel->countdown = COUNTDOWN - 1;
    }
    if (pmodel->count == 170)
      pmodel-> inc = 0;
    else if (pmodel->count == 0)
      exit(0);
  }

  while (nmbUsers < MAX_USERS && nmbRB > 0) {
    /* New user so we need to allocate memory to store its information */
    if (users == NULL) {
      users = (userS *)malloc(sizeof(userS));
      users->next = NULL;
      parameters = (user_parameters *)malloc(sizeof(user_parameters));
      parameters->first = users;
    } else {
      users->next = (userS *)malloc(sizeof(userS));
      users = users->next;
      users->next = NULL;
    }
    parameters->last = users;

    /* Lets determine the number of layers (max 4) */
    users->nmbLayer = 1;
    if (PROB_EXTRA_LAYER*pmodel->count/80 > (rand()/(float)RAND_MAX)) users->nmbLayer++;
    if (PROB_EXTRA_LAYER*pmodel->count/80 > (rand()/(float)RAND_MAX)) users->nmbLayer++;
    if (PROB_EXTRA_LAYER*pmodel->count/80 > (rand()/(float)RAND_MAX)) users->nmbLayer++;

    users->startRB = startPos;

    newRB = 10;
    /*
    newRB = (int)(MAX_RB*(rand()/(float)RAND_MAX));

    distribution = rand()/(float)RAND_MAX;
    */
    /* Create a nonlinear distribution of the RBs between users */
    /*
    if (distribution < 0.4)
      newRB = newRB/8;
    else if (distribution < 0.6)
      newRB = newRB/4;
    else if (distribution < 0.9)
      newRB = newRB/2;
    */
    /* A user has at leas one RB */
    if (!newRB)
      newRB = 1;

    if ( newRB > nmbRB ) {
      newRB = nmbRB;
    }
    users->nmbRB = newRB;
    
    nmbRB = nmbRB - users->nmbRB;
    startPos = startPos + users->nmbRB;
    /*
    users->mod = MOD_QPSK;
    if (PROB_MOD*pmodel->count/80 > (rand()/(float)RAND_MAX)) {
      users->mod = MOD_16QAM;
      if (PROB_MOD*pmodel->count/80 > (rand()/(float)RAND_MAX)) {
	users->mod = MOD_64QAM;
      }
    }
    */
    users->mod = MOD_64QAM;
    //users->mod = MOD_QPSK;
    users->data = &data[subframe_data()];

    nmbUsers++;
    switch(users->mod) {
    case MOD_PSK:
    case MOD_QPSK:
      load_QPSK += users->nmbRB * users->nmbLayer;
      break;
    case MOD_16QAM:
      load_16QAM += users->nmbRB * users->nmbLayer;
      break;
    case MOD_64QAM:
      load_64QAM += users->nmbRB * users->nmbLayer;
      break;
    }
    
    if (minRB > users->nmbRB)
      minRB = users->nmbRB;
    if (maxRB < users->nmbRB)
      maxRB = users->nmbRB;
    if (minLayer > users->nmbLayer)
      minLayer = users->nmbLayer;
    if (maxLayer < users->nmbLayer)
      maxLayer = users->nmbLayer;
    if (minMod > users->mod)
      minMod = users->mod;
    if (maxMod < users->mod)
      maxMod = users->mod;

    load_perc += user_load(users->nmbRB, users->nmbLayer, users->mod);
  }

  active = ceil(TASK_THREADS*(load_perc/100))+2;
  pmodel->active = active;

  //  printf("QPSK: %3i, 16QAM: %3i, 64QAM: %3i, Users: %2i, Active: %2i, Count: %2i, Load: %3.1f\n", load_QPSK, load_16QAM, load_64QAM, nmbUsers, pmodel->active, pmodel->count, load_perc);

  return parameters;
}
Ejemplo n.º 10
0
Archivo: sess.c Proyecto: 6wei/jabberd2
sess_t sess_start(sm_t sm, jid_t jid) {
    pool_t p;
    user_t user;
    sess_t sess, scan;
    sha1_state_t sha1;
    unsigned char hash[20];
    int replaced = 0;

    log_debug(ZONE, "session requested for %s", jid_full(jid));

    /* check whether it is to serviced domain */
    if(xhash_get(sm->hosts, jid->domain) == NULL) {
        log_write(sm->log, LOG_ERR, "request to start session in non-serviced domain: jid=%s", jid_full(jid));
        return NULL;
    }

    /* get user data for this guy */
    user = user_load(sm, jid);

    /* unknown user */
    if(user == NULL) {
        if(config_get(sm->config, "user.auto-create") == NULL) {
            log_write(sm->log, LOG_NOTICE, "user not found and user.auto-create not enabled, can't start session: jid=%s", jid_full(jid));
            return NULL;
        }

        log_debug(ZONE, "auto-creating user %s", jid_user(jid));

        if(user_create(sm, jid) != 0)
            return NULL;

        user = user_load(sm, jid);
        if(user == NULL) {
            log_write(sm->log, LOG_NOTICE, "couldn't load user, can't start session: jid=%s", jid_full(jid));
            return NULL;
        }
    }

    /* kill their old session if they have one */
    for(scan = user->sessions; scan != NULL; scan = scan->next)
        if(jid_compare_full(scan->jid, jid) == 0) {
            log_debug(ZONE, "replacing session %s (%s)", jid_full(jid), scan->c2s_id);

            /* !!! this "replaced" stuff is a hack - its really a subaction of "ended".
             *     hurrah, another control protocol rewrite is needed :(
             */
            sm_c2s_action(scan, "replaced", NULL);

            _sess_end_guts(scan);

            pool_free(scan->p);

            replaced = 1;

            break;
        }

    /* make a new session */
    p = pool_new();

    sess = (sess_t) pmalloco(p, sizeof(struct sess_st));
    sess->p = p;

    /* fill it out */
    sess->pri = 0;
    sess->user = user;

    sess->jid = jid_dup(jid);
    pool_cleanup(sess->p, (void (*))(void *) jid_free, sess->jid);

    /* a place for modules to store stuff */
    sess->module_data = (void **) pmalloco(sess->p, sizeof(void *) * sess->user->sm->mm->nindex);

    /* add it to the list */
    sess->next = user->sessions;
    user->sessions = sess;

    /* who c2s should address things to */
    sha1_init(&sha1);
    datetime_out(time(NULL), dt_DATETIME, sess->sm_id, 41);
    sha1_append(&sha1, sess->sm_id, strlen(sess->sm_id));
    sha1_append(&sha1, jid_full(sess->jid), strlen(jid_full(sess->jid)));
    sha1_finish(&sha1, hash);
    hex_from_raw(hash, 20, sess->sm_id);

    log_debug(ZONE, "smid is %s", sess->sm_id);

    /* remember it */
    xhash_put(sm->sessions, sess->sm_id, sess);

    /* inform the modules */
    /* !!! catch the return value - if its 1, don't let them in */
    mm_sess_start(sm->mm, sess);

    if(replaced)
        log_write(sm->log, LOG_NOTICE, "session replaced: jid=%s", jid_full(sess->jid));
    else
        log_write(sm->log, LOG_NOTICE, "session started: jid=%s", jid_full(sess->jid));
            
    return sess;
}