int stcp_write(stcp_t *s, int n, const void *p) { if (s->proxy == NULL) return send(s->fd, (const char *)p, n, 0); else return proxy_write(s->proxy, n, p); }
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, size_t bytes) { int ret; struct stream_out *out = (struct stream_out *)stream; pthread_mutex_lock(&out->dev->lock); pthread_mutex_lock(&out->lock); if (out->standby) { ret = start_output_stream(out); if (ret != 0) { pthread_mutex_unlock(&out->dev->lock); goto err; } out->standby = false; } pthread_mutex_unlock(&out->dev->lock); alsa_device_proxy* proxy = &out->proxy; const void * write_buff = buffer; int num_write_buff_bytes = bytes; const int num_device_channels = proxy_get_channel_count(proxy); /* what we told alsa */ const int num_req_channels = out->hal_channel_count; /* what we told AudioFlinger */ if (num_device_channels != num_req_channels) { /* allocate buffer */ const size_t required_conversion_buffer_size = bytes * num_device_channels / num_req_channels; if (required_conversion_buffer_size > out->conversion_buffer_size) { out->conversion_buffer_size = required_conversion_buffer_size; out->conversion_buffer = realloc(out->conversion_buffer, out->conversion_buffer_size); } /* convert data */ const audio_format_t audio_format = out_get_format(&(out->stream.common)); const unsigned sample_size_in_bytes = audio_bytes_per_sample(audio_format); num_write_buff_bytes = adjust_channels(write_buff, num_req_channels, out->conversion_buffer, num_device_channels, sample_size_in_bytes, num_write_buff_bytes); write_buff = out->conversion_buffer; } if (write_buff != NULL && num_write_buff_bytes != 0) { proxy_write(&out->proxy, write_buff, num_write_buff_bytes); } pthread_mutex_unlock(&out->lock); return bytes; err: pthread_mutex_unlock(&out->lock); if (ret != 0) { usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) / out_get_sample_rate(&stream->common)); } return bytes; }
unsigned int cmd_proxy_write(callbackp *callbacki) { ape_proxy *proxy; if ((proxy = proxy_are_linked(callbacki->call_user->pipe->pubid, callbacki->param[2], callbacki->g_ape)) == NULL) { send_error(callbacki->call_user, "UNKNOWN_PIPE", "109", callbacki->g_ape); } else if (proxy->state != PROXY_CONNECTED) { send_error(callbacki->call_user, "PROXY_NOT_CONNETED", "205", callbacki->g_ape); } else { proxy_write(proxy, callbacki->param[3], callbacki->g_ape); } return (FOR_NOTHING); }
static int login_imap(int fd, const char *hostname, void *void_arg) { struct imapproxyinfo *ipi=(struct imapproxyinfo *)void_arg; struct proxybuf pb; char linebuf[256]; const char *p; char *cmd; DPRINTF("Proxy connected to %s", hostname); memset(&pb, 0, sizeof(pb)); if (proxy_readline(fd, &pb, linebuf, sizeof(linebuf), 1) < 0) return -1; DPRINTF("%s: %s", hostname, linebuf); if ((p=strtok(linebuf, " \t")) == NULL || strcmp(p, "*") || (p=strtok(NULL, " \t")) == NULL || strcasecmp(p, "OK")) { fprintf(stderr, "WARN: Did not receive greeting from %s\n", hostname); return -1; } cmd=get_imap_cmd(ipi, imap_login_cmd); if (!cmd) return -1; if (proxy_write(fd, hostname, cmd, strlen(cmd))) { free(cmd); return -1; } free(cmd); #if SMAP if (strcmp(ipi->tag, "\\SMAP1") == 0) { do { if (proxy_readline(fd, &pb, linebuf, sizeof(linebuf), 0) < 0) return -1; DPRINTF("%s: %s", hostname, linebuf); } while (linebuf[0] != '+' && linebuf[0] != '-'); if (linebuf[0] != '+') { fprintf(stderr, "WARN: Login to %s failed\n", hostname); return -1; } if (fcntl(1, F_SETFL, 0) < 0 || (printf("+OK connected to proxy server.\r\n"), fflush(stdout)) < 0) return -1; return (0); } #endif for (;;) { if (proxy_readline(fd, &pb, linebuf, sizeof(linebuf), 1) < 0) return -1; DPRINTF("%s: %s", hostname, linebuf); if ((p=strtok(linebuf, " \t")) == NULL || strcmp(p, ipi->tag) || (p=strtok(NULL, " \t")) == NULL) continue; if (strcasecmp(p, "OK")) { fprintf(stderr, "WARN: Login to %s failed\n", hostname); return -1; } break; } p=getenv("IMAP_PROXY_FOREIGN"); if (p && atoi(p)) { cmd=get_imap_cmd(ipi, imap_capability_cmd); if (!cmd) return -1; if (proxy_write(fd, hostname, cmd, strlen(cmd))) { free(cmd); return -1; } free(cmd); } else { if (fcntl(1, F_SETFL, 0) < 0 || (printf("%s OK connected to proxy server.\r\n", ipi->tag), fflush(stdout)) < 0) return -1; } return 0; }
static int login_pop3(int fd, const char *hostname, void *void_arg) { struct pop3proxyinfo *ppi=(struct pop3proxyinfo *)void_arg; struct proxybuf pb; char linebuf[256]; char *cmd; DPRINTF("Proxy connected to %s", hostname); memset(&pb, 0, sizeof(pb)); if (proxy_readline(fd, &pb, linebuf, sizeof(linebuf), 1) < 0) return -1; DPRINTF("%s: %s", hostname, linebuf); if (linebuf[0] != '+') { fprintf(stderr, "WARN: Did not receive greeting from %s\n", hostname); return -1; } cmd=malloc(strlen(ppi->uid) + strlen(ppi->pwd)+100); /* Should be enough */ if (!cmd) return -1; sprintf(cmd, "USER %s\r\n", ppi->uid); if (proxy_write(fd, hostname, cmd, strlen(cmd))) { free(cmd); return -1; } if (proxy_readline(fd, &pb, linebuf, sizeof(linebuf), 1) < 0) { free(cmd); return -1; } DPRINTF("%s: %s", hostname, linebuf); if (linebuf[0] != '+') { free(cmd); fprintf(stderr, "WARN: Login userid rejected by %s\n", hostname); return -1; } sprintf(cmd, "PASS %s\r\n", ppi->pwd); if (proxy_write(fd, hostname, cmd, strlen(cmd))) { free(cmd); return -1; } if (proxy_readline(fd, &pb, linebuf, sizeof(linebuf), 1) < 0) { free(cmd); return -1; } DPRINTF("%s: %s", hostname, linebuf); if (linebuf[0] != '+') { free(cmd); fprintf(stderr, "WARN: Login password rejected by %s\n", hostname); return -1; } free(cmd); if (fcntl(1, F_SETFL, 0) < 0 || (printf("+OK Connected to proxy server.\r\n"), fflush(stdout)) < 0) return -1; return 0; }