예제 #1
0
파일: xmlns_si.c 프로젝트: biddyweb/xwbot
static void ___send_test_cmd(struct x_bus *sess, ezxml_t _from)
  {
    ezxml_t _s = NULL;
    ezxml_t __stnz = NULL;
    ezxml_t _stnz1 = NULL;
    ezxml_t _stnz2 = NULL;

    ENTER;

    __stnz = xmpp_stanza_get_root(_from);
    if (!__stnz)
    return;

    _stnz1 = ezxml_new("message");
    _s = _stnz1;
    ezxml_set_attr_d(_s,"to",ezxml_attr(__stnz,"from"));
    ezxml_set_attr(_s, "from", sess->jid);
    //	ezxml_set_attr(_stnz1,"xmlns","http://jabber.org/protocol/feature-neg");

    // add xforms
    _stnz2 = ezxml_add_child(_stnz1, "x",0);
    ezxml_set_attr(_stnz2,"xmlns","jabber:x:data");
    ezxml_set_attr(_stnz2,"type","form");

    _stnz2 = ezxml_add_child(_stnz2, "field",0);
    ezxml_set_attr(_stnz2,"var","fname");
    ezxml_set_attr(_stnz2,"type","text-single");
    ezxml_set_attr(_stnz2,"label","Select filename");

    // ezxml_insert(_stnz1, _s, 0);
    xmpp_session_send_stanza(sess, _s);
    ezxml_free(_s);

    EXIT;

    return;
  }
