michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:expandtab:shiftwidth=4:tabstop=4: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include "XRemoteClient.h" michael@0: michael@0: static void print_usage(void); michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: nsresult rv; michael@0: XRemoteClient client; michael@0: char *browser = 0; michael@0: char *profile = 0; michael@0: char *username = 0; michael@0: char *command = 0; michael@0: michael@0: if (argc < 2) { michael@0: print_usage(); michael@0: return 4; michael@0: } michael@0: michael@0: PLOptStatus os; michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "ha:u:p:"); michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { michael@0: if (PL_OPT_BAD == os) { michael@0: print_usage(); michael@0: return 4; michael@0: } michael@0: michael@0: switch (opt->option) { michael@0: case 'h': michael@0: print_usage(); michael@0: return 4; michael@0: break; michael@0: case 'u': michael@0: username = strdup(opt->value); michael@0: break; michael@0: case 'a': michael@0: browser = strdup(opt->value); michael@0: break; michael@0: case 'p': michael@0: profile = strdup(opt->value); michael@0: break; michael@0: case 0: michael@0: command = strdup(opt->value); michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: michael@0: rv = client.Init(); michael@0: // failed to connect to the X server michael@0: if (NS_FAILED(rv)) michael@0: return 1; michael@0: michael@0: // send the command - it doesn't get any easier than this michael@0: bool success = false; michael@0: char *error = 0; michael@0: rv = client.SendCommand(browser, username, profile, command, nullptr, michael@0: &error, &success); michael@0: michael@0: // failed to send command michael@0: if (NS_FAILED(rv)) { michael@0: fprintf(stderr, "%s: Error: Failed to send command: ", argv[0]); michael@0: if (error) { michael@0: fprintf(stderr, "%s\n", error); michael@0: free(error); michael@0: } michael@0: else { michael@0: fprintf(stderr, "No error string reported..\n"); michael@0: } michael@0: michael@0: return 3; michael@0: } michael@0: michael@0: // no running window found michael@0: if (!success) { michael@0: fprintf(stderr, "%s: Error: Failed to find a running server.\n", argv[0]); michael@0: return 2; michael@0: } michael@0: michael@0: // else, everything is fine. michael@0: return 0; michael@0: } michael@0: michael@0: /* static */ michael@0: void print_usage(void) { michael@0: fprintf(stderr, "Usage: mozilla-xremote-client [-a firefox|thunderbird|mozilla|any]\n"); michael@0: fprintf(stderr, " [-u ]\n"); michael@0: fprintf(stderr, " [-p ] COMMAND\n"); michael@0: }