int GetPrinterSettings( cups_option_t *p_cups_opt, int num_opt, ParamList **p_list, int *listNum ) { char *p_ppd_name = getenv("PPD"); ppd_file_t *p_ppd; ppd_choice_t *p_choice; int result = -1; PpdToOptKey *p_opt_key_table = alloc_opt_key_table(p_ppd_name); PpdToOptKey *p_table = p_opt_key_table; int numCnt = 0; char choice[BUF_SIZE]; ParamList *local_p_list = NULL; static const char *libpath; if ( (p_cups_opt == NULL) || (listNum == NULL) ) goto onErr; *listNum = 0; DEBUG_PRINT2( "DEBUG:[rastertocanonij] PPD Path(%s)\n", p_ppd_name ); if ( (p_ppd = ppdOpenFile( p_ppd_name )) == NULL ) goto onErr; ppdMarkDefaults(p_ppd); cupsMarkOptions(p_ppd, num_opt, p_cups_opt); /* add libpath */ libpath = GetExecProgPath(); if ( libpath != NULL ){ param_list_add( &local_p_list, "--filterpath", libpath, strlen(libpath) + 1 ); } while( p_table->ppd_key != NULL ){ p_choice = ppdFindMarkedChoice( p_ppd, p_table->ppd_key ); if ( p_choice ) { DEBUG_PRINT3( "DEBUG:[rastertocanonij] OPTION(%s) / VALUE(%s)\n", p_table->ppd_key, p_choice->choice ); } else { DEBUG_PRINT2( "DEBUG:[rastertocanonij] OPTION(%s) / VALUE(novalue)\n", p_table->ppd_key ); } if ( p_choice != NULL ){ strcpy( choice, p_choice->choice ); //to_lower_except_size_X(choice); param_list_add( &local_p_list, p_table->opt_key, choice, strlen(choice) + 1 ); numCnt++; } p_table++; } *listNum = numCnt; *p_list = local_p_list; result = 0; onErr: return result; }
static int DumpSettings( CNCL_P_SETTINGS *pSettings ) { int result = -1; DEBUG_PRINT( "[tocanonij] !!!----------------------!!!\n" ); DEBUG_PRINT2( "[tocanonij] papersize : %d\n", pSettings->papersize ); DEBUG_PRINT2( "[tocanonij] mediatype : %d\n", pSettings->mediatype ); DEBUG_PRINT2( "[tocanonij] borderlessprint : %d\n", pSettings->borderlessprint ); DEBUG_PRINT2( "[tocanonij] colormode : %d\n", pSettings->colormode ); DEBUG_PRINT2( "[tocanonij] duplexprint : %d\n", pSettings->duplexprint ); DEBUG_PRINT( "[tocanonij] !!!----------------------!!!\n" ); result = 0; return result; }
/** * Externalize (non-leaving) the contents of the Alarm Server backup * to the backup file. */ TInt CASSrvAlarmStore::Externalize() { TInt error = KErrNone; #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT if (!iServerWideData.ServerIsReadOnly()) { #endif DEBUG_PRINT1(_L("> Alarm Store Externalize")); // tell Alarm Queue what type of Store operation we want to perform error = ServerWideData().Queue().StartAlarmStoreOperation(CASSrvAlarmQueue::EStoreExternalize); if (!error) { TRAP(error, ExternalizeL()); // tell alarm queue that Externalize is complete ServerWideData().Queue().EndAlarmStoreOperation(error); } DEBUG_PRINT2(_L("< Alarm Store Externalize - error %i"), error); #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT } #endif return error; }
/** * Internalize (non-leaving) the contents of the Alarm Server backup * from the backup file. */ TInt CASSrvAlarmStore::Internalize(CASSrvAlarmQueue::TStoreOperation aInternalizeOperation) { TInt error = KErrNone; DEBUG_PRINT1(_L("> Alarm Store Internalize ()")); // tell Alarm Queue what type of Internalize to perform error = ServerWideData().Queue().StartAlarmStoreOperation(aInternalizeOperation); if (!error) { // don't watch for change notifications during Internalize iFlags.Set(EIsInternalizing); TRAP(error, InternalizeL()); // tell alarm queue that Internalize is complete ServerWideData().Queue().EndAlarmStoreOperation(error); // Finished Internalize, Look for notifications again, etc... iFlags.Clear(EIsInternalizing); } DEBUG_PRINT2(_L("< Alarm Store Internalize - error %i"), error); return error; }
static int GetOptionBufSize( ParamList *p_list ) { int result = -1; int key_len, val_len; int total_len = 0; if ( p_list == NULL ) goto onErr; /* topwg */ total_len += strlen( TOPWG_PATH ) + 1 + strlen( TOPWG_BIN ) + 1; /* pipe */ total_len += 2; /* tocnij */ total_len += strlen( TOCNIJ_PATH ) + 1 + strlen( TOCNIJ_BIN ) + 1; while( p_list != NULL ) { key_len = strlen( p_list->key ); val_len = strlen( p_list->value ); DEBUG_PRINT2( "DEBUG:[rastertocanonij] key : %s\n", p_list->key ); DEBUG_PRINT2( "DEBUG:[rastertocanonij] val : %s\n", p_list->value ); total_len += (key_len + 1 + val_len + 1); p_list = p_list->next; } /* teminate */ total_len += 1; /* toriaezu */ total_len *= 2; result = total_len; DEBUG_PRINT2( "DEBUG:[rastertocanonij] total_len %d\n", total_len ); onErr: return result; }
/** * Externalize (non-leaving) the contents of the Alarm Server backup * to the backup file. */ TInt CASSrvAlarmStore::ExternalizeIfRequested() { TInt error = KErrNone; DEBUG_PRINT2(_L("= Alarm Store Externalize If Requested (%u)"), iFlags.IsSet(ERequestExternalize)); if (iFlags.IsSet(ERequestExternalize)) { // Don't RunL Cancel(); error = Externalize(); } return error; }
t_uint32 ThreadImpl::ThreadFuncInstance(void *param) { try{ ThreadCallBackAbs *ptcb = (ThreadCallBackAbs*)param; ptcb->Run(); delete ptcb; }catch(const std::exception &expt) { DEBUG_PRINT2("Thread %ld has unhandled exception %s\n", ::GetCurrentThreadId(), expt.what()); assert(0); } return 0; }
bool InConnValidator::check_connection_handshake() { assert(m_buf.Size() == 68); PeerID remote_peer_id; if(parse_handshake_info(m_buf.Data(), m_infohash, remote_peer_id, m_ext_info)) { DownloaderInfo dl_info; if(m_res_manager.GetDownloaderRecorder().GetRecord(m_infohash, dl_info)) { if(dl_info.peer_id == remote_peer_id) { DEBUG_PRINT0("InConnValidator::remote peer id equal to local\n"); NetSpace::InetAddress addr; m_stream_sock.GetLocalAddr(addr);//因为这个很可能是自己,反正无论如何也要band m_res_manager.GetIPFilter().BandAddress(addr.Str(), addr.Port()); DEBUG_PRINT2("InConnValidator::check_connection_handshake : band peer entry == %s:%d\n", addr.Str().c_str(), addr.Port()); return false; } m_task_id = dl_info.task_id; m_infohash = dl_info.info_hash; m_peer_id = remote_peer_id; m_buf.Clear(); m_buf.Insert(&build_hand_shake(m_infohash, dl_info.peer_id)[0], 68); assert(m_buf.Size() == 68); return true; }else { DEBUG_PRINT0("unknow infohash\n"); return false; } }else { DEBUG_PRINT0("parse_handshake_info failed\n"); return false; } }
void CASSrvAlarmStore::ScheduleExternalizeWithRetry(TUint /*aTimeMS*/) #endif { // make sure change isn't due to Internalize if (iFlags.IsClear(EIsInternalizing)) { DEBUG_PRINT2(_L("*** Schedule Externalize - IsActive() = %u"), IsActive()); iFlags.Set(ERequestExternalize); iNumberOfAttemptedRetries = 0; #ifndef __WINC__ // set the time to RunL iff not already set to run // check that no Backup or Restore is in progress, if (!iBackupNotification->BackupInProgress() && !iBackupNotification->RestoreInProgress()&& !IsActive()) { // schedule the actual Externalize After(aTimeMS * 1000); } #endif } }
SizeToPrintArea *alloc_size_to_print_area_table(char *ppd_name) { FILE *fp = fopen(ppd_name, "r"); SizeToPrintArea *p_table_top = NULL; SizeToPrintArea *p_table; long mem_size = 0; char line_buf[LINE_BUF_SIZE]; if( fp != NULL ) { int opt_num = 0; while( read_line(fp, line_buf, LINE_BUF_SIZE) >= 0 ) { if( line_buf[0] == '*' && line_buf[1] == '%' ) { if( !strcmp(strtok(line_buf, " "), "*%CNSizeToPrintArea") ) opt_num++; } } DEBUG_PRINT2( "DEBUG:[rastertocanonij] opt_num : opt_num:%d\n",opt_num ); mem_size = sizeof(SizeToPrintArea) * (opt_num + 1); p_table_top = p_table = (SizeToPrintArea*)malloc( mem_size ); memset( p_table, 0x00, mem_size ); if( p_table_top != NULL ) { rewind(fp); while( read_line(fp, line_buf, LINE_BUF_SIZE) >= 0 ) { if( line_buf[0] == '*' && line_buf[1] == '%' ) { if( !strcmp(strtok(line_buf, " "), "*%CNSizeToPrintArea") ) { char *size_key = strtok(NULL, " "); long w = atol( strtok(NULL, " ") ); long h = atol( strtok(NULL, " ") ); if( (size_key != NULL) && (w != 0) && (h != 0) ) { int size_len = strlen(size_key) + 1; p_table->size_key = (char*)malloc(size_len); if( p_table->size_key != NULL ) { //strcpy(p_table->size_key, size_key); strncpy(p_table->size_key, size_key, size_len); p_table->size_key[size_len -1] = '\0'; p_table->width = w; p_table->height = h; p_table++; } } } } } p_table->size_key = NULL; p_table->width = 0; p_table->height = 0; } fclose(fp); } return p_table_top; }
/************************************************************************** * * Handles low level ACI events, and passes them up to an application * level callback when appropriate * **************************************************************************/ void GoosciBleGatt::pollACI() { static bool setup_required = false; // We enter the if statement only when there is a ACI event // available to be processed if (lib_aci_event_get(&aci_state, &aci_data)) { aci_evt_t *aci_evt; aci_evt = &aci_data.evt; // DEBUG_PRINTLN(F("pollACI")); // DEBUG_PRINT("evt opcode: "); // DEBUG_PRINTLN2(aci_evt->evt_opcode, HEX); // DEBUG_PRINT(F("State Total credit: ")); // DEBUG_PRINTLN(aci_state.data_credit_total); // DEBUG_PRINT(F("State Available credit: ")); // DEBUG_PRINTLN(aci_state.data_credit_available); // DEBUG_PRINT("Event Available credit: "); // DEBUG_PRINTLN(aci_evt->params.device_started.credit_available); switch (aci_evt->evt_opcode) { case ACI_EVT_DEVICE_STARTED: { // DEBUG_PRINTLN("STARTED"); aci_state.data_credit_total = aci_evt->params.device_started.credit_available; switch (aci_evt->params.device_started.device_mode) { case ACI_DEVICE_SETUP: { // DEBUG_PRINTLN("SETUP"); aci_state.device_state = ACI_DEVICE_SETUP; setup_required = true; break; } case ACI_DEVICE_STANDBY: { // DEBUG_PRINTLN("STANDBY"); aci_state.device_state = ACI_DEVICE_STANDBY; // sleep_to_wakeup_timeout = 30; if (aci_evt->params.device_started.hw_error) { // Magic number used to make sure the HW error // event is handled correctly. delay(20); } else { get_address(); // DEBUG_PRINTLN("lib_aci_connect"); lib_aci_connect(adTimeout, adInterval); } break; } case ACI_DEVICE_INVALID: { DEBUG_PRINTLN(F("Evt Device Invalid")); break; } case ACI_DEVICE_TEST: { break; } case ACI_DEVICE_SLEEP: { break; } } break; // case ACI_EVT_DEVICE_STARTED: } case ACI_EVT_CMD_RSP: { DEBUG_PRINTLN("ACI_EVT_CMD_RSP"); // If an ACI command response event comes with an error -> stop if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) { // ACI ReadDynamicData and ACI WriteDynamicData // will have status codes of // TRANSACTION_CONTINUE and TRANSACTION_COMPLETE // all other ACI commands will have status code of // ACI_STATUS_SCUCCESS for a successful command DEBUG_PRINT(F("ACI Command 0x")); DEBUG_PRINTLN2(aci_evt->params.cmd_rsp.cmd_opcode, HEX); DEBUG_PRINT(F("Evt Cmd response: Error. ")); DEBUG_PRINTLN2(aci_evt->params.cmd_rsp.cmd_status, HEX); } if (ACI_CMD_GET_DEVICE_ADDRESS == aci_evt->params.cmd_rsp.cmd_opcode) { // If this is a response to get device address, save the address addrReceived = true; // DEBUG_PRINT(F("Get device address response: ")); for (int i = BTLE_DEVICE_ADDRESS_SIZE - 1; i >= 0; --i) { deviceAddress[i] = aci_evt->params.cmd_rsp.params.get_device_address .bd_addr_own[i]; // DEBUG_PRINT2(deviceAddress[i], HEX); // DEBUG_PRINT(F(":")); } // DEBUG_PRINTLN(F("")); } else if (ACI_CMD_OPEN_ADV_PIPE == aci_evt->params.cmd_rsp.cmd_opcode) { DEBUG_PRINTLN( F("Open advertising pipe response, setting service data.")); lib_aci_set_local_data( &aci_state, PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_BROADCAST, (unsigned char *)longName, 8); DEBUG_PRINT(F("Advertising starting for ")); DEBUG_PRINTLN(deviceName); lib_aci_connect(adTimeout, adInterval); } else if (ACI_CMD_GET_DEVICE_VERSION == aci_evt->params.cmd_rsp.cmd_opcode) { DEBUG_PRINTLN("ACI_CMD_GET_DEVICE_VERSION"); } else if (ACI_CMD_SET_LOCAL_DATA == aci_evt->params.cmd_rsp.cmd_opcode) { DEBUG_PRINTLN("ACI_CMD_SET_LOCAL_DATA"); } else if (ACI_CMD_CONNECT == aci_evt->params.cmd_rsp.cmd_opcode) { DEBUG_PRINTLN("ACI_CMD_CONNECT"); } else if (ACI_CMD_DISCONNECT == aci_evt->params.cmd_rsp.cmd_opcode) { DEBUG_PRINTLN("ACI_CMD_DISCONNECT"); } else if (ACI_CMD_CHANGE_TIMING == aci_evt->params.cmd_rsp.cmd_opcode) { DEBUG_PRINTLN("ACI_CMD_CHANGE_TIMING"); } else { // print command DEBUG_PRINT(F("Unexpected ACI Command 0x")); DEBUG_PRINTLN2(aci_evt->params.cmd_rsp.cmd_opcode, HEX); } break; } case ACI_EVT_CONNECTED: { // The nRF8001 is now connected to the peer device. DEBUG_PRINTLN(F("Evt Connected")); aci_state.data_credit_available = aci_state.data_credit_total; timing_change_done = false; break; } case ACI_EVT_PIPE_STATUS: { DEBUG_PRINTLN(F("Evt Pipe Status: ")); // DEBUG_PRINT2((int) aci_evt->params.pipe_status.pipes_open_bitmap, HEX); // DEBUG_PRINT(" "); // DEBUG_PRINTLN2((int) aci_evt->params.pipe_status.pipes_closed_bitmap, HEX); if (lib_aci_is_pipe_available(&aci_state, PIPE_GOOSCI_SENSOR_VALUE_TX) && !timing_change_done) { lib_aci_change_timing(6, 6, 0, 600); // Low-latency parameters timing_change_done = true; } break; } case ACI_EVT_TIMING: { // DEBUG_PRINT("ACI_EVT_TIMING: "); // DEBUG_PRINT(aci_evt->params.timing.conn_rf_interval); // DEBUG_PRINT(" "); // DEBUG_PRINT(aci_evt->params.timing.conn_slave_rf_latency); // DEBUG_PRINT(" "); // DEBUG_PRINT(aci_evt->params.timing.conn_rf_timeout); // DEBUG_PRINT(" "); // DEBUG_PRINTLN(aci_evt->params.timing.conn_rf_interval); break; } case ACI_EVT_DISCONNECTED: { // Advertise again if the advertising timed out. DEBUG_PRINTLN(F("Evt Disconnected.")); // TODO(dek): figure out why the transition to using credits // broke disconnection (packets are still transmitted). // Setting the credits to 0 was an experiment but it didn't work. // aci_state.data_credit_available = 0; lib_aci_connect(adTimeout, adInterval); timing_change_done = false; break; } case ACI_EVT_DATA_RECEIVED: { DEBUG_PRINTLN("ACI_EVT_DATA_RECEIVED"); if (aci_evt->params.data_received.rx_data.pipe_number == PIPE_GOOSCI_SENSOR_CONFIGURATION_RX_ACK_AUTO) { int8_t packet_length = aci_evt->len; handle(aci_evt->params.data_received.rx_data.aci_data, aci_evt->len); } else { DEBUG_PRINT(F(" Data(Hex) : ")); for (int i = 0; i < aci_evt->len - 2; i++) { DEBUG_PRINT2(aci_evt->params.data_received.rx_data.aci_data[i], HEX); DEBUG_PRINT(F(" ")); } DEBUG_PRINTLN(F("")); } break; } case ACI_EVT_DATA_CREDIT: { // DEBUG_PRINTLN(F("Evt Credit: Peer has received our send")); aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit; break; } case ACI_EVT_PIPE_ERROR: { // See the appendix in the nRF8001 // Product Specication for details on the error codes DEBUG_PRINT(F("ACI Evt Pipe Error: Pipe #:")); DEBUG_PRINT2(aci_evt->params.pipe_error.pipe_number, DEC); DEBUG_PRINT(F(" Pipe Error Code: 0x")); DEBUG_PRINTLN2(aci_evt->params.pipe_error.error_code, HEX); // Increment the credit available as the data packet was not sent. // The pipe error also represents the Attribute protocol // Error Response sent from the peer and that should not be counted // for the credit. if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code) { aci_state.data_credit_available++; } break; } case ACI_EVT_DATA_ACK: { // DEBUG_PRINTLN(F("ACK")); break; } case ACI_EVT_HW_ERROR: { DEBUG_PRINTLN(F("HW error: ")); DEBUG_PRINTLN2(aci_evt->params.hw_error.line_num, DEC); for (int counter = 0; counter <= (aci_evt->len - 3); counter++) { DEBUG_PRINT(aci_evt->params.hw_error.file_name[counter]); } DEBUG_PRINTLN(); initLocalData(); lib_aci_connect(adTimeout, adInterval); break; } default: { DEBUG_PRINT(F("Evt Opcode 0x")); DEBUG_PRINT2(aci_evt->evt_opcode, HEX); DEBUG_PRINTLN(F(" unhandled")); break; } } } // setup_required is set to true when the device starts // up and enters setup mode. // It indicates that do_aci_setup() should be called. // The flag should be cleared if do_aci_setup() returns // ACI_STATUS_TRANSACTION_COMPLETE. if (setup_required) { int result = do_aci_setup(&aci_state); if (result != SETUP_SUCCESS ) { switch(result) { case SETUP_FAIL_COMMAND_QUEUE_NOT_EMPTY: DEBUG_PRINTLN("SETUP_FAIL_COMMAND_QUEUE_NOT_EMPTY"); break; case SETUP_FAIL_EVENT_QUEUE_NOT_EMPTY: DEBUG_PRINTLN("SETUP_EVENT_COMMAND_QUEUE_NOT_EMPTY"); break; case SETUP_FAIL_NOT_SETUP_EVENT: DEBUG_PRINTLN("SETUP_FAIL_NOT_SETUP_EVENT"); break; case SETUP_FAIL_NOT_COMMAND_RESPONSE: DEBUG_PRINTLN("SETUP_FAIL_NOT_COMMAND_RESPONSE"); break; } } else { setup_required = false; } } }
int main( int argc, char *argv[] ) { int fd = 0; int opt, opt_index; int result = -1; long bufSize = 0; // long writtenSize; int writtenSize = 0; long writtenSize_long = 0; char *bufTop = NULL; CNCL_P_SETTINGS Settings; char jobID[CN_START_JOBID_LEN]; char libPathBuf[CN_LIB_PATH_LEN]; void *libclss = NULL; struct option long_opt[] = { { "version", required_argument, NULL, OPT_VERSION }, { "filterpath", required_argument, NULL, OPT_FILTERPATH }, { "papersize", required_argument, NULL, OPT_PAPERSIZE }, { "mediatype", required_argument, NULL, OPT_MEDIATYPE }, { "grayscale", required_argument, NULL, OPT_COLORMODE }, { "duplexprint", required_argument, NULL, OPT_DUPLEXPRINT }, { "jobid", required_argument, NULL, OPT_JOBID }, { "uuid", required_argument, NULL, OPT_UUID }, { 0, 0, 0, 0 }, }; const char *p_ppd_name = getenv("PPD"); uint8_t *xmlBuf = NULL; int xmlBufSize; int retSize; char *tmpBuf = NULL; char uuid[UUID_LEN + 1]; DEBUG_PRINT( "[tocanonij] start tocanonij\n" ); /* init CNCL API */ GETSETCONFIGURATIONCOMMAND = NULL; GETSENDDATAPWGRASTERCOMMAND = NULL; GETPRINTCOMMAND = NULL; GETSTRINGWITHTAGFROMFILE = NULL; GETSETPAGECONFIGUARTIONCOMMAND = NULL; MAKEBJLSETTIMEJOB = NULL; GetProtocol = NULL; ParseCapabilityResponsePrint_HostEnv=NULL; MakeCommand_StartJob3 = NULL; ParseCapabilityResponsePrint_DateTime = NULL; MakeCommand_SetJobConfiguration = NULL; /* Init Settings */ memset( &Settings, 0x00, sizeof(CNCL_P_SETTINGS) ); InitpSettings( &Settings ); memset( uuid, '\0', sizeof(uuid) ); while( (opt = getopt_long( argc, argv, "0:", long_opt, &opt_index )) != -1) { switch( opt ) { case OPT_VERSION: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); break; case OPT_FILTERPATH: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); snprintf( libPathBuf, CN_LIB_PATH_LEN, "%s%s", optarg, CN_CNCL_LIBNAME ); break; case OPT_PAPERSIZE: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); Settings.papersize = ConvertStrToID( optarg, papersizeTbl ); if ( IsBorderless( optarg ) ){ Settings.borderlessprint = CNCL_PSET_BORDERLESS_ON; } else { Settings.borderlessprint = CNCL_PSET_BORDERLESS_OFF; } break; case OPT_MEDIATYPE: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); Settings.mediatype = ConvertStrToID( optarg, mediatypeTbl ); DEBUG_PRINT2( "[tocanonij] media : %d\n", Settings.mediatype ); break; #if 0 case OPT_BORDERLESSPRINT: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); if ( IsBorderless( optarg ) ){ Settings.borderlessprint = CNCL_PSET_BORDERLESS_ON; } else { Settings.borderlessprint = CNCL_PSET_BORDERLESS_OFF; } break; #endif case OPT_COLORMODE: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); Settings.colormode = ConvertStrToID( optarg, colormodeTbl ); break; case OPT_DUPLEXPRINT: DEBUG_PRINT3( "[tocanonij] OPTION(%s):VALUE(%s)\n", long_opt[opt_index].name, optarg ); //Settings.duplexprint = CNCL_PSET_DUPLEX_OFF; Settings.duplexprint = ConvertStrToID( optarg, duplexprintTbl); break; case OPT_UUID: strncpy( uuid, optarg, strlen(optarg) ); break; case OPT_JOBID: if( strlen( uuid ) == 0 ){ strncpy( uuid, optarg, strlen(optarg) ); } break; case '?': fprintf( stderr, "Error: invalid option %c:\n", optopt); break; default: break; } } /* dlopen */ /* Make progamname with path of execute progname. */ //snprintf( libPathBuf, CN_LIB_PATH_LEN, "%s%s", GetExecProgPath(), CN_CNCL_LIBNAME ); DEBUG_PRINT2( "[tocanonij] libPath : %s\n", libPathBuf ); if ( access( libPathBuf, R_OK ) ){ strncpy( libPathBuf, CN_CNCL_LIBNAME, CN_LIB_PATH_LEN ); } DEBUG_PRINT2( "[tocanonij] libPath : %s\n", libPathBuf ); libclss = dlopen( libPathBuf, RTLD_LAZY ); if ( !libclss ) { fprintf( stderr, "Error in dlopen\n" ); goto onErr1; } GETSETCONFIGURATIONCOMMAND = dlsym( libclss, "CNCL_GetSetConfigurationCommand" ); if ( dlerror() != NULL ) { fprintf( stderr, "Error in CNCL_GetSetConfigurationCommand. API not Found.\n" ); goto onErr2; } GETSENDDATAPWGRASTERCOMMAND = dlsym( libclss, "CNCL_GetSendDataPWGRasterCommand" ); if ( dlerror() != NULL ) { fprintf( stderr, "Error in CNCL_GetSendDataPWGRasterCommand\n" ); goto onErr2; } GETPRINTCOMMAND = dlsym( libclss, "CNCL_GetPrintCommand" ); if ( dlerror() != NULL ) { fprintf( stderr, "Error in CNCL_GetPrintCommand\n" ); goto onErr2; } GETSTRINGWITHTAGFROMFILE = dlsym( libclss, "CNCL_GetStringWithTagFromFile" ); if ( dlerror() != NULL ) { fprintf( stderr, "Error in CNCL_GetStringWithTagFromFile\n" ); goto onErr2; } GETSETPAGECONFIGUARTIONCOMMAND = dlsym( libclss, "CNCL_GetSetPageConfigurationCommand" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_GetSetPageConfigurationCommand\n" ); goto onErr2; } MAKEBJLSETTIMEJOB = dlsym( libclss, "CNCL_MakeBJLSetTimeJob" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_MakeBJLSetTimeJob\n" ); goto onErr2; } GetProtocol = dlsym( libclss, "CNCL_GetProtocol" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_MakeBJLSetTimeJob\n" ); goto onErr2; } ParseCapabilityResponsePrint_HostEnv = dlsym( libclss, "CNCL_ParseCapabilityResponsePrint_HostEnv" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_ParseCapabilityResponsePrint_HostEnv\n" ); goto onErr2; } MakeCommand_StartJob3 = dlsym( libclss, "CNCL_MakeCommand_StartJob3" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_MakeCommand_StartJob3\n" ); goto onErr2; } ParseCapabilityResponsePrint_DateTime = dlsym( libclss, "CNCL_ParseCapabilityResponsePrint_DateTime" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_ParseCapabilityResponsePrint_DateTime\n" ); goto onErr2; } MakeCommand_SetJobConfiguration = dlsym( libclss, "CNCL_MakeCommand_SetJobConfiguration" ); if ( dlerror() != NULL ) { fprintf( stderr, "Load Error in CNCL_MakeCommand_SetJobConfiguration\n" ); goto onErr2; } /* Check Settings */ if ( CheckSettings( &Settings ) != 0 ) goto onErr2; #if 1 /* Dump Settings */ DumpSettings( &Settings ); #endif // const char *p_ppd_name = getenv("PPD"); CAPABILITY_DATA capability; memset(&capability, '\0', sizeof(CAPABILITY_DATA)); if( ! GetCapabilityFromPPDFile(p_ppd_name, &capability) ){ goto onErr3; } int prot = GetProtocol( (char *)capability.deviceID, capability.deviceIDLength ); if( prot == 2 ){ xmlBufSize = GETSTRINGWITHTAGFROMFILE( p_ppd_name, CNCL_FILE_TAG_CAPABILITY, (int *)CNCL_DECODE_EXEC, &xmlBuf ); unsigned short hostEnv = 0; hostEnv = ParseCapabilityResponsePrint_HostEnv( xmlBuf, xmlBufSize ); /* Set JobID */ strncpy( jobID, CN_START_JOBID2, sizeof(CN_START_JOBID2) ); /* Allocate Buffer */ bufSize = sizeof(char) * CN_BUFSIZE; if ( (bufTop = malloc( bufSize )) == NULL ) goto onErr2; /* Write StartJob Command */ int ret = 0; ret = MakeCommand_StartJob3( hostEnv, uuid, jobID, bufTop, bufSize, &writtenSize ); if ( ret != 0 ) { fprintf( stderr, "Error in CNCL_GetPrintCommand\n" ); goto onErr2; } /* WriteData */ if ( (retSize = write( 1, bufTop, writtenSize )) != writtenSize ) goto onErr2; char dateTime[15]; memset(dateTime, '\0', sizeof(dateTime)); ret = ParseCapabilityResponsePrint_DateTime( xmlBuf, xmlBufSize ); if( ret == 2 ){ time_t timer = time(NULL); struct tm *date = localtime(&timer); sprintf(dateTime, "%d%02d%02d%02d%02d%02d", date->tm_year+1900, date->tm_mon+1, date->tm_mday, date->tm_hour, date->tm_min, date->tm_sec); if ( (tmpBuf = malloc( bufSize )) == NULL ) goto onErr2; ret = MakeCommand_SetJobConfiguration( jobID, dateTime, tmpBuf, bufSize, &writtenSize ); /* WriteData */ if ( (retSize = write( 1, tmpBuf, writtenSize )) != writtenSize ) goto onErr2; // writtenSize += tmpWrittenSize; } } else{ /* Set JobID */ strncpy( jobID, CN_START_JOBID, sizeof(CN_START_JOBID) ); /* OutputSetTime */ if ( OutputSetTime( 1, jobID ) != 0 ) goto onErr2; /* Allocate Buffer */ bufSize = sizeof(char) * CN_BUFSIZE; if ( (bufTop = malloc( bufSize )) == NULL ) goto onErr2; /* Write StartJob Command */ if ( GETPRINTCOMMAND( bufTop, bufSize, &writtenSize_long, jobID, CNCL_COMMAND_START1 ) != 0 ) { fprintf( stderr, "Error in CNCL_GetPrintCommand\n" ); goto onErr2; } /* WriteData */ if ( (retSize = write( 1, bufTop, writtenSize_long )) != writtenSize_long ) goto onErr2; } /* Write SetConfiguration Command */ if ( (xmlBufSize = GETSTRINGWITHTAGFROMFILE( p_ppd_name, CNCL_FILE_TAG_CAPABILITY, (int*)CNCL_DECODE_EXEC, &xmlBuf )) < 0 ){ DEBUG_PRINT2( "[tocanonij] p_ppd_name : %s\n", p_ppd_name ); DEBUG_PRINT2( "[tocanonij] xmlBufSize : %d\n", xmlBufSize ); fprintf( stderr, "Error in CNCL_GetStringWithTagFromFile\n" ); goto onErr3; } if ( GETSETCONFIGURATIONCOMMAND( &Settings, jobID, bufSize, (void *)xmlBuf, xmlBufSize, bufTop, &writtenSize_long ) != 0 ){ fprintf( stderr, "Error in CNCL_GetSetConfigurationCommand\n" ); goto onErr3; } /* WriteData */ retSize = write( 1, bufTop, writtenSize_long ); /* Write Page Data */ while ( 1 ) { int readBytes = 0; int writeBytes; char *pCurrent; CNDATA CNData; long readSize = 0; unsigned short next_page; memset( &CNData, 0, sizeof(CNDATA) ); /* read magic number */ readBytes = read( fd, &CNData, sizeof(CNDATA) ); if ( readBytes > 0 ){ if ( CNData.magic_num != MAGIC_NUMBER_FOR_CNIJPWG ){ fprintf( stderr, "Error illeagal MagicNumber\n" ); goto onErr3; } if ( CNData.image_size < 0 ){ fprintf( stderr, "Error illeagal dataSize\n" ); goto onErr3; } } else if ( readBytes < 0 ){ if ( errno == EINTR ) continue; fprintf( stderr, "DEBUG:[tocanonij] tocnij read error, %d\n", errno ); goto onErr3; } else { DEBUG_PRINT( "DEBUG:[tocanonij] !!!DATA END!!!\n" ); break; /* data end */ } /* Write Next Page Info */ if ( CNData.next_page ) { next_page = CNCL_PSET_NEXTPAGE_ON; } else { next_page = CNCL_PSET_NEXTPAGE_OFF; } if ( GETSETPAGECONFIGUARTIONCOMMAND( jobID, next_page, bufTop, bufSize, &writtenSize_long ) != 0 ) { fprintf( stderr, "Error in CNCL_GetPrintCommand\n" ); goto onErr3; } /* WriteData */ if ( (retSize = write( 1, bufTop, writtenSize_long )) != writtenSize_long ) goto onErr3; /* Write SendData Command */ memset( bufTop, 0x00, bufSize ); readSize = CNData.image_size; if ( GETSENDDATAPWGRASTERCOMMAND( jobID, readSize, bufSize, bufTop, &writtenSize_long ) != 0 ) { DEBUG_PRINT( "Error in CNCL_GetSendDataJPEGCommand\n" ); goto onErr3; } /* WriteData */ retSize = write( 1, bufTop, writtenSize_long ); while( readSize ){ pCurrent = bufTop; if ( readSize - bufSize > 0 ){ readBytes = read( fd, bufTop, bufSize ); DEBUG_PRINT2( "[tocanonij] PASS tocanonij READ1<%d>\n", readBytes ); if ( readBytes < 0 ) { if ( errno == EINTR ) continue; } readSize -= readBytes; } else { readBytes = read( fd, bufTop, readSize ); DEBUG_PRINT2( "[tocanonij] PASS tocanonij READ2<%d>\n", readBytes ); if ( readBytes < 0 ) { if ( errno == EINTR ) continue; } readSize -= readBytes; } do { writeBytes = write( 1, pCurrent, readBytes ); DEBUG_PRINT2( "[tocanonij] PASS tocanonij WRITE<%d>\n", writeBytes ); if( writeBytes < 0){ if ( errno == EINTR ) continue; goto onErr3; } readBytes -= writeBytes; pCurrent += writeBytes; } while( writeBytes > 0 ); } } /* CNCL_GetPrintCommand */ if ( GETPRINTCOMMAND( bufTop, bufSize, &writtenSize_long, jobID, CNCL_COMMAND_END ) != 0 ) { DEBUG_PRINT( "Error in CNCL_GetPrintCommand\n" ); goto onErr3; } /* WriteData */ retSize = write( 1, bufTop, writtenSize_long ); DEBUG_PRINT( "[tocanonij] to_cnijf <end>\n" ); result = 0; onErr3: if ( xmlBuf != NULL ){ free( xmlBuf ); } onErr2: if ( bufTop != NULL ){ free( bufTop ); } onErr1: if ( libclss != NULL ) { dlclose( libclss ); } if( tmpBuf != NULL ){ free(tmpBuf); } return result; }
int main(int argc, char *argv[]) { cups_option_t *p_cups_opt = NULL; ParamList *p_list = NULL; ParamList *p_list2 = NULL; char *p_data_buf = NULL; char *cmd_buf = NULL; int cmd_buf_size = 0; struct sigaction sigact; int num_opt = 0,out_num = 0; int ifd = 0; int fds[2]; int result = -1; #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) struct sigaction action; #endif #ifdef HAVE_SIGSET sigset(SIGPIPE, SIG_IGN); #elif defined(HAVE_SIGACTION) memset(&action, 0, sizeof(action)); action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &action, NULL); #else signal(SIGPIPE, SIG_IGN); #endif /* HAVE_SIGSET */ /* register signal */ memset(&sigact, 0, sizeof(sigact)); sigact.sa_handler = sigterm_handler; if( sigaction(SIGTERM, &sigact, NULL) ) { fputs("DEBUG:[rastertocanonij] pstocanonij can't register signal hander.\n", stderr); goto onErr1; } if( argc < 6 || argc > 7 ) { fputs("DEBUG:[rastertocanonij] pstocanonij illegal parameter number.\n", stderr); goto onErr1; } if( argv[5] != NULL ) { num_opt = cupsParseOptions(argv[5], 0, &p_cups_opt); if( num_opt < 0 ) { fputs("DEBUG:[rastertocanonij] illegal option.\n", stderr); goto onErr1; } } if( g_signal_received ) goto onErr1; /* Allocate buffer to communicate */ if( (p_data_buf = (char*)malloc(DATA_BUF_SIZE)) == NULL ) goto onErr1; /* Parse Option, and get option list for tocanonij filter */ if ( GetPrinterSettings( p_cups_opt, num_opt, &p_list, &out_num ) != 0 ){ fprintf( stderr, "DEBUG:Error in GetPrinterSettings\n" ); goto onErr2; } /* Parse PPD, and get option list for tocnpwg filter */ if ( GetPrinterableAreaOptionFromPPD( ref_value_from_list(p_list, "--papersize"), &p_list2, &out_num ) != 0 ){ fprintf( stderr, "DEBUG:Error in GetPrinterableAreaOptionFromPPD\n" ); goto onErr3; } DEBUG_PRINT( "DEBUG:[rastertocanonij] rastertocanonij main <0>\n" ); /* Get BufSize */ if ( (cmd_buf_size = GetOptionBufSize( p_list )) < 0 ){ fprintf( stderr, "DEBUG:[rastertocanonij] GetOptionBufSize in Error\n" ); goto onErr4; } /* Allocate Command Buffer */ cmd_buf_size = CMD_BUF_SIZE; if ( (cmd_buf = (char *)malloc( cmd_buf_size )) == NULL ) goto onErr4; DEBUG_PRINT( "DEBUG:[rastertocanonij] rastertocanonij main <1>\n" ); /* Make execute command */ if ( MakeExecCommand( cmd_buf, cmd_buf_size, p_list, p_list2 ) != 0 ){ fprintf( stderr, "DEBUG:[rastertocanonij] MakeExecCommand in Error\n" ); goto onErr5; } DEBUG_PRINT( "DEBUG:[rastertocanonij] rastertocanonij main <2>\n" ); /* set cmd_buf here .....*/ DEBUG_PRINT2( "DEBUG:[rastertocanonij] cmd_buf : %s\n", cmd_buf ); if ( (g_filter_pid = exec_filter(cmd_buf, 1, fds)) == -1 ){ fprintf( stderr, "DEBUG:[rastertocanonij] exec_filter in Error\n" ); goto onErr5; } DEBUG_PRINT( "DEBUG:[rastertocanonij] rastertocanonij main <3>\n" ); /* WriteData */ while( !g_signal_received ) { int read_bytes = read(ifd, p_data_buf, DATA_BUF_SIZE); if ( read_bytes > 0 ) { int write_bytes; char *p_data = p_data_buf; do { write_bytes = write(fds[1], p_data, read_bytes); if( write_bytes < 0 ) { if( errno == EINTR ) continue; fprintf(stderr, "DEBUG:[rastertocanonij] pstocanonij write error,%d.\n", errno); goto onErr6; } read_bytes -= write_bytes; p_data += write_bytes; } while( !g_signal_received && read_bytes > 0 ); } else if( read_bytes < 0 ) { if( errno == EINTR ) continue; fprintf(stderr, "DEBUG:[rastertocanonij] pstocanonij read error,%d.\n", errno); goto onErr6; } else { DEBUG_PRINT( "DEBUG:[rastertocanonij] rastertocanonij main <break>\n" ); break; } } DEBUG_PRINT( "DEBUG:[rastertocanonij] rastertocanonij main <4>\n" ); result = 0; onErr6: close( fds[1] ); /* wait process */ if ( g_filter_pid != -1 ){ waitpid( g_filter_pid, NULL, 0 ); } onErr5: if( cmd_buf != NULL ){ free( cmd_buf ); } onErr4: param_list_free( p_list2 ); onErr3: param_list_free( p_list ); onErr2: if( p_data_buf != NULL ){ free( p_data_buf ); } onErr1: return result; }
static int MakeExecCommand( char *cmd_buf, int cmd_buf_size, ParamList *p_list, ParamList *p_list2 ) { int result = -1; int i; char tmp_buf[CMD_BUF_SIZE]; ParamList *list_array[2]; ParamList *p_cur; /* Set tocnpwg path */ snprintf( tmp_buf, CMD_BUF_SIZE, "%s%s", GetExecProgPath(), TOPWG_BIN ); if ( access( tmp_buf, R_OK ) ){ snprintf( tmp_buf, CMD_BUF_SIZE, "%s/%s", TOPWG_PATH, TOPWG_BIN ); if ( access( tmp_buf, R_OK ) ){ fprintf( stderr, "Not found tocnpwg\n" ); goto onErr; } } //strncpy( cmd_buf, tmp_buf, cmd_buf_size ); //cmd_buf[cmd_buf_size -1] = '\0'; strcpy( cmd_buf, tmp_buf ); /* Set tocnpwg option */ list_array[0] = p_list; list_array[1] = p_list2; for ( i=0; i<2; i++ ){ p_cur = list_array[i]; while ( p_cur != NULL ) { strcat( cmd_buf, " " ); strcat( cmd_buf, p_cur->key ); strcat( cmd_buf, " " ); strcat( cmd_buf, p_cur->value ); p_cur = p_cur->next; } } /* Set tocnij path */ snprintf( tmp_buf, CMD_BUF_SIZE, "%s%s", GetExecProgPath(), TOCNIJ_BIN ); if ( access( tmp_buf, R_OK ) ){ snprintf( tmp_buf, CMD_BUF_SIZE, "%s/%s", TOCNIJ_PATH, TOCNIJ_BIN ); if ( access( tmp_buf, R_OK ) ){ fprintf( stderr, "Not exist tocanonij\n" ); goto onErr; } } strcat( cmd_buf, " | " ); strcat( cmd_buf, tmp_buf ); /* Set tocnij option */ p_cur = list_array[0]; while ( p_cur != NULL ) { strcat( cmd_buf, " " ); strcat( cmd_buf, p_cur->key ); strcat( cmd_buf, " " ); strcat( cmd_buf, p_cur->value ); p_cur = p_cur->next; } DEBUG_PRINT2( "DEBUG:[rastertocanonij] cmd_buf%s",cmd_buf ); result = 0; onErr: return result; }