1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <stdio.h> 18 19 #define LOG_TAG "DhcpEvent" 20 #include <cutils/log.h> 21 22 #include "DhcpEvent.h" 23 24 char *DhcpEvent::toString(int val, char *buffer, int max) { 25 if (val == DhcpEvent::UNKNOWN) 26 strncpy(buffer, "UNKNOWN", max); 27 else if (val == DhcpEvent::STOP) 28 strncpy(buffer, "STOP", max); 29 else if (val == DhcpEvent::RENEW) 30 strncpy(buffer, "RENEW", max); 31 else if (val == DhcpEvent::RELEASE) 32 strncpy(buffer, "RELEASE", max); 33 else if (val == DhcpEvent::TIMEOUT) 34 strncpy(buffer, "TIMEOUT", max); 35 else 36 strncpy(buffer, "(internal error)", max); 37 38 return buffer; 39 } 40 41 int DhcpEvent::parseString(const char *buffer) { 42 if (!strcasecmp(buffer, "UNKNOWN")) 43 return DhcpEvent::UNKNOWN; 44 else if (!strcasecmp(buffer, "STOP")) 45 return DhcpEvent::STOP; 46 else if (!strcasecmp(buffer, "RENEW")) 47 return DhcpEvent::RENEW; 48 else if (!strcasecmp(buffer, "RELEASE")) 49 return DhcpEvent::RELEASE; 50 else if (!strcasecmp(buffer, "TIMEOUT")) 51 return DhcpEvent::TIMEOUT; 52 else { 53 LOGW("Bad event '%s'", buffer); 54 return -1; 55 } 56 } 57