void CTlvEsM8Sta::write(BufferObj &theBuf) { LPLISTITR itr; CTlvCredential *pCredential; //there should be at least one credential TLV if(0 == ListGetCount(credential)) throw RPROT_ERR_REQD_TLV_MISSING; try { if(!(itr = ListItrCreate(credential))) throw WSC_ERR_OUTOFMEMORY; while((pCredential = (CTlvCredential *)ListItrGetNext(itr))) { pCredential->write(theBuf); } ListItrDelete(itr); } catch(...) { if(itr) ListItrDelete(itr); } }
void CTlvEsM8Sta::write(BufferObj &theBuf, BufferObj &authKey, bool isWirelessWPS) { LPLISTITR itr; CTlvCredential *pCredential; //there should be at least one credential TLV if(isWirelessWPS && 0 == ListGetCount(credential)) throw RPROT_ERR_REQD_TLV_MISSING; try { if (isWirelessWPS) { // skip including Credential if not in wireless WPS mode if(!(itr = ListItrCreate(credential))) throw WSC_ERR_OUTOFMEMORY; while((pCredential = (CTlvCredential *)ListItrGetNext(itr))) { pCredential->write(theBuf); } } //write the optional new password and device password ID if(new_pwd.Length()) { new_pwd.Write(theBuf); pwdId.Write(theBuf); } //calculate the hmac and append the TLV to the buffer uint8 hmac[SIZE_256_BITS]; if(HMAC(EVP_sha256(), authKey.GetBuf(), SIZE_256_BITS, theBuf.GetBuf(), theBuf.Length(), hmac, NULL) == NULL) { TUTRACE((TUTRACE_ERR, "RPROTO: Error generating HMAC\n")); throw RPROT_ERR_CRYPTO; } CTlvAuthenticator( WSC_ID_KEY_WRAP_AUTH, theBuf, hmac, SIZE_64_BITS); if (isWirelessWPS) { // itr is only valid if in wireless WPS mode ListItrDelete(itr); } } catch(...) { if(itr) ListItrDelete(itr); } }
PLISTLINK *ListGetPointers(HSLIST &hList, int &iListCount) { iListCount = ListGetCount(hList); PLISTLINK *pPointers = (PLISTLINK *) SysAlloc((iListCount + 1) * sizeof(PLISTLINK)); if (pPointers != NULL) { int i; PLISTLINK lpCurr = ListFirst(hList); for (i = 0; lpCurr != INVALID_SLIST_PTR; lpCurr = ListNext(hList, lpCurr), i++) pPointers[i] = lpCurr; pPointers[i] = INVALID_SLIST_PTR; } return pPointers; }
void CTlvEsM8Sta::writeGenericCredentials(BufferObj &theBuf) { LPLISTITR itr; CTlvCredential *pCredential; //there should be at least one credential TLV if(0 == ListGetCount(credential)) throw RPROT_ERR_REQD_TLV_MISSING; try { if(!(itr = ListItrCreate(credential))) throw WSC_ERR_OUTOFMEMORY; uint8 macAddr[SIZE_6_BYTES]; memset(macAddr,0,sizeof(macAddr)); while((pCredential = (CTlvCredential *)ListItrGetNext(itr))) { uint8 * pos = theBuf.Pos(); // pos will point prior to Credential pCredential->write(theBuf); // write out the Credential data theBuf.Set(pos); // rewind prior to Credential CTlvCredential cr; // local Credential to override MAC address pointer cr.parse(theBuf); // create copy of Credential from buffer cr.macAddr.Set( WSC_ID_MAC_ADDR, macAddr, SIZE_6_BYTES ); theBuf.Set(pos); cr.write(theBuf); // overwrite the data in the buffer } ListItrDelete(itr); } catch(...) { if(itr) ListItrDelete(itr); } }
void CTlvEsM8Ap::write(BufferObj &theBuf, BufferObj &authKey) { LPLISTITR indexItr, keyItr; CTlvNwKeyIndex *keyIndex; CTlvNwKey *key; try { if(!(indexItr = ListItrCreate(nwKeyIndex))) throw WSC_ERR_OUTOFMEMORY; if(!(keyItr = ListItrCreate(nwKey))) throw WSC_ERR_OUTOFMEMORY; //nwIndex is an optional field if(nwIndex.Length()) nwIndex.Write(theBuf); ssid.Write(theBuf); authType.Write(theBuf); encrType.Write(theBuf); //write the network index and network key to the buffer if(ListGetCount(nwKeyIndex) == 0) { //Condition1. There is no key index, so there can only be 1 nw key if(!(key = (CTlvNwKey *) ListItrGetNext(keyItr))) throw WSC_ERR_OUTOFMEMORY; key->Write(theBuf); } else { //Condition2. There are multiple network keys. while((keyIndex= (CTlvNwKeyIndex *) ListItrGetNext(indexItr))) { if(!(key = (CTlvNwKey *) ListItrGetNext(keyItr))) throw WSC_ERR_OUTOFMEMORY; keyIndex->Write(theBuf); key->Write(theBuf); }//while }//else //write the mac address macAddr.Write(theBuf); //write the optional new password and device password ID if(new_pwd.Length()) { new_pwd.Write(theBuf); pwdId.Write(theBuf); } //calculate the hmac and append the TLV to the buffer uint8 hmac[SIZE_256_BITS]; if(HMAC(EVP_sha256(), authKey.GetBuf(), SIZE_256_BITS, theBuf.GetBuf(), theBuf.Length(), hmac, NULL) == NULL) { TUTRACE((TUTRACE_ERR, "RPROTO: Error generating HMAC\n")); throw RPROT_ERR_CRYPTO; } CTlvAuthenticator( WSC_ID_KEY_WRAP_AUTH, theBuf, hmac, SIZE_64_BITS); ListItrDelete(indexItr); ListItrDelete(keyItr); } catch(...) { if(indexItr) ListItrDelete(indexItr); if(keyItr) ListItrDelete(keyItr); throw; } }
BOOL PlayMacro(LPCMDLIST lpCmdList, LPTSTR lpFileName, int nRepeat, BOOL fSequenceAll, LPLIST lpMacroList, HWND hParent, int PhotoCDResOverride, LPTSTR lpMacroName) /***********************************************************************/ { LPIMAGE lpImage; LPCMDLIST lpNewList; int nActivates, iCount; ITEMID idCommand; STRING szString, szAppName; BOOL fError; BOOL fSequence, fCmdSequence, fCopyPackets; LIST MacroList; LPCMDPKT lpCmdPkt, lpNextPkt; MACROSETUP Setup; COMMAND_TYPE CommandType; HWND hDlg = NULL; lpAbortProc = NULL; if (!hParent) hParent = PictPubApp.Get_hWndAstral(); // see if we need to copy our packets fCopyPackets = nRepeat > 1; if (!lpMacroList) { // read in the entire macro file for faster processing if (!ReadMacro(lpFileName, &MacroList)) return(FALSE); lpMacroList = &MacroList; } // count the number of activates in the macro file // because it affects sequencing nActivates = CountType(lpMacroList, CT_ACTIVATE); // turn of macro play mode and tell the world MacroMode = MM_PLAY; if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) ) { if ( AstralStrEx( IDS_MACROPLAY, szString, sizeof(szString) ) ) { lstrcat( szAppName, szString ); SetWindowText( PictPubApp.Get_hWndAstral(), szAppName ); } } // reset untitled number so that if a macro is played it // can deal with untitled images the same Control.UntitledNo = 0; // If no command list passed in to work on (Macro Batch Mode) // then get command list for active image if (!lpCmdList) { if (lpImage = GetActiveImage()) lpCmdList = lpImage->lpCmdList; else lpCmdList = NULL; } // See if the macro contains any low res loads and // if so ask to user if he'd like to convert them // to hi res loads and if so do the convert if (FindCommand(lpMacroList, IDS_CMD_LOWRESLOAD)) if (AstralAffirm(IDS_CONVERTLOWRES)) if (!ConvertLowResLoad(lpMacroList)) { DestroyPacketList(lpMacroList); return(FALSE); } // disable all mouse and keyboard input during macro play EnableWindow(hParent, FALSE); // if not in a threading environment and caller wants us // to display a progress dialog, then set it up and do it if (!Control.UseThreading) { iCount = ListGetCount(lpMacroList) - nActivates; iCount *= nRepeat; Setup.iTotal = iCount; Setup.idDialog = IDD_MACRO_STATUS; Setup.lpFileName = NULL; hDlg = AstralDlgParam( YES, PictPubApp.GetResourceHandle(), hParent, IDD_MACRO_STATUS, DlgMacroStatusProc, (LPARAM)(LPVOID)&Setup ); if (hDlg) { if (lpMacroName) { STRING szString; GetWindowText(hDlg, szString, sizeof(szString)); lstrcat(szString, _T(" - ")); lstrcat(szString, lpMacroName); SetWindowText(hDlg, szString); } UpdateWindow(hDlg); } } // Repeat macro nRepeat number of times fError = FALSE; while (--nRepeat >= 0 && !fError) { if (lpAbortProc && (*lpAbortProc)()) break; // back to beginning of macro file lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList); // initialize sequencing fSequence = fSequenceAll; while (!fError && lpNextPkt) { if (lpAbortProc && (*lpAbortProc)()) { fError = TRUE; break; } // get the packet to work on if (fCopyPackets) { lpCmdPkt = CopyPacket(lpNextPkt); if (!lpCmdPkt) { fError = TRUE; break; } } else { ListUnlink(lpMacroList, lpNextPkt); lpCmdPkt = lpNextPkt; } // get command id and parms for this command idCommand = lpCmdPkt->idCommand; // Find out whether this command requires sequencing // set it here, so command can change it if needed before // we actually set fSequence fCmdSequence = GetCommandSequence(idCommand); CommandType = GetCommandType(idCommand); // Handle the different types of commands switch (CommandType) { case CT_LOAD: // create new command list for load lpNewList = CreateCommandList(); if (lpNewList) { ListAddTail(&lpNewList->PacketList, lpCmdPkt); // if we already have a command list containing commands, // kick off the execution of those commands before we // switch to the new command list if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); // if some command in the command list affects // sequencing force the whole command list to // be processed if (fSequence) { FlushCommands(lpCmdList); fSequence = fSequenceAll; } } // setup new command list for us to work with lpCmdList = lpNewList; lpCmdList->PhotoCDResOverride = PhotoCDResOverride; // If there are any activates in this macro make sure a // command that creates an image processes immediately if (nActivates) { PlaybackCommands(lpCmdList); FlushCommands(lpCmdList); fSequence = fSequenceAll; fCmdSequence = NO; // already sequenced } } break; case CT_COPY: // Make sure we have a command list to work with if (!lpCmdList) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } // Just add this command to the command list ListAddTail(&lpCmdList->PacketList, lpCmdPkt); // If there are any activates in this macro make sure a // command that creates an image processes immediately if (nActivates) { PlaybackCommands(lpCmdList); FlushCommands(lpCmdList); fSequence = fSequenceAll; fCmdSequence = NO; // already sequenced } break; case CT_SAVE: case CT_EDIT: case CT_MASK: case CT_MODE: case CT_EDITUNDO: case CT_MASKUNDO: case CT_EDITOBJ: case CT_CLOSE: // Make sure we have a command list to work with if (!lpCmdList) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } if (CommandType == CT_SAVE) { PlaybackCommands(lpCmdList); if (!lpCmdList->ThreadData.lpImage) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } } // Just add this command to the command list ListAddTail(&lpCmdList->PacketList, lpCmdPkt); if (CommandType != CT_CLOSE) break; case CT_ACTIVATE: // Program or commands that affect window activation // are processed here switch (idCommand) { case IDS_CMD_CLOSE: case IDS_CMD_ACTIVATEWINDOW: { // if we already have a command list containing commands, // kick of the execution of those commands before we // switch to the new command list if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); // if some command in the command list affects // sequencing force the whole command list to // be processed if (fSequence) { FlushCommands(lpCmdList); fSequence = fSequenceAll; } } // if this was a close command, then wack the command list pointer if (idCommand == IDS_CMD_CLOSE) lpCmdList = NULL; else { // now process the activate and get a new command list lpNewList = ProgActivateWindow( (LPACTIVATEWINDOW_PARMS)lpCmdPkt->lpParms); // setup the new command list if we got one if (lpNewList) lpCmdList = lpNewList; else { CommandError(idCommand); fError = TRUE; } // activate don't go through command processing // so we have to free it up here FreeUpPacket(lpCmdPkt); } } break; default: break; } break; default: break; } // if command just handled requires sequencing // set sequencing flag if (fCmdSequence) fSequence = YES; if (fCopyPackets) // get next command packet in macro list lpNextPkt = (LPCMDPKT)ListGetNext(lpNextPkt); else // head of list will be next one if we're not copying lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList); } } // get rid of macro list DestroyPacketList(lpMacroList); // if we already have a command list containing commands, // kick off the execution of those commands if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); if (fSequenceAll) FlushCommands(lpCmdList); } // turn off the macro mode EnableWindow(hParent, TRUE); if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) ) SetWindowText( PictPubApp.Get_hWndAstral(), szAppName ); // if we have a progress dialog, nuke it if (hDlg) AstralDlgEnd(hDlg, TRUE); // if we are display the macro status for another modal dialog // make sure the main app stuff is still disabled if (hParent != PictPubApp.Get_hWndAstral()) { EnableOverlappedWindow( PictPubApp.Get_hWndAstral(), FALSE ); EnableWindow(PictPubApp.Get_hWndAstral(), FALSE); } MacroMode = MM_NONE; return(TRUE); }