Exemple #1
0
static void error_service(VSTREAM *client_stream, char *service, char **argv)
{
    DELIVER_REQUEST *request;
    int     status;

    /*
     * Sanity check. This service takes no command-line arguments.
     */
    if (argv[0])
        msg_fatal("unexpected command-line argument: %s", argv[0]);

    /*
     * This routine runs whenever a client connects to the UNIX-domain socket
     * dedicated to the error mailer. What we see below is a little protocol
     * to (1) tell the queue manager that we are ready, (2) read a request
     * from the queue manager, and (3) report the completion status of that
     * request. All connection-management stuff is handled by the common code
     * in single_server.c.
     */
    if ((request = deliver_request_read(client_stream)) != 0) {
        if (strcmp(service, MAIL_SERVICE_ERROR) == 0)
            status = deliver_message(request, "5.0.0", bounce_append);
        else if (strcmp(service, MAIL_SERVICE_RETRY) == 0)
            status = deliver_message(request, "4.0.0", defer_append);
        else
            msg_fatal("bad error service name: %s", service);
        deliver_request_done(client_stream, request, status);
    }
}
Exemple #2
0
void send_msg(void* sock, int parts, int size){
  for(int i=0; i < (parts-1); i++){
    deliver_message(sock,size,ZMQ_SNDMORE);
    sleep(operation.interval);
  }
  deliver_message(sock,size,0);

  puts(" done!");
}
Exemple #3
0
void LLFloaterIMPanel::sessionInitReplyReceived(const LLUUID& session_id)
{
	mSessionUUID = session_id;
	mVoiceChannel->updateSessionID(session_id);
	mSessionInitialized = true;

	//we assume the history editor hasn't moved at all since
	//we added the starting session message
	//so, we count how many characters to remove
	S32 chars_to_remove = mHistoryEditor->getWText().length() - mSessionStartMsgPos;
	mHistoryEditor->removeTextFromEnd(chars_to_remove);

	//and now, send the queued msg
	for (LLSD::array_iterator iter = mQueuedMsgsForInit.beginArray();
		  iter != mQueuedMsgsForInit.endArray();
		  ++iter)
	{
		deliver_message(
			iter->asString(),
			mSessionUUID,
			mOtherParticipantUUID,
			mDialog);
	}

	// auto-start the call on session initialization?
	if (mStartCallOnInitialize)
	{
		gIMMgr->startCall(mSessionUUID);
	}
}
Exemple #4
0
static void pipe_service(VSTREAM *client_stream, char *service, char **argv)
{
    DELIVER_REQUEST *request;
    int     status;

    /*
     * This routine runs whenever a client connects to the UNIX-domain socket
     * dedicated to delivery via external command. What we see below is a
     * little protocol to (1) tell the queue manager that we are ready, (2)
     * read a request from the queue manager, and (3) report the completion
     * status of that request. All connection-management stuff is handled by
     * the common code in single_server.c.
     */
    if ((request = deliver_request_read(client_stream)) != 0) {
	status = deliver_message(request, service, argv);
	deliver_request_done(client_stream, request, status);
    }
}
Exemple #5
0
static void discard_service(VSTREAM *client_stream, char *unused_service, char **argv)
{
    DELIVER_REQUEST *request;
    int     status;

    /*
     * Sanity check. This service takes no command-line arguments.
     */
    if (argv[0])
	msg_fatal("unexpected command-line argument: %s", argv[0]);

    /*
     * This routine runs whenever a client connects to the UNIX-domain socket
     * dedicated to the discard mailer. What we see below is a little
     * protocol to (1) tell the queue manager that we are ready, (2) read a
     * request from the queue manager, and (3) report the completion status
     * of that request. All connection-management stuff is handled by the
     * common code in single_server.c.
     */
    if ((request = deliver_request_read(client_stream)) != 0) {
	status = deliver_message(request);
	deliver_request_done(client_stream, request, status);
    }
}
Exemple #6
0
static int cycle(mqtt_client_t* c, mqtt_timer_t* timer)
{
    // read the socket, see what work is due
    int packet_type = read_packet(c, timer);

    int len = 0,
        rc = MQTT_SUCCESS;

    switch (packet_type)
    {
        case MQTTPACKET_CONNACK:
        case MQTTPACKET_PUBACK:
        case MQTTPACKET_SUBACK:
            break;
        case MQTTPACKET_PUBLISH:
        {
            mqtt_string_t topicName;
            mqtt_message_t msg;
            if (mqtt_deserialize_publish((unsigned char*)&msg.dup, (int*)&msg.qos, (unsigned char*)&msg.retained, (unsigned short*)&msg.id, &topicName,
               (unsigned char**)&msg.payload, (int*)&msg.payloadlen, c->readbuf, c->readbuf_size) != 1)
                goto exit;
            deliver_message(c, &topicName, &msg);
            if (msg.qos != MQTT_QOS0)
            {
                if (msg.qos == MQTT_QOS1)
                    len = mqtt_serialize_ack(c->buf, c->buf_size, MQTTPACKET_PUBACK, 0, msg.id);
                else if (msg.qos == MQTT_QOS2)
                    len = mqtt_serialize_ack(c->buf, c->buf_size, MQTTPACKET_PUBREC, 0, msg.id);
                if (len <= 0)
                    rc = MQTT_FAILURE;
                else
                    rc = send_packet(c, len, timer);
                if (rc == MQTT_FAILURE)
                    goto exit; // there was a problem
            }
            break;
        }
        case MQTTPACKET_PUBREC:
        {
            unsigned short mypacketid;
            unsigned char dup, type;
            if (mqtt_deserialize_ack(&type, &dup, &mypacketid, c->readbuf, c->readbuf_size) != 1)
                rc = MQTT_FAILURE;
            else if ((len = mqtt_serialize_ack(c->buf, c->buf_size, MQTTPACKET_PUBREL, 0, mypacketid)) <= 0)
                rc = MQTT_FAILURE;
            else if ((rc = send_packet(c, len, timer)) != MQTT_SUCCESS) // send the PUBREL packet
                rc = MQTT_FAILURE; // there was a problem
            if (rc == MQTT_FAILURE)
                goto exit; // there was a problem
            break;
        }
        case MQTTPACKET_PUBCOMP:
            break;
        case MQTTPACKET_PINGRESP:
        {
            c->ping_outstanding = 0;
            c->fail_count = 0;
            break;
        }
        case MQTT_READ_ERROR:
        {
            c->isconnected = 0; // we simulate a disconnect if reading error
            rc = MQTT_DISCONNECTED;  // so that the outer layer will reconnect and recover
            break;
        }
    }
    if (c->isconnected)
        rc = keepalive(c);
exit:
    if (rc == MQTT_SUCCESS)
        rc = packet_type;
    return rc;
}
Exemple #7
0
// Singu Note: LLFloaterIMSession::sendMsg
void LLFloaterIMPanel::onSendMsg()
{
	if (!gAgent.isGodlike() 
		&& (mSessionType == P2P_SESSION)
		&& mOtherParticipantUUID.isNull())
	{
		llinfos << "Cannot send IM to everyone unless you're a god." << llendl;
		return;
	}

	if (mInputEditor)
	{
		LLWString text = mInputEditor->getConvertedText();
		if(!text.empty())
		{
			// store sent line in history, duplicates will get filtered
			if (mInputEditor) mInputEditor->updateHistory();
			// Truncate and convert to UTF8 for transport
			std::string utf8_text = wstring_to_utf8str(text);
			bool action = convert_roleplay_text(utf8_text);
			if (!action && mRPMode)
				utf8_text = "((" + utf8_text + "))";

// [RLVa:KB] - Checked: 2010-11-30 (RLVa-1.3.0)
			if ( (RlvActions::hasBehaviour(RLV_BHVR_SENDIM)) || (RlvActions::hasBehaviour(RLV_BHVR_SENDIMTO)) )
			{
				bool fRlvFilter = false;
				switch (mSessionType)
				{
					case P2P_SESSION:	// One-on-one IM
						fRlvFilter = !RlvActions::canSendIM(mOtherParticipantUUID);
						break;
					case GROUP_SESSION:	// Group chat
						fRlvFilter = !RlvActions::canSendIM(mSessionUUID);
						break;
					case ADHOC_SESSION:	// Conference chat: allow if all participants can be sent an IM
						{
							if (!mSpeakers)
							{
								fRlvFilter = true;
								break;
							}

							LLSpeakerMgr::speaker_list_t speakers;
							mSpeakers->getSpeakerList(&speakers, TRUE);
							for (LLSpeakerMgr::speaker_list_t::const_iterator itSpeaker = speakers.begin(); 
									itSpeaker != speakers.end(); ++itSpeaker)
							{
								const LLSpeaker* pSpeaker = *itSpeaker;
								if ( (gAgentID != pSpeaker->mID) && (!RlvActions::canSendIM(pSpeaker->mID)) )
								{
									fRlvFilter = true;
									break;
								}
							}
						}
						break;
					default:
						fRlvFilter = true;
						break;
				}

				if (fRlvFilter)
				{
					utf8_text = RlvStrings::getString(RLV_STRING_BLOCKED_SENDIM);
				}
			}
// [/RLVa:KB]

			if ( mSessionInitialized )
			{
				// Split messages that are too long, same code like in llimpanel.cpp
				U32 split = MAX_MSG_BUF_SIZE - 1;
				U32 pos = 0;
				U32 total = utf8_text.length();

				while (pos < total)
				{
					U32 next_split = split;

					if (pos + next_split > total)
					{
						next_split = total - pos;
					}
					else
					{
						// don't split utf-8 bytes
						while (U8(utf8_text[pos + next_split]) != 0x20	// space
							&& U8(utf8_text[pos + next_split]) != 0x21	// !
							&& U8(utf8_text[pos + next_split]) != 0x2C	// ,
							&& U8(utf8_text[pos + next_split]) != 0x2E	// .
							&& U8(utf8_text[pos + next_split]) != 0x3F	// ?
							&& next_split > 0)
						{
							--next_split;
						}

						if (next_split == 0)
						{
							next_split = split;
							LL_WARNS("Splitting") << "utf-8 couldn't be split correctly" << LL_ENDL;
						}
						else
						{
							++next_split;
						}
					}

					std::string send = utf8_text.substr(pos, next_split);
					pos += next_split;
					LL_DEBUGS("Splitting") << "Pos: " << pos << " next_split: " << next_split << LL_ENDL;

					deliver_message(send,
									mSessionUUID,
									mOtherParticipantUUID,
									mDialog);
				}

				// local echo
				if((mSessionType == P2P_SESSION) &&
				   (mOtherParticipantUUID.notNull()))
				{
					std::string name;
					gAgent.buildFullname(name);

					// Look for actions here.
					if (action)
					{
						utf8_text.replace(0,3,"");
					}
					else
					{
						utf8_text.insert(0, ": ");
					}

					bool other_was_typing = mOtherTyping;
					addHistoryLine(utf8_text, gSavedSettings.getColor("UserChatColor"), true, gAgentID, name);
					if (other_was_typing) addTypingIndicator(mOtherTypingName);
				}
			}
			else
			{
				//queue up the message to send once the session is
				//initialized
				mQueuedMsgsForInit.append(utf8_text);
			}
		}

		LLViewerStats::getInstance()->incStat(LLViewerStats::ST_IM_COUNT);

		mInputEditor->setText(LLStringUtil::null);
	}

	// Don't need to actually send the typing stop message, the other
	// client will infer it from receiving the message.
	mTyping = false;
	mSentTypingState = true;
}
Exemple #8
0
int deliver_messages(struct list *messages) {

    int nmsgs = 0; // number of delivered messages
    int ret;

    // acquire read lock for list of messages
    ret = pthread_rwlock_rdlock(messages->listrwlock);
    assert(ret == 0);

    struct node *curMsg = messages->root;
    while (curMsg != NULL) {
        struct message *msg = curMsg->entry;

        // acquire lock for message stat list
        ret = pthread_rwlock_rdlock(msg->stats->listrwlock);
        assert(ret == 0);


        // walk through statistics of a message and check
        // with read lock whether it is eligible. If yes,
        // check again with write lock and deliver.
        struct node *curStat = msg->stats->root;
        while (curStat != NULL) {
            struct msg_statistics *stat = curStat->entry;

            // acquire read lock for statistic
            ret = pthread_rwlock_rdlock(stat->statrwlock);
            assert(ret == 0);

            int eligible = is_eligible(stat);
            
            // release read lock for statistic
            ret = pthread_rwlock_unlock(stat->statrwlock);
            assert(ret == 0);

            if (eligible) {
                // acquire write lock for statistic
                ret = pthread_rwlock_wrlock(stat->statrwlock);
                assert(ret == 0);

                // check again to make sure
                if (is_eligible(stat)) {
                    deliver_message(msg, stat); // requires write lock
                    nmsgs++;
                }
                
                // release read lock for statistic
                ret = pthread_rwlock_unlock(stat->statrwlock);
                assert(ret == 0);
            }

            curStat = curStat->next;
        }

        // release lock for message stat list
        ret = pthread_rwlock_unlock(msg->stats->listrwlock);
        assert(ret == 0);


        curMsg = curMsg->next;
    }

    // release read lock for list of messages
    ret = pthread_rwlock_unlock(messages->listrwlock);
    assert(ret == 0);

    return nmsgs;
}
Exemple #9
0
void recv_msg(void* sock){
  int retval = 0;
  zmq_msg_t msg;

  // Wow, fun bug. You have to set the identity before bind. No changing identity at runtime?
  #define IDENTITY "blaster.c"
  zmq_setsockopt(sock,ZMQ_IDENTITY,IDENTITY,strlen(IDENTITY));
  retval = zmq_bind(sock,operation.destination);

  if(retval != 0){
    switch(errno){
      case EINVAL:
        puts("zmq_bind EINVAL");
        break;
      case EPROTONOSUPPORT:
        puts("zmq_bind EPROTONOSUPPORT");
        break;
      case ENOCOMPATPROTO:
        puts("zmq_bind ENOCOMPATPROTO");
        break;
      case EADDRINUSE:
        puts("zmq_bind EADDRINUSE");
        break;
      case EADDRNOTAVAIL:
        puts("zmq_bind EADDRNOTAVAIL");
        break;
      case ENODEV:
        puts("zmq_bind ENODEV");
        break;
      case ETERM:
        puts("zmq_bind ETERM");
        break;
      case ENOTSOCK:
        puts("zmq_bind ENOTSOCK");
        break;
      case EMTHREAD:
        puts("zmq_bind EMTHREAD");
        break;
      default:
        puts("zmq_bind errno default");
    }
  }

  char identity[256];
  size_t identity_size;
  zmq_getsockopt(sock,ZMQ_IDENTITY,identity,&identity_size);
  printf("Server up (identity %.*s). Waiting for message.\n",(int)identity_size,identity);

  while(1){
    zmq_msg_init(&msg);

    retval = zmq_recv(sock,&msg,0);
    if(retval != 0){
      switch(errno){
        case EAGAIN:
          puts("zmq_connect EAGAIN");
          break;
        case ENOTSUP:
          puts("zmq_connect ENOTSUP");
          break;
        case EFSM:
          puts("zmq_connect EFSM");
          break;
        case ETERM:
          puts("zmq_connect ETERM");
          break;
        case ENOTSOCK:
          puts("zmq_connect ENOTSOCK");
          break;
        case EINTR:
          puts("zmq_connect EINTR");
          break;
        case EFAULT:
        default:
          puts("zmq_recv errno default");
      }
    }

    #ifdef LOGGING
      printf("Message %d '%.*s' (%d bytes)\n",message_count,(int)zmq_msg_size(&msg),zmq_msg_data(&msg),(int)zmq_msg_size(&msg));
      message_count=message_count+1;
    #endif

    deliver_message(sock,10,0);
    zmq_msg_close(&msg);
  }
}