void mm_lsub (MAILSTREAM *stream,int delimiter,char *mailbox,long attributes)
{
	if (attributes & LATT_NOINFERIORS) output_printf( OUTPUT_NORMAL, "%c%s, no inferiors", mailbox);
	if (attributes & LATT_NOSELECT)    output_printf( OUTPUT_NORMAL, "%c%s, no select", mailbox);
	if (attributes & LATT_MARKED)      output_printf( OUTPUT_NORMAL, "%c%s, marked", mailbox);
	if (attributes & LATT_UNMARKED)    output_printf( OUTPUT_NORMAL, "%c%s, unmarked", mailbox);
}
void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status)
{
	if (status->flags & SA_MESSAGES)    output_printf( OUTPUT_NORMAL, "Mailbox %s, %lu messages", mailbox, status->messages);
	if (status->flags & SA_RECENT)      output_printf( OUTPUT_NORMAL, "Mailbox %s, %lu recent", mailbox, status->recent);
	if (status->flags & SA_UNSEEN)      output_printf( OUTPUT_NORMAL, "Mailbox %s, %lu unseen", mailbox, status->unseen);
	if (status->flags & SA_UIDVALIDITY) output_printf( OUTPUT_NORMAL, "Mailbox %s, %lu UID validity", mailbox, status->uidvalidity);
	if (status->flags & SA_UIDNEXT)     output_printf( OUTPUT_NORMAL, "Mailbox %s, %lu next UID", mailbox, status->uidnext);
}
static void printOutputCapabilities() {
    int i, j;

    output_printf(10, "%s::%s\n", FILENAME, __FUNCTION__);
    output_printf(10, "Capabilities:\n");

    for (i = 0; AvailableOutput[i] != NULL; i++)	{
        output_printf(10, "\t%s : ", AvailableOutput[i]->Name);

        for (j = 0; AvailableOutput[i]->Capabilities[j] != NULL; j++)
            output_printf(10, "%s ", AvailableOutput[i]->Capabilities[j]);
        output_printf(10, "\n");
    }
}
Exemplo n.º 4
0
static void OutputAdd(Context_t  *context, char *port)
{
    int i, j;

    output_printf(10, "%s::%s\n", FILENAME, __FUNCTION__);

    for (i = 0; AvailableOutput[i] != NULL; i++)
    {
        for (j = 0; AvailableOutput[i]->Capabilities[j] != NULL; j++)
        {
            if (!strcmp(AvailableOutput[i]->Capabilities[j], port))
            {
                if (!strcmp("audio", port)) 
                {
                    context->output->audio = AvailableOutput[i];
                    return;
                }
                else if (!strcmp("video", port)) 
                {
                    context->output->video = AvailableOutput[i];
                    return;
                }
                else if (!strcmp("subtitle", port)) 
                {
                    context->output->subtitle = AvailableOutput[i];
                    return;
                }
            }
        }
    }
}
void mm_log (char *string,long errflg)
{
	switch ((short) errflg) {
	case NIL:
		output_printf(OUTPUT_NORMAL, "%s", string);
		break;
	case PARSE:
	case WARN:
		output_printf(OUTPUT_WARNING, "%s", string);
		break;
	case ERROR:
		output_printf(OUTPUT_ERROR, "%s", string);
		break;
	default:
		output_printf(OUTPUT_NORMAL, "%s", string);
	}
}
FeriteVariable *create_ferite_header_object( FeriteScript *script, ENVELOPE *env )
{
    FeriteVariable *header = NULL, *v = NULL;
    FeriteNamespaceBucket *nsb = NULL;
    #define BUFSIZE 1025
    char buf[BUFSIZE];
    int i = 0;

    if( env == NULL)
      return NULL;

    ADDRESS *address_source[6] = { env->from, env->reply_to, env->cc, env->bcc, env->sender, env->to };
    char *address_target[6] = { "from", "reply_to" , "cc", "bcc", "sender" , "to" };
    int n_address_source = 6;

    char *source[5] = { env->subject, env->date, env->message_id, env->in_reply_to, env->references };
    char *target[5] = { "subject", "date", "ID", "in_reply_to", "references" };
    int  n_source = 5;

    nsb = ferite_find_namespace( script, script->mainns, "Mail.MessageHeader", FENS_CLS );
    if( nsb == NULL)
	    return NULL;

    header = ferite_build_object( script, (FeriteClass *)nsb->data );
    if( header == NULL )
	    return NULL;


    //Parse each address structure in address_source[] and write the result to the
    //corresonding object member in address_target[]
    for(i=0; i < n_address_source; i++) {
	    v = create_address_list( script, address_source[i] );
	    if( v == NULL ) {
		    //set_error_string( script, self, "Couldn't create address list" );
		    return NULL;
	    }
	    ferite_object_set_var(script, VAO(header), address_target[i], v );
    }

    //Copy  each header-field in source[] to the
    //corresonding object member in address_target[]
    for(i=0; i< n_source; i++) {
	    if( source[i] ) {
		    v = fe_new_str(target[i], source[i] , 0, FE_CHARSET_DEFAULT );
		    if( v == NULL ) {
			    //set_error_string( script, self, "Couldn't create mail header" );
			    return NULL;
		    }
		    ferite_object_set_var(script, VAO(header), target[i], v );
		    if( debug_cmail_module && strcmp( target[i], "subject" ) == 0 ) {
				output_printf(OUTPUT_DEBUG,"module.mail: Processing email with subject: '%s'", source[i] );
		    }
	    }
    }
    return header;
}
Exemplo n.º 7
0
static void OutputDel(Context_t  *context, char * port) 
{
	output_printf(10, "%s::%s\n", FILENAME, __FUNCTION__);

	if (!strcmp("audio", port))
		context->output->audio = NULL;
	else if (!strcmp("video", port))
		context->output->video = NULL;   
	else if (!strcmp("subtitle", port))
		context->output->subtitle = NULL;
}
Exemplo n.º 8
0
Arquivo: net.c Projeto: aragaer/wine
static BOOL net_enum_services(void)
{
    static const WCHAR runningW[]={' ',' ',' ',' ','%','s','\n',0};
    SC_HANDLE SCManager;
    LPENUM_SERVICE_STATUS_PROCESSW services;
    DWORD size, i, count, resume;
    BOOL success = FALSE;

    SCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if(!SCManager)
    {
        output_string(STRING_NO_SCM);
        return FALSE;
    }

    EnumServicesStatusExW(SCManager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ACTIVE, NULL, 0, &size, &count, NULL, NULL);
    if(GetLastError() != ERROR_MORE_DATA)
    {
        output_error_string(GetLastError());
        goto end;
    }
    services = HeapAlloc(GetProcessHeap(), 0, size);
    resume = 0;
    if(!EnumServicesStatusExW(SCManager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ACTIVE, (LPBYTE)services, size, &size, &count, &resume, NULL))
    {
        output_error_string(GetLastError());
        goto end;
    }
    output_string(STRING_RUNNING_HEADER);
    for(i = 0; i < count; i++)
    {
        output_printf(runningW, services[i].lpDisplayName);
        WINE_TRACE("service=%s state=%d controls=%x\n",
                   wine_dbgstr_w(services[i].lpServiceName),
                   services[i].ServiceStatusProcess.dwCurrentState,
                   services[i].ServiceStatusProcess.dwControlsAccepted);
    }
    success = TRUE;

 end:
    CloseServiceHandle(SCManager);
    return success;
}
FeriteVariable *create_ferite_content_object( FeriteScript *script, MAILSTREAM *stream, BODY *body, int msgno, char *sec )
{
	if( body != NULL ) {
		FeriteVariable *object = NULL,*v = NULL;
		FeriteNamespaceBucket *nsb = NULL;
		char *object_name = NULL;

		object_name = ( body->type == TYPEMULTIPART ) ? "Mail.MessageMultiPart" : "Mail.MessagePart" ;

		nsb = ferite_find_namespace( script, script->mainns, object_name , FENS_CLS );
		if( nsb == NULL )
			return NULL;
		object = ferite_build_object( script, (FeriteClass *)nsb->data );
		if( object == NULL )
			return NULL;

		v  = fe_new_lng("type",body->type);
		ferite_object_set_var(script, VAO(object), "type", v);
		output_printf(OUTPUT_DEBUG,"module.mail: setting type %d", body->type);
		if( body->subtype ) {
			v = fe_new_str( "subtype", body->subtype, 0, FE_CHARSET_DEFAULT );
			ferite_object_set_var( script, VAO(object), "subtype", v );
		}

		if( body->type == TYPEMULTIPART ) {
			PART *part = NULL;
			int i = 0;
			char sec2[200];
			FeriteVariable *ret = NULL, *parts = NULL;

			parts = ferite_hash_get(script,VAO(object)->variables->variables,"parts");
			part = body->nested.part;
			while( part ) {
				i++;
				if( sec ) {
					snprintf(sec2,200,"%s.%d",sec,i);
				} else {
					snprintf(sec2,200,"%d",i);
				}
				ret = create_ferite_content_object( script, stream, &part->body, msgno, sec2 );
				ferite_uarray_add( script, VAUA(parts), ret , NULL, FE_ARRAY_ADD_AT_END );
				part = part->next;
			}
			v = fe_new_lng("nparts", i);
			ferite_object_set_var(script, VAO(object), "nparts", v );
		}
		else
		{
			long len = 0,len2 = 0;
			unsigned char *buf = NULL, *buf2 = NULL;
			SIZEDTEXT src, dest;
			FeriteVariable *v = NULL;
			PARAMETER *param = NULL;
			int i = 0;

			if( sec == NULL )
				sec = "1";
			buf = mail_fetchbody( stream, msgno, sec, &len );

			switch(body->encoding){
				case ENCQUOTEDPRINTABLE:
					if( debug_cmail_module )
						output_printf(OUTPUT_DEBUG,"module.mail: Decoding from encoded quotable");
					buf2 = rfc822_qprint(buf,len,&len2);
					break;
				case ENCBASE64: 
					if( debug_cmail_module )
						output_printf(OUTPUT_DEBUG,"module.mail: Decoding from base64");
					buf2=rfc822_base64(buf,len,&len2);
					break;
				default: 
					buf2=buf;
					len2=len;
			}

			if( debug_cmail_module ) {
				output_printf(OUTPUT_DEBUG,"module.mail: id: %s, description: %s", body->id, body->description);
				output_printf(OUTPUT_DEBUG,"module.mail: block type: %d.%s", body->type, body->subtype);
			}
			if( body->parameter ) /* Try and get the content type correctly */ {
				PARAMETER *ptr = body->parameter;
				while( ptr != NULL ) {
					if( caseless_compare( ptr->attribute, "charset" ) ) {
						if( debug_cmail_module )
							output_printf(OUTPUT_DEBUG,"module.mail: Found content type for block: %s", ptr->value);
						v = fe_new_str("charset", ptr->value, 0, FE_CHARSET_DEFAULT);
						ferite_object_set_var(script, VAO(object), "charset", v);
					}
					ptr = ptr->next;
				}
			}
			v = fe_new_bin_str("content", buf2, len2, FE_CHARSET_DEFAULT );
			ferite_object_set_var(script, VAO(object), "content", v );

			v = fe_new_lng("encoding", body->encoding );
			ferite_object_set_var(script, VAO(object), "encoding", v );

			if( body->id ) {
				v = fe_new_str("ID", body->id, strlen(body->id), FE_CHARSET_DEFAULT);
				ferite_object_set_var(script, VAO(object), "ID", v);
			}
			
			if( body->disposition.type && strcasecmp(body->disposition.type, "attachment") == 0) {
				param = body->disposition.parameter;
				while(param){
					if( param->attribute && ((strcasecmp(param->attribute,"filename") == 0) ||
												(strcasecmp(param->attribute,"name") == 0) ||
												(strcasecmp(param->attribute,"name*") == 0) ||
												(strcasecmp(param->attribute,"filename*") == 0) )) {
						v = fe_new_str("filename", param->value, 0, FE_CHARSET_DEFAULT );
						ferite_object_set_var(script, VAO(object), "filename", v );
						break;
					}
					param=param->next;
				}
			}
			/* If filename was not found in Content-Disposition header search for it among the parameters */
			if( strcmp(VAS(ferite_object_get_var(script, VAO(object), "filename"))->data, "") == 0 ) {
				param = body->parameter;
				while(param){
					if( param->attribute && ((strcasecmp(param->attribute,"filename") == 0) || 
												(strcasecmp(param->attribute,"name") == 0))) {
						v = fe_new_str("filename", param->value, 0, FE_CHARSET_DEFAULT );
						ferite_object_set_var(script, VAO(object), "filename", v );
						break;
					}
					param = param->next;
				}
			}
		}
		return object;
	}
	return NULL;
}
Exemplo n.º 10
0
static void *msg_thread_run(esl_thread_t *me, void *obj)
{
	esl_handle_t *handle = (esl_handle_t *) obj;
	thread_running = 1;
	while(thread_running && handle->connected) {
		int aok = 1;
		esl_status_t status = esl_recv_event_timed(handle, 10, 1, NULL);
		if (status == ESL_FAIL) {
			esl_log(ESL_LOG_WARNING, "Disconnected.\n");
			running = -1; thread_running = 0;
		} else if (status == ESL_SUCCESS) {
			aok = stdout_writable();
			if (handle->last_event) {
				int known = 1;
				const char *type = esl_event_get_header(handle->last_event, "content-type");
				if (!esl_strlen_zero(type)) {
					if (!strcasecmp(type, "log/data")) {
						const char *userdata = esl_event_get_header(handle->last_event, "user-data");
						if (esl_strlen_zero(userdata) || esl_strlen_zero(filter_uuid) || !strcasecmp(filter_uuid, userdata)) {
							int level = 0;
							const char *lname = esl_event_get_header(handle->last_event, "log-level");
#ifdef WIN32
							DWORD len = (DWORD) strlen(handle->last_event->body);
							DWORD outbytes = 0;
#endif
							if (logfilter) {
								if (!strstr(handle->last_event->body, logfilter)) {
									continue;
								}
							}

							if (lname) {
								level = atoi(lname);
							}
#ifndef WIN32
							if (aok) {
								if (feature_level) clear_line();
								if(!(global_profile->batch_mode)) {
									printf("%s", colors[level]);
								}
								if (global_profile->log_uuid && !esl_strlen_zero(userdata)) {
									printf("%s ", userdata);
								}
								printf("%s", handle->last_event->body);
								if(!(global_profile->batch_mode)) {
									if (!feature_level) printf("%s", ESL_SEQ_DEFAULT_COLOR);
								}
								if (feature_level) redisplay();
							}
#else
							if (aok) {
								if(!(global_profile->batch_mode)) {
									SetConsoleTextAttribute(hStdout, colors[level]);
								}
								if (global_profile->log_uuid && !esl_strlen_zero(userdata)) {
									WriteFile(hStdout, userdata, (DWORD)strlen(userdata), &outbytes, NULL);
									WriteFile(hStdout, " ", (DWORD)strlen(" "), &outbytes, NULL);
								}
								WriteFile(hStdout, handle->last_event->body, len, &outbytes, NULL);
								if(!(global_profile->batch_mode)) {
									SetConsoleTextAttribute(hStdout, wOldColorAttrs);
								}
							}
#endif
						}
					} else if (!strcasecmp(type, "text/disconnect-notice")) {
						running = -1; thread_running = 0;
					} else if (!strcasecmp(type, "text/event-plain")) {
						char *s;
						esl_event_serialize(handle->last_ievent, &s, ESL_FALSE);
						if (aok) {
							clear_line();
							output_printf("RECV EVENT\n%s\n", s);
							redisplay();
						}
						free(s);
					} else {
						known = 0;
					}
				}
				if (aok && !known) {
					char *s;
					output_printf("INCOMING DATA [%s]\n%s\n", type, handle->last_event->body ? handle->last_event->body : "");
					esl_event_serialize(handle->last_event, &s, ESL_FALSE);
					output_printf("RECV EVENT\n%s\n", s);
					redisplay();
					free(s);
				}
			}
		}
		if (warn_stop) {
			if (aok) {
				clear_line();
				output_printf("Type control-D or /exit or /quit or /bye to exit.\n\n");
				redisplay();
			}
			warn_stop = 0;
		}
		sleep_ms(1);
	}
	thread_running = 0;
	esl_log(ESL_LOG_DEBUG, "Thread Done\n");
	return NULL;
}
Exemplo n.º 11
0
static int new_write(const char *buf, uint buflen)
{
	output_printf(buf, buflen);
	return 0;
}
Exemplo n.º 12
0
static int new_buffered_output(char *buf, size_t buflen, void *arg)
{
	output_printf(buf,buflen);
	return 0;
}
Exemplo n.º 13
0
static int process_command(esl_handle_t *handle, const char *cmd)
{
	while (*cmd == ' ') cmd++;


	if ((*cmd == '/' && cmd++) || !strncasecmp(cmd, "...", 3)) {
		if (!strcasecmp(cmd, "help")) {
			output_printf("%s", cli_usage);
			goto end;
		}
		if (!strcasecmp(cmd, "exit") ||
			!strcasecmp(cmd, "quit") ||
			!strcasecmp(cmd, "...") ||
			!strcasecmp(cmd, "bye")
			) {
			esl_log(ESL_LOG_INFO, "Goodbye!\nSee you at ClueCon http://www.cluecon.com/\n");
			return -1;
		} else if (!strncasecmp(cmd, "logfilter", 9)) {
			cmd += 9;
			while (*cmd && *cmd == ' ') {
				cmd++;
			}
			if (!esl_strlen_zero(cmd)) {
				esl_safe_free(logfilter);
				logfilter = strdup(cmd);
			} else {
				esl_safe_free(logfilter);
			}
			output_printf("Logfilter %s\n", logfilter ? "enabled" : "disabled");
		} else if (!strncasecmp(cmd, "uuid", 4)) {
			cmd += 4;
			while (*cmd && *cmd == ' ') {
				cmd++;
			}
			if (!esl_strlen_zero(cmd)) {
				filter_uuid = strdup(cmd);
			} else {
				esl_safe_free(filter_uuid);
			}
			output_printf("UUID filtering %s\n", filter_uuid ? "enabled" : "disabled");
		} else if (!strncasecmp(cmd, "event", 5) ||
				   !strncasecmp(cmd, "noevents", 8) ||
				   !strncasecmp(cmd, "nixevent", 8) ||
				   !strncasecmp(cmd, "log", 3) ||
				   !strncasecmp(cmd, "nolog", 5) ||
				   !strncasecmp(cmd, "filter", 6)
				   ) {
			esl_send_recv(handle, cmd);
			printf("%s\n", handle->last_sr_reply);
		} else if (!strncasecmp(cmd, "debug", 5)) {
			int tmp_debug = atoi(cmd+6);
			if (tmp_debug > -1 && tmp_debug < 8) {
				esl_global_set_default_logger(tmp_debug);
				output_printf("fs_cli debug level set to %d\n", tmp_debug);
			} else {
				output_printf("fs_cli debug level must be 0 - 7\n");
			}
		} else {
			output_printf("Unknown command [%s]\n", cmd);
		}
	} else {
		char cmd_str[1024] = "";
		const char *err = NULL;

		if (!strncasecmp(cmd, "console loglevel ", 17)) { 
			snprintf(cmd_str, sizeof(cmd_str), "log %s", cmd + 17);
			esl_send_recv(handle, cmd_str);
			printf("%s\n", handle->last_sr_reply);
		}

		snprintf(cmd_str, sizeof(cmd_str), "api %s\nconsole_execute: true\n\n", cmd);
		if (esl_send_recv(handle, cmd_str)) {
			output_printf("Socket interrupted, bye!\n");
			return -1;
		}
		if (handle->last_sr_event) {
			if (handle->last_sr_event->body) {
				output_printf("%s\n", handle->last_sr_event->body);
			} else if ((err = esl_event_get_header(handle->last_sr_event, "reply-text")) && !strncasecmp(err, "-err", 3)) {
				output_printf("Error: %s!\n", err + 4);
			}
		}
	}
 end:
	return 0;
}
Exemplo n.º 14
0
void mm_dlog (char *string)
{
	output_printf(OUTPUT_DEBUG,"debug-log: %s", string);
}
Exemplo n.º 15
0
static int Command(void  *_context, OutputCmd_t command, void * argument)
{
    Context_t  *context = (Context_t*) _context;
    int ret = cERR_OUTPUT_NO_ERROR;

    output_printf(10, "%s::%s Command %d\n", FILENAME, __FUNCTION__, command);

    switch(command)
    {
    case OUTPUT_OPEN:
    {
        if (context && context->playback )
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_OPEN, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_OPEN, "audio");
            }
            if (context->playback->isSubtitle)
            {
                ret |= context->output->subtitle->Command(context, OUTPUT_OPEN, "subtitle");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_CLOSE:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_CLOSE, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_CLOSE, "audio");
            }
            if (context->playback->isSubtitle)
            {
                ret |= context->output->subtitle->Command(context, OUTPUT_CLOSE, "subtitle");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_ADD:
    {
        OutputAdd(context, (char*) argument);
        break;
    }
    case OUTPUT_DEL:
    {
        OutputDel(context, (char*) argument);
        break;
    }
    case OUTPUT_CAPABILITIES:
    {
        printOutputCapabilities();
        break;
    }
    case OUTPUT_PLAY: 
    { // 4
        if (context && context->playback )
        {
            if (context->playback->isVideo)
            {
                ret = context->output->video->Command(context, OUTPUT_PLAY, "video");
            }
            // success or not executed, dunn care
            if (!ret) 
            {
                if (context->playback->isAudio)
                {
                    ret = context->output->audio->Command(context, OUTPUT_PLAY, "audio");
                }
            }
            if (!ret) 
            {
                if (context->playback->isSubtitle)
                {
                    ret = context->output->subtitle->Command(context, OUTPUT_PLAY, "subtitle");
                }
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_STOP: 
    {
        if (context && context->playback ) 
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_STOP, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_STOP, "audio");
            }
            if (context->playback->isSubtitle)
            {
                ret |= context->output->subtitle->Command(context, OUTPUT_STOP, "subtitle");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_FLUSH:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_FLUSH, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_FLUSH, "audio");
            }
            if (context->playback->isSubtitle)
            {
                ret |= context->output->subtitle->Command(context, OUTPUT_FLUSH, "subtitle");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_PAUSE:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_PAUSE, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_PAUSE, "audio");
            }
            if (context->playback->isSubtitle)
            {
                ret |= context->output->subtitle->Command(context, OUTPUT_PAUSE, "subtitle");
            }
        }
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_FASTFORWARD:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_FASTFORWARD, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_FASTFORWARD, "audio");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_REVERSE:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_REVERSE, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_REVERSE, "audio");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_CONTINUE:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_CONTINUE, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_CONTINUE, "audio");
            }
            if (context->playback->isSubtitle)
            {
                ret |= context->output->subtitle->Command(context, OUTPUT_CONTINUE, "subtitle");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_AVSYNC:
    {
        if (context && context->playback )
        {
            if (context->playback->isVideo && context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_AVSYNC, "audio");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_CLEAR:
    {
        if (context && context->playback )
        {
            if (context->playback->isVideo && (argument == NULL || *(char *) argument == 'v'))
            {
                ret |= context->output->video->Command(context, OUTPUT_CLEAR, "video");
            }
            if (context->playback->isAudio && (argument == NULL || *(char *) argument == 'a'))
            {
                ret |= context->output->audio->Command(context, OUTPUT_CLEAR, "audio");
            }
            if (context->playback->isSubtitle && (argument == NULL || *(char *) argument == 's'))
            {
                ret |= context->output->subtitle->Command(context, OUTPUT_CLEAR, "subtitle");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_PTS:
    {
        if (context && context->playback )
        {
            if (context->playback->isVideo)
            {
                return context->output->video->Command(context, OUTPUT_PTS, argument);
            }
            if (context->playback->isAudio)
            {
                return context->output->audio->Command(context, OUTPUT_PTS, argument);
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_SWITCH:
    {
        if (context && context->playback )
        {
            if (context->playback->isAudio)
            {
                return context->output->audio->Command(context, OUTPUT_SWITCH, "audio");
            }
            if (context->playback->isVideo)
            {
                return context->output->video->Command(context, OUTPUT_SWITCH, "video");
            }
            if (context->playback->isSubtitle)
            {
                return context->output->subtitle->Command(context, OUTPUT_SWITCH, "subtitle");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_SLOWMOTION:
    {
        if (context && context->playback )
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_SLOWMOTION, "video");
            }
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_SLOWMOTION, "audio");
            }
        } 
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_AUDIOMUTE:
    {
        if (context && context->playback)
        {
            if (context->playback->isAudio)
            {
                ret |= context->output->audio->Command(context, OUTPUT_AUDIOMUTE, (char*) argument);
            }
        }
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_DISCONTINUITY_REVERSE:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                ret |= context->output->video->Command(context, OUTPUT_DISCONTINUITY_REVERSE, (void*) argument);
            }
        }
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    case OUTPUT_GET_FRAME_COUNT:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                return context->output->video->Command(context, OUTPUT_GET_FRAME_COUNT, argument);
            }
            if (context->playback->isAudio)
            {
                return context->output->audio->Command(context, OUTPUT_GET_FRAME_COUNT, argument);
            }
        }
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    case OUTPUT_GET_PROGRESSIVE:
    {
        if (context && context->playback)
        {
            if (context->playback->isVideo)
            {
                return context->output->video->Command(context, OUTPUT_GET_PROGRESSIVE, (void*) argument);
            }
        }
        else
        {
            ret = cERR_OUTPUT_INTERNAL_ERROR;
        }
        break;
    }
    }
    default:
        output_err("%s::%s OutputCmd %d not supported!\n", FILENAME, __FUNCTION__, command);
        ret = cERR_OUTPUT_INTERNAL_ERROR;
        break;
    }

    output_printf(10, "%s::%s exiting with value %d\n", FILENAME, __FUNCTION__, ret);

    return ret;
}
Exemplo n.º 16
0
void mm_fatal (char *string)
{
	output_printf(OUTPUT_ERROR,"Fatal error: %s", string);
}
Exemplo n.º 17
0
int main(int argc, char *argv[])
{
	esl_handle_t handle = {{0}};
	int count = 0;
	const char *line = NULL;
	char cmd_str[1024] = "";
	cli_profile_t *profile = NULL;
#ifndef WIN32
	char hfile[512] = "/tmp/fs_cli_history";
	char cfile[512] = "/etc/fs_cli.conf";
	char dft_cfile[512] = "/etc/fs_cli.conf";
#else
	char hfile[512] = "fs_cli_history";
	char cfile[512] = "fs_cli.conf";
	char dft_cfile[512] = "fs_cli.conf";
#endif
	char *home = getenv("HOME");
	/* Vars for optargs */
	int opt;
	static struct option options[] = {
		{"help", 0, 0, 'h'},
		{"no-color", 0, 0, 'n'},
		{"host", 1, 0, 'H'},
		{"port", 1, 0, 'P'},
		{"user", 1, 0, 'u'},
		{"password", 1, 0, 'p'},
		{"debug", 1, 0, 'd'},
		{"execute", 1, 0, 'x'},
		{"loglevel", 1, 0, 'l'},
		{"log-uuid", 0, 0, 'U'},
		{"quiet", 0, 0, 'q'},
		{"batchmode", 0, 0, 'b'},
		{"retry", 0, 0, 'r'},
		{"interrupt", 0, 0, 'i'},
		{"reconnect", 0, 0, 'R'},
		{"timeout", 1, 0, 't'},
		{"connect-timeout", 1, 0, 'T'},
		{0, 0, 0, 0}
	};
	char temp_host[128];
	int argv_host = 0;
	char temp_user[256];
	char temp_pass[128];
	int argv_pass = 0 ;
	int argv_user = 0 ;
	int temp_port = 0;
	int argv_port = 0;
	int temp_log = -1;
	int argv_error = 0;
	int argv_exec = 0;
	char argv_command[1024] = "";
	char argv_loglevel[128] = "";
	int argv_log_uuid = 0;
	int argv_quiet = 0;
	int argv_batch = 0;
	int loops = 2, reconnect = 0;
	char *ccheck;

#ifdef WIN32
	feature_level = 0;
#else
	feature_level = 1;
#endif

	if ((ccheck = getenv("FS_CLI_COLOR"))) {
		is_color = esl_true(ccheck);
	}

	strncpy(internal_profile.host, "127.0.0.1", sizeof(internal_profile.host));
	strncpy(internal_profile.pass, "ClueCon", sizeof(internal_profile.pass));
	strncpy(internal_profile.name, "internal", sizeof(internal_profile.name));
	internal_profile.port = 8021;
	set_fn_keys(&internal_profile);
	esl_set_string(internal_profile.prompt_color, prompt_color);
	esl_set_string(internal_profile.input_text_color, input_text_color);
	esl_set_string(internal_profile.output_text_color, output_text_color);
	if (home) {
		snprintf(hfile, sizeof(hfile), "%s/.fs_cli_history", home);
		snprintf(cfile, sizeof(cfile), "%s/.fs_cli_conf", home);
	}
	signal(SIGINT, handle_SIGINT);
#ifdef SIGTSTP
	signal(SIGTSTP, handle_SIGINT);
#endif
#ifdef SIGQUIT
	signal(SIGQUIT, handle_SIGQUIT);
#endif
	esl_global_set_default_logger(6); /* default debug level to 6 (info) */
	for(;;) {
		int option_index = 0;
		opt = getopt_long(argc, argv, "H:P:S:u:p:d:x:l:Ut:T:qrRhib?n", options, &option_index);
		if (opt == -1) break;
		switch (opt) {
			case 'H':
				esl_set_string(temp_host, optarg);
				argv_host = 1;
				break;
			case 'P':
				temp_port= atoi(optarg);
				if (temp_port > 0 && temp_port < 65536) {
					argv_port = 1;
				} else {
					printf("ERROR: Port must be in range 1 - 65535\n");
					argv_error = 1;
				}
				break;
			case 'n':
				is_color = 0;
				break;
			case 'u':
				esl_set_string(temp_user, optarg);
				argv_user = 1;
				break;
			case 'p':
				esl_set_string(temp_pass, optarg);
				argv_pass = 1;
				break;
			case 'd':
				temp_log=atoi(optarg);
				if (temp_log < 0 || temp_log > 7) {
					printf("ERROR: Debug level should be 0 - 7.\n");
					argv_error = 1;
				} else {
					esl_global_set_default_logger(temp_log);
				}
				break;
			case 'x':
				argv_exec = 1;
				esl_set_string(argv_command, optarg);
				break;
			case 'l':
				esl_set_string(argv_loglevel, optarg);
				break;
			case 'U':
				argv_log_uuid = 1;
				break;
			case 'q':
				argv_quiet = 1;
				break;
			case 'b':
				argv_batch = 1;
				break;
			case 'i':
				allow_ctl_c = 1;
				break;
			case 'r':
				loops += 120;
				break;
			case 'R':
				reconnect = 1;
				break;
			case 't':
				timeout = atoi(optarg);
				break;
			case 'T':
				connect_timeout = atoi(optarg);
				break;
			case 'h':
			case '?':
				print_banner(stdout, is_color);
				usage(argv[0]);
				return 0;
		}
	}
	if (argv_error) {
		printf("\n");
		return usage(argv[0]);
	}
	read_config(dft_cfile, cfile);
	if (optind < argc) {
		get_profile(argv[optind], &profile);
	}
	if (!profile) {
		if (get_profile("default", &profile)) {
			esl_log(ESL_LOG_DEBUG, "profile default does not exist using builtin profile\n");
			profile = &internal_profile;
		}
	}
	if (temp_log < 0 ) {
		esl_global_set_default_logger(profile->debug);
	}
	if (argv_host) {
		esl_set_string(profile->host, temp_host);
	}
	if (argv_port) {
		profile->port = (esl_port_t)temp_port;
	}
	if (argv_user) {
		esl_set_string(profile->user, temp_user);
	}
	if (argv_pass) {
		esl_set_string(profile->pass, temp_pass);
	}
	if (argv_batch || profile->batch_mode) {
		profile->batch_mode = 1;
		feature_level=0;
	}
	if (*argv_loglevel) {
		esl_set_string(profile->loglevel, argv_loglevel);
		profile->quiet = 0;
	}
	if (argv_log_uuid) {
		profile->log_uuid = 1;
	}
	esl_log(ESL_LOG_DEBUG, "Using profile %s [%s]\n", profile->name, profile->host);
	esl_set_string(prompt_color, profile->prompt_color);
	esl_set_string(input_text_color, profile->input_text_color);
	esl_set_string(output_text_color, profile->output_text_color);
	if (argv_host) {
		if (argv_port && profile->port != 8021) {
			snprintf(bare_prompt_str, sizeof(bare_prompt_str), "freeswitch@%s:%u@%s> ", profile->host, profile->port, profile->name);
		} else {
			snprintf(bare_prompt_str, sizeof(bare_prompt_str), "freeswitch@%s@%s> ", profile->host, profile->name);
		}
	} else {
		snprintf(bare_prompt_str, sizeof(bare_prompt_str), "freeswitch@%s> ", profile->name);
	}
	bare_prompt_str_len = (int)strlen(bare_prompt_str);
	if (feature_level) {
		snprintf(prompt_str, sizeof(prompt_str), "%s%s%s", prompt_color, bare_prompt_str, input_text_color);
	} else {
		snprintf(prompt_str, sizeof(prompt_str), "%s", bare_prompt_str);
	}
 connect:
	connected = 0;
	while (--loops > 0) {
		memset(&handle, 0, sizeof(handle));
		if (esl_connect_timeout(&handle, profile->host, profile->port, profile->user, profile->pass, connect_timeout)) {
			esl_global_set_default_logger(7);
			esl_log(ESL_LOG_ERROR, "Error Connecting [%s]\n", handle.err);
			if (loops == 1) {
				if (!argv_exec) usage(argv[0]);
				return -1;
			} else {
				sleep_s(1);
				esl_log(ESL_LOG_INFO, "Retrying\n");
			}
		} else {
			connected = 1;
			if (temp_log < 0 ) {
				esl_global_set_default_logger(profile->debug);
			} else {
				esl_global_set_default_logger(temp_log);
			}
			break;
		}
	}
	if (argv_exec) {
		const char *err = NULL;
		snprintf(cmd_str, sizeof(cmd_str), "api %s\nconsole_execute: true\n\n", argv_command);
		if (timeout) {
			esl_status_t status = esl_send_recv_timed(&handle, cmd_str, timeout);
			if (status != ESL_SUCCESS) {
				printf("Request timed out.\n");
				esl_disconnect(&handle);
				return -2;
			}
		} else {
			esl_send_recv(&handle, cmd_str);
		}
		if (handle.last_sr_event) {
			if (handle.last_sr_event->body) {
				printf("%s\n", handle.last_sr_event->body);
			} else if ((err = esl_event_get_header(handle.last_sr_event, "reply-text")) && !strncasecmp(err, "-err", 3)) {
				printf("Error: %s!\n", err + 4);
			}
		}
		esl_disconnect(&handle);
		return 0;
	}
	global_handle = &handle;
	global_profile = profile;

	if (esl_thread_create_detached(msg_thread_run, &handle) != ESL_SUCCESS) {
		printf("Error starting thread!\n");
		esl_disconnect(&handle);
		return 0;
	}

#ifdef HAVE_EDITLINE
	el = el_init(__FILE__, stdin, stdout, stderr);
	el_set(el, EL_PROMPT, &prompt);
	el_set(el, EL_EDITOR, "emacs");

	el_set(el, EL_ADDFN, "f1-key", "F1 KEY PRESS", console_f1key);
	el_set(el, EL_ADDFN, "f2-key", "F2 KEY PRESS", console_f2key);
	el_set(el, EL_ADDFN, "f3-key", "F3 KEY PRESS", console_f3key);
	el_set(el, EL_ADDFN, "f4-key", "F4 KEY PRESS", console_f4key);
	el_set(el, EL_ADDFN, "f5-key", "F5 KEY PRESS", console_f5key);
	el_set(el, EL_ADDFN, "f6-key", "F6 KEY PRESS", console_f6key);
	el_set(el, EL_ADDFN, "f7-key", "F7 KEY PRESS", console_f7key);
	el_set(el, EL_ADDFN, "f8-key", "F8 KEY PRESS", console_f8key);
	el_set(el, EL_ADDFN, "f9-key", "F9 KEY PRESS", console_f9key);
	el_set(el, EL_ADDFN, "f10-key", "F10 KEY PRESS", console_f10key);
	el_set(el, EL_ADDFN, "f11-key", "F11 KEY PRESS", console_f11key);
	el_set(el, EL_ADDFN, "f12-key", "F12 KEY PRESS", console_f12key);
	el_set(el, EL_ADDFN, "EOF-key", "EOF (^D) KEY PRESS", console_eofkey);

	el_set(el, EL_BIND, "\033OP", "f1-key", NULL);
	el_set(el, EL_BIND, "\033OQ", "f2-key", NULL);
	el_set(el, EL_BIND, "\033OR", "f3-key", NULL);
	el_set(el, EL_BIND, "\033OS", "f4-key", NULL);
	el_set(el, EL_BIND, "\033OT", "f5-key", NULL);
	el_set(el, EL_BIND, "\033OU", "f6-key", NULL);
	el_set(el, EL_BIND, "\033OV", "f7-key", NULL);
	el_set(el, EL_BIND, "\033OW", "f8-key", NULL);
	el_set(el, EL_BIND, "\033OX", "f9-key", NULL);
	el_set(el, EL_BIND, "\033OY", "f10-key", NULL);
	el_set(el, EL_BIND, "\033OZ", "f11-key", NULL);
	el_set(el, EL_BIND, "\033O[", "f12-key", NULL);

	el_set(el, EL_BIND, "\033[11~", "f1-key", NULL);
	el_set(el, EL_BIND, "\033[12~", "f2-key", NULL);
	el_set(el, EL_BIND, "\033[13~", "f3-key", NULL);
	el_set(el, EL_BIND, "\033[14~", "f4-key", NULL);
	el_set(el, EL_BIND, "\033[15~", "f5-key", NULL);
	el_set(el, EL_BIND, "\033[17~", "f6-key", NULL);
	el_set(el, EL_BIND, "\033[18~", "f7-key", NULL);
	el_set(el, EL_BIND, "\033[19~", "f8-key", NULL);
	el_set(el, EL_BIND, "\033[20~", "f9-key", NULL);
	el_set(el, EL_BIND, "\033[21~", "f10-key", NULL);
	el_set(el, EL_BIND, "\033[23~", "f11-key", NULL);
	el_set(el, EL_BIND, "\033[24~", "f12-key", NULL);

	el_set(el, EL_BIND, "\004", "EOF-key", NULL);

	el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
	el_set(el, EL_BIND, "^I", "ed-complete", NULL);

	/* "Delete" key. */
	el_set(el, EL_BIND, "\033[3~", "ed-delete-next-char", NULL);

	if (!(myhistory = history_init())) {
		esl_log(ESL_LOG_ERROR, "history could not be initialized\n");
		goto done;
	}
	history(myhistory, &ev, H_SETSIZE, 800);
	el_set(el, EL_HIST, history, myhistory);
	history(myhistory, &ev, H_LOAD, hfile);
	el_source(el, NULL);
#endif
#ifdef WIN32
	hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
	if (hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
		wOldColorAttrs = csbiInfo.wAttributes;
	}
#endif
	if (!argv_quiet && !profile->quiet) {
		snprintf(cmd_str, sizeof(cmd_str), "log %s\n\n", profile->loglevel);
		esl_send_recv(&handle, cmd_str);
	}
	if (global_profile->batch_mode) {
		setvbuf(stdout, (char*)NULL, _IONBF, 0);
	}
	print_banner(stdout, is_color);
	esl_log(ESL_LOG_INFO, "FS CLI Ready.\nenter /help for a list of commands.\n");
	output_printf("%s\n", handle.last_sr_reply);
	while (running > 0) {
		int r;
#ifdef HAVE_EDITLINE
		if (!(global_profile->batch_mode)) {
			line = el_gets(el, &count);
		} else {
#endif
		line = basic_gets(&count);
#ifdef HAVE_EDITLINE
		}
#endif
		if (count > 1 && !esl_strlen_zero(line)) {
			char *p, *cmd = strdup(line);
			assert(cmd);
			if ((p = strrchr(cmd, '\r')) || (p = strrchr(cmd, '\n'))) {
				*p = '\0';
			}
#ifdef HAVE_EDITLINE
			history(myhistory, &ev, H_ENTER, line);
#endif
			if ((r = process_command(&handle, cmd))) {
				running = r;
			}
			free(cmd);
			clear_el_buffer();
		}
		sleep_ms(1);
	}
	if (running < 0 && reconnect) {
		running = 1;
		loops = 120;
		goto connect;
	}
#ifdef HAVE_EDITLINE
 done:
	history(myhistory, &ev, H_SAVE, hfile);
	history_end(myhistory);
	el_end(el);
#endif
	esl_disconnect(&handle);
	global_handle = NULL;
	thread_running = 0;
	return 0;
}