예제 #2
0
파일: cgi_user.c 프로젝트: LinLL/ipc
int CGI_user_set_password(HTTPD_SESSION_t* http_session)
{
	int ret = 0;
	AVal av_username = AVC(""), av_password = AVC(""), av_content = AVC("");
	USRM_I_KNOW_U_t* i_m = NULL;
	bool checkin_success = false;
	bool set_success = false;
	ezxml_t output_xml = NULL;
	char* response_xml = NULL;
	
	char query_string[2048] = {""};
	
	// get current session username / password
	cgi_user_parse_query_string(http_session, query_string, &av_username, &av_password, &av_content);

	// user check in
	i_m = USRM_login(AVAL_STRDUPA(av_username), AVAL_STRDUPA(av_password));
	if(i_m){
		ezxml_t input_xml = NULL;
		checkin_success = true;

		APP_TRACE("Login success! Query string = \"%s\"", query_string);

		input_xml = ezxml_parse_str(av_content.av_val, av_content.av_len);
		if(input_xml){
			USRM_HOW_ABOUT_t how_about = USRM_GREAT;
			ezxml_t add_node = ezxml_child(input_xml, "set_pass");
			if(add_node){
				const char* attr_old_pass = ezxml_attr(add_node, "old_pass");
				const char* attr_new_pass = ezxml_attr(add_node, "new_pass");

				how_about = i_m->set_password(i_m, attr_old_pass, attr_new_pass);
				if(USRM_GREAT == how_about){
					set_success = true;
					APP_TRACE("Set user \"%s\" password success!", AVAL_STRDUPA(av_username));
					USRM_store();
				}else{
					// FIXME:
				}
			}

			ezxml_free(input_xml);
			input_xml = NULL;
		}

		// check out
		USRM_logout(i_m);
		i_m = NULL;
	}

	// make the xml content
	output_xml = ezxml_new_d("user");
	ezxml_set_attr_d(output_xml, "ver", CGI_USER_VERSION);
	ezxml_set_attr_d(output_xml, "you", AVAL_STRDUPA(av_username));
	ezxml_set_attr_d(output_xml, "ret", "success");
	if(!STR_CASE_THE_SAME(ezxml_attr(output_xml, "ret"), "success")){
		ezxml_set_attr_d(output_xml, "mesg", "");
	}
	response_xml = ezxml_toxml(output_xml);
	ezxml_free(output_xml);
	output_xml = NULL;

	// response
	cgi_user_http_response(http_session, response_xml);
	
	free(output_xml);
	output_xml = NULL;
	
	return 0;
}
예제 #3
0
파일: cgi_user.c 프로젝트: LinLL/ipc
int CGI_edit_user(HTTPD_SESSION_t* http_session)
{
	int ret = 0;
	AVal av_username = AVC(""), av_password = AVC(""), av_content = AVC("");

	USRM_I_KNOW_U_t* i_m = NULL;
	bool check_in = false;
	bool add_success = false;
	ezxml_t output_xml = NULL;
	const char* xml_text = NULL;

	char query_string[2048] = {""};

	// get current session username / password
	cgi_user_parse_query_string(http_session, query_string, &av_username, &av_password, &av_content);

	// user check in
	i_m = USRM_login(AVAL_STRDUPA(av_username), AVAL_STRDUPA(av_password));
	if(i_m){
		ezxml_t input_xml = NULL;
		ezxml_t add_node = NULL;

		APP_TRACE("Login success! Query string = \"%s\"", query_string);
		
		// check in success
		check_in = true;

		input_xml = ezxml_parse_str(av_content.av_val, av_content.av_len);
		if(input_xml){
			USRM_HOW_ABOUT_t how_about = USRM_GREAT;
			ezxml_t edit_node = ezxml_child(input_xml, "edit_user");
			if(add_node){
				const char* attr_name = ezxml_attr(edit_node, "name");
				const char* attr_admin = ezxml_attr(edit_node, "admin");
				const char* attr_permit_live = ezxml_attr(edit_node, "permit_live");
				const char* attr_permit_setting = ezxml_attr(edit_node, "permit_setting");
				const char* attr_permit_playback = ezxml_attr(edit_node, "permit_playback");

				bool const is_admin = attr_admin ? (STR_CASE_THE_SAME(attr_admin, "yes")) : false;
				uint32_t permit_flag = 0; // clear flag

				if(attr_permit_live ? (STR_CASE_THE_SAME(attr_permit_live, "permit_live")) : false){
					permit_flag |= USRM_PERMIT_LIVE;
				}
				if(attr_permit_setting ? (STR_CASE_THE_SAME(attr_permit_setting, "permit_setting")) : false){
					permit_flag |= USRM_PERMIT_SETTING;
				}
				if(attr_permit_playback ? (STR_CASE_THE_SAME(attr_permit_playback, "permit_playback")) : false){
					permit_flag |= USRM_PERMIT_PLAYBACK;
				}

				how_about = i_m->edit_user(i_m, attr_name, is_admin, permit_flag);
				if(USRM_GREAT == how_about){
					add_success = true;
					APP_TRACE("Edit user \"%s\" success!", attr_name);
					USRM_store();
				}else{
					// FIXME:

					
				}
			}

			ezxml_free(input_xml);
			input_xml = NULL;
		}

		// check out
		USRM_logout(i_m);
		i_m = NULL;
	}

	// make the xml content
	output_xml = ezxml_new_d("user");
	ezxml_set_attr_d(output_xml, "ver", CGI_USER_VERSION);
	ezxml_set_attr_d(output_xml, "you", AVAL_STRDUPA(av_username));
	ezxml_set_attr_d(output_xml, "ret", "success");
	if(!STR_CASE_THE_SAME(ezxml_attr(output_xml, "ret"), "success")){
		ezxml_set_attr_d(output_xml, "mesg", "");
	}
	xml_text = ezxml_toxml(output_xml);
	ezxml_free(output_xml);
	output_xml = NULL;

	// response
	cgi_user_http_response(http_session, xml_text);
	
	free(output_xml);
	output_xml = NULL;
	
	return 0;
}
예제 #4
0
파일: cgi_user.c 프로젝트: LinLL/ipc
static int user_list_xml(USRM_I_KNOW_U_t* i_m, ezxml_t xml_root, lpINI_PARSER ini_list)
{
	int i = 0;
	int ret = 0;
	ezxml_t list_node = NULL;
	ezxml_t user_node = NULL;
	char str_val[32] = {""};
	
	int const user_count = ini_list->read_int(ini_list, "OPTION", "user", 0);
	APP_ASSERT(user_count > 0, "Why there is no user");

	// xml root node
	list_node = ezxml_add_child_d(xml_root, "user_list", 0); // user list node
	// attribute count
	sprintf(str_val, "%d", user_count);
	ezxml_set_attr_d(list_node, "count", str_val);
	// attribute backlog
	sprintf(str_val, "%d", USR_MANGER_USER_HOURSE_BACKLOG);
	ezxml_set_attr_d(list_node, "backlog", str_val);

	for(i = 0; NULL != i_m && i < user_count && i < USR_MANGER_USER_HOURSE_BACKLOG; ++i){
		char user_section[32] = {""};
		char user_node_name[32] = {""};
		char his_name[32] = {""};
		char *can_del_user, *can_edit_user, *can_set_pass;
		bool his_is_admin;
		char buf[1024] = {""};

		sprintf(user_section, "USER%d", i);
		sprintf(user_node_name, "user%d", i);
		//APP_TRACE("Reading section [%s]", user_section);
		
		user_node = ezxml_add_child_d(list_node, user_node_name, i); // add user child to list
		strncpy(his_name, ini_list->read_text(ini_list, user_section, "name", "", buf, sizeof(buf)), ARRAY_ITEM(his_name));
		his_is_admin = ini_list->read_bool(ini_list, user_section, "admin", false);
		ezxml_set_attr_d(user_node, "name", his_name);
		ezxml_set_attr_d(user_node, "admin", ini_list->read_bool(ini_list, user_section, "admin", false) ? "yes" : "no");
		ezxml_set_attr_d(user_node, "permit_live", ini_list->read_bool(ini_list, user_section, "permit_live", false) ? "yes" : "no");
		ezxml_set_attr_d(user_node, "permit_setting", ini_list->read_bool(ini_list, user_section, "permit_setting", false) ? "yes" : "no");
		ezxml_set_attr_d(user_node, "permit_playback", ini_list->read_bool(ini_list, user_section, "permit_playback", false) ? "yes" : "no");
		
		// 1. only admin and not user himself could be deleted
		can_del_user = "******";
		if(i_m->is_admin && !STR_CASE_THE_SAME(i_m->username, his_name)){
			can_del_user = "******";
		}
		// 2. only admin to edit not admin, and not user himself
		can_edit_user = "******";

		if(i_m->is_admin && !his_is_admin && !STR_CASE_THE_SAME(i_m->username, his_name)){
			can_edit_user = "******";
		}
		// 3. only user himself could set his own password
		can_set_pass = STR_CASE_THE_SAME(i_m->username, his_name) ? "yes" : "no";

		// 4. add attributes
		ezxml_set_attr_d(user_node, "del_user", can_del_user);
		ezxml_set_attr_d(user_node, "edit_user", can_edit_user);
		ezxml_set_attr_d(user_node, "set_pass", can_set_pass);

	}

	return 0;
}
예제 #5
0
파일: cgi_user.c 프로젝트: LinLL/ipc
int CGI_user_list(HTTPD_SESSION_t* http_session)
{
	int i = 0;
	int ret = 0;
	AVal av_username = AVC(""), av_password = AVC("");
	
	char query_string[2048] = {""};
	
	USRM_I_KNOW_U_t* i_m = NULL;
	ezxml_t user_xml = NULL;
	const char* xml_text = NULL;
	
	int user_backlog = 0;

	// get current session username / password
	cgi_user_parse_query_string(http_session, query_string, &av_username, &av_password, NULL);

	// xml root node
	user_xml = ezxml_new_d("user");
	ezxml_set_attr_d(user_xml, "ver", CGI_USER_VERSION);

	// user check in
	i_m = USRM_login(AVAL_STRDUPA(av_username), AVAL_STRDUPA(av_password));
	if(i_m){
		lpINI_PARSER user_ini = NULL;
		
		// attribute count
		ezxml_set_attr_d(user_xml, "you", i_m->username);
		// attribute 'add user' permit
		ezxml_set_attr_d(user_xml, "add_user", i_m->is_admin ? "yes" : "no");
		
		// open the ini file
		user_ini = OpenIniFile(USR_MANGER_TMP_FILE);
		APP_ASSERT(NULL != user_ini, "File not existed? it's impossible");

		// put the user list to xml
		user_list_xml(i_m, user_xml, user_ini);

		// close the ini file
		CloseIniFile(user_ini);
		user_ini = NULL;

		// add return
		ezxml_set_attr_d(user_xml, "ret", "success");
		ezxml_set_attr_d(user_xml, "mesg", "check in success");

		USRM_logout(i_m);
		i_m = NULL;

	}else{
		// add return
		ezxml_set_attr_d(user_xml, "ret", "sorry");
		ezxml_set_attr_d(user_xml, "mesg", "check in falied");
	
	}

	// make the xml text
	xml_text = ezxml_toxml(user_xml);
	ezxml_free(user_xml);
	user_xml = NULL;

	// response
	cgi_user_http_response(http_session, xml_text);

	// free the xml text
	free(xml_text);
	xml_text = NULL;

	return 0;
}
예제 #6
0
파일: xmlns_si.c 프로젝트: biddyweb/xwbot
/**
 * \return <si/> response to <si/> request
 */
