EXPORT_C TBool CHTTPResponse::FindField(THttpHeaderField aField, TPtrC8& aDesc, TInt aStartIndex) const { // __LOG_ENTER(_L("CHTTPResponse::FindField (string)")); // __LOG1(_L("CHTTPResponse::FindField : searching for field type = %d"), aField); TInt index = LocateField(aField, aStartIndex); if (index >0) { TInt count = 0; for (count = index; (count < iResponse->Length()) && (iResponse->Des()[count] != 0); count++) {}; if (count <= iResponse->Length()) { aDesc.Set(&(iResponse->Des()[index]), count-index); // __LOG(_L("CHTTPResponse::FindField : found string:")); #ifdef _DEBUG DumpToLog(aDesc); #endif // __LOG_RETURN; return ETrue; } } // __LOG(_L("CHTTPResponse::FindField : nothing found")); // __LOG_RETURN; return EFalse; }
EXPORT_C TBool CHTTPResponse::FindField(THttpHeaderField aField, TTime& aTime, TInt aStartIndex) const { __LOG_ENTER(_L("CHTTPResponse::FindField (time)")); TBool result = EFalse; TInt index = LocateField(aField, aStartIndex); if (index > 0) { TPtr8 respChars = iResponse->Des(); ExtractFieldDateValue(respChars,index,aTime); result = ETrue; } __LOG_RETURN; return result; }
EXPORT_C TBool CHTTPResponse::FindBinaryDescField(THttpHeaderField aField, TPtrC8& aDesc, TInt aStartIndex) const { TInt index = LocateField(aField, aStartIndex); if (index >= 0) { TInt offset = 0; TInt fieldLength = iResponse->Des()[index]; // assume the length is in // a short integer if(fieldLength == 31) { // Nope : Code 31 indicates that the following bytes make a // UIntVar, which indicates the number of data octets after it. // The UIntVar itself could be composed of upto 5 bytes // Copy a full 5 bytes from the header // Note that actually fewer might have been used; // the UIntVar to Int converter function returns the exact number // that were used. TInt consumed = ParseUIntVar(iResponse->Des().Mid(index + 1), fieldLength); __ASSERT_DEBUG( consumed >= KErrNone, User::Invariant() ); offset += consumed; } else if (fieldLength > 127) { // Oops be sneaky and reuse this single byte // Because this is a special code fieldLength = 1; offset = -1; } if(fieldLength) { aDesc.Set(&(iResponse->Des()[index + offset + 1]), fieldLength); #ifdef _DEBUG DumpToLog(aDesc); #endif return ETrue; } } return EFalse; }
void WinEDA_LibeditFrame::OnLeftDClick(wxDC * DC, const wxPoint& MousePos) /*************************************************************************/ /* Appelé sur un double click: pour un élément editable (textes, composant): appel de l'editeur correspondant. pour une connexion en cours: termine la connexion */ { wxPoint pos = GetPosition(); LibEDA_BaseStruct* DrawEntry = CurrentDrawItem; if ( CurrentLibEntry == NULL ) return; if ( !m_ID_current_state || // Simple localisation des elements (DrawEntry == NULL) || (DrawEntry->m_Flags == 0) ) { DrawEntry = LocatePin(m_CurrentScreen->m_Curseur, CurrentLibEntry, CurrentUnit, CurrentConvert); if ( DrawEntry == NULL ) { DrawEntry = CurrentDrawItem = LocateDrawItem(GetScreen(), CurrentLibEntry,CurrentUnit, CurrentConvert,LOCATE_ALL_DRAW_ITEM); } if ( DrawEntry == NULL ) { DrawEntry = CurrentDrawItem = (LibEDA_BaseStruct*) LocateField(CurrentLibEntry); } if ( DrawEntry == NULL ) { wxPoint mpos; wxGetMousePosition(&mpos.x, &mpos.y); InstallLibeditFrame(mpos); } } // Si Commande en cours: affichage commande d'annulation if ( m_ID_current_state ) { } else { } if ( DrawEntry ) DrawEntry->Display_Infos_DrawEntry(this); else return; CurrentDrawItem = DrawEntry; DrawPanel->m_IgnoreMouseEvents = TRUE; switch ( DrawEntry->m_StructType ) { case COMPONENT_PIN_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) // Item localisé et non en edition: placement commande move { InstallPineditFrame(this, DC, pos); } break; case COMPONENT_ARC_DRAW_TYPE: case COMPONENT_CIRCLE_DRAW_TYPE: case COMPONENT_RECT_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { EditGraphicSymbol(DC, DrawEntry); } break; case COMPONENT_LINE_DRAW_TYPE: case COMPONENT_POLYLINE_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { EditGraphicSymbol(DC, DrawEntry); } else if( DrawEntry->m_Flags & IS_NEW ) { EndDrawGraphicItem(DC); } break; case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { EditSymbolText(DC, DrawEntry); } break; case COMPONENT_FIELD_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { } break; default: wxString msg; msg.Printf( wxT("WinEDA_LibeditFrame::OnLeftDClick Error: unknown StructType %d"), DrawEntry->m_StructType); DisplayError(this, msg ); break; } DrawPanel->MouseToCursorSchema(); DrawPanel->m_IgnoreMouseEvents = FALSE; }
void WinEDA_LibeditFrame::OnRightClick(const wxPoint& MousePos, wxMenu * PopMenu) /********************************************************************************/ { LibEDA_BaseStruct* DrawEntry = CurrentDrawItem; bool BlockActive = (m_CurrentScreen->BlockLocate.m_Command != BLOCK_IDLE); if ( CurrentLibEntry == NULL ) return; if ( (DrawEntry == NULL) || (DrawEntry->m_Flags == 0) ) { // Simple localisation des elements DrawEntry = LocatePin(m_CurrentScreen->m_Curseur, CurrentLibEntry, CurrentUnit, CurrentConvert); if ( DrawEntry == NULL ) { DrawEntry = CurrentDrawItem = LocateDrawItem(GetScreen(), CurrentLibEntry,CurrentUnit, CurrentConvert,LOCATE_ALL_DRAW_ITEM); } if ( DrawEntry == NULL ) { DrawEntry = CurrentDrawItem = (LibEDA_BaseStruct*) LocateField(CurrentLibEntry); } } // If Command in progresss: put the menu "cancel" and "end tool" if ( m_ID_current_state ) { if (DrawEntry && DrawEntry->m_Flags) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _("Cancel"), cancel_xpm); } else { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _("End Tool"), cancel_tool_xpm); } PopMenu->AppendSeparator(); } else { if ( (DrawEntry && DrawEntry->m_Flags) || BlockActive ) { if ( BlockActive ) AddMenusForBlock( PopMenu, this); else ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _("Cancel"), cancel_xpm); PopMenu->AppendSeparator(); } } if ( DrawEntry ) DrawEntry->Display_Infos_DrawEntry(this); else return; CurrentDrawItem = DrawEntry; switch ( DrawEntry->m_StructType ) { case COMPONENT_PIN_DRAW_TYPE: AddMenusForPin(PopMenu, (LibDrawPin*)DrawEntry, this); break; case COMPONENT_ARC_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, _("Move Arc"), move_arc_xpm); } ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, _("Arc Options"), options_arc_xpm ); if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, _("Arc Delete"), delete_arc_xpm); } break; case COMPONENT_CIRCLE_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, _("Move Circle"), move_circle_xpm); } ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, _("Circle Options"), options_circle_xpm); if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, _("Circle Delete"), delete_circle_xpm); } break; case COMPONENT_RECT_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, _("Move Rect"), move_rectangle_xpm); } ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, _("Rect Options"), options_rectangle_xpm); if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, _("Rect Delete"), delete_rectangle_xpm); } break; case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, _("Move Text"), move_text_xpm); } ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, _("Text Editor"), edit_text_xpm); ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT, _("Rotate Text"), edit_text_xpm); if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, _("Text Delete"), delete_text_xpm); } break; case COMPONENT_POLYLINE_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, _("Move Line"), move_line_xpm); } if ( DrawEntry->m_Flags & IS_NEW ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM, _("Line End"), apply_xpm); } ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, _("Line Options"), options_segment_xpm); if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, _("Line Delete"), delete_segment_xpm); } else if( (DrawEntry->m_Flags & IS_NEW) ) { if( ((LibDrawPolyline*)DrawEntry)->n > 2 ) ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT, _("Segment Delete"), delete_segment_xpm); } break; case COMPONENT_FIELD_DRAW_TYPE: if( DrawEntry->m_Flags == 0 ) { ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, _("Move Field"), move_field_xpm); } ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM, _("Field Rotate"), rotate_field_xpm); ADD_MENUITEM(PopMenu, ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM, _("Field Edit"), edit_text_xpm); break; default: wxString msg; msg.Printf( wxT("WinEDA_LibeditFrame::OnRightClick Error: unknown StructType %d"), DrawEntry->m_StructType); DisplayError(this, msg ); CurrentDrawItem = NULL; break; } PopMenu->AppendSeparator(); }
EXPORT_C TBool CHTTPResponse::CharSet(TPtrC8& aDesc) const { // __LOG_ENTER(_L("CHTTPResponse::CharSet")); // Find the byte index in the header for the content type value TInt index = LocateField(EHttpContentType); TUint8 byteCode = 0; TInt paramByteCode = KErrNotFound; TInt valueByteCode1 = KErrNotFound; TInt charsetCode = 0; // Read the byte code, unless KErrNotFound was returned if (index != KErrNotFound) { TPtr8 respChars = iResponse->Des(); TInt respLength = iResponse->Length(); // If the byteCode is in the range 0-30 then a range of bytes is // indicated: the following byte gives the content type and the // remainder are arranged as a series of parameter attribute-value // pairs. This method checks for the presence of a 'charset' parameter. byteCode = respChars[index]; // __LOG1(_L("CHTTPResponse::CharSet : found bytecode = %d"), byteCode); // Check valid range ... note that a range of zero could not contain a charset // parameter anyway, so exclude it... if ((byteCode > 0) && (byteCode <= 30)) { // Check for overrun... if this occurs it should be an error. Note that // corruption _could_ occur in this response buffer - some gateways, which // don't return error decks (e.g. AnyTime GW) send a response buffer 1 byte // long, containing only the value 0x01 - which is invalid WSP. // Be conservative and safe here - we can't overrun. Use the value of byte- // -Code (which should be the WSP encoding of how many bytes follow), or the // total length of the response - whichever is smaller. if (index + byteCode < respLength) { // e,g, header to illustrate use of offsets in this code: // 03 94 81 84 : Content-Type: application/vnd.wap.wmlc; charset=iso-8859-1 // +0 +1 +2 +3 : 03 = no. bytes in Content-Type header // : 94 = 14 | 80 = application/vnd.wap.wmlc // : 81 = 01 | 80 = Charset parameter // : 84 = 04 | 80 = iso-8859-1 paramByteCode = respChars[index + 2]; if ((paramByteCode & 0x7f) == EHttpCharset) { // We have a charset paramByteCode &= 0x7f; valueByteCode1 = respChars[index + 3]; if (valueByteCode1 & 0x80) { // A short one-byte value charsetCode = valueByteCode1 & 0x7f; } else { // A multibyte value ExtractMultiOctetInteger(charsetCode, respChars.Mid(index + 3)); } } } else { index = KErrNotFound; } } } // If a parameter-value pair was found, determine whether it encodes a // charset if ( (index != KErrNotFound) && (paramByteCode == EHttpCharset) ) { // Look up the value from the charset table. const TText8* chset; chset = CharSet(charsetCode); // Convert the charset string to the supplied descriptor if (chset) aDesc.Set(TPtrC8(chset)); else index = KErrNotFound; // We've found a charset but we don't recognise it } else // Either no content-type header (hence no charset) or a content-type // header with a parameter other than charset { index = KErrNotFound; } // __LOG1(_L("CHTTPResponse::CharSet : CharSet = %S"), &aDesc); // __LOG_RETURN; return (index !=KErrNotFound); }
EXPORT_C void CHTTPResponse::ContentType(TPtrC8& aDesc) const { // Decode the content-type data as per the WSP bnf... // Note - There is no provision available here to handle content-type parameters // so parameters are ignored here. TInt error = LocateField(EHttpContentType); TInt token = 0; TBool isString = EFalse; if (error != KErrNotFound) { TPtrC8 respChars(*iResponse); TWspPrimitiveDecoder wspDecoder(respChars); TWspPrimitiveDecoder::TWspHeaderType type = wspDecoder.VarType(); switch(type) { case TWspPrimitiveDecoder::E7BitVal: { // 128-255 - encoded 7 bit value, this header has no more data TUint8 byteCode = 0; error = wspDecoder.Val7Bit(byteCode); // error code token = static_cast<TInt>(byteCode); } break; case TWspPrimitiveDecoder::EString: { // 32-127 - value is a text string, terminated by a '\0' // Content type is embedded as a text string error = wspDecoder.String(aDesc); // error code isString = ETrue; } break; case TWspPrimitiveDecoder::ELengthVal: { // 0-31 - octet is a value length TInt dataLength = 0; error = wspDecoder.LengthVal(dataLength); if( error >= KErrNone ) { type = wspDecoder.VarType(); if( type == TWspPrimitiveDecoder::E7BitVal || type == TWspPrimitiveDecoder::ELengthVal ) { TUint32 contentTypeToken = 0; error = wspDecoder.Integer(contentTypeToken); token = static_cast<TInt>(contentTypeToken); } else if( type == TWspPrimitiveDecoder::EString ) { error = wspDecoder.String(aDesc); isString = ETrue; } } } break; default: { error = KErrNotFound; } break; } } if(error < KErrNone) token = KErrNotFound; // Look up the appropriate content type, provided an error hasn't occurred or the string // has not already been set if (token == KErrNotFound || !isString) { // Convert the content type string to the supplied descriptor const TText8* type = ContentType(token); aDesc.Set(TPtrC8(type)); // __LOG1(_L("CHTTPResponse::ContentType : contentIndex = %d"), contentIndex); } }
// Method to find a named field within the Cache Control header // // In: // aField - the field type // // Out: // the found aCacheControl string // // Rtn: TInt - set to KErrNotFound if the field was not found, // otherwise the position in the cache control descriptor that the field // was found // TInt CHTTPResponse::FindCacheControlFieldValue(TCacheControlFieldValue aField, TPtrC8& aCacheControl) const // Find a named field within the Cache Control header { __LOG_ENTER(_L("CHTTPResponse::FindCacheControlFieldValue")); TInt pos = KErrNotFound; TInt index = LocateField(EHttpCacheControl, 0); if (index >0) { // Have the cache control descriptor // Now we need to search for the field // The following rules are used to encode cache control values. // Cache-control-value = No-cache | No-store | Max-stale | // Only-if-cached | Private | Public | // No-transform | Must-revalidate | // Proxy-revalidate | Cache-extension | // Value-length Cache-directive // Cache-directive = No-cache 1*(Field-name) | // Max-age Delta-second-value | // Max-stale Delta-second-value | // Min-fresh Delta-second-value | // Private 1*(Field-name) | // Cache-extension Parameter TUint8 byteCode = iResponse->Des()[index]; // check the first byte for a recognised value if((byteCode >= 32) && (byteCode <= 127)) { // Hit the start of a Header Name string - this will be assumed // continuous until the NUL is found or until the end // of the header is hit (which would be an error) // - not supported return pos; } switch (byteCode) { case ECacheControlNoCache: // "no-cache" case ECacheCtrlNoStore: // "no-store" case ECacheCtrlMaxStale: // "max-stale" case ECacheCtrlOnlyIfCached: // "only-if-cached" case ECacheCtrlPublic: // "public" case ECacheCtrlPrivate: // "private" case ECacheCtrlNoTransform: // "no-transform" case ECacheCtrlMustRevalidate: // "must-revalidate" case ECacheCtrlProxyRevalidate: // "proxy-revalidate" if( aField == byteCode ) pos = index; // Right here (right now). break; case ECacheCtrlCacheExtension: // "cache-extension": break; // Not handled default: { // Value-length Cache-directive if(FindBinaryDescField(EHttpCacheControl,aCacheControl)) { TInt respLength = aCacheControl.Length(); TUint8 byteCode = 0; for (TInt count = 0; count < respLength; count++) { byteCode = aCacheControl[count]; if(aField == byteCode) { // Found the field we are looking for pos = count; break; } else if(count < (respLength - 1)) // Check for overrun... if this occurs it should be an error { if (byteCode <= 30) { // Codes 0-30 represent that number of following data // octets, check the cache directive field after the length if(aField == aCacheControl[count + 1]) { // Found the one we want pos = count + 1; break; } else if(byteCode) { // so the following data octets should be skipped count += byteCode; } else { __DEBUGGER(); count++; // 0 data octets follow !???? : (Strange but true) } } else if (byteCode == 31) { // Code 31 indicates that the following bytes make a // UIntVar, which indicates the number of data octets // after it. // The UIntVar itself could be composed of upto 5 bytes // Copy a full 5 bytes from the header // Note that actually fewer might have been used; // the UIntVar to Int converter function returns the exact // number that were used. TInt value = 0; TInt consumed = ParseUIntVar(aCacheControl.Mid(count + 1), value); if( consumed < KErrNone ) return KErrCorrupt; if(aField == aCacheControl[count + 1 + consumed]) { // Found the one we want pos = count + 1 + consumed; break; } else { // so the following data octets should be skipped count += 1 + consumed + value; } } } } } } break; } } __LOG_RETURN; return pos; }