Esempio n. 1
0
int Mp3OutputStream::Flush(PBYTE& p_written)
{
	int encoded = 0;

#ifdef Mp3OutputStream_Buffering
	if (m_inBufferPos > 0)
	{
		if (LameEncodeChunk(global_fags, m_inBuffer, 0, m_inBufferPos, bytes_per_sample, m_outBuffer, encoded))
		{
			if (encoded > 0 && writeCallback)
			{
				writeCallback(m_inBufferPos, (char *)m_outBuffer, encoded);
			}
		}
	}
#endif

	if (LameFlush(global_fags, m_outBuffer, encoded))
	{
		p_written = m_outBuffer;
		return encoded;
	}
	return -1;

#ifdef Mp3OutputStream_Buffering
	m_inBufferPos = 0;
#endif
}
Esempio n. 2
0
    void Channel::handleEvent(){

        if(mRevents & (POLLIN | POLLPRI)){
            if(readCallback) readCallback();
        }
        else if(mRevents & (POLLOUT)){
            if(writeCallback) writeCallback();
        }
    }
Esempio n. 3
0
// converse is called by PAM to interact with the user. Interaction means
// either writing something to stdout and stderr or reading something from
// stdin.
int converse(int n, const struct pam_message **msg, struct pam_response **resp, void *data)
{
    int i;
    struct pam_response *aresp;

    // If no messages arrived, or the number of messages is greater than
    // allowed, something is wrong with the caller.
    if (n <= 0 || n > PAM_MAX_NUM_MSG) {
        return PAM_CONV_ERR;
    }

    // According to pam_conv(3): "It is the caller's responsibility to release
    // both, this array and the responses themselves, using free(3)." The
    // caller in this situation is the PAM module and the array and the
    // responses refer to aresp and aresp[i].resp.
    aresp = calloc(n, sizeof *aresp);
    if (aresp == NULL) {
        return PAM_BUF_ERR;
    }

    // Loop over all messages and process them.
    for (i = 0; i < n; ++i) {
        aresp[i].resp_retcode = 0;
        aresp[i].resp = NULL;

        switch (msg[i]->msg_style) {
        case PAM_PROMPT_ECHO_OFF:
            // Read back response from user. What the user writes should not
            // be echoed to the screen.
            aresp[i].resp = readCallback((uintptr_t)data, 0);
            if (aresp[i].resp == NULL) {
                goto fail;
            }
            break;
        case PAM_PROMPT_ECHO_ON:
            // First write the message to stderr.
            writeCallback((uintptr_t)data, STDERR_FILENO, (char *)(msg[i]->msg));

            // Read back response from user. What the user writes will be
            // echoed to the screen.
            aresp[i].resp = readCallback((uintptr_t)data, 1);
            if (aresp[i].resp == NULL) {
                goto fail;
            }
            break;
        case PAM_ERROR_MSG:
            // Write message to stderr.
            writeCallback((uintptr_t)data, STDERR_FILENO, (char *)(msg[i]->msg));
            if (strlen(msg[i]->msg) > 0 && msg[i]->msg[strlen(msg[i]->msg) - 1] != '\n') {
                writeCallback((uintptr_t)data, STDERR_FILENO, (char *)"\n");
            }
            break;
        case PAM_TEXT_INFO:
            // Write message to stdout.
            writeCallback((uintptr_t)data, STDOUT_FILENO, (char *)(msg[i]->msg));
            if (strlen(msg[i]->msg) > 0 && msg[i]->msg[strlen(msg[i]->msg) - 1] != '\n') {
                writeCallback((uintptr_t)data, STDOUT_FILENO, (char *)"\n");
            }

            break;
        default:
            goto fail;
        }
    }
    *resp = aresp;
    return PAM_SUCCESS;

 fail:
    for (i = 0; i < n; ++i) {
        if (aresp[i].resp != NULL) {
            memset(aresp[i].resp, 0, strlen(aresp[i].resp));
            free(aresp[i].resp);
        }
    }
    memset(aresp, 0, n * sizeof *aresp);
    *resp = NULL;
    return PAM_CONV_ERR;
}