static int
xmlns_si_file_accept(struct x_bus *sess, ezxml_t __stnz)
{
  char *str;

  int err;
  ezxml_t stream_job;

  ezxml_t _stnz1;
  ezxml_t _stnz2;
  char *fname, *siz;

  ENTER;

  _stnz1 = ezxml_child(__stnz, "file");

  if (!_stnz1)
    goto ftexception;

  fname = (char *) ezxml_attr(_stnz1, "name");
  siz = (char *) ezxml_attr(_stnz1, "size");

  // get features
  for (_stnz2 = ezxml_get(__stnz, "feature", -1); _stnz2; _stnz2
      = ezxml_next(_stnz2))
    {
      str = (char *) ezxml_attr(_stnz2, "xmlns");
      if (str && strstr(str, "feature-neg"))
        break;
    };

  if (!_stnz2)
    goto ftexception;

  // find stream-method
  for (_stnz2 = ezxml_get(_stnz2, "x", 0, "field", -1); _stnz2; _stnz2
      = ezxml_next(_stnz2))
    {
      str = (char *) ezxml_attr(_stnz2, "var");
      if (str && strstr(str, "stream-method"))
        break;
    };

  if (!_stnz2)
    goto ftexception;

  // get all stream methods
  for (_stnz2 = ezxml_child(_stnz2, "option"); _stnz2; _stnz2
      = ezxml_next(_stnz2))
    {
      _stnz1 = ezxml_child(_stnz2, "value");
      if (_stnz1)
        printf("STREAM: %s\n", _stnz1->txt);
      if (!strcmp(_stnz1->txt, XMLNS_BYTESTREAMS))
        break;
    };

  if (!_stnz2)
    goto ftexception;

  /* enter critical section */
  pthread_mutex_lock(&sess->lock);
  // create new file transfer job
  _stnz2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1);
  if (!_stnz2)
    {
      _stnz2 = ezxml_child(sess->dbcore, "bytestreams");
      _stnz2 = ezxml_add_child(_stnz2, "pending", 0);
    }
  err = !_stnz2->child;
  /* if some pending job already exists */
  if (err)
    {
      stream_job = ezxml_new("job");
      ezxml_set_attr(stream_job, "type", "file-transfer");
      ezxml_set_attr_d(stream_job, "id", ezxml_attr(__stnz,"id"));
      if (ezxml_attr(__stnz, "mime-type"))
        ezxml_set_attr_d(stream_job, "mime-type", ezxml_attr(__stnz,"mime-type"));
      ezxml_set_attr_d(stream_job, "profile", ezxml_attr(__stnz,"profile"));
      ezxml_set_attr_d(stream_job, "name", fname);
      ezxml_set_attr(stream_job, "source", "remote");
      ezxml_set_attr(stream_job, "src_fd", "0");
      ezxml_set_attr(stream_job, "dst_fd", "0");
      ezxml_set_attr(stream_job, "status", "0");

      _stnz2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1);
      ezxml_insert(stream_job, _stnz2, 0);

      /* leave critical section */
      pthread_mutex_unlock(&sess->lock);
    }
  else
    {
      /* leave critical section */
      pthread_mutex_unlock(&sess->lock);
      goto ftexception;
    }

  // create si response
  _stnz1 = ezxml_new("si");
  ezxml_set_attr(_stnz1, "xmlns", XMLNS_SI);

  _stnz2 = ezxml_add_child(_stnz1, "feature", 0);
  ezxml_set_attr(_stnz2, "xmlns", XMLNS_FEATURE_NEG);

  _stnz2 = ezxml_add_child(_stnz2, "x", 0);
  ezxml_set_attr(_stnz2, "xmlns", XMLNS_X_DATA);
  ezxml_set_attr(_stnz2, "type", "submit");

  _stnz2 = ezxml_add_child(_stnz2, "field", 0);
  ezxml_set_attr(_stnz2, "var", "stream-method");

  _stnz2 = ezxml_add_child(_stnz2, "value", 0);
  ezxml_set_txt(_stnz2, XMLNS_BYTESTREAMS);

  EXIT;

  xmpp_session_reply_iq_stanza(sess,__stnz,_stnz1);

  return 0;

  ftexception:
  // create si response
  _stnz1 = ezxml_new("error");
  ezxml_set_attr(_stnz1, "code", "400");
  ezxml_set_attr_d(_stnz1,"type","cancel");

  _stnz2 = ezxml_add_child(_stnz1, "bad-request", 0);
  ezxml_set_attr(_stnz2, "xmlns", XMLNS_XMPP_STANZAS);
  _stnz2 = ezxml_add_child(_stnz1, "no-valid-streams", 0);
  ezxml_set_attr(_stnz2, "xmlns", XMLNS_SI);

  EXIT;

  xmpp_session_reply_iq_stanza(sess,__stnz,_stnz1);

  return -1;

}
예제 #7
0
파일: xmlns_si.c 프로젝트: biddyweb/xwbot
static int
xmpp_send_file(struct x_bus *sess, const char *jid, const char *name)
{
  struct stat f_stat;
  char ts[25];
  pthread_t t;
  ezxml_t stream_job;
  ezxml_t __stnz;
  ezxml_t _s1;
  ezxml_t _s2;
  char *myjid = NULL;

  if (stat(name, &f_stat))
    return -1;

  pthread_mutex_lock(&sess->lock);
  myjid = x_strdup(ezxml_attr(sess->dbcore, "jid"));
  pthread_mutex_unlock(&sess->lock);

  __stnz = ezxml_new("iq");
  ezxml_set_attr(__stnz, "type", "set");
  ezxml_set_attr_d(__stnz,"to",jid);
  ezxml_set_attr(__stnz, "from", myjid);
  // TODO Randomize ID
  ezxml_set_attr(__stnz, "id", "some-id");

  _s1 = ezxml_add_child(__stnz, "si", 0);
  ezxml_set_attr(_s1, "xmlns", XMLNS_SI);
  sprintf(ts, "s5b_%x", (int) (random() + time(NULL)));
  ezxml_set_attr_d(_s1,"id",ts);
  ezxml_set_attr(_s1, "profile", XMLNS_FILE_TRANSFER);

  _s2 = ezxml_add_child(_s1, "file", 0);
  ezxml_set_attr(_s2, "xmlns", XMLNS_FILE_TRANSFER);
  ezxml_set_attr_d(_s2,"name",name);
  sprintf(ts, "%d", (int) f_stat.st_size);
  ezxml_set_attr_d(_s2,"size",ts);

  _s2 = ezxml_add_child(_s1, "feature", 0);
  ezxml_set_attr(_s2, "xmlns", XMLNS_FEATURE_NEG);

  _s2 = ezxml_add_child(_s2, "x", 0);
  ezxml_set_attr(_s2, "xmlns", XMLNS_X_DATA);
  ezxml_set_attr(_s2, "type", "form");

  _s2 = ezxml_add_child(_s2, "field", 0);
  ezxml_set_attr(_s2, "var", "stream-method");
  ezxml_set_attr(_s2, "type", "list-single");

  _s2 = ezxml_add_child(_s2, "option", 0);
  _s2 = ezxml_add_child(_s2, "value", 0);
  ezxml_set_txt(_s2, XMLNS_BYTESTREAMS);

  /* enter critical section */
  pthread_mutex_lock(&sess->lock);
  // create new file transfer job
  // this job should be created and added to
  // new main event loop
  _s2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1);
  if (!_s2)
    {
      _s2 = ezxml_get(sess->dbcore, "bytestreams", -1);
      _s2 = ezxml_add_child(_s2, "pending", 0);
    }
  _s2 = ezxml_child(_s2, "job");
  /* if some pending job already exists */
  if (!_s2)
    {
      // create new stream job
      stream_job = ezxml_new("job");
      ezxml_set_attr_d(stream_job, "jid", jid);
      ezxml_set_attr_d(stream_job, "id",ezxml_attr(_s1,"id"));
      ezxml_set_attr(stream_job, "type", "file-transfer");
      ezxml_set_attr(stream_job, "source", "local");
      ezxml_set_attr_d(stream_job, "name", name);
      ezxml_set_attr(stream_job, "src_fd", "0");
      ezxml_set_attr(stream_job, "dst_fd", "0");
      ezxml_set_attr(stream_job, "status", "0");

      _s2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1);
      ezxml_insert(stream_job, _s2, 0);
      xmpp_stanza2stdout(sess->dbcore);
    }
  pthread_mutex_unlock(&sess->lock);

  // FIXME
  pthread_create(&t, NULL, sock5srv, (void *) sess);
  sprintf(ts, "%d", (int) t);
  pthread_mutex_lock(&sess->lock);
  _s2 = ezxml_get(sess->dbcore, "threads", -1);
  if (_s2)
    {
      _s2 = ezxml_add_child(_s2, "thread", 0);
      ezxml_set_attr(_s2, "name", "socks5");
      ezxml_set_attr_d(_s2,"id",ts);
    }
  pthread_mutex_unlock(&sess->lock);

  EXIT;

  xmpp_session_send_stanza(sess, __stnz);
  ezxml_free(__stnz);
  if (myjid)
    free(myjid);

  return 0;
}
예제 #8
0
파일: xmlns_si.c 프로젝트: biddyweb/xwbot
static void
xmlns_si_file_send(struct x_bus *sess, ezxml_t __stnz)
{
  ezxml_t _stnz;
  ezxml_t _s, _s1;
  int status;
  int has_proxy = 0;
  char *proxy = NULL;
  char *myjid = NULL;
  char *myip = NULL;

  ENTER;

  pthread_mutex_lock(&sess->lock);
  myjid = x_strdup(ezxml_attr(sess->dbcore, "jid"));
  _s = ezxml_get(sess->dbcore, "interfaces", 0, "iface", -1);
  myip = x_strdup(ezxml_attr(_s, "addr"));
  pthread_mutex_unlock(&sess->lock);

  _s = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1);
  if (_s)
    _s = ezxml_child(_s, "job");

  _stnz = ezxml_get(sess->dbcore, "ftproxy", -1);
  proxy = (char *) ezxml_attr(_stnz, "jid");
  if (proxy)
    has_proxy++;

  sscanf(ezxml_attr(_s, "status"), "%d", &status);

  if (status < 2 && has_proxy)
    {
      // _s = xmpp_stanza_get_root(_from);
      // first send request to proxy
      _stnz = ezxml_new("iq");
      ezxml_set_attr(_stnz, "id", "6756756");
      ezxml_set_attr(_stnz, "type", "get");
      ezxml_set_attr(_stnz, "from", myjid);
      ezxml_set_attr_d(_stnz,"to",proxy);

      _s1 = ezxml_add_child(_stnz, "query", 0);
      ezxml_set_attr(_s1, "xmlns", XMLNS_BYTESTREAMS);

    }
  else if (myip)
    {
      _stnz = ezxml_new("iq");
      ezxml_set_attr(_stnz, "id", "6756756");
      ezxml_set_attr(_stnz, "type", "set");
      ezxml_set_attr(_stnz, "from", myjid);
      ezxml_set_attr_d(_stnz,"to",ezxml_attr(_s,"jid"));

      // FIXME Correct random values
      _s1 = ezxml_add_child(_stnz, "query", 0);
      ezxml_set_attr(_s1, "xmlns", XMLNS_BYTESTREAMS);
      ezxml_set_attr(_s1, "mode", "tcp");

      ezxml_set_attr_d(_s1,"sid",ezxml_attr(_s,"id"));

      // FIXME Correct ip
      _s1 = ezxml_add_child(_s1, "streamhost", 0);
      ezxml_set_attr(_s1, "jid", myjid);
      ezxml_set_attr_d(_s1,"host",myip);
      ezxml_set_attr(_s1, "port", "5277");
    }
  else
    {
      /* TODO Clean file atrsnfer job */
      // ERROR
    }

  EXIT;
  xmpp_session_send_stanza(sess, _stnz);
  ezxml_free(_stnz);
  if (myjid)
    free(myjid);
  if (myip)
    free(myip);
  return;
}
예제 #9
0
파일: xmlns_si.c 프로젝트: biddyweb/xwbot
static void *
sock5srv(void *arg)
{
  struct x_bus *sess;
  char buf[128];
  int sock;
  int sockcli;
  int err;
  int dst_fd;
  int port = 5277;
  ezxml_t _s;

  struct sockaddr_in srv;
  struct sockaddr_in cli;

  sess = (struct x_bus *) arg;

  _s = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1);
  if (_s)
    _s = ezxml_child(_s, "job");

  ENTER;
  printf("Serving on %d\n", port);

  sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

  memset(&srv, 0, sizeof(struct sockaddr_in));
  srv.sin_family = AF_INET;
  srv.sin_addr.s_addr = htonl(INADDR_ANY);
  srv.sin_port = htons(port);

  if (bind(sock, (struct sockaddr *) &srv, sizeof(struct sockaddr_in)) < 0)
    {
      perror("bind()");
      close(sock);
      return NULL;
    }

  if (listen(sock, 1) < 0)
    {
      perror("listen()");
      close(sock);
      return NULL;
    }

  printf("Accepting on %d\n", port);

  if ((sockcli = accept(sock, (struct sockaddr *) &cli, (socklen_t *) &err))
      < 0)
    {
      perror("accept()");
      close(sock);
    }

  err = recv(sockcli, buf, 128, 0);
#ifdef TRACE_DEBUG
  printf("Received %d bytes (0x%x 0x%x) from server\n", err, buf[0], buf[1]);
#endif

  buf[0] = 0x05;
  buf[1] = 0x00;

  err = send(sockcli, buf, 2, 0);
#ifdef TRACE_DEBUG
  printf("Sent %d bytes to server\n", err);
#endif

  err = recv(sockcli, buf, 128, 0);
#ifdef TRACE_DEBUG
  printf("Received %d bytes (0x%x 0x%x) from server\n", err, buf[0], buf[1]);
#endif

  buf[0] = 0x05;
  buf[1] = 0x00;

  err = send(sockcli, buf, err, 0);
#ifdef TRACE_DEBUG
  printf("Sent %d bytes to server\n", err);
#endif

  /*
   * Change jobs status and schedule
   */
  pthread_mutex_lock(&sess->lock);
  dst_fd = sockcli;
  sprintf(buf, "%d", dst_fd);
  ezxml_set_attr_d(_s,"dst_fd",buf);
  pthread_mutex_unlock(&sess->lock);

  close(sock);
  EXIT;
  return NULL;
}